app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

inbox-probe-publication.spec.ts (45708B)


      1 import { test, expect } from '@playwright/test';
      2 import { build } from 'vite';
      3 import { once } from 'node:events';
      4 import { fileURLToPath } from 'node:url';
      5 import { WebSocketServer, type WebSocket } from 'ws';
      6 import { createStaticHarness } from '../integration/harness/static.ts';
      7 import type * as Fixture from './harness/inbox-probe-publication.ts';
      8 declare global {
      9   interface Window {
     10     pb: typeof Fixture;
     11     pbFixture: Awaited<ReturnType<typeof Fixture.makePublicationFixture>>;
     12     pbPending?: Promise<unknown>;
     13     pbAbort?: AbortController;
     14     pbOtherPool?: Fixture.PrivatePool;
     15     pbRestore?: () => void;
     16     pbClock?: number;
     17     pbNetworkClock?: ReturnType<Window['pbFixture']['installNetworkClock']>;
     18     pbDelayClose?: boolean;
     19     pbFailClose?: boolean;
     20     pbInvalidateOnSocket?: boolean;
     21     pbNestedCleanup?: number;
     22     pbNestedFailure?: number;
     23     pbHeldClose?: (() => void)[];
     24   }
     25 }
     26 let server: Awaited<ReturnType<typeof createStaticHarness>>,
     27   sockets: WebSocketServer,
     28   endpoint: string,
     29   bundle: string;
     30 let head = '',
     31   response: 'accepted' | 'refused' | 'unknown' | 'wrong' | 'auth_required' =
     32     'accepted',
     33   auth = false;
     34 const frames: { origin: string; frame: unknown[] }[] = [],
     35   physical = new Set<WebSocket>();
     36 let peak = 0,
     37   privatePeak = 0;
     38 const privatePhysical = new Set<WebSocket>();
     39 const privateConnections = new Map<string, number>();
     40 test.beforeAll(async () => {
     41   server = await createStaticHarness();
     42   sockets = new WebSocketServer({
     43     host: '127.0.0.1',
     44     port: 0,
     45     maxPayload: 65536
     46   });
     47   await once(sockets, 'listening');
     48   const address = sockets.address();
     49   if (!address || typeof address === 'string')
     50     throw Error('actual loopback fixture');
     51   endpoint = 'ws://127.0.0.1:' + address.port;
     52   sockets.on('connection', (socket, request) => {
     53     physical.add(socket);
     54     peak = Math.max(peak, physical.size);
     55     socket.on('close', () => physical.delete(socket));
     56     const origin = new URL(request.url!, 'http://127.0.0.1').searchParams.get(
     57       'origin'
     58     )!;
     59     if (origin !== 'wss://discovery.example.org') {
     60       privatePhysical.add(socket);
     61       privateConnections.set(origin, (privateConnections.get(origin) ?? 0) + 1);
     62       privatePeak = Math.max(privatePeak, privatePhysical.size);
     63       socket.on('close', () => privatePhysical.delete(socket));
     64     }
     65     if (auth && origin === 'wss://inbox.example.org')
     66       socket.send(JSON.stringify(['AUTH', 'probe-challenge']));
     67     socket.on('message', (bytes) => {
     68       const raw = Buffer.isBuffer(bytes)
     69         ? bytes
     70         : Array.isArray(bytes)
     71           ? Buffer.concat(bytes)
     72           : Buffer.from(bytes);
     73       const frame = JSON.parse(raw.toString()) as unknown[];
     74       frames.push({ origin, frame });
     75       if (frame[0] === 'REQ') {
     76         const filter = frame[2] as { kinds?: number[] };
     77         if (filter.kinds?.includes(10050) && head)
     78           socket.send(JSON.stringify(['EVENT', frame[1], JSON.parse(head)]));
     79         socket.send(JSON.stringify(['EOSE', frame[1]]));
     80       } else if (frame[0] === 'AUTH') {
     81         socket.send(
     82           JSON.stringify(['OK', (frame[1] as { id: string }).id, true, ''])
     83         );
     84       } else if (frame[0] === 'EVENT' && response !== 'unknown') {
     85         socket.send(
     86           JSON.stringify([
     87             'OK',
     88             response === 'wrong'
     89               ? 'f'.repeat(64)
     90               : (frame[1] as { id: string }).id,
     91             response !== 'refused' && response !== 'auth_required',
     92             response === 'auth_required'
     93               ? 'auth-required: source fixture'
     94               : response === 'refused'
     95                 ? 'blocked: source fixture'
     96                 : ''
     97           ])
     98         );
     99       }
    100     });
    101   });
    102   const result = await build({
    103     configFile: false,
    104     logLevel: 'silent',
    105     build: {
    106       write: false,
    107       minify: false,
    108       lib: {
    109         entry: fileURLToPath(
    110           new URL('./harness/inbox-probe-publication.ts', import.meta.url)
    111         ),
    112         name: 'pb',
    113         formats: ['iife']
    114       }
    115     }
    116   });
    117   const output = Array.isArray(result) ? result[0] : result;
    118   if (!('output' in output)) throw Error('compiled fixture');
    119   const chunks = output.output.filter((x) => x.type === 'chunk');
    120   expect(chunks).toHaveLength(1);
    121   bundle = chunks[0].code;
    122 });
    123 test.afterAll(async () => {
    124   for (const socket of sockets.clients) socket.terminate();
    125   await new Promise<void>((resolve) => sockets.close(() => resolve()));
    126   await server.close();
    127 });
    128 test.beforeEach(async ({ page }, testInfo) => {
    129   await expect.poll(() => physical.size).toBe(0);
    130   head = '';
    131   response = 'accepted';
    132   auth = false;
    133   peak = 0;
    134   privatePeak = 0;
    135   privateConnections.clear();
    136   frames.length = 0;
    137   await page.addInitScript(
    138     ({ endpoint }) => {
    139       const Native = window.WebSocket;
    140       window.WebSocket = class extends Native {
    141         constructor(url: string | URL, protocols?: string | string[]) {
    142           const origin = new URL(String(url)).origin;
    143           if (
    144             ![
    145               'wss://discovery.example.org',
    146               'wss://inbox.example.org',
    147               'wss://peer.example.org',
    148               'wss://archive.example.org'
    149             ].includes(origin)
    150           )
    151             throw Error('unapproved fixture origin');
    152           super(endpoint + '/?origin=' + encodeURIComponent(origin), protocols);
    153           if (
    154             window.pbInvalidateOnSocket &&
    155             origin === 'wss://inbox.example.org'
    156           )
    157             window.pb.closeInboxAccessController(
    158               window.pbFixture.controller()!
    159             );
    160         }
    161         override close(code?: number, reason?: string) {
    162           if (window.pbFailClose)
    163             throw Error('actual controlled disposal failure');
    164           if (window.pbDelayClose)
    165             (window.pbHeldClose ??= []).push(() => super.close(code, reason));
    166           else super.close(code, reason);
    167         }
    168       };
    169     },
    170     { endpoint }
    171   );
    172   await page.goto(server.url + '/search');
    173   await page.addScriptTag({ content: bundle });
    174   head = await page.evaluate(async (multi) => {
    175     window.pbFixture = await window.pb.makePublicationFixture();
    176     return window.pbFixture.preferenceWire(
    177       multi
    178         ? [
    179             'wss://inbox.example.org',
    180             'wss://peer.example.org',
    181             'wss://archive.example.org'
    182           ]
    183         : ['wss://inbox.example.org']
    184     );
    185   }, testInfo.title.includes('three-origin'));
    186   await page.evaluate(async () => {
    187     const f = window.pbFixture;
    188     await f.capture();
    189     if (
    190       (await f.reserve()).status !== 'reserved' ||
    191       (await f.prepare()) !== 'wrapped' ||
    192       (await f.commitOriginal()).status !== 'prepared'
    193     )
    194       throw Error('genuine cold native original setup');
    195   });
    196 });
    197 test.afterEach(async ({ page }) => {
    198   if (!page.isClosed())
    199     await page.evaluate(() => {
    200       window.pbRestore?.();
    201       window.pbFailClose = false;
    202       window.pbDelayClose = false;
    203       for (const release of window.pbHeldClose ?? []) release();
    204       window.pbFixture.close();
    205     });
    206 });
    207 function privateEvents() {
    208   return frames.filter(
    209     (x) => x.origin !== 'wss://discovery.example.org' && x.frame[0] === 'EVENT'
    210   );
    211 }
    212 function noPrivateReads() {
    213   expect(
    214     frames.filter(
    215       (x) => x.origin !== 'wss://discovery.example.org' && x.frame[0] === 'REQ'
    216     )
    217   ).toHaveLength(0);
    218 }
    219 
    220 test('cold original artifact is published exactly; genuine receipts and new ACKs keep one action and three attempts', async ({
    221   page
    222 }) => {
    223   const before = await page.evaluate(() => window.pbFixture.stored());
    224   expect(privateEvents()).toHaveLength(0);
    225   noPrivateReads();
    226   const observed = await page.evaluate(async () => {
    227     const f = window.pbFixture,
    228       api = window.pb,
    229       action = f.action()!;
    230     const first = await f.publish();
    231     const clone = await f.append({ ...first });
    232     const saved = await f.append(first),
    233       duplicate = await f.append(first);
    234     const afterFirst = f.snapshot()!.record;
    235     const recommit = await f.commitOriginal(),
    236       sameAction = f.action() === action;
    237     const second = await f.publish();
    238     await f.append(second);
    239     const third = await f.publish();
    240     await f.append(third);
    241     const fourth = await f.publish();
    242     return {
    243       first,
    244       clone,
    245       saved,
    246       duplicate,
    247       afterFirst,
    248       recommit: recommit.status,
    249       sameAction,
    250       second,
    251       third,
    252       fourth,
    253       row: f.snapshot()!.record,
    254       evidence: !!api.inboxProbeArchiveAttemptEvidence(first),
    255       ordinaryEvidence: !!api.privateGiftWrapAttemptEvidence(
    256         first as unknown as Parameters<
    257           typeof api.privateGiftWrapAttemptEvidence
    258         >[0]
    259       ),
    260       ready: api.inboxAccessControllerSnapshot(f.controller()!)?.readiness
    261     };
    262   });
    263   expect(observed.first).toMatchObject({
    264     status: 'accepted',
    265     role: 'access_archive',
    266     origin: 'wss://inbox.example.org',
    267     attempt: 1
    268   });
    269   expect(observed.clone.status).toBe('invalid');
    270   expect(observed.saved.status).toBe('saved');
    271   expect(observed.duplicate.status).toBe('existing');
    272   expect(observed.afterFirst.revision).toBe(2);
    273   expect(observed.afterFirst.receipts).toHaveLength(1);
    274   expect(observed.recommit).toBe('existing');
    275   expect(observed.sameAction).toBe(true);
    276   expect(observed.second).toMatchObject({
    277     status: 'accepted',
    278     actionId: observed.first.actionId,
    279     attempt: 2
    280   });
    281   expect(observed.third).toMatchObject({
    282     status: 'accepted',
    283     actionId: observed.first.actionId,
    284     attempt: 3
    285   });
    286   expect(observed.fourth).toEqual({ status: 'stopped' });
    287   expect(observed.row.revision).toBe(4);
    288   expect(observed.row.receipts).toHaveLength(3);
    289   expect(observed.evidence).toBe(true);
    290   expect(observed.ordinaryEvidence).toBe(false);
    291   expect(observed.ready).toBe('unavailable');
    292   expect(privateEvents()).toHaveLength(3);
    293   expect(privateEvents().map((x) => JSON.stringify(x.frame[1]))).toEqual(
    294     Array(3).fill(
    295       (JSON.parse(before[0].wire) as { self: { wire: string } }).self.wire
    296     )
    297   );
    298   noPrivateReads();
    299 });
    300 
    301 test('forged/cross-family permission and genuine foreign repository/session/policy/head cannot send', async ({
    302   page
    303 }) => {
    304   const observations = await page.evaluate(async () => {
    305     const f = window.pbFixture,
    306       api = window.pb,
    307       ack = f.acknowledgement()!,
    308       action = f.action()!,
    309       permission = f.permission()!;
    310     const copiedPolicy = f.copiedPolicy(),
    311       otherSession = await f.foreignSession();
    312     const invalidActions = [
    313       api.captureInboxProbePublicationAction(
    314         f.foreignRepository(),
    315         f.session,
    316         f.policy,
    317         ack,
    318         'reviewed_inbox_probe_network'
    319       ),
    320       api.captureInboxProbePublicationAction(
    321         f.repository,
    322         otherSession,
    323         f.policy,
    324         ack,
    325         'reviewed_inbox_probe_network'
    326       ),
    327       api.captureInboxProbePublicationAction(
    328         f.repository,
    329         f.session,
    330         copiedPolicy,
    331         ack,
    332         'reviewed_inbox_probe_network'
    333       ),
    334       api.captureInboxProbePublicationAction(
    335         f.repository,
    336         f.session,
    337         f.policy,
    338         { ...f.snapshot() } as typeof ack,
    339         'reviewed_inbox_probe_network'
    340       )
    341     ].map(Boolean);
    342     const invalidPermissions = [
    343       api.captureInboxProbePublication(
    344         f.repository,
    345         f.session,
    346         copiedPolicy,
    347         ack,
    348         action,
    349         'wss://inbox.example.org',
    350         'reviewed_inbox_probe_publication'
    351       ),
    352       f.permission('wss://peer.example.org'),
    353       f.permission('wss://inbox.example.org', {})
    354     ].map(Boolean);
    355     const cross = await api.publishPrivateGiftWrapAttempt(
    356       f.pool(),
    357       permission as unknown as Parameters<
    358         typeof api.publishPrivateGiftWrapAttempt
    359       >[1],
    360       new AbortController().signal
    361     );
    362     const fake = await api.publishInboxProbeArchiveAttempt(
    363       f.pool(),
    364       {} as typeof permission,
    365       new AbortController().signal
    366     );
    367     f.churnHead();
    368     return {
    369       invalidActions,
    370       invalidPermissions,
    371       cross,
    372       fake,
    373       stale: await f.publish(permission)
    374     };
    375   });
    376   expect(observations.invalidActions).toEqual([false, false, false, false]);
    377   expect(observations.invalidPermissions).toEqual([false, false, false]);
    378   expect(observations.cross).toEqual({ status: 'stopped' });
    379   expect(observations.fake).toEqual({ status: 'stopped' });
    380   expect(observations.stale).toEqual({ status: 'stopped' });
    381   expect(privateEvents()).toHaveLength(0);
    382   noPrivateReads();
    383 });
    384 for (const mutation of [
    385   'alias',
    386   'forged_fact',
    387   'corrupt_tail',
    388   'removed'
    389 ] as const) {
    390   test(`fresh native ${mutation} refuses before EVENT and cannot advance archive provenance`, async ({
    391     page
    392   }) => {
    393     const result = await page.evaluate(async (mutation) => {
    394       const f = window.pbFixture,
    395         api = window.pb,
    396         token = f.permission()!;
    397       const rows = await f.stored();
    398       if (mutation === 'removed') await f.removeOriginal();
    399       else if (mutation === 'corrupt_tail')
    400         await f.inject([
    401           { owner: f.owner, id: crypto.randomUUID(), wire: 'bad' }
    402         ]);
    403       else {
    404         if (mutation === 'alias') rows[0].wire += ' ';
    405         else {
    406           const row = JSON.parse(rows[0].wire) as {
    407             revision: number;
    408             self: { eventId: string };
    409             receipts: unknown[];
    410           };
    411           row.revision++;
    412           row.receipts.push({
    413             actionId: crypto.randomUUID(),
    414             role: 'access_archive',
    415             origin: 'wss://inbox.example.org',
    416             eventId: row.self.eventId,
    417             attempt: 1,
    418             status: 'accepted',
    419             observedAtMilliseconds: 1,
    420             readbackWire: null
    421           });
    422           rows[0].wire = JSON.stringify(row);
    423         }
    424         await f.inject(rows);
    425       }
    426       const before = await f.stored(),
    427         result = await f.publish(token);
    428       return {
    429         before,
    430         after: await f.stored(),
    431         result,
    432         evidence: !!api.inboxProbeArchiveAttemptEvidence(result),
    433         recommit: await f.commitOriginal()
    434       };
    435     }, mutation);
    436     expect(result.result).toEqual({ status: 'stopped' });
    437     expect(result.evidence).toBe(false);
    438     expect(result.after).toEqual(result.before);
    439     expect(result.recommit.status).not.toBe('existing');
    440     expect(privateEvents()).toHaveLength(0);
    441     noPrivateReads();
    442   });
    443 }
    444 
    445 test('handwritten valid receipt after actual EVENT cannot be adopted by append or refreshed ACK', async ({
    446   page
    447 }) => {
    448   const result = await page.evaluate(async () => {
    449     const f = window.pbFixture,
    450       actual = await f.publish(),
    451       rows = await f.stored();
    452     const row = JSON.parse(rows[0].wire) as {
    453       revision: number;
    454       self: { eventId: string };
    455       receipts: unknown[];
    456     };
    457     row.revision++;
    458     row.receipts.push({
    459       actionId: crypto.randomUUID(),
    460       origin: 'wss://inbox.example.org',
    461       role: 'access_archive',
    462       eventId: row.self.eventId,
    463       attempt: 1,
    464       status: 'accepted',
    465       observedAtMilliseconds: 1,
    466       readbackWire: null
    467     });
    468     rows[0].wire = JSON.stringify(row);
    469     await f.inject(rows);
    470     return {
    471       append: await f.append(actual),
    472       recommit: await f.commitOriginal(),
    473       before: rows,
    474       after: await f.stored(),
    475       snapshot: f.snapshot()!.record
    476     };
    477   });
    478   expect(result.append.status).toBe('conflict');
    479   expect(result.recommit.status).toBe('conflict');
    480   expect(result.after).toEqual(result.before);
    481   expect(result.snapshot.receipts).toHaveLength(0);
    482   expect(privateEvents()).toHaveLength(1);
    483   noPrivateReads();
    484 });
    485 
    486 test('actual named relay refusal remains a genuine bounded archive observation', async ({
    487   page
    488 }) => {
    489   response = 'refused';
    490   const result = await page.evaluate(async () => {
    491     const f = window.pbFixture,
    492       actual = await f.publish();
    493     return {
    494       actual,
    495       append: await f.append(actual),
    496       row: f.snapshot()!.record
    497     };
    498   });
    499   expect(result.actual).toMatchObject({ status: 'refused', attempt: 1 });
    500   expect(result.append.status).toBe('saved');
    501   expect(result.row.receipts[0].status).toBe('refused');
    502   expect(privateEvents()).toHaveLength(1);
    503   noPrivateReads();
    504 });
    505 for (const disposition of ['stop', 'wrong_ack', 'clock_expired'] as const) {
    506   test(`actual EVENT ${disposition} is truthful and cannot become acceptance`, async ({
    507     page
    508   }) => {
    509     response = disposition === 'wrong_ack' ? 'wrong' : 'unknown';
    510     await page.evaluate((disposition) => {
    511       const f = window.pbFixture;
    512       if (disposition === 'clock_expired') {
    513         window.pbNetworkClock = f.installNetworkClock();
    514         window.pbRestore = () => window.pbNetworkClock!.restore();
    515       }
    516       window.pbAbort = new AbortController();
    517       window.pbPending = f.publish(f.permission(), window.pbAbort.signal);
    518     }, disposition);
    519     await expect.poll(() => privateEvents().length).toBe(1);
    520     if (disposition === 'clock_expired')
    521       await page.evaluate(() => {
    522         window.pbNetworkClock!.advance(46000);
    523       });
    524     else await page.evaluate(() => window.pbAbort!.abort());
    525     const result = await page.evaluate(async () => {
    526       const actual = (await window.pbPending) as NonNullable<
    527         ReturnType<typeof window.pbFixture.last>
    528       >;
    529       return {
    530         actual,
    531         append: await window.pbFixture.append(actual),
    532         row: window.pbFixture.snapshot()!.record
    533       };
    534     });
    535     expect(result.actual.status).toBe(
    536       disposition === 'clock_expired' ? 'timed_out' : 'stopped'
    537     );
    538     expect(result.append.status).toBe('saved');
    539     expect(result.row.receipts[0].status).toBe(result.actual.status);
    540     noPrivateReads();
    541   });
    542 }
    543 
    544 test('pending fresh owner approval and SDK acquisition failure consume no attempt; original starts at one', async ({
    545   page
    546 }) => {
    547   const stopped = await page.evaluate(async () => {
    548     const f = window.pbFixture;
    549     f.pool();
    550     const restore = f.installAcquisitionFailure();
    551     try {
    552       return await f.publish();
    553     } finally {
    554       restore();
    555     }
    556   });
    557   expect(stopped).toEqual({ status: 'stopped' });
    558   expect(privateEvents()).toHaveLength(0);
    559   await page.evaluate(() => {
    560     const f = window.pbFixture;
    561     window.pbNetworkClock = f.installNetworkClock();
    562     window.pbRestore = () => window.pbNetworkClock!.restore();
    563     f.mode('hold_key');
    564     window.pbPending = f.publish();
    565   });
    566   await expect
    567     .poll(() => page.evaluate(() => window.pbFixture.waiting()))
    568     .toBe('key');
    569   expect(privateEvents()).toHaveLength(0);
    570   await page.evaluate(() => {
    571     window.pbNetworkClock!.advance(90000);
    572     window.pbFixture.mode('normal');
    573     window.pbFixture.settle();
    574   });
    575   const first = await page.evaluate(async () => window.pbPending);
    576   expect(first).toMatchObject({ status: 'accepted', attempt: 1 });
    577   const next = await page.evaluate(async () => {
    578     await window.pbFixture.append();
    579     return window.pbFixture.publish();
    580   });
    581   expect(next).toMatchObject({ status: 'accepted', attempt: 2 });
    582   expect(privateEvents()).toHaveLength(2);
    583   noPrivateReads();
    584 });
    585 
    586 test('known AUTH with pending original signer consumes no probe attempt, then only original artifact sends', async ({
    587   page
    588 }) => {
    589   auth = true;
    590   await page.evaluate(() => {
    591     const f = window.pbFixture;
    592     window.pbNetworkClock = f.installNetworkClock();
    593     window.pbRestore = () => window.pbNetworkClock!.restore();
    594     window.pbPending = window.pb.authenticateInboxAccess(
    595       f.controller()!,
    596       'wss://inbox.example.org',
    597       'reviewed_inbox_connection_auth'
    598     );
    599   });
    600   await page.evaluate(async () => window.pbPending);
    601   await expect
    602     .poll(() =>
    603       page.evaluate(
    604         () =>
    605           window.pb.inboxAccessControllerSnapshot(
    606             window.pbFixture.controller()!
    607           )?.auth[0]?.state
    608       )
    609     )
    610     .toBe('challenge');
    611   await page.evaluate(() => {
    612     const f = window.pbFixture;
    613     f.mode('hold_sign');
    614     window.pbPending = window.pb.respondInboxAccessAuthentication(
    615       f.controller()!,
    616       'wss://inbox.example.org',
    617       'reviewed_inbox_auth_response'
    618     );
    619   });
    620   await expect
    621     .poll(() => page.evaluate(() => window.pbFixture.waiting()))
    622     .toBe('sign');
    623   const stopped = await page.evaluate(() => window.pbFixture.publish());
    624   expect(stopped).toEqual({ status: 'stopped' });
    625   expect(privateEvents()).toHaveLength(0);
    626   expect(
    627     await page.evaluate(() => window.pbFixture.snapshot()!.record.receipts)
    628   ).toHaveLength(0);
    629   await page.evaluate(() => {
    630     window.pbNetworkClock!.advance(90000);
    631     window.pbFixture.mode('normal');
    632     window.pbFixture.settle();
    633   });
    634   expect(await page.evaluate(async () => window.pbPending)).toBe('accepted');
    635   const original = await page.evaluate(() => window.pbFixture.publish());
    636   expect(original).toMatchObject({ status: 'accepted', attempt: 1 });
    637   expect(privateEvents()).toHaveLength(1);
    638   expect(frames.filter((x) => x.frame[0] === 'AUTH')).toHaveLength(1);
    639   noPrivateReads();
    640 });
    641 
    642 for (const mode of ['aborted', 'uncertain'] as const) {
    643   test(`actual native archive ${mode} commit retains original evidence for exact replay`, async ({
    644     page
    645   }) => {
    646     const result = await page.evaluate(async (mode) => {
    647       const f = window.pbFixture,
    648         actual = await f.publish(),
    649         before = await f.stored();
    650       const uncertain =
    651         mode === 'uncertain' ? f.installUncertainCommit() : undefined;
    652       const restore =
    653         mode === 'aborted'
    654           ? f.installNativeAbort()
    655           : () => uncertain!.restore();
    656       let first: Awaited<ReturnType<typeof f.append>>;
    657       try {
    658         first = await f.append(actual);
    659       } finally {
    660         restore();
    661       }
    662       const afterFirst = await f.stored(),
    663         second = await f.append(actual),
    664         third = await f.append(actual);
    665       return {
    666         before,
    667         afterFirst,
    668         first,
    669         second,
    670         third,
    671         row: f.snapshot()!.record,
    672         native: uncertain?.counts()
    673       };
    674     }, mode);
    675     expect(result.first.status).toBe(
    676       mode === 'aborted' ? 'aborted' : 'reconciled'
    677     );
    678     if (mode === 'aborted') expect(result.afterFirst).toEqual(result.before);
    679     expect(result.second.status).toBe(
    680       mode === 'aborted' ? 'saved' : 'existing'
    681     );
    682     expect(result.third.status).toBe('existing');
    683     expect(result.row.revision).toBe(2);
    684     expect(result.row.receipts).toHaveLength(1);
    685     expect(privateEvents()).toHaveLength(1);
    686     noPrivateReads();
    687     if (mode === 'uncertain')
    688       expect(result.native).toMatchObject({
    689         putSuccess: 1,
    690         nativeComplete: 1,
    691         nativeAbort: 0,
    692         abortRefused: 1
    693       });
    694   });
    695 }
    696 
    697 test('original attempt metadata settles after owner loss, without restoring effect or readiness', async ({
    698   page
    699 }) => {
    700   const result = await page.evaluate(async () => {
    701     const f = window.pbFixture,
    702       actual = await f.publish();
    703     f.closeSession();
    704     const appended = await f.append(actual);
    705     return {
    706       actual,
    707       appended,
    708       rows: await f.stored(),
    709       ack: f.snapshot(),
    710       next: await f.publish()
    711     };
    712   });
    713   expect(result.appended.status).toBe('saved');
    714   expect(
    715     (JSON.parse(result.rows[0].wire) as { receipts: unknown[] }).receipts
    716   ).toHaveLength(1);
    717   expect(result.ack).toBeUndefined();
    718   expect(result.next).toEqual({ status: 'stopped' });
    719   expect(privateEvents()).toHaveLength(1);
    720   noPrivateReads();
    721 });
    722 
    723 test('held physical close retains original cleanup and prevents replacement traffic', async ({
    724   page
    725 }) => {
    726   response = 'unknown';
    727   await page.evaluate(() => {
    728     window.pbDelayClose = true;
    729     window.pbAbort = new AbortController();
    730     window.pbPending = window.pbFixture.publish(
    731       window.pbFixture.permission(),
    732       window.pbAbort.signal
    733     );
    734   });
    735   await expect.poll(() => privateEvents().length).toBe(1);
    736   await page.evaluate(() => {
    737     window.pbAbort!.abort();
    738     window.pbFixture.stop();
    739   });
    740   expect(await page.evaluate(() => window.pbFixture.publish())).toEqual({
    741     status: 'stopped'
    742   });
    743   expect(privateEvents()).toHaveLength(1);
    744   expect(peak).toBeLessThanOrEqual(3);
    745   await page.evaluate(() => {
    746     window.pbDelayClose = false;
    747     for (const release of window.pbHeldClose ?? []) release();
    748     window.pbFixture.stop();
    749   });
    750   await expect.poll(() => physical.size).toBe(0);
    751   noPrivateReads();
    752 });
    753 
    754 test('reentrant genuine UUID capture reserves one original action before callbacks', async ({
    755   page
    756 }) => {
    757   const result = await page.evaluate(async () => {
    758     const f = window.pbFixture,
    759       original = crypto.randomUUID.bind(crypto);
    760     let nested: ReturnType<typeof f.action>,
    761       entered = false;
    762     crypto.randomUUID = () => {
    763       if (!entered) {
    764         entered = true;
    765         nested = f.action();
    766       }
    767       return original();
    768     };
    769     let first: ReturnType<typeof f.action>;
    770     try {
    771       first = f.action();
    772     } finally {
    773       crypto.randomUUID = original;
    774     }
    775     const outcomes = [];
    776     for (let n = 0; n < 4; n++) {
    777       const actual = await f.publish();
    778       outcomes.push(actual);
    779       if (n < 3) await f.append(actual);
    780     }
    781     return {
    782       first: !!first,
    783       nested: !!nested,
    784       same: first === f.action(),
    785       outcomes
    786     };
    787   });
    788   expect(result.first).toBe(true);
    789   expect(result.nested).toBe(false);
    790   expect(result.same).toBe(true);
    791   expect(result.outcomes.slice(0, 3).map((x) => x.attempt)).toEqual([1, 2, 3]);
    792   expect(result.outcomes[3]).toEqual({ status: 'stopped' });
    793   expect(privateEvents()).toHaveLength(3);
    794   noPrivateReads();
    795 });
    796 
    797 for (const boundary of ['wrong_key', 'head_during_key', 'lock_busy'] as const) {
    798   test(`actual ${boundary} refuses with no EVENT or attempted archive receipt`, async ({
    799     page
    800   }) => {
    801     if (boundary === 'lock_busy') {
    802       await page.evaluate(() => {
    803         window.pbPending = navigator.locks.request(
    804           'harvestcircle:owner:' + window.pbFixture.owner,
    805           async () => {
    806             window.pbClock = 1;
    807             await new Promise<void>((resolve) => {
    808               window.pbRestore = resolve;
    809             });
    810           }
    811         );
    812       });
    813       await expect.poll(() => page.evaluate(() => window.pbClock)).toBe(1);
    814     } else {
    815       await page.evaluate((boundary) => {
    816         window.pbFixture.mode(
    817           boundary === 'wrong_key' ? 'wrong_key' : 'hold_key'
    818         );
    819       }, boundary);
    820     }
    821     await page.evaluate(() => {
    822       window.pbPending = window.pbFixture.publish();
    823     });
    824     if (boundary === 'head_during_key') {
    825       await expect
    826         .poll(() => page.evaluate(() => window.pbFixture.waiting()))
    827         .toBe('key');
    828       await page.evaluate(() => {
    829         window.pbFixture.churnHead();
    830         window.pbFixture.mode('normal');
    831         window.pbFixture.settle();
    832       });
    833     }
    834     const result = await page.evaluate(async () => {
    835       const actual = (await window.pbPending) as NonNullable<
    836         ReturnType<typeof window.pbFixture.last>
    837       >;
    838       return {
    839         actual,
    840         evidence: !!window.pb.inboxProbeArchiveAttemptEvidence(actual),
    841         rows: await window.pbFixture.stored()
    842       };
    843     });
    844     expect(result.actual.status).toBe('stopped');
    845     expect(result.evidence).toBe(false);
    846     expect(
    847       (JSON.parse(result.rows[0].wire) as { receipts: unknown[] }).receipts
    848     ).toHaveLength(0);
    849     expect(privateEvents()).toHaveLength(0);
    850     noPrivateReads();
    851     if (boundary === 'lock_busy')
    852       await page.evaluate(() => window.pbRestore?.());
    853   });
    854 }
    855 for (const clock of ['backwards', 'nonfinite'] as const) {
    856   test(`actual ${clock} network clock conservatively fences original action`, async ({
    857     page
    858   }) => {
    859     response = 'unknown';
    860     await page.evaluate(() => {
    861       window.pbNetworkClock = window.pbFixture.installNetworkClock();
    862       window.pbRestore = () => window.pbNetworkClock!.restore();
    863       window.pbPending = window.pbFixture.publish();
    864     });
    865     await expect.poll(() => privateEvents().length).toBe(1);
    866     await page.evaluate((clock) => {
    867       window.pbNetworkClock!.set(clock === 'backwards' ? 0 : NaN);
    868     }, clock);
    869     const result = await page.evaluate(async () => {
    870       const actual = (await window.pbPending) as NonNullable<
    871         ReturnType<typeof window.pbFixture.last>
    872       >;
    873       const appended = await window.pbFixture.append(actual);
    874       return {
    875         actual,
    876         appended,
    877         action: !!window.pbFixture.action(),
    878         next: await window.pbFixture.publish()
    879       };
    880     });
    881     expect(result.actual.status).toBe('timed_out');
    882     expect(result.appended.status).toBe('saved');
    883     expect(result.action).toBe(false);
    884     expect(result.next).toEqual({ status: 'stopped' });
    885     expect(privateEvents()).toHaveLength(1);
    886     noPrivateReads();
    887   });
    888 }
    889 
    890 test('actual late acknowledgement after head loss cannot become accepted', async ({
    891   page
    892 }) => {
    893   response = 'unknown';
    894   await page.evaluate(() => {
    895     window.pbPending = window.pbFixture.publish();
    896   });
    897   await expect.poll(() => privateEvents().length).toBe(1);
    898   await page.evaluate(() => window.pbFixture.churnHead());
    899   const result = await page.evaluate(async () => window.pbPending);
    900   expect(result).toMatchObject({ status: 'stopped', attempt: 1 });
    901   for (const socket of sockets.clients)
    902     if (socket.readyState === 1)
    903       socket.send(
    904         JSON.stringify([
    905           'OK',
    906           (privateEvents()[0].frame[1] as { id: string }).id,
    907           true,
    908           'late'
    909         ])
    910       );
    911   const settlement = await page.evaluate(async () => {
    912     const f = window.pbFixture;
    913     return {
    914       append: await f.append(),
    915       row: (await f.stored())[0].wire,
    916       next: await f.publish()
    917     };
    918   });
    919   expect(settlement.append.status).toBe('saved');
    920   expect(
    921     (JSON.parse(settlement.row) as { receipts: { status: string }[] })
    922       .receipts[0].status
    923   ).toBe('stopped');
    924   expect(settlement.next).toEqual({ status: 'stopped' });
    925   noPrivateReads();
    926 });
    927 
    928 test('later physical disposal failure preserves prior stopped attempt and original Stop retries cleanup', async ({
    929   page
    930 }) => {
    931   response = 'unknown';
    932   await page.evaluate(() => {
    933     window.pbAbort = new AbortController();
    934     window.pbPending = window.pbFixture.publish(
    935       window.pbFixture.permission(),
    936       window.pbAbort.signal
    937     );
    938   });
    939   await expect.poll(() => privateEvents().length).toBe(1);
    940   const result = await page.evaluate(async () => {
    941     window.pbFailClose = true;
    942     window.pbAbort!.abort();
    943     let failed = false;
    944     try {
    945       window.pbFixture.stop();
    946     } catch {
    947       failed = true;
    948     }
    949     const actual = await window.pbPending;
    950     const cleanup = window.pb.privatePoolCleanupRequired(
    951       window.pbFixture.pool()
    952     );
    953     window.pbFailClose = false;
    954     window.pbFixture.stop();
    955     return { actual, failed, cleanup, next: await window.pbFixture.publish() };
    956   });
    957   expect(result.actual).toMatchObject({ status: 'stopped', attempt: 1 });
    958   expect(result.failed).toBe(true);
    959   expect(result.cleanup).toBe(true);
    960   expect(result.next).toEqual({ status: 'stopped' });
    961   await expect.poll(() => physical.size).toBe(0);
    962   expect(privateEvents()).toHaveLength(1);
    963   noPrivateReads();
    964 });
    965 
    966 test('archive append remains eligible in a full hundred-row namespace; concurrent replay adds one fact', async ({
    967   page
    968 }) => {
    969   const result = await page.evaluate(async () => {
    970     const f = window.pbFixture,
    971       actual = await f.publish(),
    972       rows = await f.stored();
    973     const template = JSON.parse(rows[0].wire) as { id: string };
    974     const fillers = Array.from({ length: 99 }, () => {
    975       const id = crypto.randomUUID();
    976       return { owner: f.owner, id, wire: JSON.stringify({ ...template, id }) };
    977     });
    978     await f.inject(fillers);
    979     const pair = await Promise.all([f.append(actual), f.append(actual)]);
    980     const repeat = await f.append(actual);
    981     return {
    982       pair,
    983       repeat,
    984       row: f.snapshot()!.record,
    985       count: (await f.stored()).length
    986     };
    987   });
    988   expect(result.pair.map((x) => x.status).sort()).toEqual(['busy', 'saved']);
    989   expect(result.repeat.status).toBe('existing');
    990   expect(result.row.revision).toBe(2);
    991   expect(result.row.receipts).toHaveLength(1);
    992   expect(result.count).toBe(100);
    993   expect(privateEvents()).toHaveLength(1);
    994   noPrivateReads();
    995 });
    996 
    997 test('actual eight-MiB joint namespace refuses archive growth without losing original ciphertext or evidence', async ({
    998   page
    999 }) => {
   1000   const result = await page.evaluate(async () => {
   1001     const f = window.pbFixture,
   1002       actual = await f.publish(),
   1003       original = await f.stored();
   1004     const template = JSON.parse(original[0].wire) as {
   1005       id: string;
   1006       self: { eventId: string };
   1007       receipts: unknown[];
   1008     };
   1009     const id = crypto.randomUUID(),
   1010       fact = {
   1011         actionId: crypto.randomUUID(),
   1012         origin: 'wss://inbox.example.org',
   1013         role: 'access_archive',
   1014         eventId: template.self.eventId,
   1015         attempt: 1,
   1016         status: 'accepted',
   1017         observedAtMilliseconds: 1,
   1018         readbackWire: null
   1019       };
   1020     const row = (count: number) => ({
   1021       owner: f.owner,
   1022       id,
   1023       wire: JSON.stringify({
   1024         ...template,
   1025         id,
   1026         receipts: Array.from({ length: count }, () => fact)
   1027       })
   1028     });
   1029     const bytes = (rows: typeof original) =>
   1030       rows.reduce(
   1031         (sum, x) => sum + new TextEncoder().encode(JSON.stringify(x)).length,
   1032         0
   1033       );
   1034     const empty = bytes([...original, row(0)]),
   1035       step = bytes([row(1)]) - bytes([row(0)]),
   1036       limit = 8 * 1024 * 1024;
   1037     const count = Math.floor((limit - empty + 1) / (step + 1));
   1038     await f.inject([row(count)]);
   1039     const before = await f.stored(),
   1040       append = await f.append(actual),
   1041       after = await f.stored();
   1042     return {
   1043       append,
   1044       exact: JSON.stringify(before) === JSON.stringify(after),
   1045       headroom: limit - bytes(before),
   1046       count: after.length,
   1047       row: f.snapshot()!.record,
   1048       evidence: !!window.pb.inboxProbeArchiveAttemptEvidence(actual)
   1049     };
   1050   });
   1051   expect(result.headroom).toBeGreaterThanOrEqual(0);
   1052   expect(result.headroom).toBeLessThan(350);
   1053   expect(result.append.status).toBe('capacity');
   1054   expect(result.exact).toBe(true);
   1055   expect(result.count).toBe(2);
   1056   expect(result.row.revision).toBe(1);
   1057   expect(result.row.receipts).toHaveLength(0);
   1058   expect(result.evidence).toBe(true);
   1059   expect(privateEvents()).toHaveLength(1);
   1060   noPrivateReads();
   1061 });
   1062 
   1063 test('actual auth-required refusal without C7 setup prevents any subsequent probe key prompt or charge', async ({
   1064   page
   1065 }) => {
   1066   response = 'auth_required';
   1067   auth = true;
   1068   const first = await page.evaluate(() => window.pbFixture.publish());
   1069   expect(first).toMatchObject({ status: 'refused', attempt: 1 });
   1070   expect(privateEvents()).toHaveLength(1);
   1071   const refused = await page.evaluate(async () => {
   1072     const f = window.pbFixture;
   1073     await f.append();
   1074     const before = f.counts();
   1075     f.mode('hold_key');
   1076     const second = await f.publish();
   1077     return { second, before, after: f.counts(), waiting: f.waiting() };
   1078   });
   1079   expect(refused.second).toEqual({ status: 'stopped' });
   1080   expect(refused.after).toEqual(refused.before);
   1081   expect(refused.waiting).toBe('');
   1082   expect(privateEvents()).toHaveLength(1);
   1083   response = 'accepted';
   1084   await page.evaluate(() => {
   1085     window.pbFixture.mode('normal');
   1086     return window.pb.authenticateInboxAccess(
   1087       window.pbFixture.controller()!,
   1088       'wss://inbox.example.org',
   1089       'reviewed_inbox_connection_auth'
   1090     );
   1091   });
   1092   await expect
   1093     .poll(() =>
   1094       page.evaluate(
   1095         () =>
   1096           window.pb.inboxAccessControllerSnapshot(
   1097             window.pbFixture.controller()!
   1098           )?.auth[0]?.state
   1099       )
   1100     )
   1101     .toBe('challenge');
   1102   expect(
   1103     await page.evaluate(() =>
   1104       window.pb.respondInboxAccessAuthentication(
   1105         window.pbFixture.controller()!,
   1106         'wss://inbox.example.org',
   1107         'reviewed_inbox_auth_response'
   1108       )
   1109     )
   1110   ).toBe('accepted');
   1111   const next = await page.evaluate(() => window.pbFixture.publish());
   1112   expect(next).toMatchObject({
   1113     status: 'accepted',
   1114     attempt: 2,
   1115     actionId: first.actionId
   1116   });
   1117   expect(privateEvents()).toHaveLength(2);
   1118   expect(frames.filter((x) => x.frame[0] === 'AUTH')).toHaveLength(1);
   1119   noPrivateReads();
   1120 });
   1121 
   1122 test('three-origin original action has three admissions per target, nine genuine facts and bounded held physical sockets', async ({
   1123   page
   1124 }) => {
   1125   const result = await page.evaluate(async () => {
   1126     const f = window.pbFixture,
   1127       originalAction = f.action(),
   1128       outcomes = [];
   1129     for (const origin of [
   1130       'wss://inbox.example.org',
   1131       'wss://peer.example.org',
   1132       'wss://archive.example.org'
   1133     ]) {
   1134       for (let n = 0; n < 3; n++) {
   1135         const actual = await f.publish(f.permission(origin));
   1136         outcomes.push(actual);
   1137         await f.append(actual);
   1138         await f.commitOriginal();
   1139       }
   1140       outcomes.push(await f.publish(f.permission(origin)));
   1141     }
   1142     return {
   1143       outcomes,
   1144       same: f.action() === originalAction,
   1145       row: f.snapshot()!.record
   1146     };
   1147   });
   1148   expect(result.same).toBe(true);
   1149   expect(result.row.receipts).toHaveLength(9);
   1150   expect(result.row.revision).toBe(10);
   1151   const attempted = result.outcomes.filter((x) => x.actionId);
   1152   expect(new Set(attempted.map((x) => x.actionId)).size).toBe(1);
   1153   expect(attempted.map((x) => x.attempt)).toEqual([1, 2, 3, 1, 2, 3, 1, 2, 3]);
   1154   expect(result.outcomes.filter((x) => !x.actionId)).toEqual(
   1155     Array(3).fill({ status: 'stopped' })
   1156   );
   1157   expect(privateEvents()).toHaveLength(9);
   1158   expect(privatePeak).toBe(3);
   1159   expect(privatePhysical.size).toBe(3);
   1160   noPrivateReads();
   1161   await page.evaluate(() => {
   1162     window.pbDelayClose = true;
   1163     window.pbFixture.stop();
   1164   });
   1165   expect(privatePhysical.size).toBe(3);
   1166   expect(
   1167     await page.evaluate(() =>
   1168       window.pb.privatePoolCleanupRequired(window.pbFixture.pool())
   1169     )
   1170   ).toBe(true);
   1171   expect(
   1172     await page.evaluate(() =>
   1173       window.pbFixture.publish(
   1174         window.pbFixture.permission('wss://peer.example.org')
   1175       )
   1176     )
   1177   ).toEqual({ status: 'stopped' });
   1178   expect(privateEvents()).toHaveLength(9);
   1179   await page.evaluate(() => {
   1180     window.pbDelayClose = false;
   1181     for (const release of window.pbHeldClose ?? []) release();
   1182     window.pbFixture.stop();
   1183   });
   1184   await expect.poll(() => privatePhysical.size).toBe(0);
   1185   expect(privatePeak).toBe(3);
   1186 });
   1187 
   1188 test('three-origin original action shares total forty-five seconds across targets and refreshed ACKs', async ({
   1189   page
   1190 }) => {
   1191   response = 'unknown';
   1192   await page.evaluate(() => {
   1193     const f = window.pbFixture;
   1194     window.pbNetworkClock = f.installNetworkClock();
   1195     window.pbRestore = () => window.pbNetworkClock!.restore();
   1196     window.pbPending = f.publish();
   1197   });
   1198   await expect.poll(() => privateEvents().length).toBe(1);
   1199   await page.evaluate(() => window.pbNetworkClock!.advance(46000));
   1200   const result = await page.evaluate(async () => {
   1201     const f = window.pbFixture,
   1202       actual = (await window.pbPending) as NonNullable<
   1203         ReturnType<typeof f.last>
   1204       >;
   1205     await f.append(actual);
   1206     const recommit = await f.commitOriginal();
   1207     return {
   1208       actual,
   1209       recommit: recommit.status,
   1210       others: await Promise.all(
   1211         ['wss://peer.example.org', 'wss://archive.example.org'].map((origin) =>
   1212           f.publish(f.permission(origin))
   1213         )
   1214       ),
   1215       observations: window.pbNetworkClock!.observations(),
   1216       row: f.snapshot()!.record
   1217     };
   1218   });
   1219   expect(result.actual).toMatchObject({ status: 'timed_out', attempt: 1 });
   1220   expect(result.recommit).toBe('existing');
   1221   expect(result.others).toEqual([{ status: 'stopped' }, { status: 'stopped' }]);
   1222   expect(result.observations).toBeGreaterThan(2);
   1223   expect(result.row.receipts).toHaveLength(1);
   1224   expect(privateEvents()).toHaveLength(1);
   1225   expect(privatePeak).toBeLessThanOrEqual(3);
   1226   noPrivateReads();
   1227 });
   1228 
   1229 for (const nested of [false, true])
   1230   test(`three-origin actual SDK teardown ${nested ? 'reentrant Stop' : 'failure'} retries original scope while another origin remains live`, async ({
   1231     page
   1232   }) => {
   1233     await page.evaluate(async () => {
   1234       const f = window.pbFixture,
   1235         other = f.scope(['wss://archive.example.org'], 'delivery');
   1236       window.pbOtherPool = other;
   1237       const result = await window.pb.publishInboxProbeArchiveAttempt(
   1238         other,
   1239         f.permission('wss://archive.example.org')!,
   1240         new AbortController().signal
   1241       );
   1242       if (result.status !== 'accepted')
   1243         throw Error('actual other scope publication');
   1244       await f.append(result);
   1245     });
   1246     expect(privatePhysical.size).toBe(1);
   1247     response = 'unknown';
   1248     await page.evaluate((nested) => {
   1249       const f = window.pbFixture;
   1250       f.pool();
   1251       const fault = f.installAttemptTeardownFailure(
   1252         nested
   1253           ? () => {
   1254               window.pbNestedCleanup = (window.pbNestedCleanup ?? 0) + 1;
   1255               try {
   1256                 f.stop();
   1257               } catch {
   1258                 window.pbNestedFailure = (window.pbNestedFailure ?? 0) + 1;
   1259               }
   1260             }
   1261           : undefined
   1262       );
   1263       window.pbRestore = () => fault.restore();
   1264       window.pbAbort = new AbortController();
   1265       window.pbPending = f.publish(f.permission(), window.pbAbort.signal);
   1266     }, nested);
   1267     await expect.poll(() => privateEvents().length).toBe(2);
   1268     const first = await page.evaluate(async () => {
   1269       const f = window.pbFixture;
   1270       window.pbAbort!.abort();
   1271       const actual = (await window.pbPending) as NonNullable<
   1272           ReturnType<typeof f.last>
   1273         >,
   1274         evidence = window.pb.inboxProbeArchiveAttemptEvidence(actual);
   1275       const cleanup = window.pb.privatePoolCleanupRequired(f.pool());
   1276       window.pbRestore?.();
   1277       const append = await f.append(actual);
   1278       f.stop();
   1279       f.stop();
   1280       return {
   1281         actual,
   1282         evidence: !!evidence,
   1283         cleanup,
   1284         append,
   1285         cleanAfter: window.pb.privatePoolCleanupRequired(f.pool()),
   1286         row: f.snapshot()!.record,
   1287         next: await f.publish()
   1288       };
   1289     });
   1290     expect(first.actual).toMatchObject({ status: 'unknown', attempt: 1 });
   1291     expect(first.evidence).toBe(true);
   1292     expect(first.cleanup).toBe(true);
   1293     expect(first.append.status).toBe('saved');
   1294     expect(first.row.receipts[1].status).toBe('unknown');
   1295     expect(first.next).toEqual({ status: 'stopped' });
   1296     await expect.poll(() => privatePhysical.size).toBe(1);
   1297     await expect
   1298       .poll(() =>
   1299         page.evaluate(() =>
   1300           window.pb.privatePoolCleanupRequired(window.pbFixture.pool())
   1301         )
   1302       )
   1303       .toBe(false);
   1304     expect(privateConnections.get('wss://archive.example.org')).toBe(1);
   1305     response = 'accepted';
   1306     const other = await page.evaluate(async () => {
   1307       const f = window.pbFixture,
   1308         pool = window.pbOtherPool!;
   1309       return window.pb.publishInboxProbeArchiveAttempt(
   1310         pool,
   1311         f.permission('wss://archive.example.org')!,
   1312         new AbortController().signal
   1313       );
   1314     });
   1315     expect(other).toMatchObject({ status: 'accepted', attempt: 2 });
   1316     expect(privateConnections.get('wss://archive.example.org')).toBe(1);
   1317     expect(privateEvents()).toHaveLength(3);
   1318     expect(privatePeak).toBeLessThanOrEqual(3);
   1319     if (nested)
   1320       expect(
   1321         await page.evaluate(() => ({
   1322           nested: window.pbNestedCleanup,
   1323           failed: window.pbNestedFailure
   1324         }))
   1325       ).toEqual({ nested: 1, failed: 1 });
   1326     noPrivateReads();
   1327   });
   1328 
   1329 test('genuine ordinary paired publication cannot enter the separate probe facade or evidence family', async ({
   1330   page
   1331 }) => {
   1332   const result = await page.evaluate(async () => {
   1333     window.pbFixture.close();
   1334     const ordinary = await window.pb.makeOrdinaryPublicationFixture();
   1335     try {
   1336       await ordinary.prepare();
   1337       const permission = ordinary.permission('peer');
   1338       if (!permission)
   1339         throw Error('genuine original ordinary permission missing');
   1340       const result = await window.pb.publishInboxProbeArchiveAttempt(
   1341         {} as Parameters<typeof window.pb.publishInboxProbeArchiveAttempt>[0],
   1342         permission as unknown as Parameters<
   1343           typeof window.pb.publishInboxProbeArchiveAttempt
   1344         >[1],
   1345         new AbortController().signal
   1346       );
   1347       return {
   1348         result,
   1349         evidence: !!window.pb.inboxProbeArchiveAttemptEvidence(result)
   1350       };
   1351     } finally {
   1352       ordinary.close();
   1353     }
   1354   });
   1355   expect(result.result).toEqual({ status: 'stopped' });
   1356   expect(result.evidence).toBe(false);
   1357   expect(privateEvents()).toHaveLength(0);
   1358   noPrivateReads();
   1359 });
   1360 
   1361 test('actual original SDK socket construction closing the genuine controller is fenced before EVENT and attempted evidence', async ({
   1362   page
   1363 }) => {
   1364   const result = await page.evaluate(async () => {
   1365     const f = window.pbFixture;
   1366     window.pbInvalidateOnSocket = true;
   1367     const actual = await f.publish();
   1368     window.pbInvalidateOnSocket = false;
   1369     return {
   1370       actual,
   1371       evidence: !!window.pb.inboxProbeArchiveAttemptEvidence(actual),
   1372       rows: await f.stored(),
   1373       ready: window.pb.inboxAccessControllerSnapshot(f.controller()!)?.readiness
   1374     };
   1375   });
   1376   expect(result.actual.status).toBe('stopped');
   1377   expect(result.actual.actionId).toBeUndefined();
   1378   expect(result.actual.attempt).toBeUndefined();
   1379   expect(result.evidence).toBe(false);
   1380   expect(
   1381     (JSON.parse(result.rows[0].wire) as { receipts: unknown[] }).receipts
   1382   ).toHaveLength(0);
   1383   expect(result.ready).toBe('unavailable');
   1384   expect(privateEvents()).toHaveLength(0);
   1385   noPrivateReads();
   1386 });