Files
beardrive/internal/webapp/frontend/e2e/session-run.spec.ts
T
Snow Lee (Sungwon)andGitHub 5f1ac98dae feat(hub): see what each agent session read, not just what it changed (BEA-98) (#135)
History showed what an agent run CHANGED. What it read lived in a daily
aggregate with no session dimension, so the two could not be joined and
nobody could answer "when my agent answered, what did it look at — and was
it the fresh version or archive/retired-spec.md?".

The join is one string carried through four places: hook -> spool -> hub ->
run card. A run card now marks each change the run also read, lists the
files it read and never touched, and says on screen why a read can be
missing.

The three landmines the issue asks be named here:

1. Op.Note is USER-SETTABLE (`bdrive sync --note`), so joining reads to
   writes on the note string would let any member with write access forge a
   note that collides with a teammate's run card and hang their reads off
   it. Fixed by adding journal.Op.Session — set only by `bdrive sync
   --hook`, never by --note — and joining on that. The note stays settable
   and stays untrusted; the join simply never reads it. Op.Session is
   additive JSONL and, like Mtime, is never an input to Less or Replay, so
   replay determinism is untouched and older ops carry "".

   The read half has the same hole one step further on: POST /reads takes
   the session id from the CLIENT, so a member could report reads under a
   teammate's session and paint files onto their card. Every session row is
   therefore pinned to the ownsDevice-validated device, and the query
   requires ?session= AND ?device= together — a forged row can only be found
   under the forger's own device, which MayActAs guarantees is never
   somebody else's.

2. BUCKET CARDINALITY. Putting the session in the read_stats key would take
   a 2k-file project from ~2k to ~100k rows/day, into a table ReadLedger
   loads whole at boot and full-scans on every heat request, hub-wide — so
   it would slow the Dashboard for projects that never ran an agent. This
   is the escape hatch the spec itself names, taken up front: session rows
   live in their own read_sessions repo, outside ReadLedger.byKey. No
   read_stats PK migration, no change to the resident-row count, ?by=device
   byte-identical. They get their own retention (session_retention_days,
   default 30) which DELETES rather than folds — no heat total was ever
   derived from them.

3. READS ARE RECORDED ONLY FOR PATHS IN THE CURRENT REPLAY, so a session
   that read a file it then deleted shows a change with no read. That is by
   design, and the run card says so in its footer rather than leaving it to
   read as a bug.

Privacy ruling, written into internal/webapp/reads.go before anything
serves it: a session id appears only in History responses on the op that
carries it, and as a ?session= filter INPUT. It is never enumerated — no
listing endpoint, no session column in /heat output, nothing new in
?by=device.

Also: PendingReads now dedupes on (path, session), not path alone. Two
agent sessions on one device between syncs used to collapse into one event
carrying whichever session flushed last — one session's reads silently
credited to another.

Tests: journal round-trip + Less-ignores-Session; the forge test (`sync
--note "claude-code session <someone-else's>"` leaves Session empty); a
multi-device syncer test carrying the session through convergence; spool
per-session dedup; hub round-trip, cross-device forge, query contract and
non-enumeration; db_conformance on file, sqlite AND postgres; runs.ts
grouping incl. legacy fallback; a Playwright spec on the seeded run card.
2026-08-11 04:18:53 +09:00

46 lines
2.0 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { login, wikiId } from "./helpers";
/* One agent run, both halves (BEA-98). History used to show only what a run
CHANGED; the reads lived in a daily aggregate with no session dimension and
could not be joined to it. The seeded run reads three files and rewrites
one of them. */
test("a run card shows what the session read as well as what it changed", async ({ page }) => {
await login(page);
const pid = await wikiId(page);
await page.goto(`/${pid}/history`);
const card = page.locator(".hrun").first();
await expect(card).toBeVisible();
// The header counts both halves now.
await expect(card.locator(".hrun-meta")).toContainText("read 3");
await expect(card.locator(".hrun-meta")).toContainText("changed 2");
// The file the run read AND rewrote carries the read marker on its own row.
const rewritten = card.locator(".hentry", { hasText: "notes/readme.md" });
await expect(rewritten.locator(".hread")).toHaveText("read");
// The file it created was never read, so that row has no marker.
await expect(card.locator(".hentry", { hasText: "runbook.md" }).locator(".hread")).toHaveCount(0);
// What it read and did not touch is its own list.
const readOnly = card.locator(".hrun-read");
await expect(readOnly).toHaveCount(2);
await expect(readOnly.first()).toContainText("archive/retired-spec.md");
await expect(readOnly.last()).toContainText("index.md");
// Landmine 3 is on screen, not folded into a comment: a file the run read
// and then deleted shows a write with no read, and the card says why.
await expect(card.locator(".hrun-foot")).toHaveText(
"Reads shown only for files the project still has.",
);
});
test("a read-only row opens the file it names", async ({ page }) => {
await login(page);
const pid = await wikiId(page);
await page.goto(`/${pid}/history`);
await page.locator(".hrun-read", { hasText: "index.md" }).click();
await expect(page).toHaveURL(new RegExp(`/${pid}/index.md`));
});