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.

fix: report unavailable detected gate [I1,I2]

Corey Olsone96fccffd34d
diff --git a/src/init.js b/src/init.js
index 8a5b1567..7c22c502 100644
--- a/src/init.js
+++ b/src/init.js
@@ -4,8 +4,8 @@
* the main checkout as the coordinator. It runs again safely and never overwrites a file it did not
* write.
*/
-import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
-import { basename, join } from 'node:path';
+import { accessSync, appendFileSync, constants as fsConstants, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
+import { delimiter, basename, join, resolve } from 'node:path';
import { CONFIG_FILE, COORDINATOR, doctrineFile, loadConfig } from './config.js';
import { loadDoctrine } from './doctrine.js';
import { installHooks } from './hooks.js';
@@ -38,6 +38,67 @@ export function detectGate(root) {
return '';
}
+/** Check whether a command can be found on PATH or in a named project environment without running it. */
+function gateCommandAvailable(root, command) {
+ /** Check one file without executing it or resolving arbitrary shell syntax. */
+ const executableFile = (file) => {
+ try {
+ const info = statSync(file);
+ if (!info.isFile()) return false;
+ if (process.platform === 'win32') return true;
+ accessSync(file, fsConstants.X_OK);
+ return true;
+ } catch {
+ return false;
+ }
+ };
+ /** Return platform command-name variants for a directory lookup. */
+ const commandFiles = (directory) => {
+ const base = join(directory, command);
+ if (process.platform !== 'win32' || /\.[^\\/]+$/u.test(command)) return [base];
+ return (process.env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD').split(';').map((extension) => `${base}${extension}`);
+ };
+ /** Check a PATH directory entry, using the process working directory for an empty entry. */
+ const onPath = (directory) => {
+ return commandFiles(directory || process.cwd()).some(executableFile);
+ };
+ if ((process.env.PATH ?? '').split(delimiter).some(onPath)) return true;
+
+ /** Check conventional executable directories inside a named environment. */
+ const hasEnvironmentCommand = (environment) => [
+ ...commandFiles(join(environment, 'bin')),
+ ...commandFiles(join(environment, 'Scripts')),
+ ].some(executableFile);
+
+ const environments = new Set([join(root, '.venv')]);
+ if (process.env.UV_PROJECT_ENVIRONMENT) {
+ const configured = process.env.UV_PROJECT_ENVIRONMENT;
+ environments.add(resolve(root, configured));
+ }
+ if (process.env.POETRY_ACTIVE && process.env.VIRTUAL_ENV) environments.add(process.env.VIRTUAL_ENV);
+ if ([...environments].some(hasEnvironmentCommand)) return true;
+ return false;
+}
+
+/** Describe a detected gate that init cannot resolve without executing it. */
+function missingGateNote(root, gate) {
+ if (!gate) return '';
+ const command = gate.trim().split(/\s+/u)[0];
+ if (gateCommandAvailable(root, command)) return '';
+ if (command === 'pytest') {
+ const hasPoetry = existsSync(join(root, 'poetry.lock'));
+ const hasUv = existsSync(join(root, 'uv.lock')) || Boolean(process.env.UV_PROJECT_ENVIRONMENT);
+ const searched = ['PATH', 'project `.venv`'];
+ if (process.env.UV_PROJECT_ENVIRONMENT) searched.push('configured uv environment');
+ if (process.env.POETRY_ACTIVE && process.env.VIRTUAL_ENV) searched.push('active Poetry environment');
+ const setupHint = hasUv ? 'run `uv sync` and activate its `.venv`'
+ : hasPoetry ? 'run `poetry install` and activate that environment'
+ : 'install pytest or activate the project `.venv`';
+ return `gate command "pytest" is not available on ${searched.join(', ')}; ${setupHint} before running it`;
+ }
+ return `gate command "${command}" is not available on PATH; install it before running the gate`;
+}
+
/**
* The fixers to start with (C5): prettier, when the repo already depends on it, on every file it
* understands. Only fast, deterministic fixers belong at commit time; slow ones stay in the gate.
@@ -198,6 +259,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {
const { root } = info;
const doctrine = existsSync(join(root, CONFIG_FILE)) ? loadConfig(root).practice : doctrineFile(root);
const gate = detectGate(root);
+ const configured = configuredGate(root);
const written = [];
/** Record only paths setup actually writes; unrelated files never enter its staging command. */
const onWrite = (path) => written.push(path);
@@ -211,6 +273,10 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {
...installSkills(root, onWrite),
writeSessionHook(root, onWrite),
];
+ if (gate && (!configured || configured === gate)) {
+ const gateNote = missingGateNote(root, gate);
+ if (gateNote) notes.push(gateNote);
+ }
const board = openBoardHere();
try {
register(board, { lane: COORDINATOR, path: root, model });
diff --git a/test/init-gate.test.js b/test/init-gate.test.js
new file mode 100644
index 00000000..9ec13f5e
--- /dev/null
+++ b/test/init-gate.test.js
@@ -0,0 +1,117 @@
+/** Check that init only resolves the detected gate executable and never runs it [I1, I2]. */
+import assert from 'node:assert/strict';
+import { accessSync, chmodSync, constants as fsConstants, existsSync, mkdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
+import { delimiter, join } from 'node:path';
+import { after, test } from 'node:test';
+import { createE2eHelpers } from './e2e-helpers.js';
+
+const e2e = createE2eHelpers();
+after(e2e.cleanup);
+
+/** Create a fresh git repository whose detected gate is pytest. */
+function pythonRepo(box, name) {
+ const root = join(box.dir, name);
+ mkdirSync(root);
+ box.git(root, 'init', '-q', '-b', 'main');
+ writeFileSync(join(root, 'pyproject.toml'), '[project]\nname = "gate-check-fixture"\n');
+ return root;
+}
+
+/** Keep git available while excluding unrelated host commands from this init process's PATH. */
+function isolatedPath(box, name = 'isolated-path') {
+ const source = (process.env.PATH ?? '').split(delimiter).map((directory) => join(directory, process.platform === 'win32' ? 'git.exe' : 'git'))
+ .find((file) => {
+ try {
+ const info = statSync(file);
+ if (!info.isFile()) return false;
+ accessSync(file, fsConstants.X_OK);
+ return true;
+ } catch {
+ return false;
+ }
+ });
+ assert.ok(source, 'the test runner has git available on its PATH');
+ const path = join(box.dir, name);
+ mkdirSync(path);
+ symlinkSync(source, join(path, process.platform === 'win32' ? 'git.exe' : 'git'));
+ box.env.PATH = path;
+ return path;
+}
+
+/** Write a harmless executable sentinel so the test can detect an accidental gate invocation. */
+function writeGateSentinel(file, marker) {
+ const quotedMarker = `'${marker.replaceAll("'", "'\\''")}'`;
+ writeFileSync(file, `#!/bin/sh\nprintf invoked > ${quotedMarker}\n`);
+ chmodSync(file, 0o755);
+}
+
+test('init says when its gate command cannot run [I1, I2]', () => {
+ const box = e2e.sandbox();
+ for (const name of ['UV_PROJECT_ENVIRONMENT', 'POETRY_ACTIVE', 'POETRY_VIRTUALENVS_PATH', 'VIRTUAL_ENV']) delete box.env[name];
+ const path = isolatedPath(box);
+
+ const missingRoot = pythonRepo(box, 'missing-gate');
+ const missing = box.run(missingRoot, 'init');
+ assert.equal(missing.code, 0, missing.err || missing.out);
+ const warnings = missing.out.split(/\r?\n/u).filter((line) => line.includes('gate command "pytest" is not available'));
+ assert.equal(warnings.length, 1, 'a missing gate gets one actionable line');
+ assert.match(warnings[0], /install pytest or activate the project `\.venv`/u);
+
+ const pathRoot = pythonRepo(box, 'path-gate');
+ const pathMarker = join(box.dir, 'path-gate-ran');
+ writeGateSentinel(join(path, process.platform === 'win32' ? 'pytest.cmd' : 'pytest'), pathMarker);
+ const onPath = box.run(pathRoot, 'init');
+ assert.equal(onPath.code, 0, onPath.err || onPath.out);
+ assert.doesNotMatch(onPath.out, /gate command "pytest" is not available/u);
+ assert.equal(existsSync(pathMarker), false, 'init checks the executable without running the gate');
+ rmSync(join(path, process.platform === 'win32' ? 'pytest.cmd' : 'pytest'));
+
+ const environmentRoot = pythonRepo(box, 'venv-gate');
+ const environmentMarker = join(box.dir, 'venv-gate-ran');
+ const environmentBin = join(environmentRoot, '.venv', process.platform === 'win32' ? 'Scripts' : 'bin');
+ mkdirSync(environmentBin, { recursive: true });
+ writeGateSentinel(join(environmentBin, process.platform === 'win32' ? 'pytest.cmd' : 'pytest'), environmentMarker);
+ const inEnvironment = box.run(environmentRoot, 'init');
+ assert.equal(inEnvironment.code, 0, inEnvironment.err || inEnvironment.out);
+ assert.doesNotMatch(inEnvironment.out, /gate command "pytest" is not available/u);
+ assert.equal(existsSync(environmentMarker), false, 'init does not execute a gate found in .venv');
+
+ const uvRoot = pythonRepo(box, 'uv-gate');
+ const uvMarker = join(box.dir, 'uv-gate-ran');
+ const uvEnvironment = join(box.dir, 'uv-environment');
+ mkdirSync(join(uvEnvironment, process.platform === 'win32' ? 'Scripts' : 'bin'), { recursive: true });
+ writeGateSentinel(join(uvEnvironment, process.platform === 'win32' ? 'Scripts/pytest.cmd' : 'bin/pytest'), uvMarker);
+ box.env.UV_PROJECT_ENVIRONMENT = uvEnvironment;
+ const inUvEnvironment = box.run(uvRoot, 'init');
+ assert.equal(inUvEnvironment.code, 0, inUvEnvironment.err || inUvEnvironment.out);
+ assert.doesNotMatch(inUvEnvironment.out, /gate command "pytest" is not available/u);
+ assert.equal(existsSync(uvMarker), false, 'init does not execute a gate found in the configured uv environment');
+ delete box.env.UV_PROJECT_ENVIRONMENT;
+
+ const poetryRoot = pythonRepo(box, 'poetry-gate');
+ writeFileSync(join(poetryRoot, 'poetry.lock'), '');
+ const poetryMarker = join(box.dir, 'poetry-gate-ran');
+ const poetryCache = join(box.dir, 'poetry-environments');
+ const decoyEnvironment = join(poetryCache, 'gate-check-fixture-a1b2-py3.12');
+ mkdirSync(join(decoyEnvironment, process.platform === 'win32' ? 'Scripts' : 'bin'), { recursive: true });
+ writeGateSentinel(join(decoyEnvironment, process.platform === 'win32' ? 'Scripts/pytest.cmd' : 'bin/pytest'), poetryMarker);
+ box.env.POETRY_VIRTUALENVS_PATH = poetryCache;
+ const decoy = box.run(poetryRoot, 'init');
+ assert.equal(decoy.code, 0, decoy.err || decoy.out);
+ assert.match(decoy.out, /gate command "pytest" is not available on PATH, project `\.venv`/u,
+ 'a same-name Poetry cache entry is not assumed to belong to this repo');
+ assert.match(decoy.out, /run `poetry install` and activate that environment/u);
+ assert.equal(existsSync(poetryMarker), false, 'init does not execute a same-name Poetry cache entry');
+
+ delete box.env.POETRY_VIRTUALENVS_PATH;
+ const activePoetry = join(box.dir, 'active-poetry-environment');
+ mkdirSync(join(activePoetry, process.platform === 'win32' ? 'Scripts' : 'bin'), { recursive: true });
+ writeGateSentinel(join(activePoetry, process.platform === 'win32' ? 'Scripts/pytest.cmd' : 'bin/pytest'), poetryMarker);
+ box.env.POETRY_ACTIVE = '1';
+ box.env.VIRTUAL_ENV = activePoetry;
+ const inPoetryEnvironment = box.run(poetryRoot, 'init');
+ assert.equal(inPoetryEnvironment.code, 0, inPoetryEnvironment.err || inPoetryEnvironment.out);
+ assert.doesNotMatch(inPoetryEnvironment.out, /gate command "pytest" is not available/u,
+ 'an explicitly active Poetry environment is checked');
+ assert.equal(existsSync(poetryMarker), false, 'init does not execute a gate found in the active Poetry environment');
+});