|
7 | 7 | EventId, |
8 | 8 | ProviderInstanceId, |
9 | 9 | ProviderSessionId, |
| 10 | + RunId, |
10 | 11 | ThreadId, |
11 | 12 | type OrchestrationProjectShell, |
12 | 13 | type OrchestrationV2AppThread, |
@@ -206,6 +207,29 @@ describe("isAutoSettlementCandidate", () => { |
206 | 207 | ), |
207 | 208 | ).toBe(true); |
208 | 209 | }); |
| 210 | + |
| 211 | + it("keeps a thread armed to auto-resume parked until its usage limit resets", () => { |
| 212 | + const recovery = { |
| 213 | + runId: RunId.make("run-1"), |
| 214 | + resetAt: DateTime.formatIso(at(3 * DAY_MS)), |
| 215 | + autoResume: true, |
| 216 | + }; |
| 217 | + const armed = shell({ |
| 218 | + status: "failed", |
| 219 | + latestRunId: RunId.make("run-1"), |
| 220 | + latestRunCompletedAt: at(-4 * DAY_MS), |
| 221 | + limitRecovery: recovery, |
| 222 | + }); |
| 223 | + expect(ThreadSettlementService.isAutoSettlementCandidate(armed, NOW_MS)).toBe(false); |
| 224 | + for (const thread of [ |
| 225 | + shell({ ...armed, limitRecovery: { ...recovery, autoResume: false } }), |
| 226 | + shell({ ...armed, limitRecovery: { ...recovery, runId: RunId.make("run-0") } }), |
| 227 | + shell({ ...armed, latestRunId: null }), |
| 228 | + shell({ ...armed, limitRecovery: { ...recovery, resetAt: DateTime.formatIso(at(-1_000)) } }), |
| 229 | + ]) { |
| 230 | + expect(ThreadSettlementService.isAutoSettlementCandidate(thread, NOW_MS)).toBe(true); |
| 231 | + } |
| 232 | + }); |
209 | 233 | }); |
210 | 234 |
|
211 | 235 | describe("threadHasQueuedTurnStart", () => { |
@@ -322,6 +346,33 @@ describe("resolveAutoSettlementAt", () => { |
322 | 346 | ).toEqual(at(-1_000)); |
323 | 347 | }); |
324 | 348 |
|
| 349 | + it("waits out an armed auto-resume and restarts inactivity at its reset", () => { |
| 350 | + const thread = shell({ |
| 351 | + status: "failed", |
| 352 | + latestRunId: RunId.make("run-1"), |
| 353 | + latestRunCompletedAt: at(-4 * DAY_MS), |
| 354 | + limitRecovery: { |
| 355 | + runId: RunId.make("run-1"), |
| 356 | + resetAt: DateTime.formatIso(at(DAY_MS)), |
| 357 | + autoResume: true, |
| 358 | + }, |
| 359 | + }); |
| 360 | + const input = { |
| 361 | + thread, |
| 362 | + pullRequest: null, |
| 363 | + nowMs: NOW_MS, |
| 364 | + autoSettleAfterDays: 1, |
| 365 | + autoSettleOnMerge: false, |
| 366 | + }; |
| 367 | + expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toBeNull(); |
| 368 | + expect( |
| 369 | + ThreadSettlementService.resolveAutoSettlementAt({ ...input, nowMs: NOW_MS + DAY_MS }), |
| 370 | + ).toBeNull(); |
| 371 | + expect( |
| 372 | + ThreadSettlementService.resolveAutoSettlementAt({ ...input, nowMs: NOW_MS + 2 * DAY_MS + 1 }), |
| 373 | + ).toEqual(at(DAY_MS)); |
| 374 | + }); |
| 375 | + |
325 | 376 | it("settles on merge only after the user's last action and preserves the activity time", () => { |
326 | 377 | const thread = shell({ |
327 | 378 | latestUserMessageAt: at(-2 * 60 * 60 * 1_000), |
|
0 commit comments