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 fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224import { NodeServices } from "@effect/platform-node";import { describe, expect, it } from "@effect/vitest";import { agentsBlock, upsertAgentsBlock } from "@repo/agent-kit/agents-block";import { projectSkill } from "@repo/agent-kit/project-skill";import { Client } from "@repo/protocol/contracts";import type { Policy } from "@repo/protocol/domain/policy";import { RunBlock } from "@repo/protocol/domain/run";import { Handle, keyOf, LandedSha, ProjectName } from "@repo/protocol/ids";import { gitOk } from "@repo/testkit/git";import { Effect, Exit, FileSystem, Layer, Path, Schema } from "effect";import { CliOutput } from "effect/cli";import { TestConsole } from "effect/testing";
import { ConfigBundlerBun, localPolicy } from "../../src/local/local-policy.ts";import { program } from "../../src/main.ts";import { OutputPlain } from "../../src/output.ts";import { SignedOut } from "../signed-out.ts";import { aCheckRepo, handle, project } from "./fixture.ts";import type { CheckRepo } from "./fixture.ts";
const unreachable = Layer.mock(Client)({});
const services = Layer.mergeAll( TestConsole.layer, CliOutput.layer(CliOutput.defaultFormatter({ colors: false })), unreachable, OutputPlain, SignedOut).pipe(Layer.provideMerge(NodeServices.layer));
const checked = (root: string) => Effect.gen(function* () { const exit = yield* Effect.exit( program(["check", "--dir", root, "--offline", "--shape-only", "--json"]) );
const [out = ""] = (yield* TestConsole.logLines).map(String);
return { envelope: yield* Schema.decodeEffect(Schema.fromJsonString(Schema.Json))( out ), err: (yield* TestConsole.errorLines).map(String).join("\n"), exit, }; }).pipe(Effect.provide(services));
const name = ProjectName.make(project);
const skill = `.agents/skills/${keyOf(ProjectName.make(project))}-contribute/SKILL.md`;
const older = LandedSha.make("a".repeat(40));
const policyAtMain = (repo: CheckRepo) => localPolicy(repo.root, "main", { initializer: Handle.make(handle), project: name, }).pipe(Effect.provide(ConfigBundlerBun));
const olderRun = Schema.decodeSync(RunBlock)({ checks: { ok: "true" }, test: "true {path}",});
const withOlderRun = (policy: Policy): Policy => ({ ...policy, run: olderRun });
const writeFile = (repo: CheckRepo, file: string, content: string) => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const at = path.join(repo.root, file);
yield* fs.makeDirectory(path.dirname(at), { recursive: true }); yield* fs.writeFileString(at, content); });
const cleanRepo = Effect.gen(function* () { const repo = yield* aCheckRepo;
yield* gitOk(repo.root, "checkout", "--quiet", "clean");
return repo;});
describe("check, on generated files", () => { it.live( "notes a contribute skill generated for an older run block, naming it and the landing it came from", () => Effect.gen(function* () { const repo = yield* cleanRepo; const policy = yield* policyAtMain(repo);
const [copy] = yield* projectSkill({ landed: older, policy: withOlderRun(policy), project: name, });
yield* writeFile(repo, skill, copy?.content ?? "");
const printed = yield* checked(repo.root);
expect(Exit.isSuccess(printed.exit)).toBeTruthy(); expect(printed.envelope).toMatchObject({ data: { stale: [{ landed: older, path: skill }] }, ok: true, }); expect(printed.err).toContain( `${skill} differs from what main's config gives` ); expect(printed.err).toContain(older); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)) );
it.live( "notes a contribute skill edited by hand since it was generated, naming the landing it came from", () => Effect.gen(function* () { const repo = yield* cleanRepo; const policy = yield* policyAtMain(repo);
const [copy] = yield* projectSkill({ landed: older, policy, project: name, });
yield* writeFile( repo, skill, `${copy?.content ?? ""}\nOne more rule of our own.\n` );
const printed = yield* checked(repo.root);
expect(printed.envelope).toMatchObject({ data: { stale: [{ landed: older, path: skill }] }, ok: true, }); expect(printed.err).toContain( `${skill} differs from what main's config gives (it says it was generated at ${older})` ); expect(printed.err).toContain("edited by hand"); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)) );
it.live( "notes an AGENTS.md block that is not the one main's policy gives", () => Effect.gen(function* () { const repo = yield* cleanRepo; const policy = yield* policyAtMain(repo);
const block = yield* agentsBlock({ landed: older, policy: withOlderRun(policy), project: name, });
yield* writeFile( repo, "AGENTS.md", upsertAgentsBlock("# Fixture\n\nOur notes.\n", block) );
const printed = yield* checked(repo.root);
expect(printed.envelope).toMatchObject({ data: { stale: [{ path: "AGENTS.md" }] }, ok: true, }); expect(printed.err).toContain( "AGENTS.md differs from what main's config gives" ); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)) );
it.live("says nothing of copies generated from main's policy", () => Effect.gen(function* () { const repo = yield* cleanRepo; const policy = yield* policyAtMain(repo);
const copies = yield* projectSkill({ landed: older, policy, project: name, });
const block = yield* agentsBlock({ landed: older, policy, project: name, });
for (const copy of copies) { yield* writeFile(repo, copy.path, copy.content); }
yield* writeFile( repo, "AGENTS.md", upsertAgentsBlock("# Fixture\n\nOur notes.\n", block) );
const printed = yield* checked(repo.root);
expect(Exit.isSuccess(printed.exit)).toBeTruthy(); expect(printed.envelope).toStrictEqual({ command: "check", data: { ask: "fix-a", base: repo.main, head: repo.clean, lanes: [], stage: "shape", }, ok: true, v: 1, }); expect(printed.err).not.toContain("differs from"); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)) );});