Skip to content
Myr

Fit W4 group A together on main: every CLI test runs signed out, the binary runs on the real client, usage errors exit 2 as typed failures, and the heaviest tests get a hang limit

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- apps/cli/test/signed-out.ts, and the service layers in check, env-set, hook, init, why and remote-server (policy, remote, schema, surfaces): 412's `login`, `logout` and `credential` put `Credentials` in the command tree's requirements, so `program` needs it, and the tests 404, 405, 413, 414 and 415 wrote provided none (typecheck failed in 9 files). `SignedOut` holds no profile for any host; its `put` and `remove` die, so a test that writes a profile through it says so. - The merges of 413 and 414 took 404's `program` (90a806c, c92f070): a failure whose `Runtime.errorExitCode` is 2 is a usage error, printed in one line and ended as `Misused` (exit 2), which keeps 413's `InitMisused`; `init` fails with the shared `ApprovalNeeded` from `@repo/protocol/cli` (413 Comment 1); `refuseStrangeFlags(argv)` runs first (414 Comment 12). The stub table in main.test.ts is gone: every group A command is built. - 414's `usage` and 415's `HookUsage` are typed failures now, not defects: each carries its line as `message`, and `program` prints it once and exits 2 (414's and 415's leftovers, open until 404's `program` landed). Their tests pass unchanged. - apps/cli/src/bin.ts runs on `CliServices` (404 leftover 1; bin.ts's own comment said "until issue 404"): the binary called the platform through a placeholder that died. build.test.ts's helper case also asserts exit 0 and an empty stdout with no stored profile (416 Comment 1), and apps/cli/tsconfig.json includes build.ts (416 Comment 4; a tightening, typechecks clean). - build.test.ts's workspace-import pattern matched prose that tsdown keeps in doc comments ("from `@repo/git`'s `treeDiff`", from 405 and 413 sources now in bin.js). A static import or export names its module in quotes, never backticks, so only `import(`/`require(` accept a template literal. Probed: `from "…"`, `from '…'`, `import "…"`, `import("…")`, import with a template and `require("…")` still match. - init.test.ts and env-set.test.ts read 404's dry-run envelope, `data: {dryRun: true, payload}` (413 Comment 2). packages/protocol/test/cli.test.ts lists `evidence`, 418's contract on the cli surface, among the CLI paths. - Hang limits, 30 s, as the CLI's build, login and init tests already carry: the full `turbo run test` failed 3 of its first 5 runs with "Test timed out in 5000ms" on landing.model's invariant case (worst 5.8 s) and project.test.ts' story (worst 5.6 s). Alone they take 0.5 s and 0.4 s, and 2-3 s in a full run before group A merged; group A adds over 550 tests (2,280 to 2,833 in a full run), so the parallel run is busier. The limit now covers each test whose worst full-run time passed 3.3 s: the landing, claim and ratchet model describes, the project story, git's tree-diff longest-common-run case, the debt tally, and rules' equal-policies replay. No assertion changed. A planted 50 ms limit made landing.model's and the story's cases time out, so a describe-level option reaches its tests. After: verify and four more full runs green in a row. - verify green: cli 234, platform 323, protocol 356, project 330, checks 292, gate 185, config 743, agent-kit 56; debt at baseline; gen current; platform entry 1,547,725 of 1,665,000, sandbox 474,690. - ASSUMPTION: the platform entry's growth (1,513,290 to 1,547,725) is 418's evidence store, 419's Google sign-in and 420's releases; not measured per branch here.

authored by oscabriel · committed by oscabriel · parent 878da37 · Browse files · 21 files+146 added−74 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

21 files+146 added−74 removed

  • tests:+123 added−40 removed
  • other:+23 added−34 removed

21 files+146 added−74 removed

modified:apps/cli/src/local/env-set.ts+2 added-1 removed
22 unmodified lines
23import { Output } from "../output.ts";24import type { Mode } from "../output.ts";25import { repoContext } from "../repo-context.ts";26import { WorkingDirectory, projectOf, reportRefusals, usage } from "./why.ts";27import type { UsageError } from "./why.ts";2829const command = "env set";3031const encodeSet = Schema.encodeEffect(SetEnv.successSchema);
97 unmodified lines
129 * which refuses them as `not-the-value`.130 */131export const refuseStrangeFlags = (132 argv: readonly string[]132): Effect.Effect<void, never, Output> => {133): Effect.Effect<void, UsageError> => {134 const end = argv.indexOf("--");135 const words = end === -1 ? argv : argv.slice(0, end);136137 const at = words.findIndex(
105 unmodified lines
modified:apps/cli/src/local/why.ts+8 added-8 removed
39 unmodified lines
40 { defaultValue: () => "." }41);4243/**44 * A command used wrongly: its one line is already on stderr, and the44 * A command used wrongly: `program` prints its one line on stderr and the45 * process exits 2 with nothing more printed. Shared with `env set`.46 */47export class UsageError extends Schema.TaggedError<UsageError>()("UsageError", {48 reason: Schema.String,49}) {50 override readonly [Runtime.errorExitCode] = 2;51 override readonly [Runtime.errorReported] = false;5253 override get message() {54 return this.reason;55 }56}5758/**55 * Prints `reason` once on stderr and ends the command with exit 2. It ends56 * as a defect only because `program` turns every typed failure into57 * `Reported` (exit 1) and lets defects through; 414's Comments ask for a58 * typed failure once `program` maps usage errors to exit 2 (issue 404).59 * Ends the command as a usage error: `program` prints `reason` once on60 * stderr, as it does every misuse, and exits 2.61 */62export const usage = (reason: string) =>61 Output.use((output) => output.note(reason)).pipe(62 Effect.andThen(Effect.die(new UsageError({ reason })))63 );63 Effect.fail(new UsageError({ reason }));6465const isRefusal = Schema.is(Refusal);6667/**
344 unmodified lines
modified:apps/cli/src/bin.ts+4 added-15 removed
modified:apps/cli/src/hook.ts+8 added-9 removed
34 unmodified lines
35import { loadSession, saveSession } from "./hook/session.ts";36import type { SessionState } from "./hook/session.ts";37import { Output } from "./output.ts";3839const EVENTS = HookEvent.literals.join(", ");4041/**42 * The hook was called with an event it does not answer: its config is41 * wrong. A defect, so the program's exit-1 mapping of failures leaves its42 * exit code (2, a usage error) alone; its usage was printed already.43 * wrong. A usage error: `program` prints its one line and exits 2.44 */45export class HookUsage extends Schema.TaggedError<HookUsage>()("HookUsage", {46 event: Schema.String,47}) {48 override readonly [Runtime.errorExitCode] = 2;49 override readonly [Runtime.errorReported] = false;5051 override get message() {52 return `hook: no event ${this.event}; the events are ${EVENTS}`;53 }54}5551const EVENTS = HookEvent.literals.join(", ");5256const decodeEvent = Schema.decodeUnknownOption(HookEvent);5758/** The whole of stdin, as text. */59const stdinText = Effect.flatMap(Stdio.Stdio, ({ stdin }) =>
109 unmodified lines
169 Effect.gen(function* () {170 const event = decodeEvent(name);171172 if (Option.isNone(event)) {170 yield* Output.use((output) =>171 output.note(`hook: no event ${name}; the events are ${EVENTS}`)172 );173174 return yield* Effect.die(new HookUsage({ event: name }));173 return yield* new HookUsage({ event: name });174 }175176 const input = yield* Effect.flatMap(stdinText, decodeHookInput).pipe(177 Effect.option
42 unmodified lines
modified:apps/cli/test/local/check.test.ts+3 added-1 removed
48 unmodified lines
4950import { ConfigBundlerBun, localPolicy } from "../../src/local/local-policy.ts";51import { program } from "../../src/main.ts";52import { OutputPlain } from "../../src/output.ts";53import { SignedOut } from "../signed-out.ts";54import {55 aCheckRepo,56 ask,57 checkFile,
26 unmodified lines
84 Layer.mergeAll(85 TestConsole.layer,86 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),87 client,87 OutputPlain88 OutputPlain,89 SignedOut90 ).pipe(Layer.provideMerge(NodeServices.layer));9192/** Runs the CLI on `argv`: how it ended, and what it printed where. */93const run = (argv: readonly string[]) =>
388 unmodified lines
modified:apps/cli/test/local/env-set.test.ts+4 added-1 removed
33 unmodified lines
34import { refuseStrangeFlags } from "../../src/local/env-set.ts";35import { program } from "../../src/main.ts";36import { Output, OutputPlain } from "../../src/output.ts";37import type { Mode } from "../../src/output.ts";38import { SignedOut } from "../signed-out.ts";3940/** A value no output, note or log line may ever hold. */41const secret = "sk_live_0123456789abcdef";42
138 unmodified lines
181 Layer.mergeAll(182 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),183 platform,184 output,185 SignedOut,186 terminal,187 Logger.layer([188 Logger.make((options) => {189 logged.push(Logger.formatSimple.log(options));
236 unmodified lines
426 ]);427 expect(yield* decodeEnvelope(ran.out)).toStrictEqual({428 command: "env set",429 data: {428 dryRun: {430 dryRun: true,431 payload: {432 key: "SENTRY_AUTH_TOKEN",433 project: "datekit",434 value: "<redacted>",435 },
78 unmodified lines
modified:apps/cli/test/local/init.test.ts+8 added-4 removed
27 unmodified lines
2829import { projectFile } from "../../src/local/project-file.ts";30import { program } from "../../src/main.ts";31import { OutputPlain } from "../../src/output.ts";32import { SignedOut } from "../signed-out.ts";3334const CONFIG = `${Brand.configDir}/project.ts`;3536const scripts = {
170 unmodified lines
207 TestConsole.layer,208 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),209 OutputPlain,210 platform,211 SignedOut,212 startedIn(machine)213 )214 )215 );
160 unmodified lines
376377 const Plan = Schema.Struct({378 command: Schema.Literal("init"),379 data: Schema.Struct({378 dryRun: Schema.Struct({380 dryRun: Schema.Literal(true),381 payload: Schema.Struct({382 files: Schema.Array(383 Schema.Struct({ content: Schema.String, path: Schema.String })384 ),385 git: Schema.Array(Schema.Array(Schema.String)),
2 unmodified lines
388 }),389 ok: Schema.Literal(true),390 });391389 const { dryRun } = (yield* Schema.decodeUnknownEffect(Plan)(envelope))390 .data;392 const { payload: plan } = (yield* Schema.decodeUnknownEffect(Plan)(393 envelope394 )).data;395392 expect(dryRun).toStrictEqual({396 expect(plan).toStrictEqual({397 files: [{ content: proposal, path: CONFIG }],398 git: [399 ["git", "add", "--", CONFIG],400 [
411 unmodified lines
modified:apps/cli/test/local/why.test.ts+3 added-1 removed
41 unmodified lines
4243import { WorkingDirectory, parseLocation } from "../../src/local/why.ts";44import { program } from "../../src/main.ts";45import { Output, OutputPlain } from "../../src/output.ts";46import { SignedOut } from "../signed-out.ts";4748const project = ProjectName.make("datekit");4950const alice = Handle.make("alice");
156 unmodified lines
207 Layer.mergeAll(208 TestConsole.layer,209 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),210 client,210 output211 output,212 SignedOut213 )214 )215 );216
309 unmodified lines
modified:apps/cli/test/build.test.ts+8 added-3 removed
222 unmodified lines
223/** What git hands a credential helper: the host, then a blank line. */224const request = "protocol=https\nhost=example.test\n\n";225226/**227 * An import, export, `import()` or `require` of a workspace package (prose228 * in a comment may still name one).227 * An import, export, `import()` or `require` of a workspace package. A228 * static import or export names its module in quotes, never backticks, so229 * prose in a kept doc comment ("from `@repo/git`'s `treeDiff`") is not one;230 * only a call may take a template literal.231 */232const workspaceSpecifier =231 /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)["'`]@repo\//u;233 /(?:\b(?:from|import)\s*["']|\b(?:import|require)\s*\(\s*["'`])@repo\//u;234235layer(BuiltOnce, { excludeTestServices: true, timeout: "180 seconds" })(236 "bun run build",237 (it) => {
74 unmodified lines
312 only: onPath,313 stdin: request,314 });315316 // No profile is stored under the temp HOME: the helper says317 // nothing, so git goes on without a credential.318 expect(helper).toMatchObject({ exitCode: 0, stdout: "" });319 expect(helper).toStrictEqual(direct);320 expect(helper).not.toStrictEqual(unrouted);321 }),322 spawning
140 unmodified lines
modified:apps/cli/test/hook.test.ts+2 added
59 unmodified lines
60 pushCheckWith,61} from "../src/hook/push-check.ts";62import { program } from "../src/main.ts";63import { OutputPlain } from "../src/output.ts";64import { SignedOut } from "./signed-out.ts";6566/** The repo's top folder, as the session found it. */67const root = "/work/datekit";68
545 unmodified lines
614 TestConsole.layer,615 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),616 OutputPlain,617 services,618 SignedOut,619 ConfigProvider.layer(620 ConfigProvider.fromEnv({621 env: Predicate.isString(env) ? { XDG_STATE_HOME: env } : { ...env },622 })
513 unmodified lines
modified:apps/cli/test/remote-server.ts+3 added-1 removed
28 unmodified lines
29import { program } from "../src/main.ts";30import { OutputLive } from "../src/output.ts";31import { policyFor } from "../src/policy.ts";32import { WorkingDirectory } from "../src/surfaces.ts";33import { SignedOut } from "./signed-out.ts";3435/** Handlers for every contract, as a test sets them up. */36export type Handlers = Layer.Layer<37 Rpc.ToHandler<RpcGroup.Rpcs<typeof Contracts>>
59 unmodified lines
97 Layer.provide([handlers, asTester])98 ),99 policy,100 OutputLive.pipe(Layer.provide(policy)),100 promptless(prompts)101 promptless(prompts),102 SignedOut103 );104105 const run = Effect.gen(function* () {106 const exit = yield* Effect.exit(program(args));
103 unmodified lines
added:apps/cli/test/signed-out.ts+14 added
1/**2 * Credentials for a run where nobody has logged in: no profile, for any3 * host. `login` and `logout` are in the command tree, so `program` needs4 * `Credentials`; a test that writes a profile through this layer is wrong,5 * and the mock's unimplemented `put` and `remove` die and say so.6 */7import { Effect, Layer } from "effect";89import { Credentials } from "../src/credentials.ts";1011export const SignedOut = Layer.mock(Credentials)({12 current: Effect.succeedNone,13 forHost: () => Effect.succeedNone,14});
modified:apps/cli/tsconfig.json+1 added-1 removed
1 unmodified line
2 "extends": "../../tsconfig.base.json",3 "compilerOptions": {4 "allowImportingTsExtensions": true5 },6 "include": ["src/**/*.ts", "test/**/*.ts", "*.config.ts"]6 "include": ["src/**/*.ts", "test/**/*.ts", "*.config.ts", "build.ts"]7}
modified:packages/config/test/fence-wiring.test.ts+22 added-16 removed
72 unmodified lines
73 );74});7576describe("the debt count", () => {77 it.live(78 "matches debt.baseline.json over the tree as it stands",77 it.live("matches debt.baseline.json over the tree as it stands", () =>78 Effect.gen(function* () {79 const path = yield* Path.Path;80 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;81 const root = yield* repoRoot;82 const baseline = yield* readRootJson("debt.baseline.json", Tally);79 () =>80 Effect.gen(function* () {81 const path = yield* Path.Path;82 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;83 const root = yield* repoRoot;84 const baseline = yield* readRootJson("debt.baseline.json", Tally);8584 const report = yield* spawner.string(85 ChildProcess.make(86 path.join(root, "node_modules/.bin/oxlint"),87 ledgerArgs,88 { cwd: root }89 )90 );86 const report = yield* spawner.string(87 ChildProcess.make(88 path.join(root, "node_modules/.bin/oxlint"),89 ledgerArgs,90 { cwd: root }91 )92 );9392 const ledger = yield* ledgerFromOxlintJson(report);94 const ledger = yield* ledgerFromOxlintJson(report);9594 expect(tally(ledger)).toStrictEqual(baseline);95 }).pipe(Effect.provide(NodeServices.layer))96 expect(tally(ledger)).toStrictEqual(baseline);97 }).pipe(Effect.provide(NodeServices.layer)),98 // oxlint over the whole tree, which grows each wave: under half a second99 // alone, near four while turbo runs every package's tests at once. The100 // limit catches a hang.101 30_000102 );103104 it.effect(105 "reads each directive, and its line, from oxlint's JSON report",
211 unmodified lines
modified:packages/git/test/tree-diff.test.ts+5 added-1 removed
442 unmodified lines
443 cases.filter(444 ({ kept, longest, subsequence }) => !subsequence || kept !== longest445 )446 ).toStrictEqual([]);447 }).pipe(Effect.provide(RepoHostMemory))447 }).pipe(Effect.provide(RepoHostMemory)),448 // Sixty repos of real git objects: a fifth of a second alone, near four449 // while turbo runs every package's tests at once. The limit catches a450 // hang.451 30_000452 );453});
modified:packages/project/test/claim.model.test.ts+9 added-1 removed
635 unmodified lines
636637 return [];638};639640/**641 * Generated histories are CPU work alone: under a second on an idle machine,642 * several seconds while turbo runs every package's tests at once (the CLI's643 * build test compiles binaries beside them). This limit is there to catch a644 * hang, not a busy machine.645 */646const generated = { timeout: 30_000 };647640describe("the claim lifecycle, over generated histories", () => {648describe("the claim lifecycle, over generated histories", generated, () => {649 it.prop(650 "keeps every invariant after every step",651 { history: histories, layout: layouts },652 ({ history, layout }) => {
7 unmodified lines
modified:packages/project/test/landing.model.test.ts+10 added-2 removed
666 unmodified lines
667 onFailure: (violation) => Effect.fail(violation),668 onSuccess: () => Effect.succeed(true),669 });670671/**672 * Generated histories are CPU work alone: under a second on an idle machine,673 * several seconds while turbo runs every package's tests at once (the CLI's674 * build test compiles binaries beside them). This limit is there to catch a675 * hang, not a busy machine.676 */677const generated = { timeout: 30_000 };678671describe("the landing lifecycle over generated histories", () => {679describe("the landing lifecycle over generated histories", generated, () => {680 it.effect("keeps every invariant after every step", () =>681 Effect.gen(function* () {682 const result = yield* Arbitrary.checkEffect(histories, holds, {683 runs: 3000,
116 unmodified lines
800801 return Effect.succeed(true);802};803796describe("the landing queue over generated histories", () => {804describe("the landing queue over generated histories", generated, () => {805 it.effect("never admits a second request while one is landing", () =>806 Effect.gen(function* () {807 const result = yield* Arbitrary.checkEffect(808 Arbitrary.array(Arbitrary.schema(QueueMove), { maxLength: 30 }),
8 unmodified lines
modified:packages/project/test/project.test.ts+9 added
624 unmodified lines
625 },626 ]);627});628629/**630 * The first case runs the whole story (real git objects, every gate stage,631 * each landing): under half a second alone, near five while turbo runs every632 * package's tests at once. This limit is there to catch a hang, not a busy633 * machine.634 */635const wholeStory = { timeout: 30_000 };636637describe.each(["memory", "sqlite"] as const)(638 "one project over memory adapters, its store in %s",639 wholeStory,640 (store: StoreKind) => {641 const seen = story.pipe(Effect.provide(worldOf(scenario, store)));642643 it.effect(
633 unmodified lines
modified:packages/project/test/ratchets.test.ts+9 added-1 removed
496 unmodified lines
497 onFailure: (violation) => Effect.fail(violation),498 onSuccess: () => Effect.succeed(true),499 });500501/**502 * Generated histories are CPU work alone: under a second on an idle machine,503 * several seconds while turbo runs every package's tests at once (the CLI's504 * build test compiles binaries beside them). This limit is there to catch a505 * hang, not a busy machine.506 */507const generated = { timeout: 30_000 };508501describe("ratchets over generated histories", () => {509describe("ratchets over generated histories", generated, () => {510 it.effect("no baseline rises but through an accepted RaiseRatchet", () =>511 Effect.gen(function* () {512 const result = yield* Arbitrary.checkEffect(histories, holds, {513 runs: 2000,
31 unmodified lines
modified:packages/protocol/test/cli.test.ts+1 added
569 unmodified lines
570 "finish",571 "land",572 "fork",573 "vouch",574 "evidence",575 ]);576 });577578 it.effect("renders each result with the view its tag names", () =>
13 unmodified lines
modified:packages/rules/test/replay.test.ts+13 added-8 removed
61 unmodified lines
62const stampOf = (policy: typeof Policy.Encoded) =>63 policy.asks[0]?.brief.context;6465describe("evaluating a config folder twice", () => {66 it.live(67 "gives equal policies for equal facts",66 it.live("gives equal policies for equal facts", () =>67 Effect.gen(function* () {68 for (const modules of [yield* folder("cm"), yield* readsTheClock]) {69 const first = yield* evaluated(modules);70 const second = yield* evaluated(modules);68 () =>69 Effect.gen(function* () {70 for (const modules of [yield* folder("cm"), yield* readsTheClock]) {71 const first = yield* evaluated(modules);72 const second = yield* evaluated(modules);7372 expect(second).toStrictEqual(first);73 }74 }).pipe(Effect.provide(bunEvaluator()))74 expect(second).toStrictEqual(first);75 }76 }).pipe(Effect.provide(bunEvaluator())),77 // Four bun processes: a third of a second alone, near four while turbo78 // runs every package's tests at once. The limit catches a hang.79 30_00080 );8182 it.live("gives config code the facts' clock, not the wall clock", () =>83 Effect.gen(function* () {
50 unmodified lines