@artis-lab/cli 0.11.0 → 0.12.0
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/README.md +25 -11
- package/package.json +5 -3
- package/src/bin.js +7 -6
- package/src/index.js +17 -8
- package/src/lib/{chunk-WQDTNA6L.js → chunk-H32QAUSA.js} +1 -1
- package/src/lib/{chunk-Q4UVVKZI.js → chunk-KY47KP5E.js} +4 -4
- package/src/lib/{chunk-MX2ASLZR.js → chunk-OBEJTKCR.js} +13 -9
- package/src/lib/chunk-QDQQASRY.js +117 -0
- package/src/lib/chunk-YAZGW7Y4.js +10781 -0
- package/src/lib/{chunk-AEVC3USN.js → chunk-YXGHBN47.js} +854 -139
- package/src/lib/cli.d.ts +46 -3
- package/src/lib/cli.js +17 -8
- package/src/lib/exit-codes.js +1 -1
- package/src/lib/files.d.ts +19 -0
- package/src/lib/files.js +13 -0
- package/src/lib/revision-bases.d.ts +2 -3
- package/src/lib/revision-bases.js +1 -1
- package/src/lib/skill-install.d.ts +1 -1
- package/src/lib/skill-install.js +1 -1
- package/src/lib/verify.d.ts +83 -4
- package/src/lib/verify.js +15 -1
- package/src/lib/chunk-IKP5TJZP.js +0 -362
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
// packages/cli/src/lib/verify.ts
|
|
2
|
-
import { createServer } from "node:http";
|
|
3
|
-
var verifyWidths = [1280, 390];
|
|
4
|
-
var verifyThemes = ["light", "dark"];
|
|
5
|
-
function artifactContentSecurityPolicy(origin, sandboxTokens = []) {
|
|
6
|
-
const sandbox = ["allow-scripts", "allow-forms"];
|
|
7
|
-
for (const token of sandboxTokens) {
|
|
8
|
-
if (/^allow-[a-z-]+$/.test(token) && !sandbox.includes(token)) {
|
|
9
|
-
sandbox.push(token);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return `sandbox ${sandbox.join(" ")}; default-src 'none'; script-src 'unsafe-inline' ${origin}; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; form-action 'none'; base-uri 'none'`;
|
|
13
|
-
}
|
|
14
|
-
var VerifyUnavailableError = class extends Error {
|
|
15
|
-
};
|
|
16
|
-
async function launchBrowser() {
|
|
17
|
-
let chromium;
|
|
18
|
-
try {
|
|
19
|
-
const specifier = "playwright-core";
|
|
20
|
-
({ chromium } = await import(specifier));
|
|
21
|
-
} catch {
|
|
22
|
-
throw new VerifyUnavailableError(
|
|
23
|
-
"artis verify needs playwright-core. Install it next to the CLI: npm install -g playwright-core"
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
const executablePath = process.env["ARTIS_CHROME_PATH"];
|
|
27
|
-
const attempts = executablePath ? [{ executablePath }] : [{ channel: "chrome" }, { channel: "msedge" }, { channel: "chromium" }];
|
|
28
|
-
for (const attempt of attempts) {
|
|
29
|
-
try {
|
|
30
|
-
return await chromium.launch({ headless: true, ...attempt });
|
|
31
|
-
} catch {
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
throw new VerifyUnavailableError(
|
|
35
|
-
executablePath ? `Could not launch the browser at ARTIS_CHROME_PATH (${executablePath}).` : "artis verify uses the system Google Chrome (or Edge). Install one, or set ARTIS_CHROME_PATH to a Chromium-based browser."
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
async function serveDocument(html) {
|
|
39
|
-
const server = createServer((request, response) => {
|
|
40
|
-
const url = new URL(request.url ?? "/", "http://localhost");
|
|
41
|
-
const theme = url.searchParams.get("theme") === "dark" ? "dark" : "light";
|
|
42
|
-
if (url.pathname !== "/") {
|
|
43
|
-
response.writeHead(404).end();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const origin = `http://${request.headers.host}`;
|
|
47
|
-
response.writeHead(200, {
|
|
48
|
-
"content-type": "text/html; charset=utf-8",
|
|
49
|
-
"content-security-policy": artifactContentSecurityPolicy(origin)
|
|
50
|
-
});
|
|
51
|
-
response.end(stampTheme(html, theme));
|
|
52
|
-
});
|
|
53
|
-
await new Promise((resolve, reject) => {
|
|
54
|
-
server.once("error", reject);
|
|
55
|
-
server.listen(0, "127.0.0.1", () => {
|
|
56
|
-
server.off("error", reject);
|
|
57
|
-
resolve();
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
const { port } = server.address();
|
|
61
|
-
return {
|
|
62
|
-
server,
|
|
63
|
-
url: (theme) => `http://127.0.0.1:${port}/?theme=${theme}`
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function stampTheme(html, theme) {
|
|
67
|
-
const boot = `<script>document.documentElement.setAttribute('data-theme','${theme}');document.documentElement.style.colorScheme='${theme}';</script>`;
|
|
68
|
-
const head = /<head\b[^>]*>/i.exec(html);
|
|
69
|
-
if (!head) {
|
|
70
|
-
return html;
|
|
71
|
-
}
|
|
72
|
-
const at = head.index + head[0].length;
|
|
73
|
-
return html.slice(0, at) + boot + html.slice(at);
|
|
74
|
-
}
|
|
75
|
-
var RECORD_CSP_VIOLATIONS = `
|
|
76
|
-
window.__artisCsp = [];
|
|
77
|
-
document.addEventListener('securitypolicyviolation', (event) => {
|
|
78
|
-
window.__artisCsp.push({
|
|
79
|
-
directive: event.effectiveDirective || event.violatedDirective,
|
|
80
|
-
blocked: event.blockedURI || 'inline',
|
|
81
|
-
});
|
|
82
|
-
});`;
|
|
83
|
-
var INSPECT_PAGE = `(() => {
|
|
84
|
-
const describe = (el) => {
|
|
85
|
-
let text = el.tagName.toLowerCase();
|
|
86
|
-
if (el.id) text += '#' + el.id;
|
|
87
|
-
const cls = typeof el.className === 'string' ? el.className.trim().split(/\\s+/).filter(Boolean).slice(0, 2) : [];
|
|
88
|
-
if (cls.length) text += '.' + cls.join('.');
|
|
89
|
-
return text;
|
|
90
|
-
};
|
|
91
|
-
const root = document.documentElement;
|
|
92
|
-
const clientWidth = root.clientWidth;
|
|
93
|
-
const scrollWidth = Math.max(root.scrollWidth, document.body ? document.body.scrollWidth : 0);
|
|
94
|
-
let overflow = null;
|
|
95
|
-
if (scrollWidth > clientWidth + 1) {
|
|
96
|
-
// Elements past either edge whose own scroll container is the page:
|
|
97
|
-
// an element inside overflow-x: auto/hidden is contained, not the cause.
|
|
98
|
-
const scrolls = (el) => {
|
|
99
|
-
const ox = getComputedStyle(el).overflowX;
|
|
100
|
-
return ox === 'auto' || ox === 'scroll' || ox === 'hidden' || ox === 'clip';
|
|
101
|
-
};
|
|
102
|
-
const contained = (el) => {
|
|
103
|
-
for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
|
|
104
|
-
if (scrolls(p)) return true;
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
};
|
|
108
|
-
const rtl = getComputedStyle(root).direction === 'rtl';
|
|
109
|
-
const offenders = [];
|
|
110
|
-
for (const el of document.body ? document.body.querySelectorAll('*') : []) {
|
|
111
|
-
const rect = el.getBoundingClientRect();
|
|
112
|
-
const left = rect.left + window.scrollX;
|
|
113
|
-
const right = rect.right + window.scrollX;
|
|
114
|
-
// Past the left edge only counts in a right-to-left document: in LTR
|
|
115
|
-
// it is the usual off-screen pattern (skip links, visually-hidden
|
|
116
|
-
// text), which the page cannot scroll to anyway.
|
|
117
|
-
const past = rtl ? Math.max(right - clientWidth, -left) : right - clientWidth;
|
|
118
|
-
if (past > 1 && !contained(el)) offenders.push({ element: describe(el), right: Math.round(right), past });
|
|
119
|
-
}
|
|
120
|
-
offenders.sort((a, b) => b.past - a.past);
|
|
121
|
-
// overflow-x: hidden on <html>/<body> hides the scrollbar but still cuts
|
|
122
|
-
// the content off, so it is reported, flagged as hidden.
|
|
123
|
-
const hiddenBy = [root, document.body].find((el) => {
|
|
124
|
-
if (!el) return false;
|
|
125
|
-
const ox = getComputedStyle(el).overflowX;
|
|
126
|
-
return ox === 'hidden' || ox === 'clip';
|
|
127
|
-
});
|
|
128
|
-
overflow = {
|
|
129
|
-
scrollWidth,
|
|
130
|
-
clientWidth,
|
|
131
|
-
hiddenByPage: Boolean(hiddenBy),
|
|
132
|
-
offenders: offenders.slice(0, 5).map(({ element, right }) => ({ element, right })),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Drawn content of an <svg>, in its user units: the union of its visible
|
|
137
|
-
// leaf shapes (with half their stroke), skipping anything under a
|
|
138
|
-
// clip-path or mask (clipped on purpose) and anything not painted.
|
|
139
|
-
const LEAVES = 'path, rect, circle, ellipse, line, polyline, polygon, text, image, use, foreignObject';
|
|
140
|
-
const drawnBox = (svg) => {
|
|
141
|
-
const toUser = svg.getScreenCTM();
|
|
142
|
-
if (!toUser) return null;
|
|
143
|
-
const inverse = toUser.inverse();
|
|
144
|
-
let box = null;
|
|
145
|
-
for (const leaf of svg.querySelectorAll(LEAVES)) {
|
|
146
|
-
if (leaf.closest('defs, clipPath, mask, marker, pattern, symbol, linearGradient, radialGradient')) continue;
|
|
147
|
-
// A nested <svg> clips its own content; it is checked on its own terms
|
|
148
|
-
// only when it is the outermost one.
|
|
149
|
-
if (leaf.parentElement && leaf.parentElement.closest('svg') !== svg) continue;
|
|
150
|
-
let hidden = false;
|
|
151
|
-
for (let el = leaf; el && el !== svg; el = el.parentElement) {
|
|
152
|
-
const cs = getComputedStyle(el);
|
|
153
|
-
if (el.hasAttribute('clip-path') || el.hasAttribute('mask') || (cs.clipPath && cs.clipPath !== 'none') || (cs.mask && cs.mask !== 'none') || cs.display === 'none' || Number(cs.opacity) === 0) {
|
|
154
|
-
hidden = true;
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const leafStyle = getComputedStyle(leaf);
|
|
159
|
-
if (hidden || leafStyle.visibility !== 'visible') continue;
|
|
160
|
-
// Paints nothing (a transparent hover overlay): not visible content.
|
|
161
|
-
const paints = (paint) => Boolean(paint) && paint !== 'none' && paint !== 'transparent' && !(paint.startsWith('rgba(') && paint.replace(/ /g, '').endsWith(',0)'));
|
|
162
|
-
if (leaf.tagName !== 'image' && leaf.tagName !== 'use' && leaf.tagName !== 'foreignObject' && !paints(leafStyle.fill) && !paints(leafStyle.stroke)) continue;
|
|
163
|
-
let b;
|
|
164
|
-
try { b = leaf.getBBox(); } catch { continue; }
|
|
165
|
-
if (b.width === 0 && b.height === 0) continue;
|
|
166
|
-
const half = leafStyle.stroke && leafStyle.stroke !== 'none' ? (parseFloat(leafStyle.strokeWidth) || 0) / 2 : 0;
|
|
167
|
-
const matrix = leaf.getScreenCTM();
|
|
168
|
-
if (!matrix) continue;
|
|
169
|
-
const m = inverse.multiply(matrix);
|
|
170
|
-
for (const [x, y] of [[b.x - half, b.y - half], [b.x + b.width + half, b.y - half], [b.x - half, b.y + b.height + half], [b.x + b.width + half, b.y + b.height + half]]) {
|
|
171
|
-
const px = m.a * x + m.c * y + m.e;
|
|
172
|
-
const py = m.b * x + m.d * y + m.f;
|
|
173
|
-
box = box
|
|
174
|
-
? { x1: Math.min(box.x1, px), y1: Math.min(box.y1, py), x2: Math.max(box.x2, px), y2: Math.max(box.y2, py) }
|
|
175
|
-
: { x1: px, y1: py, x2: px, y2: py };
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return box;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// The region of user space the SVG actually shows: the viewBox scaled into
|
|
182
|
-
// the element's box under preserveAspectRatio (meet shows more than the
|
|
183
|
-
// viewBox, slice less), or the box itself without a viewBox.
|
|
184
|
-
const visibleRegion = (svg) => {
|
|
185
|
-
const width = svg.clientWidth || svg.getBoundingClientRect().width;
|
|
186
|
-
const height = svg.clientHeight || svg.getBoundingClientRect().height;
|
|
187
|
-
if (!width || !height) return null;
|
|
188
|
-
const vb = svg.viewBox && svg.viewBox.baseVal;
|
|
189
|
-
if (!vb || !(vb.width > 0) || !(vb.height > 0)) return { x1: 0, y1: 0, x2: width, y2: height };
|
|
190
|
-
const par = svg.preserveAspectRatio.baseVal;
|
|
191
|
-
if (par.align === 1) return { x1: vb.x, y1: vb.y, x2: vb.x + vb.width, y2: vb.y + vb.height };
|
|
192
|
-
const scale = par.meetOrSlice === 2
|
|
193
|
-
? Math.max(width / vb.width, height / vb.height)
|
|
194
|
-
: Math.min(width / vb.width, height / vb.height);
|
|
195
|
-
const shownWidth = width / scale;
|
|
196
|
-
const shownHeight = height / scale;
|
|
197
|
-
const xAlign = (par.align - 2) % 3;
|
|
198
|
-
const yAlign = Math.floor((par.align - 2) / 3);
|
|
199
|
-
const x1 = vb.x - ((shownWidth - vb.width) * xAlign) / 2;
|
|
200
|
-
const y1 = vb.y - ((shownHeight - vb.height) * yAlign) / 2;
|
|
201
|
-
return { x1, y1, x2: x1 + shownWidth, y2: y1 + shownHeight };
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const clippedSvgs = [];
|
|
205
|
-
for (const svg of document.querySelectorAll('svg')) {
|
|
206
|
-
if (svg.parentElement && svg.parentElement.closest('svg')) continue;
|
|
207
|
-
const style = getComputedStyle(svg);
|
|
208
|
-
if (style.overflow === 'visible' || style.display === 'none') continue;
|
|
209
|
-
const shown = visibleRegion(svg);
|
|
210
|
-
const drawn = shown && drawnBox(svg);
|
|
211
|
-
if (!drawn) continue;
|
|
212
|
-
const tolerance = Math.max(1, (shown.x2 - shown.x1) / 500);
|
|
213
|
-
const over = {
|
|
214
|
-
top: Math.max(0, shown.y1 - drawn.y1),
|
|
215
|
-
right: Math.max(0, drawn.x2 - shown.x2),
|
|
216
|
-
bottom: Math.max(0, drawn.y2 - shown.y2),
|
|
217
|
-
left: Math.max(0, shown.x1 - drawn.x1),
|
|
218
|
-
};
|
|
219
|
-
if (Object.values(over).some((v) => v > tolerance)) {
|
|
220
|
-
const round = (v) => Math.round(v * 10) / 10;
|
|
221
|
-
clippedSvgs.push({
|
|
222
|
-
element: describe(svg),
|
|
223
|
-
overflow: { top: round(over.top), right: round(over.right), bottom: round(over.bottom), left: round(over.left) },
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return { overflow, clippedSvgs, cspViolations: window.__artisCsp || [] };
|
|
229
|
-
})()`;
|
|
230
|
-
function isCspConsoleMessage(text) {
|
|
231
|
-
return /Content Security Policy/i.test(text);
|
|
232
|
-
}
|
|
233
|
-
async function verifyHtml(html) {
|
|
234
|
-
const { server, url } = await serveDocument(html);
|
|
235
|
-
try {
|
|
236
|
-
const browser = await launchBrowser();
|
|
237
|
-
try {
|
|
238
|
-
return await runChecks(browser, url);
|
|
239
|
-
} finally {
|
|
240
|
-
await browser.close().catch(() => void 0);
|
|
241
|
-
}
|
|
242
|
-
} finally {
|
|
243
|
-
await new Promise((resolve) => server.close(resolve));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async function runChecks(browser, url) {
|
|
247
|
-
const runs = [];
|
|
248
|
-
for (const width of verifyWidths) {
|
|
249
|
-
for (const theme of verifyThemes) {
|
|
250
|
-
const context = await browser.newContext({
|
|
251
|
-
viewport: { width, height: 900 },
|
|
252
|
-
colorScheme: theme
|
|
253
|
-
});
|
|
254
|
-
try {
|
|
255
|
-
const page = await context.newPage();
|
|
256
|
-
const consoleErrors = [];
|
|
257
|
-
page.on("console", (message) => {
|
|
258
|
-
if (message.type() === "error" && !isCspConsoleMessage(message.text())) {
|
|
259
|
-
consoleErrors.push(message.text());
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
page.on("pageerror", (error) => {
|
|
263
|
-
if (!isCspConsoleMessage(error.message)) {
|
|
264
|
-
consoleErrors.push(error.message);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
await page.addInitScript(RECORD_CSP_VIOLATIONS);
|
|
268
|
-
await page.goto(url(theme), { waitUntil: "load", timeout: 15e3 });
|
|
269
|
-
await page.waitForTimeout(400);
|
|
270
|
-
const findings = await page.evaluate(INSPECT_PAGE);
|
|
271
|
-
runs.push({
|
|
272
|
-
width,
|
|
273
|
-
theme,
|
|
274
|
-
overflow: findings.overflow,
|
|
275
|
-
clippedSvgs: findings.clippedSvgs,
|
|
276
|
-
consoleErrors: [...new Set(consoleErrors)],
|
|
277
|
-
cspViolations: dedupe(findings.cspViolations)
|
|
278
|
-
});
|
|
279
|
-
} finally {
|
|
280
|
-
await context.close();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
ok: runs.every(
|
|
286
|
-
(run) => !run.overflow && !run.clippedSvgs.length && !run.consoleErrors.length && !run.cspViolations.length
|
|
287
|
-
),
|
|
288
|
-
runs
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function dedupe(violations) {
|
|
292
|
-
const seen = /* @__PURE__ */ new Set();
|
|
293
|
-
return violations.filter((violation) => {
|
|
294
|
-
const key = `${violation.directive} ${violation.blocked}`;
|
|
295
|
-
if (seen.has(key)) return false;
|
|
296
|
-
seen.add(key);
|
|
297
|
-
return true;
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
function formatVerifyReport(report) {
|
|
301
|
-
if (report.ok) {
|
|
302
|
-
return [
|
|
303
|
-
`No problems found at ${verifyWidths.join(" and ")} px in light and dark themes.`
|
|
304
|
-
];
|
|
305
|
-
}
|
|
306
|
-
const lines = [];
|
|
307
|
-
const label = (run) => `${run.width}px ${run.theme}`;
|
|
308
|
-
const group = (pick, key) => {
|
|
309
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
310
|
-
for (const run of report.runs) {
|
|
311
|
-
for (const item of pick(run)) {
|
|
312
|
-
const entry = byKey.get(key(item)) ?? { item, runs: [] };
|
|
313
|
-
entry.runs.push(label(run));
|
|
314
|
-
byKey.set(key(item), entry);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return [...byKey.values()];
|
|
318
|
-
};
|
|
319
|
-
for (const run of report.runs) {
|
|
320
|
-
if (run.overflow) {
|
|
321
|
-
const offenders = run.overflow.offenders.map((o) => `${o.element} (to ${o.right}px)`).join(", ");
|
|
322
|
-
const hidden = run.overflow.hiddenByPage ? " (hidden by overflow-x on the page, so the content past the edge is cut off)" : "";
|
|
323
|
-
lines.push(
|
|
324
|
-
`Horizontal overflow at ${label(run)}: page is ${run.overflow.scrollWidth}px wide in a ${run.overflow.clientWidth}px viewport${hidden}${offenders ? `; widest: ${offenders}` : ""}.`
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
for (const { item, runs } of group(
|
|
329
|
-
(run) => run.clippedSvgs,
|
|
330
|
-
(svg) => `${svg.element} ${JSON.stringify(svg.overflow)}`
|
|
331
|
-
)) {
|
|
332
|
-
const sides = Object.entries(item.overflow).filter(([, value]) => value > 0).map(([side, value]) => `${side} ${value}`).join(", ");
|
|
333
|
-
lines.push(
|
|
334
|
-
`Clipped SVG ${item.element} (content past its viewport: ${sides}) at ${runs.join(", ")}.`
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
for (const { item, runs } of group(
|
|
338
|
-
(run) => run.consoleErrors,
|
|
339
|
-
(text) => text
|
|
340
|
-
)) {
|
|
341
|
-
lines.push(`Console error at ${runs.join(", ")}: ${item}`);
|
|
342
|
-
}
|
|
343
|
-
for (const { item, runs } of group(
|
|
344
|
-
(run) => run.cspViolations,
|
|
345
|
-
(violation) => `${violation.directive} ${violation.blocked}`
|
|
346
|
-
)) {
|
|
347
|
-
lines.push(
|
|
348
|
-
`CSP violation (${item.directive}) blocking ${item.blocked} at ${runs.join(", ")}. Artifacts may load nothing external: inline it or use a data: URL.`
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
return lines;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export {
|
|
355
|
-
verifyWidths,
|
|
356
|
-
verifyThemes,
|
|
357
|
-
artifactContentSecurityPolicy,
|
|
358
|
-
VerifyUnavailableError,
|
|
359
|
-
stampTheme,
|
|
360
|
-
verifyHtml,
|
|
361
|
-
formatVerifyReport
|
|
362
|
-
};
|