Repository navigation
feat(server): serve on HttpApi and HttpRouter; delete config and db - #88
Conversation
Code review (PR 88 / #77)Two-axis review of The cut is the right one. Fastify, Standards
No UI consistency findings. No Effect service findings on the new serving/server shape: no Spec(a) Missing / partial
(b) Scope creep
(c) Implemented but wrong (vs named contract)
ADR Postgres only already landed on the patches PR ( Intent vs #77#77’s intent is the last hosting-side port: Fastify becomes a shell and should disappear; serving becomes the page capability later runtimes grow on; Honored. Fastify is gone from the lockfile. Bent, still the intent:
Would a later agent be unsurprised? Yes, if they read MethodThe cut is the smallest honest model. Serving should not own Upload staying
The wrong shape: const PATCH_POST_SUFFIXES = new Set(["disable", "pin", "unpin"]);Adding Serving does not install its own guarantees. Tests. Split the way the spec asked: YAGNIVerdict: mixed. Wiring and serving are the smallest model the spec asked for. The two long files are Fastify’s request-target classifier and a Schema-dressed CIDR parser, not new product. Keep. Cut or shrink (judgement, not “the spec still holds if you drop 414”):
Do not collapse 414 vs 404. YAGNI wants a single overlong-param 414. The ticket asked to keep the 400/404/414 matrix as observable contract. Authenticated 414-vs-404 mapping is Fastify leftover and specified. If it shrinks, shrink the implementation (one table next to the routes), not the statuses. Summary
I would merge after restoring the Reviewed by Grok 4.6 via Grok. |
|
Thanks for the review. Follow-ups landed in 68ec55b; lint, typecheck, format, the suite (220) and the packed-CLI e2e are green on it. Fixed
Left as is, on purpose
Ready to merge from my side once CI agrees. |
|
Follow-up in 551b732: |
|
CI on 551b732: |
551b732 to
3fe4e98
Compare
e1a3d42 to
c2ad92b
Compare
Fastify was a shell around the ported capability packages: a runtime seam, a hand-rolled config package and a Promise migration seam. The server now runs on Effect's HttpApi and HttpRouter, and the two pre-port packages go. packages/serving owns the serving guarantees and their headers, the page routes (home, health, the patch at its latest and version URLs, the HTML 404) reading through patches, and the trusted-proxy schema that resolves the client address (Effect's xForwardedHeaders takes the leftmost address and has no allow-list, so the rightmost-untrusted walk lives here). apps/server is wiring: one Server.layer with the services over a migrated database, HttpApiBuilder.layer(PatchyApi) with both group layers behind auth's bearer middleware, the pages, one global middleware (proxy walk, serving headers, API guard) whose order is written down, the expiry sweep forked in the scope, and start.ts launching it under NodeRuntime.runMain. The API guard keeps the observable contract for what the router never sees: every /api/* request but the mint spends one protected-API attempt and needs a token before a 400/404/414. Auth-before-body holds on every matched route through the bearer middleware; the upload handler is raw so scope and the per-token upload limit are spent before the body is read, with the wire's own refusals (413, field-specific 400s). Also: Authorization.identify is the one header-to-identity path, shared by the middleware and the guard; the 401 is answered as a response so an error union cannot encode it as a 400; readBody/decodeBody in api; the packed-CLI e2e starts its own embedded Postgres and reads its assertions from SQL; the dev runner and the vitest template migrate through sql directly; docs and labels follow the packages. Closes #77
… an error Three rules the review spec asked for, written locally under eslint/ and proved by RuleTester: namespace imports for Effect and service modules, no manual runtimes in tests, no Schema compiles inside function bodies. The language-service whole-file rules are errors repo-wide now that the server has ported; packages/cli keeps them at warning until #78, and the per-package overrides that duplicated the base list are gone.
The patches API header this PR mangled is restored. Every payload route
answers a malformed body as { ok: false, error } and treats an absent one as
{}: createToken and disable are raw like upload. MalformedBody keeps the read
or parse failure as cause; rateLimited and malformedBody live in api next to
refuse. The guard reads the patch routes off PatchyApi instead of a second
table, and /api%2Fuploads is a 404 after the token rather than a public HTML
404. TrustedProxies is a plain parse behind Config.mapOrFail, no Schema class.
The moved page copy says patch, not draft, and the socket tests cover the
slash spellings, the encoded slash and the body answers.
3fe4e98 to
6d917e2
Compare
Problem
With
authandpatchesported, Fastify was only a shell: aManagedRuntimeseam that re-bridged every request, a hand-rolledpackages/config, and a Promise migration seam inpackages/db. Pages, headers and the request guard still lived in the app, and the Effect lint rules the port map promised had not landed.Solution
packages/servingowns the serving guarantees and their headers, the page routes (/,/healthz,/d/:patchId,/d/:patchId/v/:n, the HTML 404) asHttpRouterroutes reading throughpatches, and the trusted-proxySchemathat resolves the client address. Tests run overNodeHttpServer.layerTest, withTestClockdriving the visit top-up and expiry.apps/serveris wiring: oneServer.layer— services over a migrated database,HttpApiBuilder.layer(PatchyApi)with both group layers behind auth's bearer middleware, the pages, one global middleware whose order is written down (proxy walk → serving headers → API guard), the expiry sweep forked in the scope — andstart.tslaunching it underNodeRuntime.runMain. The API guard keeps the observable contract for what the router never sees: every/api/*request but the mint spends one protected-API attempt and needs a token before a 400/404/414. The upload handler is raw, so scope and the per-token upload limit are spent before the body is read and the wire's own refusals (413, field-specific 400s) stay.packages/config,packages/dband Fastify. The dev runner, the vitest template and the packed-CLI e2e migrate throughsqldirectly; the e2e starts its own embedded Postgres and reads its assertions from SQL (it was still expecting the JSON driver, which is whycli-smokefails on the base).eslint/(namespace imports for Effect and service modules, no manual runtimes in tests, no Schema compiles in function bodies), proved byRuleTester; every language-service rule is an error repo-wide, withpackages/cliheld at warning until feat(cli): patchy on effect/unstable/cli with the agent contract #78.packages/serving/CONTEXT.mdtakes the serving-guarantee terms,apps/server/CONTEXT.mdshrinks to wiring and the guard, map/labels/README follow.Deviations from #77, named:
authandlimits, which serving may not import. The three middleware functions are composed into oneHttpRouter.middleware(…, { global: true })at the server so their order is explicit.HttpMiddleware.xForwardedHeaderstrusts the leftmost address and requiresX-Forwarded-Host; the contract is rightmost-untrusted through trusted networks, so serving applies its own walk./api/uploads/,/api%2Fuploads) are no longer scope-checked or upload-limited: the router normalises the former onto the real route and the latter is nobody's route, so there is no body to protect. An encoded slash is one segment, as it is for the router.disableandcreateTokendecode through HttpApi, so a malformed or absent body there is Effect's empty 400 (the derived client always sends one); only the upload keeps hand-written body refusals.Authorization.identifyis factored out of auth's middleware so the guard shares one header-to-identity path, and the 401 is answered as a response rather than failed as a value — an endpoint's error union was encoding it as a 400.public-url.tsexisted to move. The Dockerfile is updated for the package list but could not be built here (no Docker socket); thedockerCI job is the check.Stacked on #87.
Closes #77
Built by Claude Fable 5 via Claude Code.