You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every test file in @codeassembly/kb re-rolls its own copies of trivial filesystem and KB-scaffolding test helpers: temp-directory creation, path-existence checks, and KB-root / store / registry-path builders. Several are verbatim duplicates (for example makeTempDir, a local exists wrapper, and makeRegistryPath); others are near-verbatim variants of the same idea. There is no shared test-support home, so each new test file re-rolls these helpers.
Context
The duplication is uniform across the package: both pre-existing tests and the tests added in Add a kb create command to provision new KB stores #720 follow this per-file pattern, so it reads as an established convention rather than a one-off oversight.
Tests run directly from TypeScript source through Vitest with no build step, and already import sibling .ts modules with honest .ts specifiers. A shared helper is imported the same way; there is no compile barrier for tests.
The only build consideration is keeping the shared module out of the published dist. nmr compile (the shared config/build.ts) emits every src/**/*.ts file except those matched by its ignore globs, and it is glob-driven rather than tsconfig-driven, so a per-package tsconfig exclude cannot affect it. The chosen mechanism is to add a test-utils directory name to the shared build's ignore list.
The project keeps test files as per-directory __tests__/ siblings of the modules they test and avoids a rolled-up src/__tests__/. A package-wide shared module therefore gets its own purpose-named home rather than nesting in the package-root test directory.
Scope is the kb package only for the consolidation itself. The single shared-config touch (the test-utils ignore entry) is additive and inert for packages that have no such directory.
Proposed solution
Introduce one kb-local test-support module under a new src/test-utils/ directory, and exclude that directory from the published build by adding it to the shared build's ignore globs. Migrate the kb test files to import the genuinely shared primitives (temp-directory creation and the KB-root / store / registry builders) from this module, consolidating each to a single copy. Replace the re-rolled local exists wrappers with the existing production pathExists / directoryExists from the filesystem module rather than duplicating them at all. Leave per-test setup that genuinely varies inside the individual tests.
The new module should itself model the repo's code conventions, since it is a module of helper functions: functions in case-insensitive alphabetical order absent a more compelling ordering, any internal helpers at the end, and a concise description on every exported function.
Acceptance criteria
Must have
A single kb-local test-support module under src/test-utils/ provides the shared filesystem and KB-root / store / registry test helpers.
The module is excluded from the published build (dist) by adding test-utils to the shared build's ignore globs; no tsconfig plumbing or per-package build workaround is introduced.
kb test files import the shared helpers instead of redefining them; genuinely per-test setup stays local to each test.
Re-rolled local exists wrappers are replaced by the production pathExists / directoryExists rather than moved into the shared module.
No rolled-up src/__tests__/ is introduced.
The shared module follows the repo code conventions: functions alphabetized absent a more compelling order, helpers at the end, and a concise description on every function.
Problem
Every test file in
@codeassembly/kbre-rolls its own copies of trivial filesystem and KB-scaffolding test helpers: temp-directory creation, path-existence checks, and KB-root / store / registry-path builders. Several are verbatim duplicates (for examplemakeTempDir, a localexistswrapper, andmakeRegistryPath); others are near-verbatim variants of the same idea. There is no shared test-support home, so each new test file re-rolls these helpers.Context
.tsmodules with honest.tsspecifiers. A shared helper is imported the same way; there is no compile barrier for tests.dist.nmr compile(the sharedconfig/build.ts) emits everysrc/**/*.tsfile except those matched by itsignoreglobs, and it is glob-driven rather than tsconfig-driven, so a per-packagetsconfigexclude cannot affect it. The chosen mechanism is to add atest-utilsdirectory name to the shared build'signorelist.__tests__/siblings of the modules they test and avoids a rolled-upsrc/__tests__/. A package-wide shared module therefore gets its own purpose-named home rather than nesting in the package-root test directory.test-utilsignore entry) is additive and inert for packages that have no such directory.Proposed solution
Introduce one kb-local test-support module under a new
src/test-utils/directory, and exclude that directory from the published build by adding it to the shared build'signoreglobs. Migrate the kb test files to import the genuinely shared primitives (temp-directory creation and the KB-root / store / registry builders) from this module, consolidating each to a single copy. Replace the re-rolled localexistswrappers with the existing productionpathExists/directoryExistsfrom the filesystem module rather than duplicating them at all. Leave per-test setup that genuinely varies inside the individual tests.The new module should itself model the repo's code conventions, since it is a module of helper functions: functions in case-insensitive alphabetical order absent a more compelling ordering, any internal helpers at the end, and a concise description on every exported function.
Acceptance criteria
Must have
src/test-utils/provides the shared filesystem and KB-root / store / registry test helpers.dist) by addingtest-utilsto the shared build'signoreglobs; notsconfigplumbing or per-package build workaround is introduced.existswrappers are replaced by the productionpathExists/directoryExistsrather than moved into the shared module.src/__tests__/is introduced.Dependencies