Merge branch 'next' into fix/2137-derive-progress-header-driven
This commit is contained in:
283
tests/antigravity-upgrades.test.cjs
Normal file
283
tests/antigravity-upgrades.test.cjs
Normal file
@@ -0,0 +1,283 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* antigravity capability UPGRADES — ADR-1239 Phase B / #2096 (EoS/antigravity).
|
||||
*
|
||||
* Drives the user-reachable surface (spawned `bin/install.js` via
|
||||
* `runMinimalInstall`) plus targeted unit coverage to prove the two real
|
||||
* upgrades Antigravity contributes as part of the imperative-adapter
|
||||
* migration:
|
||||
*
|
||||
* UPGRADE 1 — permission-writer: `configureAntigravityPermissions` writes
|
||||
* Antigravity's native `{"permissions":{"allow":[...]}}` schema
|
||||
* (antigravity.google/docs/cli/permissions) into the SAME settings.json
|
||||
* GSD's own hook registration writes, non-destructively appending GSD's own
|
||||
* read_file/command allow rules while preserving any existing user
|
||||
* permissions (allow/deny/ask). Uninstall removes only the GSD-owned rules.
|
||||
*
|
||||
* UPGRADE 2 — MCP companion config: `configureAntigravityMcpConfig` writes
|
||||
* a standalone `mcp_config.json` (antigravity.google/docs/cli/gcli-migration)
|
||||
* registering the `gsd` MCP server (`bin/gsd-mcp-server.js`, the SAME
|
||||
* companion OpenCode/Kilo document/wire), non-destructively preserving any
|
||||
* other user-configured `mcpServers` entries. Uninstall removes only the
|
||||
* `gsd` entry.
|
||||
*
|
||||
* Both writers are NOT GSD_TEST_MODE-gated (mirrors Kilo's dispatch, not
|
||||
* OpenCode's) — runMinimalInstall strips GSD_TEST_MODE from the spawned
|
||||
* installer's env, so both fire during a "minimal" install too.
|
||||
*/
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const { runMinimalInstall, installerEnv, INSTALL_SCRIPT } = require('./helpers/install-shared.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const {
|
||||
toTildePosixPath,
|
||||
buildAntigravityAllowRules,
|
||||
configureAntigravityPermissions,
|
||||
configureAntigravityMcpConfig,
|
||||
} = require('../bin/install.js');
|
||||
const { PROTOCOL_VERSION } = require('../gsd-core/bin/lib/mcp-server.cjs');
|
||||
const { PACKAGE_NAME } = require('../gsd-core/bin/lib/package-identity.cjs');
|
||||
|
||||
const MCP_SERVER_BIN = path.join(__dirname, '..', 'bin', 'gsd-mcp-server.js');
|
||||
|
||||
const ANTIGRAVITY_CAP = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, '..', 'capabilities', 'antigravity', 'capability.json'), 'utf8'),
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Descriptor boundary — permissionWriter wiring
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('capabilities/antigravity/capability.json declares runtime.permissionWriter: "antigravity"', () => {
|
||||
assert.equal(ANTIGRAVITY_CAP.runtime.permissionWriter, 'antigravity');
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UPGRADE 1: permission-writer unit coverage (toTildePosixPath / rule builder)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('toTildePosixPath collapses a homedir-rooted path to "~/..." form', () => {
|
||||
const home = require('node:os').homedir();
|
||||
assert.equal(toTildePosixPath(path.join(home, '.gemini', 'antigravity')), '~/.gemini/antigravity');
|
||||
});
|
||||
|
||||
test('toTildePosixPath leaves a non-homedir path as an absolute posix path', () => {
|
||||
assert.equal(toTildePosixPath('/var/tmp/some-config-dir'), '/var/tmp/some-config-dir');
|
||||
});
|
||||
|
||||
test('buildAntigravityAllowRules emits the 4 documented "action(target)" rule strings', () => {
|
||||
const rules = buildAntigravityAllowRules('/tmp/ag-config');
|
||||
assert.deepEqual(rules, [
|
||||
'read_file(/tmp/ag-config/gsd-core/*)',
|
||||
'read_file(/tmp/ag-config/agents/gsd-*)',
|
||||
'read_file(/tmp/ag-config/skills/gsd-*)',
|
||||
'command(node /tmp/ag-config/hooks/*)',
|
||||
]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UPGRADE 1: live install — settings.json permissions.allow (both scopes)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
for (const scope of ['global', 'local']) {
|
||||
test(`antigravity --${scope}: settings.json permissions.allow contains GSD's rules (UPGRADE 1)`, (t) => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'antigravity', 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.permissions && Array.isArray(settings.permissions.allow), 'permissions.allow must be an array');
|
||||
|
||||
// Asserting on the exact rule strings here would require reproducing
|
||||
// toTildePosixPath's os.homedir()-relative substitution from OUTSIDE the
|
||||
// spawned installer subprocess: runMinimalInstall overrides that
|
||||
// subprocess's HOME to `root`, so for --global (configDir === root ===
|
||||
// that subprocess's HOME) every rule collapses to the bare `~/...` form,
|
||||
// while THIS test process's own (unrelated, real) os.homedir() would
|
||||
// reconstruct full absolute paths instead — a guaranteed mismatch that
|
||||
// has nothing to do with correctness. Assert on the documented rule
|
||||
// SHAPE (action + path suffix) instead, which holds regardless of
|
||||
// whether the prefix collapsed to `~` or stayed a full absolute path.
|
||||
const expectedShapes = [
|
||||
{ action: 'read_file(', suffix: '/gsd-core/*)' },
|
||||
{ action: 'read_file(', suffix: '/agents/gsd-*)' },
|
||||
{ action: 'read_file(', suffix: '/skills/gsd-*)' },
|
||||
{ action: 'command(node ', suffix: '/hooks/*)' },
|
||||
];
|
||||
for (const { action, suffix } of expectedShapes) {
|
||||
const found = settings.permissions.allow.some((rule) => rule.startsWith(action) && rule.endsWith(suffix));
|
||||
assert.ok(found, `permissions.allow must include a rule shaped like "${action}...${suffix}" — got ${JSON.stringify(settings.permissions.allow)}`);
|
||||
}
|
||||
// Priority-scoping (deny/ask) is a user-owned decision — GSD never writes it.
|
||||
assert.equal(settings.permissions.deny, undefined, 'GSD must never write permissions.deny');
|
||||
assert.equal(settings.permissions.ask, undefined, 'GSD must never write permissions.ask');
|
||||
});
|
||||
}
|
||||
|
||||
test('configureAntigravityPermissions is idempotent — a second call adds no duplicate rules', (t) => {
|
||||
const root = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'gsd-ag-perm-idem-'));
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
configureAntigravityPermissions(true, root);
|
||||
configureAntigravityPermissions(true, root);
|
||||
const settings = JSON.parse(fs.readFileSync(path.join(root, 'settings.json'), 'utf8'));
|
||||
assert.equal(settings.permissions.allow.length, new Set(settings.permissions.allow).size, 'no duplicate allow entries');
|
||||
assert.equal(settings.permissions.allow.length, buildAntigravityAllowRules(root).length);
|
||||
});
|
||||
|
||||
test('configureAntigravityPermissions preserves a pre-existing user permissions block (allow/deny/ask)', (t) => {
|
||||
const root = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'gsd-ag-perm-preserve-'));
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
fs.writeFileSync(path.join(root, 'settings.json'), JSON.stringify({
|
||||
permissions: {
|
||||
allow: ['command(git)'],
|
||||
deny: ['command(rm -rf)'],
|
||||
ask: ['command(*)'],
|
||||
},
|
||||
userCustomField: 'preserve-me',
|
||||
}, null, 2));
|
||||
|
||||
configureAntigravityPermissions(true, root);
|
||||
|
||||
const settings = JSON.parse(fs.readFileSync(path.join(root, 'settings.json'), 'utf8'));
|
||||
assert.ok(settings.permissions.allow.includes('command(git)'), 'pre-existing allow entry preserved');
|
||||
assert.deepEqual(settings.permissions.deny, ['command(rm -rf)'], 'deny block untouched');
|
||||
assert.deepEqual(settings.permissions.ask, ['command(*)'], 'ask block untouched');
|
||||
assert.equal(settings.userCustomField, 'preserve-me', 'unrelated top-level user fields preserved');
|
||||
for (const rule of buildAntigravityAllowRules(root)) {
|
||||
assert.ok(settings.permissions.allow.includes(rule));
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UPGRADE 2: MCP companion config — live install (both scopes)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
for (const scope of ['global', 'local']) {
|
||||
test(`antigravity --${scope}: mcp_config.json registers the gsd MCP companion (UPGRADE 2)`, (t) => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'antigravity', scope });
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
const mcpConfigPath = path.join(configDir, 'mcp_config.json');
|
||||
assert.ok(fs.existsSync(mcpConfigPath), `${mcpConfigPath} must exist`);
|
||||
|
||||
const mcpConfig = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
|
||||
assert.ok(mcpConfig.mcpServers && mcpConfig.mcpServers.gsd, 'mcpServers.gsd must be present');
|
||||
assert.equal(mcpConfig.mcpServers.gsd.command, 'npx');
|
||||
assert.deepEqual(mcpConfig.mcpServers.gsd.args, ['-y', '-p', PACKAGE_NAME, 'gsd-mcp-server']);
|
||||
});
|
||||
}
|
||||
|
||||
test('configureAntigravityMcpConfig is idempotent — a second call does not clobber an existing gsd entry', (t) => {
|
||||
const root = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'gsd-ag-mcp-idem-'));
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
configureAntigravityMcpConfig(true, root);
|
||||
// Simulate a user hand-edit of the gsd entry after install.
|
||||
const configPath = path.join(root, 'mcp_config.json');
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
config.mcpServers.gsd.args.push('--custom-flag');
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
||||
|
||||
configureAntigravityMcpConfig(true, root);
|
||||
|
||||
const after = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
assert.ok(after.mcpServers.gsd.args.includes('--custom-flag'), 'a user-owned gsd override is never clobbered (Hyrum\'s Law)');
|
||||
});
|
||||
|
||||
test('configureAntigravityMcpConfig preserves a pre-existing unrelated mcpServers entry', (t) => {
|
||||
const root = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'gsd-ag-mcp-preserve-'));
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
fs.writeFileSync(path.join(root, 'mcp_config.json'), JSON.stringify({
|
||||
mcpServers: {
|
||||
'my-own-server': { command: 'my-tool', args: ['--flag'] },
|
||||
},
|
||||
}, null, 2));
|
||||
|
||||
configureAntigravityMcpConfig(true, root);
|
||||
|
||||
const config = JSON.parse(fs.readFileSync(path.join(root, 'mcp_config.json'), 'utf8'));
|
||||
assert.deepEqual(config.mcpServers['my-own-server'], { command: 'my-tool', args: ['--flag'] });
|
||||
assert.ok(config.mcpServers.gsd);
|
||||
});
|
||||
|
||||
// AC-style proof: the companion mcp_config.json points at (bin/gsd-mcp-server.js)
|
||||
// is actually reachable, not just documented. Mirrors tests/gsd-mcp-server-bin.test.cjs
|
||||
// exactly (same shim, same line-delimited JSON-RPC over stdio).
|
||||
test('UPGRADE 2: gsd-mcp-server companion is reachable — spawn, initialize, tools/list over stdio', () => {
|
||||
const stdin = [
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize' }),
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/list' }),
|
||||
].join('\n') + '\n';
|
||||
|
||||
const res = spawnSync(process.execPath, [MCP_SERVER_BIN], {
|
||||
input: stdin,
|
||||
encoding: 'utf-8',
|
||||
timeout: 15000,
|
||||
env: { ...process.env, GSD_TEST_MODE: '1' },
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 0, `gsd-mcp-server must exit cleanly on stdin EOF; stderr: ${res.stderr}`);
|
||||
const lines = res.stdout.trim().split('\n').map((l) => JSON.parse(l));
|
||||
assert.strictEqual(lines.length, 2, 'one response per request');
|
||||
assert.strictEqual(lines[0].result.protocolVersion, PROTOCOL_VERSION, 'initialize handshake succeeds');
|
||||
const toolNames = lines[1].result.tools.map((t) => t.name).sort();
|
||||
assert.deepStrictEqual(
|
||||
toolNames,
|
||||
['gsd_invoke_command', 'gsd_read_state', 'gsd_write_state'],
|
||||
'the companion the mcp_config.json entry connects to advertises the real GSD tool surface',
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Uninstall — symmetric cleanup for both upgrades
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('antigravity --global uninstall removes only GSD-owned permissions.allow rules + mcpServers.gsd, preserving user data', (t) => {
|
||||
const root = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'gsd-ag-uninstall-'));
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
const args = [INSTALL_SCRIPT, '--antigravity', '--global', '--config-dir', root];
|
||||
const installResult = spawnSync(process.execPath, args, {
|
||||
encoding: 'utf8',
|
||||
env: installerEnv({ HOME: root, USERPROFILE: root }),
|
||||
});
|
||||
assert.strictEqual(installResult.status, 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.permissions.allow.push('command(git)');
|
||||
settings.permissions.deny = ['command(rm -rf)'];
|
||||
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
||||
|
||||
const mcpConfigPath = path.join(root, 'mcp_config.json');
|
||||
const mcpConfig = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
|
||||
mcpConfig.mcpServers['my-own-server'] = { command: 'my-tool', args: [] };
|
||||
fs.writeFileSync(mcpConfigPath, JSON.stringify(mcpConfig, null, 2) + '\n');
|
||||
|
||||
const uninstallArgs = [INSTALL_SCRIPT, '--antigravity', '--global', '--config-dir', root, '--uninstall'];
|
||||
const uninstallResult = spawnSync(process.execPath, uninstallArgs, {
|
||||
encoding: 'utf8',
|
||||
env: installerEnv({ HOME: root, USERPROFILE: root }),
|
||||
});
|
||||
assert.strictEqual(uninstallResult.status, 0, `uninstall failed: ${uninstallResult.stderr}`);
|
||||
|
||||
const settingsAfter = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
||||
assert.deepEqual(settingsAfter.permissions.allow, ['command(git)'], 'GSD allow rules removed, user rule preserved');
|
||||
assert.deepEqual(settingsAfter.permissions.deny, ['command(rm -rf)'], 'user deny rule preserved');
|
||||
|
||||
const mcpConfigAfter = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
|
||||
assert.equal(mcpConfigAfter.mcpServers.gsd, undefined, 'gsd MCP entry removed');
|
||||
assert.deepEqual(mcpConfigAfter.mcpServers['my-own-server'], { command: 'my-tool', args: [] }, 'user MCP server preserved');
|
||||
});
|
||||
243
tests/augment-upgrades.test.cjs
Normal file
243
tests/augment-upgrades.test.cjs
Normal file
@@ -0,0 +1,243 @@
|
||||
'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 { spawnSync } = require('node:child_process');
|
||||
|
||||
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 = spawnSync(process.execPath, args, { encoding: 'utf8', env });
|
||||
assert.strictEqual(first.status, 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 = spawnSync(process.execPath, args, { encoding: 'utf8', env });
|
||||
assert.strictEqual(second.status, 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 = spawnSync(process.execPath, args, {
|
||||
encoding: 'utf8',
|
||||
env: installerEnv({ HOME: root, USERPROFILE: root }),
|
||||
});
|
||||
assert.strictEqual(result.status, 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 = spawnSync(process.execPath, installArgs, { encoding: 'utf8', env });
|
||||
assert.strictEqual(installResult.status, 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 = spawnSync(process.execPath, uninstallArgs, { encoding: 'utf8', env });
|
||||
assert.strictEqual(uninstallResult.status, 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');
|
||||
});
|
||||
@@ -4453,11 +4453,12 @@ describe('ADR-857 phase 5f: cross-field consistency gate rejection tests (DEFECT
|
||||
}
|
||||
});
|
||||
|
||||
test('VALID_PERMISSION_WRITERS covers exactly {opencode, kilo}', () => {
|
||||
test('VALID_PERMISSION_WRITERS covers exactly {opencode, kilo, antigravity}', () => {
|
||||
assert.ok(VALID_PERMISSION_WRITERS instanceof Set, 'Must be a Set');
|
||||
assert.strictEqual(VALID_PERMISSION_WRITERS.size, 2, 'Must cover 2 permission writers');
|
||||
assert.strictEqual(VALID_PERMISSION_WRITERS.size, 3, 'Must cover 3 permission writers');
|
||||
assert.ok(VALID_PERMISSION_WRITERS.has('opencode'), 'Must include opencode');
|
||||
assert.ok(VALID_PERMISSION_WRITERS.has('kilo'), 'Must include kilo');
|
||||
assert.ok(VALID_PERMISSION_WRITERS.has('antigravity'), 'Must include antigravity (#2096)');
|
||||
});
|
||||
|
||||
// Confirm the valid base fixture does NOT produce errors (sanity)
|
||||
|
||||
128
tests/codebuddy-upgrades.test.cjs
Normal file
128
tests/codebuddy-upgrades.test.cjs
Normal file
@@ -0,0 +1,128 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* CodeBuddy capability UPGRADES — ADR-1239 / #2098 (EoS/codebuddy).
|
||||
*
|
||||
* Drives the user-reachable surface (spawned `bin/install.js` via
|
||||
* `runMinimalInstall`) plus a direct negotiation-contract check to prove the
|
||||
* two real upgrades CodeBuddy contributes as part of the EoS migration:
|
||||
*
|
||||
* UPGRADE 1 — extended hook events: CodeBuddy's `extendedHookEvents` was
|
||||
* previously `[]` (none of the 4 extended events were wired). This PR
|
||||
* wires all four — `SubagentStop`/`Stop`/`PreCompact`/`SubagentStart` —
|
||||
* into `extendedHookEvents` (mirrors qwen #2092 / kimi exactly — same 4
|
||||
* events), so a live install registers all four as hooks in settings.json
|
||||
* routed through gsd-context-monitor.js, giving CodeBuddy the
|
||||
* subagent-lifecycle + stop/compact hooks it previously lacked.
|
||||
*
|
||||
* UPGRADE 2 — dispatch.background: CodeBuddy's capability.json already
|
||||
* declares `dispatch.background: true`, which legitimately EXCEEDS the
|
||||
* `declarative-cli` profile baseline (`false`, per
|
||||
* `PROFILE_BASELINES['declarative-cli']` in src/host-integration.cts).
|
||||
* NO agent-file/frontmatter change is involved — the CodeBuddy CLI has no
|
||||
* background-dispatch frontmatter field (agentMode/enabledAutoRun are
|
||||
* IDE-only; verified via codebuddy.ai/docs/cli/sub-agents). This is
|
||||
* surfaced purely through the negotiated contract: a documented `true`
|
||||
* value must survive negotiation without a downgrade warning.
|
||||
*/
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const { runMinimalInstall } = require('./helpers/install-shared.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const {
|
||||
profileOf,
|
||||
negotiateHostCapabilities,
|
||||
PROFILE_BASELINES,
|
||||
} = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
|
||||
const CODEBUDDY_CAP = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, '..', 'capabilities', 'codebuddy', 'capability.json'), 'utf8'),
|
||||
);
|
||||
const CODEBUDDY_AXES = CODEBUDDY_CAP.runtime.hostIntegration;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UPGRADE 1: extended hook events — all 4 newly-wired events' live-install coverage
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('capabilities/codebuddy/capability.json extendedHookEvents contains exactly the 4 documented events', () => {
|
||||
const events = CODEBUDDY_CAP.runtime.extendedHookEvents;
|
||||
assert.deepEqual(events, ['SubagentStop', 'Stop', 'PreCompact', 'SubagentStart']);
|
||||
assert.equal(events.length, 4);
|
||||
});
|
||||
|
||||
test('codebuddy --global: settings.json wires all 4 newly-added extended hook events to the GSD context-monitor hook (UPGRADE 1)', (t) => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'codebuddy', scope: 'global' });
|
||||
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'));
|
||||
|
||||
// All 4 events were newly wired by this PR — codebuddy's extendedHookEvents
|
||||
// was previously [], so none of these existed before #2098.
|
||||
const NEWLY_WIRED_EXTENDED_EVENTS = ['SubagentStop', 'Stop', 'PreCompact', 'SubagentStart'];
|
||||
|
||||
const entries = NEWLY_WIRED_EXTENDED_EVENTS.map((eventName) => {
|
||||
const eventHooks = settings.hooks && settings.hooks[eventName];
|
||||
assert.ok(Array.isArray(eventHooks) && eventHooks.length > 0,
|
||||
`settings.hooks.${eventName} must exist and be non-empty`);
|
||||
const entry = eventHooks[0].hooks[0];
|
||||
assert.ok(entry.command.includes('gsd-context-monitor'),
|
||||
`${eventName} command must reference gsd-context-monitor.js, got: ${entry.command}`);
|
||||
assert.equal(entry.timeout, 10, `${eventName} entry must have timeout 10`);
|
||||
return entry;
|
||||
});
|
||||
|
||||
const [stopEntry, ...restEntries] = entries;
|
||||
for (const entry of restEntries) {
|
||||
assert.equal(entry.command, stopEntry.command,
|
||||
'all 4 newly-wired extended events must wire the same gsd-context-monitor command');
|
||||
}
|
||||
});
|
||||
|
||||
test('a runtime whose extendedHookEvents omits SubagentStart does NOT get one (descriptor-gated, not a global default)', (t) => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'claude', scope: 'global' });
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
const settingsPath = path.join(configDir, 'settings.json');
|
||||
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
||||
|
||||
assert.ok(
|
||||
settings.hooks && Array.isArray(settings.hooks.SubagentStop) && settings.hooks.SubagentStop.length > 0,
|
||||
'claude must have SubagentStop wired (sanity — proves hooks ARE configured)',
|
||||
);
|
||||
assert.ok(
|
||||
!settings.hooks || settings.hooks.SubagentStart === undefined,
|
||||
"claude must NOT have SubagentStart wired — it is not in claude's extendedHookEvents",
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UPGRADE 2: dispatch.background negotiation — documented true survives,
|
||||
// exceeding the declarative-cli profile baseline. No agent-file/frontmatter
|
||||
// change; caller-side invocation param only (no code path emits it).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("codebuddy classifies as the 'declarative-cli' profile, whose baseline dispatch.background is false", () => {
|
||||
assert.equal(profileOf(CODEBUDDY_AXES), 'declarative-cli');
|
||||
assert.equal(PROFILE_BASELINES['declarative-cli'].dispatch.background, false,
|
||||
'sanity: the declarative-cli baseline is false — codebuddy legitimately exceeds it');
|
||||
});
|
||||
|
||||
test('negotiateHostCapabilities surfaces codebuddy\'s documented dispatch.background:true with no downgrade warning (UPGRADE 2)', () => {
|
||||
assert.equal(CODEBUDDY_AXES.dispatch.background, true,
|
||||
'sanity: the descriptor declares dispatch.background: true (documented, not undocumented)');
|
||||
|
||||
const { effective, warnings } = negotiateHostCapabilities(CODEBUDDY_AXES);
|
||||
|
||||
assert.equal(effective.dispatch.background, true,
|
||||
'a documented true value must survive negotiation, exceeding the declarative-cli baseline of false');
|
||||
assert.ok(
|
||||
!warnings.some((w) => w.includes('dispatch.background')),
|
||||
`no warning may be raised for the documented dispatch.background axis, got: ${JSON.stringify(warnings)}`,
|
||||
);
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
// allow-test-rule: structural-regression-guard — AC2 requires asserting no `runtime === 'antigravity'` string-equality branch (nor an `isAntigravity` helper, nor a `canonical === 'antigravity'` branch) remains in bin/install.js, src/runtime-artifact-conversion.cts, src/shell-command-projection.cts, and src/runtime-name-policy.cts — the descriptor-migration contract is a property of the source text, so a source-grep is the only faithful check (#2096)
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -15,6 +16,17 @@
|
||||
* profile via profileOf, (2) confirms the public adapter classifies it as
|
||||
* declarative, and (3) round-trips a real install proving a gsd command surface
|
||||
* is emitted through the same engine the adapter delegates to.
|
||||
*
|
||||
* #2096 (EoS/antigravity) additions: negotiation fails CLOSED on a corrupted
|
||||
* descriptor, the 4 still-`undocumented` dispatch sub-axes (namedDispatch/
|
||||
* nested/maxDepth/backgroundDispatch) degrade to the most-restrictive known
|
||||
* value (never their optimistic value), the validator accepts the negotiated
|
||||
* subagentToolkit:'full' + permissionWriter:'antigravity' upgrade, and the
|
||||
* hardcoded `runtime === 'antigravity'` / `isAntigravity` / `canonical ===
|
||||
* 'antigravity'` branches are retired from the folded modules (folded into
|
||||
* descriptor-driven `runtime.hostBehaviors` + `runtime.hostIntegration`).
|
||||
* UPGRADE 1 (permission-writer) + UPGRADE 2 (MCP companion) live-install
|
||||
* coverage is in tests/antigravity-upgrades.test.cjs — not duplicated here.
|
||||
*/
|
||||
|
||||
const { test, before } = require('node:test');
|
||||
@@ -23,12 +35,20 @@ const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const { profileOf } = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
const {
|
||||
profileOf,
|
||||
negotiateHostCapabilities,
|
||||
PROFILE_BASELINES,
|
||||
UNDOCUMENTED,
|
||||
} = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
const { validateCapability } = require('../gsd-core/bin/lib/capability-validator.cjs');
|
||||
const { createDeclarativeAdapter } = require('../gsd-core/bin/lib/adapter-declarative.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const { walk, runMinimalInstall, BUILD_SCRIPT } = require('./helpers/install-shared.cjs');
|
||||
|
||||
const DESC = path.join(__dirname, '..', 'capabilities', 'antigravity', 'capability.json');
|
||||
const ANTIGRAVITY_CAP = JSON.parse(fs.readFileSync(DESC, 'utf8'));
|
||||
const ANTIGRAVITY_AXES = ANTIGRAVITY_CAP.runtime.hostIntegration;
|
||||
|
||||
// hooks/dist is gitignored and built (mirrors golden-install-parity harness).
|
||||
before(() => {
|
||||
@@ -66,6 +86,130 @@ test('a real Antigravity install emits a gsd command/skill surface (invocable)',
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// #2096 EoS/antigravity — AC3/AC5: fail-closed negotiation + validator
|
||||
// acceptance + the folded descriptor (mirrors kimi/codex reference tests).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// -- AC5: negotiation fails CLOSED on a corrupted descriptor ------------------
|
||||
|
||||
test('negotiateHostCapabilities never throws for antigravity, even fully corrupted', () => {
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({}));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...ANTIGRAVITY_AXES, embeddingMode: UNDOCUMENTED }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...ANTIGRAVITY_AXES, embeddingMode: 'future-unknown' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...ANTIGRAVITY_AXES, dispatch: 'corrupted-not-an-object' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...ANTIGRAVITY_AXES, dispatch: { ...ANTIGRAVITY_AXES.dispatch, maxDepth: 'not-a-number' } }));
|
||||
});
|
||||
|
||||
test('a partial/empty antigravity descriptor degrades to the safe floor, not the declarative-cli baseline', () => {
|
||||
const result = negotiateHostCapabilities({});
|
||||
assert.equal(result.effective.embeddingMode, 'declarative', 'omitted embeddingMode degrades closed');
|
||||
assert.equal(result.effective.hookBus, 'none');
|
||||
assert.notDeepEqual(result.effective, PROFILE_BASELINES['declarative-cli']);
|
||||
assert.ok(result.warnings.length > 0);
|
||||
});
|
||||
|
||||
// AC-specific: the 4 still-undocumented dispatch sub-axes must degrade to the
|
||||
// most-restrictive KNOWN value, not their optimistic value. Real values below
|
||||
// were confirmed via:
|
||||
// node -e "const {negotiateHostCapabilities}=require('./gsd-core/bin/lib/host-integration.cjs');
|
||||
// const cap=require('./capabilities/antigravity/capability.json');
|
||||
// console.log(negotiateHostCapabilities(cap.runtime.hostIntegration).effective.dispatch)"
|
||||
// -> { namedDispatch:false, nested:false, maxDepth:0, background:false, subagentToolkit:'full', backgroundDispatch:false }
|
||||
test("antigravity's 4 still-undocumented dispatch sub-axes (namedDispatch/nested/maxDepth/backgroundDispatch) degrade to the most-restrictive known value, not their optimistic value", () => {
|
||||
// Sanity: the descriptor itself still declares these 4 as the undocumented
|
||||
// sentinel. subagentToolkit is the ONE dispatch axis Context7 confirmed as
|
||||
// 'full' (antigravity.google/docs/cli/features) — it is deliberately NOT
|
||||
// part of this still-undocumented set.
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.namedDispatch, 'undocumented');
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.nested, 'undocumented');
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.maxDepth, 'undocumented');
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.backgroundDispatch, 'undocumented');
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.subagentToolkit, 'full', 'sanity: subagentToolkit is documented, not part of the undocumented set');
|
||||
|
||||
const { effective, warnings } = negotiateHostCapabilities(ANTIGRAVITY_AXES);
|
||||
|
||||
assert.equal(effective.dispatch.namedDispatch, false, 'undocumented namedDispatch must degrade to false, never true');
|
||||
assert.equal(effective.dispatch.nested, false, 'undocumented nested must degrade to false, never true');
|
||||
assert.equal(effective.dispatch.maxDepth, 0, 'undocumented maxDepth must degrade to 0, never -1/unbounded');
|
||||
assert.equal(effective.dispatch.backgroundDispatch, false, 'undocumented backgroundDispatch must degrade to false, never true');
|
||||
|
||||
// subagentToolkit is documented 'full' (not undocumented) — it is trusted
|
||||
// and survives negotiation, in contrast to the 4 sub-axes above.
|
||||
assert.equal(effective.dispatch.subagentToolkit, 'full', "documented 'full' subagentToolkit is trusted, unlike the undocumented sub-axes");
|
||||
|
||||
// background is declared `true` (documented, not undocumented) but the
|
||||
// struct-consistency cap in negotiateHostCapabilities still zeroes it
|
||||
// because its sibling namedDispatch degraded to false — a host-declared
|
||||
// `true` never overrides the fail-closed floor forced by a degraded axis.
|
||||
assert.equal(effective.dispatch.background, false, 'background is capped to false once namedDispatch degrades closed');
|
||||
|
||||
for (const axis of ['namedDispatch', 'nested', 'backgroundDispatch']) {
|
||||
assert.ok(
|
||||
warnings.some((w) => w.includes(`dispatch.${axis}`) && w.includes('undocumented')),
|
||||
`a warning must be raised for the undocumented dispatch.${axis} axis`,
|
||||
);
|
||||
}
|
||||
assert.ok(
|
||||
warnings.some((w) => w.includes('dispatch.maxDepth')),
|
||||
'a warning must be raised for the undocumented dispatch.maxDepth axis (reported as missing/non-number)',
|
||||
);
|
||||
});
|
||||
|
||||
// -- AC3: the validator accepts the negotiated/folded descriptor values ------
|
||||
|
||||
test('capabilities/antigravity/capability.json validates — subagentToolkit "full" + permissionWriter "antigravity" are accepted', () => {
|
||||
const errors = validateCapability(ANTIGRAVITY_CAP, 'antigravity');
|
||||
assert.deepEqual(errors, [], `validateCapability must return no errors, got: ${JSON.stringify(errors)}`);
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.subagentToolkit, 'full');
|
||||
assert.equal(ANTIGRAVITY_CAP.runtime.permissionWriter, 'antigravity');
|
||||
});
|
||||
|
||||
// -- AC2: the folded-in hostBehaviors + subagentToolkit upgrade --------------
|
||||
|
||||
test('antigravity descriptor declares runtime.hostBehaviors (the folded-in behaviors) + the subagentToolkit upgrade', () => {
|
||||
const hb = ANTIGRAVITY_CAP.runtime.hostBehaviors;
|
||||
assert.ok(hb && typeof hb === 'object');
|
||||
assert.equal(hb.reviewerCli, true);
|
||||
assert.equal(hb.projectInstructionFile, 'GEMINI.md');
|
||||
assert.equal(hb.noPathRewrite, true);
|
||||
assert.equal(hb.hookPathStyle, 'raw');
|
||||
assert.equal(ANTIGRAVITY_AXES.dispatch.subagentToolkit, 'full',
|
||||
'subagentToolkit flipped undocumented -> full (antigravity.google/docs/cli/features)');
|
||||
});
|
||||
|
||||
// -- AC2: the hardcoded branches are retired across all folded modules -------
|
||||
|
||||
test('no `runtime === "antigravity"` string-equality branch (nor `isAntigravity` / `canonical === "antigravity"`) remains in the descriptor-migrated modules (AC2)', () => {
|
||||
const strip = (src) => src
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||
.replace(/\/\/[^\r\n]*/g, '')
|
||||
.replace(/`[^`]*`/g, '');
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const files = [
|
||||
path.join(repoRoot, 'bin', 'install.js'),
|
||||
path.join(repoRoot, 'src', 'runtime-artifact-conversion.cts'),
|
||||
path.join(repoRoot, 'src', 'shell-command-projection.cts'),
|
||||
path.join(repoRoot, 'src', 'runtime-name-policy.cts'),
|
||||
];
|
||||
for (const file of files) {
|
||||
const src = fs.readFileSync(file, 'utf8');
|
||||
const stripped = strip(src);
|
||||
|
||||
const eqOffenders = stripped.match(/runtime\s*[!=]==\s*'antigravity'/g) || [];
|
||||
assert.deepEqual(eqOffenders, [],
|
||||
`AC2: no hardcoded runtime==='antigravity' branch may remain in ${path.relative(repoRoot, file)}; found: ${eqOffenders.join(', ')}`);
|
||||
|
||||
const isAntigravityHits = stripped.match(/\bisAntigravity\b/g) || [];
|
||||
assert.deepEqual(isAntigravityHits, [],
|
||||
`AC2: no isAntigravity helper may remain in ${path.relative(repoRoot, file)}; found ${isAntigravityHits.length} occurrence(s)`);
|
||||
|
||||
const canonicalOffenders = stripped.match(/canonical\s*===\s*'antigravity'/g) || [];
|
||||
assert.deepEqual(canonicalOffenders, [],
|
||||
`AC2: no canonical==='antigravity' branch may remain in ${path.relative(repoRoot, file)}; found: ${canonicalOffenders.join(', ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
// Folded from tests/bug-3608-antigravity-update-runtime-classification.test.cjs — consolidation epic #1969 (B3 #1972)
|
||||
|
||||
202
tests/declarative-reference-augment.test.cjs
Normal file
202
tests/declarative-reference-augment.test.cjs
Normal file
@@ -0,0 +1,202 @@
|
||||
// allow-test-rule: structural-regression-guard — the descriptor-migration contract (no `runtime === 'augment'` / `isAugment`-as-conversion-branch dispatch logic left in the folded modules) is a property of the source text itself, so a source-grep is the only faithful check (#2097, mirrors tests/declarative-reference-antigravity.test.cjs #2096 AC2 guard).
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Declarative reference host coverage — Augment Code (ADR-1239 / #2097
|
||||
* EoS/augment migration).
|
||||
*
|
||||
* Augment is already a declarative-CLI host (nested-skill artifact layout,
|
||||
* settings-json hook surface, Claude hook event dialect). #2097 folds its two
|
||||
* remaining runtime-literal branches in src/runtime-artifact-conversion.cts
|
||||
* onto descriptor-driven dispatch (runtime.hostBehaviors.commandBodyConverter)
|
||||
* and deletes 2 dead-code sites in bin/install.js — mirroring the Antigravity
|
||||
* migration (#2096) structure without duplicating its Antigravity-specific
|
||||
* (GEMINI.md / reviewerCli / noPathRewrite) assertions.
|
||||
*
|
||||
* UPGRADE 3 (MCP companion, settings.json-hosted) live-install coverage is in
|
||||
* tests/augment-upgrades.test.cjs — not duplicated here.
|
||||
*/
|
||||
|
||||
const { test, before } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const {
|
||||
profileOf,
|
||||
negotiateHostCapabilities,
|
||||
UNDOCUMENTED,
|
||||
} = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
const { createDeclarativeAdapter } = require('../gsd-core/bin/lib/adapter-declarative.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const { walk, runMinimalInstall, BUILD_SCRIPT } = require('./helpers/install-shared.cjs');
|
||||
|
||||
const DESC = path.join(__dirname, '..', 'capabilities', 'augment', 'capability.json');
|
||||
const AUGMENT_CAP = JSON.parse(fs.readFileSync(DESC, 'utf8'));
|
||||
const AUGMENT_AXES = AUGMENT_CAP.runtime.hostIntegration;
|
||||
|
||||
// hooks/dist is gitignored and built (mirrors golden-install-parity harness).
|
||||
before(() => {
|
||||
execFileSync(process.execPath, [BUILD_SCRIPT], { encoding: 'utf-8', stdio: 'pipe' });
|
||||
});
|
||||
|
||||
test('Augment classifies as the declarative-cli profile (profileOf)', () => {
|
||||
const desc = JSON.parse(fs.readFileSync(DESC, 'utf8'));
|
||||
const axes = desc.runtime.hostIntegration;
|
||||
assert.ok(axes && axes.embeddingMode, 'augment descriptor declares hostIntegration axes');
|
||||
assert.equal(profileOf(axes), 'declarative-cli', 'Augment is a declarative-CLI host');
|
||||
});
|
||||
|
||||
test('the public declarative adapter classifies Augment as a declarative host', () => {
|
||||
const adapter = createDeclarativeAdapter({ runtime: 'augment' });
|
||||
assert.equal(adapter.kind, 'declarative');
|
||||
assert.equal(adapter.runtime, 'augment');
|
||||
assert.equal(typeof adapter.install, 'function');
|
||||
assert.equal(typeof adapter.uninstall, 'function');
|
||||
});
|
||||
|
||||
test('a real Augment install emits a gsd command/skill surface (invocable)', () => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'augment', scope: 'global' });
|
||||
try {
|
||||
const files = walk(configDir);
|
||||
assert.ok(files.length > 0, 'install must emit artifacts');
|
||||
const gsdSurface = files.filter((f) => /gsd/i.test(path.relative(configDir, f)));
|
||||
assert.ok(gsdSurface.length > 0,
|
||||
'install must emit a gsd command/skill surface (declarative reference)');
|
||||
} finally {
|
||||
cleanup(root);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// #2097 EoS/augment — fail-closed negotiation + folded dispatch sub-axes
|
||||
// (mirrors the antigravity/kimi reference tests).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('negotiateHostCapabilities never throws for augment, even fully corrupted', () => {
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({}));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...AUGMENT_AXES, embeddingMode: UNDOCUMENTED }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...AUGMENT_AXES, embeddingMode: 'future-unknown' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...AUGMENT_AXES, dispatch: 'corrupted-not-an-object' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...AUGMENT_AXES, dispatch: { ...AUGMENT_AXES.dispatch, maxDepth: 'not-a-number' } }));
|
||||
});
|
||||
|
||||
// AC-style proof: the 3 still-`undocumented` dispatch sub-axes (nested/
|
||||
// maxDepth/backgroundDispatch) must degrade to the most-restrictive KNOWN
|
||||
// value, never their optimistic value — mirrors antigravity's equivalent
|
||||
// test, but Augment documents namedDispatch/background (unlike antigravity),
|
||||
// so only 3 sub-axes are undocumented here, not 4. Real values confirmed via:
|
||||
// node -e "const {negotiateHostCapabilities}=require('./gsd-core/bin/lib/host-integration.cjs');
|
||||
// const cap=require('./capabilities/augment/capability.json');
|
||||
// console.log(negotiateHostCapabilities(cap.runtime.hostIntegration).effective.dispatch)"
|
||||
// -> { namedDispatch:true, nested:false, maxDepth:0, background:true, subagentToolkit:'full', backgroundDispatch:false }
|
||||
test("augment's 3 still-undocumented dispatch sub-axes (nested/maxDepth/backgroundDispatch) degrade to the most-restrictive known value, not their optimistic value", () => {
|
||||
// Sanity: the descriptor itself still declares these 3 as the undocumented
|
||||
// sentinel, while namedDispatch/background/subagentToolkit are documented.
|
||||
assert.equal(AUGMENT_AXES.dispatch.nested, 'undocumented');
|
||||
assert.equal(AUGMENT_AXES.dispatch.maxDepth, 'undocumented');
|
||||
assert.equal(AUGMENT_AXES.dispatch.backgroundDispatch, 'undocumented');
|
||||
assert.equal(AUGMENT_AXES.dispatch.namedDispatch, true, 'sanity: namedDispatch is documented, not part of the undocumented set');
|
||||
assert.equal(AUGMENT_AXES.dispatch.background, true, 'sanity: background is documented, not part of the undocumented set');
|
||||
assert.equal(AUGMENT_AXES.dispatch.subagentToolkit, 'full', 'sanity: subagentToolkit is documented, not part of the undocumented set');
|
||||
|
||||
const { effective, warnings } = negotiateHostCapabilities(AUGMENT_AXES);
|
||||
|
||||
assert.equal(effective.dispatch.nested, false, 'undocumented nested must degrade to false, never true');
|
||||
assert.equal(effective.dispatch.maxDepth, 0, 'undocumented maxDepth must degrade to 0, never -1/unbounded');
|
||||
assert.equal(effective.dispatch.backgroundDispatch, false, 'undocumented backgroundDispatch must degrade to false, never true');
|
||||
|
||||
// namedDispatch/background/subagentToolkit are documented — they are
|
||||
// trusted and survive negotiation unchanged, in contrast to the 3
|
||||
// undocumented sub-axes above. Augment's negotiation must NOT flatten
|
||||
// dispatch the way a fully-undocumented descriptor (e.g. antigravity's
|
||||
// namedDispatch) would.
|
||||
assert.equal(effective.dispatch.namedDispatch, true, "documented 'true' namedDispatch is trusted, unlike the undocumented sub-axes");
|
||||
assert.equal(effective.dispatch.background, true, "documented 'true' background is trusted — not capped to false, since namedDispatch did not degrade closed");
|
||||
assert.equal(effective.dispatch.subagentToolkit, 'full', "documented 'full' subagentToolkit is trusted, unlike the undocumented sub-axes");
|
||||
|
||||
for (const axis of ['nested', 'backgroundDispatch']) {
|
||||
assert.ok(
|
||||
warnings.some((w) => w.includes(`dispatch.${axis}`) && w.includes('undocumented')),
|
||||
`a warning must be raised for the undocumented dispatch.${axis} axis`,
|
||||
);
|
||||
}
|
||||
assert.ok(
|
||||
warnings.some((w) => w.includes('dispatch.maxDepth')),
|
||||
'a warning must be raised for the undocumented dispatch.maxDepth axis (reported as missing/non-number)',
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// #2097 AC2-equivalent — the hardcoded conversion-dispatch branches folded by
|
||||
// this migration are retired from the folded modules.
|
||||
//
|
||||
// Unlike antigravity (#2096), where `isAntigravity` was eliminated from
|
||||
// bin/install.js entirely, Augment's `isAugment` flag legitimately remains
|
||||
// (destructured from runtimeFlags() and used for non-conversion verification
|
||||
// logic — e.g. counting installed commands/ files). So this guard does NOT
|
||||
// assert zero `isAugment` occurrences (that would be a false failure); it
|
||||
// asserts no `isAugment` occurrence gates a call to an Augment *converter*
|
||||
// function (the exact shape of the dead branch this migration deleted:
|
||||
// `else if (isAugment) { content = convertClaudeAgentToAugmentAgent(content); }`).
|
||||
// The switch `case 'augment':` label in _applyRuntimeRewrites is intentionally
|
||||
// NOT flagged — it does plain dirName-derived path-prefix rewriting (same as
|
||||
// the still-`case`-labeled trae/codebuddy/cursor/windsurf branches), not
|
||||
// conversion-function dispatch, and antigravity's own guard tolerates its
|
||||
// `case 'antigravity':` label for the identical reason (its regex only
|
||||
// matches `runtime === 'x'`, never a `case` label).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('no `runtime === "augment"` string-equality branch remains in the descriptor-migrated modules', () => {
|
||||
const strip = (src) => src
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||
.replace(/\/\/[^\r\n]*/g, '')
|
||||
.replace(/`[^`]*`/g, '');
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const files = [
|
||||
path.join(repoRoot, 'bin', 'install.js'),
|
||||
path.join(repoRoot, 'src', 'runtime-artifact-conversion.cts'),
|
||||
];
|
||||
for (const file of files) {
|
||||
const src = fs.readFileSync(file, 'utf8');
|
||||
const stripped = strip(src);
|
||||
const eqOffenders = stripped.match(/runtime\s*[!=]==\s*'augment'/g) || [];
|
||||
assert.deepEqual(eqOffenders, [],
|
||||
`no hardcoded runtime==='augment' branch may remain in ${path.relative(repoRoot, file)}; found: ${eqOffenders.join(', ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('no `isAugment` occurrence gates a call to an Augment converter function (the deleted dead-code shape)', () => {
|
||||
const converterNames = [
|
||||
'convertClaudeAgentToAugmentAgent',
|
||||
'convertClaudeToAugmentMarkdown',
|
||||
'convertClaudeCommandToAugmentSkill',
|
||||
'convertSlashCommandsToAugmentSkillMentions',
|
||||
];
|
||||
const converterCallPattern = new RegExp(`(${converterNames.join('|')})\\s*\\(`);
|
||||
|
||||
const file = path.join(__dirname, '..', 'bin', 'install.js');
|
||||
const lines = fs.readFileSync(file, 'utf8').split(/\r?\n/);
|
||||
const offenders = [];
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
// Only condition-position occurrences count (`if (isAugment)` / `else if
|
||||
// (isAugment)`), not the runtimeFlags() destructure or unrelated reads.
|
||||
if (!/(?:if|else if)\s*\(\s*isAugment\s*\)/.test(line)) continue;
|
||||
const window = lines.slice(i, i + 4).join('\n');
|
||||
if (converterCallPattern.test(window)) {
|
||||
offenders.push(`line ${i + 1}: ${line.trim()}`);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(offenders, [],
|
||||
`no isAugment-gated call to an Augment converter may remain in bin/install.js; found: ${offenders.join(' | ')}`);
|
||||
});
|
||||
|
||||
test('legitimate isAugment destructure/enumeration sites survive (not eliminated, unlike isAntigravity)', () => {
|
||||
const file = path.join(__dirname, '..', 'bin', 'install.js');
|
||||
const src = fs.readFileSync(file, 'utf8');
|
||||
assert.ok(/isAugment/.test(src), 'isAugment must still be destructured from runtimeFlags() for non-conversion uses');
|
||||
assert.ok(/_DESCRIPTOR_AGENTS_RUNTIMES\s*=\s*new Set\(\[[^\]]*'augment'/.test(src),
|
||||
'augment must remain in _DESCRIPTOR_AGENTS_RUNTIMES (descriptor-driven agent layout)');
|
||||
});
|
||||
155
tests/declarative-reference-codebuddy.test.cjs
Normal file
155
tests/declarative-reference-codebuddy.test.cjs
Normal file
@@ -0,0 +1,155 @@
|
||||
// allow-test-rule: structural-regression-guard — AC2: assert no `runtime === 'codebuddy'` string-equality branch, no `isCodebuddy` conversion helper, no `canonical === 'codebuddy'` branch remains in bin/install.js, src/runtime-artifact-conversion.cts, src/shell-command-projection.cts, src/runtime-name-policy.cts — a source-text property, so source-grep is the faithful check (#2098)
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Declarative reference host — CodeBuddy (#2098 / ADR-1239 EoS).
|
||||
*
|
||||
* CodeBuddy already installs through the descriptor-driven artifactLayout
|
||||
* (commands/skills/agents, each with a named `converter`), and its
|
||||
* capability.json already declares `hostIntegration` + `dispatch` axes.
|
||||
* Unlike antigravity/qwen (#2096/#2092), CodeBuddy was NOT migrated off a
|
||||
* legacy runtime-keyed branch chain wholesale — issue #2098 found it was
|
||||
* already descriptor-driven except for two residual `isCodebuddy` branches
|
||||
* in bin/install.js:
|
||||
* 1. a duplicate `commands/` slash-command output report (byte-identical
|
||||
* to the generic `hostBehaviors.reportCommandsDir` block already used
|
||||
* by Cursor) — folded onto `hostBehaviors.reportCommandsDir` and deleted.
|
||||
* 2. a dead legacy agent-converter dispatch arm in the inline agent-copy
|
||||
* loop, unreachable because codebuddy is a member of
|
||||
* `_DESCRIPTOR_AGENTS_RUNTIMES` (installRuntimeArtifacts already wrote
|
||||
* the agents before that loop runs) — deleted outright.
|
||||
*
|
||||
* This test is the reference-host dogfood mirroring
|
||||
* tests/declarative-reference-antigravity.test.cjs: it (1) classifies
|
||||
* CodeBuddy's profile via profileOf, (2) confirms the public declarative
|
||||
* adapter classifies it as declarative, (3) round-trips a real install
|
||||
* proving a gsd command surface is emitted, (4) proves negotiation fails
|
||||
* CLOSED on a corrupted descriptor, (5) proves the validator accepts the
|
||||
* descriptor, and (6) source-greps the folded modules for the retired
|
||||
* `isCodebuddy` branches (AC2).
|
||||
*
|
||||
* UPGRADE 1 (extended hook events) + UPGRADE 2 (dispatch.background
|
||||
* negotiation) live-install coverage is in tests/codebuddy-upgrades.test.cjs
|
||||
* — not duplicated here.
|
||||
*/
|
||||
|
||||
const { test, before } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const {
|
||||
profileOf,
|
||||
negotiateHostCapabilities,
|
||||
PROFILE_BASELINES,
|
||||
UNDOCUMENTED,
|
||||
} = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
const { validateCapability } = require('../gsd-core/bin/lib/capability-validator.cjs');
|
||||
const { createDeclarativeAdapter } = require('../gsd-core/bin/lib/adapter-declarative.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const { walk, runMinimalInstall, BUILD_SCRIPT } = require('./helpers/install-shared.cjs');
|
||||
|
||||
const DESC = path.join(__dirname, '..', 'capabilities', 'codebuddy', 'capability.json');
|
||||
const CODEBUDDY_CAP = JSON.parse(fs.readFileSync(DESC, 'utf8'));
|
||||
const CODEBUDDY_AXES = CODEBUDDY_CAP.runtime.hostIntegration;
|
||||
|
||||
// hooks/dist is gitignored and built (mirrors golden-install-parity harness).
|
||||
before(() => {
|
||||
execFileSync(process.execPath, [BUILD_SCRIPT], { encoding: 'utf-8', stdio: 'pipe' });
|
||||
});
|
||||
|
||||
test('CodeBuddy classifies as the declarative-cli reference profile (profileOf)', () => {
|
||||
const desc = JSON.parse(fs.readFileSync(DESC, 'utf8'));
|
||||
const axes = desc.runtime.hostIntegration;
|
||||
assert.ok(axes && axes.embeddingMode, 'codebuddy descriptor declares hostIntegration axes');
|
||||
assert.equal(profileOf(axes), 'declarative-cli',
|
||||
'CodeBuddy is a Declarative-CLI host');
|
||||
});
|
||||
|
||||
test('the public declarative adapter classifies CodeBuddy as a declarative host', () => {
|
||||
const adapter = createDeclarativeAdapter({ runtime: 'codebuddy' });
|
||||
assert.equal(adapter.kind, 'declarative');
|
||||
assert.equal(adapter.runtime, 'codebuddy');
|
||||
assert.equal(typeof adapter.install, 'function');
|
||||
assert.equal(typeof adapter.uninstall, 'function');
|
||||
});
|
||||
|
||||
test('a real CodeBuddy install emits a gsd command/skill surface (invocable)', () => {
|
||||
const { configDir, root } = runMinimalInstall({ runtime: 'codebuddy', scope: 'global' });
|
||||
try {
|
||||
const files = walk(configDir);
|
||||
assert.ok(files.length > 0, 'install must emit artifacts');
|
||||
// CodeBuddy uses a flat commands/gsd-*.md slash-command surface
|
||||
// (CONTEXT.md installer module; capabilities/codebuddy/capability.json
|
||||
// artifactLayout `kind: "commands"`).
|
||||
const gsdSurface = files.filter((f) => /gsd/i.test(path.relative(configDir, f)));
|
||||
assert.ok(gsdSurface.length > 0,
|
||||
'install must emit a gsd command/skill surface (declarative reference)');
|
||||
const commandsDir = path.join(configDir, 'commands');
|
||||
assert.ok(fs.existsSync(commandsDir), 'commands/ directory must exist');
|
||||
const cmdFiles = fs.readdirSync(commandsDir)
|
||||
.filter((f) => f.startsWith('gsd-') && f.endsWith('.md'));
|
||||
assert.ok(cmdFiles.length > 0, 'commands/ must contain gsd-*.md slash commands');
|
||||
} finally {
|
||||
cleanup(root);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// #2098 EoS/codebuddy — fail-closed negotiation + validator acceptance +
|
||||
// the folded descriptor (mirrors antigravity/qwen reference tests).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('negotiateHostCapabilities never throws for codebuddy, even fully corrupted', () => {
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({}));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...CODEBUDDY_AXES, embeddingMode: UNDOCUMENTED }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...CODEBUDDY_AXES, embeddingMode: 'future-unknown' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...CODEBUDDY_AXES, dispatch: 'corrupted-not-an-object' }));
|
||||
assert.doesNotThrow(() => negotiateHostCapabilities({ ...CODEBUDDY_AXES, dispatch: { ...CODEBUDDY_AXES.dispatch, maxDepth: 'not-a-number' } }));
|
||||
});
|
||||
|
||||
test('a partial/empty codebuddy descriptor degrades to the safe floor, not the declarative-cli baseline', () => {
|
||||
const result = negotiateHostCapabilities({});
|
||||
assert.equal(result.effective.embeddingMode, 'declarative', 'omitted embeddingMode degrades closed');
|
||||
assert.equal(result.effective.hookBus, 'none');
|
||||
assert.notDeepEqual(result.effective, PROFILE_BASELINES['declarative-cli']);
|
||||
assert.ok(result.warnings.length > 0);
|
||||
});
|
||||
|
||||
test('capabilities/codebuddy/capability.json validates — no errors', () => {
|
||||
const errors = validateCapability(CODEBUDDY_CAP, 'codebuddy');
|
||||
assert.deepEqual(errors, [], `validateCapability must return no errors, got: ${JSON.stringify(errors)}`);
|
||||
});
|
||||
|
||||
// -- AC2: the hardcoded branches are retired across all folded modules -------
|
||||
|
||||
test('no `runtime === "codebuddy"` string-equality branch (nor `isCodebuddy` conversion helper / `canonical === "codebuddy"`) remains in the descriptor-migrated modules (AC2)', () => {
|
||||
const strip = (src) => src
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||
.replace(/\/\/[^\r\n]*/g, '')
|
||||
.replace(/`[^`]*`/g, '');
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const files = [
|
||||
path.join(repoRoot, 'bin', 'install.js'),
|
||||
path.join(repoRoot, 'src', 'runtime-artifact-conversion.cts'),
|
||||
path.join(repoRoot, 'src', 'shell-command-projection.cts'),
|
||||
path.join(repoRoot, 'src', 'runtime-name-policy.cts'),
|
||||
];
|
||||
for (const file of files) {
|
||||
const src = fs.readFileSync(file, 'utf8');
|
||||
const stripped = strip(src);
|
||||
|
||||
const eqOffenders = stripped.match(/runtime\s*[!=]==\s*'codebuddy'/g) || [];
|
||||
assert.deepEqual(eqOffenders, [],
|
||||
`AC2: no hardcoded runtime==='codebuddy' branch may remain in ${path.relative(repoRoot, file)}; found: ${eqOffenders.join(', ')}`);
|
||||
|
||||
const isCodebuddyHits = stripped.match(/\bisCodebuddy\b/g) || [];
|
||||
assert.deepEqual(isCodebuddyHits, [],
|
||||
`AC2: no live isCodebuddy read may remain in ${path.relative(repoRoot, file)}; found ${isCodebuddyHits.length} occurrence(s)`);
|
||||
|
||||
const canonicalOffenders = stripped.match(/canonical\s*===\s*'codebuddy'/g) || [];
|
||||
assert.deepEqual(canonicalOffenders, [],
|
||||
`AC2: no canonical==='codebuddy' branch may remain in ${path.relative(repoRoot, file)}; found: ${canonicalOffenders.join(', ')}`);
|
||||
}
|
||||
});
|
||||
@@ -336,6 +336,7 @@
|
||||
"hooks/lib/git-cmd.js": "268ba15992ca0b23",
|
||||
"hooks/lib/gsd-graphify-rebuild.sh": "66af89601074d2a9",
|
||||
"hooks/managed-hooks-registry.cjs": "721d696556b7509f",
|
||||
"mcp_config.json": "9956d6a6e88a49e1",
|
||||
"package.json": "dbf8353f77358bc1",
|
||||
"scripts/changeset/README.md": "86ff89331dfd94b2",
|
||||
"scripts/changeset/cli.cjs": "68f92a344b199271",
|
||||
|
||||
@@ -343,9 +343,14 @@ describe('bug #1906: local hook commands use $CLAUDE_PROJECT_DIR', () => {
|
||||
* dir as cwd. Claude Code and others still use "$CLAUDE_PROJECT_DIR"/ (#1906).
|
||||
*
|
||||
* #1928: Google sunset Gemini CLI (2026-06-18) and the `gemini` runtime was
|
||||
* removed from GSD entirely. `projectLocalHookPrefix` now special-cases only
|
||||
* `antigravity` — an unrecognized runtime string like the former `'gemini'`
|
||||
* falls through to the default $CLAUDE_PROJECT_DIR-anchored prefix.
|
||||
* removed from GSD entirely.
|
||||
*
|
||||
* #2096: `projectLocalHookPrefix` no longer special-cases `antigravity` by
|
||||
* name — it branches on the caller-supplied `hookPathStyle` (sourced from
|
||||
* the runtime's `hostBehaviors.hookPathStyle` descriptor field). An
|
||||
* unrecognized runtime string like the former `'gemini'`, or any runtime
|
||||
* that doesn't declare `hookPathStyle: 'raw'`, falls through to the default
|
||||
* $CLAUDE_PROJECT_DIR-anchored prefix.
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
@@ -357,7 +362,13 @@ const { projectLocalHookPrefix, projectShellCommandText } = projection;
|
||||
|
||||
describe('bug #2557: Antigravity local hooks use relative paths (not $CLAUDE_PROJECT_DIR); gemini runtime removed (#1928)', () => {
|
||||
test('Antigravity local prefix is bare dirName', () => {
|
||||
assert.equal(projectLocalHookPrefix({ runtime: 'antigravity', dirName: '.agents' }), '.agents');
|
||||
// #2096: hookPathStyle is now the caller-supplied descriptor value
|
||||
// (bin/install.js resolves it from hostBehaviors.hookPathStyle); the
|
||||
// function itself no longer knows the runtime name 'antigravity'.
|
||||
assert.equal(
|
||||
projectLocalHookPrefix({ runtime: 'antigravity', dirName: '.agents', hookPathStyle: 'raw' }),
|
||||
'.agents',
|
||||
);
|
||||
});
|
||||
|
||||
test('non-Antigravity local prefix remains $CLAUDE_PROJECT_DIR anchored', () => {
|
||||
@@ -512,7 +523,13 @@ describe('bug #3439: shell projection module owns managed-hook policy and legacy
|
||||
});
|
||||
|
||||
test('projectLocalHookPrefix centralizes runtime-specific project-dir interpolation policy', () => {
|
||||
assert.equal(projectLocalHookPrefix({ runtime: 'antigravity', dirName: '.agents' }), '.agents');
|
||||
// #2096: 'raw' hookPathStyle (descriptor-driven) is what produces the
|
||||
// bare-dirName behavior now — the function no longer branches on the
|
||||
// 'antigravity' runtime name itself.
|
||||
assert.equal(
|
||||
projectLocalHookPrefix({ runtime: 'antigravity', dirName: '.agents', hookPathStyle: 'raw' }),
|
||||
'.agents',
|
||||
);
|
||||
assert.equal(
|
||||
projectLocalHookPrefix({ runtime: 'claude', dirName: '.claude' }),
|
||||
'"$CLAUDE_PROJECT_DIR"/.claude',
|
||||
|
||||
Reference in New Issue
Block a user