From 23211f7724531e825c4894dd83f902b7acbabf4e Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 12 Sep 2026 19:39:37 -0500 Subject: [PATCH] test: isolate authorization setup and identify queued user comments Finish cold route imports before shared-mock test loops begin, and seed explicit user authorship required by locked queued-comment admission. Preserve all authorization and responsible-user assertions. Co-Authored-By: Paperclip --- .../src/__tests__/agent-cross-tenant-authz-routes.test.ts | 8 +++++++- .../heartbeat-responsible-user-invariant.test.ts | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/__tests__/agent-cross-tenant-authz-routes.test.ts b/server/src/__tests__/agent-cross-tenant-authz-routes.test.ts index ddb3f40da0..60c3a20a36 100644 --- a/server/src/__tests__/agent-cross-tenant-authz-routes.test.ts +++ b/server/src/__tests__/agent-cross-tenant-authz-routes.test.ts @@ -1,6 +1,6 @@ import express from "express"; import request from "supertest"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; vi.unmock("http"); vi.unmock("node:http"); @@ -344,6 +344,12 @@ function resetMockDefaults() { } describe.sequential("agent cross-tenant route authorization", () => { + // Pay the cold route transform cost before a test starts mutating shared mocks. + // A timed-out import otherwise leaves its request loop running into later tests. + beforeAll(async () => { + await loadRouteModules(); + }, 60_000); + beforeEach(() => { resetMockDefaults(); }); diff --git a/server/src/__tests__/heartbeat-responsible-user-invariant.test.ts b/server/src/__tests__/heartbeat-responsible-user-invariant.test.ts index 0fd788d258..fdbd86b244 100644 --- a/server/src/__tests__/heartbeat-responsible-user-invariant.test.ts +++ b/server/src/__tests__/heartbeat-responsible-user-invariant.test.ts @@ -156,7 +156,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => { membershipRole: "operator", status: "active" }); await db.insert(issues).values({ id: issueId, companyId, title: "Interrupted queue", status: "todo", assigneeAgentId: agentId, responsibleUserId: ownerUserId }); - await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorUserId: ownerUserId, body: "Continue the task" }); + await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorType: "user", authorUserId: ownerUserId, body: "Continue the task" }); await db.insert(agentWakeupRequests).values({ id: queueId, companyId, agentId, source: "automation", status: "deferred_issue_execution", requestedByActorType: "system", payload: { issueId, commentId, queuedCommentInterrupt: { actorId: operatorId, requestedAt: new Date().toISOString() }, @@ -185,7 +185,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => { membershipRole: "operator", status: "active" }); await db.insert(issues).values({ id: issueId, companyId, title: "Manual wake", status: "todo", assigneeAgentId: agentId, responsibleUserId: ownerUserId }); - await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorUserId: ownerUserId, body: "Pending work" }); + await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorType: "user", authorUserId: ownerUserId, body: "Pending work" }); await db.insert(agentWakeupRequests).values({ id: queueId, companyId, agentId, source: "automation", reason: "issue_commented", status: "deferred_issue_execution", requestedByActorType: "user", requestedByActorId: ownerUserId, payload: { issueId, commentId, _paperclipWakeContext: { wakeCommentIds: [commentId] } }, @@ -216,7 +216,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => { requestedByActorType: "user", requestedByActorId: ownerUserId }); try { await vi.waitFor(() => expect(mockAdapterExecute).toHaveBeenCalled(), { timeout: 5_000 }); - await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorUserId: ownerUserId, body: "Pending work" }); + await db.insert(issueComments).values({ id: commentId, companyId, issueId, authorType: "user", authorUserId: ownerUserId, body: "Pending work" }); await db.insert(agentWakeupRequests).values({ id: queueId, companyId, agentId, source: "automation", reason: "issue_commented", status: "deferred_issue_execution", requestedByActorType: "user", requestedByActorId: ownerUserId, @@ -358,6 +358,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => { id: commentId, companyId, issueId, + authorType: "user", authorUserId: commenterUserId, body: `Current request for ${wakeReason}`, });