Skip to content

Commit b2c9981

Browse files
test(server): cover a usage limit that ended after a newer run
1 parent 54eada7 commit b2c9981

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/ProjectionSettlement.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const createRun = Effect.fn(function* (
7272
threadId: ThreadId,
7373
status: OrchestrationV2Run["status"] = "completed",
7474
ordinal = 1,
75+
completedAt = old,
7576
) {
7677
const store = yield* ProjectionStore.ProjectionStoreV2;
7778
const runId = RunId.make(`run:${threadId}:${ordinal}`);
@@ -93,7 +94,7 @@ const createRun = Effect.fn(function* (
9394
status,
9495
requestedAt: old,
9596
startedAt: status === "queued" ? null : old,
96-
completedAt: ["completed", "rolled_back", "failed"].includes(status) ? old : null,
97+
completedAt: ["completed", "rolled_back", "failed"].includes(status) ? completedAt : null,
9798
checkpointId: null,
9899
contextHandoffId: null,
99100
},
@@ -258,6 +259,18 @@ it.effect(
258259
"usage_limit",
259260
);
260261
yield* createRun(queuedBehindLimit, "queued", 2);
262+
// Held queues run out of order; the run that ended last decides, not the ordinal.
263+
const limitEndedLast = yield* createThread("limit-ended-last");
264+
yield* createFailure(
265+
limitEndedLast,
266+
yield* createRun(limitEndedLast, "failed", 1, DateTime.add(old, { hours: 1 })),
267+
"usage_limit",
268+
);
269+
yield* createFailure(
270+
limitEndedLast,
271+
yield* createRun(limitEndedLast, "failed", 2),
272+
"provider_error",
273+
);
261274
const providerFailed = yield* createThread("provider-failed");
262275
yield* createFailure(
263276
providerFailed,

0 commit comments

Comments
 (0)