Skip to content
Myr

Read the admission test's visibility config through the rules, share the world processes' shim, and load the forwarding routes with their test file

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

W6 group 3 integration: 608, 615 and 616 merged with --no-ff from 234865c in that order, without a textual conflict (disjoint files). bun install and fix left no change; there is no gen script since 598. - 608 x 615 (test): 615's platform admission test gave datekit `export default {}` as its visibility.ts and wrapped the DO's rules to add the config, since no rules code read that file (604 #2). 608 makes the evaluator read and decode it, so `{}` failed decoding, datekit's first push declared no layer, and the known-bad push got "no repo datekit--maintainers". The test now states the config through the sdk (visibility, sealedChecks, layer, flows), as datekit does, and the wrapper is gone, so admission runs over the real read. The stale "does not read visibility.ts yet" notes in ledger-mcp.test.ts and packages/project/test/visibility/world.ts now say what holds. - 616 review (left for the integrator once 608 extended serve-world.ts): serve-world.ts and the cartridge's serve-cartridge-world.ts each carried the Bun shim plugin and the WORLD_SESSIONS decode. Both now come from apps/platform/test/world-process.ts, outside the cartridge, which imports no Worker module. serve-cartridge-world.ts's private namespace is 608's withPrivateNamespace. ASSUMPTION: nothing in 616's test reads the private namespace's remotes, which are now the store's own. - 616 #4: cartridge.test.ts lists apps/cli/test/local/env-set-live.test.ts among what goes with the cartridge (RUNS_ITS_WORLD: it runs the cartridge's world by path, which no import reader sees), and checks that it exists, so 699's deletion takes it. - apps/web forward.test.ts: importing the three route modules inside the test body took over 5 s under verify's load (608 saw it once; it failed this integration's first green verify). They are imported with the file, as the other route tests import theirs. - Checked: `bun scripts/seed.ts --world node` 9 steps, 9 done (Layer datekit--maintainers included); env-set-live 7/7; the admission test passes over the real evaluator. - verify green (platform 416, project 453, cli 262, config 109, web 264; platform entry 1,605,093 of 1,665,000).

authored by oscabriel · committed by oscabriel · parent 89eb59d · Browse files · 8 files+167 added−235 removed
This commit

State

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

Diff stats

8 files+167 added−235 removed

  • tests:+167 added−235 removed

8 files+167 added−235 removed

modified:apps/platform/test/visibility/admission.test.ts+39 added-77 removed
12 unmodified lines
13 * (`LayerGateLive`) and project state (`ProjectVisibilityLive`) plugged in14 * over a private namespace of its own; admissions are queued instead of15 * started, and the test runs each over the Worker's ports with the steps16 * kept in memory, as the `Answer` Workflow runs one over the engine's. The17 * rules package does not read `visibility.ts` yet (604 #2), so the DO's18 * rules give datekit's visibility config whenever the config folder holds19 * that file. The Checker answers lane jobs from a script, and held-back20 * jobs with area bits: green on main, red on the known-bad tree.17 * DO's rules read datekit's visibility config from its `visibility.ts` (608).18 * The Checker answers lane jobs from a script, and held-back jobs with area19 * bits: green on main, red on the known-bad tree.20 */21import { NodeServices } from "@effect/platform-node";22import { describe, expect, it } from "@effect/vitest";23import type { RepoHost } from "@repo/artifacts/repo-host";
5 unmodified lines
29 AdmissionStarts,30 ProjectVisibilityLive,31} from "@repo/project/visibility/state";32import type { HeldBackResult, LaneResult } from "@repo/protocol/domain/answer";33import { LedgerEntry } from "@repo/protocol/domain/visibility";34import {35 LedgerEntry,36 VisibilityPolicy,37} from "@repo/protocol/domain/visibility";38import {35 AreaName,36 AskId,37 CommitSha,38 LaneName,
1 unmodified line
40 ProjectName,41 RepoName,42 RepoPath,43} from "@repo/protocol/ids";48import { RulesEvaluator } from "@repo/rules/rules-evaluator";44import { LayerRepos } from "@repo/visibility/layer-repos";45import type { Context } from "effect";51import { Array, Effect, FileSystem, Layer, Order, Schema } from "effect";46import { Array, Effect, FileSystem, Layer, Order } from "effect";4748import { AdmissionParams } from "../../src/answer-runs.ts";49import type { WorkerPorts } from "../../src/ports.ts";50import { LayerGateLive } from "../../src/visibility/layers.ts";
17 unmodified lines
68} as const;6970const sdk = `${Brand.cliPackage}/rules`;7177const visibilityFile = `${Brand.configDir}/visibility.ts`;7879/** datekit's visibility config, as the rules would evaluate it: admission on. */80const datekitVisibility = Schema.decodeSync(VisibilityPolicy)({81 checks: {82 admit: { greenOnMainRuns: 3, redOnKnownBadAtLeast: 1 },83 areas: { export: "src/export/**", parser: "src/parser/**" },84 attempts: { perClaim: 3, perPersonPerAreaPerWeek: 10 },85 canary: false,86 commit: "salted-sha256-merkle",87 layer: "maintainers",88 pin: "claim",89 result: "area-bit",90 },91 env: { setters: "deciders" },92 flows: { noWriteDown: true, release: "deciders" },93 layers: [94 {95 audience: "maintainers",96 disclose: "sealed",97 holds: ["checks", "notes"],98 name: "maintainers",99 readers: "deciders",100 reason: "Held-back checks for export and parser",101 writers: "deciders",102 },103 ],104 notice: { narrowingDays: 7 },105});10672/** datekit as ines-v first pushes it, its visibility config with it. */73const start = {74 [`${Brand.configDir}/project.ts`]: [75 `import { kinds, project } from "${sdk}";`,
4 unmodified lines
80 `});`,81 ``,82 ].join("\n"),83 [`${Brand.configDir}/vouched.td`]: "bram\nines-v\nokonkwo\n",119 [visibilityFile]: "export default {};\n",84 // Admission on: three runs green on main, red on one known-bad tree.85 [`${Brand.configDir}/visibility.ts`]: [86 `import { flows, layer, sealedChecks, visibility } from "${sdk}";`,87 ``,88 `export default visibility({`,89 ` checks: sealedChecks({`,90 ` admit: { greenOnMainRuns: 3, redOnKnownBadAtLeast: 1 },`,91 ` areas: { export: "src/export/**", parser: "src/parser/**" },`,92 ` }),`,93 ` flows: flows.noWriteDown(),`,94 ` layers: {`,95 ` maintainers: layer({`,96 ` disclose: "sealed",`,97 ` holds: ["checks", "notes"],`,98 ` reason: "Held-back checks for export and parser",`,99 ` }),`,100 ` },`,101 `});`,102 ``,103 ].join("\n"),104 "package.json": '{ "name": "datekit", "private": true }\n',105 "src/export/svg.ts":106 'export const svg = (title: string) => title.replaceAll("<", "&lt;");\n',107 "src/parser/week.ts": "export const week = (iso: string) => 1;\n",108};109126/**127 * The DO's rules: the Worker's, with datekit's visibility config added at128 * any commit whose config folder holds `visibility.ts`.129 */130const rulesWithVisibility = Layer.effect(131 RulesEvaluator,132 Effect.map(Effect.service(RulesEvaluator), (rules) =>133 RulesEvaluator.of({134 ...rules,135 evaluate: (input) =>136 Effect.map(rules.evaluate(input), (policy) =>137 Object.hasOwn(input.modules.modules, visibilityFile)138 ? { ...policy, visibility: datekitVisibility }139 : policy140 ),141 })142 )143);144110/** A held-back check, by path: its area and its source. */111const checkFile = (area: string, name: string, body: string) =>112 [113 `checks/held-back/${area}/${name}.test.ts`,
129 unmodified lines
243244 const layers = Layer.succeed(LayerRepos, LayerRepos.of(store));245246 return {282 project: Layer.mergeAll(283 ProjectVisibilityLive.pipe(284 Layer.provide(285 Layer.mergeAll(286 layers,287 WebCryptoSalts,288 Layer.succeed(289 AdmissionStarts,290 AdmissionStarts.of({291 start: (input) =>292 Effect.sync(() => {293 queued.push(AdmissionParams.make(input));294 }),295 })247 project: ProjectVisibilityLive.pipe(248 Layer.provide(249 Layer.mergeAll(250 layers,251 WebCryptoSalts,252 Layer.succeed(253 AdmissionStarts,254 AdmissionStarts.of({255 start: (input) =>256 Effect.sync(() => {257 queued.push(AdmissionParams.make(input));258 }),259 })296 )260 )261 )299 ),300 rulesWithVisibility262 )263 ),264 worker: Layer.mergeAll(265 LayerGateLive.pipe(Layer.provide(layers)),266 Layer.effectDiscard(
308 unmodified lines
modified:apps/platform/test/visibility/ledger-mcp.test.ts+3 added-3 removed
modified:apps/platform/test/visibility/serve-cartridge-world.ts+6 added-59 removed
26 unmodified lines
27 *28 * A process, not an import: apps never import apps, and the CLI's29 * end-to-end `env set` test (W6 616) runs it. It lives in the cartridge30 * and goes with it. The Worker's modules import `cloudflare:workers`, which31 * this file serves from `../workers-shim.ts` through Bun's runtime plugins32 * before it loads them, as `../serve-world.ts` does.31 * `../world-process.ts` serves from the shim before this file loads them,32 * as it does for `../serve-world.ts`.33 */34import { NodeRuntime, NodeServices } from "@effect/platform-node";35import type { RepoHost } from "@repo/artifacts/repo-host";36import { CheckJob, CheckRunner } from "@repo/checks/check-runner";
3 unmodified lines
40 EventRow,41 LedgerRow,42} from "@repo/project/project-store/rows";43import { ProjectName } from "@repo/protocol/ids";44import { fakeArtifactsBinding } from "@repo/testkit/fake-artifacts-binding";44import {46 Config,45 Console,46 Effect,47 Layer,48 Logger,
3 unmodified lines
52 Stdio,53 Stream,54} from "effect";5558import * as shim from "../workers-shim.ts";56import { shimWorkers, worldSessions } from "../world-process.ts";57import type { PlugIn } from "../world.ts";5861/** Bun's runtime plugins, as far as this file uses them (the platform has no Bun types). */62interface BunPlugins {63 readonly plugin: (plugin: {64 readonly name: string;65 readonly setup: (build: {66 readonly module: (67 specifier: string,68 load: () => {69 readonly exports: typeof shim;70 readonly loader: "object";71 }72 ) => void;73 }) => void;74 }) => void;75}7677declare const Bun: BunPlugins;7879/** `cloudflare:workers` served from the shim, for every module loaded after. */80const shimWorkers = Effect.sync(() => {81 Bun.plugin({82 name: "cloudflare-workers-shim",83 setup: (build) => {84 build.module("cloudflare:workers", () => ({85 exports: { ...shim },86 loader: "object",87 }));88 },89 });90});9192/** Where the private namespace's stand-in says its repos are. */93const PRIVATE_REMOTES = "https://artifacts.private.test";9459/**60 * The Checker: each job kept as it came, and every lane failed the same61 * way, a count lane printing nothing.62 */
25 unmodified lines
88 }),89 })90 );91128const decodeSessions = Schema.decodeUnknownEffect(129 Schema.fromJsonString(Schema.Record(Schema.String, Schema.String))130);13192/**93 * Each job as the Checker got it, encoded by its fields alone: without94 * `CheckJob`'s rule that only landed code carries values, so a job that95 * breaks the rule still shows, values and all, for a test to refuse.
26 unmodified lines
122123const serve = Effect.gen(function* () {124 yield* shimWorkers;125166 const raw = yield* Config.String("WORLD_SESSIONS").pipe(167 Config.withDefault("{}")168 );126 const sessions = yield* worldSessions;127170 const sessions = yield* decodeSessions(raw).pipe(171 Effect.catch(() =>172 Effect.die("WORLD_SESSIONS is not a JSON object from token to handle")173 )174 );175128 // Loaded after the shim: each reaches `cloudflare:workers`.129 const [130 { coreLoopWorld, listen },179 { fakeEnv },131 { fakeEnv, withPrivateNamespace },132 { decodeEnv },133 { live },134 { stateLive },135 { envLive },
9 unmodified lines
145 );146147 /** The world's stage config, the second store standing in for the private namespace. */148 const configOver = (aside: RepoHost["Service"]) =>197 decodeEnv({198 ...fakeEnv(),199 ARTIFACTS_PRIVATE: fakeArtifactsBinding(aside, {200 remoteBase: PRIVATE_REMOTES,201 }),202 }).pipe(Effect.orDie);149 decodeEnv(withPrivateNamespace(fakeEnv(), aside)).pipe(Effect.orDie);150151 /**152 * The cartridge as the Worker plugs it: whole over the Worker's ports, and153 * the project service's part of it (its visibility state and its env)
101 unmodified lines
modified:apps/platform/test/serve-world.ts+4 added-57 removed
23 unmodified lines
24 * The seed's `--world node` runs it (W5 509, `scripts/lib/seed.ts`) and25 * reaches it over HTTP and git, as it reaches a stage. A process, not an26 * import: apps never import apps, and no file outside the platform imports27 * its test world. The Worker's modules import `cloudflare:workers`, which28 * this file serves from `workers-shim.ts` through Bun's runtime plugins,29 * before it loads them, as vitest's alias does for the platform's tests.28 * `world-process.ts` serves from the shim before this file loads them.29 */30import { NodeRuntime, NodeServices } from "@effect/platform-node";31import type { RepoHost } from "@repo/artifacts/repo-host";32import { CheckRunner, shaOf } from "@repo/checks/check-runner";
2 unmodified lines
35import { Projects } from "@repo/project/projects";36import { VerifierBlocked } from "@repo/protocol/refusal";37import { git } from "@repo/testkit/git";38import { untouchable } from "@repo/testkit/untouchable";40import {41 Config,42 Console,43 Effect,44 FileSystem,45 Layer,46 Schema,47 Stdio,48 Stream,49} from "effect";39import { Console, Effect, FileSystem, Layer, Stdio, Stream } from "effect";4041import type * as Cartridges from "../src/cartridges.ts";42import type { decodeEnv, PlatformConfig } from "../src/platform.ts";43import type { WorkerPorts } from "../src/ports.ts";44import { fakeEnv, withPrivateNamespace } from "./fake-env.ts";55import * as shim from "./workers-shim.ts";45import { shimWorkers, worldSessions } from "./world-process.ts";46import type { PlugIn } from "./world.ts";4758/** Bun's runtime plugins, as far as this file uses them (the platform has no Bun types). */59interface BunPlugins {60 readonly plugin: (plugin: {61 readonly name: string;62 readonly setup: (build: {63 readonly module: (64 specifier: string,65 load: () => {66 readonly exports: typeof shim;67 readonly loader: "object";68 }69 ) => void;70 }) => void;71 }) => void;72}7374declare const Bun: BunPlugins;7576/** `cloudflare:workers` served from the shim, for every module loaded after. */77const shimWorkers = Effect.sync(() => {78 Bun.plugin({79 name: "cloudflare-workers-shim",80 setup: (build) => {81 build.module("cloudflare:workers", () => ({82 exports: { ...shim },83 loader: "object",84 }));85 },86 });87});8848/**49 * A clone of the bare repo at `bare`, its work tree set to `at`, removed50 * when the job ends. The clone shares the repo's objects, so a composed or51 * merged commit is there whatever ref holds it.
96 unmodified lines
148 worker: all,149 };150 };151193const decodeSessions = Schema.decodeUnknownEffect(194 Schema.fromJsonString(Schema.Record(Schema.String, Schema.String))195);196152const serve = Effect.gen(function* () {153 yield* shimWorkers;154200 const raw = yield* Config.String("WORLD_SESSIONS").pipe(201 Config.withDefault("{}")202 );155 const sessions = yield* worldSessions;156204 const sessions = yield* decodeSessions(raw).pipe(205 Effect.catch(() =>206 Effect.die("WORLD_SESSIONS is not a JSON object from token to handle")207 )208 );209157 const { coreLoopWorld } = yield* Effect.promise(() => import("./world.ts"));158159 const cartridges = yield* Effect.promise(160 () => import("../src/cartridges.ts")
22 unmodified lines
added:apps/platform/test/world-process.ts+66 added
1/**2 * What a test world run as a process of its own needs before it builds the3 * world (`serve-world.ts`, and the visibility cartridge's4 * `visibility/serve-cartridge-world.ts`): `cloudflare:workers` served from5 * the shim, since the Worker's modules import it and the process loads them6 * after, as vitest's alias does for the platform's tests; and the people7 * `WORLD_SESSIONS` names.8 *9 * This module imports no Worker module, so a world process may import it10 * statically and load the rest after `shimWorkers` has run.11 */12import { Config, Effect, Schema } from "effect";1314import * as shim from "./workers-shim.ts";1516/** Bun's runtime plugins, as far as this file uses them (the platform has no Bun types). */17interface BunPlugins {18 readonly plugin: (plugin: {19 readonly name: string;20 readonly setup: (build: {21 readonly module: (22 specifier: string,23 load: () => {24 readonly exports: typeof shim;25 readonly loader: "object";26 }27 ) => void;28 }) => void;29 }) => void;30}3132declare const Bun: BunPlugins;3334/** `cloudflare:workers` served from the shim, for every module loaded after. */35export const shimWorkers = Effect.sync(() => {36 Bun.plugin({37 name: "cloudflare-workers-shim",38 setup: (build) => {39 build.module("cloudflare:workers", () => ({40 exports: { ...shim },41 loader: "object",42 }));43 },44 });45});4647const decodeSessions = Schema.decodeUnknownEffect(48 Schema.fromJsonString(Schema.Record(Schema.String, Schema.String))49);5051/**52 * The people who may call beside dora, alice and bob: `WORLD_SESSIONS`, a53 * JSON object from token to handle (as `SESSION_TOKENS` is); none when it54 * is unset.55 */56export const worldSessions = Effect.gen(function* () {57 const raw = yield* Config.String("WORLD_SESSIONS").pipe(58 Config.withDefault("{}")59 );6061 return yield* decodeSessions(raw).pipe(62 Effect.catch(() =>63 Effect.die("WORLD_SESSIONS is not a JSON object from token to handle")64 )65 );66});
modified:apps/web/test/forward.test.ts+19 added-21 removed
11 unmodified lines
12import { untouchable } from "@repo/testkit/untouchable";13import { Effect } from "effect";1415import { forwarded } from "../src/features/agents/forward.ts";16import { Route as skills } from "../src/routes/[.]well-known/agent-skills/$.ts";17import { Route as installScript } from "../src/routes/install[.]sh.ts";18import { Route as releases } from "../src/routes/releases/$.ts";19import { backend } from "../src/server/backend.ts";2021const PLATFORM_URL = "https://platform-test.example.workers.dev";22
104 unmodified lines
127 })128 );129});130128/** What a route module says of its server handlers. */129interface RouteModule {130 readonly Route: {131 readonly options: { readonly server?: { readonly handlers?: object } };132 };131/** What a route says of its server handlers. */132interface ServerRoute {133 readonly options: { readonly server?: { readonly handlers?: object } };134}135135const forwardingRoutes: readonly (readonly [136 string,137 () => Promise<RouteModule>,138])[] = [139 ["the skills", () => import("../src/routes/[.]well-known/agent-skills/$.ts")],140 ["the install script", () => import("../src/routes/install[.]sh.ts")],141 ["the releases", () => import("../src/routes/releases/$.ts")],136// Imported with the file, not in the test: loading a route module pulls in137// the router, which can take longer than a test's timeout under a full138// verify's load.139const forwardingRoutes: readonly (readonly [string, ServerRoute])[] = [140 ["the skills", skills],141 ["the install script", installScript],142 ["the releases", releases],143];144145describe("the forwarding routes", () => {145 it.effect.each(forwardingRoutes)(146 it.each(forwardingRoutes)(147 "%s answer GET and HEAD, and nothing else",147 ([, load]) =>148 Effect.gen(function* () {149 const { Route } = yield* Effect.promise(load);150151 expect(152 Object.keys(Route.options.server?.handlers ?? {}).toSorted()153 ).toStrictEqual(["GET", "HEAD"]);154 })148 (_name, route) => {149 expect(150 Object.keys(route.options.server?.handlers ?? {}).toSorted()151 ).toStrictEqual(["GET", "HEAD"]);152 }153 );154});
modified:packages/config/test/cartridge.test.ts+26 added-14 removed
41 unmodified lines
42 * they are its too, though none may be written yet.43 */44const TEST_HOMES = ["packages/project/test/visibility/"] as const;4546/** Every folder that goes when the cartridge goes. */47const CARTRIDGE = [...MANIFEST, ...TEST_HOMES];46/**47 * Tests outside its folders that run the cartridge's world as a process,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;5354/** Every folder, and every file, that goes when the cartridge goes. */55const CARTRIDGE = [...MANIFEST, ...TEST_HOMES, ...RUNS_ITS_WORLD];5657/**58 * Where the line that plugs the cartridge in lives (`ports.ts` merges every59 * cartridge `cartridges.ts` names over the platform's ports), and the one60 * module it names.
580 unmodified lines
641 });642});643644describe("the visibility cartridge", () => {645 it.effect(646 "has every folder of its manifest, and every test outside it that runs its world",637 it.effect("has every folder of its manifest", () =>638 provided(639 Effect.gen(function* () {640 const fs = yield* FileSystem.FileSystem;641 const path = yield* Path.Path;642 const root = yield* repoRoot;647 () =>648 provided(649 Effect.gen(function* () {650 const fs = yield* FileSystem.FileSystem;651 const path = yield* Path.Path;652 const root = yield* repoRoot;653644 const missing = yield* Effect.filter(MANIFEST, (folder) =>645 Effect.map(fs.exists(path.join(root, folder)), (found) => !found)646 );654 const missing = yield* Effect.filter(655 [...MANIFEST, ...RUNS_ITS_WORLD],656 (each) =>657 Effect.map(fs.exists(path.join(root, each)), (found) => !found)658 );659648 expect(missing).toStrictEqual([]);649 })650 )660 expect(missing).toStrictEqual([]);661 })662 )663 );664665 it.effect(666 "is plugged in by one marked line, which names its live module alone",
98 unmodified lines
modified:packages/project/test/visibility/world.ts+4 added-4 removed
4 unmodified lines
5 * private namespace's `LayerRepos`, salts drawn from a counter, and6 * admissions recorded instead of started. Answer runs wait for the test to7 * drive them (`drive`), so an answer can stop where its held-back run is.8 *9 * Its rules evaluator returns the scenario's policy at every commit, with10 * datekit's visibility config (a maintainers layer; sealed areas `export`11 * and `parser`) whenever the commit's config folder holds `visibility.ts`:12 * the rules package does not read that file yet (601 #4, 604 #2).9 * Its rules evaluator runs no config code: it returns the scenario's policy10 * at every commit, with datekit's visibility config (a maintainers layer;11 * sealed areas `export` and `parser`) whenever the commit's config folder12 * holds `visibility.ts`, as the real evaluator reads that file (608).13 */14import { RefName, RepoHost } from "@repo/artifacts/repo-host";15import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";16import { memoryFs } from "@repo/artifacts/repo-host/memory-fs";
519 unmodified lines