GitNexus/gitnexus/test/integration/query-compilation.test.ts
Gergő Magyar 7376e92063
fix: consolidate C/C++/C#/Rust language support from 6 overlapping PRs (#237)
* fix: consolidate C/C++/C#/Rust language support from 6 overlapping PRs

Merges fixes from PRs #163, #170, #178, #216, #227, #234 into a single
coherent changeset with shared modules and deduplication.

Phase 0 — Pre-merge consolidation:
- Extract isNodeExported to shared export-detection.ts module
- Extract TREE_SITTER_BUFFER_SIZE to shared constants.ts with adaptive sizing
- Consolidate FUNCTION_NODE_TYPES, extractFunctionName, isBuiltInOrNoise
  from duplicated call-processor.ts and parse-worker.ts into shared utils.ts
- Add query compilation smoke tests for all 12 languages

Language fixes:
- fix(c/cpp): isExported checks static linkage instead of returning false
- fix(c/cpp): .h files parsed as C++ (tree-sitter-cpp is superset of C)
- fix(c/cpp): expanded entry point patterns (~30 new for C, ~18 for C++)
- fix(cpp): add typedef, union, macro, prototype, inline method queries
- fix(c#): isExported scans sibling modifiers instead of parent walk
- fix(c#): heritage queries use correct base_list AST structure
- fix(c#): add framework detection, import resolution, entry point scoring
- fix(rust): isExported scans sibling visibility_modifier in declaration
- fix(builtins): remove open/read/write/close (real C POSIX syscalls)
- fix(buffer): adaptive bufferSize (2x fileSize, 512KB-32MB range)
- feat(ts/js): add call_expression query patterns for const assignments

Deduplication:
- call-processor.ts: -226 lines (uses shared utils)
- parse-worker.ts: -320 lines (uses shared utils)
- parsing-processor.ts: -156 lines (uses shared export-detection)

* perf: fix review findings — hoist Sets, deduplicate DEFINITION_CAPTURE_KEYS

- Hoist CSHARP_DECL_TYPES and RUST_DECL_TYPES to module-level constants
  in export-detection.ts (was allocating new Set on every isNodeExported call)
- Extract DEFINITION_CAPTURE_KEYS and getDefinitionNodeFromCaptures to
  shared utils.ts (was duplicated in parsing-processor.ts and parse-worker.ts)
- Pre-compute merged entry point patterns to avoid per-call array spread
  in calculateEntryPointScore

* test: add C, C++, and Tree-sitter buffer size tests

* fix: C/C++/Rust review findings + comprehensive test coverage (+72 tests)

Source fixes:
- Add Rust built-in noise (unwrap, clone, into, collect, panic, etc.)
- C++ anonymous namespace → internal linkage (not exported)
- Replace .text regex with storage_class_specifier child scan (perf)
- Raise file skip threshold from 512KB to 32MB (TREE_SITTER_MAX_BUFFER)
- Export TREE_SITTER_MAX_BUFFER from constants.ts
- Add C++ double pointer query patterns to CPP_QUERIES
- Add C#: record_struct, record_class, file_scoped_namespace to decl types
- Add Rust: union_item to visibility scanning set

Tests (214 → 286):
- ingestion-utils: +24 (Rust/C# noise, pointer/ref/destructor extraction, buffer)
- parsing: +36 (real AST C/C++ static/namespace, Rust/C#/Java/PHP/Swift edge cases)
- tree-sitter-languages: +12 (query accuracy for C/C++/C#/Rust captures)
2026-03-10 23:03:32 +00:00

61 lines
2.4 KiB
TypeScript

import { describe, it, expect, beforeAll } from 'vitest';
import { loadParser, loadLanguage, isLanguageAvailable } from '../../src/core/tree-sitter/parser-loader.js';
import { LANGUAGE_QUERIES } from '../../src/core/ingestion/tree-sitter-queries.js';
import { SupportedLanguages } from '../../src/config/supported-languages.js';
import Parser from 'tree-sitter';
/**
* Smoke test: verify that every LANGUAGE_QUERIES entry compiles against
* its tree-sitter grammar without throwing. A silent Query compilation
* failure is the #1 cause of "0 nodes extracted for language X" bugs.
*/
describe('Query compilation smoke tests', () => {
let parser: Parser;
beforeAll(async () => {
parser = await loadParser();
});
const languageFiles: Record<string, string> = {
[SupportedLanguages.TypeScript]: 'test.ts',
[SupportedLanguages.JavaScript]: 'test.js',
[SupportedLanguages.Python]: 'test.py',
[SupportedLanguages.Java]: 'Test.java',
[SupportedLanguages.C]: 'test.c',
[SupportedLanguages.CPlusPlus]: 'test.cpp',
[SupportedLanguages.CSharp]: 'Test.cs',
[SupportedLanguages.Go]: 'test.go',
[SupportedLanguages.Rust]: 'test.rs',
[SupportedLanguages.PHP]: 'test.php',
[SupportedLanguages.Kotlin]: 'Test.kt',
[SupportedLanguages.Swift]: 'test.swift',
};
// Known query compilation failures — remove from this set as PRs fix them
const knownFailures = new Set<string>([]);
for (const [lang, filename] of Object.entries(languageFiles)) {
const testFn = knownFailures.has(lang) ? it.fails : it;
testFn(`compiles query for ${lang}`, async () => {
if (!isLanguageAvailable(lang as SupportedLanguages)) {
return; // parser binary not available in this environment
}
await loadLanguage(lang as SupportedLanguages, filename);
const queryStr = LANGUAGE_QUERIES[lang as SupportedLanguages];
expect(queryStr).toBeTruthy();
const grammar = parser.getLanguage();
// This is the line that silently fails in production when queries
// use node types that don't exist in the grammar.
const query = new Parser.Query(grammar, queryStr);
expect(query).toBeDefined();
// Verify it can actually run against a minimal tree
const tree = parser.parse('');
const matches = query.matches(tree.rootNode);
expect(Array.isArray(matches)).toBe(true);
});
}
});