Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

PRD-8532 Replace Picsum E2E fixtures with local images (#4151)

Andrew Mikofalvy6d10e945d734
diff --git a/packages/app/playwright.a11y.config.ts b/packages/app/playwright.a11y.config.ts
index fa93aaf67..63e19d3b0 100644
--- a/packages/app/playwright.a11y.config.ts
+++ b/packages/app/playwright.a11y.config.ts
@@ -1,6 +1,6 @@
import { availableParallelism } from 'node:os';
import { defineConfig } from '@playwright/test';
-import { resolveWorkerCount } from './playwright.config.ts';
+import { EXPECT_TIMEOUT_MS, resolveWorkerCount } from './playwright.config.ts';
/**
* A11y Playwright config — per-worker fixture isolation (same shape as
@@ -42,6 +42,7 @@ export default defineConfig({
testDir: './tests/a11y',
testMatch: /.*\.e2e\.ts$/,
timeout: 120_000,
+ expect: { timeout: EXPECT_TIMEOUT_MS },
retries: isCI ? 2 : 0,
failOnFlakyTests: false,
forbidOnly: isCI,
diff --git a/packages/app/playwright.config.ts b/packages/app/playwright.config.ts
index c459f42cc..d924a3c0a 100644
--- a/packages/app/playwright.config.ts
+++ b/packages/app/playwright.config.ts
@@ -64,6 +64,13 @@ export function resolveWorkerCount(logicalCpus: number): number {
return Math.max(1, Math.floor(logicalCpus / LOGICAL_CPUS_PER_WORKER));
}
+/**
+ * Shared with the a11y and visual configs, which import it: all three tiers
+ * run on the same per-worker fixture, so they share one convergence band.
+ * Rationale for the value itself is on `expect` below.
+ */
+export const EXPECT_TIMEOUT_MS = isCI ? 15_000 : 5_000;
+
export default defineConfig({
testDir: './tests/stress',
testMatch: /.*\.e2e\.ts$/,
@@ -85,7 +92,7 @@ export default defineConfig({
// assertions safe by default; the per-test `timeout: 120_000` still bounds
// total damage. Keep inline `timeout:` overrides for genuinely exceptional
// waits only (cold-start, provider sync) — not as the default idiom.
- expect: { timeout: isCI ? 15_000 : 5_000 },
+ expect: { timeout: EXPECT_TIMEOUT_MS },
// failOnFlakyTests: false globally — retries absorb infra flake. Setting it
// true (so retry-success still fails the PR) promoted infrastructure noise
// (WebSocket EPIPE/ECONNRESET, transient CC1 broadcast jitter) to PR-red,
diff --git a/packages/app/playwright.visual.config.ts b/packages/app/playwright.visual.config.ts
index 90ca01fad..2431fb75b 100644
--- a/packages/app/playwright.visual.config.ts
+++ b/packages/app/playwright.visual.config.ts
@@ -1,6 +1,6 @@
import { availableParallelism } from 'node:os';
import { defineConfig } from '@playwright/test';
-import { resolveWorkerCount } from './playwright.config.ts';
+import { EXPECT_TIMEOUT_MS, resolveWorkerCount } from './playwright.config.ts';
/**
* Visual Playwright config — per-worker fixture isolation (same shape as
@@ -38,6 +38,7 @@ export default defineConfig({
testDir: './tests/visual',
testMatch: /.*\.e2e\.ts$/,
timeout: 120_000,
+ expect: { timeout: EXPECT_TIMEOUT_MS },
retries: 0,
// Fail when baselines are missing rather than silently auto-blessing the
// first run. Baseline updates require the explicit `test:visual:update`
diff --git a/packages/app/tests/integration/e2e-stop-rules.test.ts b/packages/app/tests/integration/e2e-stop-rules.test.ts
index b3b6a24db..d19adab5e 100644
--- a/packages/app/tests/integration/e2e-stop-rules.test.ts
+++ b/packages/app/tests/integration/e2e-stop-rules.test.ts
@@ -29,9 +29,21 @@
* easing token
* 11. Static value imports of the DEV ACP thread harness, which would
* defeat the dynamic-import gate that keeps it out of production
+ * 12. Remote placeholder-image hosts anywhere under
+ * tests/{stress,visual,a11y} — every `.ts`, not just `*.e2e.ts`,
+ * because entry 6 channels shared logic into `_helpers/` and the stub
+ * this rule replaced lived exactly there. Local fixtures decode
+ * deterministically; remote ones flake offline.
+ * Host-scoped deliberately, not lazily. The three hosts are the ones
+ * this repo actually contains in image-source position (docs' img
+ * reference, CM6-ELEMENTS.md, showcase/), not a guess at vendors; and
+ * an image-source-scoped predicate would miss the spellings that carry
+ * a host here, while redding the specs that put a reserved-name URL in
+ * genuine image-source position, where the decode is either irrelevant
+ * or required to fail — see the self-test below, which pins both halves
*/
-import { readdirSync, readFileSync } from 'node:fs';
+import { type Dirent, readdirSync, readFileSync } from 'node:fs';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
@@ -52,27 +64,33 @@ interface FileLines {
lines: string[];
}
-function listE2eFiles(): FileLines[] {
- const all: FileLines[] = [];
- for (const dir of E2E_DIRS) {
- let entries: string[];
+const unreadableScanDirs: string[] = [];
+
+function listE2eTsFiles(): FileLines[] {
+ const out: FileLines[] = [];
+ function walk(dir: string) {
+ let entries: Dirent[];
try {
- entries = readdirSync(dir);
- } catch {
- continue;
- }
- for (const name of entries) {
- if (!name.endsWith('.e2e.ts')) continue;
- const absPath = join(dir, name);
- const source = readFileSync(absPath, 'utf-8');
- all.push({
- path: relative(REPO_ROOT, absPath),
- absPath,
- lines: source.split('\n'),
- });
+ entries = readdirSync(dir, { withFileTypes: true });
+ } catch (cause) {
+ const reason = cause instanceof Error ? cause.message : String(cause);
+ unreadableScanDirs.push(`${relative(REPO_ROOT, dir)} (${reason})`);
+ return;
+ }
+ for (const entry of entries) {
+ const abs = join(dir, entry.name);
+ if (entry.isDirectory()) {
+ walk(abs);
+ continue;
+ }
+ if (!entry.isFile()) continue;
+ if (!entry.name.endsWith('.ts')) continue;
+ const source = readFileSync(abs, 'utf-8');
+ out.push({ path: relative(REPO_ROOT, abs), absPath: abs, lines: source.split('\n') });
}
}
- return all;
+ for (const dir of E2E_DIRS) walk(dir);
+ return out;
}
function listAppSrcTsFiles(): FileLines[] {
@@ -117,6 +135,10 @@ function findSpawnIsolationViolations(
return violations;
}
+function isRemoteImageHost(line: string): boolean {
+ return /\b(picsum\.photos|images\.unsplash\.com|via\.placeholder\.com)\b/i.test(line);
+}
+
function isStaticDevHarnessImport(line: string): boolean {
return /^\s*(?:import|export)\s+(?!type\b)[^;]*from\s+['"][^'"]*dev-thread-harness['"]/.test(
line,
@@ -139,10 +161,28 @@ function collectMatches(
}
describe('E2E STOP rule — zero allowlist', () => {
- const e2eFiles = listE2eFiles();
+ const e2eTsFiles = listE2eTsFiles();
+ const e2eFiles = e2eTsFiles.filter((file) => file.path.endsWith('.e2e.ts'));
test('there are E2E files to check (sanity)', () => {
+ expect(
+ unreadableScanDirs,
+ 'a scan directory could not be read at any depth — the bans below would silently skip its files',
+ ).toEqual([]);
+ expect(e2eTsFiles.length).toBeGreaterThan(0);
expect(e2eFiles.length).toBeGreaterThan(0);
+ for (const dir of E2E_DIRS) {
+ const tsFromDir = e2eTsFiles.filter((file) => file.absPath.startsWith(`${dir}/`));
+ expect(
+ tsFromDir.length,
+ `no *.ts under ${relative(REPO_ROOT, dir)} — renamed, moved, or emptied?`,
+ ).toBeGreaterThan(0);
+ const fromDir = e2eFiles.filter((file) => file.absPath.startsWith(`${dir}/`));
+ expect(
+ fromDir.length,
+ `no *.e2e.ts under ${relative(REPO_ROOT, dir)} — renamed, moved, or emptied?`,
+ ).toBeGreaterThan(0);
+ }
});
test('no page.waitForTimeout( in tests/{stress,visual,a11y}/*.e2e.ts (AC-3)', () => {
@@ -500,6 +540,31 @@ describe('E2E STOP rule — zero allowlist', () => {
}
});
+ test('no remote placeholder-image hosts in tests/{stress,visual,a11y} (PRD-8532)', () => {
+ const violations = collectMatches(e2eTsFiles, isRemoteImageHost);
+ if (violations.length > 0) {
+ throw new Error(
+ `Remote placeholder-image host found — write a local fixture under tests/stress/_fixtures and wait with waitForImageDecoded (from the ./_helpers barrel) instead:\n${violations.join('\n')}`,
+ );
+ }
+ });
+
+ test('remote-image-host rule fires on planted hosts and not on adjacent negatives', () => {
+ expect(isRemoteImageHost('<img src="https://picsum.photos/200" alt="remote" />')).toBe(true);
+ expect(isRemoteImageHost('![alt](https://via.placeholder.com/50)')).toBe(true);
+ expect(isRemoteImageHost('src="https://IMAGES.UNSPLASH.COM/photo-1" />')).toBe(true);
+ expect(isRemoteImageHost("const REMOTE_IMAGE_HOSTS = ['picsum.photos'];")).toBe(true);
+ expect(isRemoteImageHost("await page.route('**://picsum.photos/**', handler);")).toBe(true);
+ expect(isRemoteImageHost("await srcInput.fill('https://picsum.photos/200');")).toBe(true);
+
+ expect(isRemoteImageHost('<img src="https://example.com/safe.png" alt="safe" />')).toBe(false);
+ expect(isRemoteImageHost('![remote](https://invalid.invalid/missing.png)')).toBe(false);
+ expect(isRemoteImageHost('<img src="/real-shot.png" alt="local" />')).toBe(false);
+ expect(isRemoteImageHost("const url = 'https://unsplash.com/photos/abc';")).toBe(false);
+ expect(isRemoteImageHost("const s = 'notpicsum.photosly';")).toBe(false);
+ expect(isRemoteImageHost("const s = 'picsumXphotos';")).toBe(false);
+ });
+
test('predev routes i18n compile through the OK_TEST_SKIP_I18N_COMPILE guard (not a direct compile)', () => {
const pkgPath = join(__dirname, '..', '..', 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as {
diff --git a/packages/app/tests/stress/_helpers/image.ts b/packages/app/tests/stress/_helpers/image.ts
new file mode 100644
index 000000000..5341072f4
--- /dev/null
+++ b/packages/app/tests/stress/_helpers/image.ts
@@ -0,0 +1,14 @@
+import { expect, type Locator } from '@playwright/test';
+
+export async function waitForImageDecoded(image: Locator): Promise<void> {
+ await expect
+ .poll(() =>
+ image
+ .evaluate(
+ (element) =>
+ element instanceof HTMLImageElement && element.complete && element.naturalWidth > 0,
+ )
+ .catch(() => false),
+ )
+ .toBe(true);
+}
diff --git a/packages/app/tests/stress/_helpers/index.ts b/packages/app/tests/stress/_helpers/index.ts
index 6c562c2b3..3a191cbba 100644
--- a/packages/app/tests/stress/_helpers/index.ts
+++ b/packages/app/tests/stress/_helpers/index.ts
@@ -17,6 +17,7 @@ export {
type WorkerServer,
} from './fixtures.ts';
export { waitForGraphSimulationSettled } from './graph.ts';
+export { waitForImageDecoded } from './image.ts';
export {
assertLanded,
injectForcedEstimateError,
@@ -34,7 +35,6 @@ export {
waitForActiveProviderSynced,
} from './provider.ts';
export { escapeRegExp } from './regexp.ts';
-export { stubRemoteImages } from './remote-image-stub.ts';
export { matchIsWithinReadableScrollport } from './scrollport.ts';
export {
checkCollabSync,
diff --git a/packages/app/tests/stress/_helpers/remote-image-stub.ts b/packages/app/tests/stress/_helpers/remote-image-stub.ts
deleted file mode 100644
index 819035e52..000000000
--- a/packages/app/tests/stress/_helpers/remote-image-stub.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import type { Page } from '@playwright/test';
-
-const STUB_PNG_BASE64 =
- 'iVBORw0KGgoAAAANSUhEUgAAASwAAADICAIAAADdvUsCAAABsUlEQVR42u3TQQ0AAAjEsBOLBFxgGhk8aFIFS5bqAQ5FAjAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQMCGYEDAhmBAwIZgQTKgCmBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAiYEEwImBBMCJgQTAgmVAFMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBEwIJgRMCCYETAgmBBMCJgQTAiaEnxboihYsGmarVAAAAABJRU5ErkJggg==';
-
-const REMOTE_IMAGE_HOSTS = ['picsum.photos'];
-
-export async function stubRemoteImages(page: Page): Promise<void> {
- const body = Buffer.from(STUB_PNG_BASE64, 'base64');
- for (const host of REMOTE_IMAGE_HOSTS) {
- await page.route(`**://${host}/**`, (route) =>
- route.fulfill({
- status: 200,
- contentType: 'image/png',
- headers: { 'cache-control': 'no-store' },
- body,
- }),
- );
- }
-}
diff --git a/packages/app/tests/stress/grip-click-nodeselect.e2e.ts b/packages/app/tests/stress/grip-click-nodeselect.e2e.ts
index 021ae590f..1edf04d08 100644
--- a/packages/app/tests/stress/grip-click-nodeselect.e2e.ts
+++ b/packages/app/tests/stress/grip-click-nodeselect.e2e.ts
@@ -1,14 +1,25 @@
import { randomUUID } from 'node:crypto';
+import { readFileSync, writeFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import type { Page } from '@playwright/test';
-import { expect, stubRemoteImages, test } from './_helpers';
+import { expect, test, waitForImageDecoded } from './_helpers';
+
+const FIXTURES_DIR = join(dirname(fileURLToPath(import.meta.url)), '_fixtures');
interface ApiSeed {
seedDocs: (docs: Array<{ name: string; markdown: string }>) => Promise<void>;
}
-async function setupDoc(page: Page, api: ApiSeed, markdown: string): Promise<string> {
+async function setupDoc(
+ page: Page,
+ api: ApiSeed,
+ markdown: string,
+ writeAsset?: () => void,
+): Promise<string> {
const docName = `grip-${randomUUID().slice(0, 8)}`;
await api.seedDocs([{ name: docName, markdown }]);
+ writeAsset?.();
await page.goto(`/#/${docName}`);
await page.waitForSelector('.ProseMirror:not(.composer-prosemirror)');
await page.waitForFunction(() => Boolean(window.__activeEditor), null, { timeout: 5_000 });
@@ -24,7 +35,14 @@ async function hoverBlockAndGetGripBox(
const box = await target.boundingBox();
if (!box) throw new Error(`no boundingBox for ${selector}`);
- await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
+ const hoverY = box.y + box.height / 2;
+ const viewport = page.viewportSize();
+ if (viewport && hoverY >= viewport.height) {
+ throw new Error(
+ `hover point for ${selector} is off-screen (y=${hoverY}, viewport height ${viewport.height}) — the block renders taller than the window, so mouse.move never reaches it`,
+ );
+ }
+ await page.mouse.move(box.x + box.width / 2, hoverY);
const grip = page.locator('.ok-drag-grip');
await expect(grip).toBeVisible({ timeout: 5_000 });
@@ -152,9 +170,26 @@ test('AC22: grip click NodeSelects an Accordion (composite)', async ({ page, api
await expect(wrapper).toHaveAttribute('data-selected', 'true');
});
-test('AC22: grip click NodeSelects an img (self-closing leaf)', async ({ page, api }) => {
- await stubRemoteImages(page);
- await setupDoc(page, api, '<img src="https://picsum.photos/200" alt="test image" />\n\nafter\n');
+test('AC22: grip click NodeSelects an img (self-closing leaf)', async ({
+ page,
+ api,
+ workerServer,
+}) => {
+ const name = `grip-image-${randomUUID().slice(0, 8)}.png`;
+ await setupDoc(
+ page,
+ api,
+ `<img src="/${name}" alt="test image" width="200" height="200" />\n\nafter\n`,
+ () => {
+ writeFileSync(
+ join(workerServer.contentDir, name),
+ readFileSync(join(FIXTURES_DIR, 'real-shot.png')),
+ );
+ },
+ );
+ const image = page.getByRole('img', { name: 'test image', exact: true });
+ await expect(image).toBeVisible();
+ await waitForImageDecoded(image);
await resetSelectionToDocStart(page);
const gripBox = await hoverBlockAndGetGripBox(
diff --git a/packages/app/tests/stress/jsx-image-body-click.e2e.ts b/packages/app/tests/stress/jsx-image-body-click.e2e.ts
index 7cf8e2195..20130d09a 100644
--- a/packages/app/tests/stress/jsx-image-body-click.e2e.ts
+++ b/packages/app/tests/stress/jsx-image-body-click.e2e.ts
@@ -1,14 +1,25 @@
import { randomUUID } from 'node:crypto';
+import { readFileSync, writeFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import type { Page } from '@playwright/test';
-import { expect, stubRemoteImages, test } from './_helpers';
+import { expect, test, waitForImageDecoded } from './_helpers';
+
+const FIXTURES_DIR = join(dirname(fileURLToPath(import.meta.url)), '_fixtures');
interface ApiSeed {
seedDocs: (docs: Array<{ name: string; markdown: string }>) => Promise<void>;
}
-async function setupDoc(page: Page, api: ApiSeed, markdown: string): Promise<string> {
+async function setupDoc(
+ page: Page,
+ api: ApiSeed,
+ markdown: string,
+ writeAsset: () => void,
+): Promise<string> {
const docName = `imgclick-${randomUUID().slice(0, 8)}`;
await api.seedDocs([{ name: docName, markdown }]);
+ writeAsset();
await page.goto(`/#/${docName}`);
await page.waitForSelector('.ProseMirror:not(.composer-prosemirror)');
await page.waitForFunction(() => Boolean(window.__activeEditor), null, { timeout: 5_000 });
@@ -18,13 +29,15 @@ async function setupDoc(page: Page, api: ApiSeed, markdown: string): Promise<str
test('AC21/F4: img body-click does NOT NodeSelect (Zoom interception pin)', async ({
page,
api,
+ workerServer,
}) => {
- await stubRemoteImages(page);
- await setupDoc(
- page,
- api,
- '<img src="https://picsum.photos/id/237/300/200" alt="real loaded asset" />\n\nafter\n',
- );
+ const name = `img-click-${randomUUID().slice(0, 8)}.png`;
+ await setupDoc(page, api, `<img src="/${name}" alt="real loaded asset" />\n\nafter\n`, () => {
+ writeFileSync(
+ join(workerServer.contentDir, name),
+ readFileSync(join(FIXTURES_DIR, 'real-shot.png')),
+ );
+ });
await page.evaluate(() => {
const editor = window.__activeEditor;
@@ -33,10 +46,11 @@ test('AC21/F4: img body-click does NOT NodeSelect (Zoom interception pin)', asyn
});
const wrapper = page.locator('.jsx-component-wrapper[data-component-type="img"]').first();
- await wrapper.waitFor({ state: 'visible', timeout: 5_000 });
+ await expect(wrapper).toBeVisible();
const img = wrapper.locator('img').first();
- await img.waitFor({ state: 'visible', timeout: 5_000 });
+ await expect(img).toBeVisible();
+ await waitForImageDecoded(img);
await img.click();
const selType = await page.evaluate(() => {
diff --git a/packages/app/tsconfig.json b/packages/app/tsconfig.json
index 98ee597e2..1168fd854 100644
--- a/packages/app/tsconfig.json
+++ b/packages/app/tsconfig.json
@@ -27,11 +27,22 @@
// imports and `exclude` only filters the `*.test.ts`/`*.test.tsx` entry
// points. That is the deliberate cost of typechecking the helper, not an
// oversight. Naming further files here is a separate change.
+ //
+ // `tests/stress/_helpers/image.ts` is named for the same reason: its
+ // `instanceof HTMLImageElement` narrowing is what gives the polled element
+ // `.complete`/`.naturalWidth`, since Playwright types `evaluate`'s argument
+ // as `SVGElement | HTMLElement`. Nothing else typechecks the E2E helpers, so
+ // without this, deleting that narrowing compiles silently; with it, deleting
+ // it fails as TS2339 on both properties. That is the whole guarantee: a cast
+ // to `HTMLImageElement` still compiles (a downcast within the union is
+ // permitted), and the `.complete` conjunct is not pinned. It imports only
+ // `@playwright/test`, so its closure adds no other file to the program.
"include": [
"src",
"*.ts",
"tests/stress/fixtures",
- "tests/half-open-forced-close.test-helper.ts"
+ "tests/half-open-forced-close.test-helper.ts",
+ "tests/stress/_helpers/image.ts"
],
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.test.tsx"]
}