Skip to content

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.

test(sentinel): prove resume defers checks to explicit run [N26]

Corey Olsond3f03dbfaa15
diff --git a/test/sentinels.test.js b/test/sentinels.test.js
index 08d1827c..a04b8eae 100644
--- a/test/sentinels.test.js
+++ b/test/sentinels.test.js
@@ -69,9 +69,9 @@ function fixture(t) {
assert.equal(receipt.error, undefined, JSON.stringify(receipt)); return receipt.result;
};
/** Run the actual CLI against this real board; view means the explicit test person adapter. */
- const cli = async (args, personChannel) => {
+ const cli = async (args, personChannel, cwd = root) => {
let output = ''; let error = '';
- const code = await main([...args, '--json'], { cwd: root, clock, personChannel,
+ const code = await main([...args, '--json'], { cwd, clock, personChannel,
stdout: { isTTY: false, write: text => { output += text; } }, stderr: { write: text => { error += text; } } });
return { code, document: output ? JSON.parse(output) : null, error };
};
@@ -119,6 +119,55 @@ function repeatedCause(box) {
return { red, green, items, check: 'test -f up.txt' };
}
+test('resume never runs a sentinel and sentinel run runs the due ones [N26,A6,D3]', async t => {
+ const box = fixture(t);
+ const marker = join(box.directory, 'explicit-run.json');
+ writeFileSync(join(box.root, 'value.txt'), 'committed trunk input');
+ writeFileSync(join(box.root, 'slow-check.mjs'), `import {readFileSync,writeFileSync} from 'node:fs';
+import {setTimeout} from 'node:timers/promises';
+const value=readFileSync('value.txt','utf8');
+writeFileSync(${JSON.stringify(marker)},JSON.stringify({cwd:process.cwd(),value}));
+await setTimeout(30_000);
+console.log('explicit trunk receipt: '+value);
+`);
+ runFixtureGit(['add', 'slow-check.mjs', 'value.txt'], { cwd: box.root, env: box.env });
+ runFixtureGit(['commit', '-q', '-m', 'test: committed sentinel input [N26,A6]'], { cwd: box.root, env: box.env });
+ const agentRoot = join(box.directory, 'agent');
+ runFixtureGit(['worktree', 'add', '--quiet', '--detach', agentRoot, 'main'], { cwd: box.root, env: box.env });
+ const joined = await box.cli(['join', 'core', '--model', 'gpt-6.1-sol', '--route', 'mid'], undefined, agentRoot);
+ assert.equal(joined.code, 0, joined.error);
+ writeFileSync(join(agentRoot, 'value.txt'), 'uncommitted agent input');
+ const command = `${quote(process.execPath)} slow-check.mjs`;
+ assert.equal((await box.cli(['sentinel', 'propose', 'slow-trunk', '--check', command, '--every', 'hourly', '--owner', box.agent, '--timeout', '35000'])).code, 0);
+ assert.equal((await box.cli(['sentinel', 'approve', 'slow-trunk'], 'view')).code, 0);
+
+ // The frozen bar measures ordinary in-process handling after setup, not module loading or cold CLI startup.
+ const began = performance.now();
+ const resumed = await box.cli(['resume'], undefined, agentRoot);
+ const elapsed = performance.now() - began;
+ assert.equal(resumed.code, 0, resumed.error);
+ assert.ok(elapsed < 100, `resume took ${elapsed.toFixed(3)} ms with a due 30 s sentinel`);
+ assert.equal(existsSync(marker), false, 'resume neither runs the watch nor detaches a checker into the agent session');
+ assert.equal(sentinels(box.board)[0].lastRun, null);
+ assert.equal(store.events(box.board).some(row => row.event_kind === 'sentinel-start'), false);
+
+ const run = await box.cli(['sentinel', 'run'], undefined, agentRoot);
+ assert.equal(run.code, 0, run.error);
+ const executed = JSON.parse(readFileSync(marker, 'utf8'));
+ assert.notEqual(executed.cwd, agentRoot, 'the explicit runner never uses the agent checkout');
+ assert.notEqual(executed.cwd, box.root, 'the runner prepares a separate checkout rather than using live trunk');
+ assert.equal(executed.value, 'committed trunk input', 'the run reads trunk, not the dirty agent file');
+ assert.equal(existsSync(executed.cwd), false, 'the prepared checkout is cleaned after its owned check finishes');
+ const watched = sentinels(box.board)[0];
+ assert.equal(watched.lastRun.green, true);
+ assert.match(watched.lastRun.output, /explicit trunk receipt: committed trunk input/u);
+ assert.equal(watched.check, command, 'the approved command is not rewritten for the new execution directory');
+ assert.equal(readFileSync(join(agentRoot, 'value.txt'), 'utf8'), 'uncommitted agent input');
+ const help = await box.cli(['sentinel', 'run', '--help']);
+ assert.equal(help.code, 0, help.error);
+ assert.match(JSON.stringify(help.document), /cron|scheduled CI/iu);
+});
+
test('a repeated cause can be drafted as a sentinel [A6,D1,D3]', async t => {
const box = fixture(t);
const cause = repeatedCause(box);