Skip to content

cli: restore the .scm preload so cd cli && bun test starts - #1363

Open
KazenDev wants to merge 1 commit into
CodebuffAI:mainfrom
KazenDev:fix/scm-loader-preload
Open

KazenDev wants to merge 1 commit into
CodebuffAI:mainfrom
KazenDev:fix/scm-loader-preload

Conversation

@KazenDev

Copy link
Copy Markdown

cli/bunfig.toml preloads ../test/setup-scm-loader.ts, and that file is not in this repo (git ls-files test/ is empty). bun stops on the first preload it cannot resolve, so the command the docs give for this package never starts:

$ cd cli && bun test src/utils/time-format.test.ts
bun test v1.3.14 (0d9b296a)

src/utils/time-format.test.ts:
error: preload not found "../test/setup-scm-loader.ts"

docs/testing.md passes the same path to --preload in its leak-reproduction example, so a reader copying that line hits it too. This PR adds the loader the two references already expect.

What the loader does

Bun resolves an import of an extension it does not know to the file's path. packages/code-map/src/languages.ts already reads that path back off disk when it is absolute — the code comment there says as much — which is why the CLI works without this file. But the query then only arrives as text in the one case where the path happens to be absolute and readable, and a bundler that inlines the import has no file to read at all.

bun 1.3.14 has no loader: 'text', so the emitted module is export default followed by the JSON-escaped text. Measured, importing one of the real query files:

import q from '…/tree-sitter-c_sharp-tags.scm' value
with the preload (class_declaration\n name: (identifier) @identifier\n… — the text
without it /home/…/packages/code-map/src/tree-sitter-queries/… — an absolute path

Before / after

cd cli && bun test tests run pass fail errors
main 0error: preload not found
this PR 3165 3133 20 18

The 4 extra tests are the new file's. The failure set is unchanged: the same file list run from the repo root, which is the only invocation that started before this change, reports the same 20 failures and the same 18 errors (diff of the failure names is empty).

Worth saying where those come from, since they are now visible in the documented command:

  • 18 errorsFailed to load CLI environment via packages/internal/src/env. That package is out of this mirror's scope.
  • 3 named failures — the release wrapper tests require('tar'), which is not installed.
  • The remaining counted failures come from files that error before their first assertion, for the same two reasons.

Not in this PR, on purpose

cli/package.json runs the suite as NODE_ENV=production bun test …. With that variable set, react/jsx-dev-runtime resolves to React's production stub, and all 54 tests in freebuff-model-selector.test.tsx fail at jsxDEV is not a function. Unsetting it brings every one of them back. That is a question about the script's environment, not about this preload, so it is left as it is here and reported rather than bundled in.

Verification

  • cli/src/__tests__/scm-loader.test.ts: 4 tests, 0 fail. They import what the loader emits from a temp file, so the escaping is covered by a real module load rather than by string comparison.
  • The loader is a preload, so its test lives with the package that preloads it.
  • Prettier clean. tsc --noEmit reports 10 errors, the same count as on main, none of them in the files added here.

cli/bunfig.toml lists ../test/setup-scm-loader.ts as a preload and the repo
does not contain it, so bun aborts on the first unresolvable preload and no
test in the package runs. Add the loader both that config and
docs/testing.md already reference, so a .scm query arrives as its text
instead of a path.
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