f3348f45c0
Add events-only Context Runtime shadow portal verification to save LLM tokens, wire Tool Gateway → dsh headless smoke, and document both flows. Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Minimal Tool Gateway → dsh executor E2E (one headless task, costs LLM tokens).
|
|
*
|
|
* Usage:
|
|
* MEMIND_TOOL_GATEWAY_DSH_ENABLED=1 \
|
|
* node scripts/test-dsh-executor-gateway-e2e.mjs
|
|
*/
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { buildDshExecutorLaunchPlan } from '../dsh-agent-launch.mjs';
|
|
import { createToolGateway } from '../tool-gateway.mjs';
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const cwd = process.argv[2] ?? root;
|
|
const instruction = process.env.MEMIND_DSH_GATEWAY_TASK
|
|
?? 'List three files in the workspace root and stop. Do not modify any files.';
|
|
|
|
process.env.MEMIND_TOOL_GATEWAY_ENABLED = process.env.MEMIND_TOOL_GATEWAY_ENABLED ?? '1';
|
|
process.env.MEMIND_TOOL_GATEWAY_DRY_RUN = '0';
|
|
process.env.MEMIND_TOOL_GATEWAY_DSH_ENABLED = process.env.MEMIND_TOOL_GATEWAY_DSH_ENABLED ?? '1';
|
|
process.env.MEMIND_TOOL_GATEWAY_DSH_TASK_TYPES = process.env.MEMIND_TOOL_GATEWAY_DSH_TASK_TYPES ?? 'repo_refactor';
|
|
|
|
const gateway = createToolGateway({
|
|
env: process.env,
|
|
llmProviderService: {
|
|
async getExecutorLaunchPlan(executor, options) {
|
|
if (executor !== 'dsh') {
|
|
throw new Error(`unexpected executor ${executor}`);
|
|
}
|
|
return buildDshExecutorLaunchPlan({
|
|
cwd: options.cwd,
|
|
instruction: options.instruction,
|
|
env: process.env,
|
|
runtimeEnv: {
|
|
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY ?? process.env.OPENAI_API_KEY ?? '',
|
|
},
|
|
});
|
|
},
|
|
},
|
|
});
|
|
|
|
const status = gateway.getStatus();
|
|
console.log('DSH_GATEWAY_E2E_PROBE:');
|
|
console.log(JSON.stringify({
|
|
enabled: status.enabled,
|
|
dryRun: status.dryRun,
|
|
executors: status.executors,
|
|
dshEnabled: status.dshEnabled,
|
|
dshTaskTypes: status.dshTaskTypes,
|
|
selected: gateway.selectExecutor({ taskType: 'repo_refactor' }),
|
|
}, null, 2));
|
|
|
|
if (!status.dshEnabled) {
|
|
console.error('DSH_GATEWAY_E2E_FAIL: MEMIND_TOOL_GATEWAY_DSH_ENABLED is off');
|
|
process.exit(1);
|
|
}
|
|
|
|
const result = await gateway.executeJob({
|
|
runId: 'dsh-gateway-e2e',
|
|
requestId: 'dsh-gateway-req',
|
|
userId: 'local-user',
|
|
cwd,
|
|
taskType: 'repo_refactor',
|
|
timeoutMs: Number(process.env.MEMIND_DSH_GATEWAY_TIMEOUT_MS ?? 180_000),
|
|
userMessage: {
|
|
content: [{ type: 'text', text: instruction }],
|
|
metadata: {
|
|
memindRun: {
|
|
taskType: 'repo_refactor',
|
|
toolMode: 'code',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const stdoutPreview = String(result.stdout ?? result.displayStdout ?? '').trim().slice(0, 500);
|
|
console.log('DSH_GATEWAY_E2E_RESULT:');
|
|
console.log(JSON.stringify({
|
|
ok: result.ok,
|
|
executor: result.executor,
|
|
exitCode: result.exitCode,
|
|
stdoutPreview,
|
|
}, null, 2));
|
|
|
|
if (!result.ok || result.executor !== 'dsh') {
|
|
console.error('DSH_GATEWAY_E2E_FAIL');
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('DSH_GATEWAY_E2E_OK');
|