* test(#3145): bound the installer/runtime cluster onto the process seam Migrates 156 unbounded sync spawn sites across 47 files. Allowlist 120 to 73. Timeouts are sized from evidence already in the tree rather than a house default, because this wave spawns installers rather than git plumbing and an undersized bound does not catch a hang -- it manufactures CI flake, which is worse, since a flake gets re-run instead of investigated. install.test.cjs records a real spawnSync ETIMEDOUT at a 60000ms cap on a loaded bench while another lane passed the same commit in 12.7s, so full installs are bound at 120000ms against that recorded incident. Also adds an auditable escape to the guard's timeout ceiling. The 600000ms cap was set in #3143 from partial evidence, but fragment-single-edit- propagation carries a documented, load-tested 900000ms bound on a run that chains a full build plus eight generators -- the guard would have rejected a correct timeout the moment that file left the allowlist. A value above the ceiling is now permitted only with an inline allow-spawn-timeout-ceiling marker carrying a non-empty reason. It raises the ceiling; it never waives the requirement for a bound, which is asserted directly. install-shared.cjs keeps its hand-rolled assert rather than routing through throwIfFailed: its message embeds both streams, and throwIfFailed carries only a trimmed stderr. The message now also names the outcome, so a bounded timeout reads as such across its 38 importers instead of as expected null to equal 0. * test(#3145): extract class-norm timeouts and correct the build-hooks sizing A pre-PR review found 52 copies of four class-norm timeout constants across this wave. These are not per-suite fixture bindings -- they are shared facts about how long a class of subprocess takes, derived from a recorded bench incident. That norm already moved once (60000 to 120000 after a real ETIMEDOUT), and 52 copies would have drifted the next time it moved. Extracts tests/helpers/timeouts.cjs, where each norm is justified once, and converts the copies. A site that genuinely differs -- a real tsc compile, or regen:derived -- keeps its own local constant with its own justification. Also corrects a misclassification: scripts/build-hooks.js was sized as a build at 120000 in twelve places and 60000 in another, but it compiles and bundles nothing. Its own header says no bundling needed; it copies pre-built files and syntax-checks them with vm. Three different values bounded one script; now there is one. * test(#3145): fix red CI — lint self-match and a Windows chunk overrun Two failures on PR 3176. lint-allow-test-rule-refs read a RuleTester fixture as a real exemption. The fixture exists to prove an unrelated marker does NOT suppress the rule, so it carries that marker's literal text as test data. Split via concatenation, the same idiom no-unbounded-spawn-allowlist.test.cjs already uses for its own self-match problem. The explanatory comment needed the same treatment. The Windows shard 3/3 chunk was killed at its 600000ms budget. Output stopped seven minutes before the kill, so this was an overrun rather than a slow chunk: regenDerivedPropagatesSingleFragmentEditWithNoSecondSourceSurface runs regen:derived bounded at 900000ms, which is larger than the whole chunk budget, so the chunk killer always fires first and it can never complete there. Both the test and that bound predate this change; modifying the file pulled it into the Windows targeted set and exposed it. Skipped on Windows with the reason recorded; the Linux lanes cover it. The 900000 bound and its ceiling marker are unchanged -- they are correct. * test(#3145): refresh the stale test-timings cost table The Windows shard was killed at its 600000ms per-chunk budget. run-tests.cjs packs chunks by measured duration from tests/test-timings.json, and an unknown file falls back to the table's median weight -- advisory by design, but it silently underweights exactly the files that matter. Four of the failing chunk's 22 files were absent from the table, including the two heaviest: fragment-single-edit-propagation.install.test.cjs at 230s (it runs regen:derived) and agent-fragments-emission.install.test.cjs at 79s. Both were weighted as average, so the chunk's total weight read 53.68 against a budget of 60 and the packer produced a single chunk. Regenerated from a passing full-suite run, per the remedy the script itself documents. 700 to 770 entries, 70 added, 0 dropped -- verified, since gen-test-timings.cjs replaces the table wholesale rather than merging. Proven against the real packer: the same 22 files now weigh 103.91 and split into two chunks. No logic, budget, or timeout was changed; raising a budget to make a red gate pass is not a fix. --------- Co-authored-by: sim <sim@local>
244 lines
13 KiB
JavaScript
244 lines
13 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Augment Code capability UPGRADES — ADR-1239 / #2097 (EoS/augment migration).
|
|
*
|
|
* Mirrors tests/antigravity-upgrades.test.cjs's structure. Augment already
|
|
* shipped as a declarative-CLI host prior to #2097 (nested-skill artifact
|
|
* layout, settings-json hook surface, Claude hook event dialect, dispatch
|
|
* namedDispatch/background/subagentToolkit:'full'), so UPGRADE 1 (dispatch)
|
|
* and UPGRADE 2 (hook-bus) below are REGRESSION locks on that pre-existing
|
|
* wiring, not new capabilities. UPGRADE 3 (MCP companion) IS new: #2097 adds
|
|
* `mergeGsdMcpServerIntoSettings`, registering the GSD companion MCP server
|
|
* inside Augment's own settings.json `mcpServers` block (Augment hosts MCP
|
|
* there, unlike Antigravity's standalone mcp_config.json) — non-destructively
|
|
* appending GSD's own entry while preserving any other user-configured
|
|
* `mcpServers` entries. Uninstall removes only the GSD-owned `gsd` entry.
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
const { runNode } = require('./helpers/process-seam.cjs');
|
|
|
|
const { runMinimalInstall, installerEnv, INSTALL_SCRIPT } = require('./helpers/install-shared.cjs');
|
|
const { cleanup } = require('./helpers.cjs');
|
|
const {
|
|
mergeGsdMcpServerIntoSettings,
|
|
} = require('../bin/install.js');
|
|
const { negotiateHostCapabilities } = require('../gsd-core/bin/lib/host-integration.cjs');
|
|
const { PACKAGE_NAME } = require('../gsd-core/bin/lib/package-identity.cjs');
|
|
|
|
const AUGMENT_CAP = JSON.parse(
|
|
fs.readFileSync(path.join(__dirname, '..', 'capabilities', 'augment', 'capability.json'), 'utf8'),
|
|
);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// UPGRADE 1: dispatch — descriptor + negotiation regression lock
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('capabilities/augment/capability.json declares dispatch.namedDispatch/background/subagentToolkit for full subagent support (UPGRADE 1)', () => {
|
|
const dispatch = AUGMENT_CAP.runtime.hostIntegration.dispatch;
|
|
assert.equal(dispatch.namedDispatch, true);
|
|
assert.equal(dispatch.background, true);
|
|
assert.equal(dispatch.subagentToolkit, 'full');
|
|
});
|
|
|
|
test('negotiateHostCapabilities does NOT flatten dispatch for augment — namedDispatch/background/subagentToolkit survive negotiation (UPGRADE 1)', () => {
|
|
const { effective } = negotiateHostCapabilities(AUGMENT_CAP.runtime.hostIntegration);
|
|
assert.equal(effective.dispatch.namedDispatch, true,
|
|
'documented namedDispatch:true must survive negotiation unflattened');
|
|
assert.equal(effective.dispatch.background, true,
|
|
'documented background:true must survive negotiation unflattened (not capped to false)');
|
|
assert.equal(effective.dispatch.subagentToolkit, 'full',
|
|
'documented subagentToolkit:full must survive negotiation unflattened');
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// UPGRADE 2: hook-bus — live install proves the settings.json hook surface
|
|
// (SessionStart/PostToolUse/PreToolUse) is actually wired for augment.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
for (const scope of ['global', 'local']) {
|
|
test(`augment --${scope}: settings.json contains GSD's managed hook entries (UPGRADE 2)`, (t) => {
|
|
const { configDir, root } = runMinimalInstall({ runtime: 'augment', scope });
|
|
t.after(() => cleanup(root));
|
|
|
|
const settingsPath = path.join(configDir, 'settings.json');
|
|
assert.ok(fs.existsSync(settingsPath), `${settingsPath} must exist`);
|
|
|
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
assert.ok(settings.hooks && typeof settings.hooks === 'object', 'settings.hooks must be an object');
|
|
|
|
// Augment's hookEvents dialect is 'claude' (capabilities/augment/capability.json),
|
|
// so it gets the Claude-dialect event names (PostToolUse/PreToolUse), not
|
|
// antigravity's gemini-dialect (AfterTool/BeforeTool).
|
|
assert.ok(Array.isArray(settings.hooks.SessionStart) && settings.hooks.SessionStart.length > 0,
|
|
'settings.hooks.SessionStart must be registered');
|
|
assert.ok(Array.isArray(settings.hooks.PostToolUse) && settings.hooks.PostToolUse.length > 0,
|
|
'settings.hooks.PostToolUse must be registered');
|
|
assert.ok(Array.isArray(settings.hooks.PreToolUse) && settings.hooks.PreToolUse.length > 0,
|
|
'settings.hooks.PreToolUse must be registered');
|
|
|
|
const hasGsdCommand = (entries) => entries.some(
|
|
(entry) => entry && Array.isArray(entry.hooks) &&
|
|
entry.hooks.some((h) => h && typeof h.command === 'string' && h.command.includes('gsd-')),
|
|
);
|
|
assert.ok(hasGsdCommand(settings.hooks.SessionStart), 'SessionStart must reference a gsd- managed hook');
|
|
assert.ok(hasGsdCommand(settings.hooks.PostToolUse), 'PostToolUse must reference a gsd- managed hook');
|
|
assert.ok(hasGsdCommand(settings.hooks.PreToolUse), 'PreToolUse must reference a gsd- managed hook');
|
|
});
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// UPGRADE 3: MCP companion config — direct-unit idempotency + preservation
|
|
// (mirrors antigravity's configureAntigravityMcpConfig unit tests exactly,
|
|
// scoped to the in-memory settings object mergeGsdMcpServerIntoSettings mutates).
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('mergeGsdMcpServerIntoSettings adds mcpServers.gsd with command "npx" and args including gsd-mcp-server + PACKAGE_NAME', () => {
|
|
const settings = {};
|
|
mergeGsdMcpServerIntoSettings(settings);
|
|
assert.ok(settings.mcpServers && settings.mcpServers.gsd, 'mcpServers.gsd must be present');
|
|
assert.equal(settings.mcpServers.gsd.command, 'npx');
|
|
assert.deepEqual(settings.mcpServers.gsd.args, ['-y', '-p', PACKAGE_NAME, 'gsd-mcp-server']);
|
|
});
|
|
|
|
test('mergeGsdMcpServerIntoSettings is idempotent — a second call does not clobber an existing gsd entry', () => {
|
|
const settings = {};
|
|
mergeGsdMcpServerIntoSettings(settings);
|
|
// Simulate a user hand-edit of the gsd entry after install.
|
|
settings.mcpServers.gsd.args.push('--custom-flag');
|
|
|
|
mergeGsdMcpServerIntoSettings(settings);
|
|
|
|
assert.ok(settings.mcpServers.gsd.args.includes('--custom-flag'),
|
|
"a user-owned gsd override is never clobbered (Hyrum's Law)");
|
|
assert.equal(Object.keys(settings.mcpServers).length, 1, 'exactly one mcpServers entry (gsd)');
|
|
});
|
|
|
|
test('mergeGsdMcpServerIntoSettings preserves a pre-existing unrelated mcpServers entry', () => {
|
|
const settings = {
|
|
mcpServers: {
|
|
'my-own-server': { command: 'my-tool', args: ['--flag'] },
|
|
},
|
|
};
|
|
mergeGsdMcpServerIntoSettings(settings);
|
|
|
|
assert.deepEqual(settings.mcpServers['my-own-server'], { command: 'my-tool', args: ['--flag'] });
|
|
assert.ok(settings.mcpServers.gsd);
|
|
assert.equal(Object.keys(settings.mcpServers).length, 2, 'both entries present');
|
|
});
|
|
|
|
test('mergeGsdMcpServerIntoSettings recovers a corrupted (non-object) mcpServers field', () => {
|
|
const settingsArrayCase = { mcpServers: ['not', 'an', 'object'] };
|
|
mergeGsdMcpServerIntoSettings(settingsArrayCase);
|
|
assert.ok(settingsArrayCase.mcpServers.gsd, 'array mcpServers must be recovered to an object with gsd set');
|
|
|
|
const settingsStringCase = { mcpServers: 'corrupted-string' };
|
|
mergeGsdMcpServerIntoSettings(settingsStringCase);
|
|
assert.ok(settingsStringCase.mcpServers.gsd, 'non-object mcpServers must be recovered to an object with gsd set');
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// UPGRADE 3: MCP companion config — live install (both scopes) proves the
|
|
// end-to-end wiring through finishInstall, not just the unit function.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
for (const scope of ['global', 'local']) {
|
|
test(`augment --${scope}: settings.json registers the gsd MCP companion (UPGRADE 3)`, (t) => {
|
|
const { configDir, root } = runMinimalInstall({ runtime: 'augment', scope });
|
|
t.after(() => cleanup(root));
|
|
|
|
const settingsPath = path.join(configDir, 'settings.json');
|
|
assert.ok(fs.existsSync(settingsPath), `${settingsPath} must exist`);
|
|
|
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
assert.ok(settings.mcpServers && settings.mcpServers.gsd, 'mcpServers.gsd must be present');
|
|
assert.equal(settings.mcpServers.gsd.command, 'npx');
|
|
assert.deepEqual(settings.mcpServers.gsd.args, ['-y', '-p', PACKAGE_NAME, 'gsd-mcp-server']);
|
|
});
|
|
}
|
|
|
|
test('augment --global: reinstalling does not duplicate or clobber the gsd MCP companion entry (live-install idempotency)', (t) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-augment-mcp-idem-'));
|
|
t.after(() => cleanup(root));
|
|
|
|
const args = [INSTALL_SCRIPT, '--augment', '--global', '--config-dir', root];
|
|
const env = installerEnv({ HOME: root, USERPROFILE: root });
|
|
|
|
const first = runNode(args, { env, timeoutMs: 120000 });
|
|
assert.strictEqual(first.exitCode, 0, `first install failed: ${first.stderr}`);
|
|
|
|
const settingsPath = path.join(root, 'settings.json');
|
|
const afterFirst = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
assert.ok(afterFirst.mcpServers.gsd);
|
|
// Simulate a user hand-edit of the gsd entry between installs.
|
|
afterFirst.mcpServers.gsd.args.push('--custom-flag');
|
|
fs.writeFileSync(settingsPath, JSON.stringify(afterFirst, null, 2) + '\n');
|
|
|
|
const second = runNode(args, { env, timeoutMs: 120000 });
|
|
assert.strictEqual(second.exitCode, 0, `second install failed: ${second.stderr}`);
|
|
|
|
const afterSecond = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
assert.equal(Object.keys(afterSecond.mcpServers).length, 1, 'reinstall must not duplicate the gsd entry');
|
|
assert.ok(afterSecond.mcpServers.gsd.args.includes('--custom-flag'),
|
|
"a user-owned gsd override is never clobbered across reinstall (Hyrum's Law)");
|
|
});
|
|
|
|
test('augment --global: installing preserves a pre-existing unrelated mcpServers entry (live-install preservation)', (t) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-augment-mcp-preserve-'));
|
|
fs.mkdirSync(root, { recursive: true });
|
|
t.after(() => cleanup(root));
|
|
|
|
// Pre-seed settings.json with a user's own MCP server BEFORE install runs.
|
|
fs.writeFileSync(path.join(root, 'settings.json'), JSON.stringify({
|
|
mcpServers: {
|
|
other: { command: 'my-tool', args: ['--flag'] },
|
|
},
|
|
}, null, 2));
|
|
|
|
const args = [INSTALL_SCRIPT, '--augment', '--global', '--config-dir', root];
|
|
const result = runNode(args, {
|
|
env: installerEnv({ HOME: root, USERPROFILE: root }),
|
|
timeoutMs: 120000,
|
|
});
|
|
assert.strictEqual(result.exitCode, 0, `install failed: ${result.stderr}`);
|
|
|
|
const settings = JSON.parse(fs.readFileSync(path.join(root, 'settings.json'), 'utf8'));
|
|
assert.deepEqual(settings.mcpServers.other, { command: 'my-tool', args: ['--flag'] },
|
|
"the user's pre-existing mcpServers entry must be preserved");
|
|
assert.ok(settings.mcpServers.gsd, 'the gsd companion entry must also be present');
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Uninstall — symmetric cleanup for the MCP companion entry.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('augment --global uninstall removes only the GSD-owned mcpServers.gsd entry, preserving user data', (t) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-augment-uninstall-'));
|
|
t.after(() => cleanup(root));
|
|
|
|
const env = installerEnv({ HOME: root, USERPROFILE: root });
|
|
const installArgs = [INSTALL_SCRIPT, '--augment', '--global', '--config-dir', root];
|
|
const installResult = runNode(installArgs, { env, timeoutMs: 120000 });
|
|
assert.strictEqual(installResult.exitCode, 0, `install failed: ${installResult.stderr}`);
|
|
|
|
// Seed user-owned data alongside GSD's contributions, post-install.
|
|
const settingsPath = path.join(root, 'settings.json');
|
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
settings.mcpServers['my-own-server'] = { command: 'my-tool', args: [] };
|
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
|
|
const uninstallArgs = [INSTALL_SCRIPT, '--augment', '--global', '--config-dir', root, '--uninstall'];
|
|
const uninstallResult = runNode(uninstallArgs, { env, timeoutMs: 120000 });
|
|
assert.strictEqual(uninstallResult.exitCode, 0, `uninstall failed: ${uninstallResult.stderr}`);
|
|
|
|
const settingsAfter = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
assert.equal(settingsAfter.mcpServers && settingsAfter.mcpServers.gsd, undefined, 'gsd MCP entry removed');
|
|
assert.deepEqual(settingsAfter.mcpServers['my-own-server'], { command: 'my-tool', args: [] },
|
|
'user MCP server preserved');
|
|
});
|