fix: handle ABI-incompatible grammars and fix 28 test failures #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all 28 test failures on the current main branch. The root cause is a combination of ABI-incompatible tree-sitter grammar bindings and stale test expectations.
Swift/Dart grammar ABI incompatibility (21 test failures)
Swift (
tree-sitter-swift0.6.0): The package fails to install on macOS arm64 (Apple Silicon) —require('tree-sitter-swift')throwsMODULE_NOT_FOUND. There is no prebuilt binary for this platform and the source build fails.loadGrammar()correctly returnednull, but 8 tests ran unconditionally.Dart (
@sengac/tree-sitter-dart1.1.6): This is the more subtle failure. The npm package installs andrequire()succeeds, but the grammar object has an incompatible ABI withtree-sitter0.22.4. Callingparser.setLanguage(dart)crashes with:This is a two-stage failure that
loadGrammar()couldn't detect:loadGrammar('dart')→ returns the grammar object (require worked) ✓getParser('dart')→ callsparser.setLanguage()→ uncaught crash ✗The grammar's internal
nodeTypeNamesByIdarray isundefined, indicating it was built against a different tree-sitter ABI version than the 0.22.4 currently installed.Source fix (
src/extraction/grammars.ts):parser.setLanguage()intry/catchinsidegetParser()so ABI-incompatible grammars degrade gracefully (returnnull+ log warning) instead of crashing the processisLanguageSupported()andgetSupportedLanguages()to callgetParser()(validates full ABI compatibility) instead ofloadGrammar()(only checks if require succeeds)Test fix (
__tests__/extraction.test.ts):describe.skipIf(!isLanguageSupported('swift'))/describe.skipIf(!isLanguageSupported('dart'))to all Swift/Dart test blocksswift/dartfrom "should list all supported languages" assertion — availability is platform-dependentSchema version mismatch (1 test failure)
foundation.test.tsexpectedversion?.versionto be1, butDatabaseConnection.initialize()now inserts version2directly (after the v2 migration was added). Fixed assertion to expect2.DB test initialization errors (4 test failures)
pr19-improvements.test.tsDB tests had two bugs:DatabaseConnection.initialize(testDir)with a directory path —better-sqlite3cannot open a directory as a database file. Fixed toDatabaseConnection.initialize(path.join(testDir, 'test.db')).db.getDatabase()which doesn't exist — the method isdb.getDb().MCP truncation test (1 test failure)
Object.create(ToolHandler.prototype)bypasses the constructor, so the class fieldMAX_OUTPUT_LENGTH = 15000is never initialized (it'sundefined). The comparisontext.length <= undefinedis alwaysfalse, causing every string — even short ones — to be truncated. Fixed by explicitly setting the property on the prototype-created handler.Test plan
npm run buildcompiles without errorsnpm test— 11 passed, 0 failed (333 passed, 21 skipped for unavailable grammars)