Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cli/src/__tests__/scm-loader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, test } from 'bun:test'

import goQuery from '../../../packages/code-map/src/tree-sitter-queries/tree-sitter-go-tags.scm'

/**
* Guards test/setup-scm-loader.ts (registered as a preload in
* cli/bunfig.toml). Without it, importing any module that reaches
* @codebuff/sdk — which re-exports code-map, which imports .scm
* tree-sitter query files — dies at import time with "Unknown file type",
* which bun reports as an unhandled error between tests rather than a
* failure (see docs/testing.md). This file imports a .scm directly: if the
* preload is missing or regresses, the whole file fails to load instead of
* passing vacuously.
*/
describe('setup-scm-loader preload', () => {
test('loads .scm imports as strings', () => {
expect(typeof goQuery).toBe('string')
expect(goQuery.length).toBeGreaterThan(0)
// Tree-sitter queries capture nodes with @capture names; the go tags
// query is nontrivial, so this also proves the content came through
// intact rather than as an empty stub.
expect(goQuery).toContain('@')
})
})
29 changes: 29 additions & 0 deletions test/setup-scm-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Bun preload: teach bun to import .scm (tree-sitter query) files as text.
*
* packages/code-map/src/languages.ts imports .scm files directly, and the SDK
* barrel re-exports code-map — so any test importing @codebuff/sdk (or the CLI
* modules that reach it) needs this registered before those imports evaluate.
*
* cli/bunfig.toml lists this preload, but the file itself was not present in
* the public mirror, so sdk-touching tests died at import time ("Unknown file
* type" for the first .scm import), which bun reports as an unhandled error
* between tests rather than a test failure (see docs/testing.md).
*
* The bundled build handles .scm imports the same way: loader 'text', default
* export is the file's contents as a string.
*/
import { plugin } from 'bun'
import { readFileSync } from 'fs'

plugin({
name: 'scm-text-loader',
setup(build) {
build.onLoad({ filter: /\.scm$/ }, (args) => ({
// Wrap in a JS module: bun's plugin API only accepts code loaders
// (js/json/...), and the import sites expect a default-exported string.
contents: `export default ${JSON.stringify(readFileSync(args.path, 'utf8'))}`,
loader: 'js' as const,
}))
},
})
Loading