Skip to content

Write HTML. Render video. Built for agents.

test(lint): make catalog and scaling tests pass on Windows (#5579)

lbianlbian178eea5634d4
diff --git a/packages/lint/src/rules/structure.catalog.test.ts b/packages/lint/src/rules/structure.catalog.test.ts
index dd6ac4ca4a..43ff5339bf 100644
--- a/packages/lint/src/rules/structure.catalog.test.ts
+++ b/packages/lint/src/rules/structure.catalog.test.ts
@@ -1,5 +1,5 @@
import { readdirSync, readFileSync } from "node:fs";
-import { join, resolve } from "node:path";
+import { basename, join, resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { lintHyperframeHtml } from "../hyperframeLinter";
@@ -30,7 +30,7 @@ describe("structure rules on the shipped catalog and skills", () => {
const hits: string[] = [];
let roots = 0;
for (const file of files) {
- const isRoot = file.endsWith("/index.html");
+ const isRoot = basename(file) === "index.html";
roots += isRoot ? 1 : 0;
const { findings } = await lintHyperframeHtml(readFileSync(file, "utf8"), {
host: "studio",
diff --git a/packages/lint/src/utils.test.ts b/packages/lint/src/utils.test.ts
index f32ec2bcc6..3f5662cf15 100644
--- a/packages/lint/src/utils.test.ts
+++ b/packages/lint/src/utils.test.ts
@@ -207,6 +207,9 @@ describe("stripJsStringLiterals scaling", () => {
// output string's growth adds its own cost and 8x input measures ~20x even
// for the linear scan. Inside that range 8x input measures ~8x; a quadratic
// scan measures 60x or more.
+ //
+ // Each sample repeats the scan until it has spent at least 50ms: Windows
+ // updates `process.cpuUsage` in ~15.6ms ticks, so one fast scan can read 0.
it("stays linear in slash-dense input", { timeout: 30_000 }, () => {
const cpuMs = (n: number) => {
const src = "a=b/c;".repeat(n);
@@ -214,9 +217,15 @@ describe("stripJsStringLiterals scaling", () => {
let best = Infinity;
for (let run = 0; run < 5; run += 1) {
const started = process.cpuUsage();
- stripJsStringLiterals(src);
- const spent = process.cpuUsage(started);
- best = Math.min(best, (spent.user + spent.system) / 1000);
+ let iterations = 0;
+ let spentMs = 0;
+ while (spentMs < 50) {
+ stripJsStringLiterals(src);
+ iterations += 1;
+ const spent = process.cpuUsage(started);
+ spentMs = (spent.user + spent.system) / 1000;
+ }
+ best = Math.min(best, spentMs / iterations);
}
return best;
};