DashboardcraftCraft src/index.ts has top-level side e…

Craft src/index.ts has top-level side effect — never import it in tests

Category: gotcha
Confidence: 0.85
ID: 019f8985-3aa7-7638-b114-dcab725c307c
Project ID: e16af391-c497-4837-b681-c849a5514499
Cross-project: No
Recalled in other projects: 1
Source session: 0goKXKlJTHOVwC4wG
Created: 2026-07-22 11:10:37
Updated: 2026-07-22 11:10:37

Cross-Project Recalls

ProjectHitsLast recalled
cli 2 6d ago

Content

Trap: extracting a testable helper (e.g. --workspace flag parsing) into src/index.ts and importing it directly in a test file looks convenient. But index.ts ends with withTracing(main, {...})() executed at module load — importing it anywhere runs the actual CLI as a side effect. Fix: don't export helpers from index.ts for direct unit testing; instead verify behavior through a lower-level module (e.g. assert getConfiguration().targets resolves correctly post-setActiveWorkspace in config.test.ts) or verify end-to-end via the built binary (node build.mjs then run dist/craft ...). Found during getsentry/craft PR #848 (feat/workspaces-schema) review.

Move to: