From f49b5dfd7959d45564d36f1e89b02c4513b46f96 Mon Sep 17 00:00:00 2001 From: 0libote <79215282+0libote@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:44:08 +0000 Subject: [PATCH] sync(hallmark): hallmark from Nutlope/hallmark@04977e1 --- .github/upstream-state/hallmark/hallmark | 2 +- skills/hallmark/scripts/capture.mjs | 10 ++++++---- skills/hallmark/scripts/capture.test.mjs | 25 +++++++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.github/upstream-state/hallmark/hallmark b/.github/upstream-state/hallmark/hallmark index 44f175a..0a5058a 100644 --- a/.github/upstream-state/hallmark/hallmark +++ b/.github/upstream-state/hallmark/hallmark @@ -1 +1 @@ -407fa689f4a276f2fd389208d271d0fef08f5058 +04977e15f3dfd6ee4b74c887dac3eb52665d6c92 diff --git a/skills/hallmark/scripts/capture.mjs b/skills/hallmark/scripts/capture.mjs index 6155d95..df020f3 100644 --- a/skills/hallmark/scripts/capture.mjs +++ b/skills/hallmark/scripts/capture.mjs @@ -15,7 +15,7 @@ // of the viewport; --full captures the whole scroll height. It never draws a browser bar or a device // frame: the page frames the picture in the theme's material. import { mkdirSync, existsSync, writeFileSync } from 'node:fs'; -import { join, dirname, resolve, relative } from 'node:path'; +import { join, dirname, resolve, relative, sep } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { createRequire } from 'node:module'; @@ -70,7 +70,7 @@ if (has('cdp')) { const dpr = await page.evaluate(() => devicePixelRatio).catch(() => 1); const rel = relative(process.cwd(), file); console.log(`${rel} ${Math.round(box.width * dpr)} x ${Math.round(box.height * dpr)} (app window)`); - console.log(` `); + console.log(` `); await app.disconnect(); process.exit(0); } @@ -107,7 +107,9 @@ try { await new Promise((r) => setTimeout(r, wait)); await p.bringToFront(); const slug = route === '/' ? 'home' : route.replace(/^\/|\/$/g, '').replace(/[^\w-]+/g, '-'); - const file = join(out, `${name}-${slug}-${size}${selector ? '-part' : ''}.png`); + const stem = join(out, `${name}-${slug}-${size}${selector ? '-part' : ''}`); + let file = `${stem}.png`, suffix = 2; + while (made.some((m) => m.file === file)) file = `${stem}-${suffix++}.png`; let shot; if (selector) { const el = await p.$(selector); @@ -124,7 +126,7 @@ try { for (const m of made) { const rel = relative(process.cwd(), m.file); console.log(`${rel} ${m.w} x ${m.h} (${m.route}, ${m.size})`); - console.log(` `); + console.log(` `); } if (!made.length) process.exitCode = 1; else console.log(`\n${made.length} screenshot${made.length > 1 ? 's' : ''}. Look at each one before placing it: sample data only, nothing personal (names, emails, tokens), the screen in the state that tells the page's story.`); diff --git a/skills/hallmark/scripts/capture.test.mjs b/skills/hallmark/scripts/capture.test.mjs index 6defea2..eb0091f 100644 --- a/skills/hallmark/scripts/capture.test.mjs +++ b/skills/hallmark/scripts/capture.test.mjs @@ -9,11 +9,11 @@ import test from 'node:test'; const skip = !process.env.HALLMARK_PUPPETEER || !process.env.CHROME_PATH ? 'set HALLMARK_PUPPETEER and CHROME_PATH for real-browser regressions' : false; const script = fileURLToPath(new URL('./capture.mjs', import.meta.url)); -async function capture(routes, prepare, check) { +async function capture(routes, prepare, check, out) { const dir = mkdtempSync(join(tmpdir(), 'hallmark-capture-')); const server = createServer((req, res) => { if (req.url === '/redirect') { res.writeHead(302, { Location: '/ok' }); res.end(); return; } - const status = req.url === '/ok' ? 200 : req.url === '/missing' ? 404 : 500; + const status = ['/ok', '/', '/home', '/a/b', '/a-b', '/a-b-2'].includes(req.url) ? 200 : req.url === '/missing' ? 404 : 500; res.writeHead(status, { 'Content-Type': 'text/html' }); res.end(`${status}

${status === 200 ? 'Owned product fixture' : 'Error document'}

`); }); @@ -21,7 +21,7 @@ async function capture(routes, prepare, check) { try { prepare?.(dir); const result = await new Promise((resolve, reject) => { - const p = spawn(process.execPath, [script, `http://127.0.0.1:${server.address().port}`, '--routes', routes, '--sizes', 'desktop', '--wait', '0', '--scale', '1', '--out', dir], { env: process.env }); + const p = spawn(process.execPath, [script, `http://127.0.0.1:${server.address().port}`, '--routes', routes, '--sizes', 'desktop', '--wait', '0', '--scale', '1', '--out', out || dir], { cwd: dir, env: process.env }); let stdout = '', stderr = ''; p.stdout.on('data', (s) => { stdout += s; }); p.stderr.on('data', (s) => { stderr += s; }); @@ -54,6 +54,12 @@ test('capture keeps successful routes when another route fails', { skip }, async assert.deepEqual([...readFileSync(join(dir, 'screen-ok-desktop.png')).subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10]); }); }); +test('capture prints the src with forward slashes', { skip }, async () => { + await capture('/ok', null, (dir, result) => { + assert.equal(result.status, 0, result.stderr); + assert.match(result.stdout, / { await capture('/redirect', null, (dir, result) => { assert.equal(result.status, 0, result.stderr); @@ -61,3 +67,16 @@ test('capture accepts a redirect to a successful document', { skip }, async () = assert.match(result.stdout, / { + await capture(routes, null, (dir, result) => { + assert.equal(result.status, 0, result.stdout + result.stderr); + const files = readdirSync(dir); + assert.equal(files.length, routes.split(',').length); + for (const file of files) assert.deepEqual([...readFileSync(join(dir, file)).subarray(0, 8)], [137, 80, 78, 71, 13, 10, 26, 10]); + const sources = [...result.stdout.matchAll(/ m[1]); + assert.equal(new Set(sources).size, files.length); + }); + }); +}