mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:50:43 +00:00
test: share subagent cleanup decision fixture
This commit is contained in:
@@ -19,60 +19,57 @@ function makeEntry(overrides: Partial<SubagentRunRecord> = {}): SubagentRunRecor
|
||||
describe("resolveDeferredCleanupDecision", () => {
|
||||
const now = 2_000;
|
||||
|
||||
it("defers completion-message cleanup while descendants are still pending", () => {
|
||||
const decision = resolveDeferredCleanupDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: true }),
|
||||
function resolveDecision(
|
||||
overrides: Pick<
|
||||
Parameters<typeof resolveDeferredCleanupDecision>[0],
|
||||
"activeDescendantRuns" | "entry"
|
||||
> &
|
||||
Partial<
|
||||
Pick<Parameters<typeof resolveDeferredCleanupDecision>[0], "resolveAnnounceRetryDelayMs">
|
||||
>,
|
||||
) {
|
||||
return resolveDeferredCleanupDecision({
|
||||
now,
|
||||
activeDescendantRuns: 2,
|
||||
announceExpiryMs: 5 * 60_000,
|
||||
announceCompletionHardExpiryMs: 30 * 60_000,
|
||||
maxAnnounceRetryCount: 3,
|
||||
deferDescendantDelayMs: 1_000,
|
||||
resolveAnnounceRetryDelayMs: () => 2_000,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
it("defers completion-message cleanup while descendants are still pending", () => {
|
||||
const decision = resolveDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: true }),
|
||||
activeDescendantRuns: 2,
|
||||
});
|
||||
|
||||
expect(decision).toEqual({ kind: "defer-descendants", delayMs: 1_000 });
|
||||
});
|
||||
|
||||
it("hard-expires completion-message cleanup when descendants never settle", () => {
|
||||
const decision = resolveDeferredCleanupDecision({
|
||||
const decision = resolveDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: true, endedAt: now - (30 * 60_000 + 1) }),
|
||||
now,
|
||||
activeDescendantRuns: 1,
|
||||
announceExpiryMs: 5 * 60_000,
|
||||
announceCompletionHardExpiryMs: 30 * 60_000,
|
||||
maxAnnounceRetryCount: 3,
|
||||
deferDescendantDelayMs: 1_000,
|
||||
resolveAnnounceRetryDelayMs: () => 2_000,
|
||||
});
|
||||
|
||||
expect(decision).toEqual({ kind: "give-up", reason: "expiry" });
|
||||
});
|
||||
|
||||
it("keeps regular expiry behavior for non-completion flows", () => {
|
||||
const decision = resolveDeferredCleanupDecision({
|
||||
const decision = resolveDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: false, endedAt: now - (5 * 60_000 + 1) }),
|
||||
now,
|
||||
activeDescendantRuns: 0,
|
||||
announceExpiryMs: 5 * 60_000,
|
||||
announceCompletionHardExpiryMs: 30 * 60_000,
|
||||
maxAnnounceRetryCount: 3,
|
||||
deferDescendantDelayMs: 1_000,
|
||||
resolveAnnounceRetryDelayMs: () => 2_000,
|
||||
});
|
||||
|
||||
expect(decision).toEqual({ kind: "give-up", reason: "expiry", retryCount: 1 });
|
||||
});
|
||||
|
||||
it("uses retry backoff for completion-message flows once descendants are settled", () => {
|
||||
const decision = resolveDeferredCleanupDecision({
|
||||
const decision = resolveDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: true, announceRetryCount: 1 }),
|
||||
now,
|
||||
activeDescendantRuns: 0,
|
||||
announceExpiryMs: 5 * 60_000,
|
||||
announceCompletionHardExpiryMs: 30 * 60_000,
|
||||
maxAnnounceRetryCount: 3,
|
||||
deferDescendantDelayMs: 1_000,
|
||||
resolveAnnounceRetryDelayMs: (retryCount) => retryCount * 1_000,
|
||||
});
|
||||
|
||||
@@ -80,14 +77,9 @@ describe("resolveDeferredCleanupDecision", () => {
|
||||
});
|
||||
|
||||
it("uses retry backoff for non-completion flows so cleanup can settle after announce failures", () => {
|
||||
const decision = resolveDeferredCleanupDecision({
|
||||
const decision = resolveDecision({
|
||||
entry: makeEntry({ expectsCompletionMessage: false, announceRetryCount: 1 }),
|
||||
now,
|
||||
activeDescendantRuns: 0,
|
||||
announceExpiryMs: 5 * 60_000,
|
||||
announceCompletionHardExpiryMs: 30 * 60_000,
|
||||
maxAnnounceRetryCount: 3,
|
||||
deferDescendantDelayMs: 1_000,
|
||||
resolveAnnounceRetryDelayMs: (retryCount) => retryCount * 1_000,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user