Skip to content

Commit 3e8dcaf

Browse files
d-csclaude
andcommitted
test(run-ops split): assert expireRun completes the run when resolveEnv is null
The review fix (c9237f5) took env resolution off the expireRun path: org/ project/environment identity now comes from the run's latest execution snapshot, so the run is fully expired (message acked, waitpoint completed to unblock any parent, runExpired emitted) even when the control-plane resolver returns null. The old test still encoded the pre-fix contract (no event, no ack) and asserted expiredEvents.length === 0. Update it to assert the graceful-degradation contract the fix intends. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 53c0cff commit 3e8dcaf

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

  • internal-packages/run-engine/src/engine/tests

internal-packages/run-engine/src/engine/tests/ttl.test.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,11 +1611,12 @@ describe("RunEngine ttl", () => {
16111611
);
16121612

16131613
containerTest(
1614-
"expireRun degrades gracefully when the env has vanished (resolveEnv null)",
1614+
"expireRun completes the run even when env resolution is unavailable (resolveEnv null)",
16151615
async ({ prisma, redisOptions }) => {
1616-
// Contract: if the env vanishes mid-expiry, the legacy per-run expireRun
1617-
// path degrades gracefully — it returns without emitting runExpired and
1618-
// without acknowledging the message off the queue, rather than crashing.
1616+
// Contract: env resolution is NOT on the expire path — identity comes from
1617+
// the run's latest execution snapshot. So with resolveEnv returning null the
1618+
// run is still fully expired (message acked, waitpoint completed to unblock a
1619+
// parent, runExpired emitted), instead of silently dropped.
16191620
const authenticatedEnvironment = await setupAuthenticatedEnvironment(prisma, "PRODUCTION");
16201621

16211622
const passthrough = new PassthroughControlPlaneResolver({
@@ -1701,14 +1702,28 @@ describe("RunEngine ttl", () => {
17011702
assertNonNullable(executionData);
17021703
expect(executionData.snapshot.executionStatus).toBe("QUEUED");
17031704

1704-
// (a) no throw, (b) no runExpired event, (c) message not acked off the queue.
1705+
// (a) no throw, (b) runExpired IS emitted from snapshot identity,
1706+
// (c) message IS acked off the queue, (d) run reaches EXPIRED.
17051707
await expect(engine.ttlSystem.expireRun({ runId: run.id })).resolves.toBeUndefined();
1706-
expect(expiredEvents.length).toBe(0);
1708+
1709+
expect(expiredEvents.length).toBe(1);
1710+
expect(expiredEvents[0]!.run.id).toBe(run.id);
1711+
expect(expiredEvents[0]!.run.status).toBe("EXPIRED");
1712+
expect(expiredEvents[0]!.organization.id).toBe(authenticatedEnvironment.organization.id);
1713+
expect(expiredEvents[0]!.project.id).toBe(authenticatedEnvironment.project.id);
1714+
expect(expiredEvents[0]!.environment.id).toBe(authenticatedEnvironment.id);
1715+
17071716
const messageExists = await engine.runQueue.messageExists(
17081717
authenticatedEnvironment.organization.id,
17091718
run.id
17101719
);
1711-
expect(messageExists).toBe(1);
1720+
expect(messageExists).toBe(0);
1721+
1722+
const expiredRun = await prisma.taskRun.findUnique({
1723+
where: { id: run.id },
1724+
select: { status: true },
1725+
});
1726+
expect(expiredRun?.status).toBe("EXPIRED");
17121727
} finally {
17131728
await engine.quit();
17141729
}

0 commit comments

Comments
 (0)