Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(test): avoid release archive pipe races [C7]
Corey Olson8a54f5616fcf
diff --git a/test/engine.test.js b/test/engine.test.jsindex b3b02778..40b4dce7 100644--- a/test/engine.test.js+++ b/test/engine.test.js@@ -1,9 +1,8 @@/** Real-SQLite tests for the deterministic, sequence-ordered move engine [H3,H16]. */import assert from 'node:assert/strict';-import { runFixtureExecFile as execFileSync } from './fixture-child.js';import { mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';-import { join, resolve } from 'node:path';+import { join } from 'node:path';import { pathToFileURL } from 'node:url';import { test } from 'node:test';import * as store from '../src/board.js';@@ -11,6 +10,7 @@ import { exportBoard, importBoard, restoreRelaySnapshot } from '../src/exchange.import { applyEngineMove, applyRelayMove, prepareEngineMove, appliedSequence, engineReceipt, refuseRelayMove, startRelayEpoch, checkpointSequence, ENGINE_OPERATIONS } from '../src/engine.js';import { ENGINE_VERSION } from '../src/machine.js';import { Refused } from '../src/refused.js';+import { unpackRelease } from './release-archive.js';const HOUR = 3_600_000;const CLAIM_AT = '2026-10-07T18:00:00.000Z';@@ -297,8 +297,7 @@ test('fallback refusal identity hashes operation arguments when no ciphertext ditest('released engine 3 stops a background completion before changing rows or its cursor [V2,H16]', async t => {const { directory, copies, item } = engineCopies(t);- const archive = execFileSync('git', ['archive', 'v0.8.1'], { cwd: resolve(import.meta.dirname, '..'), maxBuffer: 32 * 1024 * 1024 });- execFileSync('tar', ['-x', '-C', directory], { input: archive });+ unpackRelease('v0.8.1', directory);const released = await import(pathToFileURL(join(directory, 'src/engine.js')).href);const releasedMachine = await import(pathToFileURL(join(directory, 'src/machine.js')).href);assert.equal(releasedMachine.ENGINE_VERSION, 3, 'exercise the actual released client');@@ -332,8 +331,7 @@ test('released engine 3 stops a background completion before changing rows or ittest('an engine 6 client meets an item hold and is told to upgrade [H16,M1]', async t => {const { directory, copies, item } = engineCopies(t);- const archive = execFileSync('git', ['archive', 'v0.8.3'], { cwd: resolve(import.meta.dirname, '..'), maxBuffer: 32 * 1024 * 1024 });- execFileSync('tar', ['-x', '-C', directory], { input: archive });+ unpackRelease('v0.8.3', directory);const released = await import(pathToFileURL(join(directory, 'src/engine.js')).href);const releasedMachine = await import(pathToFileURL(join(directory, 'src/machine.js')).href);assert.equal(releasedMachine.ENGINE_VERSION, 6, 'exercise the actual 0.8.3 client');diff --git a/test/merged.test.js b/test/merged.test.jsindex 949956b9..20d11481 100644--- a/test/merged.test.js+++ b/test/merged.test.js@@ -10,6 +10,7 @@ import { pathToFileURL } from 'node:url';import * as store from '../src/board.js';import { applyEngineMove, prepareEngineMove } from '../src/engine.js';import { exportBoard } from '../src/exchange.js';+import { unpackRelease } from './release-archive.js';const TEMP_DIRS = [];const HOUR = 3_600_000;@@ -149,8 +150,7 @@ test('[R3,H16] a released client stops before losing an exceptional merged note'const box = await fixture(t);const directory = join(box.dir, 'released');mkdirSync(directory);- const archive = execFileSync('git', ['archive', 'v0.8.3'], { cwd: resolve(import.meta.dirname, '..'), maxBuffer: 32 * 1024 * 1024 });- execFileSync('tar', ['-x', '-C', directory], { input: archive });+ unpackRelease('v0.8.3', directory);const released = await import(pathToFileURL(join(directory, 'src/engine.js')).href);const machine = await import(pathToFileURL(join(directory, 'src/machine.js')).href);assert.equal(machine.ENGINE_VERSION, 6, 'exercise the actual released client');diff --git a/test/release-archive.js b/test/release-archive.jsnew file mode 100644index 00000000..6b9978d2--- /dev/null+++ b/test/release-archive.js@@ -0,0 +1,32 @@+/** Extract a tagged release without racing a short-reading tar process [C7]. */+import { spawnSync } from 'node:child_process';+import { randomUUID } from 'node:crypto';+import { rmSync } from 'node:fs';+import { basename, dirname, join, resolve } from 'node:path';++const REPOSITORY = resolve(import.meta.dirname, '..');++/**+ * Archive a tag to a file, then ask tar to read that file so an early tar exit cannot break Git's pipe.+ *+ * @param {string} tag+ * @param {string} directory+ * @returns {void}+ */+export function unpackRelease(tag, directory) {+ const archive = join(dirname(directory), `${basename(directory)}-${randomUUID()}.tar`);+ try {+ const created = spawnSync('git', ['archive', `--output=${archive}`, tag], {+ cwd: REPOSITORY, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024,+ });+ if (created.status !== 0 || created.error) {+ throw new Error(`git archive ${tag} failed for ${directory}: status ${created.status}; ${created.stderr || created.error?.message || ''}`);+ }+ const extracted = spawnSync('tar', ['-x', '-f', archive, '-C', directory], { encoding: 'utf8' });+ if (extracted.status !== 0 || extracted.error) {+ throw new Error(`tar failed to unpack ${tag} into ${directory}: status ${extracted.status}; stderr: ${extracted.stderr || extracted.error?.message || ''}`);+ }+ } finally {+ rmSync(archive, { force: true });+ }+}diff --git a/test/release-archive.test.js b/test/release-archive.test.jsnew file mode 100644index 00000000..36a6b514--- /dev/null+++ b/test/release-archive.test.js@@ -0,0 +1,62 @@+/** The released-source extraction helper tolerates tar stopping its stdin early [C7]. */+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { delimiter, join, resolve } from 'node:path';+import { tmpdir } from 'node:os';+import { test } from 'node:test';+import { unpackRelease } from './release-archive.js';++const ROOT = resolve(import.meta.dirname, '..');++test('an old release unpacks even when tar stops reading early [C7]', t => {+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-release-archive-'));+ const stub = join(directory, 'bin');+ const extracted = join(directory, 'actual');+ const early = join(directory, 'early');+ mkdirSync(stub);+ mkdirSync(extracted);+ mkdirSync(early);+ t.after(() => rmSync(directory, { recursive: true, force: true }));+ const tar = join(stub, 'tar');+ writeFileSync(tar, '#!/bin/sh\nhead -c 512 >/dev/null\nexit 0\n', { mode: 0o700 });+ chmodSync(tar, 0o700);+ const archive = spawnSync('git', ['archive', 'v0.8.3'], { cwd: ROOT, maxBuffer: 32 * 1024 * 1024 });+ assert.equal(archive.status, 0, archive.stderr?.toString());+ assert.ok(archive.stdout.length > 512, 'the release archive exceeds the stand-in tar read limit');++ const oldPipeline = spawnSync('tar', ['-x', '-C', early], {+ cwd: ROOT, env: { ...process.env, PATH: `${stub}${delimiter}${process.env.PATH ?? ''}` },+ input: archive.stdout, encoding: 'utf8',+ });+ assert.equal(oldPipeline.error?.code, 'EPIPE', 'the stdin-piping form breaks when tar exits after one block');++ const path = process.env.PATH;+ process.env.PATH = `${stub}${delimiter}${path ?? ''}`;+ try {+ assert.doesNotThrow(() => unpackRelease('v0.8.3', extracted));+ } finally {+ if (path === undefined) delete process.env.PATH;+ else process.env.PATH = path;+ }++ writeFileSync(tar, '#!/bin/sh\necho controlled-tar-error >&2\nexit 7\n', { mode: 0o700 });+ process.env.PATH = `${stub}${delimiter}${path ?? ''}`;+ try {+ assert.throws(() => unpackRelease('v0.8.3', extracted), error => {+ assert.match(error.message, /v0\.8\.3/);+ assert.match(error.message, new RegExp(extracted.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')));+ assert.match(error.message, /status 7/);+ assert.match(error.message, /controlled-tar-error/);+ return true;+ }, 'tar failures identify the tag, destination, status and stderr');+ } finally {+ if (path === undefined) delete process.env.PATH;+ else process.env.PATH = path;+ }++ const realDirectory = join(directory, 'real-tar');+ mkdirSync(realDirectory);+ unpackRelease('v0.8.3', realDirectory);+ assert.equal(readFileSync(join(realDirectory, 'src', 'engine.js'), 'utf8').includes('ENGINE_VERSION'), true);+});diff --git a/test/reopen.test.js b/test/reopen.test.jsindex b28f471d..2f3ea0ba 100644--- a/test/reopen.test.js+++ b/test/reopen.test.js@@ -1,9 +1,8 @@/** Real Git, SQLite and ordered-engine coverage for coordinator criterion reopen [V2,V6,H16]. */import assert from 'node:assert/strict';-import { runFixtureExecFile as execFileSync } from './fixture-child.js';import { mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';-import { join, resolve } from 'node:path';+import { join } from 'node:path';import { pathToFileURL } from 'node:url';import { after, test } from 'node:test';import * as store from '../src/board.js';@@ -11,6 +10,7 @@ import { appliedSequence, applyRelayMove, engineReceipt, prepareEngineMove } froimport { exportBoard, importBoard } from '../src/exchange.js';import { ENGINE_VERSION } from '../src/machine.js';import { createE2eHelpers } from './e2e-helpers.js';+import { unpackRelease } from './release-archive.js';const e2e = createE2eHelpers();after(e2e.cleanup);@@ -128,10 +128,7 @@ test('a reopened item resubmits at a new head after a criterion edit [V2,V6,H16]const beforeOldReceiver = exportBoard(oldReceiver);const oldDirectory = mkdtempSync(join(tmpdir(), 'pullboard-engine-7-reopen-'));t.after(() => rmSync(oldDirectory, { recursive: true, force: true }));- const archive = execFileSync('git', ['archive', 'v0.8.4'], {- cwd: resolve(import.meta.dirname, '..'), maxBuffer: 32 * 1024 * 1024,- });- execFileSync('tar', ['-x', '-C', oldDirectory], { input: archive });+ unpackRelease('v0.8.4', oldDirectory);const oldEngine = await import(pathToFileURL(join(oldDirectory, 'src/engine.js')).href);const oldMachine = await import(pathToFileURL(join(oldDirectory, 'src/machine.js')).href);assert.equal(oldMachine.ENGINE_VERSION, 7, 'exercise the actual released engine-7 client');