























@@ -5,7 +5,9 @@ import {
55applyPiCompactionSettingsFromConfig,
66DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR,
77isSilentOverflowProneModel,
8+resolveEffectiveCompactionMode,
89resolveCompactionReserveTokensFloor,
10+shouldDisablePiAutoCompaction,
911} from "./pi-settings.js";
10121113describe("applyPiCompactionSettingsFromConfig", () => {
@@ -347,6 +349,40 @@ describe("resolveCompactionReserveTokensFloor", () => {
347349).toBe(0);
348350});
349351});
352+describe("resolveEffectiveCompactionMode", () => {
353+it("defaults to default compaction mode", () => {
354+expect(resolveEffectiveCompactionMode()).toBe("default");
355+expect(resolveEffectiveCompactionMode({ agents: { defaults: { compaction: {} } } })).toBe(
356+"default",
357+);
358+expect(
359+resolveEffectiveCompactionMode({
360+agents: { defaults: { compaction: { mode: "default" } } },
361+}),
362+).toBe("default");
363+});
364+365+it("returns safeguard for explicit safeguard mode", () => {
366+expect(
367+resolveEffectiveCompactionMode({
368+agents: { defaults: { compaction: { mode: "safeguard" } } },
369+}),
370+).toBe("safeguard");
371+});
372+373+it("returns safeguard when a compaction provider is configured", () => {
374+expect(
375+resolveEffectiveCompactionMode({
376+agents: { defaults: { compaction: { provider: "deepseek" } } },
377+}),
378+).toBe("safeguard");
379+expect(
380+resolveEffectiveCompactionMode({
381+agents: { defaults: { compaction: { mode: "default", provider: "deepseek" } } },
382+}),
383+).toBe("safeguard");
384+});
385+});
350386351387describe("isSilentOverflowProneModel", () => {
352388// Reporter's repro shape: openrouter routing to z-ai/glm. Both the bare
@@ -432,6 +468,36 @@ describe("isSilentOverflowProneModel", () => {
432468});
433469});
434470471+describe("shouldDisablePiAutoCompaction", () => {
472+it("returns false with no owner, default mode, and ordinary provider behavior", () => {
473+expect(shouldDisablePiAutoCompaction({})).toBe(false);
474+expect(shouldDisablePiAutoCompaction({ compactionMode: "default" })).toBe(false);
475+expect(
476+shouldDisablePiAutoCompaction({
477+contextEngineInfo: { id: "legacy", name: "Legacy", ownsCompaction: false },
478+compactionMode: "default",
479+silentOverflowProneProvider: false,
480+}),
481+).toBe(false);
482+});
483+484+it("returns true when a context engine owns compaction", () => {
485+expect(
486+shouldDisablePiAutoCompaction({
487+contextEngineInfo: { id: "third-party", name: "Third-party", ownsCompaction: true },
488+}),
489+).toBe(true);
490+});
491+492+it("returns true when effective compaction mode is safeguard", () => {
493+expect(shouldDisablePiAutoCompaction({ compactionMode: "safeguard" })).toBe(true);
494+});
495+496+it("returns true for silent-overflow-prone providers", () => {
497+expect(shouldDisablePiAutoCompaction({ silentOverflowProneProvider: true })).toBe(true);
498+});
499+});
500+435501describe("applyPiAutoCompactionGuard", () => {
436502// Direct repro of openclaw#75799: pi-ai's silent-overflow detection misfires
437503// on a successful turn against z.ai-style providers, triggering Pi's
@@ -481,6 +547,26 @@ describe("applyPiAutoCompactionGuard", () => {
481547expect(setCompactionEnabled).toHaveBeenCalledWith(false);
482548});
483549550+it("disables Pi auto-compaction when provider config forces safeguard mode", () => {
551+const setCompactionEnabled = vi.fn();
552+const settingsManager = {
553+getCompactionReserveTokens: () => 20_000,
554+getCompactionKeepRecentTokens: () => 4_000,
555+applyOverrides: () => {},
556+ setCompactionEnabled,
557+};
558+559+const result = applyPiAutoCompactionGuard({
560+ settingsManager,
561+compactionMode: resolveEffectiveCompactionMode({
562+agents: { defaults: { compaction: { provider: "deepseek" } } },
563+}),
564+});
565+566+expect(result).toEqual({ supported: true, disabled: true });
567+expect(setCompactionEnabled).toHaveBeenCalledWith(false);
568+});
569+484570// Default-mode runs against ordinary providers must keep Pi's auto-compaction
485571// enabled. Disabling it across the board would silently remove Pi's
486572// overflow-recovery path inside Session.prompt() for users who are not
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。