|
| 1 | +/** |
| 2 | + * Adversarial coverage for the v0.12.3 release payload (v0.12.2..HEAD): the Altimate Base |
| 3 | + * no-consent-gate PR (#1361, 429/49 tests of its own — see the entrypoint-late-notice-wiring |
| 4 | + * pin) plus the routing-pin fix, PLUS the two P0s and P1 found by this release's own |
| 5 | + * multi-persona review and fixed here: |
| 6 | + * |
| 7 | + * - `altimate agent create` and `altimate review` never called `FreeTier.autoRegisterWithin()` |
| 8 | + * before resolving a provider (Chaos Gremlin/Support Engineer persona, both P0): a fresh |
| 9 | + * install's first `agent create` or `review` run failed with a raw upstream error / silently |
| 10 | + * produced zero AI findings, because no provider had ever been registered. |
| 11 | + * - `tui.ts`'s up-to-3s auto-register wait gave zero terminal feedback on a fresh install |
| 12 | + * (End User persona, P1): reads as a hang on the very first launch. |
| 13 | + * |
| 14 | + * This file does NOT re-test PR #1361's own extensive coverage (stale-zen-cycle, |
| 15 | + * altimate-base-auto-register, altimate-base-headless-disclosure, routing-pin, etc. — all |
| 16 | + * re-run and confirmed green during this release's Step 5/5c). It targets only the NEW code |
| 17 | + * from this release's fixes, following the source-assertion pattern already established in |
| 18 | + * test/altimate/entrypoint-late-notice-wiring.test.ts for these same Effect-based / heavy CLI |
| 19 | + * command files. |
| 20 | + */ |
| 21 | +import { describe, test, expect } from "bun:test" |
| 22 | +import { readFileSync } from "fs" |
| 23 | +import { join, resolve } from "path" |
| 24 | + |
| 25 | +const cmdDir = resolve(import.meta.dir, "..", "..", "src", "cli", "cmd") |
| 26 | + |
| 27 | +function read(file: string): string { |
| 28 | + return readFileSync(join(cmdDir, file), "utf-8") |
| 29 | +} |
| 30 | + |
| 31 | +describe("v0.12.3: agent.ts / review.ts auto-register ordering", () => { |
| 32 | + test("agent.ts registers Altimate Base BEFORE resolving/calling Agent.generate", () => { |
| 33 | + const source = read("agent.ts") |
| 34 | + const registerIdx = source.indexOf("autoRegisterWithin(") |
| 35 | + const generateIdx = source.indexOf("agentSvc.generate(") |
| 36 | + expect(registerIdx, "agent.ts must call autoRegisterWithin()").toBeGreaterThan(-1) |
| 37 | + expect(generateIdx, "agent.ts must call agentSvc.generate()").toBeGreaterThan(-1) |
| 38 | + // Registering AFTER the model/provider is already being resolved defeats the fix: a fresh |
| 39 | + // install would still hit the unregistered path on its first LLM call. |
| 40 | + expect(registerIdx, "registration must precede the generate() call, not follow it").toBeLessThan(generateIdx) |
| 41 | + }) |
| 42 | + |
| 43 | + test("agent.ts's registration call is not swallowed inside the generate() error handler", () => { |
| 44 | + const source = read("agent.ts") |
| 45 | + // The existing `.catch((error) => { spinner.stop(...) ... })` on agentSvc.generate() must |
| 46 | + // stay scoped to the generate call only — folding registration into that same try/catch |
| 47 | + // would mask a registration failure as a generic "LLM failed to generate agent" message. |
| 48 | + const catchIdx = source.indexOf(".catch((error) => {") |
| 49 | + const registerIdx = source.indexOf("autoRegisterWithin(") |
| 50 | + expect(catchIdx, "the existing generate() catch handler must still be present").toBeGreaterThan(-1) |
| 51 | + expect(registerIdx).toBeLessThan(catchIdx) |
| 52 | + }) |
| 53 | + |
| 54 | + test("review.ts registers Altimate Base BEFORE reviewPullRequest AND outside the latency timer", () => { |
| 55 | + const source = read("review.ts") |
| 56 | + const registerIdx = source.indexOf("autoRegisterWithin(") |
| 57 | + const reviewCallIdx = source.indexOf("await reviewPullRequest({") |
| 58 | + const timerIdx = source.indexOf("const startedAt = Date.now()") |
| 59 | + expect(registerIdx, "review.ts must call autoRegisterWithin()").toBeGreaterThan(-1) |
| 60 | + expect(reviewCallIdx, "review.ts must call reviewPullRequest()").toBeGreaterThan(-1) |
| 61 | + expect(timerIdx, "review.ts must still time the engine via startedAt").toBeGreaterThan(-1) |
| 62 | + expect(registerIdx, "registration must precede the review call").toBeLessThan(reviewCallIdx) |
| 63 | + // A registration wait folded into the timed region would inflate every review_run latency |
| 64 | + // metric on a fresh install (or after a credential rotation) with startup cost that has |
| 65 | + // nothing to do with the review engine itself. |
| 66 | + expect(registerIdx, "registration must be excluded from the engine latency timer").toBeLessThan(timerIdx) |
| 67 | + }) |
| 68 | + |
| 69 | + test("review.ts's registration call runs even when --no-ai is set (matches R1: registers regardless of the caller's own model)", () => { |
| 70 | + const source = read("review.ts") |
| 71 | + const registerIdx = source.indexOf("autoRegisterWithin(") |
| 72 | + const noAiCheckIdx = source.indexOf("noAi:") |
| 73 | + expect(registerIdx).toBeGreaterThan(-1) |
| 74 | + // The registration call must be unconditional — not gated behind `!args.noAi` — so the |
| 75 | + // CI `--post --mode gate` deterministic-only path still benefits the NEXT invocation that |
| 76 | + // does use the AI lane. Asserted by requiring no `noAi`/`args.ai` reference appears between |
| 77 | + // the register call and its own closing brace. |
| 78 | + const blockEnd = source.indexOf("// altimate_change end", registerIdx) |
| 79 | + const between = source.slice(registerIdx, blockEnd) |
| 80 | + expect(between, "the registration block must not branch on noAi/args.ai").not.toMatch(/noAi|args\.ai\b/) |
| 81 | + expect(noAiCheckIdx).toBeGreaterThan(blockEnd) |
| 82 | + }) |
| 83 | +}) |
| 84 | + |
| 85 | +describe("v0.12.3: tui.ts startup-feedback timer", () => { |
| 86 | + function readTui(): string { |
| 87 | + return readFileSync(join(cmdDir, "tui.ts"), "utf-8") |
| 88 | + } |
| 89 | + |
| 90 | + test("the feedback timer is gated behind a short, non-zero delay (never fires instantly)", () => { |
| 91 | + const source = readTui() |
| 92 | + const match = source.match(/setTimeout\(\(\) => UI\.println\("Connecting to Altimate Base…"\), (\d+)\)/) |
| 93 | + expect(match, "tui.ts must set a delayed status line before autoRegisterWithin()").not.toBeNull() |
| 94 | + const delayMs = Number(match![1]) |
| 95 | + // Zero (or missing) would flash on every launch, including the fast/already-registered |
| 96 | + // path this delay exists to protect; too long would defeat the "no feedback during a |
| 97 | + // fresh-install hang" fix End User flagged. Bounded to a sane window around the ~250-300ms |
| 98 | + // suggestion rather than pinned to one exact value. |
| 99 | + expect(delayMs).toBeGreaterThan(0) |
| 100 | + expect(delayMs).toBeLessThanOrEqual(500) |
| 101 | + }) |
| 102 | + |
| 103 | + test("the feedback timer is always cleared, even if autoRegisterWithin() throws", () => { |
| 104 | + const source = readTui() |
| 105 | + const start = source.indexOf("const registerFeedback = setTimeout(") |
| 106 | + expect(start, "must find the registerFeedback timer declaration").toBeGreaterThan(-1) |
| 107 | + const scope = source.slice(start, start + 400) |
| 108 | + // Must be a try/finally around the await, not a bare await — a throw from |
| 109 | + // autoRegisterWithin() (it currently never throws, but must not be relied upon) would |
| 110 | + // otherwise leak the timer and could still print the status line after the process is |
| 111 | + // already tearing down. |
| 112 | + expect(scope).toMatch(/try\s*\{[\s\S]*?await FreeTier\.autoRegisterWithin\(\)[\s\S]*?\}\s*finally\s*\{[\s\S]*?clearTimeout\(registerFeedback\)/) |
| 113 | + }) |
| 114 | + |
| 115 | + test("autoRegisterWithin() is still called with no arguments in tui.ts (unchanged contract: TUI renders its own onboarding, no headless callback)", () => { |
| 116 | + const source = readTui() |
| 117 | + // Regression guard: wrapping the call in a delayed-feedback block must not have also, |
| 118 | + // accidentally, started passing a headless disclosure callback — the TUI's own |
| 119 | + // useAltimateBaseDisclosureNotice() owns that surface; a second notice source here would |
| 120 | + // double-print. |
| 121 | + expect(source).toMatch(/await FreeTier\.autoRegisterWithin\(\)\s*$/m) |
| 122 | + }) |
| 123 | +}) |
0 commit comments