Files
gnome-jarvis/test/shell-tools.test.js
T
snxraven e9040d110a
Rolling release / release (push) Successful in 6m40s
Updates
2026-09-12 07:22:47 -04:00

57 lines
2.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import os from 'node:os';
const require = createRequire(import.meta.url);
const tools = require('../vendor/agent-harness/agent/tools.js');
const permRules = require('../vendor/agent-harness/agent/perm-rules.js');
const toolBudget = require('../vendor/agent-harness/agent/tool-budget.js');
test('runShell captures stdout after the process closes', async () => {
const result = await tools.runShell(os.tmpdir(), 'printf hello-jarvis');
assert.equal(result.exitCode, 0);
assert.match(result.stdout, /hello-jarvis/);
});
test('formatShellResult puts command output in front of the exit code', () => {
assert.equal(tools.formatShellResult({ exitCode: 0, stdout: 'Linux 6.8\n', stderr: '' }), 'Linux 6.8\nexit 0');
assert.equal(tools.formatShellResult({ exitCode: 0, stdout: '', stderr: '' }), '(no output)\nexit 0');
});
test('Always allow wildcard matches later shell commands', () => {
const rules = permRules.addRule([], 'run_terminal_cmd', { command: '*' }, 'allow');
assert.equal(permRules.resolve(rules, 'run_terminal_cmd', { command: 'uname -a' }), 'allow');
assert.equal(permRules.resolve(rules, 'run_terminal_cmd', { command: 'ls -la /tmp' }), 'allow');
});
test('run_terminal_cmd description still exists for the model', () => {
const def = tools.SCHEMAS.find((item) => item.name === 'run_terminal_cmd');
assert.ok(def);
assert.match(def.description, /shell command/i);
});
test('Jarvis voice budget runs one shell then forces an answer', () => {
const budget = toolBudget.fromPayload({}, 'jarvis-qvac');
assert.equal(budget.maxShellCalls, 1);
assert.equal(budget.maxTurns, 6);
assert.equal(toolBudget.shouldSkipShell(budget), false);
toolBudget.markShell(budget);
assert.equal(budget.answerOnly, true);
assert.equal(toolBudget.shouldSkipShell(budget), true);
assert.match(toolBudget.skipShellMessage(), /already ran/i);
assert.equal(
toolBudget.lastToolText([{ role: 'tool', content: 'Static hostname: nest\nexit 0' }], 80),
'Static hostname: nest exit 0'
);
});
test('coding-agent origin does not cap shell chaining', () => {
const budget = toolBudget.fromPayload({}, 'local');
assert.equal(budget.maxShellCalls, 0);
toolBudget.markShell(budget);
toolBudget.markShell(budget);
assert.equal(toolBudget.shouldSkipShell(budget), false);
assert.equal(budget.answerOnly, false);
});