diff --git a/doc/plans/2026-10-25-chat-run-milestone-sleep-audit.md b/doc/plans/2026-10-25-chat-run-milestone-sleep-audit.md index b2d2368f8f7..dc5bce6b89b 100644 --- a/doc/plans/2026-10-25-chat-run-milestone-sleep-audit.md +++ b/doc/plans/2026-10-25-chat-run-milestone-sleep-audit.md @@ -1577,3 +1577,25 @@ Evidence: Latest-head CI/review and stack reconciliation remain required. These local passes do not discharge previous cancellation/deadlock evidence or parent review findings. No merge or host-sleep qualification is claimed. + + +## Master integration: extracted GitHub credential fixture + +Master extracted the credential fixture into a helper shared with project Git +authorization. Its direct `acceptSteeredIdentity(db, ...)` call bypassed the +existing transaction owner. Combined verification reproduced four credential +failures and one project-authorization failure when activation registered work. +The helper now calls `reconcileSteeredIdentity`, which already owns the task/run +locks and transaction. No production transaction contract changed. + +The project suite initially skipped all 30 cases because embedded PostgreSQL was +unavailable. It now supports the existing validated external-test-database option +through `PAPERCLIP_PROJECT_GIT_TEST_DATABASE_URL` and closes that pool. Use a fresh +disposable database per run: the suite seeds fixed A/B user IDs. Reusing the red +run's database caused a duplicate-user setup failure; a new database resolved +that fixture setup issue without changing product behavior. All 25 credential +cases and all 30 project-authorization cases then passed on the owning branch. +The original failures remain in `/tmp/sleep-master-credentials-tests.log` and +`/tmp/sleep-master-project-git-external-before.log`; corrected results are in +`/tmp/sleep-master-identity-fixture-tests.log` (credentials) and +`/tmp/sleep-master-project-git-fixed.log` (project authorization). diff --git a/server/src/__tests__/helpers/github-credentials-fixture.ts b/server/src/__tests__/helpers/github-credentials-fixture.ts index cd18ca64c72..ee43dd18da0 100644 --- a/server/src/__tests__/helpers/github-credentials-fixture.ts +++ b/server/src/__tests__/helpers/github-credentials-fixture.ts @@ -1,6 +1,6 @@ import { randomUUID } from "node:crypto"; import { agents, companies, companyMemberships, companySecrets, connectionGrants, heartbeatRuns, issueComments, issues, toolApplications, toolConnectionInstalls, toolConnections, userSecretDefinitions, type Db } from "@paperclipai/db"; -import { initializeRunIdentity, reserveSteeredIdentity, acceptSteeredIdentity } from "../../services/run-identity.js"; +import { initializeRunIdentity, reserveSteeredIdentity, reconcileSteeredIdentity } from "../../services/run-identity.js"; export function githubCredentialsFixture(getDb: () => Db) { async function seed() { @@ -145,7 +145,7 @@ export function githubCredentialsFixture(getDb: () => Db) { ...input, messageId: id, }); - await acceptSteeredIdentity(db, context!); + await reconcileSteeredIdentity(db, context!); } return { seed, grant, switchTo }; } diff --git a/server/src/__tests__/project-git-authorization.test.ts b/server/src/__tests__/project-git-authorization.test.ts index 940b8a5bc78..9bd67aa5a3b 100644 --- a/server/src/__tests__/project-git-authorization.test.ts +++ b/server/src/__tests__/project-git-authorization.test.ts @@ -1,3 +1,4 @@ +import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js"; import express from "express"; import request from "supertest"; import { eq } from "drizzle-orm"; @@ -20,18 +21,19 @@ vi.mock("../services/github-fetch.js", async importOriginal => ({ ...await importOriginal(), ghFetch: vi.fn(async () => new Response(null, { status: 404 })), })); -const support = await getEmbeddedPostgresTestSupport(); +const external = resolveExternalTestDatabaseUrl("PAPERCLIP_PROJECT_GIT_TEST_DATABASE_URL"); +const support = external ? { supported: true } : await getEmbeddedPostgresTestSupport(); (support.supported ? describe : describe.skip)("explicit project Git authorization", () => { let db: ReturnType, database: Awaited>; const { seed, grant, switchTo } = githubCredentialsFixture(() => db); beforeAll(async () => { - database = await startEmbeddedPostgresTestDatabase("paperclip-project-git-authorization-"); - db = createDb(database.connectionString); + if (!external) database = await startEmbeddedPostgresTestDatabase("paperclip-project-git-authorization-"); + db = createDb(external ?? database!.connectionString); await db.insert(authUsers).values(["A", "B"].map(id => ({ id, name: id, email: `${id}@example.invalid`, createdAt: new Date(), updatedAt: new Date(), }))); }, 30_000); - afterAll(async () => { await database?.cleanup(); }, 60_000); + afterAll(async () => { await db?.$client.end({ timeout: 1 }); await database?.cleanup(); }, 60_000); async function projectAuthorizationFixture() { const input = await seed(); const selected = await grant(input, "A");