Skip to content
Myr

stale.test.ts

This file

Path

apps/cli/test/local/stale.test.ts

223 lines · 6.6 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

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–7why, one step back
1import { NodeServices } from "@effect/platform-node";
2import { describe, expect, it } from "@effect/vitest";3import { agentsBlock, upsertAgentsBlock } from "@repo/agent-kit/agents-block";4import { projectSkill } from "@repo/agent-kit/project-skill";5import { Client } from "@repo/protocol/contracts";6import type { Policy } from "@repo/protocol/domain/policy";7import { RunBlock } from "@repo/protocol/domain/run";

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 8why, one step back
8import { Handle, keyOf, LandedSha, ProjectName } from "@repo/protocol/ids";

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 9–49why, one step back
9import { gitOk } from "@repo/testkit/git";
10import { Effect, Exit, FileSystem, Layer, Path, Schema } from "effect";11import { CliOutput } from "effect/cli";12import { TestConsole } from "effect/testing";1314import { ConfigBundlerBun, localPolicy } from "../../src/local/local-policy.ts";15import { program } from "../../src/main.ts";16import { OutputPlain } from "../../src/output.ts";17import { SignedOut } from "../signed-out.ts";18import { aCheckRepo, handle, project } from "./fixture.ts";19import type { CheckRepo } from "./fixture.ts";2021const unreachable = Layer.mock(Client)({});2223const services = Layer.mergeAll(24 TestConsole.layer,25 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),26 unreachable,27 OutputPlain,28 SignedOut29).pipe(Layer.provideMerge(NodeServices.layer));3031const checked = (root: string) =>32 Effect.gen(function* () {33 const exit = yield* Effect.exit(34 program(["check", "--dir", root, "--offline", "--shape-only", "--json"])35 );3637 const [out = ""] = (yield* TestConsole.logLines).map(String);3839 return {40 envelope: yield* Schema.decodeEffect(Schema.fromJsonString(Schema.Json))(41 out42 ),43 err: (yield* TestConsole.errorLines).map(String).join("\n"),44 exit,45 };46 }).pipe(Effect.provide(services));4748const name = ProjectName.make(project);49

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 50why, one step back
50const skill = `.agents/skills/${keyOf(ProjectName.make(project))}-contribute/SKILL.md`;

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 51–223why, one step back
51
52const older = LandedSha.make("a".repeat(40));5354const policyAtMain = (repo: CheckRepo) =>55 localPolicy(repo.root, "main", {56 initializer: Handle.make(handle),57 project: name,58 }).pipe(Effect.provide(ConfigBundlerBun));5960const olderRun = Schema.decodeSync(RunBlock)({61 checks: { ok: "true" },62 test: "true {path}",63});6465const withOlderRun = (policy: Policy): Policy => ({ ...policy, run: olderRun });6667const writeFile = (repo: CheckRepo, file: string, content: string) =>68 Effect.gen(function* () {69 const fs = yield* FileSystem.FileSystem;70 const path = yield* Path.Path;71 const at = path.join(repo.root, file);7273 yield* fs.makeDirectory(path.dirname(at), { recursive: true });74 yield* fs.writeFileString(at, content);75 });7677const cleanRepo = Effect.gen(function* () {78 const repo = yield* aCheckRepo;7980 yield* gitOk(repo.root, "checkout", "--quiet", "clean");8182 return repo;83});8485describe("check, on generated files", () => {86 it.live(87 "notes a contribute skill generated for an older run block, naming it and the landing it came from",88 () =>89 Effect.gen(function* () {90 const repo = yield* cleanRepo;91 const policy = yield* policyAtMain(repo);9293 const [copy] = yield* projectSkill({94 landed: older,95 policy: withOlderRun(policy),96 project: name,97 });9899 yield* writeFile(repo, skill, copy?.content ?? "");100101 const printed = yield* checked(repo.root);102103 expect(Exit.isSuccess(printed.exit)).toBeTruthy();104 expect(printed.envelope).toMatchObject({105 data: { stale: [{ landed: older, path: skill }] },106 ok: true,107 });108 expect(printed.err).toContain(109 `${skill} differs from what main's config gives`110 );111 expect(printed.err).toContain(older);112 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))113 );114115 it.live(116 "notes a contribute skill edited by hand since it was generated, naming the landing it came from",117 () =>118 Effect.gen(function* () {119 const repo = yield* cleanRepo;120 const policy = yield* policyAtMain(repo);121122 const [copy] = yield* projectSkill({123 landed: older,124 policy,125 project: name,126 });127128 yield* writeFile(129 repo,130 skill,131 `${copy?.content ?? ""}\nOne more rule of our own.\n`132 );133134 const printed = yield* checked(repo.root);135136 expect(printed.envelope).toMatchObject({137 data: { stale: [{ landed: older, path: skill }] },138 ok: true,139 });140 expect(printed.err).toContain(141 `${skill} differs from what main's config gives (it says it was generated at ${older})`142 );143 expect(printed.err).toContain("edited by hand");144 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))145 );146147 it.live(148 "notes an AGENTS.md block that is not the one main's policy gives",149 () =>150 Effect.gen(function* () {151 const repo = yield* cleanRepo;152 const policy = yield* policyAtMain(repo);153154 const block = yield* agentsBlock({155 landed: older,156 policy: withOlderRun(policy),157 project: name,158 });159160 yield* writeFile(161 repo,162 "AGENTS.md",163 upsertAgentsBlock("# Fixture\n\nOur notes.\n", block)164 );165166 const printed = yield* checked(repo.root);167168 expect(printed.envelope).toMatchObject({169 data: { stale: [{ path: "AGENTS.md" }] },170 ok: true,171 });172 expect(printed.err).toContain(173 "AGENTS.md differs from what main's config gives"174 );175 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))176 );177178 it.live("says nothing of copies generated from main's policy", () =>179 Effect.gen(function* () {180 const repo = yield* cleanRepo;181 const policy = yield* policyAtMain(repo);182183 const copies = yield* projectSkill({184 landed: older,185 policy,186 project: name,187 });188189 const block = yield* agentsBlock({190 landed: older,191 policy,192 project: name,193 });194195 for (const copy of copies) {196 yield* writeFile(repo, copy.path, copy.content);197 }198199 yield* writeFile(200 repo,201 "AGENTS.md",202 upsertAgentsBlock("# Fixture\n\nOur notes.\n", block)203 );204205 const printed = yield* checked(repo.root);206207 expect(Exit.isSuccess(printed.exit)).toBeTruthy();208 expect(printed.envelope).toStrictEqual({209 command: "check",210 data: {211 ask: "fix-a",212 base: repo.main,213 head: repo.clean,214 lanes: [],215 stage: "shape",216 },217 ok: true,218 v: 1,219 });220 expect(printed.err).not.toContain("differs from");221 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))222 );223});