Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Checks:
```bash
npm test # 95 tests: evaluator, policies, store, fault injection, concurrency, HTTP, flows
npm run typecheck # server, tests and UI
npm run test:e2e # 9 Playwright tests: judge journey against the real server (run `npx playwright install chromium` once)
npm run test:e2e # 10 Playwright tests: judge journey against the real server (run `npx playwright install chromium` once)
# E2E_BASE_URL=https://… npm run test:e2e runs the same journey as a smoke test against a deployed URL
npm run spike:sqlite
```
Expand Down
22 changes: 22 additions & 0 deletions e2e/judge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ test('@mobile renders without horizontal scroll and shows the verdict', async ({
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow).toBeLessThanOrEqual(0);
});

test('first load: a late session response cannot split the page across two sessions', async ({ page }) => {
// Reproduces the live-network race: boot requests and the scenario load each start a session; if the older
// session's Set-Cookie lands after the scenario was created, later requests read a session that does not own it.
let release!: () => void;
const scenarioCreated = new Promise<void>((r) => { release = r; });
let posts = 0;
await page.route('**/api/session', async (route) => {
const hold = route.request().method() === 'POST' && posts++ === 0;
const response = await route.fetch();
if (hold) await Promise.race([scenarioCreated, new Promise((r) => setTimeout(r, 3000))]);
await route.fulfill({ response });
});
await page.route('**/api/scenarios/*', async (route) => {
const response = await route.fetch();
await route.fulfill({ response });
if (route.request().method() === 'POST') release();
});
await page.goto('/');
await expectTruthful(page, 'DEFER');
await expect(page.getByRole('alert')).toHaveCount(0);
});
5 changes: 4 additions & 1 deletion ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export class ApiError extends Error {
}

let sessionPromise: Promise<void> | null = null;
export const newSession = () => (sessionPromise = fetch('/api/session', { method: 'POST' }).then(() => undefined));
// Sessions are created one after another: two concurrent POSTs let the older response's Set-Cookie land last,
// so later requests would carry a session that does not own the proposal the caller just created.
export const newSession = () => (sessionPromise = (sessionPromise ?? Promise.resolve()).catch(() => {})
.then(() => fetch('/api/session', { method: 'POST' })).then(() => undefined));

export async function api<T = any>(method: string, path: string, body?: unknown, retried = false): Promise<T> {
if (!sessionPromise) newSession();
Expand Down
Loading