refactor: launch external tools without Room credentials or hook settings
A Launcher launch still opens the tool in the active workspace's folder, tracks its process, streams observed output and stops it. What it no longer does: - set WAGGLE_SIGNAL_EMIT, WAGGLE_SIDECAR_URL, HIVE_MIND_DATA_DIR or the Room identity variables (WAGGLE_RUN_ID, WAGGLE_ROOM_ID, WAGGLE_DANCE_TEAM_ID, WAGGLE_SENDER_ID, WAGGLE_RUN_TOKEN). Only the removed coding-agent hooks and the WaggleDance CLI read them. The external-process allowlist now admits WAGGLE_WORKSPACE_ID alone; - issue a run credential. Run tokens existed for Room workers (the dance CLI and OpenClaw's model calls), so the registry's credential store, the middleware's run-token bearer on /v1/chat/completions and the proxy's per-run model scope go. While an agent run with a model is active, the proxy still serves only the session bearer. The run record that a launch creates in the agent-run registry stays: it backs cancel from the Room canvas, which this change does not remove.
This commit is contained in:
@@ -170,28 +170,6 @@ describe('AgentRunRegistry', () => {
|
||||
await expect(registry.control(first.id, 'cancel')).rejects.toThrow(/already cancelled/);
|
||||
});
|
||||
|
||||
it('issues ephemeral worker credentials and revokes them at terminal state', () => {
|
||||
const { registry, file } = createRegistry();
|
||||
const room = registry.createRoom({
|
||||
workspaceIds: ['alpha'], source: 'external_tool', title: 'External', task: 'Collaborate',
|
||||
});
|
||||
const worker = registry.createWorker({
|
||||
parentRunId: room.id, workspaceId: 'alpha', source: 'external_tool',
|
||||
executor: { kind: 'external_tool', toolId: 'codex' }, title: 'Codex', task: room.task,
|
||||
status: 'running',
|
||||
});
|
||||
|
||||
const token = registry.issueCredential(worker.id);
|
||||
expect(token.length).toBeGreaterThanOrEqual(32);
|
||||
expect(registry.authenticateCredential(token)?.id).toBe(worker.id);
|
||||
expect(registry.authenticateCredential('x'.repeat(43))).toBeUndefined();
|
||||
expect(fs.readFileSync(file, 'utf8')).not.toContain(token);
|
||||
|
||||
registry.update(worker.id, { status: 'completed' });
|
||||
expect(registry.authenticateCredential(token)).toBeUndefined();
|
||||
expect(() => registry.issueCredential(room.id)).toThrow(/Worker run not found/);
|
||||
});
|
||||
|
||||
it('marks internal work interrupted after restart and reconciles external pids separately', () => {
|
||||
const { registry, file } = createRegistry();
|
||||
const internalRoom = registry.createRoom({
|
||||
|
||||
@@ -19,7 +19,7 @@ import { CostTracker, runAgentLoop } from '@waggle/agent';
|
||||
import { ExecutionTraceStore, WaggleDB } from '@waggle/core';
|
||||
import { AgentRunRegistry } from '../../src/local/agent-run-registry.js';
|
||||
import { anthropicProxyRoutes } from '../../src/local/routes/anthropic-proxy.js';
|
||||
import { securityMiddleware, type RunTokenAuthResult } from '../../src/local/security-middleware.js';
|
||||
import { securityMiddleware } from '../../src/local/security-middleware.js';
|
||||
import { PROVIDER_ENV_NAMES } from '../../src/local/provider-env.js';
|
||||
|
||||
const MODEL_SPEND_RESERVATION_HEADER = 'x-waggle-model-spend-reservation';
|
||||
@@ -32,7 +32,6 @@ function createTestServer(options: {
|
||||
configApiKey?: string;
|
||||
dataDir?: string;
|
||||
sessionToken?: string;
|
||||
authenticateRunToken?: (token: string) => RunTokenAuthResult;
|
||||
costTracker?: CostTracker;
|
||||
traceStore?: FastifyInstance['traceStore'];
|
||||
registerSpendTarget?: string;
|
||||
@@ -70,10 +69,9 @@ function createTestServer(options: {
|
||||
dataDir: options.dataDir ?? '/tmp/nonexistent-waggle-test',
|
||||
});
|
||||
|
||||
if (options.sessionToken || options.authenticateRunToken) {
|
||||
if (options.sessionToken) {
|
||||
server.register(securityMiddleware, {
|
||||
sessionToken: options.sessionToken,
|
||||
authenticateRunToken: options.authenticateRunToken,
|
||||
});
|
||||
}
|
||||
server.register(anthropicProxyRoutes);
|
||||
@@ -1420,232 +1418,53 @@ describe('Anthropic Proxy Routes', () => {
|
||||
costTracker.releaseReservedModelSpend(reservation);
|
||||
});
|
||||
|
||||
it('rejects a run token completion when the requested model is outside the assigned run model', async () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-run-token-model-scope-'));
|
||||
it('serves only the session bearer while an agent run with a model is active', async () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-active-run-bearer-'));
|
||||
const registry = new AgentRunRegistry(path.join(dataDir, 'agent-runs.json'));
|
||||
const room = registry.createRoom({
|
||||
workspaceIds: ['workspace-1'],
|
||||
source: 'external_tool',
|
||||
title: 'OpenClaw room',
|
||||
task: 'Use the assigned model only',
|
||||
source: 'fleet',
|
||||
title: 'Fleet room',
|
||||
task: 'Answer with the assigned model',
|
||||
});
|
||||
const run = registry.createWorker({
|
||||
registry.createWorker({
|
||||
parentRunId: room.id,
|
||||
workspaceId: 'workspace-1',
|
||||
source: 'external_tool',
|
||||
executor: { kind: 'external_tool', toolId: 'openclaw', model: 'anthropic/claude-sonnet-4-6' },
|
||||
title: 'OpenClaw',
|
||||
source: 'fleet',
|
||||
executor: { kind: 'waggle_agent', model: 'anthropic/claude-sonnet-4-6' },
|
||||
title: 'Fleet agent',
|
||||
task: room.task,
|
||||
status: 'running',
|
||||
});
|
||||
const runToken = registry.issueCredential(run.id);
|
||||
server = createTestServer({
|
||||
vaultApiKey: 'anthropic-key',
|
||||
vaultProviders: { openai: { value: 'openai-key' } },
|
||||
});
|
||||
server = createTestServer({ vaultApiKey: 'anthropic-key' });
|
||||
server.decorate('agentRunRegistry', registry);
|
||||
server.decorate('agentState', { wsSessionToken: 'desktop-session-token' } as FastifyInstance['agentState']);
|
||||
globalThis.fetch = vi.fn(async () => new Response(JSON.stringify({
|
||||
content: [{ type: 'text', text: 'assigned model response' }],
|
||||
content: [{ type: 'text', text: 'ok' }],
|
||||
model: 'claude-sonnet-4-6',
|
||||
stop_reason: 'end_turn',
|
||||
usage: { input_tokens: 1, output_tokens: 2 },
|
||||
}), { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof globalThis.fetch;
|
||||
|
||||
try {
|
||||
const response = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
payload: {
|
||||
model: 'openai/gpt-4.1',
|
||||
messages: [{ role: 'user', content: 'Use a different provider' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(response.json().error.message).toContain('outside the assigned run model');
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
|
||||
const sameProvider = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
payload: {
|
||||
model: 'anthropic/claude-opus-4-6',
|
||||
messages: [{ role: 'user', content: 'Use a different Anthropic model' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(sameProvider.statusCode).toBe(403);
|
||||
expect(sameProvider.json().error.message).toContain('outside the assigned run model');
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
|
||||
const missingToken = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
payload: {
|
||||
model: 'openai/gpt-4.1',
|
||||
messages: [{ role: 'user', content: 'Use a different provider without a run token' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(missingToken.statusCode).toBe(401);
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
|
||||
const invalidToken = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: 'Bearer invalid-run-token-with-enough-entropy-123' },
|
||||
payload: {
|
||||
model: 'openai/gpt-4.1',
|
||||
messages: [{ role: 'user', content: 'Use a different provider with an invalid run token' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(invalidToken.statusCode).toBe(401);
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
|
||||
const assigned = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: `bearer ${runToken}` },
|
||||
payload: {
|
||||
model: 'claude-sonnet-4.6',
|
||||
messages: [{ role: 'user', content: 'Use the assigned provider' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(assigned.statusCode).toBe(200);
|
||||
expect(assigned.json().choices[0].message.content).toBe('assigned model response');
|
||||
expect(vi.mocked(globalThis.fetch).mock.calls[0][0]).toBe('https://api.anthropic.com/v1/messages');
|
||||
} finally {
|
||||
registry.close();
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects a run token completion when the token is revoked between auth and route handling', async () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-run-token-revocation-race-'));
|
||||
const registry = new AgentRunRegistry(path.join(dataDir, 'agent-runs.json'));
|
||||
const room = registry.createRoom({
|
||||
workspaceIds: ['workspace-1'],
|
||||
source: 'external_tool',
|
||||
title: 'OpenClaw room',
|
||||
task: 'Use the assigned model only',
|
||||
});
|
||||
const run = registry.createWorker({
|
||||
parentRunId: room.id,
|
||||
workspaceId: 'workspace-1',
|
||||
source: 'external_tool',
|
||||
executor: { kind: 'external_tool', toolId: 'openclaw', model: 'anthropic/claude-sonnet-4-6' },
|
||||
title: 'OpenClaw',
|
||||
task: room.task,
|
||||
});
|
||||
const runToken = registry.issueCredential(run.id);
|
||||
let revokedAfterMiddlewareAuth = false;
|
||||
server = createTestServer({
|
||||
vaultApiKey: 'anthropic-key',
|
||||
sessionToken: 'desktop-session-token',
|
||||
authenticateRunToken: (candidate) => {
|
||||
if (candidate !== runToken) return false;
|
||||
const authenticatedRun = registry.authenticateCredential(candidate);
|
||||
if (!authenticatedRun) return false;
|
||||
if (!revokedAfterMiddlewareAuth) {
|
||||
revokedAfterMiddlewareAuth = true;
|
||||
registry.revokeCredential(candidate);
|
||||
}
|
||||
return { runId: authenticatedRun.id, model: authenticatedRun.executor.model };
|
||||
const completion = (authorization?: string) => server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: authorization ? { authorization } : {},
|
||||
payload: {
|
||||
model: 'claude-sonnet-4.6',
|
||||
messages: [{ role: 'user', content: 'Hello' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
server.decorate('agentRunRegistry', registry);
|
||||
globalThis.fetch = vi.fn(async () => new Response(JSON.stringify({
|
||||
content: [{ type: 'text', text: 'should not forward' }],
|
||||
model: 'claude-sonnet-4-6',
|
||||
stop_reason: 'end_turn',
|
||||
usage: { input_tokens: 1, output_tokens: 2 },
|
||||
}), { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof globalThis.fetch;
|
||||
|
||||
try {
|
||||
const response = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
payload: {
|
||||
model: 'openai/gpt-4.1',
|
||||
messages: [{ role: 'user', content: 'Use a different provider after token revocation' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
expect(response.json().error.message).toContain('no longer active');
|
||||
const missing = await completion();
|
||||
expect(missing.statusCode).toBe(401);
|
||||
const foreign = await completion('Bearer run-token-with-enough-entropy-1234567890');
|
||||
expect(foreign.statusCode).toBe(401);
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
registry.close();
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects a run token completion when the assigned model changes after middleware auth', async () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-run-token-model-reassignment-'));
|
||||
const registry = new AgentRunRegistry(path.join(dataDir, 'agent-runs.json'));
|
||||
const room = registry.createRoom({
|
||||
workspaceIds: ['workspace-1'],
|
||||
source: 'external_tool',
|
||||
title: 'OpenClaw room',
|
||||
task: 'Use the currently assigned model only',
|
||||
});
|
||||
const run = registry.createWorker({
|
||||
parentRunId: room.id,
|
||||
workspaceId: 'workspace-1',
|
||||
source: 'external_tool',
|
||||
executor: { kind: 'external_tool', toolId: 'openclaw', model: 'anthropic/claude-sonnet-4-6' },
|
||||
title: 'OpenClaw',
|
||||
task: room.task,
|
||||
});
|
||||
const runToken = registry.issueCredential(run.id);
|
||||
let reassignedAfterMiddlewareAuth = false;
|
||||
server = createTestServer({
|
||||
vaultApiKey: 'anthropic-key',
|
||||
sessionToken: 'desktop-session-token',
|
||||
authenticateRunToken: (candidate) => {
|
||||
if (candidate !== runToken) return false;
|
||||
const authenticatedRun = registry.authenticateCredential(candidate);
|
||||
if (!authenticatedRun) return false;
|
||||
if (!reassignedAfterMiddlewareAuth) {
|
||||
reassignedAfterMiddlewareAuth = true;
|
||||
registry.update(authenticatedRun.id, { executor: { model: 'anthropic/claude-haiku-4-5' } });
|
||||
}
|
||||
return { runId: authenticatedRun.id, model: authenticatedRun.executor.model };
|
||||
},
|
||||
});
|
||||
server.decorate('agentRunRegistry', registry);
|
||||
globalThis.fetch = vi.fn(async () => new Response(JSON.stringify({
|
||||
content: [{ type: 'text', text: 'should not forward' }],
|
||||
model: 'claude-sonnet-4-6',
|
||||
stop_reason: 'end_turn',
|
||||
usage: { input_tokens: 1, output_tokens: 2 },
|
||||
}), { status: 200, headers: { 'content-type': 'application/json' } })) as unknown as typeof globalThis.fetch;
|
||||
|
||||
try {
|
||||
const response = await server.inject({
|
||||
method: 'POST',
|
||||
url: '/v1/chat/completions',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
payload: {
|
||||
model: 'claude-sonnet-4.6',
|
||||
messages: [{ role: 'user', content: 'Use the model that was assigned during middleware auth' }],
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(response.json().error.message).toContain('outside the assigned run model');
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
const session = await completion('Bearer desktop-session-token');
|
||||
expect(session.statusCode, session.body).toBe(200);
|
||||
} finally {
|
||||
registry.close();
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
|
||||
@@ -23,13 +23,11 @@ import {
|
||||
async function createTestServer(opts?: {
|
||||
rateLimiter?: { maxRequests?: number; windowMs?: number };
|
||||
sessionToken?: string;
|
||||
authenticateRunToken?: (token: string) => boolean;
|
||||
}) {
|
||||
const server = Fastify({ logger: false });
|
||||
await server.register(securityMiddleware, {
|
||||
rateLimiter: opts?.rateLimiter,
|
||||
sessionToken: opts?.sessionToken,
|
||||
authenticateRunToken: opts?.authenticateRunToken,
|
||||
});
|
||||
|
||||
// Simple test routes
|
||||
@@ -424,52 +422,21 @@ describe('Bearer Token Authentication', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('accepts a narrow run token only as a Bearer on the model completion route', async () => {
|
||||
const runToken = 'run-token-with-enough-entropy-1234567890';
|
||||
const server = await createTestServer({
|
||||
sessionToken: TEST_TOKEN,
|
||||
authenticateRunToken: (candidate) => candidate === runToken,
|
||||
});
|
||||
it('accepts only the session token on the model completion route (no run tokens)', async () => {
|
||||
const server = await createTestServer({ sessionToken: TEST_TOKEN });
|
||||
try {
|
||||
const completion = await server.inject({
|
||||
method: 'POST', url: '/v1/chat/completions',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
headers: { authorization: `Bearer ${TEST_TOKEN}` },
|
||||
});
|
||||
expect(completion.statusCode).toBe(200);
|
||||
|
||||
const unrelated = await server.inject({
|
||||
method: 'GET', url: '/api/test',
|
||||
headers: { 'x-waggle-run-token': runToken },
|
||||
});
|
||||
expect(unrelated.statusCode).toBe(401);
|
||||
const unrelatedBearer = await server.inject({
|
||||
method: 'GET', url: '/api/test',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
});
|
||||
expect(unrelatedBearer.statusCode).toBe(401);
|
||||
const wrongTransport = await server.inject({
|
||||
const runTokenShaped = await server.inject({
|
||||
method: 'POST', url: '/v1/chat/completions',
|
||||
headers: { 'x-waggle-run-token': runToken },
|
||||
headers: { authorization: 'Bearer run-token-with-enough-entropy-1234567890' },
|
||||
});
|
||||
expect(wrongTransport.statusCode).toBe(401);
|
||||
// The WaggleDance transport no longer accepts run tokens in either form.
|
||||
const danceHeader = await server.inject({
|
||||
method: 'POST', url: '/api/waggle-dance/signal',
|
||||
headers: { 'x-waggle-run-token': runToken },
|
||||
});
|
||||
expect(danceHeader.statusCode).toBe(401);
|
||||
expect(danceHeader.json().code).toBe('MISSING_TOKEN');
|
||||
const danceBearer = await server.inject({
|
||||
method: 'POST', url: '/api/waggle-dance/signal',
|
||||
headers: { authorization: `Bearer ${runToken}` },
|
||||
});
|
||||
expect(danceBearer.statusCode).toBe(401);
|
||||
const wrongCompletion = await server.inject({
|
||||
method: 'POST', url: '/v1/chat/completions',
|
||||
headers: { authorization: 'Bearer wrong-run-token-with-enough-entropy-123' },
|
||||
});
|
||||
expect(wrongCompletion.statusCode).toBe(401);
|
||||
expect(wrongCompletion.json().code).toBe('INVALID_TOKEN');
|
||||
expect(runTokenShaped.statusCode).toBe(401);
|
||||
expect(runTokenShaped.json().code).toBe('INVALID_TOKEN');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ vi.mock('@waggle/agent', async (importOriginal) => {
|
||||
import { buildLocalServer } from '../src/local/index.js';
|
||||
import { injectWithAuth } from './test-utils.js';
|
||||
import { detectInstalledTools, launchTool } from '@waggle/agent';
|
||||
import { loopbackSidecarUrl } from '../src/local/routes/tools.js';
|
||||
import { resolveWorkspaceExecutionRoot } from '../src/local/workspace-execution-root.js';
|
||||
|
||||
function createTmpDir(prefix: string): string {
|
||||
@@ -131,10 +130,6 @@ describe('POST /api/tools/launch', () => {
|
||||
id: 'claude-code',
|
||||
installedPath: '/server-detected/claude-code',
|
||||
workspaceId,
|
||||
dataDir: tmpDir,
|
||||
runId: expect.stringMatching(/^run_/),
|
||||
roomId: expect.stringMatching(/^room_/),
|
||||
runToken: expect.any(String),
|
||||
}),
|
||||
);
|
||||
expect(body.roomId).toMatch(/^room_/);
|
||||
@@ -168,18 +163,15 @@ describe('POST /api/tools/launch', () => {
|
||||
},
|
||||
});
|
||||
const body = response.json() as { runId: string };
|
||||
const call = vi.mocked(launchTool).mock.calls[0][0] as { runToken?: string };
|
||||
expect(server.agentRunRegistry.authenticateCredential(call.runToken ?? '')?.id).toBe(body.runId);
|
||||
|
||||
for (const listener of exitListeners) listener(0);
|
||||
|
||||
expect(server.agentRunRegistry.get(body.runId)).toMatchObject({
|
||||
status: 'completed', result: { summary: 'Interactive tool process exited successfully' },
|
||||
});
|
||||
expect(server.agentRunRegistry.authenticateCredential(call.runToken ?? '')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('passes signalEmit:true so a dock launch lights the bus (#1)', async () => {
|
||||
it('passes no hook, Room or data-directory settings to the launched tool', async () => {
|
||||
vi.mocked(launchTool).mockClear();
|
||||
const res = await injectWithAuth(server, {
|
||||
method: 'POST',
|
||||
@@ -188,15 +180,9 @@ describe('POST /api/tools/launch', () => {
|
||||
payload: { id: 'claude-code', installedPath: '/usr/local/bin/claude' },
|
||||
});
|
||||
expect(res.statusCode).toBe(202);
|
||||
expect(launchTool).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ signalEmit: true }),
|
||||
);
|
||||
// sidecarUrl is derived from the loopback host fastify.inject used,
|
||||
// so it is either undefined (non-loopback authority) or an
|
||||
// http://<loopback> string — never a non-loopback origin.
|
||||
const callArg = vi.mocked(launchTool).mock.calls[0][0] as { sidecarUrl?: string };
|
||||
if (callArg.sidecarUrl !== undefined) {
|
||||
expect(callArg.sidecarUrl).toMatch(/^http:\/\/(127\.0\.0\.1|localhost|\[::1\]|::1)(:\d+)?$/i);
|
||||
const callArg = vi.mocked(launchTool).mock.calls[0][0] as unknown as Record<string, unknown>;
|
||||
for (const removed of ['signalEmit', 'sidecarUrl', 'dataDir', 'runId', 'roomId', 'runToken']) {
|
||||
expect(callArg, removed).not.toHaveProperty(removed);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -929,31 +915,6 @@ describe('POST /api/tools/hooks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── loopbackSidecarUrl helper (#1) ──────────────────────────────────
|
||||
|
||||
describe('loopbackSidecarUrl', () => {
|
||||
it.each([
|
||||
['127.0.0.1:3333', 'http://127.0.0.1:3333'],
|
||||
['localhost', 'http://localhost'],
|
||||
['localhost:8080', 'http://localhost:8080'],
|
||||
['[::1]:3000', 'http://[::1]:3000'],
|
||||
])('maps loopback host %s → %s', (host, expected) => {
|
||||
expect(loopbackSidecarUrl(host)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
'',
|
||||
'evil.com',
|
||||
'10.0.0.5:3333',
|
||||
'example.com:80',
|
||||
'169.254.1.1',
|
||||
'::1', // bare (unbracketed) IPv6 → rejected; would be a malformed URL
|
||||
])('returns undefined for non-loopback / missing host %s', (host) => {
|
||||
expect(loopbackSidecarUrl(host as string | undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ── persistence + reconcile across sidecar restart (#2) ─────────────
|
||||
|
||||
describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
@@ -989,7 +950,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
});
|
||||
expect(response.statusCode).toBe(202);
|
||||
const { runId } = response.json() as { runId: string };
|
||||
const runToken = (vi.mocked(launchTool).mock.calls[0][0] as { runToken: string }).runToken;
|
||||
expect(fs.existsSync(path.join(tmpDir, 'launched-processes.json'))).toBe(true);
|
||||
await server1.close();
|
||||
server1 = undefined;
|
||||
@@ -997,7 +957,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
server2 = await buildLocalServer({ dataDir: tmpDir });
|
||||
await server2.ready();
|
||||
expect(server2.agentRunRegistry.get(runId)?.status).toBe('running');
|
||||
expect(server2.agentRunRegistry.authenticateCredential(runToken)).toBeUndefined();
|
||||
expect(server2.toolProcessTracker?.list().some((process) => process.pid === child.pid)).toBe(true);
|
||||
|
||||
const launchCallsBeforeCompeting = vi.mocked(launchTool).mock.calls.length;
|
||||
@@ -1146,7 +1105,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
payload: { id: 'claude-code', installedPath: '/x', workspaceId },
|
||||
});
|
||||
const { runId } = response.json() as { runId: string };
|
||||
const runToken = (vi.mocked(launchTool).mock.calls[0][0] as { runToken: string }).runToken;
|
||||
await server1.close();
|
||||
server1 = undefined;
|
||||
await stopChild(child);
|
||||
@@ -1157,7 +1115,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
status: 'interrupted',
|
||||
result: { error: 'External process was not running when Waggle restarted' },
|
||||
});
|
||||
expect(server2.agentRunRegistry.authenticateCredential(runToken)).toBeUndefined();
|
||||
expect(server2.toolProcessTracker?.list().some((process) => process.pid === child.pid)).toBe(false);
|
||||
} finally {
|
||||
if (server1) await server1.close();
|
||||
|
||||
Reference in New Issue
Block a user