fix: handle ABI-incompatible grammars and fix 28 test failures#30
Closed
MO2k4 wants to merge 1 commit intocolbymchenry:mainfrom
Closed
fix: handle ABI-incompatible grammars and fix 28 test failures#30MO2k4 wants to merge 1 commit intocolbymchenry:mainfrom
MO2k4 wants to merge 1 commit intocolbymchenry:mainfrom
Conversation
…e test expectations
Root cause: tree-sitter grammar native bindings for Swift and Dart are
incompatible with tree-sitter 0.22.4 on macOS arm64 (Apple Silicon,
macOS 26.2, Node.js v22.22.0).
Swift (tree-sitter-swift 0.6.0):
- The npm package fails to install entirely — `require('tree-sitter-swift')`
throws MODULE_NOT_FOUND. There is no prebuilt binary for this platform
and the source build fails. `loadGrammar()` correctly returned null,
but 8 tests still ran unconditionally and failed.
Dart (@sengac/tree-sitter-dart 1.1.6):
- The npm package installs and `require()` succeeds, but the grammar
object has an incompatible ABI with tree-sitter 0.22.4.
`parser.setLanguage(dart)` crashes with "Cannot read properties of
undefined (reading 'length')" inside tree-sitter's internal
`initializeLanguageNodeClasses` function. This is a two-stage failure:
`loadGrammar()` returned non-null (require worked), but `getParser()`
threw an uncaught exception at `setLanguage()`. The grammar was likely
built against a different tree-sitter ABI version.
Source fix (src/extraction/grammars.ts):
- Wrap `parser.setLanguage()` in try/catch inside `getParser()` so
ABI-incompatible grammars degrade gracefully instead of crashing
- Change `isLanguageSupported()` and `getSupportedLanguages()` to call
`getParser()` (validates full ABI compatibility) instead of
`loadGrammar()` (only checks if require succeeds)
Test fixes:
- Skip Swift/Dart test blocks via `describe.skipIf(!isLanguageSupported())`
so they are skipped on platforms where grammars are unavailable
- Remove hardcoded swift/dart from "supported languages" assertion since
availability is platform-dependent
- Fix schema version test: expected 1 but schema is now version 2 after
the v2 migration was added
- Fix DB tests: pass file path (path.join(testDir, 'test.db')) not bare
directory to DatabaseConnection.initialize() — better-sqlite3 cannot
open a directory as a database file
- Fix DB tests: call db.getDb() not db.getDatabase() — the latter method
does not exist on DatabaseConnection
- Fix truncation tests: manually set MAX_OUTPUT_LENGTH on Object.create'd
handler since constructor is bypassed and class field initializers
never run
Contributor
Author
|
Closing — these fixes are included in #35 (cherry-picked + extended with Kotlin skipIf guards and Windows path normalization). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)