From 1a73db2ca7f3ee318103d1796cd86ecfe39b6b70 Mon Sep 17 00:00:00 2001 From: dawn Date: Wed, 14 Oct 2026 04:30:36 +0300 Subject: [PATCH] e2e: claim the attestation the page writes after a knot write Signed-off-by: dawn --- e2e/README.md | 1 + e2e/harness/attestations.ts | 50 +++++++++++++++++++++++++++++++++++++ e2e/harness/flow.ts | 2 ++ e2e/harness/run.ts | 4 +-- e2e/harness/shared.ts | 12 +-------- e2e/harness/tabs.ts | 20 +++++++++++---- e2e/harness/vocabulary.ts | 2 +- e2e/specs/comments.spec.ts | 6 ----- 8 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 e2e/harness/attestations.ts diff --git a/e2e/README.md b/e2e/README.md index 136cf7777..79edffc53 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -49,6 +49,7 @@ harness/ shared.ts steps and checks that more than one spec uses run.ts who acts, which repo, what each step does services.ts asking pds, knot, etc. what they have after a write + attestations.ts claiming the attestation the page writes to the pds after a knot write cobgit.ts looking inside the knot's git for what a write left there versions.ts every version the knot has of a record stream.ts watching hydrant's event stream for a write to show up diff --git a/e2e/harness/attestations.ts b/e2e/harness/attestations.ts new file mode 100644 index 000000000..8f3b81b04 --- /dev/null +++ b/e2e/harness/attestations.ts @@ -0,0 +1,50 @@ +import { expect } from "@playwright/test"; + +import type { Account } from "./config"; +import type { Written } from "./net"; +import type { Run } from "./run"; +import { knot, lookBefore, pds, settle } from "./services"; +import type { Held } from "./tabs"; +import { versionsOf } from "./versions"; +import { attestationId, record, type Slot } from "./vocabulary"; + +// an attestation is a record in its author's own repo, and the run erases a slot's records as +// the first account to write it, so each account gets a slot of its own +const slots = new Map(); +const attestationBy = ({ name }: Account) => { + const slot = slots.get(name) ?? record(attestationId.nsid); + slots.set(name, slot); + return slot; +}; + +export const isAttested = (held: Held) => held.host === knot.host && held.method !== "delete"; + +// the page attests every knot write by itself, so tracing one has to claim that put too +export const claimAttestation = async (run: Run, written: Written) => { + const slot = attestationBy(run.actor); + // two knot writes in a row put two attestations in the queue, so take the one naming this write + const held = await run.hold( + slot, + (body) => + body.record?.subject?.uri === written.uri && body.record?.subject?.cid === written.cid + ); + expect(held.host, "the attestation should go to the pds").toBe(pds.host); + expect(held.method, "the attestation should be a put").toBe("put"); + + // the same version can come back under a newer change, so the newest match is the one just made + const { versions } = await versionsOf(written.uri); + const change = versions.filter((version) => version.cid === written.cid).at(-1)?.changeId; + expect( + change, + `the knot should list ${written.cid} among the versions of ${written.uri}` + ).toBeDefined(); + expect(held.body.record, "the attestation should name the knot's change").toMatchObject({ + $type: attestationId.nsid, + subject: { uri: written.uri, cid: written.cid }, + change + }); + + const before = { ...(await lookBefore([pds], held)), released: Date.now() }; + const attestation = await run.release(slot, held); + await settle(attestation, [pds], run.actor, attestationId.nsid, held.method, before); +}; diff --git a/e2e/harness/flow.ts b/e2e/harness/flow.ts index e29b2b927..a2eb0707f 100644 --- a/e2e/harness/flow.ts +++ b/e2e/harness/flow.ts @@ -2,6 +2,7 @@ import { expect, test, type Browser, type TestStepInfo } from "@playwright/test" import { fileURLToPath } from "node:url"; import { setPolicy, type Policy } from "./api"; +import { claimAttestation, isAttested } from "./attestations"; import { browserLaunch, config, type Account } from "./config"; import type { Reply } from "./net"; import { recorded } from "./record"; @@ -224,6 +225,7 @@ class Flow { const before = { ...(await lookBefore(hops, held)), released: Date.now() }; const written = await run.release(slot, held); await settle(written, hops, run.actor, slot.nsid, held.method, before); + if (isAttested(held)) await claimAttestation(run, written); }); } diff --git a/e2e/harness/run.ts b/e2e/harness/run.ts index 435be46fa..92b459304 100644 --- a/e2e/harness/run.ts +++ b/e2e/harness/run.ts @@ -201,8 +201,8 @@ export class Run implements Ctx { return this.tabs.open(this.actor, this.people.signsInThroughThePage(this.actor)); } - hold(slot: Slot) { - return this.tabs.hold(this.actor, slot); + hold(slot: Slot, matching?: (body: any) => boolean) { + return this.tabs.hold(this.actor, slot, matching); } // a refused write is never recorded, so the slot keeps what it had diff --git a/e2e/harness/shared.ts b/e2e/harness/shared.ts index a649a538e..5b583625b 100644 --- a/e2e/harness/shared.ts +++ b/e2e/harness/shared.ts @@ -8,7 +8,6 @@ import { ok, selfUri, until, xrpc, type Reply, type Written } from "./net"; import { bobbin, hydrant, knot, pds, refsNaming, spindle } from "./services"; import { alerts, - attestationId, commentId, commentMenu, confirmDelete, @@ -252,16 +251,7 @@ export const sendsPatch = }), "create" ) - .trace(patchId, through(knot, hydrant, bobbin)) - .sends( - attestationId, - pds, - (ctx) => ({ - record: { subject: { uri: ctx.get(patchId).uri, cid: ctx.get(patchId).cid } } - }), - "put" - ) - .trace(attestationId, through(pds)); + .trace(patchId, through(knot, hydrant, bobbin)); export const subscribesToPull = (flow: Flow) => flow diff --git a/e2e/harness/tabs.ts b/e2e/harness/tabs.ts index 882420c73..ff37b36b5 100644 --- a/e2e/harness/tabs.ts +++ b/e2e/harness/tabs.ts @@ -66,10 +66,16 @@ const holdWrites = async (where: Page | BrowserContext) => { const describe = (w: Write) => `${w.nsid} ${w.body.collection} to ${w.host}`; - const next = async (collection: string, timeout = 10_000): Promise => { + const next = async ( + collection: string, + timeout = 10_000, + matching?: (body: any) => boolean + ): Promise => { const deadline = Date.now() + timeout; for (;;) { - const at = parked.findIndex((w) => w.body.collection === collection); + const at = parked.findIndex( + (w) => w.body.collection === collection && (!matching || matching(w.body)) + ); if (at >= 0) { const { nsid, host, body, route } = parked.splice(at, 1)[0]; return { @@ -88,7 +94,10 @@ const holdWrites = async (where: Page | BrowserContext) => { const left = deadline - Date.now(); if (left <= 0) { const held = parked.map(describe).join(", ") || "nothing"; - throw new Error(`no write to ${collection} was sent, the page sent: ${held}`); + const which = matching ? " that matched" : ""; + throw new Error( + `no write to ${collection}${which} was sent, the page sent: ${held}` + ); } await new Promise((wake) => { waiting.push(wake); @@ -177,11 +186,12 @@ export class Tabs { await test.step("log in through the login page", () => logIn(page, account)); } - async hold(account: Account, slot: Slot) { + // a slot already holding a write answers with that one, whatever it is asked to match + async hold(account: Account, slot: Slot, matching?: (body: any) => boolean) { const tab = this.of(account); let held = tab.held.get(slot); if (!held) { - held = await tab.writes.next(slot.nsid); + held = await tab.writes.next(slot.nsid, undefined, matching); tab.held.set(slot, held); } return held; diff --git a/e2e/harness/vocabulary.ts b/e2e/harness/vocabulary.ts index 06e8c0c31..e6b1681d7 100644 --- a/e2e/harness/vocabulary.ts +++ b/e2e/harness/vocabulary.ts @@ -21,7 +21,7 @@ export const manifestId = record("org.tangled.repo.manifest"); export const refsId = record("org.tangled.git.refs"); // a pull is a ticket too, its own slot so one flow can hold an issue and a pull at once -// the page also fires subscribe and attest writes on its own, the flow has to let them through +// the page also fires a subscribe write on its own, the flow has to let it through export const ticketId = record("org.tangled.track.ticket"); export const pullId = record("org.tangled.track.ticket"); export const patchId = record("org.tangled.review.patch"); diff --git a/e2e/specs/comments.spec.ts b/e2e/specs/comments.spec.ts index c92944e65..37f885545 100644 --- a/e2e/specs/comments.spec.ts +++ b/e2e/specs/comments.spec.ts @@ -2,7 +2,6 @@ import { expect } from "@playwright/test"; import { comments } from "../harness/api"; import { - attestationId, bobbin, commentId, component, @@ -144,7 +143,6 @@ flow("reacting to an issue and taking the reaction back") ) .sees(not(chip)) .trace(reaction, through(knot, hydrant, bobbin)) - .trace(attestationId, through(pds)) .sees(chipSaying(1)) .reload() .sees(chipSaying(1)) @@ -166,7 +164,6 @@ flow("a reaction from each of two people adds up and one taking theirs back leav .click(issuePicker) .click(thumbs) .trace(reaction, through(knot, hydrant, bobbin)) - .trace(attestationId, through(pds)) .sees(chipSaying(1)) .actor("fan") @@ -175,7 +172,6 @@ flow("a reaction from each of two people adds up and one taking theirs back leav .click(chip) .sends(reaction, knot, { record: { reaction: "👍" } }, "create") .trace(reaction, through(knot, hydrant, bobbin)) - .trace(attestationId, through(pds)) .sees(chipSaying(2)) .reload() .sees(chipSaying(2)) @@ -205,7 +201,6 @@ withOneComment("reacting to a comment and taking the reaction back") "create" ) .trace(reaction, through(knot, hydrant, bobbin)) - .trace(attestationId, through(pds)) .sees(chipSaying(1)) .reload() .sees(chipSaying(1)) @@ -249,7 +244,6 @@ withOneComment("editing a comment keeps its reactions on screen") .click(commentPicker) .click(thumbs) .trace(reaction, through(knot, hydrant, bobbin)) - .trace(attestationId, through(pds)) .sees(chipSaying(1)) .click(within(component("CommentCard"), testid("moreMenu"))) -- knotmirror 0.0.1