feat(scopes): migrate GPL open backend + web e2e to scope grammar

backend-example (open ref backend): USER_HEADER, scope on the project DTO, raw routes under /api/scopes/:scope, no-op reportDrift + DOM lib (was red on main → now typecheck-green). GPL web specs (tools-open, symbol/footprint-write-remote, global-setup-web): /p/demo/:tool/* → /:scope/projects/demo/(file | -/:tool), direct API fetches scoped + x-pcbjam-owner → x-pcbjam-user. Reference backend keeps lib type 'user' (cosmetic vs closed 'org').

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gergő Törcsvári 2026-06-30 09:26:16 +02:00
commit fe0bec9909
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322
6 changed files with 75 additions and 46 deletions

View file

@ -1,8 +1,10 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
// Mirrors @pcbjam/shared OWNER_HEADER (tests/ doesn't depend on the shared pkg).
const OWNER_HEADER = 'x-pcbjam-owner';
// Mirrors @pcbjam/shared USER_HEADER (tests/ doesn't depend on the shared pkg).
const USER_HEADER = 'x-pcbjam-user';
// The reference backend serves its single project/libs under any scope.
const SCOPE = 'default';
/**
* 0009-C: the FULL remote footprint write round-trip no in-memory spike. Boot
@ -51,7 +53,7 @@ test('footprint editor save persists to the backend (remote write round-trip)',
page.on('console', (m) => logs.push(`[${m.type()}] ${m.text()}`));
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await page.goto(`/p/demo/footprint_editor/?libowner=${owner}`);
await page.goto(`/default/projects/demo/-/footprint_editor?libowner=${owner}`);
await expect(page.locator('#canvas')).toBeVisible({ timeout: 180000 });
await waitForRegistry(page, 180000);
await page.waitForFunction(
@ -64,8 +66,8 @@ test('footprint editor save persists to the backend (remote write round-trip)',
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
// Boot's ensure-user-lib created the writable container for this owner.
const ownerHeaders = { [OWNER_HEADER]: owner };
const libsRes = await fetch(`${BACKEND}/api/libs?kind=footprint`, { headers: ownerHeaders });
const ownerHeaders = { [USER_HEADER]: owner };
const libsRes = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs?kind=footprint`, { headers: ownerHeaders });
const libsBody = (await libsRes.json()) as { id: string; type: string }[];
logs.push(`[spec] libs: ${JSON.stringify(libsBody)}`);
expect(libsBody.some((l) => l.type === 'user' && l.id === USER_LIB), 'user lib created at boot').toBe(true);
@ -89,7 +91,7 @@ test('footprint editor save persists to the backend (remote write round-trip)',
await expect
.poll(
async () => {
const r = await fetch(`${BACKEND}/api/libs/${USER_LIB}/items`, { headers: ownerHeaders });
const r = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs/${USER_LIB}/items`, { headers: ownerHeaders });
items = r.ok ? ((await r.json()) as { kind: string; name: string }[]) : [];
return items.filter((i) => i.kind === 'footprint').length;
},
@ -103,7 +105,7 @@ test('footprint editor save persists to the backend (remote write round-trip)',
// The persisted body is a well-formed fork-native footprint (native version).
const bodyRes = await fetch(
`${BACKEND}/api/libs/${USER_LIB}/items/footprint/${encodeURIComponent(saved.name)}`,
`${BACKEND}/api/scopes/${SCOPE}/libs/${USER_LIB}/items/footprint/${encodeURIComponent(saved.name)}`,
{ headers: ownerHeaders },
);
const body = await bodyRes.text();

View file

@ -11,6 +11,9 @@ import type { FullConfig } from '@playwright/test';
*/
const API_BASE = process.env.BACKEND_URL ?? 'http://localhost:3060';
// The reference backend serves its single project under any scope; the editor
// addresses it as /:scope/projects/:name, so the specs use a fixed scope.
const SCOPE = 'default';
const DEMO_SLUG = 'demo';
const DEMO_FILES = ['demo.kicad_sch', 'demo.kicad_pcb', 'demo.kicad_wks'];
// Origin libs the remote-lib specs browse/place (symbol-write/footprint-browse).
@ -41,10 +44,10 @@ async function waitForApi(timeoutMs = 60000): Promise<void> {
}
async function verifyDemoProject(): Promise<void> {
const r = await fetch(`${API_BASE}/api/projects/${DEMO_SLUG}`);
const r = await fetch(`${API_BASE}/api/scopes/${SCOPE}/projects/${DEMO_SLUG}`);
if (!r.ok) {
throw new Error(
`GET /api/projects/${DEMO_SLUG} -> HTTP ${r.status}; ` +
`GET /api/scopes/${SCOPE}/projects/${DEMO_SLUG} -> HTTP ${r.status}; ` +
`is the backend's PROJECT_DIR pointing at tests/fixtures/demo?`
);
}
@ -58,9 +61,9 @@ async function verifyDemoProject(): Promise<void> {
async function verifyLibs(): Promise<void> {
for (const kind of ['symbol', 'footprint'] as const) {
const r = await fetch(`${API_BASE}/api/libs?kind=${kind}`);
const r = await fetch(`${API_BASE}/api/scopes/${SCOPE}/libs?kind=${kind}`);
if (!r.ok) {
throw new Error(`GET /api/libs?kind=${kind} -> HTTP ${r.status}`);
throw new Error(`GET /api/scopes/${SCOPE}/libs?kind=${kind} -> HTTP ${r.status}`);
}
const libs = (await r.json()) as { id: string }[];
const have = new Set(libs.map((l) => l.id));

View file

@ -1,8 +1,10 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
// Mirrors @pcbjam/shared OWNER_HEADER (tests/ doesn't depend on the shared pkg).
const OWNER_HEADER = 'x-pcbjam-owner';
// Mirrors @pcbjam/shared USER_HEADER (tests/ doesn't depend on the shared pkg).
const USER_HEADER = 'x-pcbjam-user';
// The reference backend serves its single project/libs under any scope.
const SCOPE = 'default';
/**
* 0004-D: the FULL remote write round-trip no in-memory spike. Boot ensures a
@ -30,7 +32,7 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
page.on('console', (m) => logs.push(`[${m.type()}] ${m.text()}`));
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await page.goto(`/p/demo/symbol_editor/?libowner=${owner}`);
await page.goto(`/default/projects/demo/-/symbol_editor?libowner=${owner}`);
await expect(page.locator('#canvas')).toBeVisible({ timeout: 150000 });
await waitForRegistry(page, 150000);
await page.waitForFunction(
@ -43,8 +45,8 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
// Boot's ensure-user-lib created "My Symbols" (slug my-symbols) for this owner.
const ownerHeaders = { [OWNER_HEADER]: owner };
const libsRes = await fetch(`${BACKEND}/api/libs`, { headers: ownerHeaders });
const ownerHeaders = { [USER_HEADER]: owner };
const libsRes = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs`, { headers: ownerHeaders });
const libsBody = (await libsRes.json()) as { id: string; type: string }[];
expect(libsBody.some((l) => l.type === 'user' && l.id === 'my-symbols'), 'user lib created at boot').toBe(true);
@ -96,7 +98,7 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
await expect
.poll(
async () => {
const r = await fetch(`${BACKEND}/api/libs/my-symbols/items`, { headers: ownerHeaders });
const r = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs/my-symbols/items`, { headers: ownerHeaders });
items = r.ok ? ((await r.json()) as { kind: string; name: string }[]) : [];
return items.length;
},
@ -110,7 +112,7 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
// The persisted body is a well-formed fork-native kicad_symbol_lib.
const bodyRes = await fetch(
`${BACKEND}/api/libs/my-symbols/items/symbol/${encodeURIComponent(saved.name)}`,
`${BACKEND}/api/scopes/${SCOPE}/libs/my-symbols/items/symbol/${encodeURIComponent(saved.name)}`,
{ headers: ownerHeaders },
);
const body = await bodyRes.text();

View file

@ -11,8 +11,12 @@ import { test, expect, type Page } from '@playwright/test';
* ensured by global-setup-web.ts.
*/
/** Scope segment for the demo project (the reference backend serves it for any). */
const SCOPE = 'default';
interface ToolCase {
/** URL path after /p/demo/ */
/** URL tail after /:scope/projects/demo/ a file path (tool inferred from the
* extension) for file tools, or `-/<tool>` for a file-less boot. */
route: string;
/** title the document settles on once the tool is up / file is open */
titleRe: RegExp;
@ -21,13 +25,13 @@ interface ToolCase {
}
const CASES: Record<string, ToolCase> = {
eeschema: { route: 'eeschema/demo.kicad_sch', titleRe: /demo — Schematic Editor/i, fileless: false },
pcbnew: { route: 'pcbnew/demo.kicad_pcb', titleRe: /demo — PCB Editor/i, fileless: false },
pl_editor: { route: 'pl_editor/demo.kicad_wks', titleRe: /demo — Drawing Sheet Editor/i, fileless: false },
calculator: { route: 'calculator/', titleRe: /Calculator Tools/i, fileless: true },
symbol_editor: { route: 'symbol_editor/', titleRe: /Symbol Editor/i, fileless: true },
footprint_editor: { route: 'footprint_editor/', titleRe: /Footprint Editor/i, fileless: true },
gerbview: { route: 'gerbview/', titleRe: /Gerber Viewer/i, fileless: true },
eeschema: { route: 'demo.kicad_sch', titleRe: /demo — Schematic Editor/i, fileless: false },
pcbnew: { route: 'demo.kicad_pcb', titleRe: /demo — PCB Editor/i, fileless: false },
pl_editor: { route: 'demo.kicad_wks', titleRe: /demo — Drawing Sheet Editor/i, fileless: false },
calculator: { route: '-/calculator', titleRe: /Calculator Tools/i, fileless: true },
symbol_editor: { route: '-/symbol_editor', titleRe: /Symbol Editor/i, fileless: true },
footprint_editor: { route: '-/footprint_editor', titleRe: /Footprint Editor/i, fileless: true },
gerbview: { route: '-/gerbview', titleRe: /Gerber Viewer/i, fileless: true },
};
/** Console text that must never appear (wizard-crash + URL-regex modal markers). */
@ -38,7 +42,7 @@ async function bootAndAssert(page: Page, tc: ToolCase): Promise<void> {
page.on('console', (m) => consoleLines.push(m.text()));
page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
await page.goto(`/p/demo/${tc.route}`);
await page.goto(`/${SCOPE}/projects/demo/${tc.route}`);
// boot.ts mounts the Emscripten <canvas id="canvas"> once the runtime starts.
await expect(page.locator('#canvas')).toBeVisible({ timeout: 120000 });