Skip to content

Instantly share code, notes, and snippets.

@yordis
Last active October 27, 2026 04:04
Show Gist options
  • Select an option

  • Save yordis/82a67245ebaa2f1458bbf1ecb7c64519 to your computer and use it in GitHub Desktop.

Select an option

Save yordis/82a67245ebaa2f1458bbf1ecb7c64519 to your computer and use it in GitHub Desktop.
Capture scripts for pingdotgg/t3code#25709
// Usage: REQ_FROM=<worktree>/apps/web/package.json node capture.mjs <label> <origin> <pairUrlFile> <outDir> <rows,comma>
import { createRequire } from "node:module";
import { readFileSync } from "node:fs";
const { chromium } = createRequire(process.env.REQ_FROM)("playwright");
const [label, origin, pairFile, outDir, rowArg] = process.argv.slice(2);
const rows = new Set(rowArg.split(","));
// Defaults to 1440 light. MATRIX=1 adds 390 and dark for local review only.
const VIEWPORTS = [
{ name: "1440", width: 1440, height: 900 },
...(process.env.MATRIX === "1" ? [{ name: "390", width: 390, height: 844 }] : []),
];
const THEMES = process.env.MATRIX === "1" ? ["light", "dark"] : ["light"];
const browser = await chromium.launch();
const context = await browser.newContext({ viewport: VIEWPORTS[0], deviceScaleFactor: 1, reducedMotion: "reduce" });
const page = await context.newPage();
await page.clock.setFixedTime(new Date("2026-10-26T12:00:00Z"));
await page.goto(readFileSync(pairFile, "utf8").trim());
await page.waitForURL((u) => !u.pathname.startsWith("/pair"), { timeout: 30000 });
// The environment label is the host's computer name; replace it so no machine name is published.
const mask = () =>
page.evaluate(() => {
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
if (/Mac Studio/.test(n.nodeValue)) n.nodeValue = n.nodeValue.replace(/\S+[’']s Mac Studio/g, "this server");
}
});
async function settle() {
await page.waitForLoadState("networkidle").catch(() => {});
await page.evaluate(() => document.fonts.ready);
for (let i = 0; i < 20; i++) {
await mask();
const a = await page.screenshot();
await page.waitForTimeout(500);
await mask();
const b = await page.screenshot();
if (a.equals(b)) return b;
}
throw new Error("frame never settled");
}
async function each(name, prepare) {
for (const vp of VIEWPORTS) {
for (const theme of THEMES) {
await page.setViewportSize({ width: vp.width, height: vp.height });
await page.emulateMedia({ colorScheme: theme, reducedMotion: "reduce" });
await prepare();
const buf = await settle();
const file = `${outDir}/${label}-${name}-${vp.name}-${theme}.png`;
(await import("node:fs")).writeFileSync(file, buf);
console.log(file);
}
}
}
const go = async (path) => {
await page.goto(`${origin}${path}`);
await page.getByText("Settings", { exact: true }).first().waitFor();
};
const closeDialogs = async () => {
while (await page.getByRole("dialog").or(page.getByRole("alertdialog")).count()) {
await page.keyboard.press("Escape");
await page.waitForTimeout(300);
}
};
const listed = () => page.getByRole("button", { name: "Toggle account visibility" });
const emptyState = () => page.getByText("No secret providers configured.");
async function removeAll() {
await go("/settings/secrets");
await listed().or(emptyState()).first().waitFor();
while (await page.getByRole("button", { name: "Remove", exact: true }).count()) {
await page.getByRole("button", { name: "Remove", exact: true }).first().click();
await page.getByRole("button", { name: "Remove provider" }).click();
await page.waitForTimeout(500);
}
await emptyState().waitFor();
}
async function addProvider(name, account) {
await page.getByRole("button", { name: "Add provider" }).first().click();
await page.getByRole("textbox", { name: "Name" }).fill(name);
await page.getByRole("textbox", { name: "Account" }).fill(account);
await page.getByRole("dialog").getByRole("button", { name: "Add provider" }).click();
await page.getByText(name, { exact: true }).waitFor();
await go("/settings/secrets");
}
if (rows.has("general")) await each("general", () => go("/settings/general"));
if (rows.has("secrets-url")) await each("secrets-url", async () => { await page.goto(`${origin}/settings/secrets`); await page.waitForTimeout(1500); });
if (rows.has("search")) {
await each("search", async () => {
await go("/settings/general");
const input = page.getByRole("combobox", { name: "Search settings" });
if (!(await input.isVisible())) await page.getByRole("button", { name: "Search settings" }).click();
await input.fill("secret");
await page.waitForTimeout(300);
});
}
if (rows.has("empty")) {
await removeAll();
await each("empty", async () => { await go("/settings/secrets"); await emptyState().waitFor(); });
}
if (rows.has("add")) {
await each("add", async () => {
await go("/settings/secrets");
await emptyState().waitFor();
await page.getByRole("button", { name: "Add provider" }).first().click();
await page.getByRole("textbox", { name: "Name" }).fill("Personal");
await page.getByRole("textbox", { name: "Account" }).fill("my.1password.com");
});
}
if (rows.has("add-invalid")) {
await each("add-invalid", async () => {
await go("/settings/secrets");
await page.getByRole("button", { name: "Add provider" }).first().click();
await page.getByRole("textbox", { name: "Account" }).fill("-bad");
await page.getByRole("dialog").getByRole("button", { name: "Add provider" }).click();
await page.getByRole("alert").first().waitFor();
});
}
if (rows.has("list")) {
await page.setViewportSize({ width: 1440, height: 900 });
await go("/settings/secrets");
await addProvider("Personal", "my.1password.com");
await addProvider("Work", "acme.1password.com");
await each("list", async () => { await go("/settings/secrets"); await page.getByText("Work", { exact: true }).waitFor(); });
}
if (rows.has("list-revealed")) {
await each("list-revealed", async () => {
await go("/settings/secrets");
await listed().first().click();
await page.mouse.move(0, 0);
await page.evaluate(() => document.activeElement?.blur());
await page.getByText("my.1password.com").waitFor();
await page.waitForTimeout(400);
});
}
if (rows.has("edit")) {
await each("edit", async () => {
await go("/settings/secrets");
await page.getByRole("button", { name: "Edit", exact: true }).first().click();
await page.getByRole("dialog").waitFor();
});
}
if (rows.has("remove")) {
await each("remove", async () => {
await go("/settings/secrets");
await page.getByRole("button", { name: "Remove", exact: true }).first().click();
await page.getByRole("button", { name: "Remove provider" }).waitFor();
});
}
await browser.close();
// Usage: REQ_FROM=<worktree>/apps/web/package.json node record.mjs <origin> <pairUrlFile> <outDir>
import { createRequire } from "node:module";
import { readFileSync, renameSync } from "node:fs";
const { chromium } = createRequire(process.env.REQ_FROM)("playwright");
const [origin, pairFile, outDir] = process.argv.slice(2);
const viewport = { width: 1440, height: 900 };
const browser = await chromium.launch();
const setup = await browser.newContext({ viewport });
const sp = await setup.newPage();
await sp.goto(readFileSync(pairFile, "utf8").trim());
await sp.waitForURL((u) => !u.pathname.startsWith("/pair"), { timeout: 30000 });
await sp.goto(`${origin}/settings/secrets`);
await sp.getByRole("button", { name: "Add provider" }).first().waitFor();
while (await sp.getByRole("button", { name: "Remove", exact: true }).count()) {
await sp.getByRole("button", { name: "Remove", exact: true }).first().click();
await sp.getByRole("button", { name: "Remove provider" }).click();
await sp.waitForTimeout(500);
}
await sp.getByText("No secret providers configured.").waitFor();
const storageState = await setup.storageState();
await setup.close();
const ctx = await browser.newContext({ viewport, storageState, colorScheme: "dark", reducedMotion: "reduce", recordVideo: { dir: outDir, size: viewport } });
await ctx.addInitScript(() => {
const fix = (root) => {
const w = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
for (let n; (n = w.nextNode()); )
if (/Mac Studio/.test(n.nodeValue)) n.nodeValue = n.nodeValue.replace(/\S+[’']s Mac Studio/g, "this server");
};
new MutationObserver(() => fix(document.documentElement)).observe(document, { subtree: true, childList: true, characterData: true });
});
const page = await ctx.newPage();
const t0 = Date.now();
const mark = (s) => console.log(`${((Date.now() - t0) / 1000).toFixed(1)}s ${s}`);
await page.goto(`${origin}/settings/secrets`);
await page.getByText("No secret providers configured.").waitFor();
mark("empty state shown");
await page.waitForTimeout(1000);
await page.getByRole("button", { name: "Add provider" }).first().click();
mark("clicked Add provider");
await page.waitForTimeout(600);
await page.getByRole("textbox", { name: "Name" }).pressSequentially("Personal", { delay: 80 });
await page.getByRole("textbox", { name: "Account" }).pressSequentially("my.1password.com", { delay: 60 });
mark("typed name and account");
await page.waitForTimeout(600);
await page.getByRole("textbox", { name: "Account" }).press("Enter");
mark("pressed Enter");
await page.getByRole("button", { name: "Toggle account visibility" }).waitFor();
mark("dialog closed, provider listed");
await page.waitForTimeout(1500);
const video = page.video();
await ctx.close();
renameSync(await video.path(), `${outDir}/after-on-enter-submits-1440-dark.webm`);
await browser.close();

Seeding and running

Before: git worktree add --detach <before-worktree> a2398c2ce3, run node scripts/setup-worktree.ts, then start it with an empty database so it matches the after side's thread list:

T3CODE_DEV_SEED=0 vp run dev

After (cc07e1c5c7): vp run dev for flag off, T3CODE_FEATURE_SECRETS=1 vp run dev for flag on. Both sides start with no secret providers; the capture script removes any before the empty-state row and adds the listed ones itself.

Pair each browser with a token minted for that worktree:

node apps/server/src/bin.ts pair --base-dir <worktree>/.t3 --label capture \
  --scope orchestration:read --scope settings:write --scope providers:manage

Write the pairing URL (host rewritten to the web dev port) to a file and pass it to the scripts:

REQ_FROM=<worktree>/apps/web/package.json node capture.mjs before http://localhost:<port> pair-file out general,secrets-url,search
REQ_FROM=<worktree>/apps/web/package.json node capture.mjs after-on http://localhost:<port> pair-file out general,search,empty,add,add-invalid,list,edit,remove
REQ_FROM=<worktree>/apps/web/package.json node record.mjs http://localhost:<port> pair-file out

Diffs:

magick compare -metric AE -fuzz 0  before.png after.png -highlight-color red -lowlight-color white -compose src diff0.png
magick compare -metric AE -fuzz 2% before.png after.png -highlight-color red -lowlight-color white -compose src diff2.png

The scripts replace the server's computer name in the dialog copy with "this server" before every frame.

What to publish

record.mjs produces the main evidence: one recording that walks the whole flow. When there are many states to show, extend the recording instead of adding screenshots. Publish at most 4 screenshots from capture.mjs, and none is fine. It captures only 1440 light unless MATRIX=1 is set, and the extra viewports, themes, and diffs are for local review, not for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment