GitNexus/gitnexus/test/unit/scope-resolution/rust/rust-mod-scope-qualifier.test.ts
Gergő Magyar 999cc9f913
fix(deps): upgrade native tree-sitter to 0.25.1 (#3531)
* 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>
2026-10-10 13:07:59 +03:00

101 lines
3.7 KiB
TypeScript

/**
* Unit tests for the enclosing-`mod` qualifier and the module-name filter
* (#2742, hardened by the #2745 review).
*
* The integration suite proves the resolution outcomes; these pin the two
* primitives directly, including the branches a fixture cannot reach — a scoped
* target with no enclosing `mod`, and an all-anchor qualifier.
*/
import { describe, it, expect } from 'vitest';
import Parser from 'tree-sitter';
import Rust from 'tree-sitter-rust';
import {
qualifyByEnclosingModScope,
type SyntaxNode,
} from '../../../../src/core/ingestion/utils/ast-helpers.js';
import { couldNameAModule } from '../../../../src/core/ingestion/languages/rust/module-path.js';
const parser = new Parser();
parser.setLanguage(Rust);
/** First node of `type` in a post-order walk — the innermost such node. */
function findNode(root: SyntaxNode, type: string): SyntaxNode {
const stack: SyntaxNode[] = [root];
const hits: SyntaxNode[] = [];
while (stack.length > 0) {
const node = stack.pop() as SyntaxNode;
if (node.type === type) hits.push(node);
for (let i = 0; i < node.childCount; i++) {
const child = node.child(i);
if (child !== null) stack.push(child);
}
}
const deepest = hits.sort((a, b) => b.startIndex - a.startIndex)[0];
expect(deepest).toBeDefined();
return deepest;
}
function qualify(code: string, nodeType: string, rawText: string): string {
const tree = parser.parse(code);
return qualifyByEnclosingModScope(findNode(tree.rootNode, nodeType), rawText);
}
describe('qualifyByEnclosingModScope', () => {
it('leaves an item at the crate root untouched', () => {
expect(qualify('fn dispatch() {}', 'function_item', 'dispatch')).toBe('dispatch');
});
it('prefixes one enclosing mod', () => {
expect(qualify('mod inner { fn dispatch() {} }', 'function_item', 'dispatch')).toBe(
'inner.dispatch',
);
});
it('prefixes the whole chain, outermost first', () => {
expect(
qualify('mod outer { mod tools { fn dispatch() {} } }', 'function_item', 'dispatch'),
).toBe('outer.tools.dispatch');
});
// The reason the no-enclosing-mod case returns raw text rather than
// normalizing: `splitQualifiedName` rewrites `::` to `.`, which would move a
// scoped impl target's node id away from the id its owner edge emits (#1975).
it('returns a SCOPED target verbatim when there is no enclosing mod', () => {
expect(qualify('impl a::Inner { fn helper(&self) {} }', 'impl_item', 'a::Inner')).toBe(
'a::Inner',
);
});
it('is the identity for an unscoped name, mod or no mod', () => {
expect(qualify('impl Inner { fn helper(&self) {} }', 'impl_item', 'Inner')).toBe('Inner');
});
});
describe('couldNameAModule', () => {
const known = new Set(['tools', 'inner']);
it('accepts a qualifier whose head names a known module', () => {
expect(couldNameAModule(['tools'], known)).toBe(true);
});
it('rejects a type-qualified call (`Vec::new`) whose head names no module', () => {
expect(couldNameAModule(['Vec'], known)).toBe(false);
});
it('tests the first NON-anchor segment, not the anchor', () => {
expect(couldNameAModule(['crate', 'tools'], known)).toBe(true);
expect(couldNameAModule(['crate', 'Vec'], known)).toBe(false);
expect(couldNameAModule(['super', 'inner'], known)).toBe(true);
});
// `self::f()` names the caller's own module, which is always worth trying —
// there is no head segment to test against the name set.
it('accepts an all-anchor qualifier', () => {
expect(couldNameAModule(['self'], known)).toBe(true);
expect(couldNameAModule(['crate'], known)).toBe(true);
});
it('accepts the macro-expansion spelling of the crate anchor', () => {
expect(couldNameAModule(['$crate', 'tools'], known)).toBe(true);
});
});