From 1d9bc9391eceaecf9f3ea4b126207bfa6246fe09 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Sat, 5 Sep 2026 08:48:49 +0000 Subject: [PATCH] fix: address Zig PR review feedback (#3180) Check for the vendored package without loading its native binding so a broken installed Zig grammar fails the parsing test instead of skipping. Match the optional child descriptor in the Zig metadata declaration and include Zig in the two optional/vendored grammar comments. Validation: 159 targeted tests, TypeScript, metadata type fixture, and formatting passed. Injected native-load failure now fails instead of skipping; explicit Zig opt-out still skips. --- gitnexus/test/helpers/grammar-introspection.ts | 2 +- .../test/integration/tree-sitter-languages.test.ts | 14 ++++---------- .../test/unit/parser-loader-skip-optional.test.ts | 2 +- .../tree-sitter-zig/bindings/node/index.d.ts | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/gitnexus/test/helpers/grammar-introspection.ts b/gitnexus/test/helpers/grammar-introspection.ts index f1c0b0dee..503290ab5 100644 --- a/gitnexus/test/helpers/grammar-introspection.ts +++ b/gitnexus/test/helpers/grammar-introspection.ts @@ -109,7 +109,7 @@ interface NodeTypeEntry { /** Resolve the on-disk directory of an installed package, or null if absent. */ function resolvePackageDir(pkg: string): string | null { - // Vendored grammars (c/dart/proto/swift/kotlin) are NOT in node_modules — they + // Vendored grammars (c/dart/proto/swift/kotlin/zig) are NOT in node_modules — they // load from vendor/ by absolute path (vendored-grammars.ts / #2111), so resolve // their node-types.json from there rather than via _require.resolve. if (VENDORED_GRAMMAR_PACKAGES.has(pkg)) { diff --git a/gitnexus/test/integration/tree-sitter-languages.test.ts b/gitnexus/test/integration/tree-sitter-languages.test.ts index dfb68f430..7c3f3eb9e 100644 --- a/gitnexus/test/integration/tree-sitter-languages.test.ts +++ b/gitnexus/test/integration/tree-sitter-languages.test.ts @@ -10,7 +10,7 @@ import { import { SupportedLanguages, getLanguageFromFilename } from 'gitnexus-shared'; import { getProvider } from '../../src/core/ingestion/languages/index.js'; import Parser from 'tree-sitter'; -import { requireVendoredGrammar } from '../../src/core/tree-sitter/vendored-grammars.js'; +import { vendoredGrammarDir } from '../../src/core/tree-sitter/vendored-grammars.js'; const fixturesDir = path.resolve(__dirname, '..', 'fixtures', 'sample-code'); @@ -690,15 +690,9 @@ describe('Tree-sitter multi-language parsing', () => { // mismatch, bad export) must fail this test, not silently skip it. A // deliberate `GITNEXUS_SKIP_OPTIONAL_GRAMMARS` opt-out in the environment // is the one non-failure reason an installed grammar reports unavailable. - const zigPackageInstalled = (() => { - if (isGrammarRuntimeSkipped(SupportedLanguages.Zig)) return false; - try { - requireVendoredGrammar('tree-sitter-zig'); - return true; - } catch { - return false; - } - })(); + const zigPackageInstalled = + !isGrammarRuntimeSkipped(SupportedLanguages.Zig) && + fs.existsSync(path.join(vendoredGrammarDir('tree-sitter-zig'), 'package.json')); it.skipIf(!zigPackageInstalled)('parses functions, structs, enums, and imports', async () => { expect(isLanguageAvailable(SupportedLanguages.Zig)).toBe(true); await loadLanguage(SupportedLanguages.Zig); diff --git a/gitnexus/test/unit/parser-loader-skip-optional.test.ts b/gitnexus/test/unit/parser-loader-skip-optional.test.ts index 1b1fbe925..4e7613c00 100644 --- a/gitnexus/test/unit/parser-loader-skip-optional.test.ts +++ b/gitnexus/test/unit/parser-loader-skip-optional.test.ts @@ -6,7 +6,7 @@ import { SupportedLanguages } from '../../src/config/supported-languages.js'; * * `GITNEXUS_SKIP_OPTIONAL_GRAMMARS` used to be an install-time-only env (the * postinstall build scripts read it). `parser-loader` now also honors it at - * analyze time: when set, genuinely-optional grammars (swift/dart/kotlin) + * analyze time: when set, genuinely-optional grammars (swift/dart/kotlin/zig) * report unavailable so the ingestion pipeline skips their files, mirroring a * genuinely-absent binding. Grammars that are required `dependencies` routed * through the optional machinery for ABI safety (C — `severity: 'error'`) are diff --git a/gitnexus/vendor/tree-sitter-zig/bindings/node/index.d.ts b/gitnexus/vendor/tree-sitter-zig/bindings/node/index.d.ts index efe259eed..6cb1f9974 100644 --- a/gitnexus/vendor/tree-sitter-zig/bindings/node/index.d.ts +++ b/gitnexus/vendor/tree-sitter-zig/bindings/node/index.d.ts @@ -15,7 +15,7 @@ type NodeInfo = }) | (BaseNode & { fields: { [name: string]: ChildNode }; - children: ChildNode[]; + children?: ChildNode; }); type Language = {