fix(augment): make hook installation transactional
This commit is contained in:
1 parent
b59404cd33
commit
323757e43d
12 files changed
+1121
-506
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createFixture,
|
||||
runProcess,
|
||||
} from '../test-support/augment-test-helpers.mjs';
|
||||
|
||||
const auggieEntry = process.env.ELYDORA_AUGGIE_ENTRY;
|
||||
|
||||
test('official Auggie accepts the installed user hook contract', {
|
||||
skip: auggieEntry ? false : 'set ELYDORA_AUGGIE_ENTRY to the official Auggie entry file',
|
||||
}, async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
const install = await fixture.install();
|
||||
assert.equal(install.code, 0, install.stderr);
|
||||
const environment = {
|
||||
HOME: fixture.homeDir,
|
||||
USERPROFILE: fixture.homeDir,
|
||||
};
|
||||
const version = await runProcess(
|
||||
process.execPath,
|
||||
[auggieEntry, '--version'],
|
||||
environment,
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(version.code, 0, version.stderr);
|
||||
assert.match(version.stdout, /0\.33\.0/);
|
||||
|
||||
const load = await runProcess(
|
||||
process.execPath,
|
||||
[auggieEntry, 'tools', 'list'],
|
||||
environment,
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(load.code, 0, load.stderr);
|
||||
assert.doesNotMatch(
|
||||
`${load.stdout}\n${load.stderr}`,
|
||||
/invalid settings|settings validation|failed to parse|hook configuration error/i,
|
||||
);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
+125
-329
@@ -1,193 +1,87 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { mkdtemp, mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import { lstat, readFile, stat, writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import {
|
||||
VALID_PRIVATE_KEY,
|
||||
auditWrapperName,
|
||||
cliPath,
|
||||
createFixture,
|
||||
generatedCommand,
|
||||
guardWrapperName,
|
||||
installConfig,
|
||||
managedHandler,
|
||||
pluginModuleUrl,
|
||||
readSettings,
|
||||
registryModuleUrl,
|
||||
runNode,
|
||||
runPlugin,
|
||||
} from '../test-support/augment-test-helpers.mjs';
|
||||
|
||||
const pluginModuleUrl = pathToFileURL(path.resolve('dist/plugins/augment.js')).href;
|
||||
const registryModuleUrl = pathToFileURL(path.resolve('dist/plugins/registry.js')).href;
|
||||
const cliPath = path.resolve('dist/cli.js');
|
||||
const wrapperExtension = process.platform === 'win32' ? '.cmd' : '.sh';
|
||||
const guardWrapperName = `augment-guard${wrapperExtension}`;
|
||||
const auditWrapperName = `augment-hook${wrapperExtension}`;
|
||||
|
||||
function runNode(args, env, input = '', cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, args, {
|
||||
cwd,
|
||||
env: { ...process.env, ...env },
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
||||
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
||||
child.once('error', reject);
|
||||
child.once('close', (code) => resolve({ code, stdout, stderr }));
|
||||
child.stdin.end(input);
|
||||
});
|
||||
async function assertMissing(filePath) {
|
||||
await assert.rejects(lstat(filePath), { code: 'ENOENT' });
|
||||
}
|
||||
|
||||
function runCommand(command, input = '') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, { shell: true, stdio: ['pipe', 'pipe', 'pipe'] });
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
||||
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
||||
child.once('error', reject);
|
||||
child.once('close', (code) => resolve({ code, stdout, stderr }));
|
||||
child.stdin.end(input);
|
||||
});
|
||||
}
|
||||
|
||||
function quotePosix(value) {
|
||||
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
||||
}
|
||||
|
||||
function quoteWindows(value) {
|
||||
return `"${value.replaceAll('"', '\\"')}"`;
|
||||
}
|
||||
|
||||
function generatedCommand(wrapperPath) {
|
||||
return process.platform === 'win32' ? quoteWindows(wrapperPath) : quotePosix(wrapperPath);
|
||||
}
|
||||
|
||||
async function runPlugin(fixture, method, argument) {
|
||||
const script = `
|
||||
import { augmentPlugin } from ${JSON.stringify(pluginModuleUrl)};
|
||||
const argument = JSON.parse(process.env.ELYDORA_TEST_ARGUMENT);
|
||||
const result = await augmentPlugin[process.env.ELYDORA_TEST_METHOD](argument);
|
||||
if (result !== undefined) console.log(JSON.stringify(result));
|
||||
`;
|
||||
return runNode(
|
||||
['--input-type=module', '--eval', script],
|
||||
{
|
||||
HOME: fixture.homeDir,
|
||||
USERPROFILE: fixture.homeDir,
|
||||
ELYDORA_TEST_ARGUMENT: JSON.stringify(argument),
|
||||
ELYDORA_TEST_METHOD: method,
|
||||
},
|
||||
'',
|
||||
fixture.workspaceDir,
|
||||
);
|
||||
}
|
||||
|
||||
async function createFixture({ existingSettings, guardSource, hookSource } = {}) {
|
||||
const rootDir = await mkdtemp(path.join(os.tmpdir(), 'elydora-augment-'));
|
||||
const homeDir = path.join(rootDir, "home with spaces and 'quote");
|
||||
const workspaceDir = path.join(homeDir, 'workspace');
|
||||
const agentDir = path.join(homeDir, '.elydora', 'agent-1');
|
||||
const configPath = path.join(homeDir, '.augment', 'settings.json');
|
||||
const guardScriptPath = path.join(agentDir, 'guard.js');
|
||||
const hookScriptPath = path.join(agentDir, 'hook.js');
|
||||
const guardWrapperPath = path.join(agentDir, guardWrapperName);
|
||||
const auditWrapperPath = path.join(agentDir, auditWrapperName);
|
||||
await mkdir(workspaceDir, { recursive: true });
|
||||
await mkdir(agentDir, { recursive: true });
|
||||
await writeFile(
|
||||
guardScriptPath,
|
||||
guardSource ?? "process.stderr.write('Agent is frozen by Elydora.'); process.exit(2);\n",
|
||||
);
|
||||
await writeFile(hookScriptPath, hookSource ?? 'process.exit(0);\n');
|
||||
await writeFile(path.join(agentDir, 'config.json'), JSON.stringify({
|
||||
agent_id: 'agent-1',
|
||||
agent_name: 'augment',
|
||||
}));
|
||||
if (existingSettings !== undefined) {
|
||||
await mkdir(path.dirname(configPath), { recursive: true });
|
||||
await writeFile(configPath, typeof existingSettings === 'string'
|
||||
? existingSettings
|
||||
: JSON.stringify(existingSettings, null, 2));
|
||||
}
|
||||
const fixture = {
|
||||
agentDir,
|
||||
auditWrapperPath,
|
||||
configPath,
|
||||
guardScriptPath,
|
||||
guardWrapperPath,
|
||||
homeDir,
|
||||
hookScriptPath,
|
||||
workspaceDir,
|
||||
async close() {
|
||||
await rm(rootDir, { recursive: true, force: true });
|
||||
},
|
||||
};
|
||||
fixture.installResult = await runPlugin(fixture, 'install', {
|
||||
agentName: 'augment',
|
||||
agentId: 'agent-1',
|
||||
baseUrl: 'https://api.elydora.com',
|
||||
guardScriptPath,
|
||||
hookScriptPath,
|
||||
});
|
||||
return fixture;
|
||||
}
|
||||
|
||||
function managedHandler(settings, event, wrapperPath) {
|
||||
const command = generatedCommand(wrapperPath);
|
||||
for (const group of settings.hooks?.[event] ?? []) {
|
||||
const handler = group.hooks.find((candidate) => candidate.command === command);
|
||||
if (handler) return handler;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
test('Augment Code CLI is registered in the SDK and CLI', async () => {
|
||||
test('Augment Code CLI is registered and owns its complete runtime installation', async () => {
|
||||
const { SUPPORTED_AGENTS } = await import(registryModuleUrl);
|
||||
const { augmentPlugin } = await import(pluginModuleUrl);
|
||||
assert.deepEqual(SUPPORTED_AGENTS.get('augment'), {
|
||||
name: 'Augment Code CLI',
|
||||
configDir: '~/.augment',
|
||||
configFile: 'settings.json',
|
||||
});
|
||||
const homeDir = await mkdtemp(path.join(os.tmpdir(), 'elydora-augment-cli-'));
|
||||
const workspaceDir = path.join(homeDir, 'workspace');
|
||||
await mkdir(workspaceDir);
|
||||
assert.equal(augmentPlugin.managesRuntime, true);
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
const result = await runNode(['--no-warnings', cliPath, 'status'], {
|
||||
HOME: homeDir,
|
||||
USERPROFILE: homeDir,
|
||||
}, '', workspaceDir);
|
||||
HOME: fixture.homeDir,
|
||||
USERPROFILE: fixture.homeDir,
|
||||
}, fixture.projectDir);
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
assert.match(result.stdout, /Augment Code CLI \(augment\)/);
|
||||
} finally {
|
||||
await rm(homeDir, { recursive: true, force: true });
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie install preserves user settings and is idempotent', async () => {
|
||||
test('Auggie installation preserves official settings and is idempotent', async () => {
|
||||
const existing = {
|
||||
telemetryEnabled: false,
|
||||
hooks: {
|
||||
SessionStart: [{
|
||||
hooks: [{ type: 'command', command: 'existing-command', args: ['one'], timeout: 5_000 }],
|
||||
metadata: { includeUserContext: true },
|
||||
metadata: {
|
||||
includeConversationData: true,
|
||||
includeMCPMetadata: false,
|
||||
includeUserContext: true,
|
||||
},
|
||||
label: 'keep group metadata',
|
||||
}],
|
||||
PromptSubmit: [{ hooks: [{ type: 'command', command: 'prompt-hook' }] }],
|
||||
Notification: [{ hooks: [{ type: 'command', command: 'notification-hook' }] }],
|
||||
PreToolUse: [{
|
||||
matcher: 'launch-process',
|
||||
hooks: [{ type: 'command', command: 'user-command' }],
|
||||
}],
|
||||
},
|
||||
};
|
||||
const fixture = await createFixture({ existingSettings: existing });
|
||||
const fixture = await createFixture({ settings: existing });
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
const second = await runPlugin(fixture, 'install', {
|
||||
agentName: 'augment',
|
||||
agentId: 'agent-1',
|
||||
guardScriptPath: fixture.guardScriptPath,
|
||||
hookScriptPath: fixture.hookScriptPath,
|
||||
});
|
||||
const first = await fixture.install();
|
||||
assert.equal(first.code, 0, first.stderr);
|
||||
const firstRaw = await readFile(fixture.settingsPath, 'utf-8');
|
||||
const second = await fixture.install();
|
||||
assert.equal(second.code, 0, second.stderr);
|
||||
const settings = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
assert.equal(await readFile(fixture.settingsPath, 'utf-8'), firstRaw);
|
||||
|
||||
const { settings } = await readSettings(fixture.settingsPath);
|
||||
assert.equal(settings.telemetryEnabled, false);
|
||||
assert.deepEqual(settings.hooks.SessionStart, existing.hooks.SessionStart);
|
||||
assert.deepEqual(settings.hooks.PromptSubmit, existing.hooks.PromptSubmit);
|
||||
assert.deepEqual(settings.hooks.Notification, existing.hooks.Notification);
|
||||
assert.deepEqual(settings.hooks.PreToolUse[0], existing.hooks.PreToolUse[0]);
|
||||
assert.equal(settings.hooks.PreToolUse.length, 2);
|
||||
assert.equal(settings.hooks.PostToolUse.length, 1);
|
||||
assert.equal(settings.hooks.PreToolUse[1].matcher, '.*');
|
||||
for (const [event, wrapperPath] of [
|
||||
['PreToolUse', fixture.guardWrapperPath],
|
||||
['PostToolUse', fixture.auditWrapperPath],
|
||||
@@ -197,10 +91,23 @@ test('Auggie install preserves user settings and is idempotent', async () => {
|
||||
assert.equal(handler.type, 'command');
|
||||
assert.equal(handler.timeout, 10_000);
|
||||
}
|
||||
|
||||
const runtimeConfig = JSON.parse(
|
||||
await readFile(path.join(fixture.agentDir, 'config.json'), 'utf-8'),
|
||||
);
|
||||
assert.deepEqual(runtimeConfig, {
|
||||
org_id: 'org-1',
|
||||
agent_id: 'agent-1',
|
||||
kid: 'kid-1',
|
||||
base_url: fixture.baseUrl,
|
||||
token: 'token-1',
|
||||
agent_name: 'augment',
|
||||
});
|
||||
assert.equal(await readFile(path.join(fixture.agentDir, 'private.key'), 'utf-8'), VALID_PRIVATE_KEY);
|
||||
assert.match(await readFile(fixture.hookScriptPath, 'utf-8'), /const NATIVE_PAYLOAD = true;/);
|
||||
const guardWrapper = await readFile(fixture.guardWrapperPath, 'utf-8');
|
||||
const auditWrapper = await readFile(fixture.auditWrapperPath, 'utf-8');
|
||||
assert.match(guardWrapper, new RegExp(path.basename(fixture.guardScriptPath).replace('.', '\\.')));
|
||||
assert.match(auditWrapper, new RegExp(path.basename(fixture.hookScriptPath).replace('.', '\\.')));
|
||||
assert.match(guardWrapper, /guard\.js/);
|
||||
assert.match(await readFile(fixture.auditWrapperPath, 'utf-8'), new RegExp('hook\\.js'));
|
||||
if (process.platform !== 'win32') {
|
||||
assert.equal((await stat(fixture.guardWrapperPath)).mode & 0o111, 0o100);
|
||||
assert.match(guardWrapper, /^#!\/bin\/sh\nexec /);
|
||||
@@ -208,128 +115,17 @@ test('Auggie install preserves user settings and is idempotent', async () => {
|
||||
assert.match(guardWrapper, /^@echo off\r?\n/);
|
||||
assert.match(guardWrapper, /exit \/b %errorlevel%/);
|
||||
}
|
||||
await assert.rejects(
|
||||
readFile(path.join(fixture.workspaceDir, '.augment', 'settings.json')),
|
||||
{ code: 'ENOENT' },
|
||||
);
|
||||
await assert.rejects(
|
||||
readFile(path.join(fixture.workspaceDir, '.augment', 'settings.local.json')),
|
||||
{ code: 'ENOENT' },
|
||||
);
|
||||
await assertMissing(path.join(fixture.projectDir, '.augment', 'settings.json'));
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie wrappers block freezes and forward official input byte-for-byte', async () => {
|
||||
const capturePath = path.join(os.tmpdir(), `elydora-augment-event-${process.pid}-${Date.now()}.json`);
|
||||
const hookSource = `
|
||||
const fs = require('node:fs');
|
||||
const chunks = [];
|
||||
process.stdin.on('data', (chunk) => chunks.push(chunk));
|
||||
process.stdin.on('end', () => fs.writeFileSync(${JSON.stringify(capturePath)}, Buffer.concat(chunks)));
|
||||
`;
|
||||
const fixture = await createFixture({ hookSource });
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
const settings = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
const guard = managedHandler(settings, 'PreToolUse', fixture.guardWrapperPath);
|
||||
const audit = managedHandler(settings, 'PostToolUse', fixture.auditWrapperPath);
|
||||
const prePayload = JSON.stringify({
|
||||
hook_event_name: 'PreToolUse',
|
||||
conversation_id: 'conversation-1',
|
||||
workspace_roots: [fixture.workspaceDir],
|
||||
tool_name: 'launch-process',
|
||||
tool_input: { command: 'echo test' },
|
||||
is_mcp_tool: false,
|
||||
});
|
||||
const guardResult = await runCommand(guard.command, prePayload);
|
||||
assert.equal(guardResult.code, 2);
|
||||
assert.match(guardResult.stderr, /Agent is frozen by Elydora/);
|
||||
const postPayload = JSON.stringify({
|
||||
hook_event_name: 'PostToolUse',
|
||||
conversation_id: 'conversation-1',
|
||||
workspace_roots: [fixture.workspaceDir],
|
||||
tool_name: 'launch-process',
|
||||
tool_input: { command: 'echo test' },
|
||||
tool_output: 'test',
|
||||
is_mcp_tool: false,
|
||||
});
|
||||
const auditResult = await runCommand(audit.command, postPayload);
|
||||
assert.equal(auditResult.code, 0, auditResult.stderr);
|
||||
assert.equal(await readFile(capturePath, 'utf-8'), postPayload);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
await rm(capturePath, { force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie status requires a complete pair, core runtimes, and wrappers', async () => {
|
||||
test('Auggie install replaces stale managed handlers and preserves user groups', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
let status = await runPlugin(fixture, 'status', null);
|
||||
assert.equal(JSON.parse(status.stdout).installed, true);
|
||||
await rm(fixture.guardWrapperPath);
|
||||
status = await runPlugin(fixture, 'status', null);
|
||||
assert.equal(JSON.parse(status.stdout).installed, false);
|
||||
await runPlugin(fixture, 'install', {
|
||||
agentName: 'augment',
|
||||
agentId: 'agent-1',
|
||||
guardScriptPath: fixture.guardScriptPath,
|
||||
hookScriptPath: fixture.hookScriptPath,
|
||||
});
|
||||
await rm(fixture.hookScriptPath);
|
||||
status = await runPlugin(fixture, 'status', null);
|
||||
assert.equal(JSON.parse(status.stdout).installed, false);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie uninstall removes exact ownership and preserves user groups', async () => {
|
||||
const fixture = await createFixture({ existingSettings: {
|
||||
owner: 'user',
|
||||
hooks: { Notification: [] },
|
||||
} });
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
const settings = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
settings.hooks.PreToolUse.unshift({ hooks: [], label: 'keep empty group' });
|
||||
settings.hooks.PreToolUse[1].hooks.push({ type: 'command', command: 'user-command' });
|
||||
settings.hooks.PreToolUse.push({ hooks: [{
|
||||
type: 'command',
|
||||
command: generatedCommand(`${fixture.guardWrapperPath}.backup`),
|
||||
timeout: 10_000,
|
||||
}] });
|
||||
settings.hooks.PreToolUse.push({ hooks: [{
|
||||
type: 'command',
|
||||
command: generatedCommand(path.join(fixture.agentDir, '..', 'agent-10', guardWrapperName)),
|
||||
timeout: 10_000,
|
||||
}] });
|
||||
await writeFile(fixture.configPath, JSON.stringify(settings, null, 2));
|
||||
const uninstallId = process.platform === 'win32' ? 'AGENT-1' : 'agent-1';
|
||||
const result = await runPlugin(fixture, 'uninstall', uninstallId);
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
const remaining = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
assert.equal(remaining.owner, 'user');
|
||||
assert.deepEqual(remaining.hooks.Notification, []);
|
||||
assert.equal(remaining.hooks.PreToolUse.length, 4);
|
||||
assert.deepEqual(remaining.hooks.PreToolUse[0], { hooks: [], label: 'keep empty group' });
|
||||
assert.equal(remaining.hooks.PreToolUse[1].hooks[0].command, 'user-command');
|
||||
assert.match(JSON.stringify(remaining), /augment-guard.*backup/);
|
||||
assert.match(JSON.stringify(remaining), /agent-10/);
|
||||
assert.equal(remaining.hooks.PostToolUse, undefined);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie install replaces stale Elydora handlers and preserves empty groups', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
const settings = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const { settings } = await readSettings(fixture.settingsPath);
|
||||
settings.hooks.PreToolUse.unshift({ hooks: [], label: 'keep empty group' });
|
||||
for (const [event, wrapperName] of [
|
||||
['PreToolUse', guardWrapperName],
|
||||
@@ -341,15 +137,10 @@ test('Auggie install replaces stale Elydora handlers and preserves empty groups'
|
||||
timeout: 10_000,
|
||||
}] });
|
||||
}
|
||||
await writeFile(fixture.configPath, JSON.stringify(settings, null, 2));
|
||||
const result = await runPlugin(fixture, 'install', {
|
||||
agentName: 'augment',
|
||||
agentId: 'agent-1',
|
||||
guardScriptPath: fixture.guardScriptPath,
|
||||
hookScriptPath: fixture.hookScriptPath,
|
||||
});
|
||||
await writeFile(fixture.settingsPath, `${JSON.stringify(settings, null, 2)}\n`);
|
||||
const result = await fixture.install();
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
const current = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||
const current = (await readSettings(fixture.settingsPath)).settings;
|
||||
assert.doesNotMatch(JSON.stringify(current), /agent-old/);
|
||||
assert.deepEqual(current.hooks.PreToolUse[0], { hooks: [], label: 'keep empty group' });
|
||||
assert.equal(current.hooks.PreToolUse.length, 2);
|
||||
@@ -359,23 +150,59 @@ test('Auggie install replaces stale Elydora handlers and preserves empty groups'
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie uninstall removes settings owned entirely by Elydora', async () => {
|
||||
const fixture = await createFixture();
|
||||
test('Auggie uninstall removes exact ownership and preserves user settings', async () => {
|
||||
const fixture = await createFixture({ settings: {
|
||||
owner: 'user',
|
||||
hooks: { Notification: [] },
|
||||
} });
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
const result = await runPlugin(fixture, 'uninstall', 'agent-1');
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const { settings } = await readSettings(fixture.settingsPath);
|
||||
settings.hooks.PreToolUse[0].hooks.push({ type: 'command', command: 'user-command' });
|
||||
settings.hooks.PreToolUse.push({ hooks: [{
|
||||
type: 'command',
|
||||
command: generatedCommand(`${fixture.guardWrapperPath}.backup`),
|
||||
timeout: 10_000,
|
||||
}] });
|
||||
settings.hooks.PreToolUse.push({ hooks: [{
|
||||
type: 'command',
|
||||
command: generatedCommand(path.join(fixture.agentDir, '..', 'agent-10', guardWrapperName)),
|
||||
timeout: 10_000,
|
||||
}] });
|
||||
await writeFile(fixture.settingsPath, `${JSON.stringify(settings, null, 2)}\n`);
|
||||
const uninstallId = process.platform === 'win32' ? 'AGENT-1' : 'agent-1';
|
||||
const result = await runPlugin(fixture, 'uninstall', uninstallId);
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
await assert.rejects(readFile(fixture.configPath), { code: 'ENOENT' });
|
||||
const remaining = (await readSettings(fixture.settingsPath)).settings;
|
||||
assert.equal(remaining.owner, 'user');
|
||||
assert.deepEqual(remaining.hooks.Notification, []);
|
||||
assert.equal(remaining.hooks.PreToolUse[0].hooks[0].command, 'user-command');
|
||||
assert.match(JSON.stringify(remaining), /augment-guard.*backup/);
|
||||
assert.match(JSON.stringify(remaining), /agent-10/);
|
||||
assert.equal(remaining.hooks.PostToolUse, undefined);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie rejects malformed settings and invalid hook contracts before writes', async () => {
|
||||
test('Auggie uninstall removes settings owned entirely by Elydora', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const result = await runPlugin(fixture, 'uninstall', 'agent-1');
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
await assertMissing(fixture.settingsPath);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie rejects malformed settings and invalid official hook contracts before writes', async () => {
|
||||
const cases = [
|
||||
'{ malformed',
|
||||
'null',
|
||||
'[]',
|
||||
'{"hooks":{},"hooks":{}}',
|
||||
{ hooks: null },
|
||||
{ hooks: { UnknownEvent: [] } },
|
||||
{ hooks: { PreToolUse: null } },
|
||||
@@ -389,64 +216,33 @@ test('Auggie rejects malformed settings and invalid hook contracts before writes
|
||||
{ hooks: { PreToolUse: [{ hooks: [{ type: 'command', command: 'x', timeout: 0 }] }] } },
|
||||
{ hooks: { PreToolUse: [{ hooks: [], metadata: { includeUserContext: 'yes' } }] } },
|
||||
];
|
||||
for (const existingSettings of cases) {
|
||||
const fixture = await createFixture({ existingSettings });
|
||||
for (const settings of cases) {
|
||||
const fixture = await createFixture({ settings });
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 1, `${JSON.stringify(existingSettings)}\n${fixture.installResult.stderr}`);
|
||||
const expected = typeof existingSettings === 'string'
|
||||
? existingSettings
|
||||
: JSON.stringify(existingSettings, null, 2);
|
||||
assert.equal(await readFile(fixture.configPath, 'utf-8'), expected);
|
||||
await assert.rejects(readFile(fixture.guardWrapperPath), { code: 'ENOENT' });
|
||||
await assert.rejects(readFile(fixture.auditWrapperPath), { code: 'ENOENT' });
|
||||
const before = await readFile(fixture.settingsPath, 'utf-8');
|
||||
const result = await fixture.install();
|
||||
assert.equal(result.code, 1, `${JSON.stringify(settings)}\n${result.stderr}`);
|
||||
assert.equal(await readFile(fixture.settingsPath, 'utf-8'), before);
|
||||
await assertMissing(fixture.guardWrapperPath);
|
||||
await assertMissing(fixture.auditWrapperPath);
|
||||
await assertMissing(fixture.guardScriptPath);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie install rejects missing runtimes before creating files', async () => {
|
||||
const homeDir = await mkdtemp(path.join(os.tmpdir(), 'elydora-augment-missing-'));
|
||||
const workspaceDir = path.join(homeDir, 'workspace');
|
||||
const agentDir = path.join(homeDir, '.elydora', 'agent-1');
|
||||
const fixture = { homeDir, workspaceDir };
|
||||
await mkdir(workspaceDir);
|
||||
test('Auggie validates complete install config before creating files', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
const result = await runPlugin(fixture, 'install', {
|
||||
agentName: 'augment',
|
||||
agentId: 'agent-1',
|
||||
guardScriptPath: path.join(agentDir, 'guard.js'),
|
||||
hookScriptPath: path.join(agentDir, 'hook.js'),
|
||||
...installConfig(fixture),
|
||||
privateKey: 'invalid',
|
||||
});
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /runtime is missing/i);
|
||||
await assert.rejects(readFile(path.join(homeDir, '.augment', 'settings.json')), { code: 'ENOENT' });
|
||||
await assert.rejects(readFile(path.join(agentDir, guardWrapperName)), { code: 'ENOENT' });
|
||||
} finally {
|
||||
await rm(homeDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie status surfaces malformed referenced runtime metadata', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
await writeFile(path.join(fixture.agentDir, 'config.json'), '{ malformed');
|
||||
const status = await runPlugin(fixture, 'status', null);
|
||||
assert.equal(status.code, 1);
|
||||
assert.match(status.stderr, /parse Elydora runtime config/i);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie atomic writes leave no temporary files', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||
for (const directory of [fixture.agentDir, path.dirname(fixture.configPath)]) {
|
||||
assert.equal((await readdir(directory)).some((name) => name.endsWith('.tmp')), false);
|
||||
}
|
||||
assert.match(result.stderr, /canonical 32-byte base64url/i);
|
||||
await assertMissing(fixture.settingsPath);
|
||||
await assertMissing(fixture.guardScriptPath);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createFixture,
|
||||
managedHandler,
|
||||
readSettings,
|
||||
runHandler,
|
||||
runPlugin,
|
||||
startApiServer,
|
||||
} from '../test-support/augment-test-helpers.mjs';
|
||||
|
||||
async function status(fixture) {
|
||||
const result = await runPlugin(fixture, 'status', null);
|
||||
return { result, value: result.code === 0 ? JSON.parse(result.stdout) : undefined };
|
||||
}
|
||||
|
||||
test('Auggie guard propagates exit code 2 for a frozen agent', async () => {
|
||||
const api = await startApiServer({ status: 'frozen' });
|
||||
const fixture = await createFixture({ baseUrl: api.baseUrl });
|
||||
try {
|
||||
const install = await fixture.install();
|
||||
assert.equal(install.code, 0, install.stderr);
|
||||
const settings = (await readSettings(fixture.settingsPath)).settings;
|
||||
const guard = managedHandler(settings, 'PreToolUse', fixture.guardWrapperPath);
|
||||
const payload = JSON.stringify({
|
||||
hook_event_name: 'PreToolUse',
|
||||
conversation_id: 'conversation-1',
|
||||
workspace_roots: [fixture.projectDir],
|
||||
tool_name: 'launch-process',
|
||||
tool_input: { command: 'echo test' },
|
||||
is_mcp_tool: false,
|
||||
});
|
||||
const result = await runHandler(guard, payload, fixture);
|
||||
assert.equal(result.code, 2, result.stderr);
|
||||
assert.match(result.stderr, /Agent "augment" is frozen/);
|
||||
assert.equal(api.requests.filter((request) => request.method === 'GET').length, 1);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
await api.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie audit preserves the complete native hook payload', async () => {
|
||||
const api = await startApiServer();
|
||||
const fixture = await createFixture({ baseUrl: api.baseUrl });
|
||||
try {
|
||||
const install = await fixture.install();
|
||||
assert.equal(install.code, 0, install.stderr);
|
||||
const settings = (await readSettings(fixture.settingsPath)).settings;
|
||||
const audit = managedHandler(settings, 'PostToolUse', fixture.auditWrapperPath);
|
||||
const payload = {
|
||||
hook_event_name: 'PostToolUse',
|
||||
conversation_id: 'conversation-1',
|
||||
workspace_roots: [fixture.projectDir],
|
||||
tool_name: 'launch-process',
|
||||
tool_input: { command: 'echo test', nested: { preserve: true } },
|
||||
tool_output: { stdout: 'test', stderr: '', exit_code: 0 },
|
||||
is_mcp_tool: false,
|
||||
conversation_data: [{ role: 'user', content: 'preserve this' }],
|
||||
mcp_metadata: { server: 'local', transport: 'stdio' },
|
||||
user_context: { account: 'user-1' },
|
||||
future_field: { survives: ['exactly', 2] },
|
||||
};
|
||||
const result = await runHandler(audit, JSON.stringify(payload), fixture);
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
const request = api.requests.find((candidate) => candidate.method === 'POST');
|
||||
assert(request);
|
||||
assert.deepEqual(JSON.parse(request.raw).payload, payload);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
await api.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie status requires settings, exact runtime identity, key, scripts, and wrappers', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
assert.equal((await status(fixture)).value.installed, true);
|
||||
|
||||
await rm(fixture.guardWrapperPath);
|
||||
assert.equal((await status(fixture)).value.installed, false);
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
|
||||
await rm(fixture.hookScriptPath);
|
||||
assert.equal((await status(fixture)).value.installed, false);
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
|
||||
await writeFile(fixture.auditWrapperPath, 'tampered wrapper\n');
|
||||
assert.equal((await status(fixture)).value.installed, false);
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
|
||||
const keyPath = path.join(fixture.agentDir, 'private.key');
|
||||
await writeFile(keyPath, 'invalid');
|
||||
const invalidKey = await status(fixture);
|
||||
assert.equal(invalidKey.result.code, 1);
|
||||
assert.match(invalidKey.result.stderr, /private key is invalid/i);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie status surfaces malformed and mismatched runtime metadata', async (t) => {
|
||||
for (const [name, contents, pattern] of [
|
||||
['malformed', '{ malformed', /parse Elydora runtime config/i],
|
||||
['duplicate', '{"agent_name":"augment","agent_name":"augment"}', /duplicate field/i],
|
||||
['mismatched', JSON.stringify({
|
||||
org_id: 'org-1',
|
||||
agent_id: 'other-agent',
|
||||
kid: 'kid-1',
|
||||
base_url: 'https://api.elydora.com',
|
||||
agent_name: 'augment',
|
||||
}), /identity does not match/i],
|
||||
['unsupported field', JSON.stringify({
|
||||
org_id: 'org-1',
|
||||
agent_id: 'agent-1',
|
||||
kid: 'kid-1',
|
||||
base_url: 'https://api.elydora.com',
|
||||
agent_name: 'augment',
|
||||
hidden: true,
|
||||
}), /unsupported field/i],
|
||||
]) {
|
||||
await t.test(name, async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
await writeFile(path.join(fixture.agentDir, 'config.json'), contents);
|
||||
const current = await status(fixture);
|
||||
assert.equal(current.result.code, 1);
|
||||
assert.match(current.result.stderr, pattern);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie status ignores incomplete managed hook pairs', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const { settings } = await readSettings(fixture.settingsPath);
|
||||
delete settings.hooks.PostToolUse;
|
||||
await writeFile(fixture.settingsPath, `${JSON.stringify(settings, null, 2)}\n`);
|
||||
const current = await status(fixture);
|
||||
assert.equal(current.result.code, 0, current.result.stderr);
|
||||
assert.equal(current.value.hookConfigured, false);
|
||||
assert.equal(current.value.installed, false);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,306 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
lstat,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createFixture,
|
||||
installConfig,
|
||||
installationModuleUrl,
|
||||
ioModuleUrl,
|
||||
managedInstallationModuleUrl,
|
||||
runNode,
|
||||
writeJson,
|
||||
} from '../test-support/augment-test-helpers.mjs';
|
||||
|
||||
const managedFileNames = [
|
||||
'guard.js',
|
||||
'config.json',
|
||||
'private.key',
|
||||
'hook.js',
|
||||
`augment-guard${process.platform === 'win32' ? '.cmd' : '.sh'}`,
|
||||
`augment-hook${process.platform === 'win32' ? '.cmd' : '.sh'}`,
|
||||
];
|
||||
|
||||
async function assertMissing(filePath) {
|
||||
await assert.rejects(lstat(filePath), { code: 'ENOENT' });
|
||||
}
|
||||
|
||||
async function snapshotInstallation(fixture) {
|
||||
const entries = await Promise.all(managedFileNames.map(async (name) => [
|
||||
path.join(fixture.agentDir, name),
|
||||
await readFile(path.join(fixture.agentDir, name), 'utf-8'),
|
||||
]));
|
||||
entries.push([fixture.settingsPath, await readFile(fixture.settingsPath, 'utf-8')]);
|
||||
return new Map(entries);
|
||||
}
|
||||
|
||||
async function assertSnapshot(snapshot) {
|
||||
for (const [filePath, expected] of snapshot) {
|
||||
assert.equal(await readFile(filePath, 'utf-8'), expected, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
async function assertNoTransactionFiles(fixture) {
|
||||
const names = [
|
||||
...await readdir(fixture.agentDir),
|
||||
...await readdir(path.dirname(fixture.settingsPath)),
|
||||
];
|
||||
assert.equal(names.some((name) => /\.(tmp|rollback)$/.test(name)), false, names.join(', '));
|
||||
}
|
||||
|
||||
function testEnvironment(fixture, overrides = {}) {
|
||||
return {
|
||||
HOME: fixture.homeDir,
|
||||
USERPROFILE: fixture.homeDir,
|
||||
ELYDORA_INSTALL_CONFIG: JSON.stringify(installConfig(fixture, overrides)),
|
||||
};
|
||||
}
|
||||
|
||||
test('Auggie rolls back all seven files when a transaction commit fails', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const before = await snapshotInstallation(fixture);
|
||||
const source = `
|
||||
import { rename } from 'node:fs/promises';
|
||||
import { readConfig } from ${JSON.stringify(ioModuleUrl)};
|
||||
import {
|
||||
commitAugmentInstallation,
|
||||
prepareAugmentInstallation,
|
||||
} from ${JSON.stringify(installationModuleUrl)};
|
||||
const document = await readConfig();
|
||||
const prepared = await prepareAugmentInstallation(
|
||||
JSON.parse(process.env.ELYDORA_INSTALL_CONFIG),
|
||||
{ document, changed: false },
|
||||
);
|
||||
let calls = 0;
|
||||
await commitAugmentInstallation(prepared, async (from, to) => {
|
||||
calls += 1;
|
||||
if (calls === 5) throw new Error('injected rename failure');
|
||||
await rename(from, to);
|
||||
});
|
||||
`;
|
||||
const result = await runNode(
|
||||
['--input-type=module', '--eval', source],
|
||||
testEnvironment(fixture, { orgId: 'org-updated', token: 'token-updated' }),
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /injected rename failure/i);
|
||||
await assertSnapshot(before);
|
||||
await assertNoTransactionFiles(fixture);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie detects concurrent settings changes before runtime commit', async () => {
|
||||
const fixture = await createFixture({ settings: { telemetryEnabled: true } });
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const before = await snapshotInstallation(fixture);
|
||||
const concurrent = '{"telemetryEnabled":false,"hooks":{"Notification":[]}}\n';
|
||||
const source = `
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import { readConfig } from ${JSON.stringify(ioModuleUrl)};
|
||||
import {
|
||||
commitAugmentInstallation,
|
||||
prepareAugmentInstallation,
|
||||
} from ${JSON.stringify(installationModuleUrl)};
|
||||
const document = await readConfig();
|
||||
const prepared = await prepareAugmentInstallation(
|
||||
JSON.parse(process.env.ELYDORA_INSTALL_CONFIG),
|
||||
{ document, changed: false },
|
||||
);
|
||||
await writeFile(document.configPath, process.env.ELYDORA_CONCURRENT, 'utf-8');
|
||||
await commitAugmentInstallation(prepared);
|
||||
`;
|
||||
const result = await runNode(
|
||||
['--input-type=module', '--eval', source],
|
||||
{
|
||||
...testEnvironment(fixture, { orgId: 'updated' }),
|
||||
ELYDORA_CONCURRENT: concurrent,
|
||||
},
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /changed during Augment Code CLI installation/i);
|
||||
for (const [filePath, expected] of before) {
|
||||
if (filePath !== fixture.settingsPath) {
|
||||
assert.equal(await readFile(filePath, 'utf-8'), expected);
|
||||
}
|
||||
}
|
||||
assert.equal(await readFile(fixture.settingsPath, 'utf-8'), concurrent);
|
||||
await assertNoTransactionFiles(fixture);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie rejects a stale settings document before staging files', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const before = await snapshotInstallation(fixture);
|
||||
const concurrent = '{"hooks":{"Notification":[]}}\n';
|
||||
const source = `
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import { readConfig } from ${JSON.stringify(ioModuleUrl)};
|
||||
import { prepareAugmentInstallation } from ${JSON.stringify(installationModuleUrl)};
|
||||
const document = await readConfig();
|
||||
await writeFile(document.configPath, process.env.ELYDORA_CONCURRENT, 'utf-8');
|
||||
await prepareAugmentInstallation(
|
||||
JSON.parse(process.env.ELYDORA_INSTALL_CONFIG),
|
||||
{ document, changed: false },
|
||||
);
|
||||
`;
|
||||
const result = await runNode(
|
||||
['--input-type=module', '--eval', source],
|
||||
{ ...testEnvironment(fixture), ELYDORA_CONCURRENT: concurrent },
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /changed before installation/i);
|
||||
for (const [filePath, expected] of before) {
|
||||
if (filePath !== fixture.settingsPath) {
|
||||
assert.equal(await readFile(filePath, 'utf-8'), expected);
|
||||
}
|
||||
}
|
||||
assert.equal(await readFile(fixture.settingsPath, 'utf-8'), concurrent);
|
||||
await assertNoTransactionFiles(fixture);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie rejects orphaned and mismatched runtime identities before writes', async (t) => {
|
||||
await t.test('orphaned runtime', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
await mkdir(fixture.agentDir, { recursive: true });
|
||||
await writeFile(fixture.guardScriptPath, 'orphaned guard\n');
|
||||
const result = await fixture.install();
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /identity cannot be verified/i);
|
||||
assert.equal(await readFile(fixture.guardScriptPath, 'utf-8'), 'orphaned guard\n');
|
||||
await assertMissing(fixture.settingsPath);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('mismatched identity', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
await writeJson(path.join(fixture.agentDir, 'config.json'), {
|
||||
agent_name: 'augment',
|
||||
agent_id: 'another-agent',
|
||||
});
|
||||
const configPath = path.join(fixture.agentDir, 'config.json');
|
||||
const before = await readFile(configPath, 'utf-8');
|
||||
const result = await fixture.install();
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /identity does not match/i);
|
||||
assert.equal(await readFile(configPath, 'utf-8'), before);
|
||||
await assertMissing(fixture.settingsPath);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('Auggie rejects linked settings, runtime directories, and wrappers', async (t) => {
|
||||
for (const kind of ['settings', 'runtime', 'wrapper']) {
|
||||
await t.test(kind, async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
const target = path.join(fixture.rootDir, `${kind}-target`);
|
||||
await mkdir(target, { recursive: true });
|
||||
if (kind === 'settings') {
|
||||
await mkdir(path.dirname(fixture.settingsPath), { recursive: true });
|
||||
const targetFile = path.join(target, 'settings.json');
|
||||
await writeFile(targetFile, '{}\n');
|
||||
await symlink(targetFile, fixture.settingsPath, 'file');
|
||||
} else if (kind === 'runtime') {
|
||||
await mkdir(fixture.homeDir, { recursive: true });
|
||||
await symlink(target, path.join(fixture.homeDir, '.elydora'), 'junction');
|
||||
} else {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
const targetFile = path.join(target, 'wrapper');
|
||||
await writeFile(targetFile, 'external wrapper\n');
|
||||
await rm(fixture.guardWrapperPath);
|
||||
await symlink(targetFile, fixture.guardWrapperPath, 'file');
|
||||
}
|
||||
const result = await fixture.install();
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /physical (directory|file)/i);
|
||||
} catch (error) {
|
||||
if (error?.code === 'EPERM') {
|
||||
t.skip(`symbolic links unavailable: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('Managed runtime extensions reject paths outside the agent directory', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
const source = `
|
||||
import { prepareManagedInstallation } from ${JSON.stringify(managedInstallationModuleUrl)};
|
||||
const config = JSON.parse(process.env.ELYDORA_INSTALL_CONFIG);
|
||||
await prepareManagedInstallation({
|
||||
agentKey: 'augment',
|
||||
displayName: 'Augment Code CLI',
|
||||
hookSources: [{
|
||||
directoryLabel: 'Auggie configuration directory',
|
||||
label: 'Auggie user settings',
|
||||
filePath: process.env.ELYDORA_SETTINGS_PATH,
|
||||
source: '{}\\n',
|
||||
}],
|
||||
runtimeFiles: [{
|
||||
fileName: '../outside.js',
|
||||
label: 'Unsafe runtime',
|
||||
source: 'unsafe',
|
||||
mode: 448,
|
||||
}],
|
||||
config,
|
||||
}, 'guard.js', 'hook.js');
|
||||
`;
|
||||
const result = await runNode(
|
||||
['--input-type=module', '--eval', source],
|
||||
{
|
||||
...testEnvironment(fixture),
|
||||
ELYDORA_SETTINGS_PATH: fixture.settingsPath,
|
||||
},
|
||||
fixture.projectDir,
|
||||
);
|
||||
assert.equal(result.code, 1);
|
||||
assert.match(result.stderr, /fileName must be a basename/i);
|
||||
await assertMissing(path.join(fixture.agentDir, '..', 'outside.js'));
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('Auggie installation leaves no transaction artifacts', async () => {
|
||||
const fixture = await createFixture();
|
||||
try {
|
||||
assert.equal((await fixture.install()).code, 0);
|
||||
await assertNoTransactionFiles(fixture);
|
||||
} finally {
|
||||
await fixture.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user