Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit f527f538607c36aa07a06798ce0c750fcc651bd6
parent e25ed384e2bb1a52ea97a66227ac564fd49c9c3f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 12:00:28 -0400

editor e2e: report-draft refresh — the plan, no change $0, an update with the restricted sweep, the editor's own door

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Meditor/e2e/report-draft.spec.ts | 129++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 125 insertions(+), 4 deletions(-)

diff --git a/editor/e2e/report-draft.spec.ts b/editor/e2e/report-draft.spec.ts @@ -6,9 +6,9 @@ import { fileURLToPath } from "node:url"; // By relative path, as digest.spec.ts imports common: the test kit's fakes and // the synthetic corpus are plain .mjs. import { FAKE_KEY, startFakeAnthropic, textTurn, toolTurn, type FakeAnthropic } from "../../common/testing/llm/fakeAnthropic.mjs"; -import { ORIGIN, writeDraftCorpus } from "../../common/testing/draft/corpus.mjs"; +import { LATE_RECORD, ORIGIN, withRecords, writeDraftCorpus } from "../../common/testing/draft/corpus.mjs"; import { baseUrl } from "./baseUrl"; -import { resetData, testPaths, writeSettings } from "./helpers"; +import { resetData, testPaths, writeChannelConfig, writeSettings } from "./helpers"; // `pnpm ops report-draft` end to end (release 27 S6): the editor against the // fake Anthropic (started here, on loopback; settings point at it with a @@ -34,8 +34,8 @@ test.afterAll(async () => { await rm(keyDir, { recursive: true, force: true }); }); -async function setup(caps: Record<string, number> = {}) { - await resetData(null); +async function setup(caps: Record<string, number> = {}, fixture: string | null = null) { + await resetData(fixture); const keyFile = join(keyDir, "anthropic.env"); await writeFile(keyFile, `ANTHROPIC_API_KEY=${FAKE_KEY}\n`); await chmod(keyFile, 0o600); @@ -198,3 +198,124 @@ test("a media draft (release 28 M3): a teaser on the API, a step on the done ite expect(api.remaining()).toBe(0); }); + +// ─── a refresh (umtool R4) ─── + +const KIT = join(RUNS, ".."); + +// i1 of `article`: the kit's basic sweep, done, with the trace of the one +// enumeration it ran (over `channel`, read from `build`). +async function doneBasicSweep(article: string, o: { channel?: string; report?: unknown; build?: string } = {}) { + const channel = o.channel ?? "synth-kitchen"; + const itDir = join(testPaths().transcriptsDir, "reports", article, "iterations", "1"); + await mkdir(itDir, { recursive: true }); + const at = new Date().toISOString(); + await writeFile( + join(itDir, "iteration.json"), + JSON.stringify({ + format: "archilyzer-iteration", version: 1, article, n: 1, kind: "sweep", parent: null, copyOf: null, model: "claude-sonnet-5-5", + question: "What does the baker say about the contest?", scope: { channels: [channel] }, status: "done", + usage: { "claude-sonnet-5-5": { usd: 0.4, inputTokens: 1, outputTokens: 1 } }, coverage: { matched: 1, read: 2, partial: false, unreached: [] }, + steps: [], createdAt: at, updatedAt: at, endedAt: at, + }), + ); + const report = o.report ?? { ...JSON.parse(await readFile(join(KIT, "reports", "basic.report.json"), "utf8")), id: article }; + await writeFile(join(itDir, "report.json"), JSON.stringify(report)); + await writeFile(join(itDir, "sweep.md"), await readFile(join(KIT, "sweeps", "basic.md"), "utf8")); + const build = o.build ?? join(testPaths().transcriptsDir, ".export-builds", "draft-e2e", "out"); + const trace = [ + { t: "run", at, run: 1, phase: "start", task: "sweep-agent", model: "claude-sonnet-5-5" }, + { t: "scope", at, run: 1, source: `local:${build}`, channels: [channel], question: "What does the baker say about the contest?" }, + { t: "enumerate", at, run: 1, query: "contest", n: 1, ids: ["pie-stream-02"], partial: false, unreached: [], counts: { "pie-stream-02": 2 } }, + ]; + await writeFile(join(itDir, "trace.jsonl"), trace.map((e) => JSON.stringify(e)).join("\n") + "\n"); +} + +test("a refresh over ops: the plan (dryRun, nothing written), then the job — the fetch skipped where it cannot run, no change, $0", async ({ request }) => { + test.setTimeout(120_000); + await setup(); + await doneBasicSweep("synth-refresh"); + const planned = await request.post(`${baseUrl}/api/ops/report-draft`, { headers: AUTH, data: { task: "refresh", article: "synth-refresh", dryRun: true } }); + expect(planned.status()).toBe(200); + const { plan } = (await planned.json()) as { plan: { parent: { n: number; queries: string[] }; channels: { slug: string; skip?: string }[]; build: { site: string | null; reason?: string }; capUsd: number } }; + expect(plan.parent).toMatchObject({ n: 1, queries: ["contest"] }); + expect(plan.channels).toEqual([{ slug: "synth-kitchen", kind: null, platform: null, actions: [], skip: "not a channel of this editor" }]); + expect(plan.build).toMatchObject({ site: null, reason: "the build draft-e2e is not a site's: it is read as it stands" }); + expect(plan.capUsd).toBe(3); + await expect(readFile(join(testPaths().transcriptsDir, "reports", "synth-refresh", "iterations", "2", "iteration.json"))).rejects.toThrow(/ENOENT/); + + const before = api.requests.length; + const { status, body } = await draft(request, { task: "refresh", article: "synth-refresh" }); + expect(status, body.error).toBe(200); + expect(body.iteration).toBe(2); + const job = await jobUntil(request, body.jobId!, (s) => ["done", "failed", "cancelled"].includes(s)); + const tail = (job.tail ?? []).join("\n"); + expect(job.job?.status ?? job.status, tail).toBe("done"); + expect(tail).toContain('"task":"refresh"'); + expect(tail).toMatch(/"refresh":\{"status":"no-change","newIds":0,"changed":0,"drifted":0,"deleted":0,"summary":"Nothing new since 20\d\d-/); + expect(api.requests.length, "no model was asked").toBe(before); + const it = await iterationJson("synth-refresh", 2); + expect(it).toMatchObject({ kind: "refresh", parent: 1, status: "done", jobId: body.jobId, refresh: { status: "no-change" } }); + const f = JSON.parse(await readFile(join(testPaths().transcriptsDir, "reports", "synth-refresh", "iterations", "2", "refresh.json"), "utf8")); + expect(f.fetch).toEqual([{ channel: "synth-kitchen", action: "sync", status: "skipped", reason: "not a channel of this editor" }]); + expect(f.build).toMatchObject({ site: null, status: "skipped" }); + expect(f.delta.quotes).toHaveLength(6); +}); + +test("a refresh that finds a new recording: a sweep restricted to it, then the report revised — a new iteration with its finding", async ({ request }) => { + test.setTimeout(120_000); + await setup(); + await doneBasicSweep("synth-refreshed"); + // A later build holds one recording more. + await writeDraftCorpus(join(testPaths().transcriptsDir, ".export-builds", "draft-e2e", "out"), { channels: withRecords([LATE_RECORD]) }); + const link = `${ORIGIN}/?v=synth-kitchen%2Fcontest-stream-04&t=5`; + api.push( + toolTurn("enumerate_matches", { query: "contest", channels: ["synth-kitchen"] }), + toolTurn("write_report", { markdown: `# New on the contest\n\nOne new stream mentions it.\n\n## The contest\n\n- She says she was not a judge: "I was not a judge at the contest this year either" [Contest results @ 0:05](${link})\n` }), + textTurn("sweep.md: 1 finding."), + toolTurn("apply_ops", { ops: [{ op: "add", section: "The contest", text: "She says she was not a judge", quote: "I was not a judge at the contest this year either", link }] }), + textTurn("Added the new finding."), + ); + const { status, body } = await draft(request, { task: "refresh", article: "synth-refreshed", model: "claude-sonnet-5-5", fetch: false }); + expect(status, body.error).toBe(200); + const job = await jobUntil(request, body.jobId!, (s) => ["done", "failed", "cancelled"].includes(s)); + const tail = (job.tail ?? []).join("\n"); + expect(job.job?.status ?? job.status, tail).toBe("done"); + expect(tail).toMatch(/"refresh":\{"status":"updated","newIds":1,"changed":0,"drifted":0,"deleted":0/); + expect(api.remaining()).toBe(0); + const dir = join(testPaths().transcriptsDir, "reports", "synth-refreshed", "iterations", "2"); + const f = JSON.parse(await readFile(join(dir, "refresh.json"), "utf8")); + expect(f).toMatchObject({ status: "updated", delta: { newIds: ["contest-stream-04"] }, update: { sweep: { ids: ["contest-stream-04"], findings: 1 }, revision: { status: "done" } } }); + const report = JSON.parse(await readFile(join(dir, "report.json"), "utf8")); + expect(Object.values(report.citations).some((c) => (c as { id?: string }).id === "contest-stream-04")).toBe(true); + const ledger = await readFile(join(testPaths().transcriptsDir, ".generation-usage.jsonl"), "utf8"); + expect(ledger).toContain('"task":"refresh"'); +}); + +test("a refresh through the editor's own door: the channel's sync and its report run as jobs, then the delta", async ({ request }) => { + test.setTimeout(150_000); + await setup({}, "two-slow-channels"); + // slow-b without its --test-slow flag: a sync that finishes in seconds. + await writeChannelConfig("slow-b", { name: "Slow B", url: "https://www.youtube.com/@slow-b/videos" }); + // A composed build holding slow-b, and an article citing it. + const rec = { ...LATE_RECORD, channelSlug: "slow-b", channel: "Slow B", slug: "slow-b/contest-stream-04" }; + const build = join(testPaths().transcriptsDir, ".export-builds", "slowb", "out"); + await writeDraftCorpus(build, { channels: [{ slug: "slow-b", name: "Slow B", platform: "youtube", records: [rec] }] }); + const report = { + format: "archilyzer-report", version: 1, id: "slowb-refresh", kind: "sweep", title: "Slow B on the contest", summary: "One finding.", + citations: { c1: { kind: "video", channel: "slow-b", id: "contest-stream-04", start: 5, end: 9.8, quote: "I was not a judge at the contest this year either" } }, + sections: [{ id: "s1", title: "The contest", body: "She [was not a judge](cite:c1)." }], + }; + await doneBasicSweep("slowb-refresh", { channel: "slow-b", report, build }); + const { status, body } = await draft(request, { task: "refresh", article: "slowb-refresh" }); + expect(status, body.error).toBe(200); + const job = await jobUntil(request, body.jobId!, (s) => ["done", "failed", "cancelled"].includes(s), 120_000); + const tail = (job.tail ?? []).join("\n"); + expect(job.job?.status ?? job.status, tail).toBe("done"); + const f = JSON.parse(await readFile(join(testPaths().transcriptsDir, "reports", "slowb-refresh", "iterations", "2", "refresh.json"), "utf8")); + const sync = f.fetch.find((s: { action: string }) => s.action === "sync"); + expect(sync, JSON.stringify(f.fetch)).toMatchObject({ channel: "slow-b", status: "done" }); + expect(sync.jobId).toBeTruthy(); + expect(f.fetch.find((s: { action: string }) => s.action === "refresh-report")).toMatchObject({ status: "done" }); + expect(f.status).toBe("no-change"); +});