(input: ActivityInput, summary: WorkflowSummary)
| 1013 | * Cleans up container when done. |
| 1014 | */ |
| 1015 | export async function logWorkflowComplete(input: ActivityInput, summary: WorkflowSummary): Promise<void> { |
| 1016 | const { workflowId } = input; |
| 1017 | const sessionMetadata = buildSessionMetadata(input); |
| 1018 | |
| 1019 | // 1. Initialize audit session and mark final status |
| 1020 | const auditSession = new AuditSession(sessionMetadata); |
| 1021 | await auditSession.initialize(workflowId); |
| 1022 | await auditSession.updateSessionStatus(summary.status); |
| 1023 | |
| 1024 | // 2. Load cumulative metrics from session.json |
| 1025 | const sessionData = (await auditSession.getMetrics()) as { |
| 1026 | metrics: { |
| 1027 | total_duration_ms: number; |
| 1028 | total_cost_usd: number; |
| 1029 | agents: Record<string, { final_duration_ms: number; total_cost_usd: number }>; |
| 1030 | }; |
| 1031 | }; |
| 1032 | |
| 1033 | // 3. Fill in metrics for skipped agents (resumed from previous run) |
| 1034 | const agentMetrics = { ...summary.agentMetrics }; |
| 1035 | for (const agentName of summary.completedAgents) { |
| 1036 | if (!agentMetrics[agentName]) { |
| 1037 | const agentData = sessionData.metrics.agents[agentName]; |
| 1038 | if (agentData) { |
| 1039 | agentMetrics[agentName] = { |
| 1040 | durationMs: agentData.final_duration_ms, |
| 1041 | costUsd: agentData.total_cost_usd, |
| 1042 | }; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | // 4. Build cumulative summary with cross-run totals |
| 1048 | const cumulativeSummary: WorkflowSummary = { |
| 1049 | ...summary, |
| 1050 | totalDurationMs: sessionData.metrics.total_duration_ms, |
| 1051 | totalCostUsd: sessionData.metrics.total_cost_usd, |
| 1052 | agentMetrics, |
| 1053 | }; |
| 1054 | |
| 1055 | // 5. Write completion entry to workflow.log |
| 1056 | await auditSession.logWorkflowComplete(cumulativeSummary); |
| 1057 | |
| 1058 | // 6. Drop the authenticated browser session |
| 1059 | try { |
| 1060 | await fs.rm(authStateFile(sessionMetadata), { force: true }); |
| 1061 | } catch (error) { |
| 1062 | const detail = error instanceof Error ? error.message : String(error); |
| 1063 | console.warn(`Failed to clean up auth-state.json: ${detail}`); |
| 1064 | } |
| 1065 | |
| 1066 | // 7. Clean up container |
| 1067 | removeContainer(workflowId); |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * Merge external findings into the exploitation queue for a vulnerability type. |
nothing calls this directly
no test coverage detected