diff --git a/packages/client/ui-theme/tests/stylesheet-scan.client.spec.ts b/packages/client/ui-theme/tests/stylesheet-scan.client.spec.ts new file mode 100644 index 0000000000..e65cb1a16a --- /dev/null +++ b/packages/client/ui-theme/tests/stylesheet-scan.client.spec.ts @@ -0,0 +1,32 @@ +/** Tests for the package-tree scan helpers that the stylesheet contracts range over. */ +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { afterEach, expect, it } from 'vitest' +import { packageFiles } from './stylesheet-scan.ts' + +const roots: string[] = [] + +afterEach(() => { + for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) +}) + +it('skips dot directories holding transient roots', () => { + const root = mkdtempSync(join(tmpdir(), 'dsh-stylesheet-scan-')) + roots.push(root) + mkdirSync(join(root, 'pkg', 'nested'), { recursive: true }) + writeFileSync(join(root, 'pkg', 'package.json'), '{}') + writeFileSync(join(root, 'pkg', 'nested', 'package.json'), '{}') + mkdirSync(join(root, '.typert-worker-failure-probe')) + writeFileSync(join(root, '.typert-worker-failure-probe', 'package.json'), '{}') + + // The helper reports `/`-separated paths on every platform, so the Windows + // temporary root's separators must not reach the expectation. Traversal + // reports the nested manifest before its parent, and directory order is not + // guaranteed, so both sides are compared sorted. + const normalized = root.replaceAll('\\', '/') + expect(packageFiles(name => name === 'package.json', root).sort()).toEqual([ + `${normalized}/pkg/nested/package.json`, + `${normalized}/pkg/package.json`, + ]) +}) diff --git a/packages/client/ui-theme/tests/stylesheet-scan.ts b/packages/client/ui-theme/tests/stylesheet-scan.ts index 91311945bf..ce796bc62c 100644 --- a/packages/client/ui-theme/tests/stylesheet-scan.ts +++ b/packages/client/ui-theme/tests/stylesheet-scan.ts @@ -73,22 +73,28 @@ export function varReferences(value: string): string[] { /** * Every file shipped as package source whose name the predicate accepts, - * excluding build output and installed dependencies. + * excluding build output, installed dependencies, and dot directories. + * Dot directories hold VCS metadata and per-test temporary roots rather than + * shipped source, and their owner can remove one while a scan reads it. * @param accepts - filename predicate. - * @returns absolute paths under packages/, `/`-separated on every platform so + * @param root - tree to walk, the packages directory by default. + * @returns absolute paths under `root`, `/`-separated on every platform so * specs can match repo-relative suffixes verbatim. */ -export function packageFiles(accepts: (name: string) => boolean): string[] { +export function packageFiles(accepts: (name: string) => boolean, root: string = PACKAGES_DIR): string[] { const found: string[] = [] const walk = (dir: string): void => { for (const entry of readdirSync(dir, { withFileTypes: true })) { const path = join(dir, entry.name) if (entry.isDirectory()) { - if (entry.name !== 'node_modules' && entry.name !== 'lib' && entry.name !== 'dist') walk(path) + // Dot directories hold VCS metadata and the temporary roots each spec + // creates inside the package tree, never shipped package source; a + // concurrent owner can remove one while a scan reads it. + if (!entry.name.startsWith('.') && entry.name !== 'node_modules' && entry.name !== 'lib' && entry.name !== 'dist') walk(path) } else if (accepts(entry.name)) found.push(path.replaceAll('\\', '/')) } } - walk(PACKAGES_DIR) + walk(root) return found } diff --git a/scripts/run-gates.spec.ts b/scripts/run-gates.spec.ts index dd6d7cf536..89458b4d2b 100644 --- a/scripts/run-gates.spec.ts +++ b/scripts/run-gates.spec.ts @@ -1,4 +1,6 @@ -import { readFileSync } from 'node:fs' +import { mkdtempSync, readFileSync, rmSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi, type MockInstance } from 'vitest' import { cliGateOptions, @@ -9,6 +11,7 @@ import { gatesForMode, parsePidPpidLines, runGate, + runGateWithRetry, runGates, taskkillArgs, type Gate, @@ -617,6 +620,8 @@ describe('gate graph validation', () => { command: process.execPath, args: ['/private/pnpm.cjs', '--filter', '@deepseek-ai/dsh-desktop', 'exec', 'install-electron'], env: { ELECTRON_GET_USE_PROXY: '1' }, + retries: 2, + retryDelayMs: 15000, }) expect(gates.find(gate => gate.id === 'built-bin-smoke')?.needs).toContain('electron-install') expect(gates.filter(gate => gate.id !== 'electron-install').every(gate => gate.env?.ELECTRON_GET_USE_PROXY === undefined)).toBe(true) @@ -1068,6 +1073,62 @@ describe('gate process outcomes', () => { }) }) +describe('gate retries', () => { + it('runs a gate that declares no retries exactly once', async () => { + const subject = gate('single') + const execute = vi.fn(async () => resultFor(subject, 'passed')) + + const result = await runGateWithRetry(subject, undefined, execute) + + expect(execute).toHaveBeenCalledTimes(1) + expect(result).toMatchObject({ status: 'passed', exitCode: 0 }) + }) + + it('repeats a failed gate until a later attempt passes', async () => { + const directory = mkdtempSync(join(tmpdir(), 'run-gates-retry-')) + onTestFinished(() => { rmSync(directory, { recursive: true, force: true }) }) + const marker = join(directory, 'attempts') + const result = await runGateWithRetry(gate('fetch', { + args: ['-e', [ + "const fs = require('node:fs')", + `const marker = ${JSON.stringify(marker)}`, + "const attempts = fs.existsSync(marker) ? Number(fs.readFileSync(marker, 'utf8')) + 1 : 1", + 'fs.writeFileSync(marker, String(attempts))', + 'if (attempts === 1) process.exit(1)', + ].join(';')], + // One attempt remains unused after the second attempt passes, so the + // loop also exercises its status check rather than only its attempt cap. + retries: 2, + retryDelayMs: 0, + })) + + expect(result).toMatchObject({ status: 'passed', exitCode: 0 }) + expect(readFileSync(marker, 'utf8')).toBe('2') + }) + + it('stops at the declared attempt count and keeps the last failure', async () => { + const subject = gate('fetch', { retries: 2 }) + const execute = vi.fn(async () => resultFor(subject, 'failed')) + + const result = await runGateWithRetry(subject, undefined, execute) + + expect(execute).toHaveBeenCalledTimes(3) + expect(result).toMatchObject({ status: 'failed', exitCode: 1 }) + }) + + it('does not repeat a gate that the fail-fast signal terminated', async () => { + const controller = new AbortController() + controller.abort() + const subject = gate('fetch', { retries: 2, retryDelayMs: 0 }) + const execute = vi.fn(async () => ({ ...resultFor(subject, 'failed'), aborted: true })) + + const result = await runGateWithRetry(subject, controller.signal, execute) + + expect(execute).toHaveBeenCalledTimes(1) + expect(result).toMatchObject({ status: 'failed', aborted: true }) + }) +}) + describe('fail-fast scheduling', () => { it('aborts the aggregate at the first blocking failure', async () => { const slow = gate('slow') diff --git a/scripts/run-gates.ts b/scripts/run-gates.ts index 6caa503c79..782ed05639 100644 --- a/scripts/run-gates.ts +++ b/scripts/run-gates.ts @@ -55,6 +55,10 @@ export interface Gate { quick?: boolean /** Keep a failure visible without failing the aggregate. */ allowFailure?: boolean + /** Extra attempts after a failed run, for a gate whose failure can come from one remote fetch. */ + retries?: number + /** Wait before each retry, in milliseconds; default 0. */ + retryDelayMs?: number /** Write child output as it arrives instead of buffering it until completion. */ streamOutput?: boolean } @@ -133,7 +137,7 @@ export async function runAggregate(name: string, gates: Gate[], concurrencyDefau const startedAt = performance.now() console.log(`run-gates: ${name} running ${gates.length} gate(s) with ${maxConcurrency} worker(s) from ${concurrencySource}${failFast ? ', fail-fast after first blocking failure' : ''}.`) - const results = await runGates(gates, maxConcurrency, runGate, printResult, cliGateOptions(failFast)) + const results = await runGates(gates, maxConcurrency, runGateWithRetry, printResult, cliGateOptions(failFast)) printSummary(results, performance.now() - startedAt) return results.some(result => result.gate.allowFailure !== true && (result.status === 'failed' || result.status === 'skipped')) ? 1 @@ -628,6 +632,14 @@ function ciWindowsCompleteGates(): Gate[] { } // Native Electron fixtures need the locked binary before Vitest removes ambient proxies. +// +// The installer fetches the 100 MB Electron release archive through the runner +// proxy, and one gateway timeout there fails the required Windows coverage lane +// before any test runs. On 2026-11-09 four jobs on three branches stopped at +// `504 (Gateway Time-out)` for that URL after ~12 s, while other jobs fetched +// the same archive minutes later (2.5 s from a warm cache, 14.7 s cold), so the +// fetch gets three attempts instead of one. The wait outlasts the observed +// gateway timeout, after which a fresh connection can reach the archive. function electronInstallGate(): Gate { return { id: 'electron-install', @@ -635,6 +647,8 @@ function electronInstallGate(): Gate { displayCommand: 'pnpm --filter @deepseek-ai/dsh-desktop exec install-electron', ...pnpmInvocation(['--filter', '@deepseek-ai/dsh-desktop', 'exec', 'install-electron']), env: { ELECTRON_GET_USE_PROXY: '1' }, + retries: 2, + retryDelayMs: 15000, } } @@ -1409,6 +1423,36 @@ export async function runGate(gate: Gate, signal?: AbortSignal): Promise { + const started = performance.now() + const attempts = 1 + Math.max(0, gate.retries ?? 0) + let result = await execute(gate, signal) + for (let attempt = 2; attempt <= attempts && result.status === 'failed' && signal?.aborted !== true; attempt++) { + const delayMs = Math.max(0, gate.retryDelayMs ?? 0) + console.log(`run-gates: retrying ${gate.label} (attempt ${String(attempt)} of ${String(attempts)}) in ${String(delayMs)} ms`) + await new Promise(resolve => setTimeout(resolve, delayMs)) + result = await execute(gate, signal) + } + return { ...result, durationMs: performance.now() - started } +} + /** * Parse the state, parent, and process-group fields from a `/proc//stat` * line. The comm field may contain spaces and parentheses, so the state starts