test: prune orphaned test-support fixtures and helpers (#23360)

Co-Authored-By: Paperclip <Paperclip-Paperclip@users.noreply.github.com>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-12-02 16:40:01 -06:00
1 parent d5c22b8424
commit 9aaeae40bf
5 files changed
+2 -387

No files matched your search

@@ -8,8 +8,7 @@
//
// vi.mock() only applies to the file that declares it, so each suite keeps its
// own environment-execution-target mock and passes its `targets` map in.
import { appendHeartbeatRunEvent } from "../heartbeat-run-events.js";
import { recordRequiredWorkspaceRestoreFailure, terminalizeLegacyExecution } from "../legacy-execution-recovery.js";
import { recordRequiredWorkspaceRestoreFailure } from "../legacy-execution-recovery.js";
import { resolveExternalTestDatabaseUrl } from "../../__tests__/helpers/external-test-database.js";
import { environmentService } from "../environments.js";
import { classifyEnvironmentCapabilities, environmentRuntimeService } from "../environment-runtime.js";
@@ -39,7 +38,6 @@ import { heartbeatService } from "../heartbeat.js";
import { prepareRemoteWorkspace, reserveRemoteWorkspace } from "../remote-workspaces.js";
import { issueRoutes } from "../../routes/issues.js";
import { errorHandler } from "../../middleware/index.js";
import * as workerProof from "../native-runtime/native-workspace-platform-proof.js";
export let db: ReturnType<typeof createDb>;
export let root: string;
@@ -348,55 +346,6 @@ export async function interruptedRemotePreparation(interruption: "shutdown" | "l
return f;
}
export async function withheldPreparationRetry(f: { companyId: string; issueId: string; runId: string; actionId: string }) {
const source = await run(f.runId);
const [withheld] = await db.insert(heartbeatRuns).values({ companyId: f.companyId, agentId: source.agentId,
responsibleUserId: source.responsibleUserId, scopeKind: "issue", issueId: f.issueId, runtimeMode: "legacy", status: "cancelled", finishedAt: new Date(),
retryOfRunId: f.runId, scheduledRetryAttempt: 1, scheduledRetryReason: "transient_failure",
errorCode: "execution_reconciliation_required", contextSnapshot: { issueId: f.issueId },
resultJson: { stopReason: "execution_reconciliation_required", timeoutSource: "stale_queued_run_gate",
executionWait: { issueId: f.issueId, recoveryActionId: f.actionId } },
}).returning();
return withheld;
}
export async function failedRemotePreparation(sourceLayout: RecoverySourceLayout = "retained", startedMarker = false, warning = false) {
const f = await interruptedRemotePreparation("shutdown", sourceLayout);
const source = await run(f.runId);
const error = "Repository access is no longer available; refresh the repository catalog";
await terminalizeLegacyExecution({ db, run: source, status: "failed", reconcileIfNeeded: false,
patch: { errorCode: "setup_failed", error, executionStage: "preparing",
startedAt: new Date(Date.now() - 1000), contextSnapshot: { ...source.contextSnapshot, source: "native_status_decision" },
resultJson: { ...source.resultJson, stopReason: "adapter_failed",
executionRecovery: { kind: "bootstrap", providerWorkStarted: false } } } });
if (warning) await appendHeartbeatRunEvent(db, { companyId: f.companyId, runId: f.runId, agentId: source.agentId,
eventType: "agent_observability.unavailable", stream: "system", level: "warn",
payload: { reason: "unsupported_harness", revision: randomUUID() } });
if (startedMarker) await appendHeartbeatRunEvent(db, { companyId: f.companyId, runId: f.runId, agentId: source.agentId,
eventType: "lifecycle", stream: "system", level: "info", message: "run started" });
await appendHeartbeatRunEvent(db, { companyId: f.companyId, runId: f.runId, agentId: source.agentId,
eventType: "error", stream: "system", level: "error", message: error });
await appendHeartbeatRunEvent(db, { companyId: f.companyId, runId: f.runId, agentId: source.agentId,
eventType: "lifecycle", stream: "system", level: "info", message: "task.run.measured",
payload: { phase: "task.run.measured", outcome: "failed", durationMs: 1000, durableSettlement: true } });
return f;
}
export async function stoppedWorkspaceWorker(f: { runId: string }) {
const source = await run(f.runId);
const deploymentWorker = { provider: "railway" as const, projectId: randomUUID(), environmentId: randomUUID(), serviceId: randomUUID(), deploymentId: randomUUID() };
const owner = { token: randomUUID(), hostname: "previous-controller", pid: 123,
processStartedAt: new Date().toISOString(), worker: deploymentWorker };
const stopProof = { v: 1 as const, iss: "paperclip-cloud" as const, aud: "paperclip-workspace-worker-stop/v1" as const,
sub: "test-stack", stopped: true as const, iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 30, runId: f.runId, ownerToken: owner.token, worker: deploymentWorker };
const proof = vi.spyOn(workerProof, "requestWorkspaceWorkerStopProof").mockResolvedValue({ status: "verified", proof: stopProof });
await db.update(heartbeatRuns).set({ runnerProfileJson: {
...source.runnerProfileJson, nativeWorkspaceFinalizationOwner: owner,
} }).where(eq(heartbeatRuns.id, f.runId));
return { proof, stopProof, owner, deploymentWorker };
}
export async function warmHandoffSource(hops = 1, beforeStop?: (lease: typeof environmentLeases.$inferSelect) => Promise<void>,
options: { firstOwnerInSharedWorkspace?: boolean } = {}) {
const sharedWorkspaceId = options.firstOwnerInSharedWorkspace ? randomUUID() : undefined;