Skip to content
Myr

mcp.test.ts

This file

Path

apps/platform/test/mcp.test.ts

965 lines · 25.7 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take 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–18why, one step back
1import { describe, expect, it, layer } from "@effect/vitest";
2import { commandDocs } from "@repo/agent-kit/command-doc";3import { readManaged } from "@repo/agent-kit/generated-file";4import { platformSkill } from "@repo/agent-kit/platform";5import { Brand } from "@repo/brand";6import { CheckAt } from "@repo/checks/check-runner";7import { Contracts, EnvSchemaOf, Surfaces } from "@repo/protocol/contracts";8import type { Contract, ContractOn } from "@repo/protocol/contracts";9import { Ask, AskListing } from "@repo/protocol/domain/ask";10import { CheckSpec } from "@repo/protocol/domain/check";11import { ProjectListing } from "@repo/protocol/domain/front-page";12import {13 AskId,14 CommitSha,15 DecisionId,16 Handle,17 LaneName,18 ProjectName,

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 19why, one step back
19 ProposalId,

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

line 20why, one step back
20 RepoPath,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 21why, one step back
21 keyOf,

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 22–31why, one step back
22 RequestId,
23} from "@repo/protocol/ids";24import { CurrentPrincipal, Principal } from "@repo/protocol/principal";25import {26 NotClaimed,27 NotDecider,28 ProjectExists,29 UnknownAsk,30 UnknownCommit,31 UnknownDecision,

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

line 32why, one step back
32 UnknownPath,

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

line 33why, one step back
33 UnknownProject,

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

line 34why, one step back
34 UnknownRevision,

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 35–55why, one step back
35} from "@repo/protocol/refusal";
36import type { Refusal } from "@repo/protocol/refusal";37import { explain } from "@repo/protocol/render";38import {39 Array,40 Context,41 Effect,42 Layer,43 Option,44 Predicate,45 Schema,46 SchemaAST,47} from "effect";48import type { Rpc } from "effect/rpc";4950import { MemorySessions } from "../src/sessions/memory.ts";51import { operatorToken } from "./fake-env.ts";52import { noProjects, origin, served } from "./harness.ts";53import { coreLoopWorld } from "./world.ts";54import type { CoreLoopWorld } from "./world.ts";55

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 56why, one step back
56const project = ProjectName.make("dora/datekit");

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 57–61why, one step back
57
58const fixWeek = AskId.make("fix-week");5960const nope = AskId.make("no-such-ask");61

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 62why, one step back
62const nowhere = ProjectName.make("alice/nowhere");

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 63–79why, one step back
63
64const redThenGreen = LaneName.make("redThenGreen");6566const sdk = `${Brand.cliPackage}/rules`;6768const start = {69 [`${Brand.configDir}/project.ts`]: [70 `import { kinds, project } from "${sdk}";`,71 ``,72 `export default project({`,73 ` kinds: [kinds.fix],`,74 ` run: { checks: {}, test: "bun test {path}" },`,75 `});`,76 ``,77 ].join("\n"),78 [`${Brand.configDir}/vouched.td`]: "alice\nbob\n",79 "README.md": "datekit: dates, parsed\n",

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 80why, one step back
80 "package.json": '{ "name": "dora/datekit", "private": true }\n',

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 81–308why, one step back
81 "src/week.ts": "export const week = (iso: string) => 0;\n",
82};8384const want = "week reads the ISO week of a date";8586const askFiles = Array.make(87 {88 content: [89 `import { kinds, territory } from "${sdk}";`,90 ``,91 `export default kinds.fix.ask({`,92 ` path: "test/${fixWeek}.test.ts",`,93 ` territory: territory.paths("src/week.ts"),`,94 ` want: "${want}",`,95 `});`,96 ``,97 ].join("\n"),98 path: RepoPath.make(`${Brand.configDir}/asks/${fixWeek}.ask.ts`),99 },100 {101 content: [102 `import { expect, it } from "bun:test";`,103 `import { week } from "../src/week.ts";`,104 ``,105 `it("${want}", () => {`,106 ` expect(week("2026-10-07")).toBe(41);`,107 `});`,108 ``,109 ].join("\n"),110 path: RepoPath.make(`test/${fixWeek}.test.ts`),111 }112);113114class Seeded extends Context.Service<Seeded, CoreLoopWorld>()("test/Seeded") {}115116const seeded = Layer.effect(117 Seeded,118 Effect.gen(function* () {119 const world = yield* coreLoopWorld();120 const dora = world.rpc("dora");121 const doraGit = world.git("dora");122123 const made = yield* dora.initProject({ project });124 const home = yield* doraGit.clone(made.remote);125126 yield* doraGit.commit(home, "Start datekit", start);127 yield* doraGit.push(home);128129 yield* world.script(130 CheckAt.cases.Commit.make({131 commit: yield* world.composed(project, askFiles),132 }),133 redThenGreen,134 ["failed", "failed"]135 );136137 yield* dora.openAsk({ ask: fixWeek, files: askFiles, project });138139 return world;140 }).pipe(Effect.orDie)141);142143const version = "2026-07-28";144145const meta = {146 "io.modelcontextprotocol/clientCapabilities": {},147 "io.modelcontextprotocol/clientInfo": { name: "test", version: "0.0.0" },148 "io.modelcontextprotocol/protocolVersion": version,149};150151const routedBy = new Map([152 ["prompts/get", "name"],153 ["resources/read", "uri"],154 ["tools/call", "name"],155]);156157const mcpRequest = (158 method: string,159 params: Readonly<Record<string, Schema.Json>>,160 token?: string161) => {162 const headers = new Headers({163 accept: "application/json, text/event-stream",164 "content-type": "application/json",165 "mcp-method": method,166 "mcp-protocol-version": version,167 });168169 const key = routedBy.get(method);170 const routed = key === undefined ? undefined : params[key];171172 if (Predicate.isString(routed)) {173 headers.set("mcp-name", routed);174 }175176 if (token !== undefined) {177 headers.set("authorization", `Bearer ${token}`);178 }179180 return new Request(`${origin}/mcp`, {181 body: JSON.stringify({182 id: 1,183 jsonrpc: "2.0",184 method,185 params: { _meta: meta, ...params },186 }),187 headers,188 method: "POST",189 });190};191192const Reply = Schema.fromJsonString(193 Schema.Struct({194 error: Schema.optionalKey(Schema.Struct({ message: Schema.String })),195 result: Schema.optionalKey(Schema.Unknown),196 })197);198199const replyOf = (response: Response) =>200 Effect.promise(() => response.text()).pipe(201 Effect.map((text) =>202 response.headers.get("content-type")?.includes("text/event-stream") ===203 true204 ? (text205 .split("\n")206 .findLast((line) => line.startsWith("data: "))207 ?.slice("data: ".length) ?? "")208 : text209 ),210 Effect.flatMap(Schema.decodeEffect(Reply))211 );212213const resultOf = <S extends Schema.Top>(214 fetch: (request: Request) => Effect.Effect<Response>,215 schema: S,216 method: string,217 params: Readonly<Record<string, Schema.Json>>,218 token = operatorToken219) =>220 fetch(mcpRequest(method, params, token)).pipe(221 Effect.flatMap(replyOf),222 Effect.flatMap(({ error, result }) => {223 expect(error, `${method} failed`).toBeUndefined();224225 return Schema.decodeUnknownEffect(schema)(result);226 })227 );228229const errorOf = (230 fetch: (request: Request) => Effect.Effect<Response>,231 method: string,232 params: Readonly<Record<string, Schema.Json>>,233 token = operatorToken234) =>235 fetch(mcpRequest(method, params, token)).pipe(236 Effect.flatMap(replyOf),237 Effect.map(({ error }) => error?.message)238 );239240const TextContents = Schema.Struct({241 contents: Schema.Array(242 Schema.Struct({243 mimeType: Schema.optionalKey(Schema.String),244 text: Schema.String,245 uri: Schema.String,246 })247 ),248});249250const Templates = Schema.Struct({251 resourceTemplates: Schema.Array(252 Schema.Struct({253 mimeType: Schema.optionalKey(Schema.String),254 name: Schema.String,255 uriTemplate: Schema.String,256 })257 ),258});259260const Resources = Schema.Struct({261 resources: Schema.Array(262 Schema.Struct({263 mimeType: Schema.optionalKey(Schema.String),264 name: Schema.String,265 uri: Schema.String,266 })267 ),268});269270const Prompts = Schema.Struct({271 prompts: Schema.Array(272 Schema.Struct({273 arguments: Schema.optionalKey(274 Schema.Array(275 Schema.Struct({276 name: Schema.String,277 required: Schema.optionalKey(Schema.Boolean),278 })279 )280 ),281 description: Schema.optionalKey(Schema.String),282 name: Schema.String,283 })284 ),285});286287const PromptText = Schema.Struct({288 messages: Schema.NonEmptyArray(289 Schema.Struct({290 content: Schema.Struct({291 text: Schema.String,292 type: Schema.Literal("text"),293 }),294 role: Schema.Literal("user"),295 })296 ),297});298299const ToolResult = Schema.Struct({300 content: Schema.Tuple([301 Schema.Struct({302 text: Schema.fromJsonString(Schema.Unknown),303 type: Schema.Literal("text"),304 }),305 ]),306 isError: Schema.Boolean,307});308

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 309–320why, one step back
309const ToolText = Schema.Struct({
310 content: Schema.Tuple([311 Schema.Struct({ text: Schema.String, type: Schema.Literal("text") }),312 ]),313 isError: Schema.Boolean,314});315316const Answered = Schema.Struct({317 isError: Schema.Boolean,318 structuredContent: Schema.Unknown,319});320

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

line 321why, one step back
321const briefUri = (of: ProjectName, ask: AskId) =>

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 322why, one step back
322 `${Brand.urlScheme}ask/${keyOf(of)}/${ask}`;

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 323–365why, one step back
323
324const skillBody = platformSkill({ commands: commandDocs(Contracts) }).pipe(325 Effect.map(([file]) =>326 Option.match(327 Option.flatMap(Option.fromNullishOr(file), ({ content }) =>328 readManaged(content)329 ),330 { onNone: () => "", onSome: ({ body }) => body }331 )332 )333);334335type OwnError<R> =336 R extends Rpc.Rpc<337 infer _Tag,338 infer _Payload,339 infer _Success,340 infer Error,341 infer _Middleware,342 infer _Requires343 >344 ? Error["Type"]345 : never;346347type Refusing<R> = R extends Rpc.Any348 ? [OwnError<R>] extends [never]349 ? never350 : R["_tag"]351 : never;352353interface Provoked<Tag extends string> {354 readonly args: Rpc.Payload<Rpc.ExtractTag<Contract, Tag>>;355 readonly refusal: OwnError<Rpc.ExtractTag<Contract, Tag>>;356}357358const base = CommitSha.make("1111111111111111111111111111111111111111");359360const head = CommitSha.make("3333333333333333333333333333333333333333");361362const requestId = RequestId.make("mcp-refused-0001");363364const decision = DecisionId.make("dec-000001");365

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 366–367why, one step back
366const untagged = "v9.9.9";
367

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 368–381why, one step back
368const provoked = {
369 claim: {370 args: { ask: nope, project },371 refusal: new UnknownAsk({ ask: nope }),372 },373 decide: {374 args: { choice: "accept", decision, project },375 refusal: new UnknownDecision({ decision }),376 },377 // Keyed by the class: lint keeps "shape" out of code names.378 [EnvSchemaOf._tag]: {379 args: { project: nowhere },380 refusal: new UnknownProject({ project: nowhere }),381 },

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 382–385why, one step back
382 draftAsk: {
383 args: { project: nowhere, proposal: ProposalId.make("prop-000001") },384 refusal: new UnknownProject({ project: nowhere }),385 },

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 386–417why, one step back
386 finish: {
387 args: { ask: fixWeek, base, head, project, requestId },388 refusal: new NotDecider({}),389 },390 flagAsk: {391 args: { ask: nope, project, reason: "the want names a file" },392 refusal: new UnknownAsk({ ask: nope }),393 },394 fork: {395 args: { project: nowhere },396 refusal: new UnknownProject({ project: nowhere }),397 },398 initProject: {399 args: { project },400 refusal: new ProjectExists({ project }),401 },402 land: {403 args: { base, head, message: "Tidy the week", project, requestId },404 refusal: new NotDecider({}),405 },406 landing: {407 args: { project, sha: head },408 refusal: new UnknownCommit({ sha: head }),409 },410 ledger: {411 args: { project: nowhere },412 refusal: new UnknownProject({ project: nowhere }),413 },414 listAsks: {415 args: { project: nowhere },416 refusal: new UnknownProject({ project: nowhere }),417 },

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 418–425why, one step back
418 listRefs: {
419 args: { project: nowhere },420 refusal: new UnknownProject({ project: nowhere }),421 },422 log: {423 args: { at: untagged, project },424 refusal: new UnknownRevision({ rev: untagged }),425 },

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 426–429why, one step back
426 openAsk: {
427 args: { ask: nope, files: askFiles, project },428 refusal: new NotDecider({}),429 },

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 430–433why, one step back
430 projectPolicy: {
431 args: { project: nowhere },432 refusal: new UnknownProject({ project: nowhere }),433 },

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 434–437why, one step back
434 proposeAsk: {
435 args: { project: nowhere, want },436 refusal: new UnknownProject({ project: nowhere }),437 },

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 438–445why, one step back
438 readFile: {
439 args: { at: untagged, path: RepoPath.make("README.md"), project },440 refusal: new UnknownRevision({ rev: untagged }),441 },442 readTree: {443 args: { project: nowhere },444 refusal: new UnknownProject({ project: nowhere }),445 },

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 446–452why, one step back
446 release: {
447 args: { ask: fixWeek, project },448 refusal: NotClaimed.of(fixWeek),449 },450 showAsk: {451 args: { ask: nope, project },452 refusal: new UnknownAsk({ ask: nope }),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 453–456why, one step back
453 },
454 showProposal: {455 args: { project: nowhere, proposal: ProposalId.make("prop-000001") },456 refusal: new UnknownProject({ project: nowhere }),

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 457–477why, one step back
457 },
458 status: {459 args: { project: nowhere },460 refusal: new UnknownProject({ project: nowhere }),461 },462 submitAnswer: {463 args: { ask: fixWeek, base, head, project, requestId },464 refusal: NotClaimed.of(fixWeek),465 },466 today: {467 args: { project: nowhere },468 refusal: new UnknownProject({ project: nowhere }),469 },470 verdict: {471 args: { ask: nope, project },472 refusal: new UnknownAsk({ ask: nope }),473 },474 vouch: {475 args: { handle: Handle.make("alice"), project, verdict: "vouch" },476 refusal: new NotDecider({}),477 },

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 478–481why, one step back
478 why: {
479 args: { at: untagged, path: RepoPath.make("src/week.ts"), project },480 refusal: new UnknownRevision({ rev: untagged }),481 },

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 482–679why, one step back
482} satisfies {
483 readonly [Tag in Refusing<ContractOn<"mcp">>]: Provoked<Tag>;484};485486const refusingOnMcp = [...Contracts.requests.values()].filter(487 (rpc) =>488 Context.get(rpc.annotations, Surfaces).includes("mcp") &&489 !SchemaAST.isNever(rpc.errorSchema.ast)490);491492const provokedBy = new Map<493 string,494 { readonly args: unknown; readonly refusal: Refusal }495>(Object.entries(provoked));496497layer(seeded, { excludeTestServices: true, timeout: "120 seconds" })(498 "the platform's MCP surface, once datekit has fix-week open",499 (test) => {500 test.effect("lists the ask brief as a resource template", () =>501 Effect.gen(function* () {502 const { fetch } = yield* Seeded;503504 const { resourceTemplates } = yield* resultOf(505 fetch,506 Templates,507 "resources/templates/list",508 {}509 );510511 expect(resourceTemplates).toContainEqual({512 mimeType: "text/markdown",513 name: "ask brief",514 uriTemplate: `${Brand.urlScheme}ask/{project}/{ask}`,515 });516 })517 );518519 test.effect("reads an ask's brief as showAsk gives it, in Markdown", () =>520 Effect.gen(function* () {521 const world = yield* Seeded;522 const uri = briefUri(project, fixWeek);523524 const { brief } = yield* world525 .rpc("anonymous")526 .showAsk({ ask: fixWeek, project });527528 const read = yield* resultOf(529 world.fetch,530 TextContents,531 "resources/read",532 {533 uri,534 }535 );536537 expect(read.contents).toStrictEqual([538 { mimeType: "text/markdown", text: brief, uri },539 ]);540 })541 );542543 test.effect(544 "answers an ask it does not have with an error naming UnknownAsk",545 () =>546 Effect.gen(function* () {547 const { fetch } = yield* Seeded;548549 const message = yield* errorOf(fetch, "resources/read", {550 uri: briefUri(project, nope),551 });552553 expect(message).toContain(554 explain([new UnknownAsk({ ask: nope })]).join("\n")555 );556 })557 );558559 test.effect("lists the projects as a resource", () =>560 Effect.gen(function* () {561 const { fetch } = yield* Seeded;562563 const { resources } = yield* resultOf(564 fetch,565 Resources,566 "resources/list",567 {}568 );569570 expect(resources).toContainEqual({571 mimeType: "text/markdown",572 name: "projects",573 uri: `${Brand.urlScheme}projects`,574 });575 })576 );577578 test.effect(579 "lists the prompt contribute, described as the skill is, which may name a project",580 () =>581 Effect.gen(function* () {582 const { fetch } = yield* Seeded;583584 const { prompts } = yield* resultOf(585 fetch,586 Prompts,587 "prompts/list",588 {}589 );590591 const contribute = prompts.find(({ name }) => name === "contribute");592593 expect(contribute).toMatchObject({594 arguments: [{ name: "project", required: false }],595 name: "contribute",596 });597 expect(contribute?.description).toMatch(598 new RegExp(599 `^Contribute to projects on ${Brand.name} with the \`${Brand.cli}\` CLI`,600 "u"601 )602 );603 })604 );605606 test.effect(607 "gives the platform's skill as contribute, as gen writes it",608 () =>609 Effect.gen(function* () {610 const { fetch } = yield* Seeded;611 const body = yield* skillBody;612613 const { messages } = yield* resultOf(614 fetch,615 PromptText,616 "prompts/get",617 {618 name: "contribute",619 }620 );621622 expect(body).toContain(`# ${Brand.name}`);623 expect(messages.map(({ content }) => content.text)).toStrictEqual([624 body,625 ]);626 })627 );628629 test.effect("adds a named project's open asks to contribute", () =>630 Effect.gen(function* () {631 const { fetch } = yield* Seeded;632 const body = yield* skillBody;633634 const { messages } = yield* resultOf(fetch, PromptText, "prompts/get", {635 arguments: { project },636 name: "contribute",637 });638639 const text = messages.map(({ content }) => content.text).join("\n");640641 expect(text).toContain(body);642 expect(text).toContain(fixWeek);643 expect(text).toContain(briefUri(project, fixWeek));644 })645 );646647 test.effect(648 "answers contribute for a project nobody made with an error naming UnknownProject",649 () =>650 Effect.gen(function* () {651 const { fetch } = yield* Seeded;652653 const message = yield* errorOf(fetch, "prompts/get", {654 arguments: { project: nowhere },655 name: "contribute",656 });657658 expect(message).toContain(659 explain([new UnknownProject({ project: nowhere })]).join("\n")660 );661 })662 );663664 test.effect(665 "keeps resources and prompts from a caller with no credential",666 () =>667 Effect.gen(function* () {668 const { fetch } = yield* Seeded;669670 const statuses = yield* Effect.forEach(671 [672 mcpRequest("resources/read", { uri: briefUri(project, fixWeek) }),673 mcpRequest("resources/templates/list", {}),674 mcpRequest("prompts/get", { name: "contribute" }),675 ],676 (request) => Effect.map(fetch(request), ({ status }) => status)677 );678679 expect(statuses).toStrictEqual([401, 401, 401]);

Merge build/1106 into mainoscabrielbefore adoptionefa96f3

lines 680–791why, one step back
680 })
681 );682683 test.effect("reads a file at main as structured content", () =>684 Effect.gen(function* () {685 const world = yield* Seeded;686 const { landed } = yield* world.rpc("anonymous").listRefs({ project });687688 const result = yield* resultOf(world.fetch, Answered, "tools/call", {689 arguments: { path: "README.md", project },690 name: "readFile",691 });692693 const file = yield* Schema.decodeUnknownEffect(694 Schema.Struct({695 at: Schema.String,696 binary: Schema.Boolean,697 path: Schema.String,698 text: Schema.String,699 truncated: Schema.Boolean,700 })701 )(result.structuredContent);702703 expect(result.isError).toBeFalsy();704 expect(file).toStrictEqual({705 at: landed,706 binary: false,707 path: "README.md",708 text: start["README.md"],709 truncated: false,710 });711 })712 );713714 test.effect("lists the root folder at main", () =>715 Effect.gen(function* () {716 const { fetch } = yield* Seeded;717718 const result = yield* resultOf(fetch, Answered, "tools/call", {719 arguments: { project },720 name: "readTree",721 });722723 const listing = yield* Schema.decodeUnknownEffect(724 Schema.Struct({725 entries: Schema.Array(726 Schema.Struct({ name: Schema.String, type: Schema.String })727 ),728 })729 )(result.structuredContent);730731 expect(result.isError).toBeFalsy();732 expect(listing.entries).toStrictEqual([733 { name: Brand.configDir, type: "tree" },734 { name: "src", type: "tree" },735 { name: "test", type: "tree" },736 { name: "README.md", type: "blob" },737 { name: "package.json", type: "blob" },738 ]);739 })740 );741742 test.effect(743 "refuses a file main does not have with UnknownPath, its tag kept",744 () =>745 Effect.gen(function* () {746 const world = yield* Seeded;747 const missing = RepoPath.make("src/month.ts");748749 const { landed } = yield* world750 .rpc("anonymous")751 .listRefs({ project });752753 const commit = yield* Effect.fromNullishOr(landed);754755 const result = yield* resultOf(756 world.fetch,757 ToolResult,758 "tools/call",759 {760 arguments: { path: missing, project },761 name: "readFile",762 }763 );764765 const [{ text }] = result.content;766767 expect(result.isError).toBeTruthy();768 expect(text).toHaveProperty("_tag", "UnknownPath");769 expect(770 yield* Schema.decodeUnknownEffect(UnknownPath)(text)771 ).toStrictEqual(new UnknownPath({ commit, path: missing }));772 })773 );774775 test.effect(776 "refuses a log page of more than 100 commits by its input",777 () =>778 Effect.gen(function* () {779 const { fetch } = yield* Seeded;780781 const result = yield* resultOf(fetch, ToolText, "tools/call", {782 arguments: { limit: 101, project },783 name: "log",784 });785786 const [{ text }] = result.content;787788 expect(result.isError).toBeTruthy();789 expect(text).toMatch(/^Invalid parameters for tool 'log'/u);790 expect(text).toContain("between 1 and 100");791 expect(text).toContain('["limit"]');

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 792–822why, one step back
792 })
793 );794795 test("provokes every contract MCP serves that can refuse", () => {796 expect(refusingOnMcp.map(({ _tag }) => _tag)).toStrictEqual(797 expect.arrayContaining(["showAsk", "submitAnswer", "initProject"])798 );799 expect([...provokedBy.keys()].toSorted()).toStrictEqual(800 refusingOnMcp.map(({ _tag }) => _tag).toSorted()801 );802 });803804 test.effect.each(refusingOnMcp.map(({ _tag }) => _tag))(805 "returns %s's refusal as JSON its error union decodes",806 (tag) =>807 Effect.gen(function* () {808 const { fetch } = yield* Seeded;809 const rpc = yield* Effect.fromNullishOr(Contracts.requests.get(tag));810 const row = yield* Effect.fromNullishOr(provokedBy.get(tag));811812 const args = yield* Schema.encodeUnknownEffect(813 Schema.toCodecJson(rpc.payloadSchema)814 )(row.args);815816 const result = yield* resultOf(fetch, ToolResult, "tools/call", {817 arguments: args,818 name: tag,819 });820821 const [{ text }] = result.content;822

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

line 823why, one step back
823 // Before decoding, so a call that wrongly succeeded fails here, not as a decode error.

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 824–965why, one step back
824 expect(result.isError, `${tag} was not refused`).toBeTruthy();
825826 const refusal = yield* Schema.decodeUnknownEffect(rpc.errorSchema)(827 text828 );829830 expect(text).toMatchObject({831 _tag: row.refusal._tag,832 next: row.refusal.next,833 retryable: row.refusal.retryable,834 });835 expect(refusal).toStrictEqual(row.refusal);836 })837 );838 }839);840841const sessions = MemorySessions.layer({842 "alice-token": Handle.make("alice"),843 "bob-token": Handle.make("bob"),844});845846const callerName = CurrentPrincipal.useSync((principal) =>847 Principal.match(principal, {848 Anonymous: () => "anyone",849 Person: ({ handle }) => handle,850 })851);852853const askWire = {854 askedBy: "dora",855 blockedBy: [],856 brief: { want },857 check: Schema.encodeSync(CheckSpec)(858 CheckSpec.cases.RedThenGreen.make({859 path: RepoPath.make(`test/${fixWeek}.test.ts`),860 })861 ),862 file: `${Brand.configDir}/asks/${fixWeek}.ask.ts`,863 id: fixWeek,864 kind: "fix",865 openedAt: "2026-10-07T12:00:00.000Z",866 openedIn: "4444444444444444444444444444444444444444",867 project,868 state: "open",869 territory: { module: ".", paths: ["src/week.ts"] },870} as const;871872const naming = Layer.mergeAll(873 noProjects,874 Contracts.toLayerHandler("showAsk", () =>875 Effect.map(callerName, (who) => ({876 ask: Schema.decodeSync(Ask)(askWire),877 brief: `# ${fixWeek}\n\nRead by ${who}.`,878 }))879 ),880 Contracts.toLayerHandler("listProjects", () =>881 Effect.succeed({882 projects: [883 Schema.decodeSync(ProjectListing)({884 openAsks: 1,885 posture: "open",886 project,887 }),888 ],889 })890 ),891 Contracts.toLayerHandler("listAsks", () =>892 Effect.map(callerName, (who) => ({893 asks: [894 Schema.decodeSync(AskListing)({895 ask: fixWeek,896 blockedBy: [],897 claimed: false,898 kind: "fix",899 territory: ".",900 want: `listed for ${who}`,901 }),902 ],903 }))904 ),905 sessions906);907908describe("the platform's MCP resources and prompts, over scripted contracts", () => {909 it.effect("read through the Client the tools use, as the caller", () =>910 Effect.gen(function* () {911 const { fetch } = yield* served(naming);912913 const brief = yield* resultOf(914 fetch,915 TextContents,916 "resources/read",917 { uri: briefUri(project, fixWeek) },918 "alice-token"919 );920921 const prompt = yield* resultOf(922 fetch,923 PromptText,924 "prompts/get",925 { arguments: { project }, name: "contribute" },926 "bob-token"927 );928929 expect(brief.contents.map(({ text }) => text)).toStrictEqual([930 `# ${fixWeek}\n\nRead by alice.`,931 ]);932 expect(933 prompt.messages.map(({ content }) => content.text).join("\n")934 ).toContain("listed for bob");935 })936 );937938 it.effect("reads the projects as a Markdown table", () =>939 Effect.gen(function* () {940 const { fetch } = yield* served(naming);941 const uri = `${Brand.urlScheme}projects`;942943 const read = yield* resultOf(944 fetch,945 TextContents,946 "resources/read",947 { uri },948 "alice-token"949 );950951 expect(read.contents).toHaveLength(1);952 expect(read.contents[0]).toMatchObject({953 mimeType: "text/markdown",954 uri,955 });956 expect(read.contents[0]?.text).toContain(957 [958 "| project | posture | open asks | landed |",959 "| --- | --- | --- | --- |",960 `| ${project} | open | 1 | never |`,961 ].join("\n")962 );963 })964 );965});