Skip to content

Conversation

@MO2k4
Copy link
Contributor

@MO2k4 MO2k4 commented Feb 11, 2026

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-swift 0.6.0): The package fails to install on macOS arm64 (Apple Silicon) — 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 ran unconditionally.

Dart (@sengac/tree-sitter-dart 1.1.6): This is the more subtle failure. The npm package installs and require() succeeds, but the grammar object has an incompatible ABI with tree-sitter 0.22.4. Calling parser.setLanguage(dart) crashes with:

TypeError: Cannot read properties of undefined (reading 'length')
    at initializeLanguageNodeClasses (node_modules/tree-sitter/index.js:858:42)
    at Parser.setLanguage (node_modules/tree-sitter/index.js:355:5)

This is a two-stage failure that loadGrammar() couldn't detect:

  1. loadGrammar('dart') → returns the grammar object (require worked) ✓
  2. getParser('dart') → calls parser.setLanguage()uncaught crash

The grammar's internal nodeTypeNamesById array is undefined, indicating it was built against a different tree-sitter ABI version than the 0.22.4 currently installed.

Source fix (src/extraction/grammars.ts):

  • Wrap parser.setLanguage() in try/catch inside getParser() so ABI-incompatible grammars degrade gracefully (return null + log warning) instead of crashing the process
  • Change isLanguageSupported() and getSupportedLanguages() to call getParser() (validates full ABI compatibility) instead of loadGrammar() (only checks if require succeeds)

Test fix (__tests__/extraction.test.ts):

  • Add describe.skipIf(!isLanguageSupported('swift')) / describe.skipIf(!isLanguageSupported('dart')) to all Swift/Dart test blocks
  • Remove hardcoded swift/dart from "should list all supported languages" assertion — availability is platform-dependent

Schema version mismatch (1 test failure)

foundation.test.ts expected version?.version to be 1, but DatabaseConnection.initialize() now inserts version 2 directly (after the v2 migration was added). Fixed assertion to expect 2.

DB test initialization errors (4 test failures)

pr19-improvements.test.ts DB tests had two bugs:

  • Called DatabaseConnection.initialize(testDir) with a directory pathbetter-sqlite3 cannot open a directory as a database file. Fixed to DatabaseConnection.initialize(path.join(testDir, 'test.db')).
  • Called db.getDatabase() which doesn't exist — the method is db.getDb().

MCP truncation test (1 test failure)

Object.create(ToolHandler.prototype) bypasses the constructor, so the class field MAX_OUTPUT_LENGTH = 15000 is never initialized (it's undefined). The comparison text.length <= undefined is always false, causing every string — even short ones — to be truncated. Fixed by explicitly setting the property on the prototype-created handler.

Test plan

  • npm run build compiles without errors
  • npm test11 passed, 0 failed (333 passed, 21 skipped for unavailable grammars)
  • Skipped tests are only Swift (8) and Dart (13) — both have unavailable native bindings
  • All other languages (TypeScript, JavaScript, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Kotlin, Svelte, Liquid) continue to pass

…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
@MO2k4
Copy link
Contributor Author

MO2k4 commented Feb 11, 2026

Closing — these fixes are included in #35 (cherry-picked + extended with Kotlin skipIf guards and Windows path normalization).

@MO2k4 MO2k4 closed this Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant