fix(#4485): isolate hook E2E tests from ambient capabilities (#4529)

* test(#4485): isolate hook E2E capability homes

* test(#4485): isolate the remaining plan hook E2E

* test(#4485): make ambient-home assertions real

* test(#4485): remove stale helper imports

---------

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
Michel Moreira
2026-09-15 00:44:18 -03:00
committed by GitHub
parent e2bfc06558
commit e5c4941f2a
4 changed files with 83 additions and 11 deletions

View File

@@ -29,7 +29,7 @@ const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const { cleanup } = require('./helpers.cjs');
const { cleanup, installSpawnEnv, withAmbientCapabilityHome } = require('./helpers.cjs');
const GSD_TOOLS = path.join(__dirname, '..', 'gsd-core', 'bin', 'gsd-tools.cjs');
@@ -66,7 +66,7 @@ const CLEAN_ENV = {
/**
* Run gsd-tools via spawnSync. Returns { status, stdout, stderr }.
* Passes env overrides merged on top of process.env + CLEAN_ENV.
* Passes env overrides through the canonical sandboxed child environment.
*/
function runTools(args, cwd, envOverrides = {}) {
return spawnSync(
@@ -76,7 +76,7 @@ function runTools(args, cwd, envOverrides = {}) {
cwd: cwd || process.cwd(),
encoding: 'utf8',
timeout: PLAN_PRE_HOOK_CLI_TIMEOUT_MS,
env: { ...process.env, ...CLEAN_ENV, ...envOverrides },
env: installSpawnEnv({ ...CLEAN_ENV, ...envOverrides }),
},
);
}
@@ -278,11 +278,20 @@ describe('plan:pre all-off — empty resolution', () => {
assert.strictEqual(result.status, 0, `exit non-zero. stderr=${result.stderr?.slice(0, 300)}`);
const envelope = parseEnvelope(result, 'all-off');
assert.deepEqual(envelope.activeHooks, [],
assert.deepStrictEqual(envelope.activeHooks, [],
`activeHooks must be empty when all flags false. Got: ${JSON.stringify(envelope.activeHooks.map(h=>h.capId))}`);
assert.strictEqual(envelope.rendered, '_No active hooks at plan:pre._',
'rendered must be placeholder when no active hooks');
});
test('#4485: an ambient plan:pre capability cannot perturb the empty resolution', (t) => {
withAmbientCapabilityHome(t, 'gsd-ambient-plan-pre-', 'ambient-plan-pre', 'plan:pre');
const result = runTools(['loop', 'render-hooks', 'plan:pre', '--cwd', tmpDir, '--raw'], tmpDir);
assert.strictEqual(result.status, 0, `exit non-zero. stderr=${result.stderr?.slice(0, 300)}`);
const envelope = parseEnvelope(result, 'all-off-ambient');
assert.deepStrictEqual(envelope.activeHooks, []);
});
});
// ─── 6. check ui.plan-gate: frontend + no-spec → block:true ──────────────────