From 7b21505668664ac60b44170f97123a75155f0358 Mon Sep 17 00:00:00 2001 From: lab 1207 Date: Sun, 6 Sep 2026 12:33:07 +0530 Subject: [PATCH 1/2] Add missing test/setup-scm-loader.ts preload for .scm imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cli/bunfig.toml lists test/setup-scm-loader.ts among its preloads, but the file was never exported to the public mirror. Any test reaching the SDK barrel (which re-exports code-map, which imports .scm tree-sitter query files) threw "Unknown file type" at import time, which bun surfaces as an unhandled error between tests — a fresh clone showed a wall of dead test files with no obvious cause. The plugin registers a bun loader that imports .scm files as a default-exported string, matching what the bundled build does. Verified against the CLI suite: 1,576 pass, with only the pre-existing Windows-path failures in export-conversation.test.ts remaining (unrelated). 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- test/setup-scm-loader.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/setup-scm-loader.ts 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, + })) + }, +}) From 9317d5c6227d2cdc74784105bb365be7f8b41a4a Mon Sep 17 00:00:00 2001 From: lab 1207 Date: Sun, 6 Sep 2026 22:29:13 +0530 Subject: [PATCH 2/2] Add a regression test for the .scm preload loader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per review on #1286: nothing asserted the loader behavior itself. This imports the go tree-sitter query .scm directly and asserts it arrives as a non-empty string with capture syntax intact. Without the preload the file fails to load at all (verified: running it without the cli/bunfig preload fails), so a future refactor cannot silently regress the loader. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- cli/src/__tests__/scm-loader.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cli/src/__tests__/scm-loader.test.ts 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('@') + }) +})