command-doc.test.ts
This file
Path
packages/agent-kit/test/command-doc.test.ts
179 lines · 4.8 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
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–101why, one step back1import { describe, expect, it } from "@effect/vitest";2import { Contracts } from "@repo/protocol/contracts";3import { Schema } from "effect";45import {6 CommandDoc,7 commandDocs,8 contractCommandDocs,9 localCommandDocs,10} from "../src/command-doc.ts";1112const contract = contractCommandDocs(Contracts);1314const all = [...contract, ...localCommandDocs];1516const named = (words: string) =>17 all.filter(({ path }) => path.join(" ") === words);1819describe(contractCommandDocs, () => {20 it("makes one row per CLI contract, from its annotations", () => {21 expect(named("claim")).toStrictEqual([22 {23 contract: "claim",24 flags: ["--project", "--json", "--dry-run"],25 needsApproval: false,26 path: ["claim"],27 positional: ["ask"],28 readOnly: false,29 source: "contract",30 summary:31 "Claim an ask: an exclusive, expiring right to answer it, with a fork to push to; claiming it again returns the same claim.",32 },33 ]);34 });3536 it("splits a nested name into words, and gives a read no --dry-run", () => {37 expect(named("env shape")).toStrictEqual([38 {39 contract: "envShape",40 flags: ["--project", "--json"],41 needsApproval: false,42 path: ["env", "shape"],43 positional: [],44 readOnly: true,45 source: "contract",46 summary:47 "Show a project's env shape: the public schema of its environment variables, and who set each write-only value; never a value.",48 },49 ]);50 });5152 it("gives a contract that needs approval --yes", () => {53 expect(named("vouch")[0]?.flags).toStrictEqual([54 "--handle",55 "--note",56 "--project",57 "--verdict",58 "--json",59 "--yes",60 "--dry-run",61 ]);62 });6364 it("leaves out a stream, which has no command", () => {65 expect(contract.some(({ contract: tag }) => tag === "watch")).toBeFalsy();66 });6768 it("leaves a contract to the local command that stands in for it", () => {69 expect(named("init")).toStrictEqual(70 localCommandDocs.filter(({ path }) => path.join(" ") === "init")71 );72 expect(named("env set")).toHaveLength(1);73 expect(named("env set")[0]?.source).toBe("local");74 });75});7677describe("every command row", () => {78 it("is a CommandDoc", () => {79 expect(all.length).toBeGreaterThan(0);80 expect(all.filter((row) => !Schema.is(CommandDoc)(row))).toStrictEqual([]);81 });8283 it("has a path no other row has", () => {84 const paths = all.map(({ path }) => path.join(" "));8586 expect(paths).toStrictEqual([...new Set(paths)]);87 });8889 it("includes each hand-written command the CLI has", () => {90 expect(91 localCommandDocs.map(({ path }) => path.join(" ")).toSorted()92 ).toStrictEqual([93 "check",94 "credential",95 "env set",96 "hook",97 "init",98 "login",99 "logout",100 "mcp",101 "schema",Wire `today --tui` into the CLI, and keep the decision under the cursor on screenoscabrielbefore adoption368c432
line 102why, one step back102 "today",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 103–159why, one step back103 "why",104 ]);105 });106});107108const calling = (docs: readonly CommandDoc[], tag: string) =>109 docs.flatMap((doc) =>110 doc.contract === tag ? [`${doc.path.join(" ")} (${doc.source})`] : []111 );112113describe(commandDocs, () => {114 const docs = commandDocs(Contracts);115 const words = docs.map(({ path }) => path.join(" "));116117 it("lists every command the CLI has, from a contract or written by hand", () => {118 const byName = new Map(docs.map((doc) => [doc.path.join(" "), doc]));119120 expect(docs).toHaveLength(contract.length + localCommandDocs.length);121 expect(byName.get("asks")).toMatchObject({122 contract: "listAsks",123 needsApproval: false,124 positional: [],125 readOnly: true,126 source: "contract",127 });128 expect(129 [130 "check",131 "credential",132 "env set",133 "hook",134 "init",135 "login",136 "logout",137 "mcp",138 "schema",139 "why",140 ].map((name) => [name, byName.get(name)?.source])141 ).toStrictEqual([142 ["check", "local"],143 ["credential", "local"],144 ["env set", "local"],145 ["hook", "local"],146 ["init", "local"],147 ["login", "local"],148 ["logout", "local"],149 ["mcp", "local"],150 ["schema", "local"],151 ["why", "local"],152 ]);153 });154155 it("sorts the commands by their words, so a command's subcommands follow it", () => {156 expect(157 words.filter((name) => name.startsWith("ask") || name.startsWith("env"))158 ).toStrictEqual([159 "ask",Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
line 160why, one step back160 "ask draft",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 161–166why, one step back161 "ask flag",162 "ask open",163 "asks",164 "env set",165 "env shape",166 ]);Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 167–172why, one step back167 expect(words.slice(0, 4)).toStrictEqual([168 "ask",169 "ask draft",170 "ask flag",171 "ask open",172 ]);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 173–179why, one step back173 });174175 it("gives a contract a hand-written command calls no row of its own", () => {176 expect(calling(docs, "initProject")).toStrictEqual(["init (local)"]);177 expect(calling(docs, "setEnv")).toStrictEqual(["env set (local)"]);178 });179});