import { injectable } from "@codemation/core"; import type { CreateTestSuiteRunArgs, TestSuiteChildRunSummary, TestSuiteRunRecord, TestSuiteRunRepository, UpdateTestSuiteRunPatch, } from "../../domain/runs/TestSuiteRunRepository"; @injectable() export class InMemoryTestSuiteRunRepository implements TestSuiteRunRepository { private readonly recordsById = new Map(); async create(args: CreateTestSuiteRunArgs): Promise { const now = new Date().toISOString(); const record: TestSuiteRunRecord = { id: args.id, workflowId: args.workflowId, triggerNodeId: args.triggerNodeId, triggerNodeName: args.triggerNodeName, status: "running", concurrency: args.concurrency, startedAt: args.startedAt, totalCases: 0, passedCases: 0, failedCases: 0, updatedAt: now, }; this.recordsById.set(args.id, record); } async update(id: string, patch: UpdateTestSuiteRunPatch): Promise { const existing = this.recordsById.get(id); if (!existing) { throw new Error(`Unknown TestSuiteRun id: ${id}`); } this.recordsById.set(id, { ...existing, ...patch, updatedAt: new Date().toISOString(), }); } async findById(id: string): Promise { return this.recordsById.get(id); } async listByWorkflow( args: Readonly<{ workflowId: string; limit?: number }>, ): Promise> { const filtered = [...this.recordsById.values()] .filter((r) => r.workflowId === args.workflowId) .sort((a, b) => (a.startedAt < b.startedAt ? 1 : -1)); return filtered.slice(0, args.limit ?? filtered.length); } async listChildRuns(_testSuiteRunId: string): Promise> { return []; } async deleteById(id: string): Promise { this.recordsById.delete(id); } }