Vendored
+74
-1
@@ -17,6 +17,7 @@ const stationarity = require('../agent/stationarity.js');
|
||||
const truncate = require('../agent/truncate.js');
|
||||
const permRules = require('../agent/perm-rules.js');
|
||||
const policy = require('../agent/policy.js');
|
||||
const toolBudget = require('../agent/tool-budget.js');
|
||||
const paths = require('../lib/paths.js');
|
||||
const device = require('../lib/device.js');
|
||||
|
||||
@@ -35,6 +36,14 @@ function testCatalog() {
|
||||
assert.ok(listed && listed.label.indexOf('~3.5 GB') >= 0);
|
||||
}
|
||||
|
||||
function hugeToolDefs() {
|
||||
return Array.from({ length: 24 }, (_, i) => ({
|
||||
name: 'tool_' + i,
|
||||
description: 'd'.repeat(400),
|
||||
parameters: { type: 'object', properties: { q: { type: 'string' } } },
|
||||
}));
|
||||
}
|
||||
|
||||
function testCompaction() {
|
||||
const sys = { role: 'system', content: 'sys' };
|
||||
const user = { role: 'user', content: 'hello' };
|
||||
@@ -48,6 +57,39 @@ function testCompaction() {
|
||||
assert.ok(out.length < hist.length);
|
||||
assert.strictEqual(out[0].role, 'system');
|
||||
assert.ok(compaction.isOverflowError(new Error('prompt too long for context window')));
|
||||
|
||||
const tools = hugeToolDefs();
|
||||
const short = [
|
||||
{ role: 'system', content: 'You are Jarvis' },
|
||||
{ role: 'assistant', content: 'Hello! How can I help you today?' },
|
||||
{ role: 'user', content: 'Hi, please tell me about my computer.' },
|
||||
];
|
||||
assert.ok(compaction.toolTokens(tools) > 2000);
|
||||
assert.equal(compaction.shouldCompact(short, tools, 8192), false);
|
||||
const kept = compaction.compact(short, {
|
||||
budgetTokens: compaction.historyBudget(8192, tools, 0),
|
||||
tools,
|
||||
});
|
||||
assert.strictEqual(kept.length, short.length);
|
||||
assert.strictEqual(kept[2].content, short[2].content);
|
||||
assert.ok(JSON.stringify(kept).indexOf('Earlier turns were compacted') < 0);
|
||||
|
||||
const four = short.concat([
|
||||
{ role: 'assistant', content: 'Let me look.' },
|
||||
{ role: 'user', content: 'Go ahead.' },
|
||||
]);
|
||||
assert.ok(compaction.nonSystemCount(four) >= compaction.MIN_COMPACT_MESSAGES);
|
||||
const stillKept = compaction.heuristicCompact(four, {
|
||||
budgetTokens: compaction.historyBudget(8192, tools, 0),
|
||||
tools,
|
||||
});
|
||||
assert.ok(stillKept.some((m) => String(m.content).indexOf('tell me about my computer') >= 0));
|
||||
assert.ok(JSON.stringify(stillKept).indexOf('Earlier turns were compacted') < 0);
|
||||
|
||||
assert.strictEqual(compaction.autoContinue([{ role: 'assistant', content: 'hi' }], { voice: true }), null);
|
||||
assert.ok(compaction.autoContinue([{ role: 'assistant', content: 'hi' }]));
|
||||
assert.ok(compaction.compactReminder({ voice: true }).indexOf('Do not greet') >= 0);
|
||||
assert.ok(compaction.VOICE_COMPACT_PROMPT.indexOf('Do not greet') >= 0);
|
||||
}
|
||||
|
||||
function testSearchReplace() {
|
||||
@@ -66,7 +108,17 @@ function testToolSet() {
|
||||
];
|
||||
const page = toolSet.filterBuiltinSchemas(all, { hostWorkspace: false, builtinTools: ['todo_write'] });
|
||||
assert.ok(!page.find((t) => t.name === 'read_file'));
|
||||
assert.ok(page.find((t) => t.name === 'todo_write'));
|
||||
const withFetch = toolSet.filterBuiltinSchemas(all, {
|
||||
hostWorkspace: true,
|
||||
builtinTools: ['web_fetch'],
|
||||
webFetch: true,
|
||||
});
|
||||
assert.ok(withFetch.find((t) => t.name === 'web_fetch'));
|
||||
const noFetch = toolSet.filterBuiltinSchemas(all, {
|
||||
hostWorkspace: true,
|
||||
builtinTools: ['web_fetch'],
|
||||
});
|
||||
assert.ok(!noFetch.find((t) => t.name === 'web_fetch'));
|
||||
}
|
||||
|
||||
function testPrompts() {
|
||||
@@ -74,6 +126,18 @@ function testPrompts() {
|
||||
assert.ok(prompts.DEFAULT_SYSTEM.indexOf('BridgeSwarm') < 0);
|
||||
const page = prompts.assemble({ cwd: 'container', hostWorkspace: false });
|
||||
assert.ok(page.indexOf('host filesystem') >= 0);
|
||||
const voice = prompts.assemble({
|
||||
personality: 'voice',
|
||||
extra: 'You are Jarvis, a local Ubuntu GNOME voice assistant.',
|
||||
cwd: '/tmp/jarvis',
|
||||
hostWorkspace: true,
|
||||
fsRead: () => '# AGENTS.md\nFollow coding-agent rules.',
|
||||
});
|
||||
assert.ok(voice.indexOf('You are Jarvis') >= 0);
|
||||
assert.ok(voice.indexOf(prompts.DEFAULT_SYSTEM) < 0);
|
||||
assert.ok(voice.indexOf('coding agent') < 0);
|
||||
assert.ok(voice.indexOf('AGENTS.md') < 0);
|
||||
assert.ok(voice.indexOf('Current workspace:') >= 0);
|
||||
}
|
||||
|
||||
function testNet() {
|
||||
@@ -81,6 +145,9 @@ function testNet() {
|
||||
assert.throws(() => net.assertPublicHttpUrl('http://192.168.1.1/x'));
|
||||
const u = net.assertPublicHttpUrl('https://example.com/a');
|
||||
assert.strictEqual(u.hostname, 'example.com');
|
||||
assert.strictEqual(net.assertHttpUrl('https://ifconfig.me/ip').hostname, 'ifconfig.me');
|
||||
assert.strictEqual(net.assertHttpUrl('http://192.168.1.1/status').hostname, '192.168.1.1');
|
||||
assert.throws(() => net.assertHttpUrl('file:///etc/passwd'));
|
||||
}
|
||||
|
||||
function testCustomTools() {
|
||||
@@ -124,6 +191,12 @@ function testTruncateAndPerm() {
|
||||
assert.strictEqual(pat, 'git status');
|
||||
assert.ok(policy.shellSafe('git status'));
|
||||
assert.ok(!policy.shellSafe('rm -rf /'));
|
||||
assert.ok(permRules.globish('uname -a', '*'));
|
||||
assert.strictEqual(permRules.patternFromArgs('run_terminal_cmd', { command: '*' }), '*');
|
||||
const voice = toolBudget.fromPayload({}, 'jarvis-qvac');
|
||||
toolBudget.markShell(voice);
|
||||
assert.strictEqual(voice.answerOnly, true);
|
||||
assert.ok(toolBudget.shouldSkipShell(voice));
|
||||
}
|
||||
|
||||
function testPaths() {
|
||||
|
||||
Reference in New Issue
Block a user