mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-11 03:38:07 +00:00
* fix(deps): upgrade native tree-sitter to 0.25.1 * fix(tree-sitter): preserve sync loading and update verified capture baselines Route C# scope queries through the synchronous native grammar loader so the compiled analyze module remains require-compatible on Node 22.18. Refresh only the audited empty-Python-module and renamed-PHP-fixture captures, and pin the runtime assertion to 0.25.1. Validated 479 targeted tests, all 16 scope-capture benchmark cases, Python capture/import guards, compiled C# worker parsing, build, typecheck and formatting. Performance budgets are unchanged. * fix(tree-sitter): refresh upstream vendors and preserve parser semantics * fix(ci): refresh prebuilds and support Windows ARM Refresh macOS, Linux ARM, and Windows x64 grammar binaries from the successful native CI builds. Pin node-gyp 12.4.0 so the Windows ARM jobs recognize Visual Studio 2026. Use local Git filtering for E2E to avoid PR-files API timeouts on generated parser diffs. Validation: 143 focused tests, Actionlint, and all 16 scope-capture benchmark checks passed. Full npm test run started; native database suites still running. * fix(ci): refresh Windows ARM grammar prebuilds Import all seven Windows ARM grammar artifacts from successful native build run 37965761760. Artifact filenames and SHA-256 hashes verified; all 42 native build jobs passed. Validation: 31 prebuild coverage tests passed. * fix(bench): stabilize scope capture timing guard Warm each input size seven times and use 21 median samples while retaining isolated timing blocks. Yield between languages so native finalizers release allocations outside the measured sections. Keep all fixture sizes, fingerprints, scaling formulas, and budgets unchanged. Validation: all 16 language guards passed with a 2 GB heap limit (1.38 deep-chain ratio; 1518 MB peak RSS). Linear and quadratic controls passed their expected guard outcomes. Formatting and graph change analysis passed. Full npm test is running without failures so far. * fix(parser): reduce TypeScript capture traversal cost * fix(test): await parser worker readiness before teardown * fix(parser): load C# synchronously in workers * fix(grpc): resolve native proto detections against their own file With the native proto grammar active, sibling .proto files that declare the same short service name under different packages tied in the directory-based resolveProtoConflict heuristic and both providers were dropped. A proto-origin detection already knows its defining file, so use that file's entry before falling back to the heuristic. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(packaging): assert native grammars load from the installed tarball The packaged-install smoke only ran `gitnexus --version`, so a grammar that failed to load from the published package (bundled runtime, patched peer manifests, vendored prebuilds, C# sync loader, Protobuf wrapper) would ship silently; the dev-tree ABI smoke also accepts vendored grammars that report unavailable. Parse a sample for every registered grammar plus the native Protobuf plugin from the installed package, on the main thread and in a worker thread. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(tree-sitter): track compatibility workarounds instead of 0.25 readiness The daily readiness report still targeted tree-sitter@0.25.0, so after the upgrade it would keep reporting "Blocked" and never close its tracking issue. Repurpose it to track what we carry for the bundled runtime: derive the target from the package.json pin, list each pack-time peer patch from prepare-tree-sitter-bundle.cjs with its drop condition (bump, wait for an upstream release, transitive, or intentionally pinned), and reword the buckets. The workflow adopts the issue opened under the old title. Also update the grammar-update-monitor header and auto-PR text, which still described the 0.21.1 runtime and a tree-sitter-c hold. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(dart): assert both nested labels target the loop; fix Zig call-shape doc The nested-label CFG test only jumped to `outer` and checked reachability, which still passes when a jump is retargeted to the inner loop (its exit reaches the outer header). Jump to both labels and assert the exact `continue` edges; dropping the inner label now fails the test. Update the Zig callable-flow comment: call_expression now wraps actuals in a required `arguments:` field. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Codex <codex@openai.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
190 lines
6.9 KiB
TypeScript
190 lines
6.9 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { loadParser, loadLanguage } from '../../src/core/tree-sitter/parser-loader.js';
|
|
import { SupportedLanguages } from '../../src/config/supported-languages.js';
|
|
|
|
describe('parser-loader', () => {
|
|
it('keeps reporting C# grammar initialization failures on repeated calls', async () => {
|
|
vi.resetModules();
|
|
const loader = await import('../../src/core/tree-sitter/parser-loader.js');
|
|
const failure = new Error('C# grammar failed to load');
|
|
const loadGrammar = vi.spyOn(loader, 'getLanguageGrammar').mockImplementation(() => {
|
|
throw failure;
|
|
});
|
|
try {
|
|
const { getCsharpParser } =
|
|
await import('../../src/core/ingestion/languages/csharp/query.js');
|
|
expect(() => getCsharpParser()).toThrow(failure);
|
|
expect(() => getCsharpParser()).toThrow(failure);
|
|
loadGrammar.mockRestore();
|
|
const parser = getCsharpParser();
|
|
expect(parser.parse('class Recovered {}').rootNode.hasError).toBe(false);
|
|
expect(getCsharpParser()).toBe(parser);
|
|
} finally {
|
|
loadGrammar.mockRestore();
|
|
}
|
|
});
|
|
|
|
describe('loadParser', () => {
|
|
it('returns a Parser instance', async () => {
|
|
const parser = await loadParser();
|
|
expect(parser).toBeDefined();
|
|
expect(typeof parser.parse).toBe('function');
|
|
});
|
|
|
|
it('returns the same singleton instance', async () => {
|
|
const parser1 = await loadParser();
|
|
const parser2 = await loadParser();
|
|
expect(parser1).toBe(parser2);
|
|
});
|
|
});
|
|
|
|
describe('loadLanguage', () => {
|
|
it('loads TypeScript language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.TypeScript)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads JavaScript language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.JavaScript)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads Python language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.Python)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads Java language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.Java)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads C language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.C)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads C++ language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.CPlusPlus)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads C# language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.CSharp)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads Go language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.Go)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads Rust language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.Rust)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads PHP language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.PHP)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads TSX grammar for .tsx files', async () => {
|
|
// TSX uses a different grammar (TypeScript.tsx vs TypeScript.typescript)
|
|
await expect(
|
|
loadLanguage(SupportedLanguages.TypeScript, 'Component.tsx'),
|
|
).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads TS grammar for .ts files', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.TypeScript, 'utils.ts')).resolves.not.toThrow();
|
|
});
|
|
|
|
it('loads Ruby language', async () => {
|
|
await expect(loadLanguage(SupportedLanguages.Ruby)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('throws for unsupported language', async () => {
|
|
await expect(loadLanguage('erlang' as SupportedLanguages)).rejects.toThrow(
|
|
'Unsupported language',
|
|
);
|
|
});
|
|
});
|
|
|
|
// #1242: regression coverage for the Windows tree-sitter@0.21.1 + tree-sitter-c
|
|
// ABI mismatch. setLanguage alone could pass while the first non-trivial
|
|
// traversal/query produced "Cannot read properties of undefined (reading
|
|
// '161')" inside unmarshalNode (or a native segfault under the worker).
|
|
describe('C parser ABI compatibility (#1242)', () => {
|
|
const C_SOURCE = `#include <stdio.h>
|
|
struct Foo { int a; int b; };
|
|
typedef struct Foo Bar;
|
|
static int helper(int x) { return x * 2; }
|
|
int add(int a, int b) { return a + b; }
|
|
int main(void) {
|
|
Bar b = {1, 2};
|
|
return add(b.a, helper(b.b));
|
|
}
|
|
`;
|
|
|
|
it('parses a non-trivial C translation unit and walks the tree', async () => {
|
|
const parser = await loadParser();
|
|
await loadLanguage(SupportedLanguages.C);
|
|
const tree = parser.parse(C_SOURCE);
|
|
|
|
expect(tree.rootNode.type).toBe('translation_unit');
|
|
|
|
let nodeCount = 0;
|
|
const walk = (node: { type: string; children: any[] }): void => {
|
|
nodeCount += 1;
|
|
// Touching `.type` here is what triggered the original
|
|
// unmarshalNode crash on incompatible ABIs.
|
|
expect(typeof node.type).toBe('string');
|
|
for (const child of node.children) walk(child);
|
|
};
|
|
walk(tree.rootNode as any);
|
|
expect(nodeCount).toBeGreaterThan(20);
|
|
});
|
|
|
|
it('extracts function definitions and call expressions via a query', async () => {
|
|
const Parser = (await import('tree-sitter')).default;
|
|
const parser = await loadParser();
|
|
await loadLanguage(SupportedLanguages.C);
|
|
const tree = parser.parse(C_SOURCE);
|
|
const language = parser.getLanguage();
|
|
|
|
const query = new (Parser as any).Query(
|
|
language,
|
|
'(function_definition declarator: (function_declarator declarator: (identifier) @name)) ' +
|
|
'(call_expression function: (identifier) @callee)',
|
|
);
|
|
const captures = query.captures(tree.rootNode);
|
|
const names = captures.filter((c: any) => c.name === 'name').map((c: any) => c.node.text);
|
|
const callees = captures.filter((c: any) => c.name === 'callee').map((c: any) => c.node.text);
|
|
|
|
expect(names).toEqual(expect.arrayContaining(['helper', 'add', 'main']));
|
|
expect(callees).toEqual(expect.arrayContaining(['add', 'helper']));
|
|
});
|
|
|
|
it('walks a TreeCursor without throwing (catches unmarshalNode regressions)', async () => {
|
|
const parser = await loadParser();
|
|
await loadLanguage(SupportedLanguages.C);
|
|
const tree = parser.parse(C_SOURCE);
|
|
const cursor = tree.walk();
|
|
let visited = 0;
|
|
const descend = (): void => {
|
|
visited += 1;
|
|
if (cursor.gotoFirstChild()) {
|
|
do {
|
|
descend();
|
|
} while (cursor.gotoNextSibling());
|
|
cursor.gotoParent();
|
|
}
|
|
};
|
|
descend();
|
|
expect(visited).toBeGreaterThan(20);
|
|
});
|
|
});
|
|
|
|
describe('Swift optional dependency', () => {
|
|
it('loads Swift from the default optional dependency and parses source', async () => {
|
|
const parser = await loadParser();
|
|
await loadLanguage(SupportedLanguages.Swift);
|
|
|
|
const tree = parser.parse('class Foo { func bar() {} }');
|
|
|
|
expect(tree.rootNode.type).toBe('source_file');
|
|
expect(tree.rootNode.namedChildCount).toBe(1);
|
|
});
|
|
});
|
|
});
|