From 37dd2211d7fb06f575b8783c3cd9dda58dbe42c1 Mon Sep 17 00:00:00 2001 From: GRayHook Date: Thu, 18 Jun 2026 22:58:43 +0700 Subject: [PATCH] Phase 15: add kept-window tests for skill-reinject:inject entries Verify inject custom messages count as present in kept slice and are ignored when compaction firstKeptEntryId starts after them. Co-authored-by: Cursor --- test/kept-window.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/kept-window.test.ts b/test/kept-window.test.ts index 431e05b..3f37bdd 100644 --- a/test/kept-window.test.ts +++ b/test/kept-window.test.ts @@ -42,6 +42,18 @@ function compactionEntry(id: string, firstKeptEntryId: string): SessionEntry { } as SessionEntry; } +function reinjectCustomMessage(id: string, content: string): SessionEntry { + return { + type: "custom_message", + id, + parentId: null, + timestamp: ts, + customType: "skill-reinject:inject", + content, + display: true, + } as SessionEntry; +} + const skillBlock = (name: string) => `\nbody\n`; @@ -94,6 +106,32 @@ describe("skillsPresentInKeptWindow", () => { expect(skillsPresentInKeptWindow([userMessage("k1", skillBlock("alpha"))], [])).toEqual(new Set()); expect(skillsPresentInKeptWindow([], ["alpha", "beta"])).toEqual(new Set()); }); + + it("detects skill blocks in skill-reinject:inject custom messages", () => { + const kept = [reinjectCustomMessage("inj1", skillBlock("beta"))]; + expect(skillsPresentInKeptWindow(kept, ["alpha", "beta"])).toEqual(new Set(["beta"])); + }); + + it("ignores reinject custom outside kept slice when slicing branch", () => { + const branch: SessionEntry[] = [ + reinjectCustomMessage("inj0", skillBlock("alpha")), + userMessage("e2", "kept start"), + compactionEntry("e4", "e2"), + ]; + const kept = getKeptEntries(branch, "e2"); + expect(skillsPresentInKeptWindow(kept, ["alpha", "beta"])).toEqual(new Set()); + expect(skillsPresentInKeptWindow(kept, ["alpha"])).toEqual(new Set()); + }); + + it("counts reinject custom inside kept slice", () => { + const branch: SessionEntry[] = [ + userMessage("e2", "kept start"), + reinjectCustomMessage("inj1", skillBlock("alpha")), + compactionEntry("e4", "e2"), + ]; + const kept = getKeptEntries(branch, "e2"); + expect(skillsPresentInKeptWindow(kept, ["alpha", "beta"])).toEqual(new Set(["alpha"])); + }); }); describe("filterSkillsNeedingReinjectByKept", () => {