Skip to content

feat(content-store): rename storage with filesystem and Azure layers - #86

Merged
allisonmahmood merged 2 commits into
mainfrom
feat/content-store
Aug 29, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
feat/content-store

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

`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.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:l 501-1,000 changed lines labels Aug 29, 2026

@allisonmahmood allisonmahmood left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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_DRIVER is gone (config, docs, Dockerfile, scripts, tests). Selection is still operator-visible AZURE_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 runPromise seam”: packages/db never called the store. Seam is putObject/getObject/deleteObject in apps/server/src/runtime.ts (app.ts, expiry-sweep). Right consumer.
  • Dual config: ServerConfig.storageDir still parses PATCHY_STORAGE_DIR while the filesystem layer reads it via Effect Config; tests copy it in testing.ts. Production start.ts ignores storageDir.

(b) Scope creep

  • No unused streaming API. Service is string in/out, matching app.ts / expiry-sweep. Azure still buffers readableStreamBody internally, as the old driver did.
  • InvalidObjectKey is implied by “ObjectNotFound, StoreUnavailable…” and the old filesystem path-escape check.
  • BlobContainer is the asked-for failing-layer test seam.

(c) Looks implemented, looks wrong

  • Shared ContentStore types InvalidObjectKey on every op; filesystem rejects empty/../ keys; Azure does not (../escape.html is a blob name; empty keys become StoreUnavailable). CONTEXT.md itself scopes path-escape to the filesystem layer.
  • Unused account = Config.option(...); layerBlobContainer uses Config.string("AZURE_STORAGE_ACCOUNT") (required, not the exported option). Connection string is Redacted as asked.
  • Filesystem default is still .local/drafts (rootDir, ServerConfig.storageDir, image /data/drafts). pnpm dev writes .local/dev/storage/ only because scripts/dev sets PATCHY_STORAGE_DIR. Smoke claim is true for the runner, not the package default.
  • Filesystem tests: makeTempDirectoryScoped under it.layer. Azure tests: failing BlobContainer layer, no live account. Both match the spec.
  • html-fixtures.test.ts now uses getServerConfig({}) → .local/drafts instead of the old temp-dir store. afterEach only deletes tempDir (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.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed the review in the follow-up commit:

  • BlobContainer as a Promise-shaped inline service — now its own module, packages/content-store/src/BlobContainer.ts, in the canonical order (BlobRequestFailed, the three Configs, the tag, make, layer) with Effect-typed methods that wrap the SDK in tryPromise and normalise a RestError status onto statusCode: Option<Int>. AzureContentStore.make only yields it and maps 404 → ObjectNotFound, anything else → StoreUnavailable, so the failing-layer test still exercises the mapping the issue asked for.
  • Unused account Config / second lookup — account is now the single Config.string("AZURE_STORAGE_ACCOUNT") and is yielded on the managed-identity branch; nothing reads the key twice.
  • Azure never failing InvalidObjectKey — one shared ContentStore.checkKey (empty or NUL key) runs in both layers before the backend is touched; the path-escape check stays filesystem-only, as CONTEXT.md scopes it. Covered in the Azure test.
  • html-fixtures.test.ts writing to .local/drafts — the config now points PATCHY_STORAGE_DIR at the test's temp dir.
  • Identity store middle-man in the package tests — replaced with yield* ContentStore.ContentStore.

Not changed, with reasons:

  • Selection still operator-visible via AZURE_STORAGE_CONTAINER — that is what feat(content-store): rename storage with filesystem and Azure layers #75 specifies ("apps/server provides the Azure layer when its config is present, the filesystem layer otherwise"); the deployment has to say which container somewhere, and the driver enum is gone.
  • ServerConfig.storageDir duplicating the Effect Config — production reads only the Effect Config; the ServerConfig copy exists to feed the test runtime's ConfigProvider, same interim as the auth keys, and goes with packages/config.
  • Filesystem default .local/drafts — unchanged from before; the dev runner sets PATCHY_STORAGE_DIR explicitly, as it did.
  • StoreUnavailable.operation — the review itself classed this as allowed.

pnpm lint, typecheck, format:check and test (456) are green locally; CI was green on the previous commit. Ready to merge once CI finishes on this one (base is #85).

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.
@allisonmahmood
allisonmahmood merged commit f8bed11 into main Aug 29, 2026
7 checks passed
@allisonmahmood
allisonmahmood deleted the feat/content-store branch August 29, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(content-store): rename storage with filesystem and Azure layers

1 participant