Skip to content
Myr

Close W6: give the layer gate its own upstream, prove the cartridge removable by deletion, and name its fences in AGENTS.md

Before adoption: this commit came in with the history the project adopted, so no landing records it.

W6 integration (699). Found live on dev-oscabriel, fixed red first: - The layer gate's private upstream was the public one: privateUpstream piped the same UpstreamRepoHost layer the core ports build over ARTIFACTS, and a layer built twice in one memo map is shared, so every layer clone or push on a stage asked the public namespace and answered "no repo datekit--maintainers" (the DO had made the repo in layers-dev-oscabriel). It is Layer.fresh now. Test: layer-gateway.test.ts "the stage's layer gate asks the private namespace for a layer repo, never the public one" (red by assertion: the fake binding touched was ARTIFACTS.get). The Node world never saw it: its upstream is not UpstreamRepoHost. From the cartridge deletion test (a scratch worktree, discarded): - The Cartridge type lives in apps/platform/src/cartridges.ts, so the module keeps a line when its last marked line is deleted (an empty module fails lint's no-empty-file), and serve-world.ts types the cartridges as ports.ts does (an empty namespace made them never). - cartridge.test.ts also lists seed-layer.test.ts (it runs the world the cartridge plugs into) and examples/datekit/layers/ (content only the cartridge can seed), and its header names every line outside the manifest a deletion takes. Decision: cartridge.test.ts goes with the cartridge rather than skipping, since a fence for a cartridge that is gone holds nothing. - Result: deleting the manifest, those files, the marked line, the two dependency lines, ARTIFACTS_PRIVATE and MASTER_KEY (with their test wiring, two bootstrap.test.ts rows and seed.test.ts's three Layer lines), then bun run types and bun install, left bun run verify green: 103 files, 18,364 lines deleted; platform entry 1,518,193 bytes without it, 1,605,141 with it. AGENTS.md "Held by": principle 6 names cartridge.test.ts; principle 7 names the layer gateway, held-back, guards and landing-guard tests that now exist (its "No fence yet: the gateway's layer guard" is gone). Live on dev-oscabriel (deployed from 191b3b5 plus the gate fix, smoke seven of seven): ines-v landed datekit's visibility config (0-day notice, ASSUMPTION recorded in spec §8.8) and accepted its PostureChange; the seed pushed the maintainers layer; admission ran ten container runs and admitted export (7 checks by 3 authors) and parser (4 by 3); a contributor's clone got 403 and a maintainer's held checks/held-back/**; bram's answer that broke quote escaping got HeldBackFailed{export} in status, verdict and git notes; his fix landed with "Held-back: export 7/7 @ sha256:…; parser 4/4 @ sha256:…"; env set SENTRY_AUTH_TOKEN showed "set by ines-v" in env shape, ledger and web, and a later run's recorded env held only __SENTRY_AUTH_TOKEN_PLACEHOLDER__.

authored by oscabriel · committed by oscabriel · parent 191b3b5 · Browse files · 7 files+106 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+106 added−23 removed

  • tests:+80 added−10 removed
  • other:+26 added−13 removed

7 files+106 added−23 removed

modified:apps/platform/src/visibility/layers.ts+8 added-2 removed
modified:apps/platform/src/cartridges.ts+15 added
modified:apps/platform/src/ports.ts+1 added-9 removed
46 unmodified lines
47import { WorkerFetch } from "./adapters/fetch.ts";48import { LanderSandbox } from "./adapters/lander-sandbox.ts";49import { WorkerRateLimits } from "./adapters/rate-limits.ts";50import * as cartridges from "./cartridges.ts";51import type { Cartridge } from "./cartridges.ts";52import type { PlatformConfig } from "./platform.ts";53import type { RateLimits } from "./rate-limits.ts";54import { ProjectSockets } from "./watch.ts";55
11 unmodified lines
67 | RulesEvaluator68 | Upstream;6970/**70 * A cartridge: its layer for one stage's config, over the platform's own71 * ports. What it provides are ports with defaults, so its layer adds no72 * service a host must name.73 */74type Cartridge = (75 config: PlatformConfig76) => Layer.Layer<never, never, WorkerPorts>;7778/**71 * Every cartridge `cartridges.ts` names, merged over `ports`. Deleting a72 * cartridge's line there unplugs it: the ports it filled answer their73 * defaults again.74 */
63 unmodified lines
modified:apps/platform/test/visibility/layer-gateway.test.ts+36 added-1 removed
18 unmodified lines
19import { RefName, RepoName } from "@repo/artifacts/repo-host";20import type { RepoHost } from "@repo/artifacts/repo-host";21import { Brand } from "@repo/brand";22import { CheckAt } from "@repo/checks/check-runner";23import { Exchange } from "@repo/git/upstream";24import {25 noPlan,26 noVisibility,27 ProjectVisibility,
13 unmodified lines
41import { explain } from "@repo/protocol/render";42import { git } from "@repo/testkit/git";43import type { Ran } from "@repo/testkit/git";44import { LayerRepos } from "@repo/visibility/layer-repos";44import { Array, Effect, FileSystem, Layer, Option, Redacted } from "effect";45import {46 Array,47 Cause,48 Effect,49 Exit,50 FileSystem,51 Layer,52 Option,53 Redacted,54} from "effect";5556import { LayerGate, noLayers } from "../../src/layer-gate.ts";57import { decodeEnv } from "../../src/platform.ts";58import { workerPorts } from "../../src/ports.ts";
578 unmodified lines
637638 expect(gate === noLayers).toBeFalsy();639 })640 );641642 // Found live (699): the gate's upstream was memoized with the public643 // namespace's, so every layer clone on a stage answered "no repo".644 it.effect(645 "the stage's layer gate asks the private namespace for a layer repo, never the public one",646 () =>647 Effect.gen(function* () {648 const config = yield* decodeEnv(fakeEnv()).pipe(Effect.orDie);649650 const exit = yield* LayerGate.use((gate) =>651 gate.upstream.exchange(652 layerRepo,653 Exchange.Advertise({654 headers: new Headers(),655 service: "git-upload-pack",656 })657 )658 ).pipe(Effect.provide(workerPorts(config)), Effect.exit);659660 // Both fake bindings refuse every call, each naming itself.661 expect(Exit.isFailure(exit) ? Cause.pretty(exit.cause) : "").toContain(662 "a test touched ARTIFACTS_PRIVATE."663 );664 })665 );666});
modified:apps/platform/test/serve-world.ts+12 added-4 removed
37 unmodified lines
38import { untouchable } from "@repo/testkit/untouchable";39import { Console, Effect, FileSystem, Layer, Stdio, Stream } from "effect";4041import type * as Cartridges from "../src/cartridges.ts";42import type { Cartridge } from "../src/cartridges.ts";43import type { decodeEnv, PlatformConfig } from "../src/platform.ts";44import type { WorkerPorts } from "../src/ports.ts";45import { fakeEnv, withPrivateNamespace } from "./fake-env.ts";46import { shimWorkers, worldSessions } from "./world-process.ts";
62 unmodified lines
109 get: (id) =>110 Promise.resolve(untouchable<WorkflowInstance>("an admission", { id })),111});112112/** Every cartridge in `plugged`, for one stage's config, merged. */113/**114 * Every cartridge in `plugged`, for one stage's config, merged. Typed as115 * `ports.ts` types them, so a platform whose `cartridges.ts` names none (a116 * cartridge deleted) still typechecks here.117 */118const pluggedFor =119 (plugged: typeof Cartridges) =>115 (config: PlatformConfig): Layer.Layer<never, never, WorkerPorts> =>116 Layer.mergeAll(120 (config: PlatformConfig): Layer.Layer<never, never, WorkerPorts> => {121 const each: readonly Cartridge[] = Object.values(plugged);122123 return Layer.mergeAll(124 Layer.empty,118 ...Object.values(plugged).map((cartridge) => cartridge(config))125 ...each.map((cartridge) => cartridge(config))126 );127 };128129/**130 * Every cartridge in `plugged`, over the world's ports, for a stage whose131 * private namespace is `aside`: over the Worker's ports as they are, and
59 unmodified lines
modified:packages/config/test/cartridge.test.ts+32 added-5 removed
47 unmodified lines
48 * by its path rather than an import (the CLI's end-to-end `env set`, W649 * 616: apps never import apps), so no import reader sees them: they go50 * with it too.51 */52const RUNS_ITS_WORLD = ["apps/cli/test/local/env-set-live.test.ts"] as const;52const RUNS_ITS_WORLD = [53 "apps/cli/test/local/env-set-live.test.ts",54 // The seed's layer step, over the world the cartridge plugs into (608).55 "packages/config/test/seed-layer.test.ts",56] as const;5754/** Every folder, and every file, that goes when the cartridge goes. */55const CARTRIDGE = [...MANIFEST, ...TEST_HOMES, ...RUNS_ITS_WORLD];58/**59 * The examples' content that only a platform with the cartridge can seed:60 * datekit's maintainers layer (608). Without it the seed plans no layer.61 */62const ITS_CONTENT = ["examples/datekit/layers/"] as const;6364/**65 * Every folder, and every file, that goes when the cartridge goes. Deleting66 * it also takes the lines that name it (W6 699 did it in a scratch worktree67 * and verify stayed green): the marked line in `cartridges.ts`; the two68 * `@repo/visibility` dependency lines; `ARTIFACTS_PRIVATE` and `MASTER_KEY`69 * in the platform's `wrangler.jsonc`, `.env.schema` and `platform.ts`, its70 * tests' fake env (`withPrivateNamespace` and its imports, and its use in71 * `serve-world.ts`), `bindings.test.ts`, `platform.test.ts` and72 * `env.test-d.ts`, then `bun run types`; the private namespace and73 * `MASTER_KEY` rows in `bootstrap.test.ts`; and datekit's three `Layer`74 * lines in `seed.test.ts`. Bootstrap still plans the stage's `layers-<s>`75 * namespace (`infra/stages.ts`), which nothing binds then.76 */77const CARTRIDGE = [78 ...MANIFEST,79 ...TEST_HOMES,80 ...RUNS_ITS_WORLD,81 ...ITS_CONTENT,82];8384/**85 * Where the line that plugs the cartridge in lives (`ports.ts` merges every86 * cartridge `cartridges.ts` names over the platform's ports), and the one87 * module it names.88 */
580 unmodified lines
669});670671describe("the visibility cartridge", () => {672 it.effect(646 "has every folder of its manifest, and every test outside it that runs its world",673 "has every folder of its manifest, every test outside it that runs its world, and the example content only it can seed",674 () =>675 provided(676 Effect.gen(function* () {677 const fs = yield* FileSystem.FileSystem;678 const path = yield* Path.Path;679 const root = yield* repoRoot;680681 const missing = yield* Effect.filter(655 [...MANIFEST, ...RUNS_ITS_WORLD],682 [...MANIFEST, ...RUNS_ITS_WORLD, ...ITS_CONTENT],683 (each) =>684 Effect.map(fs.exists(path.join(root, each)), (found) => !found)685 );686
105 unmodified lines
modified:AGENTS.md+2 added-2 removed
21 unmodified lines
22| 2 | **Parse at the boundary, trust inside.** Decode every external input (HTTP, git, DO RPC, WebSocket, rule facts, env) with Effect Schema; inside, use branded types (`AskId`, `LandedSha`, `PatchId`). Decode the Worker `env` once, in one Layer. | The Effect diagnostics at error in `tsconfig.base.json`; `anti-slop/no-unknown-parameters`, `anti-slop/no-widen-then-assert` and `anti-slop/require-safety-comment-for-type-assertion`; `apps/platform/test/platform.test.ts` (a bad env fails at start, decoded once in `apps/platform/src/platform.ts`); `apps/platform/test/bindings.test.ts` (the decoded bindings, vars and secrets equal each wrangler.jsonc block's, and each port's factory takes its binding as the generated Env types it, without a cast) |23| 3 | **Refusals are a closed `Schema.TaggedError` union and a public contract.** Handle them with `Match.exhaustive` or `catchTags`. Each carries a `retryable` and a `next` command fixed per tag, an optional `at`, and no `message` field. A `_tag` is renamed only with an alias. `protocol/render` is the one renderer for git `remote:`, CLI and MCP text. Stage-1 refusals accumulate. | `packages/protocol/test/refusal.test.ts`; `packages/protocol/test/render.test.ts`; `packages/protocol/test/mcp.test.ts` (a refusal from tools/call keeps its tag); `anti-slop-effect/prefer-effect-match` and `anti-slop-effect/no-manual-tag-comparison`; `packages/gate/test/shape.test.ts` (one push hears every stage-1 refusal at once); `apps/platform/test/mcp.test.ts` (each refusing MCP contract comes back as its exact refusal); `apps/cli/test/policy.test.ts`; `apps/cli/test/local/check.test.ts` (the local check gives the gateway's stage-1 refusals for the same commit) |24| 4 | **One schema, many surfaces.** Change `packages/protocol`; every surface derives from it. Projections live only in `apps/*/src/surfaces.ts`. The CLI's command list is `commandDocs` in `@repo/agent-kit`, which the platform's skill, the CLI's MCP prompt and the web's `llms.txt` all read. | `apps/cli/test/commands-doc.test.ts` (the command list against the real CLI's commands, flags and positionals); `packages/protocol/test/mcp.test.ts` (every MCP tool's schemas, with no JSON Schema leak); per-package `allowedUnstableApis` with `unstableApiUsage` at error |25| 5 | **The name lives only in `packages/brand`.** Internal packages use `@repo/*`. DO classes, Workflows, queues and databases carry job names. | `brand:check` (`scripts/brand.ts`, tested by `packages/brand/test/leaks.test.ts`) |26| 6 | **Pure core, thin hosts.** Only `@repo/artifacts` calls Artifacts. Each beta dependency sits behind one job-named port with a `/memory` adapter in the owning package. Apps import packages only. Worker code stays free of `node:child_process`, `@effect/platform-bun` and OpenTUI. `rules` and `gate` run in both Workers and Bun. `alchemy/*` stays in `infra/`. No module-level mutable state in a package's `src/`. | Scoped `allowedUnstableApis`; `packages/artifacts/test/repo-host-contract.ts` (one RepoHost contract every adapter passes); `apps/platform/test/bindings.test.ts` and `apps/platform/test/worker-init.test.ts` (the Worker starts on its real adapters, composed in `apps/platform/src/ports.ts`); `apps/web/test/production-bundle.test.ts` (no dev-world module in the web's production build). No fence: import direction and module-level state |27| 7 | **Deny by default for visibility.** Land the answer's tree, never the composed tree. Nothing from a layer enters a public tree. Snapshot before held-back files are written. Public-serving Workers have no private-namespace binding. Public commits, trailers, notes and errors name public paths only. | `PrivatePathInPublicTree`, raised by the gate's stage 1 (`packages/gate/test/shape.test.ts`); `apps/platform/test/bindings.test.ts`; `apps/sandbox/test/checker.test.ts` (no snapshot once the held-back slot is reached); `apps/web/test/env.test-d.ts` (the web's Env has no private-namespace or Artifacts binding) and `apps/platform/test/env.test-d.ts` (only the platform's has both). No fence yet: the gateway's layer guard (W6 606) |26| 6 | **Pure core, thin hosts.** Only `@repo/artifacts` calls Artifacts. Each beta dependency sits behind one job-named port with a `/memory` adapter in the owning package. Apps import packages only. Worker code stays free of `node:child_process`, `@effect/platform-bun` and OpenTUI. `rules` and `gate` run in both Workers and Bun. `alchemy/*` stays in `infra/`. No module-level mutable state in a package's `src/`. | Scoped `allowedUnstableApis`; `packages/artifacts/test/repo-host-contract.ts` (one RepoHost contract every adapter passes); `apps/platform/test/bindings.test.ts` and `apps/platform/test/worker-init.test.ts` (the Worker starts on its real adapters, composed in `apps/platform/src/ports.ts`); `apps/web/test/production-bundle.test.ts` (no dev-world module in the web's production build); `packages/config/test/cartridge.test.ts` (the visibility cartridge is plugged in by one marked line and reached by nothing else, so removing it is a deletion). No fence: import direction and module-level state |27| 7 | **Deny by default for visibility.** Land the answer's tree, never the composed tree. Nothing from a layer enters a public tree. Snapshot before held-back files are written. Public-serving Workers have no private-namespace binding. Public commits, trailers, notes and errors name public paths only. | `PrivatePathInPublicTree`, one rule for the gate's stage 1 and the landing guard (`packages/gate/test/shape.test.ts`, `packages/visibility/test/guards.test.ts`); `apps/platform/test/visibility/layer-gateway.test.ts` (only a layer's readers clone it, every read is logged, a fork push cannot carry its paths); `apps/sandbox/test/held-back.test.ts` (egress off and the snapshot taken before any sealed file is written; one bit per area, no output); `apps/platform/test/visibility/held-back.test.ts` (the `Held-back:` trailer, the landing guards, no stored value in a note or a kept log); `apps/platform/test/bindings.test.ts`; `apps/sandbox/test/checker.test.ts` (no snapshot once the held-back slot is reached); `apps/web/test/env.test-d.ts` (the web's Env has no private-namespace or Artifacts binding) and `apps/platform/test/env.test-d.ts` (only the platform's has both) |28| 8 | **Deterministic and idempotent.** Rule evaluation sees frozen time and randomness and only injected facts. Re-running an operation converges. Check results are keyed by (tree SHA, check version), push events deduped by (repo, sha), and land requests carry a `requestId`. | `globalDate`, `globalRandom`, `globalTimers` and `cryptoRandomUUID` at error, with their in-Effect twins; `packages/rules/test/replay.test.ts`; `packages/project/test/project-store.contract.ts`; `packages/project/test/claim.model.test.ts` and `packages/project/test/landing.model.test.ts`; `apps/platform/test/workflows/answer.test.ts`; `apps/platform/test/workflows/on-push.test.ts`; `apps/platform/test/core-loop.test.ts`. No fence yet: one push deduped by (repo, sha) across the gateway's record and OnPush's (W3 313 #2) |29| 9 | **Effect v4 only.** Read `node_modules/effect/src` as API truth. Off limits: `effect/unstable/*`, v3 `@effect/platform` and `@effect/cli`, and `effect/workflow` or `effect/cluster` on Workers. | `outdatedApi`; `no-restricted-imports` |30| 10 | **Escapes need a reason.** Every `oxlint-disable`, `@effect-diagnostics` or `@ts-expect-error` carries its reason after `--`, and is added only where no idiomatic code does the job. | `check` fails on an unused directive. No fence: the reason |31| 11 | **`bun run verify` is the authority.** Deploy only to an explicit stage, after `verify`, with smoke after. A red gate is fixed, never deployed around. | `packages/config/test/verify.test.ts` (verify's steps); `infra/deploy.ts` refuses without a known stage, runs `verify` first and `scripts/smoke.ts` after (`packages/config/test/deploy.test.ts`, `packages/config/test/smoke.test.ts`) |
113 unmodified lines