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(resources): gate browser-free checks on machine setting [O5,O6,C7]

Corey Olson98a64f6f42b7
diff --git a/test/resources.test.js b/test/resources.test.js
index 7f12cd90..a1aafa5e 100644
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@ -283,6 +283,14 @@ function configureBrowserSlots(box, slots) {
});
}
+/** Set or remove the opt-in browser-free-check policy in a fixture's machine settings. */
+function setBrowserFreeChecks(box, value) {
+ const file = join(box.home, 'settings.json');
+ if (value === undefined) { rmSync(file, { force: true }); return; }
+ mkdirSync(box.home, { recursive: true });
+ writeFileSync(file, `${JSON.stringify({ gate: { browserFreeChecks: value } }, null, 2)}\n`);
+}
+
/** Read the next worker event, failing promptly with its stderr if it exits unexpectedly. */
async function event(child, timeoutMs = 10_000) {
if (child.pendingLines.length) return JSON.parse(child.pendingLines.shift());
@@ -402,6 +410,7 @@ test('single-quoted named-test checks skip the browser slot [C7]', async () => {
test('a non-browser check does not wait for the browser slot [C7]', async () => {
const box = fixture();
+ setBrowserFreeChecks(box, true);
const { repo, base } = checkProject(box);
const itemCheck = 'node bin/run-tests.js --test-name-pattern "item check marker" test/cpu-check.test.js';
const submitCheck = 'node bin/run-tests.js --test-name-pattern "submit check marker" test/cpu-check.test.js';
@@ -452,6 +461,48 @@ test('a non-browser check does not wait for the browser slot [C7]', async () =>
}, submitResult.stderr);
});
+test('browser-free checks skip the slot only when the machine allows it [C7]', async () => {
+ const box = fixture();
+ const { repo } = checkProject(box);
+ const check = `out=$(node bin/run-tests.js --test-name-pattern "item check marker" test/cpu-check.test.js 2>&1); printf '%s\\n' "$out"; printf '%s\\n' "$out" | grep -Eq '^[[:space:]]*ok [0-9]+ - item check marker' && printf '%s\\n' "$out" | grep -Eq '^# fail 0$'`;
+ const added = runFixtureChild(process.execPath, [BIN, 'add', 'coordinator', 'Browser-free policy check', '--check', check, '--wait', '--json'], {
+ cwd: repo, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(added.status, 0, added.stderr);
+ const item = JSON.parse(added.stdout).item.item_id;
+ const marker = join(repo, 'item-check-started');
+
+ async function checkWithPolicy(value, shouldStartWithBrowserHeld) {
+ setBrowserFreeChecks(box, value);
+ rmSync(marker, { force: true });
+ const browserHolder = poolWorker(box, { agent: `policy-browser-${String(value)}`, browser: true, item: '681', kind: 'gate' });
+ await acquired(browserHolder);
+ const started = waitForMarker(marker);
+ const resultPromise = runFixtureChildAsync(process.execPath, [BIN, 'check', String(item), '--yes'], { cwd: repo, env: box.env });
+ let result;
+ try {
+ if (shouldStartWithBrowserHeld) {
+ await started;
+ assert.ok(privateList(box).find(({ name }) => name === 'browser')?.holders.some(({ agent }) => agent === `policy-browser-${String(value)}`),
+ 'the browser lease stays live while an opted-in browser-free check runs');
+ } else {
+ await waitUntil(() => privateList(box).find(({ name }) => name === 'gate')?.line.some(({ kind, item: waitingItem }) => kind === 'check' && waitingItem === String(item)),
+ 'a browser-disabled check to wait in the gate queue');
+ assert.equal(existsSync(marker), false, 'the check does not start while browser-free checks are disabled or absent');
+ }
+ } finally {
+ await release(browserHolder);
+ result = await resultPromise;
+ }
+ assert.equal(result.status, 0, result.failure ?? result.stderr);
+ assert.equal(readFileSync(marker, 'utf8'), 'started');
+ }
+
+ await checkWithPolicy(false, false);
+ await checkWithPolicy(true, true);
+ await checkWithPolicy(undefined, false);
+});
+
/** Kill and reap every fixture worker before deleting its private files. */
after(async () => {
const running = [...CHILDREN];