diff --git a/cli/src/__tests__/scm-loader.test.ts b/cli/src/__tests__/scm-loader.test.ts new file mode 100644 index 0000000000..f243b323fc --- /dev/null +++ b/cli/src/__tests__/scm-loader.test.ts @@ -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('@') + }) +}) diff --git a/test/setup-scm-loader.ts b/test/setup-scm-loader.ts new file mode 100644 index 0000000000..20fa413834 --- /dev/null +++ b/test/setup-scm-loader.ts @@ -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, + })) + }, +})