@1agh/maude 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/studio/bin/_html-playwright.mjs +198 -19
- package/apps/studio/bin/_pdf-playwright.mjs +1 -0
- package/apps/studio/bin/_png-playwright.mjs +23 -6
- package/apps/studio/bin/_pptx-playwright.mjs +4 -1
- package/apps/studio/bin/_pw-launch.mjs +48 -0
- package/apps/studio/bin/_svg-playwright.mjs +45 -12
- package/apps/studio/bin/_video-playwright.mjs +123 -11
- package/apps/studio/canvas-edit.ts +33 -0
- package/apps/studio/canvas-lib.tsx +7 -0
- package/apps/studio/client/app.jsx +84 -23
- package/apps/studio/client/export-lane.js +37 -2
- package/apps/studio/dist/client.bundle.js +601 -601
- package/apps/studio/export-dialog.tsx +24 -19
- package/apps/studio/exporters/_runtime.ts +31 -1
- package/apps/studio/exporters/capture-chrome.ts +111 -0
- package/apps/studio/exporters/capture-core.ts +659 -3
- package/apps/studio/exporters/format-scopes.ts +88 -0
- package/apps/studio/exporters/html.ts +3 -2
- package/apps/studio/exporters/jobs.ts +180 -18
- package/apps/studio/exporters/pdf.ts +21 -1
- package/apps/studio/exporters/remote.ts +73 -4
- package/apps/studio/exporters/scope.ts +14 -3
- package/apps/studio/exporters/video.ts +75 -8
- package/apps/studio/http.ts +74 -7
- package/apps/studio/test/canvas-hide-chrome.test.ts +30 -0
- package/apps/studio/test/export-capture-hygiene.test.ts +675 -0
- package/apps/studio/test/export-e2e-lanes.test.ts +857 -0
- package/apps/studio/test/export-format-scope-coherence.test.ts +89 -0
- package/apps/studio/test/exporters/jobs.test.ts +73 -0
- package/apps/studio/test/exporters/scope.test.ts +33 -0
- package/apps/studio/test/fixtures/tiny-subset.woff2 +0 -0
- package/apps/studio/test/pdf-print-boxes.test.ts +33 -0
- package/apps/studio/whats-new.json +9 -0
- package/package.json +8 -8
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
// export-capture-hygiene.test.ts — DDR-231 Phase 2 T2/T3.
|
|
2
|
+
//
|
|
3
|
+
// The Phase-1 fidelity gate (export-capture-fidelity.test.ts) compares the
|
|
4
|
+
// browser lane against the playwright reference IN THE SAME ENGINE on a
|
|
5
|
+
// fixture that has neither editor chrome nor a network-loaded asset. Both
|
|
6
|
+
// defects the first live cloud export hit therefore passed it clean:
|
|
7
|
+
//
|
|
8
|
+
// 1. CHROME LEAK — the browser lane captures the LIVE canvas DOM, where the
|
|
9
|
+
// artboard's own `.dc-artboard-label` header (an editor affordance, a
|
|
10
|
+
// child of `[data-dc-screen]`) is visible. The desktop lane never sees it
|
|
11
|
+
// because its shell is loaded with `?hide-chrome=1`, which flips
|
|
12
|
+
// `_shell.html`'s `#canvas-hide-chrome` block to `media="all"`. Evidence:
|
|
13
|
+
// the exported `post-lokace.svg` carried
|
|
14
|
+
// `<g class="dc-artboard-label" aria-label="Artboard Lokace týdne …">`.
|
|
15
|
+
// 2. ASSETS NOT EMBEDDED — every `<image>` kept a remote `http(s)` href and
|
|
16
|
+
// the artifact had zero `data:` URIs, so the SVG renders with broken
|
|
17
|
+
// images outside the serving origin, and the PNG rasterization (an
|
|
18
|
+
// SVG-as-image loads NO external resources) drops them entirely.
|
|
19
|
+
// 3. NO LOAD WAIT — the capture serializes immediately, so an artboard whose
|
|
20
|
+
// images are still decoding captures without them.
|
|
21
|
+
//
|
|
22
|
+
// This file pins all three against a real Chromium with a real HTTP origin,
|
|
23
|
+
// which is what makes #2 reproducible at all (a `file:`/`setContent` fixture
|
|
24
|
+
// has no network asset to fail on).
|
|
25
|
+
|
|
26
|
+
import { describe, expect, test } from 'bun:test';
|
|
27
|
+
import { readFileSync } from 'node:fs';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
|
|
30
|
+
import { getBrowserBundle, getCaptureCoreBundle } from '../exporters/_browser-bundles.ts';
|
|
31
|
+
|
|
32
|
+
/** A real (tiny, latin-subset, OFL) woff2 — the test is about the `@font-face`
|
|
33
|
+
* `src` becoming a `data:` URI, not about glyph coverage. */
|
|
34
|
+
const WOFF2 = readFileSync(join(import.meta.dir, 'fixtures', 'tiny-subset.woff2'));
|
|
35
|
+
|
|
36
|
+
/** 1×1 red PNG — small enough to inline in the fixture host verbatim. */
|
|
37
|
+
const PNG_1PX = Buffer.from(
|
|
38
|
+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
|
39
|
+
'base64'
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const SVG_ASSET = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><circle cx="5" cy="5" r="4" fill="#0a0"/></svg>`;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A canvas-shaped fixture: the world plane, one artboard, the artboard's own
|
|
46
|
+
* `.dc-artboard-label` header (exactly where canvas-lib puts it — a child of
|
|
47
|
+
* the `[data-dc-screen]` article), a shell-level overlay, and two network
|
|
48
|
+
* assets (a raster `<img>` and an SVG `<img>`).
|
|
49
|
+
*/
|
|
50
|
+
function fixtureHtml(origin: string): string {
|
|
51
|
+
return `<!doctype html><html><head><meta charset="utf-8"></head>
|
|
52
|
+
<body style="margin:0;background:#222">
|
|
53
|
+
<div class="dc-world">
|
|
54
|
+
<article class="dc-artboard" data-dc-screen="board-1"
|
|
55
|
+
style="position:absolute;left:0;top:0;width:360px;height:240px;background:#12203a;
|
|
56
|
+
font-family:Arial,Helvetica,sans-serif;color:#f5f2ea">
|
|
57
|
+
<header class="dc-artboard-label sku">Artboard Lokace týdne · IG Post · 1:1</header>
|
|
58
|
+
<div class="dc-artboard-body" style="padding:16px">
|
|
59
|
+
<div style="font-size:18px;font-weight:700">Summer Camp</div>
|
|
60
|
+
<img id="photo" src="${origin}/photo.png" width="120" height="80" alt="photo" />
|
|
61
|
+
<img id="logo" src="${origin}/logo.svg" width="40" height="40" alt="logo" />
|
|
62
|
+
</div>
|
|
63
|
+
</article>
|
|
64
|
+
<div class="dc-mm" style="position:absolute;left:10px;top:10px;width:60px;height:40px;background:#f0f">minimap</div>
|
|
65
|
+
<div class="dc-participants" style="position:absolute;right:4px;top:4px">MD</div>
|
|
66
|
+
</div>
|
|
67
|
+
</body></html>`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Serve the fixture + its assets from a real origin so `<img>` is a real fetch. */
|
|
71
|
+
function startFixtureHost(): { origin: string; stop: () => void } {
|
|
72
|
+
const server = Bun.serve({
|
|
73
|
+
port: 0,
|
|
74
|
+
fetch(req) {
|
|
75
|
+
const { pathname } = new URL(req.url);
|
|
76
|
+
if (pathname === '/photo.png') {
|
|
77
|
+
return new Response(PNG_1PX, { headers: { 'content-type': 'image/png' } });
|
|
78
|
+
}
|
|
79
|
+
if (pathname === '/logo.svg') {
|
|
80
|
+
return new Response(SVG_ASSET, { headers: { 'content-type': 'image/svg+xml' } });
|
|
81
|
+
}
|
|
82
|
+
const origin = `http://127.0.0.1:${server.port}`;
|
|
83
|
+
return new Response(fixtureHtml(origin), { headers: { 'content-type': 'text/html' } });
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return { origin: `http://127.0.0.1:${server.port}`, stop: () => server.stop(true) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
describe('browser-lane capture hygiene (chrome + assets)', () => {
|
|
90
|
+
test(
|
|
91
|
+
'a captured artboard carries no editor chrome and no remote resource refs',
|
|
92
|
+
async () => {
|
|
93
|
+
const [iife, core] = await Promise.all([
|
|
94
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
95
|
+
getCaptureCoreBundle(),
|
|
96
|
+
]);
|
|
97
|
+
const host = startFixtureHost();
|
|
98
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
99
|
+
launchChromium: () => Promise<{
|
|
100
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
101
|
+
close: () => Promise<void>;
|
|
102
|
+
}>;
|
|
103
|
+
};
|
|
104
|
+
const browser = await launchChromium();
|
|
105
|
+
try {
|
|
106
|
+
const ctx = await browser.newContext({
|
|
107
|
+
viewport: { width: 800, height: 600 },
|
|
108
|
+
deviceScaleFactor: 1,
|
|
109
|
+
});
|
|
110
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
111
|
+
const page: any = await ctx.newPage();
|
|
112
|
+
const consoleErrors: string[] = [];
|
|
113
|
+
page.on('console', (m: { type: () => string; text: () => string }) => {
|
|
114
|
+
if (m.type() === 'error') consoleErrors.push(m.text());
|
|
115
|
+
});
|
|
116
|
+
await page.goto(host.origin, { waitUntil: 'domcontentloaded' });
|
|
117
|
+
await page.addScriptTag({ path: iife });
|
|
118
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
119
|
+
await page.waitForFunction(
|
|
120
|
+
() => !!(window as never as Record<string, unknown>)['__maudeCaptureCore']
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const { svg, chromeDrawables } = await page.evaluate(async () => {
|
|
124
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
125
|
+
const w = window as any;
|
|
126
|
+
const core = w.__maudeCaptureCore;
|
|
127
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
128
|
+
const out: string = await core.svgForElement(target, w.domToSvg);
|
|
129
|
+
// dom-to-svg still emits an (empty) <g> for a display:none element,
|
|
130
|
+
// carrying its class — inert, and the playwright reference lane
|
|
131
|
+
// produces the same. What must be absent is anything that PAINTS, so
|
|
132
|
+
// assert on drawable descendants rather than on the class string.
|
|
133
|
+
const doc = new DOMParser().parseFromString(out, 'image/svg+xml');
|
|
134
|
+
const drawable = 'text,image,rect,path,circle,ellipse,line,polygon,polyline,use';
|
|
135
|
+
let painted = 0;
|
|
136
|
+
for (const sel of core.CAPTURE_HIDDEN_SELECTORS as string[]) {
|
|
137
|
+
// Class/attribute selectors survive serialization; ids are rewritten.
|
|
138
|
+
if (sel.startsWith('#')) continue;
|
|
139
|
+
for (const node of doc.querySelectorAll(sel)) {
|
|
140
|
+
painted += node.querySelectorAll(drawable).length;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { svg: out, chromeDrawables: painted };
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// (1) chrome — the artboard's own label header, and any overlay from
|
|
147
|
+
// `_shell.html`'s `#canvas-hide-chrome` list, must contribute nothing
|
|
148
|
+
// that renders. The label's text is the exact leak the live cloud
|
|
149
|
+
// export shipped.
|
|
150
|
+
expect(chromeDrawables).toBe(0);
|
|
151
|
+
// …and the nodes are gone outright, so the label text does not even
|
|
152
|
+
// survive as `aria-label` metadata in the delivered file.
|
|
153
|
+
expect(svg).not.toContain('dc-artboard-label');
|
|
154
|
+
expect(svg).not.toContain('Lokace týdne');
|
|
155
|
+
expect(svg).not.toContain('minimap');
|
|
156
|
+
|
|
157
|
+
// (2) assets — every resource ref must be embedded. A remote
|
|
158
|
+
// `http(s)://` href in the output is the live defect: an SVG-as-image
|
|
159
|
+
// loads no external resources, so the raster silently drops it.
|
|
160
|
+
const remoteRefs = svg.match(/(?:xlink:)?href="https?:\/\/[^"]+"/g) ?? [];
|
|
161
|
+
expect(remoteRefs).toEqual([]);
|
|
162
|
+
expect(svg).toContain('data:image/png');
|
|
163
|
+
|
|
164
|
+
// The capture must not have papered over a failure by logging it.
|
|
165
|
+
expect(consoleErrors.filter((t) => /inlin|resource/i.test(t))).toEqual([]);
|
|
166
|
+
} finally {
|
|
167
|
+
await browser.close();
|
|
168
|
+
host.stop();
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{ timeout: 60_000 }
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
test(
|
|
175
|
+
'the capture waits for images that have not decoded yet',
|
|
176
|
+
async () => {
|
|
177
|
+
const [iife, core] = await Promise.all([
|
|
178
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
179
|
+
getCaptureCoreBundle(),
|
|
180
|
+
]);
|
|
181
|
+
// A host that stalls the photo response — the capture must still come
|
|
182
|
+
// back with the image embedded, not race past it.
|
|
183
|
+
const server = Bun.serve({
|
|
184
|
+
port: 0,
|
|
185
|
+
async fetch(req) {
|
|
186
|
+
const { pathname } = new URL(req.url);
|
|
187
|
+
if (pathname === '/photo.png') {
|
|
188
|
+
await Bun.sleep(600);
|
|
189
|
+
return new Response(PNG_1PX, { headers: { 'content-type': 'image/png' } });
|
|
190
|
+
}
|
|
191
|
+
if (pathname === '/logo.svg') {
|
|
192
|
+
return new Response(SVG_ASSET, { headers: { 'content-type': 'image/svg+xml' } });
|
|
193
|
+
}
|
|
194
|
+
return new Response(fixtureHtml(`http://127.0.0.1:${server.port}`), {
|
|
195
|
+
headers: { 'content-type': 'text/html' },
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
200
|
+
launchChromium: () => Promise<{
|
|
201
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
202
|
+
close: () => Promise<void>;
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
const browser = await launchChromium();
|
|
206
|
+
try {
|
|
207
|
+
const ctx = await browser.newContext({ viewport: { width: 800, height: 600 } });
|
|
208
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
209
|
+
const page: any = await ctx.newPage();
|
|
210
|
+
// `domcontentloaded`, deliberately: the slow <img> is still in flight,
|
|
211
|
+
// which is exactly the live-canvas state the browser lane captures in.
|
|
212
|
+
await page.goto(`http://127.0.0.1:${server.port}`, { waitUntil: 'domcontentloaded' });
|
|
213
|
+
await page.addScriptTag({ path: iife });
|
|
214
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
215
|
+
await page.waitForFunction(
|
|
216
|
+
() => !!(window as never as Record<string, unknown>)['__maudeCaptureCore']
|
|
217
|
+
);
|
|
218
|
+
const svg: string = await page.evaluate(async () => {
|
|
219
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
220
|
+
const w = window as any;
|
|
221
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
222
|
+
return await w.__maudeCaptureCore.svgForElement(target, w.domToSvg);
|
|
223
|
+
});
|
|
224
|
+
expect(svg).toContain('data:image/png');
|
|
225
|
+
} finally {
|
|
226
|
+
await browser.close();
|
|
227
|
+
server.stop(true);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
{ timeout: 60_000 }
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('browser-lane capture hygiene (webfonts)', () => {
|
|
235
|
+
test(
|
|
236
|
+
'@font-face sources are embedded — from a <link> stylesheet AND an inline <style>',
|
|
237
|
+
async () => {
|
|
238
|
+
// Fonts are the classic silent fidelity killer (DDR-231 SHIPPER's top
|
|
239
|
+
// risk): an SVG whose @font-face still points at the serving origin
|
|
240
|
+
// renders in a fallback face everywhere but the live page, and nothing
|
|
241
|
+
// errors. Two declaration shapes, because dom-to-svg only copies the
|
|
242
|
+
// first on its own (it needs a stylesheet href to absolutize `src`) —
|
|
243
|
+
// the second is what capture-core's appendInlineFontFaces carries over.
|
|
244
|
+
const [iife, core] = await Promise.all([
|
|
245
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
246
|
+
getCaptureCoreBundle(),
|
|
247
|
+
]);
|
|
248
|
+
const server = Bun.serve({
|
|
249
|
+
port: 0,
|
|
250
|
+
fetch(req) {
|
|
251
|
+
const { pathname } = new URL(req.url);
|
|
252
|
+
if (pathname === '/f.woff2')
|
|
253
|
+
return new Response(WOFF2, { headers: { 'content-type': 'font/woff2' } });
|
|
254
|
+
if (pathname === '/linked.css')
|
|
255
|
+
return new Response(
|
|
256
|
+
'@font-face{font-family:"LinkedFace";src:url(/f.woff2) format("woff2")}',
|
|
257
|
+
{ headers: { 'content-type': 'text/css' } }
|
|
258
|
+
);
|
|
259
|
+
return new Response(
|
|
260
|
+
`<!doctype html><html><head><link rel="stylesheet" href="/linked.css">
|
|
261
|
+
<style>@font-face{font-family:"InlineFace";src:url("/f.woff2") format("woff2")}</style>
|
|
262
|
+
</head><body style="margin:0"><div class="dc-world">
|
|
263
|
+
<article data-dc-screen="b1" style="position:absolute;left:0;top:0;width:320px;height:120px;background:#123;color:#fff">
|
|
264
|
+
<p style="font-family:LinkedFace,serif">Linked</p>
|
|
265
|
+
<p style="font-family:InlineFace,serif">Inline</p>
|
|
266
|
+
</article></div></body></html>`,
|
|
267
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
272
|
+
launchChromium: () => Promise<{
|
|
273
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
274
|
+
close: () => Promise<void>;
|
|
275
|
+
}>;
|
|
276
|
+
};
|
|
277
|
+
const browser = await launchChromium();
|
|
278
|
+
try {
|
|
279
|
+
const ctx = await browser.newContext({});
|
|
280
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
281
|
+
const page: any = await ctx.newPage();
|
|
282
|
+
await page.goto(`http://127.0.0.1:${server.port}`, { waitUntil: 'load' });
|
|
283
|
+
await page.addScriptTag({ path: iife });
|
|
284
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
285
|
+
await page.waitForFunction(
|
|
286
|
+
() => !!(window as never as Record<string, unknown>).__maudeCaptureCore
|
|
287
|
+
);
|
|
288
|
+
const svg: string = await page.evaluate(async () => {
|
|
289
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
290
|
+
const w = window as any;
|
|
291
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
292
|
+
return await w.__maudeCaptureCore.svgForElement(target, w.domToSvg);
|
|
293
|
+
});
|
|
294
|
+
const faces = svg.match(/@font-face[^}]*}/g) ?? [];
|
|
295
|
+
const families = faces.map((f) => /font-family:\s*"?([^;"]+)"?/.exec(f)?.[1]?.trim());
|
|
296
|
+
expect(families.sort()).toEqual(['InlineFace', 'LinkedFace']);
|
|
297
|
+
for (const face of faces) expect(face).toContain('data:font/woff2;base64,');
|
|
298
|
+
// No font source may still point at the serving origin.
|
|
299
|
+
expect(svg.match(/url\(["']?https?:[^)]*\)/g) ?? []).toEqual([]);
|
|
300
|
+
} finally {
|
|
301
|
+
await browser.close();
|
|
302
|
+
server.stop(true);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{ timeout: 60_000 }
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('browser-lane capture hygiene (CSS filter on images)', () => {
|
|
310
|
+
test(
|
|
311
|
+
'an <img> with a CSS filter is embedded with the filter BAKED IN',
|
|
312
|
+
async () => {
|
|
313
|
+
// The alligators "Duo" treatment: `filter: url(#poster5) contrast(…)`
|
|
314
|
+
// against an SVG filter mounted elsewhere in the page. dom-to-svg puts no
|
|
315
|
+
// `filter` on its <image>, so the original bytes rendered flat — the cloud
|
|
316
|
+
// PNG/SVG/PPTX lost the photo treatment the desktop screenshot kept.
|
|
317
|
+
const [iife, core] = await Promise.all([
|
|
318
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
319
|
+
getCaptureCoreBundle(),
|
|
320
|
+
]);
|
|
321
|
+
const server = Bun.serve({
|
|
322
|
+
port: 0,
|
|
323
|
+
fetch(req) {
|
|
324
|
+
const { pathname } = new URL(req.url);
|
|
325
|
+
if (pathname === '/photo.png')
|
|
326
|
+
return new Response(PNG_1PX, { headers: { 'content-type': 'image/png' } });
|
|
327
|
+
return new Response(
|
|
328
|
+
`<!doctype html><body style="margin:0">
|
|
329
|
+
<svg width="0" height="0" style="position:absolute"><filter id="poster5" color-interpolation-filters="sRGB"><feColorMatrix type="saturate" values="0"/></filter></svg>
|
|
330
|
+
<div class="dc-world"><article data-dc-screen="b1" style="position:absolute;left:0;top:0;width:200px;height:120px;background:#123">
|
|
331
|
+
<img id="p" src="/photo.png" width="120" height="60" style="filter:url(#poster5) contrast(1.22);object-fit:cover">
|
|
332
|
+
</article></div></body>`,
|
|
333
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
334
|
+
);
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
338
|
+
launchChromium: () => Promise<{
|
|
339
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
340
|
+
close: () => Promise<void>;
|
|
341
|
+
}>;
|
|
342
|
+
};
|
|
343
|
+
const browser = await launchChromium();
|
|
344
|
+
try {
|
|
345
|
+
const ctx = await browser.newContext({});
|
|
346
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
347
|
+
const page: any = await ctx.newPage();
|
|
348
|
+
await page.goto(`http://127.0.0.1:${server.port}`, { waitUntil: 'load' });
|
|
349
|
+
await page.addScriptTag({ path: iife });
|
|
350
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
351
|
+
await page.waitForFunction(
|
|
352
|
+
() => !!(window as never as Record<string, unknown>).__maudeCaptureCore
|
|
353
|
+
);
|
|
354
|
+
const verdict = await page.evaluate(async () => {
|
|
355
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
356
|
+
const w = window as any;
|
|
357
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
358
|
+
const svg: string = await w.__maudeCaptureCore.svgForElement(target, w.domToSvg);
|
|
359
|
+
const href = /<image[^>]*href="(data:[^"]+)"/.exec(svg)?.[1] ?? null;
|
|
360
|
+
const par = /<image[^>]*preserveAspectRatio="([^"]+)"/.exec(svg)?.[1] ?? null;
|
|
361
|
+
if (!href) return { href: null, pixel: null, par };
|
|
362
|
+
// Decode the embedded bitmap and read its first pixel: the source is
|
|
363
|
+
// pure red (#ff0000); saturate(0) turns it grey — equal channels.
|
|
364
|
+
const img = new Image();
|
|
365
|
+
await new Promise<void>((ok, ko) => {
|
|
366
|
+
img.onload = () => ok();
|
|
367
|
+
img.onerror = () => ko(new Error('decode'));
|
|
368
|
+
img.src = href;
|
|
369
|
+
});
|
|
370
|
+
const c = document.createElement('canvas');
|
|
371
|
+
c.width = 1;
|
|
372
|
+
c.height = 1;
|
|
373
|
+
const g = c.getContext('2d') as CanvasRenderingContext2D;
|
|
374
|
+
g.drawImage(img, 0, 0);
|
|
375
|
+
return {
|
|
376
|
+
href: href.slice(0, 22),
|
|
377
|
+
pixel: Array.from(g.getImageData(0, 0, 1, 1).data),
|
|
378
|
+
par,
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
expect(verdict.href).toBe('data:image/png;base64,');
|
|
382
|
+
// `object-fit: cover` → SVG `slice`, or the photo letterboxes (the
|
|
383
|
+
// green side bands on every exported hero).
|
|
384
|
+
expect(verdict.par).toBe('xMidYMid slice');
|
|
385
|
+
const [r, g, b] = verdict.pixel as number[];
|
|
386
|
+
// Grey = the filter was baked. Red would mean the original bytes shipped.
|
|
387
|
+
expect(Math.abs(r - g)).toBeLessThan(8);
|
|
388
|
+
expect(Math.abs(g - b)).toBeLessThan(8);
|
|
389
|
+
} finally {
|
|
390
|
+
await browser.close();
|
|
391
|
+
server.stop(true);
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{ timeout: 60_000 }
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
describe('browser-lane capture hygiene (paint dom-to-svg cannot express)', () => {
|
|
399
|
+
test(
|
|
400
|
+
'a repeating-linear-gradient clipped to a polygon survives as SVG paint',
|
|
401
|
+
async () => {
|
|
402
|
+
// The alligators "Sash": a diagonal yellow stripe band clipped to the
|
|
403
|
+
// top-right corner triangle. dom-to-svg matches `linear-gradient` only
|
|
404
|
+
// and drops `clip-path`, so the element vanished from every dom-to-svg
|
|
405
|
+
// lane while the screenshot lanes kept it. capture-core substitutes an
|
|
406
|
+
// equivalent inline <svg> (spreadMethod="repeat" + <clipPath>) for the
|
|
407
|
+
// duration of the serialization.
|
|
408
|
+
const [iife, core] = await Promise.all([
|
|
409
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
410
|
+
getCaptureCoreBundle(),
|
|
411
|
+
]);
|
|
412
|
+
const server = Bun.serve({
|
|
413
|
+
port: 0,
|
|
414
|
+
fetch() {
|
|
415
|
+
return new Response(
|
|
416
|
+
`<!doctype html><body style="margin:0"><div class="dc-world">
|
|
417
|
+
<article data-dc-screen="b1" style="position:absolute;left:0;top:0;width:240px;height:240px;background:#f1efe8">
|
|
418
|
+
<div aria-hidden="true" style="position:absolute;top:0;right:0;width:120px;height:120px;
|
|
419
|
+
background:repeating-linear-gradient(-45deg,#ffcd00 0 14px,transparent 14px 28px);
|
|
420
|
+
clip-path:polygon(100% 0,0 0,100% 100%)"></div>
|
|
421
|
+
</article></div></body>`,
|
|
422
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
423
|
+
);
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
427
|
+
launchChromium: () => Promise<{
|
|
428
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
429
|
+
close: () => Promise<void>;
|
|
430
|
+
}>;
|
|
431
|
+
};
|
|
432
|
+
const browser = await launchChromium();
|
|
433
|
+
try {
|
|
434
|
+
const ctx = await browser.newContext({});
|
|
435
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
436
|
+
const page: any = await ctx.newPage();
|
|
437
|
+
await page.goto(`http://127.0.0.1:${server.port}`, { waitUntil: 'load' });
|
|
438
|
+
await page.addScriptTag({ path: iife });
|
|
439
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
440
|
+
await page.waitForFunction(
|
|
441
|
+
() => !!(window as never as Record<string, unknown>).__maudeCaptureCore
|
|
442
|
+
);
|
|
443
|
+
const verdict = await page.evaluate(async () => {
|
|
444
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
445
|
+
const w = window as any;
|
|
446
|
+
const core = w.__maudeCaptureCore;
|
|
447
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
448
|
+
const svg: string = await core.svgForElement(target, w.domToSvg);
|
|
449
|
+
// The live element must be back to its CSS paint afterwards.
|
|
450
|
+
const sash = target.querySelector('div[aria-hidden]') as HTMLElement;
|
|
451
|
+
const restored =
|
|
452
|
+
getComputedStyle(sash).backgroundImage.startsWith('repeating-linear-gradient(') &&
|
|
453
|
+
!sash.querySelector('svg');
|
|
454
|
+
const blob: Blob = await core.rasterizeSvg(svg, 1);
|
|
455
|
+
const img = new Image();
|
|
456
|
+
const url = URL.createObjectURL(blob);
|
|
457
|
+
await new Promise<void>((ok, ko) => {
|
|
458
|
+
img.onload = () => ok();
|
|
459
|
+
img.onerror = () => ko(new Error('decode'));
|
|
460
|
+
img.src = url;
|
|
461
|
+
});
|
|
462
|
+
const c = document.createElement('canvas');
|
|
463
|
+
c.width = 240;
|
|
464
|
+
c.height = 240;
|
|
465
|
+
const g = c.getContext('2d') as CanvasRenderingContext2D;
|
|
466
|
+
g.drawImage(img, 0, 0);
|
|
467
|
+
// Sample a diagonal run across the top-right triangle: with stripes
|
|
468
|
+
// present, SOME of those pixels are yellow; none are if the band
|
|
469
|
+
// vanished. And the bottom-left corner (outside the clip) stays bg.
|
|
470
|
+
let yellow = 0;
|
|
471
|
+
for (let i = 0; i < 40; i += 1) {
|
|
472
|
+
const [r, gg, b] = g.getImageData(235 - i, 5 + i, 1, 1).data;
|
|
473
|
+
if (r > 230 && gg > 180 && gg < 225 && b < 60) yellow += 1;
|
|
474
|
+
}
|
|
475
|
+
const [br, bg, bb] = g.getImageData(20, 220, 1, 1).data;
|
|
476
|
+
return {
|
|
477
|
+
hasRepeat: svg.includes('spreadMethod="repeat"'),
|
|
478
|
+
hasClip: svg.includes('<clipPath'),
|
|
479
|
+
yellow,
|
|
480
|
+
corner: [br, bg, bb],
|
|
481
|
+
restored,
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
expect(verdict.hasRepeat).toBe(true);
|
|
485
|
+
expect(verdict.hasClip).toBe(true);
|
|
486
|
+
expect(verdict.yellow).toBeGreaterThan(5);
|
|
487
|
+
expect(verdict.corner).toEqual([241, 239, 232]);
|
|
488
|
+
expect(verdict.restored).toBe(true);
|
|
489
|
+
} finally {
|
|
490
|
+
await browser.close();
|
|
491
|
+
server.stop(true);
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
{ timeout: 60_000 }
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
describe('HTML export is inert (security review F1)', () => {
|
|
499
|
+
test(
|
|
500
|
+
'a canvas with <script>/onerror/javascript:/foreignObject exports as non-executable HTML',
|
|
501
|
+
async () => {
|
|
502
|
+
// The self-contained HTML file is opened LOCALLY by a member (file://
|
|
503
|
+
// origin). A tenant-authored canvas (untrusted, DDR-054) must not smuggle
|
|
504
|
+
// executable markup into it. Drive the real _html-playwright shim over a
|
|
505
|
+
// canvas-shaped page carrying every script sink, and assert the produced
|
|
506
|
+
// document is neutralized (no <script>, no on* handler, no javascript:,
|
|
507
|
+
// no <foreignObject>) AND carries a script-src 'none' CSP meta.
|
|
508
|
+
const server = Bun.serve({
|
|
509
|
+
port: 0,
|
|
510
|
+
fetch() {
|
|
511
|
+
return new Response(
|
|
512
|
+
`<!doctype html><html><head><title>x</title>
|
|
513
|
+
<script>window.__evil = 1</script></head>
|
|
514
|
+
<body style="margin:0"><div class="dc-world">
|
|
515
|
+
<article data-dc-screen="b1" style="position:absolute;left:0;top:0;width:200px;height:120px;background:#123">
|
|
516
|
+
<img src="x" onerror="window.__evil=2">
|
|
517
|
+
<a href="javascript:window.__evil=3">x</a>
|
|
518
|
+
<svg><foreignObject><div onclick="window.__evil=4">x</div></foreignObject></svg>
|
|
519
|
+
</article>
|
|
520
|
+
</div></body></html>`,
|
|
521
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
522
|
+
);
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
const { spawn } = await import('bun');
|
|
526
|
+
const { mkdtempSync } = await import('node:fs');
|
|
527
|
+
const { tmpdir } = await import('node:os');
|
|
528
|
+
const { join } = await import('node:path');
|
|
529
|
+
const out = join(mkdtempSync(join(tmpdir(), 'maude-html-f1-')), 'out.html');
|
|
530
|
+
const shim = join(import.meta.dir, '..', 'bin', '_html-playwright.mjs');
|
|
531
|
+
const proc = spawn({
|
|
532
|
+
cmd: [
|
|
533
|
+
'node',
|
|
534
|
+
shim,
|
|
535
|
+
'--url',
|
|
536
|
+
`http://127.0.0.1:${server.port}`,
|
|
537
|
+
'--selector',
|
|
538
|
+
'[data-dc-screen="b1"]',
|
|
539
|
+
'--out',
|
|
540
|
+
out,
|
|
541
|
+
'--timeout',
|
|
542
|
+
'15',
|
|
543
|
+
],
|
|
544
|
+
stdout: 'pipe',
|
|
545
|
+
stderr: 'pipe',
|
|
546
|
+
});
|
|
547
|
+
const code = await proc.exited;
|
|
548
|
+
server.stop(true);
|
|
549
|
+
expect(code).toBe(0);
|
|
550
|
+
const html = await Bun.file(out).text();
|
|
551
|
+
// Neutralized.
|
|
552
|
+
expect(html).not.toMatch(/<script[\s>]/i);
|
|
553
|
+
expect(html).not.toMatch(/\bon\w+\s*=/i);
|
|
554
|
+
expect(html).not.toMatch(/javascript:/i);
|
|
555
|
+
expect(html).not.toMatch(/<foreignobject/i);
|
|
556
|
+
// Belt: a CSP that forbids script even if a sink were missed.
|
|
557
|
+
expect(html).toMatch(/http-equiv="Content-Security-Policy"[^>]*script-src 'none'/i);
|
|
558
|
+
},
|
|
559
|
+
{ timeout: 60_000 }
|
|
560
|
+
);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
describe('security review — path traversal + remote-ref beacon', () => {
|
|
564
|
+
test(
|
|
565
|
+
'a `../`-laden data-dc-screen id cannot write outside the out-dir (F1, svg + html)',
|
|
566
|
+
async () => {
|
|
567
|
+
const { spawn } = await import('bun');
|
|
568
|
+
const { mkdtempSync, existsSync } = await import('node:fs');
|
|
569
|
+
const { tmpdir } = await import('node:os');
|
|
570
|
+
const { join } = await import('node:path');
|
|
571
|
+
// A canvas with two artboards whose ids are path-traversal payloads.
|
|
572
|
+
const server = Bun.serve({
|
|
573
|
+
port: 0,
|
|
574
|
+
fetch() {
|
|
575
|
+
return new Response(
|
|
576
|
+
`<!doctype html><body style="margin:0"><div class="dc-world">
|
|
577
|
+
<article data-dc-screen="../../ESCAPED-A" style="position:absolute;left:0;top:0;width:80px;height:60px;background:#123"></article>
|
|
578
|
+
<article data-dc-screen="../../ESCAPED-B" style="position:absolute;left:0;top:0;width:80px;height:60px;background:#345"></article>
|
|
579
|
+
</div></body>`,
|
|
580
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
581
|
+
);
|
|
582
|
+
},
|
|
583
|
+
});
|
|
584
|
+
const iife = await getBrowserBundle('dom-to-svg', 'domToSvg');
|
|
585
|
+
const core = await getCaptureCoreBundle();
|
|
586
|
+
try {
|
|
587
|
+
for (const [shim, ext, extraArgs] of [
|
|
588
|
+
['_svg-playwright.mjs', 'svg', ['--bundle-path', iife, '--core-path', core]],
|
|
589
|
+
['_html-playwright.mjs', 'html', []],
|
|
590
|
+
] as const) {
|
|
591
|
+
const base = mkdtempSync(join(tmpdir(), 'maude-f1-'));
|
|
592
|
+
const outDir = join(base, 'out');
|
|
593
|
+
const proc = spawn({
|
|
594
|
+
cmd: [
|
|
595
|
+
'node',
|
|
596
|
+
join(import.meta.dir, '..', 'bin', shim),
|
|
597
|
+
'--url',
|
|
598
|
+
`http://127.0.0.1:${server.port}`,
|
|
599
|
+
'--selector',
|
|
600
|
+
'[data-dc-screen]',
|
|
601
|
+
'--multi',
|
|
602
|
+
'--out-dir',
|
|
603
|
+
outDir,
|
|
604
|
+
'--timeout',
|
|
605
|
+
'15',
|
|
606
|
+
...extraArgs,
|
|
607
|
+
],
|
|
608
|
+
stdout: 'pipe',
|
|
609
|
+
stderr: 'pipe',
|
|
610
|
+
});
|
|
611
|
+
expect(await proc.exited).toBe(0);
|
|
612
|
+
// The traversal target — `<base>/ESCAPED-A.<ext>` — must NOT exist.
|
|
613
|
+
expect(existsSync(join(base, `ESCAPED-A.${ext}`))).toBe(false);
|
|
614
|
+
expect(existsSync(join(base, `ESCAPED-B.${ext}`))).toBe(false);
|
|
615
|
+
// The sanitized files land INSIDE out-dir instead.
|
|
616
|
+
expect(existsSync(join(outDir, `artboard-1.${ext}`))).toBe(true);
|
|
617
|
+
}
|
|
618
|
+
} finally {
|
|
619
|
+
server.stop(true);
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
{ timeout: 90_000 }
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
test('a remote background url the CSP blocks is dropped from the SVG, not left as a beacon (F5)', async () => {
|
|
626
|
+
const [iife, core] = await Promise.all([
|
|
627
|
+
getBrowserBundle('dom-to-svg', 'domToSvg'),
|
|
628
|
+
getCaptureCoreBundle(),
|
|
629
|
+
]);
|
|
630
|
+
// The capture page pins connect-src 'self' (cspForCapture) — but here we
|
|
631
|
+
// assert the BOUNDARY: even without a CSP, a remote ref that fails to
|
|
632
|
+
// inline must be removed. Point at a black-hole host so the fetch fails.
|
|
633
|
+
const server = Bun.serve({
|
|
634
|
+
port: 0,
|
|
635
|
+
fetch() {
|
|
636
|
+
return new Response(
|
|
637
|
+
`<!doctype html><body style="margin:0"><div class="dc-world">
|
|
638
|
+
<article data-dc-screen="b1" style="position:absolute;left:0;top:0;width:200px;height:120px;background:#123">
|
|
639
|
+
<img src="http://127.0.0.1:1/beacon.png" width="40" height="40">
|
|
640
|
+
</article></div></body>`,
|
|
641
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
642
|
+
);
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
const { launchChromium } = (await import('../bin/_pw-launch.mjs')) as {
|
|
646
|
+
launchChromium: () => Promise<{
|
|
647
|
+
newContext: (o: unknown) => Promise<{ newPage: () => Promise<unknown> }>;
|
|
648
|
+
close: () => Promise<void>;
|
|
649
|
+
}>;
|
|
650
|
+
};
|
|
651
|
+
const browser = await launchChromium();
|
|
652
|
+
try {
|
|
653
|
+
const ctx = await browser.newContext({});
|
|
654
|
+
// biome-ignore lint/suspicious/noExplicitAny: playwright page surface
|
|
655
|
+
const page: any = await ctx.newPage();
|
|
656
|
+
await page.goto(`http://127.0.0.1:${server.port}`, { waitUntil: 'load' });
|
|
657
|
+
await page.addScriptTag({ path: iife });
|
|
658
|
+
await page.addScriptTag({ path: core, type: 'module' });
|
|
659
|
+
await page.waitForFunction(
|
|
660
|
+
() => !!(window as never as Record<string, unknown>).__maudeCaptureCore
|
|
661
|
+
);
|
|
662
|
+
const svg: string = await page.evaluate(async () => {
|
|
663
|
+
// biome-ignore lint/suspicious/noExplicitAny: injected globals
|
|
664
|
+
const w = window as any;
|
|
665
|
+
const target = document.querySelector('[data-dc-screen]') as Element;
|
|
666
|
+
return await w.__maudeCaptureCore.svgForElement(target, w.domToSvg);
|
|
667
|
+
});
|
|
668
|
+
expect(svg.match(/https?:\/\/127\.0\.0\.1:1/g) ?? []).toEqual([]);
|
|
669
|
+
expect(svg).not.toContain('beacon.png');
|
|
670
|
+
} finally {
|
|
671
|
+
await browser.close();
|
|
672
|
+
server.stop(true);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
});
|