Files
msd-core/tests/augment-upgrades.test.cjs
Jakub Zych a9a7a328e6 refactor: hard-fork GSD -> MSD (Make Software Done)
Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD
across contents and paths, upstream package/repo coordinates -> @golem15/msd-core
and golem15com/msd-core. Deep links into upstream history, sibling upstream
packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is.

Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line,
package/plugin identity, regenerated lockfile, install-tree fixtures, derived
registries and benchmark baseline; migration checksum baseline re-locked
(MSD keeps its own install state, so no install had applied the old sums);
sort-order and regex-escaped expectations in tests adjusted.
2026-10-06 01:47:40 +02:00

245 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
* `mergeMsdMcpServerIntoSettings`, registering the MSD 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 MSD's own entry while preserving any other user-configured
* `mcpServers` entries. Uninstall removes only the MSD-owned `msd` 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 { INSTALL_TIMEOUT_MS } = require('./helpers/timeouts.cjs');
const {
mergeMsdMcpServerIntoSettings,
} = require('../bin/install.js');
const { negotiateHostCapabilities } = require('../msd-core/bin/lib/host-integration.cjs');
const { PACKAGE_NAME } = require('../msd-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 MSD'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 hasMsdCommand = (entries) => entries.some(
(entry) => entry && Array.isArray(entry.hooks) &&
entry.hooks.some((h) => h && typeof h.command === 'string' && h.command.includes('msd-')),
);
assert.ok(hasMsdCommand(settings.hooks.SessionStart), 'SessionStart must reference a msd- managed hook');
assert.ok(hasMsdCommand(settings.hooks.PostToolUse), 'PostToolUse must reference a msd- managed hook');
assert.ok(hasMsdCommand(settings.hooks.PreToolUse), 'PreToolUse must reference a msd- 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 mergeMsdMcpServerIntoSettings mutates).
// ---------------------------------------------------------------------------
test('mergeMsdMcpServerIntoSettings adds mcpServers.msd with command "npx" and args including msd-mcp-server + PACKAGE_NAME', () => {
const settings = {};
mergeMsdMcpServerIntoSettings(settings);
assert.ok(settings.mcpServers && settings.mcpServers.msd, 'mcpServers.msd must be present');
assert.equal(settings.mcpServers.msd.command, 'npx');
assert.deepEqual(settings.mcpServers.msd.args, ['-y', '-p', PACKAGE_NAME, 'msd-mcp-server']);
});
test('mergeMsdMcpServerIntoSettings is idempotent — a second call does not clobber an existing msd entry', () => {
const settings = {};
mergeMsdMcpServerIntoSettings(settings);
// Simulate a user hand-edit of the msd entry after install.
settings.mcpServers.msd.args.push('--custom-flag');
mergeMsdMcpServerIntoSettings(settings);
assert.ok(settings.mcpServers.msd.args.includes('--custom-flag'),
"a user-owned msd override is never clobbered (Hyrum's Law)");
assert.equal(Object.keys(settings.mcpServers).length, 1, 'exactly one mcpServers entry (msd)');
});
test('mergeMsdMcpServerIntoSettings preserves a pre-existing unrelated mcpServers entry', () => {
const settings = {
mcpServers: {
'my-own-server': { command: 'my-tool', args: ['--flag'] },
},
};
mergeMsdMcpServerIntoSettings(settings);
assert.deepEqual(settings.mcpServers['my-own-server'], { command: 'my-tool', args: ['--flag'] });
assert.ok(settings.mcpServers.msd);
assert.equal(Object.keys(settings.mcpServers).length, 2, 'both entries present');
});
test('mergeMsdMcpServerIntoSettings recovers a corrupted (non-object) mcpServers field', () => {
const settingsArrayCase = { mcpServers: ['not', 'an', 'object'] };
mergeMsdMcpServerIntoSettings(settingsArrayCase);
assert.ok(settingsArrayCase.mcpServers.msd, 'array mcpServers must be recovered to an object with msd set');
const settingsStringCase = { mcpServers: 'corrupted-string' };
mergeMsdMcpServerIntoSettings(settingsStringCase);
assert.ok(settingsStringCase.mcpServers.msd, 'non-object mcpServers must be recovered to an object with msd 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 msd 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.msd, 'mcpServers.msd must be present');
assert.equal(settings.mcpServers.msd.command, 'npx');
assert.deepEqual(settings.mcpServers.msd.args, ['-y', '-p', PACKAGE_NAME, 'msd-mcp-server']);
});
}
test('augment --global: reinstalling does not duplicate or clobber the msd MCP companion entry (live-install idempotency)', (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'msd-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: INSTALL_TIMEOUT_MS });
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.msd);
// Simulate a user hand-edit of the msd entry between installs.
afterFirst.mcpServers.msd.args.push('--custom-flag');
fs.writeFileSync(settingsPath, JSON.stringify(afterFirst, null, 2) + '\n');
const second = runNode(args, { env, timeoutMs: INSTALL_TIMEOUT_MS });
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 msd entry');
assert.ok(afterSecond.mcpServers.msd.args.includes('--custom-flag'),
"a user-owned msd 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(), 'msd-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: INSTALL_TIMEOUT_MS,
});
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.msd, 'the msd companion entry must also be present');
});
// ---------------------------------------------------------------------------
// Uninstall — symmetric cleanup for the MCP companion entry.
// ---------------------------------------------------------------------------
test('augment --global uninstall removes only the MSD-owned mcpServers.msd entry, preserving user data', (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'msd-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: INSTALL_TIMEOUT_MS });
assert.strictEqual(installResult.exitCode, 0, `install failed: ${installResult.stderr}`);
// Seed user-owned data alongside MSD'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: INSTALL_TIMEOUT_MS });
assert.strictEqual(uninstallResult.exitCode, 0, `uninstall failed: ${uninstallResult.stderr}`);
const settingsAfter = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
assert.equal(settingsAfter.mcpServers && settingsAfter.mcpServers.msd, undefined, 'msd MCP entry removed');
assert.deepEqual(settingsAfter.mcpServers['my-own-server'], { command: 'my-tool', args: [] },
'user MCP server preserved');
});