test: settle deferred GitHub replay and retain saved lease fixture

This commit is contained in:
Dotta committed 2026-10-05 18:23:43 -05:00
1 parent b012b3aebe
commit 5a23ef6595
3 files changed
+46 -2

No files matched your search

@@ -61865,7 +61865,7 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
},
);
it("orders reversed GitHub edit and delete callbacks behind their durable root", async () => {
it.each([false, true])("orders reversed GitHub edit and delete callbacks behind their durable root (root processed before replay: %s)", async (rootProcessedFirst) => {
const fixture = await seedCompany();
const deferred: Array<() => void | Promise<void>> = [];
const { callbacks, endpoint, service, wakeup, webhookSecret } =
@@ -61968,8 +61968,28 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
// One root-conversation drain plus one durable-ingress callback per HTTP
// request is queued. The duplicate delivery callback becomes a no-op.
expect(deferred).toHaveLength(4);
if (rootProcessedFirst) {
await deferred.shift()?.();
await vi.waitFor(async () => {
const [root] = await db
.select({ state: chatDeliveries.state })
.from(chatDeliveries)
.where(eq(chatDeliveries.endpointId, endpoint.id));
expect(root.state).toBe("processed");
});
}
await drainDeferred();
// The scheduler callbacks start background promises. Wait for durable
// replay admission before draining the conversation work it schedules.
await vi.waitFor(async () => {
const deliveries = await db
.select({ id: chatDeliveries.id })
.from(chatDeliveries)
.where(eq(chatDeliveries.endpointId, endpoint.id));
expect(deliveries).toHaveLength(3);
});
await vi.waitFor(async () => {
await drainDeferred();
const deliveries = await db
.select({
eventKind: chatDeliveries.eventKind,
@@ -838,11 +838,13 @@ describe("live remote runner lease reattachment", () => {
mockGetLease.mockResolvedValue(originalLease());
});
it("reattaches the original active ephemeral lease without acquiring or resuming a sandbox", async () => {
const savedLease = originalLease();
mockGetLease.mockResolvedValue(savedLease);
const runtime = makeMockRuntime();
const result = await environmentRunOrchestrator({} as never, { environmentRuntime: runtime }).acquireForRun(input);
expect(mockGetLease).toHaveBeenCalledWith("lease-1");
expect(runtime.acquireRunLease).not.toHaveBeenCalled();
expect(result.lease).toEqual(originalLease());
expect(result.lease).toEqual(savedLease);
expect(result.leaseContext.executionWorkspaceId).toBe("ew-1");
expect(result.environment.config.reuseLease).toBe(false);
});