Repository navigation
feat(content-store): rename storage with filesystem and Azure layers - #86
Conversation
allisonmahmood
left a comment
There was a problem hiding this comment.
Two-axis review of this PR against #75 (feat/auth-package...HEAD, 9a72298). Six read-only agents: Standards, Spec, Effect conventions, method, YAGNI, and the Fastify runtime seam.
Standards
Hard
packages/content-store/src/AzureContentStore.ts:26-33,65-108 — BlobContainer is a second Context.Service in the Azure module, Promise-shaped, built inline in Layer.effect with no make. .agents/skills/effect-service-conventions/SKILL.md / AGENTS.md: one file per service (errors, tag, make, layer). Sibling adapter is packages/analytics/src/PostHogClient.ts (own module, Effect methods, SDK in make). Expected: extract an Effect adapter (SDK, tryPromise, RestError mapping in make/layer); AzureContentStore.make only yield*s it. Do not make DefaultAzureCredential / BlobServiceClient their own services.
export const account = Config.option(Config.string("AZURE_STORAGE_ACCOUNT"));Never yielded. The live path re-reads a different Config:
const service = Option.isSome(secret)
? BlobServiceClient.fromConnectionString(Redacted.value(secret.value))
: new BlobServiceClient(
`https://${yield* Config.string("AZURE_STORAGE_ACCOUNT")}.blob.core.windows.net`,
new DefaultAzureCredential()
);Skill: one Effect Config per key. Expected: yield* account on the identity branch, or drop the export.
AzureContentStore.ts:38-62 vs ContentStore.ts:48-58 and FilesystemContentStore.ts:25-34 — Azure never fails InvalidObjectKey. The shared ContentStore["Service"] channel and packages/content-store/CONTEXT.md name that as a store failure (“the key names nothing”). Empty/\0 keys become StoreUnavailable in prod. Expected: shared key check in both layers. Path-escape (../) may stay filesystem-only (CONTEXT.md).
Not a violation: StoreUnavailable.operation — multi-value discriminator with a generic message; same shape as PostHogError; diagnostic-only (callers do not branch on it). Skill explicitly allows this.
Judgement
Middle Man — identity yield in both package tests:
const store = Effect.flatMap(ContentStore.ContentStore, Effect.succeed);Use yield* ContentStore.ContentStore.
Duplicated Code / dual parsers — ServerConfig.storageDir still trims/""→.local/drafts (packages/config/src/index.ts); FilesystemContentStore.rootDir is Effect Config (raw). testing.ts copies one into the other. Pre-port seam; parsers can drift. Not a second production reader (start.ts uses Effect Config only).
Spec
Intent. “Storage” is reserved for a later per-patch file primitive: package renamed, CONTEXT.md avoids “storage.” Which store runs is meant to be the platform’s call; PATCHY_STORAGE_DRIVER is gone and start.ts picks Azure iff AZURE_STORAGE_CONTAINER is set. Self-hosters still flip that by setting the container; docs/SELF_HOSTING.md still documents two backends as options.
(a) Missing / partial
- “layers chosen by wiring, not by an operator's env var” / “spec self-hosting removal (operator driver choice)”:
PATCHY_STORAGE_DRIVERis gone (config, docs, Dockerfile, scripts, tests). Selection is still operator-visibleAZURE_STORAGE_CONTAINER. Matches “Azure when its config is present”; checklist-complete, intent-partial. - “packages/db's upload contract keeps calling the store through a thin
runPromiseseam”:packages/dbnever called the store. Seam isputObject/getObject/deleteObjectinapps/server/src/runtime.ts(app.ts, expiry-sweep). Right consumer. - Dual config:
ServerConfig.storageDirstill parsesPATCHY_STORAGE_DIRwhile the filesystem layer reads it via EffectConfig; tests copy it intesting.ts. Productionstart.tsignoresstorageDir.
(b) Scope creep
- No unused streaming API. Service is
stringin/out, matchingapp.ts/ expiry-sweep. Azure still buffersreadableStreamBodyinternally, as the old driver did. InvalidObjectKeyis implied by “ObjectNotFound,StoreUnavailable…” and the old filesystem path-escape check.BlobContaineris the asked-for failing-layer test seam.
(c) Looks implemented, looks wrong
- Shared
ContentStoretypesInvalidObjectKeyon every op; filesystem rejects empty/../keys; Azure does not (../escape.htmlis a blob name; empty keys becomeStoreUnavailable). CONTEXT.md itself scopes path-escape to the filesystem layer. - Unused
account = Config.option(...);layerBlobContainerusesConfig.string("AZURE_STORAGE_ACCOUNT")(required, not the exported option). Connection string isRedactedas asked. - Filesystem default is still
.local/drafts(rootDir,ServerConfig.storageDir, image/data/drafts).pnpm devwrites.local/dev/storage/only becausescripts/devsetsPATCHY_STORAGE_DIR. Smoke claim is true for the runner, not the package default. - Filesystem tests:
makeTempDirectoryScopedunderit.layer. Azure tests: failingBlobContainerlayer, no live account. Both match the spec. html-fixtures.test.tsnow usesgetServerConfig({})→.local/draftsinstead of the old temp-dir store.afterEachonly deletestempDir(the JSON db). Accepted fixtures now land in the worktree’s.local/drafts.
Method
Verdict: right with caveats. This is the port map’s intended split: one ContentStore tag, two implementation modules with plain make/layer, wiring chooses the layer. A rename-only of the Promise classes would have missed the ticket.
Driver selection in start.ts (Layer.unwrap on Config.option(AzureContentStore.container), then Layer.orDie) is the right switch: presence of the Azure config, not a leftover driver enum. Incomplete Azure dies at runtime.context(), same fail-at-startup policy as analytics.
The three runPromise adapters (putObject / getObject / deleteObject) sit next to consume / authenticate / track and are the right interim until the patches port. Fault injection is the prescribed method: controlledContentStore wraps FilesystemContentStore.layer instead of subclassing; Azure tests provide a failing BlobContainer layer.
Caveat: BlobContainer methods return Promise, then make re-wraps with Effect.tryPromise. PostHogClient wraps the SDK in Effect. If the adapter stays, Effect-typed methods would match the sibling. Config ownership (each layer’s Config slice, ServerConfig.storageDir only for the test ConfigProvider) is the right pre-port interim.
YAGNI
Keep. Factory, PATCHY_STORAGE_DRIVER, HtmlStorage / StorageOptions, Promise classes, putHtmlObject names — gone. One ContentStore with string put/get/delete; spec allowed streaming, they didn’t. Tagged errors with cause. Filesystem is FileSystem + a scoped temp dir. controlledContentStore wraps ContentStore itself.
Cut. Dead account export — zero references; the layer already does yield* Config.string("AZURE_STORAGE_ACCOUNT") on the identity path. Identity store in both package tests (Effect.flatMap(ContentStore.ContentStore, Effect.succeed)) is yield* ContentStore.ContentStore.
Judgement. BlobContainer as a public Context.Service is the one place the Azure side grew past the spec. The spec asked for “error mapping tested by an alternate failing layer.” PostHogClient earns a second service (reshape, never-fail track, shutdown finalizer). This mapping is RestError 404 → ObjectNotFound. A test-only make(blobs) argument, or a five-line mapper, would have been smaller; keeping the seam and Effect-typing it is the other honest shape. StoreUnavailable.operation is unused by callers (only the Azure test asserts it); PostHogError has the same diagnostic field, so it can stay.
The store itself is the smallest model. The dead account export and the fixture test writing outside tempDir are the cuts that would make it look that way.
Standards: 3 hard, 2 judgement. Worst: unused Azure account Config plus the Promise-shaped BlobContainer adapter.
Spec: 3 partial, 0 creep, 2 wrong. Worst: html-fixtures.test.ts writing accepted uploads to .local/drafts instead of the temp dir the old FileSystemHtmlStorage used.
Reviewed by Grok 4.6.
|
Addressed the review in the follow-up commit:
Not changed, with reasons:
|
c467098 to
4593d55
Compare
The object store for a patch's bytes was packages/storage, a pair of Promise classes picked by PATCHY_STORAGE_DRIVER. "Storage" is reserved for the later per-patch file primitive, and the driver was an operator choice the platform should make itself. packages/content-store owns one ContentStore service (put, get, delete by key) with typed failures (InvalidObjectKey, ObjectNotFound, StoreUnavailable with the driver error as cause) and two layers: the filesystem for dev and tests, Azure Blob for production, each reading its own Config slice. apps/server picks the Azure layer when AZURE_STORAGE_CONTAINER is set and the filesystem otherwise; the app and the expiry sweep reach the store through the runtime seam until the patches port. PATCHY_STORAGE_DRIVER is gone, and the package's language-service diagnostics are errors. Closes #75
BlobContainer is its own Effect-typed service module (errors, tag, make, layer) that wraps the SDK and normalises RestError statuses; the Azure store maps those onto ObjectNotFound and StoreUnavailable. The account Config is read on the managed-identity branch instead of a second lookup. Both layers refuse an empty or NUL key as InvalidObjectKey through one shared check. The fixture test points the store at its temp dir, and the package tests yield the service directly.
8457bbb to
63a902d
Compare
`packages/storage` was the object store for a patch's bytes: two Promise classes picked by an operator's `PATCHY_STORAGE_DRIVER`. "Storage" is reserved for the later per-patch file primitive, and which store runs is the platform's call, not a setting.
It is now `packages/content-store`: one `ContentStore` service (`put`, `get`, `delete` by object key) with typed failures — `InvalidObjectKey`, `ObjectNotFound`, `StoreUnavailable` carrying the driver error as `cause` — and two layers, filesystem for `pnpm dev` and tests and Azure Blob for production, each on its own `Config` slice with the connection string `Redacted`. `apps/server/src/start.ts` wires the Azure layer when `AZURE_STORAGE_CONTAINER` is set and the filesystem layer otherwise; the upload contract and the expiry sweep reach the store through the existing runtime seam until the `patches` port. Tests are on `@effect/vitest`: the filesystem layer against a scoped temp dir, the Azure error mapping through a failing `BlobContainer` layer, and the server's fault-injection tests through an alternate controlled layer instead of a subclass. `PATCHY_STORAGE_DRIVER` is deleted, `@patchy/storage` no longer exists, and the package's language-service diagnostics are errors.
Smoked under `pnpm dev`: an upload lands under `.local/dev/storage/`.
Stacked on #85.
Closes #75
Built by Claude Fable 5 via Claude Code.