Skip to content

Commit 2b23163

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 1b8a6a1 commit 2b23163

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
@@ -1612,11 +1612,12 @@ describe("RunEngine ttl", () => {
16121612
);
16131613

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

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

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

0 commit comments

Comments
 (0)