test(runner): preserve production conformance run context

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-08-18 16:22:45 +00:00
1 parent 904199558d
commit 931cdd8dff
1 file changed
+37 -1
@@ -251,6 +251,8 @@ class PaperclipRouteSemanticPort {
async refresh(): Promise<void> {
const [issue] = await this.db.select().from(issues).where(eq(issues.id, this.binding.taskId));
if (issue === undefined) throw new Error("semantic_conformance_task_missing");
const [run] = await this.db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, this.binding.runId));
if (run === undefined) throw new Error("semantic_conformance_run_missing");
const comments = await this.db.select().from(issueComments)
.where(eq(issueComments.issueId, issue.id))
.orderBy(asc(issueComments.createdAt), asc(issueComments.id));
@@ -269,7 +271,10 @@ class PaperclipRouteSemanticPort {
const relations = await this.db.select().from(issueRelations)
.where(and(eq(issueRelations.relatedIssueId, issue.id), eq(issueRelations.type, "blocks")));
const audit = await this.db.select().from(activityLog)
.where(eq(activityLog.companyId, this.ids.companyId))
.where(and(
eq(activityLog.companyId, this.ids.companyId),
eq(activityLog.runId, this.binding.runId),
))
.orderBy(asc(activityLog.createdAt), asc(activityLog.id));
const state = createCapabilityFixtureState({
@@ -346,6 +351,25 @@ class PaperclipRouteSemanticPort {
})),
});
state.lifecycle = "running";
state.activeRunId = run.id;
state.runs = [{
id: run.id,
companyId: run.companyId,
actorId: run.agentId,
taskId: issue.id,
sessionId: run.sessionIdAfter ?? run.sessionIdBefore ?? run.externalRunId ?? run.id,
backendKind: "runner",
sourceInstanceId: "paperclip-production-services",
status: toFixtureRunStatus(run.status),
attempt: run.scheduledRetryAttempt + 1,
openedAt: (run.startedAt ?? run.createdAt).toISOString(),
finishedAt: run.finishedAt?.toISOString() ?? null,
wake: { reason: "manual", payload: {} },
capabilities: [...this.binding.capabilities],
events: [],
result: null,
sessionCheckpoint: null,
}];
state.revision = this.#state.revision + 1;
state.audit = audit.map((entry) => ({
id: entry.id,
@@ -490,6 +514,18 @@ class PaperclipRouteSemanticPort {
}
}
function toFixtureRunStatus(status: string): CapabilityFixtureState["runs"][number]["status"] {
switch (status) {
case "running":
case "succeeded":
case "failed":
case "cancelled":
return status;
default:
throw new Error(`semantic_conformance_run_status_unmapped:${status}`);
}
}
function createProductionAuthorityApp(db: Db, ids: PaperclipSemanticConformanceIds): Application {
const app = express();
app.use(express.json());