


























11// Coverage for aggregate timeout handling while waiting on compaction retry.
22import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
33import { describe, expect, it, vi } from "vitest";
4-import { waitForCompactionRetryWithAggregateTimeout } from "./compaction-retry-aggregate-timeout.js";
4+import {
5+hasActiveCompactionRetryWork,
6+waitForCompactionRetryWithAggregateTimeout,
7+} from "./compaction-retry-aggregate-timeout.js";
5869type AggregateTimeoutParams = Parameters<typeof waitForCompactionRetryWithAggregateTimeout>[0];
710type TimeoutCallback = NonNullable<AggregateTimeoutParams["onTimeout"]>;
@@ -42,7 +45,7 @@ function buildAggregateTimeoutParams(
4245waitForCompactionRetry: overrides.waitForCompactionRetry,
4346abortable: overrides.abortable ?? (async (promise) => await promise),
4447aggregateTimeoutMs: overrides.aggregateTimeoutMs ?? 60_000,
45-isCompactionStillInFlight: overrides.isCompactionStillInFlight,
48+isCompactionRetryStillActive: overrides.isCompactionRetryStillActive,
4649 onTimeout,
4750};
4851}
@@ -63,23 +66,23 @@ describe("waitForCompactionRetryWithAggregateTimeout", () => {
6366});
6467});
656866-it("keeps waiting while compaction remains in flight", async () => {
67-// The aggregate timer should not cut off active compaction work; timeout
68-// starts once compaction is no longer in flight.
69+it("keeps waiting while compaction retry work remains active", async () => {
70+// The aggregate timer should not cut off either the compaction call or its
71+// retry model run; timeout starts once both phases are idle.
6972await withFakeTimers(async () => {
70-let compactionInFlight = true;
73+let retryWorkActive = true;
7174const waitForCompactionRetry = vi.fn(
7275async () =>
7376await new Promise<void>((resolve) => {
7477setTimeout(() => {
75-compactionInFlight = false;
78+retryWorkActive = false;
7679resolve();
7780}, 170_000);
7881}),
7982);
8083const params = buildAggregateTimeoutParams({
8184 waitForCompactionRetry,
82-isCompactionStillInFlight: () => compactionInFlight,
85+isCompactionRetryStillActive: () => retryWorkActive,
8386});
84878588const resultPromise = waitForCompactionRetryWithAggregateTimeout(params);
@@ -101,7 +104,7 @@ describe("waitForCompactionRetryWithAggregateTimeout", () => {
101104}, 90_000);
102105const params = buildAggregateTimeoutParams({
103106 waitForCompactionRetry,
104-isCompactionStillInFlight: () => compactionInFlight,
107+isCompactionRetryStillActive: () => compactionInFlight,
105108});
106109107110const resultPromise = waitForCompactionRetryWithAggregateTimeout(params);
@@ -202,3 +205,21 @@ describe("waitForCompactionRetryWithAggregateTimeout", () => {
202205});
203206});
204207});
208+209+describe("hasActiveCompactionRetryWork", () => {
210+it.each([
211+{ isCompactionInFlight: true, isSessionStreaming: false },
212+{ isCompactionInFlight: false, isSessionStreaming: true },
213+])("returns true while either retry phase is active", (params) => {
214+expect(hasActiveCompactionRetryWork(params)).toBe(true);
215+});
216+217+it("returns false once compaction and the retry model run are idle", () => {
218+expect(
219+hasActiveCompactionRetryWork({
220+isCompactionInFlight: false,
221+isSessionStreaming: false,
222+}),
223+).toBe(false);
224+});
225+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。