fix(ci): add zig parse snippet to prebuild validate

The six zig prebuild jobs failed at "Validate the .node loads and parses"
because snippets[GRAMMAR] was undefined and tree-sitter threw
"Input must be a function".

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Gergo Magyar 2026-09-05 06:13:29 +00:00
parent 45d5a01268
commit f301b0a966
2 changed files with 29 additions and 1 deletions

View file

@ -477,11 +477,14 @@ jobs:
proto: "syntax = \"proto3\";\nmessage M { int32 id = 1; }",
kotlin: "fun main() { println(\"hi\") }",
swift: "func greet() { print(\"hi\") }",
zig: "pub fn main() void {}",
};
const src = snippets[process.env.GRAMMAR];
if (!src) throw new Error("no validate snippet for grammar: " + process.env.GRAMMAR);
const lang = require("node-gyp-build")(process.cwd());
const Parser = require("tree-sitter");
const p = new Parser(); p.setLanguage(lang);
const tree = p.parse(snippets[process.env.GRAMMAR]);
const tree = p.parse(src);
if (!tree || !tree.rootNode || tree.rootNode.hasError) {
throw new Error("parse failed/error: " + (tree && tree.rootNode && tree.rootNode.type));
}

View file

@ -175,3 +175,28 @@ describe('npm-dependency grammar prebuild coverage', () => {
});
}
});
describe('prebuild workflow validate snippets cover every REGISTRY grammar', () => {
// The "Validate the .node loads and parses" step looks up snippets[GRAMMAR].
// A missing key yields undefined, and tree-sitter's parse() throws
// "Input must be a function" — the six zig jobs on #3180.
const workflow = readFileSync(
path.join(GITNEXUS_ROOT, '..', '.github/workflows/build-tree-sitter-prebuilds.yml'),
'utf8',
);
const registry = [
...workflow.matchAll(/^\s{12}(\w+):\s+\{\s+name:\s+'tree-sitter-/gm),
].map((m) => m[1]);
const snippets = [...workflow.matchAll(/^\s{14}(\w+):\s+"/gm)].map((m) => m[1]);
it('REGISTRY and snippets are both non-empty (the regex still matches the workflow)', () => {
expect(registry.length).toBeGreaterThan(0);
expect(snippets.length).toBeGreaterThan(0);
});
it('every REGISTRY grammar has a parse snippet', () => {
expect(snippets.sort(), 'add a snippets.<grammar> entry when extending REGISTRY').toEqual(
[...registry].sort(),
);
});
});