


























@@ -1,3 +1,4 @@
1+// Covers safety timeouts around embedded-agent compaction calls.
12import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
23import type { CompactResult, ContextEngine } from "../context-engine/types.js";
34import {
@@ -19,6 +20,7 @@ describe("compactWithSafetyTimeout", () => {
1920});
20212122it("rejects with timeout when compaction never settles", async () => {
23+// Hung compaction must not stall the agent turn indefinitely.
2224vi.useFakeTimers();
2325const compactPromise = compactWithSafetyTimeout(() => new Promise<never>(() => {}));
2426const timeoutAssertion = expect(compactPromise).rejects.toThrow("Compaction timed out");
@@ -71,6 +73,8 @@ describe("compactWithSafetyTimeout", () => {
7173});
72747375it("aborts early on external abort signal and calls onCancel once", async () => {
76+// Run-level aborts should win over the safety timer and still trigger one
77+// cancellation path.
7478vi.useFakeTimers();
7579const controller = new AbortController();
7680const onCancel = vi.fn();
@@ -210,6 +214,8 @@ describe("compactContextEngineWithSafetyTimeout", () => {
210214});
211215212216it("threads a signal that follows the run abort signal into the plugin compact() params", async () => {
217+// Plugin context engines receive an abort signal derived from the run signal
218+// so they can stop work promptly.
213219vi.useFakeTimers();
214220const controller = new AbortController();
215221const reason = new Error("run aborted");
@@ -239,6 +245,8 @@ describe("compactContextEngineWithSafetyTimeout", () => {
239245});
240246241247it("threads the host timeout abort signal into the plugin compact() params", async () => {
248+// Timeout cancellation is delivered through the same plugin abort signal as
249+// external run cancellation.
242250vi.useFakeTimers();
243251let compactAbortSignal: AbortSignal | undefined;
244252const compact = vi.fn<CompactFn>((params) => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。