fix(shared): resolve data-dir paths per call instead of capturing at import - #1490
Conversation
|
Deep review done. The sweep itself is solid: all four #1477 modules fully converted with no surviving derived-path constants, no consumer relied on freezing, vendoring clean, and per-module revert-verification confirms every module has a test that fails if it regresses (11/11 restored). Honest scoping too - browser.ts called out rather than smuggled. One fix needed before merge: the const materializedSchemaPaths = new Set<string>();
async function ensureSchemaFile(): Promise<string> {
const schemaPath = getCodexReviewSchemaPath();
if (!materializedSchemaPaths.has(schemaPath)) {
await mkdir(dirname(schemaPath), { recursive: true });
await writeFile(schemaPath, CODEX_REVIEW_SCHEMA);
materializedSchemaPaths.add(schemaPath);
}
return schemaPath;
}Same shape in all three modules (using We'll file the follow-up for the one remaining frozen capture ( |
|
Pushed Added the requested regression assertion in |
Problem
Four modules evaluate
getPlannotatorDataDir()at module scope and freeze every path derived from it, so they answer to whateverPLANNOTATOR_DATA_DIRwas when the module first loaded — the same import-time capturestorage.tshad until #1437/#1473, with the same consequences: 38 test files set the variable at runtime and Bun's test-file order is filesystem-dependent, so the captured value varies as test files are added.packages/shared/improvement-hooks.ts—DATA_DIR,HOOKS_BASE_DIR,LEGACY_BASE_DIRpackages/server/codex-review.ts—DATA_DIR,DEBUG_LOG_PATH,SCHEMA_DIR,SCHEMA_FILEpackages/server/tour/tour-review.ts—TOUR_SCHEMA_DIR,TOUR_SCHEMA_FILEpackages/server/guide/guide-review.ts—GUIDE_SCHEMA_DIR,GUIDE_SCHEMA_FILEChange
All of these now resolve per call. The
*SchemaMaterializedbooleans became per-path existence checks, so a data-dir switch after import materializes the schema in the new location instead of returning the old path forever.CODEX_REVIEW_SCHEMA_PATH(a re-export of the frozen string; no in-repo consumers) is replaced bygetCodexReviewSchemaPath().Verification
Bun 1.3.14, disposable HOME + temp
PLANNOTATOR_DATA_DIR:storage.test.ts:improvement-hooks.test.tsis rewritten in-process (the subprocess/fake-HOME workaround is no longer needed) andcodex-command-builders.test.tscovers all three schema modules, including re-materialization after a mid-test dir switch.88 pass / 0 failacross the 8 touched-area test files.apps/pi-extension/vendor.sh) and smoke-imported with the env set after import — the generated copies follow the new data dir (they are gitignored build output, so there is nothing to commit).Deliberately out of scope:
packages/server/browser.ts(IPC_REGISTRY) keeps its module-scope capture — same pattern, separate surface.Fixes #1477