Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { RunId, ThreadId } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";
import type { ProjectionLimitRecoveryCandidate } from "./ProjectionStore.ts";
import { limitRecoveryCommand } from "./UsageLimitRecoveryWorker.ts";

const stoppedAt = "2026-10-18T10:00:00.000Z";
const resetAt = "2026-10-18T11:00:00.000Z";
const candidate: ProjectionLimitRecoveryCandidate = {
id: ThreadId.make("quota-test"),
status: "failed",
lastErrorClass: "usage_limit",
latestRunId: RunId.make("stopped-run"),
usageLimitResetAt: resetAt,
archivedAt: null,
settledOverride: "active",
pendingRuntimeRequest: null,
latestRunCompletedAt: DateTime.makeUnsafe(stoppedAt),
updatedAt: DateTime.makeUnsafe(stoppedAt),
limitRecovery: null,
snoozedUntil: null,
};

describe("quota reset continuation provenance", () => {
it("attributes reset continuations to T3 while preserving the original recovery identity", () => {
const armed = {
...candidate,
limitRecovery: { runId: candidate.latestRunId!, resetAt, autoResume: true, snooze: true },
};
expect(limitRecoveryCommand(armed, true, Date.parse(resetAt) - 1)).toBeNull();
const resume = limitRecoveryCommand(armed, true, Date.parse(resetAt));
expect(resume).toMatchObject({
type: "message.dispatch",
createdBy: "agent",
creationSource: "server",
usageLimitContinuationOfRunId: candidate.latestRunId,
text: "Continue where you left off.",
});
expect(resume?.commandId).toEqual(
limitRecoveryCommand(armed, true, Date.parse(resetAt) + 1)?.commandId,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function limitRecoveryCommand(
text: "Continue where you left off.",
attachments: [],
dispatchMode: { type: "start_immediately" },
createdBy: "user",
createdBy: "agent",
creationSource: "server",
};
}
Expand Down
Loading