prepare-listing.spec.ts (5885B)
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/prepare-listing.ts'; 6 declare global { 7 interface Window { 8 hcp110: typeof Fixture; 9 hcp110Fixture: 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/prepare-listing.ts', import.meta.url) 24 ), 25 name: 'hcp110', 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.hcp110Fixture = await window.hcp110.createFixture(); 42 }); 43 }); 44 test.afterEach(async ({ page }) => { 45 if (!page.isClosed()) 46 await page.evaluate(() => window.hcp110Fixture?.close()); 47 }); 48 49 test('HCP110 double submit retains one immutable intent and future edits cannot replace it', async ({ 50 page 51 }) => { 52 const result = await page.evaluate(() => window.hcp110Fixture.doubleSubmit()); 53 expect(result.same).toBe(true); 54 expect(result.repeatReview).toBe('existing'); 55 expect(result.repeatCaptureUnchanged).toBe(true); 56 expect(result.operations).toBe(1); 57 expect(result.futureCaptureUnchanged).toBe(true); 58 expect(result.retry).toBe('existing'); 59 expect(result.signatures).toBe(0); 60 }); 61 test('HCP110 concurrent original reviews retain one command capture across asynchronous hashing', async ({ 62 page 63 }) => { 64 const result = await page.evaluate(() => 65 window.hcp110Fixture.concurrentReviews() 66 ); 67 expect(result.sameReview).toBe(true); 68 expect(result.sameTemplate).toBe(true); 69 expect(result.first).toBe('saved'); 70 expect(result.second).toBe('existing'); 71 expect(result.operations).toBe(1); 72 expect(result.signatures).toBe(0); 73 }); 74 test('HCP110 actual committed intent with lost acknowledgement reconciles exact original capture without another write', async ({ 75 page 76 }) => { 77 const result = await page.evaluate(() => 78 window.hcp110Fixture.unknown('exact') 79 ); 80 expect(result.status).toBe('existing'); 81 expect(result.nativePuts).toBe(1); 82 expect(result.originalCapture).toBe(true); 83 expect(result.operations).toBe(1); 84 expect(result.retry).toBe('existing'); 85 expect(result.signatures).toBe(0); 86 }); 87 test('HCP110 failed native readback preserves original unknown completion before explicit retry', async ({ 88 page 89 }) => { 90 const result = await page.evaluate(() => 91 window.hcp110Fixture.unknown('unavailable') 92 ); 93 expect(result.status).toBe('unknown_completion'); 94 expect(result.nativePuts).toBe(1); 95 expect(result.originalCapture).toBe(true); 96 expect(result.operations).toBe(1); 97 expect(result.retry).toBe('existing'); 98 expect(result.signatures).toBe(0); 99 }); 100 test('HCP110 actual mismatched readback refuses the original command without adopting another capture', async ({ 101 page 102 }) => { 103 const result = await page.evaluate(() => 104 window.hcp110Fixture.unknown('mismatch') 105 ); 106 expect(result.status).toBe('conflict'); 107 expect(result.originalCapture).toBe(false); 108 expect(result.nativePuts).toBe(2); 109 expect(result.operations).toBe(1); 110 expect(result.retry).toBe('conflict'); 111 expect(result.signatures).toBe(0); 112 }); 113 test('HCP110 native read request setup failure resolves typed unavailable without writes', async ({ 114 page 115 }) => { 116 const result = await page.evaluate(() => window.hcp110Fixture.failedRead()); 117 expect(result.status).toBe('unavailable'); 118 expect(result.operations).toBe(0); 119 expect(result.signatures).toBe(0); 120 }); 121 122 test('HCP110 changing the same command conflicts and a random listing identifier is independent of title', async ({ 123 page 124 }) => { 125 const result = await page.evaluate(() => 126 window.hcp110Fixture.commandConflict() 127 ); 128 expect(result.conflict).toBe('conflict'); 129 expect(result.identifierRandom).toBe(true); 130 expect(result.identifierStable).toBe(true); 131 expect(result.operations).toBe(1); 132 expect(result.signatures).toBe(0); 133 }); 134 135 test('HCP110 exact acknowledged draft revision and original frozen destinations are reserved', async ({ 136 page 137 }) => { 138 const result = await page.evaluate(() => 139 window.hcp110Fixture.exactRevision() 140 ); 141 expect(result.exact).toBe(true); 142 expect(result.description).toBe('Second complete description'); 143 expect(result.targetsFrozen).toBe(true); 144 expect(result.signatures).toBe(0); 145 }); 146 147 test('HCP110 stale draft revision or original readiness retirement cannot reserve a new intent', async ({ 148 page 149 }) => { 150 const result = await page.evaluate(() => window.hcp110Fixture.stale()); 151 expect(result.changedDraft).toBe('conflict'); 152 expect(result.retired).toBe('unavailable'); 153 expect(result.operations).toBe(0); 154 expect(result.signatures).toBe(0); 155 }); 156 157 test('HCP110 actual transaction abort creates no operation and original explicit retry reconciles the same capture', async ({ 158 page 159 }) => { 160 const result = await page.evaluate(() => window.hcp110Fixture.abort()); 161 expect(result.aborted).toBe('aborted'); 162 expect(result.beforeRetry).toBe(0); 163 expect(result.retry).toBe('saved'); 164 expect(result.operations).toBe(1); 165 expect(result.originalCapture).toBe(true); 166 expect(result.signatures).toBe(0); 167 });