Skip to content

refactor(storage): one module for the storage root and its layout (Refs #53) - #100

Merged
Jihair54 merged 2 commits into
mainfrom
refactor/53-storage-paths
Nov 26, 2026
Merged

Jihair54 merged 2 commits into
mainfrom
refactor/53-storage-paths

Conversation

@Jihair54

Copy link
Copy Markdown
Contributor

Refs #53 (SV-021). This is the behavior-preserving half: the storage layout is named in one place. Relocating the root through STORAGE_DIR is 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-rotation and release-manifest. Each one repeated the root and its own sub-layout.

Change

  • New lib/storage-paths.ts. It holds storageRoot() and storagePath(...segments), plus the layouts used more than once: artifactsDir(), artifactFile(sha256) and corpusExportDir(tenantId). It only joins: every caller still validates what it passes in (SHA-256, tenant, ring, release entry path) before calling.
  • The eight callers use it.
    • keyRotationFile and releaseArtifactFile keep their signatures and build on storagePath.
    • Four modules no longer import path.
  • Same behavior. The root is still storage/ under the working directory, read on each call rather than when the module loads. Tests that chdir into a sandbox keep working.
  • Two renames. The IOC feed route had a local artifactsDir, and loadManifestBytes had a local storagePath. Kept as they were, each would have read the helper of the same name inside its own initializer (TDZ). The first local is now storeDir; the second is gone.

Not in this PR: STORAGE_DIR

#53 proposes an env override for the root. #97 is reworking lib/env.ts and docs/configuration.md right now. I'd rather add storageDir there as an accessor, and make storageRoot() 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 new tests/unit/storage-paths.test.ts, which checks each helper against the old inline expression and that the root follows a chdir made after import.

Not run locally: npm run test:integration (no Postgres on this host). corpus-routes, content-manifest and release exercise these paths there, and CI's server job runs them against Postgres 15.

🤖 Generated with Claude Code

#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]>
@Jihair54
Jihair54 requested a review from SoFrexs November 26, 2026 10:20

@SoFrexs SoFrexs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed ac75f11.

A clean, behavior-preserving extraction. Each of the eight callers builds the same path as before:

  • artifactFile(sha) is storage/artifacts/<sha>;
  • corpusExportDir(t) is storage/corpus/<t>;
  • keyRotationFile and releaseArtifactFile keep 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.ts exports contentArtifactPath(entry) (artifacts/${sha256}) and contentManifestPath(ring, version) (manifests/content-...). lib/release-manifest.ts exports releaseManifestPath (manifests/release-...). None of them has a caller in app/, lib/, scripts/ or tests/. contentArtifactPath duplicates artifactFile relative to the root, so a later layout change would have to find both. Either delete the three (or at least contentArtifactPath), or move the manifest names into storage-paths.ts if 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-paths import sits between the path and crypto node imports. Group it with the other @/lib imports.

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]>
@Jihair54

Copy link
Copy Markdown
Contributor Author

Thanks. Both are done in ee01b36.

  • [should-fix] Dead path builders. Removed contentArtifactPath, contentManifestPath and releaseManifestPath. A grep of app/, lib/, scripts/ and tests/ finds no caller, and the docs and shell scripts do not name them either. The #804 rationale that sat on contentArtifactPath (artifacts keyed by hash, so a corrective release needs no restoration) moved to artifactFile, so the layout and its reason now live in one place.
  • [nit] Imports. @/lib/storage-paths now sits with the other @/lib imports in the artifact route and in corpus.ts.

npm run typecheck is clean, npm run lint stays at 113 warnings, and npx vitest run tests/unit passes 91 files.

🤖 Generated with Claude Code

@Jihair54
Jihair54 merged commit 0cfd55f into main Nov 26, 2026
4 checks passed
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.

2 participants