sign-listing.spec.ts (6857B)
1 import { expect, test } from '@playwright/test'; 2 import { build } from 'vite'; 3 import { fileURLToPath } from 'node:url'; 4 import { createStaticHarness } from '../integration/harness/static.ts'; 5 import type * as Fixture from './harness/sign-listing.ts'; 6 declare global { 7 interface Window { 8 hcp111: typeof Fixture; 9 hcp111Fixture: Awaited<ReturnType<typeof Fixture.createFixture>>; 10 } 11 } 12 let server: Awaited<ReturnType<typeof createStaticHarness>>, bundle: string; 13 test.beforeAll(async () => { 14 server = await createStaticHarness(); 15 const result = await build({ 16 configFile: false, 17 logLevel: 'silent', 18 build: { 19 write: false, 20 minify: false, 21 lib: { 22 entry: fileURLToPath( 23 new URL('./harness/sign-listing.ts', import.meta.url) 24 ), 25 name: 'hcp111', 26 formats: ['iife'] 27 } 28 } 29 }); 30 const output = Array.isArray(result) ? result[0] : result; 31 if (!('output' in output)) throw Error('fixture bundle missing'); 32 const chunks = output.output.filter((row) => row.type === 'chunk'); 33 expect(chunks).toHaveLength(1); 34 bundle = chunks[0].code; 35 }); 36 test.afterAll(async () => server.close()); 37 test.beforeEach(async ({ page }) => { 38 await page.goto(server.url + '/search'); 39 await page.addScriptTag({ content: bundle }); 40 await page.evaluate(async () => { 41 window.hcp111Fixture = await window.hcp111.createFixture(); 42 }); 43 }); 44 test.afterEach(async ({ page }) => { 45 if (!page.isClosed()) 46 await page.evaluate(() => window.hcp111Fixture?.close()); 47 }); 48 test('HCP111 original verified signed artifact commits before a typed plan and repeated clicks never re-sign', async ({ 49 page 50 }) => { 51 const r = await page.evaluate(() => window.hcp111Fixture.exact()); 52 console.log('HCP111_DIAGNOSTIC_ACTUAL_ORIGINAL_RESULT', JSON.stringify(r)); 53 expect(r.status).toBe('prepared'); 54 expect(r.same).toBe(true); 55 expect(r.signatures).toBe(1); 56 expect(r.keys).toBeGreaterThan(1); 57 expect(r.revision).toBe(2); 58 expect(r.artifact?.eventId).toBe(r.expectedHash); 59 expect(r.plan?.wire).toBe(r.artifact?.wire); 60 expect(r.originalCapture).toBe(true); 61 expect(r.retry).toBe('prepared'); 62 expect(r.sameArtifact).toBe(true); 63 }); 64 for (const mode of [ 65 'author', 66 'kind', 67 'time', 68 'tags', 69 'content', 70 'cached', 71 'mutate' 72 ] as const) 73 test(`HCP111 actual signed changed ${mode} response never commits or exposes a plan`, async ({ 74 page 75 }) => { 76 const r = await page.evaluate( 77 (mode) => window.hcp111Fixture.wrong(mode), 78 mode 79 ); 80 expect(r.exposed).toBe(false); 81 expect(r.signatures).toBe(1); 82 expect(r.revision).toBe(1); 83 expect(r.artifact).toBeNull(); 84 expect(r.retry).not.toBe('prepared'); 85 }); 86 test('HCP111 changed actual fresh extension key stops signature and plan', async ({ 87 page 88 }) => { 89 const r = await page.evaluate(() => window.hcp111Fixture.changedKey()); 90 expect(r.exposed).toBe(false); 91 expect(r.signatures).toBe(0); 92 expect(r.artifact).toBeNull(); 93 }); 94 for (const logout of [false, true]) 95 test(`HCP111 held actual signature after Stop logout=${logout} remains original without artifact or plan`, async ({ 96 page 97 }) => { 98 const r = await page.evaluate( 99 (logout) => window.hcp111Fixture.late(logout), 100 logout 101 ); 102 expect(r.exposed).toBe(false); 103 expect(r.signatures).toBe(1); 104 expect(r.revision).toBe(1); 105 expect(r.artifact).toBeNull(); 106 expect(r.snapshot?.owner).toBe(r.originalOwner); 107 expect(r.snapshot?.command).toBe(r.command); 108 expect(r.snapshot?.hash).toBe(r.expectedHash); 109 expect(r.snapshot?.lateAvailable).toBe(true); 110 }); 111 for (const revision of [1, 2] as const) 112 test(`HCP111 actual revision${revision} transaction abort stops the dependent effect`, async ({ 113 page 114 }) => { 115 const r = await page.evaluate( 116 (revision) => window.hcp111Fixture.fault(revision, false), 117 revision 118 ); 119 expect(r.exposed).toBe(false); 120 expect(r.faultPuts).toBe(1); 121 expect(r.revision).toBe(revision - 1); 122 expect(r.artifact).toBeNull(); 123 expect(r.signatures).toBe(revision - 1); 124 expect(r.originalCapture).toBe(true); 125 }); 126 test('HCP111 actual artifact commit lost acknowledgement reconciles exact original signed bytes before plan', async ({ 127 page 128 }) => { 129 const r = await page.evaluate(() => window.hcp111Fixture.fault(2, true)); 130 expect(r.status).toBe('prepared'); 131 expect(r.exposed).toBe(true); 132 expect(r.faultPuts).toBe(1); 133 expect(r.revision).toBe(2); 134 expect(r.signatures).toBe(1); 135 expect(r.sameArtifact).toBe(true); 136 expect(r.originalCapture).toBe(true); 137 }); 138 test('HCP111 original inbox retirement during the actual prompt revokes continuity without another effect', async ({ 139 page 140 }) => { 141 const r = await page.evaluate(() => window.hcp111Fixture.late(false, true)); 142 expect(r.exposed).toBe(false); 143 expect(r.signatures).toBe(1); 144 expect(r.revision).toBe(1); 145 expect(r.artifact).toBeNull(); 146 expect(r.snapshot?.owner).toBe(r.originalOwner); 147 expect(r.snapshot?.hash).toBe(r.expectedHash); 148 expect(r.snapshot?.lateAvailable).toBe(true); 149 }); 150 test('HCP111 unavailable artifact readback preserves uncertainty until exact original explicit retry without a new signature or put', async ({ 151 page 152 }) => { 153 const r = await page.evaluate(() => 154 window.hcp111Fixture.fault(2, true, true) 155 ); 156 expect(r.status).toBe('unknown'); 157 expect(r.exposed).toBe(false); 158 expect(r.faultPuts).toBe(1); 159 expect(r.revision).toBe(2); 160 expect(r.signatures).toBe(1); 161 expect(r.originalCapture).toBe(true); 162 expect(r.retryStatus).toBe('prepared'); 163 expect(r.retryExact).toBe(true); 164 expect(r.retryPuts).toBe(0); 165 }); 166 test('HCP111 actual valid mismatched signed artifact readback conflicts without adoption or another effect', async ({ 167 page 168 }) => { 169 const r = await page.evaluate(() => 170 window.hcp111Fixture.fault(2, true, false, 'valid') 171 ); 172 expect(r.status).toBe('conflict'); 173 expect(r.exposed).toBe(false); 174 expect(r.readStatus).toBe('found'); 175 expect(r.faultPuts).toBe(2); 176 expect(r.nativePuts).toBe(3); 177 expect(r.revision).toBe(2); 178 expect(r.signatures).toBe(1); 179 expect(r.originalCapture).toBe(false); 180 expect(r.retryStatus).toBe('conflict'); 181 expect(r.retryExact).toBe(false); 182 expect(r.retryPuts).toBe(0); 183 }); 184 test('HCP111 actual corrupt artifact readback preserves stored evidence and refuses an explicit retry', async ({ 185 page 186 }) => { 187 const r = await page.evaluate(() => 188 window.hcp111Fixture.fault(2, true, false, 'corrupt') 189 ); 190 expect(r.status).toBe('unknown'); 191 expect(r.exposed).toBe(false); 192 expect(r.readStatus).toBe('corrupt_record'); 193 expect(r.corruptWire).toBe('{"schema":999}'); 194 expect(r.faultPuts).toBe(2); 195 expect(r.nativePuts).toBe(3); 196 expect(r.signatures).toBe(1); 197 expect(r.retryStatus).toBe('unavailable'); 198 expect(r.retryExact).toBe(false); 199 expect(r.retryPuts).toBe(0); 200 });