40 lines
3.3 KiB
JavaScript
40 lines
3.3 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { randomUUID } from 'node:crypto';
|
|
import { resolveControlledInstallation } from '../src/core/engines/controlled-installation.mjs';
|
|
import { ControlledDeepSeekSession } from '../src/core/engines/controlled-session.mjs';
|
|
const root = path.resolve('.qa/controlled-native-' + randomUUID()), cwd = path.join(root, 'project');
|
|
fs.mkdirSync(cwd, { recursive: true }); fs.writeFileSync(path.join(cwd, 'README.md'), '# Owned controlled SDK fixture\n');
|
|
const owner = Object.fromEntries(['sessionId', 'projectId', 'taskId', 'runId', 'jobId'].map(key => [key, randomUUID()]));
|
|
const installation = resolveControlledInstallation(process.cwd(), process.env.AGENT_WORKBENCH_DEEPSEEK_ROOT);
|
|
assert.equal(installation.controlledStatus, 'available', installation.message);
|
|
const controller = new AbortController(), timeout = setTimeout(() => controller.abort(new Error('Owned fixture deadline.')), 30000);
|
|
const driver = new ControlledDeepSeekSession(installation, { timeoutMs: 10000 }); let success = false, failure = null, modelCalls = 0, toolCalls = 0;
|
|
try {
|
|
await driver.open({ directory: path.join(root, 'runtime'), cwd, owner, sdkSessionId: randomUUID(), signal: controller.signal,
|
|
tools: [{ name: 'read_file', description: 'Read one owned fixture file.', parameters: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'] } }],
|
|
config: { model: 'fixture-controlled', maxOutputTokens: 512, contextLimit: 32000, maxRunDurationMs: 30000 },
|
|
onModel: async input => {
|
|
modelCalls++;
|
|
assert.equal(input.model, 'fixture-controlled');
|
|
return { message: { role: 'assistant', content: modelCalls === 1 ? '' : 'Owned fixture inspected.', ...(modelCalls === 1 ? {
|
|
tool_calls: [{ id: 'controlled-read-1', type: 'function', function: { name: 'read_file', arguments: JSON.stringify({ path: 'README.md' }) } }],
|
|
} : {}) }, usage: { prompt_tokens: 30, completion_tokens: 8, total_tokens: 38 } };
|
|
},
|
|
onTool: async input => { toolCalls++; assert.equal(input.name, 'read_file'); assert.equal(input.arguments.path, 'README.md'); return { text: fs.readFileSync(path.join(cwd, input.arguments.path), 'utf8') }; },
|
|
onState: state => console.log('STATE ' + state),
|
|
});
|
|
await driver.prompt('Read README.md with the owned tool and report completion.');
|
|
assert.equal(await driver.wait(), 'Owned fixture inspected.'); assert.equal(modelCalls, 2); assert.equal(toolCalls, 1);
|
|
success = true;
|
|
} catch (error) { failure = { name: error.name, message: error.message, stack: error.stack }; }
|
|
finally {
|
|
const report = await driver.close({ force: !success }); clearTimeout(timeout);
|
|
fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify({ success, scope: 'actual-harness-scripted-model-controlled-bridge', installation,
|
|
owner, modelCalls, toolCalls, realModelRequests: 0, failure, report }, null, 2));
|
|
fs.writeFileSync('.qa/controlled-native-first-location.json', JSON.stringify({ root, result: path.join(root, 'result.json') }));
|
|
console.log(JSON.stringify({ success, root, modelCalls, toolCalls, realModelRequests: 0, status: report.status, error: failure?.message ?? null, stderr: report.stderr?.slice(-3000) }));
|
|
assert.equal(success, true, failure?.message); assert.equal(report.status, 'closed'); assert.equal(report.cleanup.rootExited, true);
|
|
}
|