Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Nightly Windows tests stop timing out: shards pack by Windows test times (GST-3440) (#4661)
Garry Tan6484fd58aea6
diff --git a/.github/workflows/windows-free-tests.yml b/.github/workflows/windows-free-tests.ymlindex 55dab78cb..2a6893b22 100644--- a/.github/workflows/windows-free-tests.yml+++ b/.github/workflows/windows-free-tests.yml@@ -18,10 +18,10 @@ name: Windows Free Tests# the curated files, one shard per Windows job, and an aggregate that requires# every strict result and exact coverage. The plan and the verify step are# static (file contents and the git revision), so they run on Linux. Packing-# reads Windows-measured durations (scripts/free-test-durations-windows.json):-# Windows-only files such as the native cookie job cost minutes there and-# nothing on Linux. Refresh it with a `record_durations` dispatch and commit-# the artifact.+# reads Windows-measured durations (scripts/free-test-durations-windows.json),+# with a file's Linux time when the Windows seed lacks it: Windows-only files+# such as the native cookie job cost minutes there and nothing on Linux.+# Refresh it with a `record_durations` dispatch and commit the artifact.## Native browser qualification campaigns (Windows cookie extraction, launch# diagnostics) are dispatch-only in native-qualification.yml.@@ -110,11 +110,10 @@ jobs:bun-version: 1.4.2- id: planname: Curate and balance the Windows-safe free suite- # Eight shards: the 2026-11-16 Windows seed sums to about 96 min of- # per-file work, about 12 min a shard, which ran at 0.6-0.9x inside a- # shard, so each job lands near 10 min, under its 15-minute limit.+ # At least eight shards, more when needed so no shard plans past 720 s,+ # 80% of its 15-minute job (GST-3440); in-shard time ran at 0.6-0.9x+ # recorded, plus about 70 s of job setup.env:- GSTACK_FREE_TEST_DURATIONS: scripts/free-test-durations-windows.jsonJOBS_OVERRIDE: ${{ inputs.windows_jobs }}run: |set -euo pipefail@@ -126,7 +125,7 @@ jobs:if [ "$jobs" != "$WINDOWS_FREE_JOBS" ]; thenecho "- Sub-shard experiment: $jobs sub-shards per Windows shard (default $WINDOWS_FREE_JOBS); not a PR Windows Free Tests result" >> "$GITHUB_STEP_SUMMARY"fi- matrix=$(bun run scripts/test-free-shards.ts --windows-only --ci-plan "$RUNNER_TEMP/windows-plan.json" --shards 8 --shard-jobs "$jobs")+ matrix=$(bun run scripts/test-free-shards.ts --windows-only --ci-plan "$RUNNER_TEMP/windows-plan.json" --shards 8 --shard-jobs "$jobs" --shard-budget-seconds 720)echo "matrix=$matrix" >> "$GITHUB_OUTPUT"- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7with:diff --git a/changelog.d/windows-shards-pack-by-windows-time.md b/changelog.d/windows-shards-pack-by-windows-time.mdnew file mode 100644index 000000000..5ef41e873--- /dev/null+++ b/changelog.d/windows-shards-pack-by-windows-time.md@@ -0,0 +1 @@+**The nightly Windows test run no longer loses a shard to its 15-minute limit.** Its plan packs files by their Windows-recorded time, uses a file's Linux time only when the Windows recording lacks it (instead of a 161-second guess), and adds shards beyond eight until no shard plans more than 12 minutes of work. docs/TESTING_INTERNALS.md (GST-3440)diff --git a/docs/TESTING_INTERNALS.md b/docs/TESTING_INTERNALS.mdindex 119f62188..c9098ae28 100644--- a/docs/TESTING_INTERNALS.md+++ b/docs/TESTING_INTERNALS.md@@ -1850,7 +1850,10 @@ The full curated suite below runs nightly on main and on dispatch, never on a PR`windows-latest` job(`bun run test:windows --ci-run`), and verifies every shard receipt on Linux(`--windows-only --ci-verify`). Packing uses Windows-measured durations from-`scripts/free-test-durations-windows.json`; the weekly+`scripts/free-test-durations-windows.json`, and a file's Linux time when that+seed lacks it. With `--shard-budget-seconds 720`, `--shards 8` is a floor: the+planner adds shards until no shard plans more than 12 minutes, 80% of the+15-minute job. The weekly`free-durations-record.yml` run refreshes them, or by hand run`gh workflow run windows-free-tests.yml --ref <branch> -f record_durations=true`,then download the `free-test-durations-windows` artifact and commit it.diff --git a/scripts/harness-pins/scripts/test-pr-profile.ts.json b/scripts/harness-pins/scripts/test-pr-profile.ts.jsonindex 932768a4a..24141a1a9 100644--- a/scripts/harness-pins/scripts/test-pr-profile.ts.json+++ b/scripts/harness-pins/scripts/test-pr-profile.ts.json@@ -1 +1 @@-{"blob":"7de8d1dd5060bc0ec25fca1f3b348c354e5938a1","since":7,"nonBehavioral":"GST-3386 adds .github/workflows/test-changes.yml to FREE_ONLY_PR_FILES in scripts/test-pr-profile.ts: the new workflow is a free, flag-only check, so it only classifies that file as free-lane in the workflow inventory; no paid case's selection, prompt, threshold, samples or verdict can change"}+{"blob":"16093cf648950c2a863689e261ea2d06279a8740","since":7,"nonBehavioral":"GST-3440 adds scripts/free-test-durations-windows.json to FREE_ONLY_PR_FILES in scripts/test-pr-profile.ts: the Windows duration seed is read only by the free Windows shard plan, so it only stops a seed refresh from selecting paid cases; no paid case's selection, prompt, threshold, samples or verdict can change"}diff --git a/scripts/test-free-shards.ts b/scripts/test-free-shards.tsindex dedaecb4b..e439a3a2f 100755--- a/scripts/test-free-shards.ts+++ b/scripts/test-free-shards.ts@@ -77,6 +77,9 @@* bun run scripts/test-free-shards.ts --attribute-home # name real-home writers: each file alone, private HOME* bun run scripts/test-free-shards.ts --ci-plan plan.json --shards 20* bun run scripts/test-free-shards.ts --ci-run plan.json --shard 1 --result result.json+ * bun run scripts/test-free-shards.ts --windows-only --ci-plan plan.json --shards 8 --shard-budget-seconds 720+ * # --shards becomes a floor: the Windows plan adds shards, up to twice it, until every+ * # shard predicts at most 720 s, and fails past that (GST-3440).* bun run scripts/test-free-shards.ts --ci-plan plan.json --shards 20 --shard-jobs 2* # the plan stores a per-shard k: min(k, the shard's files that may run in parallel),* # kept only when above 1, so the exclusive TREE_MUTATING shard stays one child.@@ -382,6 +385,23 @@ export function loadFreeTestDurations(rootDir = ROOT): Record<string, number> |return Object.keys(seed.durations).length === 0 ? null : seed.durations;}+export const WINDOWS_FREE_TEST_DURATIONS_FILE = 'scripts/free-test-durations-windows.json';++/**+ * Windows plans pack by Windows-recorded time. A file the Windows seed lacks+ * falls back to its Linux time instead of the Windows 99th percentile (161 s),+ * which once packed 27 such files as phantom load and left one shard with+ * 946 s of real Windows work against a 900 s job (GST-3440).+ */+export function loadWindowsFreeTestDurations(rootDir = ROOT): Record<string, number> {+ const read = (file: string) => {+ const seed = readDurationSeed(path.join(rootDir, file), FREE_LANE_POLICY.acceptsSeedDuration);+ if (seed.status === 'corrupt') console.error(`[test:free] WARNING: corrupt durations seed ${file} (${seed.error.message})`);+ return seed.status === 'ok' ? seed.durations : {};+ };+ return { ...read(FREE_TEST_DURATIONS_FILE), ...read(WINDOWS_FREE_TEST_DURATIONS_FILE) };+}+export interface PackedShards {shards: string[][];/** Predicted total per shard, aligned with `shards` — feeds walls + logs. */@@ -493,6 +513,20 @@ export function createFreeCiPlan(files: string[], count: number, durations: Recoreturn { ...body, id: planDigest(body) };}+/**+ * The Windows plan with the fewest shards, from `minimum` up to twice it, whose+ * every shard predicts at most `budgetMs` (--shard-budget-seconds). Needing more+ * than that means a stale Windows seed, so the plan fails instead of growing further.+ */+export function createWindowsCiPlan(files: string[], minimum: number, budgetMs: number, durations: Record<string, number>, revision: string, shardJobs = 1): FreeCiPlan {+ for (let count = minimum; count <= minimum * 2; count += 1) {+ const plan = createFreeCiPlan(files, count, durations, revision, shardJobs);+ if (plan.shards.every(shard => shard.predictedMs <= budgetMs)) return plan;+ }+ throw new Error(`No Windows plan of ${minimum} to ${minimum * 2} shards keeps every shard within ${budgetMs / 1000} s.`+ + ` Refresh ${WINDOWS_FREE_TEST_DURATIONS_FILE} with a record_durations dispatch of windows-free-tests.yml.`);+}+/*** --ci-plan's stdout, the GitHub matrix. With --job-setup-seconds each entry* carries the shard's job timeout (ciShardJobTimeoutMinutes); without it, the@@ -629,6 +663,8 @@ type CliOptions = {shardJobs?: number;/** Set only by --job-setup-seconds (with --ci-plan): the matrix then carries each shard's job timeout. */jobSetupSeconds?: number;+ /** Set only by --shard-budget-seconds (with --windows-only --ci-plan): --shards is then a floor. */+ shardBudgetSeconds?: number;};export function parseCliOptions(argv: string[]): CliOptions {@@ -646,6 +682,7 @@ export function parseCliOptions(argv: string[]): CliOptions {let jobs: number | undefined;let shardJobs: number | undefined;let jobSetupSeconds: number | undefined;+ let shardBudgetSeconds: number | undefined;let junitDir: string | undefined;const paths: Record<'ciPlan' | 'ciRun' | 'ciVerify' | 'result' | 'results' | 'filesFrom', string | null> = {ciPlan: null, ciRun: null, ciVerify: null, result: null, results: null, filesFrom: null,@@ -682,6 +719,11 @@ export function parseCliOptions(argv: string[]): CliOptions {jobSetupSeconds = /^\d+$/.test(value) ? Number(value) : NaN;if (!(jobSetupSeconds > 0 && jobSetupSeconds <= 3600)) throw new Error('--job-setup-seconds needs a whole number of seconds from 1 to 3600');},+ '--shard-budget-seconds': (next) => {+ const value = next() ?? '';+ shardBudgetSeconds = /^\d+$/.test(value) ? Number(value) : NaN;+ if (!(shardBudgetSeconds > 0 && shardBudgetSeconds <= 21600)) throw new Error('--shard-budget-seconds needs a whole number of seconds from 1 to 21600');+ },'--shards': (next) => {const value = next();if (!value) throw new Error('Missing value for --shards');@@ -709,8 +751,9 @@ export function parseCliOptions(argv: string[]): CliOptions {if (jobs !== undefined && !paths.ciRun) rejectJobsWithoutCiRun();if (shardJobs !== undefined && !paths.ciPlan) rejectShardJobsWithoutCiPlan();if (jobSetupSeconds !== undefined && !paths.ciPlan) throw new Error('--job-setup-seconds applies only to --ci-plan');+ if (shardBudgetSeconds !== undefined && !(paths.ciPlan && windowsOnly)) throw new Error('--shard-budget-seconds applies only to --windows-only --ci-plan');if (quick && (recordDurations || windowsOnly || shardIndex !== null)) throw new Error('--quick cannot change recording, Windows or shard selection');- return { dryRun, listOnly, recordDurations, windowsOnly, verbose, shardCount, shardIndex, wallTimeoutMs, wallTimeoutExplicit, quick, attributeHome, ...paths, ...(jobs === undefined ? {} : { jobs }), ...(shardJobs === undefined ? {} : { shardJobs }), ...(jobSetupSeconds === undefined ? {} : { jobSetupSeconds }), ...(junitDir === undefined ? {} : { junitDir }) };+ return { dryRun, listOnly, recordDurations, windowsOnly, verbose, shardCount, shardIndex, wallTimeoutMs, wallTimeoutExplicit, quick, attributeHome, ...paths, ...(jobs === undefined ? {} : { jobs }), ...(shardJobs === undefined ? {} : { shardJobs }), ...(jobSetupSeconds === undefined ? {} : { jobSetupSeconds }), ...(shardBudgetSeconds === undefined ? {} : { shardBudgetSeconds }), ...(junitDir === undefined ? {} : { junitDir }) };}const describeLines = (lines: string[]) => `${lines.slice(0, 5).join(', ')}${lines.length > 5 ? ` (+${lines.length - 5} more)` : ''}`;@@ -2047,14 +2090,22 @@ async function main(): Promise<number> {fs.renameSync(temporary, file);};if (options.ciPlan) {- const durations = loadFreeTestDurations() ?? {};+ const durations = curation ? loadWindowsFreeTestDurations() : loadFreeTestDurations() ?? {};if (curation) {const line = windowsCurationLine(curation);console.error(`[test:free] ${line}`);appendStepSummary(line);}warnUnseededFreeFiles(ciFiles, durations);- const plan = createFreeCiPlan(ciFiles, options.shardCount, durations, revision, options.shardJobs, options.jobSetupSeconds);+ const budgetSeconds = options.shardBudgetSeconds;+ const plan = budgetSeconds !== undefined+ ? createWindowsCiPlan(ciFiles, options.shardCount, budgetSeconds * 1000, durations, revision, options.shardJobs)+ : createFreeCiPlan(ciFiles, options.shardCount, durations, revision, options.shardJobs, options.jobSetupSeconds);+ if (budgetSeconds !== undefined) {+ const line = `Windows plan: ${plan.shards.length} shards, heaviest ${Math.round(Math.max(...plan.shards.map(shard => shard.predictedMs)) / 1000)} s of a ${budgetSeconds} s budget`;+ console.error(`[test:free] ${line}`);+ appendStepSummary(line);+ }validateFreeCiPlan(plan, ciFiles, revision);const matrix = ciPlanMatrix(plan, options.jobSetupSeconds);if ('include' in matrix) {diff --git a/scripts/test-pr-profile.ts b/scripts/test-pr-profile.tsindex 7de8d1dd5..16093cf64 100644--- a/scripts/test-pr-profile.ts+++ b/scripts/test-pr-profile.ts@@ -238,6 +238,7 @@ export const FREE_ONLY_PR_FILES = ['test/helpers/auq-parallel-worker.ts','test/helpers/stored-zip.ts', // Read only by the free test-health report tests.'scripts/free-test-durations.json',+ 'scripts/free-test-durations-windows.json', // Read only by the free Windows plan (scripts/test-free-shards.ts --windows-only --ci-plan).'scripts/free-test-seed-allowlist.json', // Read only by the free seed ratchet (test/free-seed-ratchet.test.ts).'scripts/paid-test-durations.json','scripts/ubicloud/**',diff --git a/test/windows-native-workflows.test.ts b/test/windows-native-workflows.test.tsindex fa89d2d7b..2647d6c91 100644--- a/test/windows-native-workflows.test.ts+++ b/test/windows-native-workflows.test.ts@@ -8,7 +8,7 @@ import { spawnSync } from 'node:child_process';import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import os from 'node:os';import path from 'node:path';-import { collectFreeTestFiles, createFreeCiPlan, curateWindowsSafe, parseCliOptions, validateFreeCiPlan } from '../scripts/test-free-shards';+import { collectFreeTestFiles, createFreeCiPlan, createWindowsCiPlan, curateWindowsSafe, parseCliOptions, validateFreeCiPlan } from '../scripts/test-free-shards';import { windowsCurationLine } from '../scripts/lib/free-ci-health';import { KNOWN_WINDOWS_SAFE, WINDOWS_PROBE_SAFE } from '../scripts/lib/windows-curation';@@ -34,8 +34,8 @@ test('the Windows lane runs nightly and by hand, plans, runs one strict shard peconst plan = windows.jobs['windows-plan'];expect(plan['runs-on']).toBe('ubuntu-24.04');const planStep = plan.steps.find((step: any) => step.id === 'plan');- expect(planStep.run).toContain('--windows-only --ci-plan "$RUNNER_TEMP/windows-plan.json" --shards 8');- expect(planStep.env.GSTACK_FREE_TEST_DURATIONS).toBe('scripts/free-test-durations-windows.json');+ expect(planStep.run).toContain('--windows-only --ci-plan "$RUNNER_TEMP/windows-plan.json" --shards 8 --shard-jobs "$jobs" --shard-budget-seconds 720)');+ expect(planStep.env.GSTACK_FREE_TEST_DURATIONS).toBeUndefined();const shard = windows.jobs['windows-free-shard'];expect(shard['runs-on']).toBe('windows-latest');expect(shard.needs).toEqual(['windows-plan', 'reuse']);@@ -82,6 +82,42 @@ test.skipIf(!Bun.which('bash'))('windows-plan passes the one sub-shard constant,} finally { rmSync(directory, { recursive: true, force: true }); }});+test.skipIf(!Bun.which('bash'))('the windows-plan step packs real Windows seed time, so no shard plans past 80% of its job limit (GST-3440)', () => {+ const budgetMs = windows.jobs['windows-free-shard']['timeout-minutes'] * 60_000 * 0.8;+ const planStep = windows.jobs['windows-plan'].steps.find((step: any) => step.id === 'plan');+ const directory = mkdtempSync(path.join(os.tmpdir(), 'windows plan budget '));+ const toShell = (p: string) => p.split(path.sep).join('/');+ const env: Record<string, string | undefined> = { ...process.env };+ delete env.GSTACK_FREE_TEST_DURATIONS;+ try {+ const result = spawnSync('bash', ['-c', planStep.run], {+ cwd: root, encoding: 'utf8', timeout: 60_000,+ env: { ...env, ...windows.env, ...planStep.env, JOBS_OVERRIDE: '', RUNNER_TEMP: toShell(directory),+ GITHUB_OUTPUT: toShell(path.join(directory, 'output')), GITHUB_STEP_SUMMARY: toShell(path.join(directory, 'summary')) },+ });+ expect(result.status, result.stderr).toBe(0);+ const plan = JSON.parse(readFileSync(path.join(directory, 'windows-plan.json'), 'utf8')) as { shards: Array<{ shard: number; files: string[]; predictedMs: number }> };+ const seed = (file: string) => JSON.parse(readFileSync(path.join(root, file), 'utf8')).durations as Record<string, number>;+ const windowsMs = seed('scripts/free-test-durations-windows.json');+ const linuxMs = seed('scripts/free-test-durations.json');+ const recorded = plan.shards.map(({ shard, files }) => ({ shard, seconds: Math.round(files.reduce((ms, file) => ms + (windowsMs[file] ?? linuxMs[file] ?? 0), 0) / 1000) }));+ expect(recorded.filter(({ seconds }) => seconds * 1000 > budgetMs)).toEqual([]);+ expect(plan.shards.filter(({ predictedMs }) => predictedMs > budgetMs).map(({ shard }) => shard)).toEqual([]);+ expect(planStep.run).toContain(`--shard-budget-seconds ${budgetMs / 1000})`);+ } finally { rmSync(directory, { recursive: true, force: true }); }+}, 90_000);++test('only a Windows plan takes a shard budget, and a single-shard Windows listing plan never grows (GST-3440)', () => {+ expect(parseCliOptions(['--windows-only', '--ci-plan', 'p.json', '--shard-budget-seconds', '720']).shardBudgetSeconds).toBe(720);+ expect(parseCliOptions(['--windows-only', '--ci-plan', 'p.json']).shardBudgetSeconds).toBeUndefined();+ expect(() => parseCliOptions(['--ci-plan', 'p.json', '--shard-budget-seconds', '720'])).toThrow('--shard-budget-seconds applies only to --windows-only --ci-plan');+ for (const bad of ['0', 'x', '1.5']) expect(() => parseCliOptions(['--windows-only', '--ci-plan', 'p.json', '--shard-budget-seconds', bad])).toThrow('--shard-budget-seconds needs');+ const files = ['a.test.ts', 'b.test.ts', 'c.test.ts', 'd.test.ts'];+ const durations = { 'a.test.ts': 400, 'b.test.ts': 400, 'c.test.ts': 400, 'd.test.ts': 400 };+ expect(createWindowsCiPlan(files, 1, 800, durations, 'rev').shards.map(shard => shard.predictedMs)).toEqual([800, 800]);+ expect(() => createWindowsCiPlan(files, 1, 300, durations, 'rev')).toThrow('No Windows plan of 1 to 2 shards keeps every shard within 0.3 s');+});+test('a Windows CI plan binds the curated file set, so it never verifies as the full Linux suite', () => {for (const argv of [['--windows-only', '--ci-plan', 'p.json'], ['--windows-only', '--ci-run', 'p.json', '--shard', '1', '--result', 'r.json'], ['--windows-only', '--ci-verify', 'p.json', '--results', 'd']]) {expect(parseCliOptions(argv).windowsOnly).toBe(true);