Open History to see the last commit
1// Records one seeded usage-limit evidence thread (see usage-limit-web-evidence-seed.ts) at 1440 light.
2// node usage-limit-web-evidence-record.mjs <pairingUrl> <row> <outDir> <label> <action> [seconds]
3// action: watch (observe only) | resume (click the composer's "Resume thread" if present) |
4// arm (click the banner's "Resume at reset").
5// Writes <row>-<label>.webm plus a .captions.json of UTC-stamped steps. Usage limits are SYNTHETIC.
6import * as NodeModule from "node:module";
7import * as NodeFS from "node:fs";
8import * as NodePath from "node:path";
9
10const [pairingUrl, row, outDir, label, action = "watch", seconds = "20"] = process.argv.slice(2);
11if (!pairingUrl || !row || !outDir || !label) throw new Error("missing arguments");
12const require = NodeModule.createRequire(
13 NodePath.resolve(import.meta.dirname, "../../web/package.json"),
14);
15const { chromium } = require("playwright");
16const manifest = process.env.SEED_HOME
17 ? JSON.parse(NodeFS.readFileSync(`${process.env.SEED_HOME}/fixture-${row}.json`, "utf8"))
18 : null;
19const captions = [];
20const start = Date.now();
21const caption = (text) => {
22 const entry = {
23 t: (Date.now() - start) / 1000,
24 utc: new Date().toISOString(),
25 resetAt: manifest?.resetAt ?? null,
26 text,
27 };
28 captions.push(entry);
29 console.log(JSON.stringify(entry));
30};
31const browser = await chromium.launch();
32const pair = await browser.newContext({ viewport: { width: 1440, height: 900 } });
33const pairPage = await pair.newPage();
34await pairPage.goto(pairingUrl);
35await pairPage.waitForURL((url) => !url.pathname.startsWith("/pair"), { timeout: 180_000 });
36const title = pairPage.getByText(new RegExp(`^${row} `)).first();
37await title.waitFor({ timeout: 60_000 });
38await title.click();
39await pairPage.waitForURL((url) => url.pathname.includes(encodeURIComponent(`evidence:${row}`)), {
40 timeout: 60_000,
41});
42const threadUrl = pairPage.url();
43const storageState = await pair.storageState();
44await pair.close();
45NodeFS.mkdirSync(outDir, { recursive: true });
46const context = await browser.newContext({
47 viewport: { width: 1440, height: 900 },
48 colorScheme: "light",
49 storageState,
50 recordVideo: { dir: outDir, size: { width: 1440, height: 900 } },
51});
52const page = await context.newPage();
53caption(
54 `[${label}] open ${row}: SYNTHETIC usage-limit fixture seeded (reset ${manifest?.resetAt ?? "?"})`,
55);
56await page.goto(threadUrl);
57await page.getByText("Work on this.").first().waitFor({ timeout: 120_000 });
58await page.waitForTimeout(3000);
59const banner = async () =>
60 (await page.getByText("Usage limit reached", { exact: true }).count()) > 0
61 ? "banner shown"
62 : "no banner";
63caption(`[${label}] loaded: ${await banner()}; sidebar row ${row}`);
64if (action === "arm") {
65 const arm = page.getByRole("button", { name: "Resume at reset" });
66 if ((await arm.count()) > 0) {
67 caption(`[${label}] click "Resume at reset"`);
68 await arm.first().click();
69 await page.waitForTimeout(4000);
70 const cancel = await page.getByRole("button", { name: "Cancel auto-resume" }).count();
71 caption(`[${label}] after click: "Cancel auto-resume" ${cancel > 0 ? "shown" : "not shown"}`);
72 } else {
73 caption(`[${label}] "Resume at reset" button absent; nothing to click`);
74 }
75}
76if (action === "resume") {
77 const resume = page.getByRole("button", { name: /Resume thread/i });
78 if ((await resume.count()) > 0) {
79 caption(`[${label}] click "Resume thread"`);
80 await resume.first().click();
81 await page.waitForTimeout(6000);
82 caption(
83 `[${label}] after click: ${await banner()}; continuation message ${(await page.getByText("Continue where you left off").count()) > 0 ? "visible" : "not visible"}`,
84 );
85 } else {
86 caption(`[${label}] "Resume thread" button absent; nothing to click`);
87 }
88}
89const end = Date.now() + Number(seconds) * 1000;
90while (Date.now() < end) {
91 await page.waitForTimeout(5000);
92 caption(`[${label}] ${await banner()}`);
93}
94const video = page.video();
95await context.close();
96const file = NodePath.join(outDir, `${row}-${label}.webm`);
97NodeFS.renameSync(await video.path(), file);
98NodeFS.writeFileSync(
99 file.replace(/\.webm$/, ".captions.json"),
100 JSON.stringify({ browser: browser.version(), threadUrl, captions }, null, 2),
101);
102await browser.close();