Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions worker/src/temporal/activities/__tests__/mcp.activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,36 @@ describe('MCP Activities', () => {
expect(rmCalls.length).toBe(2);
});

it('does not mirror successful cleanup diagnostics to console.log by default', async () => {
delete process.env.SENTRIS_DEBUG_WORKFLOW;
(globalThis.fetch as unknown as ReturnType<typeof vi.fn>).mockResolvedValue(
createMockFetchResponse({ containerIds: ['container-1'] }),
);

mockExecFile.mockImplementation(async (cmd: string, args: string[]) => {
if (args.includes('ps')) {
return { stdout: '', stderr: '' };
}
if (args.includes('rm')) {
return { stdout: '', stderr: '' };
}
if (args.includes('volume')) {
return { stdout: '', stderr: '' };
}
return { stdout: '', stderr: '' };
});

const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

try {
await cleanupRunResourcesActivity({ runId: 'run-cleanup-quiet' });

expect(consoleSpy).not.toHaveBeenCalled();
} finally {
consoleSpy.mockRestore();
}
});

it('skips containers with unsafe IDs', async () => {
(globalThis.fetch as unknown as ReturnType<typeof vi.fn>).mockResolvedValue(
createMockFetchResponse({ containerIds: ['valid-container', '; rm -rf /'] }),
Expand Down
9 changes: 5 additions & 4 deletions worker/src/temporal/activities/mcp.activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AreAllToolsReadyActivityInput,
AreAllToolsReadyActivityOutput,
} from '../types';
import { workflowDiagnosticLog } from '../workflow-diagnostics';

const DEFAULT_API_BASE_URL =
process.env.SENTRIS_API_BASE_URL ?? process.env.API_BASE_URL ?? 'http://localhost:3211';
Expand Down Expand Up @@ -138,7 +139,7 @@ export async function cleanupRunResourcesActivity(
.map((line) => line.trim())
.filter(Boolean);

console.log(
workflowDiagnosticLog(
`[MCP Cleanup] Found ${namePatternContainerIds.length} containers matching name pattern`,
);
} catch (error: unknown) {
Expand All @@ -150,13 +151,13 @@ export async function cleanupRunResourcesActivity(
new Set([...registryContainerIds, ...namePatternContainerIds]),
);

console.log(
workflowDiagnosticLog(
`[MCP Cleanup] Cleaning up ${allContainerIds.length} containers for run ${input.runId} ` +
`(${registryContainerIds.length} from registry, ${namePatternContainerIds.length} from name pattern)`,
);

if (allContainerIds.length === 0) {
console.log(`[MCP Cleanup] No containers to clean up for run ${input.runId}`);
workflowDiagnosticLog(`[MCP Cleanup] No containers to clean up for run ${input.runId}`);
} else {
await Promise.all(
allContainerIds.map(async (containerId: string) => {
Expand All @@ -167,7 +168,7 @@ export async function cleanupRunResourcesActivity(
}
try {
await execFileAsync('docker', ['rm', '-f', containerId]);
console.log(`[MCP Cleanup] Removed container: ${containerId}`);
workflowDiagnosticLog(`[MCP Cleanup] Removed container: ${containerId}`);
} catch (error: unknown) {
console.warn(`[MCP Cleanup] Failed to remove container ${containerId}:`, error);
}
Expand Down
Loading