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
test(land): cover lost group identities [Q1,Q3,C7]
Corey Olsonb5ed0c5f285b
diff --git a/src/landing-worker.js b/src/landing-worker.jsindex 66a9c346..4e7a2da1 100644--- a/src/landing-worker.js+++ b/src/landing-worker.js@@ -30,10 +30,10 @@ function census() {} catch { return null; }}-/** Stop a currently owned group; a recorded worker identity permits cleanup after guardian death without trusting a reused PID. */-function stop(child, member) {+/** Stop owned descendants and their group; optional observers exercise census races without signaling foreign processes. */+export function stop(child, member, { read = census, kill = process.kill } = {}) {if (!child.pid) return;- const rows = census();+ const rows = read();const root = rows?.get(child.pid);const known = member && rows?.get(member.pid);const ownsRoot = root && (child.pid === process.pid || root.ppid === process.pid && child.exitCode === null && child.signalCode === null);@@ -46,20 +46,20 @@ function stop(child, member) {changed = false;for (const row of rows.values()) if (owned.has(row.ppid) && !owned.has(row.pid)) { owned.add(row.pid); changed = true; }} while (changed);- const current = census();+ const current = read();if (!current) return; // Missing identity evidence never authorizes a process-group signal.// Stop producers first: killing a held gate must not wake its worker into post-gate Git work.for (const pid of owned) if (pid !== child.pid && !current.get(pid)?.state.startsWith('Z') && current.get(pid)?.started === rows.get(pid)?.started&& current.get(pid)?.processSha256 === rows.get(pid)?.processSha256) {- try { process.kill(pid, 'SIGKILL'); } catch (error) { if (error.code !== 'ESRCH') throw error; }+ try { kill(pid, 'SIGKILL'); } catch (error) { if (error.code !== 'ESRCH') throw error; }}// Descendant signals can empty the group; its earlier census is no longer a signal target.- const group = census();+ const group = read();if (!group || !runningGroup(group, child.pid)) return;- try { process.kill(-child.pid, 'SIGKILL'); }+ try { kill(-child.pid, 'SIGKILL'); }catch (error) {if (error.code === 'ESRCH') return;- const after = error.code === 'EPERM' ? census() : null;+ const after = error.code === 'EPERM' ? read() : null;if (after && !runningGroup(after, child.pid)) return; // macOS can report EPERM for an already-empty group.throw error; // A live group or unknown census never licenses suppressing a permission failure.}diff --git a/test/land-marker-fixture.js b/test/land-marker-fixture.jsnew file mode 100644index 00000000..4c26e4a7--- /dev/null+++ b/test/land-marker-fixture.js@@ -0,0 +1,14 @@+/** Shared marker observations for the real landing fixtures [B3,R3]. */+import { readFileSync } from 'node:fs';++export const MARKER_NOT_YET = Symbol('marker not yet written');++/** Read a complete marker, treating a missing or mid-write file as unpublished. */+export function readMarker(file) {+ try { return JSON.parse(readFileSync(file, 'utf8')); }+ catch (error) {+ if (error.code === 'ENOENT' || error instanceof SyntaxError) return MARKER_NOT_YET;+ throw error;+ }+}+diff --git a/test/land-stop-fixture.js b/test/land-stop-fixture.jsnew file mode 100644index 00000000..fab41d4a--- /dev/null+++ b/test/land-stop-fixture.js@@ -0,0 +1,76 @@+/** Exercise real landing-stop decisions against controlled observations and a private live child [Q1,Q3,C7]. */+import assert from 'node:assert/strict';+import { once } from 'node:events';+import { stop } from '../src/landing-worker.js';+import { startFixtureChild } from './fixture-child.js';++const GROUP = 41001;++/** One observer row; these synthetic PIDs are never passed to a real signal function. */+function row(pid, changes = {}) {+ return { pid, ppid: GROUP, pgid: GROUP, started: 'Fri Oct 23 16:00:00 2026',+ processSha256: 'a'.repeat(64), state: 'S', ...changes };+}++/** A process census with the same indexed shape as the real ps observer. */+function censusRows(...rows) { return new Map(rows.map(entry => [entry.pid, entry])); }++/** Run the actual stop implementation; all signals here go only to a recording observer. */+function observedStop(finalRows) {+ const original = censusRows(row(GROUP, { ppid: process.pid }), row(GROUP + 1));+ const snapshots = [original, original, finalRows];+ const signals = [];+ const logs = [];+ stop({ pid: GROUP, exitCode: null, signalCode: null }, undefined, {+ read: () => { assert.ok(snapshots.length, 'the stop never invents another observation'); return snapshots.shift(); },+ kill: (pid, signal) => signals.push([pid, signal]),+ log: text => logs.push(text),+ });+ assert.equal(snapshots.length, 0);+ return { signals, logs };+}++/** Missing original identity evidence never licenses a group broadcast; a known live group still stops. */+export async function assertLandingStopIdentity() {+ const foreign = row(GROUP + 9, { ppid: 1, started: 'Fri Oct 23 16:01:00 2026', processSha256: 'b'.repeat(64) });+ const outcomes = [+ observedStop(censusRows(foreign)),+ observedStop(censusRows(foreign, row(GROUP, { started: foreign.started }))),+ observedStop(censusRows(foreign, row(GROUP, { processSha256: foreign.processSha256 }))),+ observedStop(censusRows(foreign, row(GROUP, { pgid: GROUP + 10 }))),+ observedStop(censusRows(foreign, row(GROUP, { state: 'Z' }))),+ observedStop(null),+ ];+ for (const outcome of outcomes) {+ assert.deepEqual(outcome.signals, [[GROUP + 1, 'SIGKILL']], 'a group with no original live witness receives no negative-PGID signal');+ assert.match(outcome.logs.join('\n'), /skipp.*(?:identity|census|witness)/iu, 'the missing attribution is explained, not claimed drained or proven reused');+ }+ const original = observedStop(censusRows(row(GROUP, { ppid: 1 })));+ assert.deepEqual(original.signals, [[GROUP + 1, 'SIGKILL'], [-GROUP, 'SIGKILL']], 'reparenting keeps a matching original identity valid');+ assert.deepEqual(original.logs, []);+ await stopPrivateChild();+}++/** A fresh, handshaken detached child proves the real observer and real signal path still clean up owned work. */+async function stopPrivateChild() {+ const child = startFixtureChild(process.execPath, ['-e', "process.send('ready'); setInterval(() => {}, 1000);"], {+ detached: true, stdio: ['ignore', 'ignore', 'pipe', 'ipc'],+ });+ // budget: private cleanup must finish within ten seconds, including the ready handshake.+ const deadline = AbortSignal.timeout(10_000);+ const closed = once(child, 'close', { signal: deadline });+ void closed.catch(() => { /* The ready await reports a spawn error before close is awaited. */ });+ try {+ const [message] = await once(child, 'message', { signal: deadline });+ assert.equal(message, 'ready');+ stop(child);+ const [, signal] = await closed;+ assert.equal(signal, 'SIGKILL', 'the real owned process group is stopped');+ } finally {+ if (child.exitCode === null && child.signalCode === null) {+ const cleanup = once(child, 'close');+ child.kill('SIGKILL');+ await cleanup;+ }+ }+}diff --git a/test/land.test.js b/test/land.test.jsindex c00aaa9b..6e3a8cf6 100644--- a/test/land.test.js+++ b/test/land.test.js@@ -10,26 +10,22 @@ import { landingFailures, landingSubject } from '../src/land.js';import { createE2eHelpers } from './e2e-helpers.js';import { startFixtureChild, runFixtureChild } from './fixture-child.js';import { assertNoRemoteLanding } from './land-no-remote-fixture.js';+import { MARKER_NOT_YET, readMarker } from './land-marker-fixture.js';+import { assertLandingStopIdentity } from './land-stop-fixture.js';const e2e = createE2eHelpers();after(e2e.cleanup);const { sandbox, project, commitFile, waitFor, BIN } = e2e;const FILES = [1, 2, 3, 4].map((n) => `web/land-${n}.test.js`);-const MARKER_NOT_YET = Symbol('marker not yet written');++test('a landing stop never signals a reused process group [Q1,Q3,C7]', async () => {+ await assertLandingStopIdentity();+});test('a repo with no remote lands into the local trunk and status reads as normal [I1,B3,R3,H5]', () => {assertNoRemoteLanding(sandbox, commitFile);});-/** Read a complete marker, treating a missing or mid-write file as unpublished. */-function readMarker(file) {- try { return JSON.parse(readFileSync(file, 'utf8')); }- catch (error) {- if (error.code === 'ENOENT' || error instanceof SyntaxError) return MARKER_NOT_YET;- throw error;- }-}-/** Read a private board through public functions, never by mutating its database. */function onBoard(box, action, clock) {const board = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'), clock);