Repository navigation
refactor(storage): one module for the storage root and its layout (Refs #53) - #100
Conversation
#53) Eight callers built `path.join(process.cwd(), "storage", ...)` inline. lib/storage-paths.ts now names the root (storageRoot, storagePath) and the layouts used more than once (artifactsDir, artifactFile, corpusExportDir). keyRotationFile and releaseArtifactFile keep their signatures and build on storagePath. Behaviour is unchanged: the root is still storage/ under the working directory, read on each call, so tests that chdir into a sandbox keep working. Two callers had a local variable named like the new helper (artifactsDir in the IOC feed route, storagePath in loadManifestBytes); they are renamed, since the helper would otherwise be read inside its own initializer. Relocating the root (STORAGE_DIR, as #53 proposes) is left for a follow-up through lib/env.ts once #97 lands, to avoid two PRs editing the same accessors. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jihair54 <[email protected]>
SoFrexs
left a comment
There was a problem hiding this comment.
Reviewed ac75f11.
A clean, behavior-preserving extraction. Each of the eight callers builds the same path as before:
artifactFile(sha)isstorage/artifacts/<sha>;corpusExportDir(t)isstorage/corpus/<t>;keyRotationFileandreleaseArtifactFilekeep their signatures.
The traversal guard in loadManifestBytes still runs before storagePath(relativePath). Reading cwd on each call keeps the chdir sandboxes working, and the test pins that. The two TDZ renames are well spotted. A grep of app/ and lib/ on this head finds no other inline path.join(process.cwd(), "storage", ...). Leaving STORAGE_DIR to a follow-up after #97 is sensible.
- [should-fix] The layout is still named in a second place, as dead code.
lib/content-manifest.tsexportscontentArtifactPath(entry)(artifacts/${sha256}) andcontentManifestPath(ring, version)(manifests/content-...).lib/release-manifest.tsexportsreleaseManifestPath(manifests/release-...). None of them has a caller inapp/,lib/,scripts/ortests/.contentArtifactPathduplicatesartifactFilerelative to the root, so a later layout change would have to find both. Either delete the three (or at leastcontentArtifactPath), or move the manifest names intostorage-paths.tsif they are meant to stay. Touching the layout is the moment to pay this down; otherwise, open an issue for it. - [nit] In the artifact route and in
corpus.ts, the new@/lib/storage-pathsimport sits between thepathandcryptonode imports. Group it with the other@/libimports.
CI is green: server, both unit-cross-os and dco.
🤖 Generated with Claude Code
…mports Review of #100: contentArtifactPath, contentManifestPath and releaseManifestPath had no caller in app/, lib/, scripts/ or tests/, and contentArtifactPath named the artifact layout a second time. They are removed; the #804 rationale that sat on contentArtifactPath moves to artifactFile. The storage-paths import joins the other @/lib imports in the artifact route and corpus.ts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jihair54 <[email protected]>
|
Thanks. Both are done in
🤖 Generated with Claude Code |
Refs #53 (SV-021). This is the behavior-preserving half: the storage layout is named in one place. Relocating the root through
STORAGE_DIRis a follow-up, see below.Why
Eight callers built
path.join(process.cwd(), "storage", …)inline: the artifact route, the IOC feed route,content-manifest,content-publish,content-retention,corpus,key-rotationandrelease-manifest. Each one repeated the root and its own sub-layout.Change
lib/storage-paths.ts. It holdsstorageRoot()andstoragePath(...segments), plus the layouts used more than once:artifactsDir(),artifactFile(sha256)andcorpusExportDir(tenantId). It only joins: every caller still validates what it passes in (SHA-256, tenant, ring, release entry path) before calling.keyRotationFileandreleaseArtifactFilekeep their signatures and build onstoragePath.path.storage/under the working directory, read on each call rather than when the module loads. Tests thatchdirinto a sandbox keep working.artifactsDir, andloadManifestByteshad a localstoragePath. Kept as they were, each would have read the helper of the same name inside its own initializer (TDZ). The first local is nowstoreDir; the second is gone.Not in this PR:
STORAGE_DIR#53 proposes an env override for the root. #97 is reworking
lib/env.tsanddocs/configuration.mdright now. I'd rather addstorageDirthere as an accessor, and makestorageRoot()read it, once #97 lands. That way two PRs don't edit the same accessors. With this PR in place, that follow-up is a one-function change.Tested
Windows host, Node 24.20:
npm run typecheck: clean.npm run lint: 113 warnings, at the cap. None comes from the changed lines.npx vitest run tests/unit: 91 files passed. That includes the newtests/unit/storage-paths.test.ts, which checks each helper against the old inline expression and that the root follows achdirmade after import.Not run locally:
npm run test:integration(no Postgres on this host).corpus-routes,content-manifestandreleaseexercise these paths there, and CI'sserverjob runs them against Postgres 15.🤖 Generated with Claude Code