harness.ts
This file
Path
apps/platform/test/harness.ts
203 lines · 5.9 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–9why, one step back1import { RepoHost } from "@repo/artifacts/repo-host";2import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";3import { Upstream } from "@repo/git/upstream";4import type { FrontPage } from "@repo/project/front-page";5import { FrontPageMemory } from "@repo/project/front-page/memory";6import { Projects } from "@repo/project/projects";7import { Contracts } from "@repo/protocol/contracts";8import { UnknownProject } from "@repo/protocol/refusal";9import { untouchable } from "@repo/testkit/untouchable";Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 10why, one step back10import { Effect, Layer, Option, Schema } from "effect";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 11–16why, one step back11import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";12import { RpcClient, RpcSerialization } from "effect/rpc";1314import { MemoryRateLimits, WorkerCaps } from "../src/adapters/rate-limits.ts";15import { Handlers } from "../src/handlers.ts";16import { ReleaseStore } from "../src/releases.ts";Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 17why, one step back17import { HostInfo, serve, Stage } from "../src/surfaces.ts";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 18–132why, one step back18import type { Services } from "../src/surfaces.ts";1920export const origin = "http://localhost";2122// MCP's 2026-07-28 protocol is stateless: each request names its version and23// client in `_meta` and repeats its method and target in headers.24const version = "2026-07-28";2526const meta = {27 "io.modelcontextprotocol/clientCapabilities": {},28 "io.modelcontextprotocol/clientInfo": { name: "test", version: "0.0.0" },29 "io.modelcontextprotocol/protocolVersion": version,30};3132interface Params {33 readonly arguments?: Readonly<Record<string, string>>;34 readonly name?: string;35}3637const mcpRequest = (method: string, params: Params, token?: string) => {38 const headers = new Headers({39 accept: "application/json, text/event-stream",40 "content-type": "application/json",41 "mcp-method": method,42 "mcp-protocol-version": version,43 });4445 if (params.name !== undefined) {46 headers.set("mcp-name", params.name);47 }4849 if (token !== undefined) {50 headers.set("authorization", `Bearer ${token}`);51 }5253 return new Request(`${origin}/mcp`, {54 body: JSON.stringify({55 id: 1,56 jsonrpc: "2.0",57 method,58 params: { _meta: meta, ...params },59 }),60 headers,61 method: "POST",62 });63};6465export const toolCall = (66 name: string,67 args: Readonly<Record<string, string>>,68 token?: string69) => mcpRequest("tools/call", { arguments: args, name }, token);7071export const toolList = (token: string) => mcpRequest("tools/list", {}, token);7273const ToolResult = Schema.Struct({74 content: Schema.Tuple([75 Schema.Struct({76 text: Schema.fromJsonString(Schema.Unknown),77 type: Schema.Literal("text"),78 }),79 ]),80 isError: Schema.Boolean,81});8283const Reply = Schema.fromJsonString(Schema.Struct({ result: ToolResult }));8485const lastMessage = (response: Response) =>86 Effect.promise(() => response.text()).pipe(87 Effect.map((text) =>88 response.headers.get("content-type")?.includes("text/event-stream") ===89 true90 ? (text91 .split("\n")92 .findLast((line) => line.startsWith("data: "))93 ?.slice("data: ".length) ?? "")94 : text95 )96 );9798const Listed = Schema.fromJsonString(99 Schema.Struct({100 result: Schema.Struct({101 tools: Schema.Array(Schema.Struct({ name: Schema.String })),102 }),103 })104);105106export const toolNames = (response: Response) =>107 lastMessage(response).pipe(108 Effect.flatMap(Schema.decodeEffect(Listed)),109 Effect.map(({ result }) => result.tools.map(({ name }) => name))110 );111112export const toolResult = (response: Response) =>113 lastMessage(response).pipe(114 Effect.flatMap(Schema.decodeEffect(Reply)),115 Effect.map(({ result }) => ({116 isError: result.isError,117 json: result.content[0].text,118 }))119 );120121const unused = (port: string) => () =>122 Effect.die(`a surfaces test called ${port}, which it never sets up`);123124const defaults = Layer.mergeAll(125 Layer.succeed(126 Projects,127 Projects.of({ create: unused("Projects"), get: unused("Projects") })128 ),129 Layer.succeed(Upstream, Upstream.of({ exchange: unused("Upstream") })),130 Layer.succeed(ReleaseStore, ReleaseStore.of({ get: unused("ReleaseStore") })),131 FrontPageMemory.layer({ credits: [], entries: [], projects: [] }),132 Layer.succeed(RepoHost, untouchable<RepoHost["Service"]>("RepoHost")),Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 133–137why, one step back133 Layer.succeed(Stage, Stage.of({ name: "local" })),134 Layer.succeed(135 HostInfo,136 HostInfo.of({ draftModel: "test-model", webUrl: Option.none() })137 )Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 138–151why, one step back138);139140export const noProjects = Handlers.pipe(141 Layer.provide([142 Layer.succeed(143 Projects,144 Projects.of({145 create: unused("Projects.create"),146 get: (project) => Effect.fail(new UnknownProject({ project })),147 })148 ),149 FrontPageMemory.layer({ credits: [], entries: [], projects: [] }),150 MemoryRateLimits(WorkerCaps),151 EvidenceStoreMemory,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 152why, one step back152 Layer.succeed(RepoHost, untouchable<RepoHost["Service"]>("RepoHost")),Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 153–159why, one step back153 ])154);155156export const served = Effect.fnUntraced(function* <E>(157 services: Layer.Layer<158 Exclude<159 Services,Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 160–166why, one step back160 | Projects161 | ReleaseStore162 | Upstream163 | FrontPage164 | RepoHost165 | Stage166 | HostInfoMerge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 167–203why, one step back167 >,168 E169 >170) {171 const { dispose, handler } = serve(Layer.merge(defaults, services));172173 yield* Effect.addFinalizer(() => Effect.promise(dispose));174175 return {176 fetch: (request: Request) => Effect.promise(() => handler(request)),177 handler,178 };179});180181export const rpcClient = (182 handler: (request: Request) => Promise<Response>,183 token?: string184) => {185 const fetch: typeof globalThis.fetch = (input, init) =>186 handler(new Request(input, init));187188 return RpcClient.make(Contracts).pipe(189 Effect.provide(190 RpcClient.layerProtocolHttp({191 transformClient: HttpClient.mapRequest((request) =>192 token === undefined193 ? request194 : HttpClientRequest.bearerToken(request, token)195 ),196 url: `${origin}/rpc`,197 }).pipe(198 Layer.provide([FetchHttpClient.layer, RpcSerialization.layerJson]),199 Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetch))200 )201 )202 );203};