Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: explain interrupted pregate stages (#12013)
Adam Eivya45a28fcbb34
diff --git a/scripts/pregate.js b/scripts/pregate.jsindex e36b664f4b..2ebd4a476f 100644--- a/scripts/pregate.js+++ b/scripts/pregate.js@@ -31,7 +31,9 @@* plan flagged so they are a decision rather than a surprise.*/-import { spawnSync } from 'child_process';+import { spawn, spawnSync } from 'child_process';+import { writeSync } from 'fs';+import { constants } from 'os';import { execFileSync } from 'child_process';import { dirname, join } from 'path';import { fileURLToPath } from 'url';@@ -247,7 +249,48 @@ export function parseArgs(argv) {return options;}-function main() {+/** Wait asynchronously so owner signals can be attributed during a stage. */+function runStage(stage) {+ return new Promise((resolve) => {+ const child = spawn(process.execPath, [join(REPO_ROOT, 'scripts', stage.script), ...stage.args], {+ cwd: REPO_ROOT,+ stdio: 'inherit',+ env: { ...pregateWorkerEnv(process.env), ...stage.env },+ // A separate group lets cancellation reach only this stage's descendants.+ detached: process.platform !== 'win32',+ });+ const handlers = new Map();+ const cleanup = () => {+ for (const [signal, handler] of handlers) process.removeListener(signal, handler);+ };+ for (const signal of ['SIGINT', 'SIGTERM']) {+ const handler = () => {+ // Flush before restoring the signal's default termination behavior.+ writeSync(2, `❌ Pregate incomplete: stage="${stage.name}" owner_pid=${process.pid} child_pid=${child.pid ?? 'unavailable'} received_signal=${signal}.\n`);+ cleanup();+ try {+ if (process.platform === 'win32') child.kill(signal);+ else if (child.pid) process.kill(-child.pid, signal);+ } catch (error) {+ if (error.code !== 'ESRCH') writeSync(2, `❌ Stage cancellation failed: ${error.code ?? 'unknown'}.\n`);+ }+ process.kill(process.pid, signal);+ };+ handlers.set(signal, handler);+ process.once(signal, handler);+ }+ child.once('error', (error) => {+ cleanup();+ resolve({ error });+ });+ child.once('close', (status, signal) => {+ cleanup();+ resolve({ status, signal, pid: child.pid });+ });+ });+}++async function main() {let options;try {options = parseArgs(process.argv.slice(2));@@ -345,15 +388,15 @@ function main() {for (const stage of stages) {console.log(`▶️ ${stage.name}`);- const result = spawnSync(process.execPath, [join(REPO_ROOT, 'scripts', stage.script), ...stage.args], {- cwd: REPO_ROOT,- stdio: 'inherit',- env: { ...pregateWorkerEnv(process.env), ...stage.env },- });+ const result = await runStage(stage);if (result.error) {console.error(`❌ ${stage.name} could not start: ${result.error.message}`);process.exit(1);}+ if (result.signal) {+ console.error(`❌ Pregate incomplete: stage="${stage.name}" owner_pid=${process.pid} child_pid=${result.pid} child_signal=${result.signal}.`);+ process.exit(constants.signals[result.signal] ? 128 + constants.signals[result.signal] : 1);+ }if (result.status !== 0) {console.error(`❌ ${stage.name} failed — fix it before pushing (CI would fail the same way).`);process.exit(result.status ?? 1);@@ -364,4 +407,9 @@ function main() {console.log(`✅ Pregate passed: ${stages.map((stage) => stage.name).join(', ')}${caveat}.`);}-if (isDirectlyInvoked(import.meta.url)) main();+if (isDirectlyInvoked(import.meta.url)) {+ main().catch((error) => {+ console.error(`❌ Pregate incomplete: ${error.message}`);+ process.exitCode = 1;+ });+}diff --git a/scripts/pregate.test.js b/scripts/pregate.test.jsindex 34064bf5ec..520f1cff41 100644--- a/scripts/pregate.test.js+++ b/scripts/pregate.test.js@@ -8,7 +8,7 @@* "CI will also run: db" from a plan field that has since been renamed.*/import { afterAll, afterEach, beforeAll, beforeEach, describe, it, expect } from 'vitest';-import { execFileSync, spawnSync } from 'child_process';+import { execFileSync, spawn, spawnSync } from 'child_process';import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';import { tmpdir } from 'os';import { cp } from 'fs/promises';@@ -187,6 +187,45 @@ describe('pregate hidden-content invocation', () => {},);+ // Only the fixture-owned scan process is signaled; no real test runner starts.+ it.skipIf(process.platform === 'win32')('attributes owner cancellation to its active stage and preserves SIGTERM', async () => {+ write('scripts/scan-diff-hidden-content.js', `+ console.log('fixture-stage-ready');+ setInterval(() => {}, 1000);+ `);+ const runner = spawn(process.execPath, ['scripts/pregate.js', '--base', base, '--skip-lint'], {+ cwd: root, stdio: ['ignore', 'pipe', 'pipe'],+ });+ let stdout = '';+ let stderr = '';+ runner.stderr.on('data', (data) => { stderr += data; });+ runner.stdout.on('data', (data) => {+ stdout += data;+ if (stdout.includes('fixture-stage-ready')) runner.kill('SIGTERM');+ });+ try {+ const result = await new Promise((resolve, reject) => {+ runner.once('error', reject);+ runner.once('close', (status, signal) => resolve({ status, signal }));+ });+ expect(result).toEqual({ status: null, signal: 'SIGTERM' });+ expect(stderr).toContain(`Pregate incomplete: stage="hidden-content scan" owner_pid=${runner.pid}`);+ expect(stderr).toMatch(/child_pid=\d+ received_signal=SIGTERM/);+ expect(stdout).not.toContain('Pregate passed');+ } finally {+ runner.kill('SIGKILL');+ }+ });++ it.skipIf(process.platform === 'win32')('reports a stage child signal as incomplete rather than an ordinary assertion failure', () => {+ write('scripts/scan-diff-hidden-content.js', "process.kill(process.pid, 'SIGTERM');\n");+ const result = run('--skip-lint');+ expect(result.status).toBe(143);+ expect(result.stderr).toMatch(/Pregate incomplete: stage="hidden-content scan" owner_pid=\d+ child_pid=\d+ child_signal=SIGTERM/);+ expect(result.stderr).not.toContain('failed — fix it');+ expect(result.stdout).not.toContain('Pregate passed');+ });+it('passes clean uncommitted changes even when the plan selects no lint or tests', () => {git('config', 'core.autocrlf', 'true');write(trackedPath, `${clean}staged\n`);