[repo] Workspace: Scaffold Phase 0 with schema, engine, content, ui and the PWA shell
pnpm + turbo workspace with the commands from CLAUDE.md §3. The contracts from §6 as JSON Schemas with generated types; localDay as the one place a day is computed; the forbidden-word list shared by lint:copy and the library validator, with 13 negative fixtures; a Svelte 5 PWA shell built under /Rosea/ with a meta CSP. E2E and offline suites run against the built bundle; the offline one closes the server rather than emulating. Analysis: .agents/features/phase0-workspace.md
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import AxeBuilder from '@axe-core/playwright';
|
||||
import { expect, test, type Page } from '@playwright/test';
|
||||
import { PRODUCT_NAME } from '@rosea/schema';
|
||||
import { en } from '@rosea/ui/copy';
|
||||
import { BASE, startStaticServer, type StaticServer } from './static-server.js';
|
||||
|
||||
let server: StaticServer;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
server = await startStaticServer();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await server.close();
|
||||
});
|
||||
|
||||
/** Opens the app and records every request and every CSP violation on the way. */
|
||||
async function open(page: Page): Promise<{ requests: string[]; cspViolations: string[] }> {
|
||||
const requests: string[] = [];
|
||||
const cspViolations: string[] = [];
|
||||
page.on('request', (r) => requests.push(r.url()));
|
||||
page.on('console', (m) => {
|
||||
if (m.type() === 'error' && /Content Security Policy/i.test(m.text())) cspViolations.push(m.text());
|
||||
});
|
||||
await page.goto(server.url);
|
||||
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||
// Let the worker register and precache, so its requests are counted too.
|
||||
await page.waitForFunction(() => navigator.serviceWorker.ready.then(() => true), null, { timeout: 20_000 });
|
||||
return { requests, cspViolations };
|
||||
}
|
||||
|
||||
test('the built app renders its name and its one line, under the base path', async ({ page }) => {
|
||||
await open(page);
|
||||
await expect(page.getByText(en.shell.preparing)).toBeVisible();
|
||||
await expect(page).toHaveTitle(PRODUCT_NAME);
|
||||
});
|
||||
|
||||
test('nothing is requested from any other origin', async ({ page }) => {
|
||||
const { requests } = await open(page);
|
||||
expect(requests.length, 'the page must have made requests for this to mean anything').toBeGreaterThan(0);
|
||||
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
|
||||
});
|
||||
|
||||
test('nothing is written to cookies or Web Storage', async ({ page }) => {
|
||||
await open(page);
|
||||
const written = await page.evaluate(() => ({
|
||||
cookie: document.cookie,
|
||||
localStorage: localStorage.length,
|
||||
sessionStorage: sessionStorage.length
|
||||
}));
|
||||
expect(written).toEqual({ cookie: '', localStorage: 0, sessionStorage: 0 });
|
||||
expect(await page.context().cookies()).toEqual([]);
|
||||
});
|
||||
|
||||
test('the built page carries the CSP and no inline script, and nothing violates it', async ({ page }) => {
|
||||
const { cspViolations } = await open(page);
|
||||
const html = await (await fetch(server.url)).text();
|
||||
|
||||
// Read from the DOM, not the raw HTML: Vite escapes the quotes as '.
|
||||
const csp = await page.locator('meta[http-equiv="Content-Security-Policy"]').getAttribute('content');
|
||||
expect(csp, 'CSP meta tag in the built index.html').toBeTruthy();
|
||||
expect(csp).toContain("default-src 'self'");
|
||||
expect(csp).not.toContain('unsafe-inline');
|
||||
expect(csp).not.toContain('unsafe-eval');
|
||||
|
||||
const inline = [...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/g)].filter(
|
||||
([, attrs, body]) => !/\bsrc=/.test(attrs ?? '') && (body ?? '').trim() !== ''
|
||||
);
|
||||
expect(inline.map(([tag]) => tag)).toEqual([]);
|
||||
expect(cspViolations).toEqual([]);
|
||||
});
|
||||
|
||||
test('manifest scope, start_url and the service worker scope all equal the base path', async ({ page }) => {
|
||||
await open(page);
|
||||
|
||||
const manifestHref = await page.locator('link[rel="manifest"]').getAttribute('href');
|
||||
expect(manifestHref, 'manifest link').toBeTruthy();
|
||||
const manifest = (await (await fetch(new URL(manifestHref!, server.url))).json()) as Record<string, unknown>;
|
||||
|
||||
expect(manifest['scope']).toBe(BASE);
|
||||
expect(manifest['start_url']).toBe(BASE);
|
||||
expect(manifest['name']).toBe(PRODUCT_NAME);
|
||||
|
||||
const swScope = await page.evaluate(async () => (await navigator.serviceWorker.ready).scope);
|
||||
expect(swScope).toBe(server.url);
|
||||
|
||||
// The icon the manifest names must exist where the manifest says it is.
|
||||
const icons = manifest['icons'] as { src: string }[];
|
||||
for (const icon of icons) {
|
||||
const res = await fetch(new URL(icon.src, new URL(manifestHref!, server.url)));
|
||||
expect(res.status, icon.src).toBe(200);
|
||||
}
|
||||
});
|
||||
|
||||
test('the shell has no accessibility violations', async ({ page }) => {
|
||||
await open(page);
|
||||
const results = await new AxeBuilder({ page }).analyze();
|
||||
expect(results.violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user