c071f240d3
Stale pendingReinject from auto compaction is blocked until the next user prompt after manual /compact with default settings; a later auto compaction resets the clear flag. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
consumeCompactionOnSessionCompact,
|
|
createCompactionRuntime,
|
|
} from "../src/compaction";
|
|
import { clearPendingReinjectOnUserPrompt, tryConsumeDeferredReinject } from "../src/reinject";
|
|
import { createDefaultSettings } from "../src/settings";
|
|
import { createInitialState } from "../src/state";
|
|
|
|
describe("manual compaction defer clear", () => {
|
|
it("schedules clear on manual compaction when reinjectOnManualCompaction is false", () => {
|
|
const runtime = createCompactionRuntime();
|
|
const state = createInitialState();
|
|
state.pendingReinject = ["alpha"];
|
|
runtime.pendingCompactionSource = "manual";
|
|
|
|
const shouldReinject = consumeCompactionOnSessionCompact(runtime, state, null, createDefaultSettings());
|
|
|
|
expect(shouldReinject).toBe(false);
|
|
expect(runtime.clearPendingReinjectOnNextUserInput).toBe(true);
|
|
expect(state.pendingReinject).toEqual(["alpha"]);
|
|
});
|
|
|
|
it("blocks deferred inject until user prompt clears stale pending", () => {
|
|
const runtime = createCompactionRuntime();
|
|
const state = createInitialState();
|
|
state.pendingReinject = ["alpha"];
|
|
runtime.clearPendingReinjectOnNextUserInput = true;
|
|
|
|
expect(
|
|
tryConsumeDeferredReinject(state, createDefaultSettings(), [], undefined, runtime),
|
|
).toBeUndefined();
|
|
expect(state.pendingReinject).toEqual(["alpha"]);
|
|
});
|
|
|
|
it("clears pending on user prompt and allows deferred inject again", () => {
|
|
const runtime = createCompactionRuntime();
|
|
const state = createInitialState();
|
|
state.pendingReinject = ["alpha"];
|
|
runtime.clearPendingReinjectOnNextUserInput = true;
|
|
|
|
expect(clearPendingReinjectOnUserPrompt(state, runtime)).toBe(true);
|
|
expect(state.pendingReinject).toEqual([]);
|
|
expect(runtime.clearPendingReinjectOnNextUserInput).toBe(false);
|
|
});
|
|
|
|
it("does not schedule clear when manual compaction may reinject", () => {
|
|
const runtime = createCompactionRuntime();
|
|
const state = createInitialState();
|
|
state.pendingReinject = ["alpha"];
|
|
runtime.pendingCompactionSource = "manual";
|
|
const settings = createDefaultSettings();
|
|
settings.reinjectOnManualCompaction = true;
|
|
|
|
const shouldReinject = consumeCompactionOnSessionCompact(runtime, state, true, settings);
|
|
|
|
expect(shouldReinject).toBe(true);
|
|
expect(runtime.clearPendingReinjectOnNextUserInput).toBe(false);
|
|
});
|
|
|
|
it("clears stale manual flag when a later auto compaction enqueues reinject", () => {
|
|
const runtime = createCompactionRuntime();
|
|
const state = createInitialState();
|
|
runtime.clearPendingReinjectOnNextUserInput = true;
|
|
state.pendingReinject = ["beta"];
|
|
runtime.pendingCompactionSource = "auto";
|
|
|
|
const shouldReinject = consumeCompactionOnSessionCompact(runtime, state, true, createDefaultSettings());
|
|
|
|
expect(shouldReinject).toBe(true);
|
|
expect(runtime.clearPendingReinjectOnNextUserInput).toBe(false);
|
|
expect(clearPendingReinjectOnUserPrompt(state, runtime)).toBe(false);
|
|
expect(state.pendingReinject).toEqual(["beta"]);
|
|
});
|
|
});
|