Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(showcase): await Chrome shutdown before cleanup

杨嘉伟db192fe80434
diff --git a/scripts/build-readme-showcase.mjs b/scripts/build-readme-showcase.mjs
index 55b9c3a7..906ebe93 100644
--- a/scripts/build-readme-showcase.mjs
+++ b/scripts/build-readme-showcase.mjs
@@ -234,6 +234,19 @@ async function evaluate(cdp, sessionId, expression, awaitPromise = false) {
return result.result?.value;
}
+async function stopChrome(chrome) {
+ if (chrome.exitCode !== null || chrome.signalCode !== null) return;
+ const closed = new Promise(resolve => chrome.once('close', resolve));
+ chrome.kill('SIGTERM');
+ const graceful = await Promise.race([
+ closed.then(() => true),
+ sleep(5000).then(() => false),
+ ]);
+ if (graceful) return;
+ chrome.kill('SIGKILL');
+ await closed;
+}
+
async function captureFrames(chromePath, tempRoot) {
const profileRoot = path.join(tempRoot, 'profile');
const framesRoot = path.join(tempRoot, 'frames');
@@ -299,7 +312,7 @@ async function captureFrames(chromePath, tempRoot) {
throw error;
} finally {
cdp.failAll(new Error('capture finished'));
- chrome.kill('SIGTERM');
+ await stopChrome(chrome);
}
}
diff --git a/test/readme-showcase.test.mjs b/test/readme-showcase.test.mjs
index 6671de88..668c1faf 100644
--- a/test/readme-showcase.test.mjs
+++ b/test/readme-showcase.test.mjs
@@ -142,6 +142,9 @@ test('README motion proof is compact, looping, and backed by current gallery art
assert.match(builder, /\?embed=1&theme=dark\$\{scene\.hash\}/);
assert.doesNotMatch(builder, /play=1|#view=/);
assert.match(builder, /path\.relative\(from, to\)\.split\(path\.sep\)\.join\('\/'\)/);
+ assert.match(builder, /async function stopChrome\(chrome\)/);
+ assert.match(builder, /await stopChrome\(chrome\)/);
+ assert.match(builder, /chrome\.kill\('SIGKILL'\)/);
const buffer = fs.readFileSync(assetPath);
const receipt = JSON.parse(fs.readFileSync(receiptPath, 'utf8'));
const inspected = inspectGif(buffer);