Skip to content
Myr

assisted.test.ts

This file

Path

packages/project/test/assisted.test.ts

312 lines · 8.5 KiB · TypeScript

Last changed by

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

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–13why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { RefName, RepoHost } from "@repo/artifacts/repo-host";3import { creditsOf } from "@repo/git/trailers";4import type { HarnessAudit } from "@repo/protocol/audit";5import type { Ask } from "@repo/protocol/domain/ask";6import { CheckSpec } from "@repo/protocol/domain/check";7import type { Policy } from "@repo/protocol/domain/policy";8import {9 AskId,10 LandedSha,11 LaneName,12 RepoName,13 RepoPath,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 14why, one step back
14 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 15–34why, one step back
15 RequestId,
16} from "@repo/protocol/ids";17import type { CommitSha } from "@repo/protocol/ids";18import { Anonymous, Person } from "@repo/protocol/principal";19import { advanceTo } from "@repo/testkit/clock";20import type { Files } from "@repo/testkit/git-client";21import { aProject, withAsk, withVouches } from "@repo/testkit/scenarios";22import { Array, Effect, Option } from "effect";2324import type { ProjectApi } from "../src/project.ts";25import { projectService } from "../src/project.ts";26import { CheckScript, composedAt, mergedAt, Pusher, worldOf } from "./world.ts";2728const scenario = aProject({ people: ["bob"] }).pipe(29 withVouches(["bob"]),30 withAsk({ id: "parse-iso", territory: "packages/parser" })31);3233const { project } = scenario;34

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 35why, one step back
35const repo = RepoName.make(keyOf(project));

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 36–46why, one step back
36
37const mainRef = RefName.make("refs/heads/main");3839const parseIso = AskId.make("parse-iso");4041const alice = Person.make({ handle: scenario.initializer });4243const bob = Person.make({44 handle: scenario.people.get("bob") ?? scenario.initializer,45});46

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 47why, one step back
47const bobFork = RepoName.make(`${keyOf(project)}--${parseIso}--${bob.handle}`);

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 48–77why, one step back
48
49const lanes = [50 LaneName.make("redThenGreen"),51 LaneName.make("lint"),52 LaneName.make("types"),53];5455const ask: Ask = Option.getOrThrow(56 Array.findFirst(scenario.policy.asks, ({ id }) => id === parseIso)57);5859const askFiles = Array.make(60 { content: `export default "${parseIso}";\n`, path: ask.file },61 {62 content: [63 `import { expect, it } from "vitest";`,64 `import { parse } from "../src/parse.ts";`,65 ``,66 `it("parses a year", () => {`,67 ` expect(parse("2026")).toBe(2026);`,68 `});`,69 ``,70 ].join("\n"),71 path: CheckSpec.guards.RedThenGreen(ask.check)72 ? ask.check.path73 : RepoPath.make("test/parse-iso.test.ts"),74 }75);7677const start: Files = [

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 78–81why, one step back
78 [
79 "package.json",80 '{ "name": "alice/datekit", "workspaces": ["packages/*"] }\n',81 ],

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 82–312why, one step back
82 ["packages/parser/package.json", '{ "name": "parser" }\n'],
83 ["packages/parser/src/parse.ts", "export const parse = (s) => 0;\n"],84];8586const answerAt = (step: number): Files => [87 ...start.filter(([path]) => path !== "packages/parser/src/parse.ts"),88 ...askFiles.map(({ content, path }) => [path, content] as const),89 [90 "packages/parser/src/parse.ts",91 `export const parse = (s) => Number(s); // step ${step}\n`,92 ],93];9495const mainTip = Effect.gen(function* () {96 const refs = yield* (yield* RepoHost).refs(repo).pipe(Effect.orDie);9798 return LandedSha.make(99 Option.getOrThrow(Option.fromNullishOr(refs.get(mainRef)))100 );101});102103const opened = (api: ProjectApi) =>104 Effect.gen(function* () {105 yield* api.initProject(alice, {});106107 const first = yield* Pusher.use((pusher) =>108 pusher.push(repo, Option.none(), start, "Start")109 );110111 yield* api.recordFirstPush(alice, first);112113 const composed = yield* composedAt(repo, yield* mainTip, askFiles);114115 yield* CheckScript.use((checker) =>116 checker.script(composed, LaneName.make("redThenGreen"), [117 "failed",118 "failed",119 ])120 );121122 return (yield* api.openAsk(alice, { ask: parseIso, files: askFiles }))123 .landed;124 });125126const answered = (127 policy: Policy,128 pushes: readonly Option.Option<HarnessAudit>[],129 claimedAnewAt?: number130) =>131 Effect.gen(function* () {132 yield* advanceTo("2026-10-07T12:00:00Z");133134 const api = yield* projectService(project);135 const base = yield* opened(api);136137 yield* api.claim(bob, parseIso);138139 const heads = yield* Effect.reduce(140 pushes,141 (): readonly CommitSha[] => [],142 (done, audit, step) =>143 Effect.gen(function* () {144 if (step === claimedAnewAt) {145 yield* api.release(bob, parseIso);146 yield* api.claim(bob, parseIso);147 }148149 const parent = Option.getOrElse(150 Option.fromUndefinedOr(done.at(-1)),151 (): CommitSha => base152 );153154 const head = yield* Pusher.use((pusher) =>155 pusher.push(bobFork, Option.some(parent), answerAt(step))156 );157158 yield* api.recordPush({159 after: head,160 before: Option.some(parent),161 eventId: `push-${step}`,162 pusher: bob,163 ref: mainRef,164 repo: bobFork,165 ...Option.match(audit, {166 onNone: () => ({}),167 onSome: (named) => ({ audit: named }),168 }),169 });170171 return [...done, head];172 })173 );174175 const head = Option.getOrThrow(Option.fromUndefinedOr(heads.at(-1)));176177 const merged = yield* mergedAt({178 base,179 fork: bobFork,180 head,181 main: base,182 repo,183 });184185 yield* CheckScript.use((checker) =>186 Effect.forEach(187 lanes,188 (lane) => checker.script(merged, lane, ["passed"]),189 {190 discard: true,191 }192 )193 );194195 yield* api.submitAnswer(bob, {196 ask: parseIso,197 base,198 head,199 requestId: RequestId.make("req-assisted-0001"),200 });201202 const landed = yield* mainTip;203 const host = yield* RepoHost;204 const commit = yield* host.readCommit(repo, landed).pipe(Effect.orDie);205206 const { message } = Option.getOrThrow(commit);207 const { landing } = yield* api.landing(Anonymous.make({}), landed);208209 return {210 author: landing.author,211 credited: creditsOf(message).credits.map(({ handle }) => handle),212 landedOn: landed === base ? "base" : "answer",213 trailers: message214 .split("\n")215 .filter((line) => line.startsWith("Assisted-by: ")),216 view: landing.assisted,217 };218 }).pipe(Effect.provide(worldOf({ policy }, "memory")));219220const claudeCode = Option.some({ harness: "claude-code", model: "haiku" });221222const pi = Option.some({ harness: "pi", model: "kimi-k3" });223224const story = { timeout: 30_000 };225226describe("Assisted-by on an answer's landing", () => {227 it.effect(228 "names each harness that pushed to the claim once, in the order they first pushed",229 () =>230 Effect.map(231 answered(scenario.policy, [claudeCode, pi, claudeCode]),232 (seen) => {233 expect(seen).toStrictEqual({234 author: bob.handle,235 credited: [alice.handle, bob.handle],236 landedOn: "answer",237 trailers: [238 "Assisted-by: claude-code:haiku (claimed)",239 "Assisted-by: pi:kimi-k3 (claimed)",240 ],241 view: [242 { harness: "claude-code", model: "haiku", verified: false },243 { harness: "pi", model: "kimi-k3", verified: false },244 ],245 });246 }247 ),248 story249 );250251 it.effect(252 "names none when the project's policy says agents: none",253 () =>254 Effect.map(255 answered({ ...scenario.policy, agents: "none" }, [claudeCode, pi]),256 ({ landedOn, trailers, view }) => {257 expect({ landedOn, trailers, view }).toStrictEqual({258 landedOn: "answer",259 trailers: [],260 view: [],261 });262 }263 ),264 story265 );266267 it.effect(268 "names none for pushes no harness named",269 () =>270 Effect.map(271 answered(scenario.policy, [Option.none(), Option.none()]),272 ({ landedOn, trailers, view }) => {273 expect({ landedOn, trailers, view }).toStrictEqual({274 landedOn: "answer",275 trailers: [],276 view: [],277 });278 }279 ),280 story281 );282283 it.effect(284 "names only the harnesses that pushed since the ask was claimed anew",285 () =>286 Effect.map(287 answered(scenario.policy, [claudeCode, pi], 1),288 ({ landedOn, trailers }) => {289 expect({ landedOn, trailers }).toStrictEqual({290 landedOn: "answer",291 trailers: ["Assisted-by: pi:kimi-k3 (claimed)"],292 });293 }294 ),295 story296 );297298 it.effect(299 "names a harness without a model by its harness alone",300 () =>301 Effect.map(302 answered(scenario.policy, [303 Option.none(),304 Option.some({ harness: "codex" }),305 ]),306 ({ trailers }) => {307 expect(trailers).toStrictEqual(["Assisted-by: codex (claimed)"]);308 }309 ),310 story311 );312});