

























@@ -760,4 +760,49 @@ describe("installContextEngineLoopHook", () => {
760760expect(retryResult).toBe(compactedView);
761761expect(engine.assemble).toHaveBeenCalledTimes(1);
762762});
763+764+it("clears the cached assembled view when the source history shrinks", async () => {
765+const agent = makeGuardableAgent();
766+const compactedView = [makeUser("compacted")];
767+const engine = makeMockEngine({
768+assemble: async () => ({ messages: compactedView, estimatedTokens: 0 }),
769+});
770+installHook(agent, engine);
771+772+const { transformed: firstResult } = await callAfterInitialToolResult(agent, {
773+includeSecondUser: false,
774+firstResultText: "r",
775+});
776+expect(firstResult).toBe(compactedView);
777+778+const postResetMessages = [makeUser("fresh post-reset turn")];
779+const postResetResult = await callTransform(agent, postResetMessages);
780+expect(postResetResult).toBe(postResetMessages);
781+});
782+783+it("clears the cached assembled view when assemble fails", async () => {
784+const agent = makeGuardableAgent();
785+const compactedView = [makeUser("compacted")];
786+const engine = makeMockEngine({
787+assemble: async () => ({ messages: compactedView, estimatedTokens: 0 }),
788+});
789+installHook(agent, engine);
790+791+const { withNew, transformed: firstResult } = await callAfterInitialToolResult(agent, {
792+includeSecondUser: false,
793+firstResultText: "r",
794+});
795+expect(firstResult).toBe(compactedView);
796+797+const afterFailureMessages = [...withNew, makeUser("after failure")];
798+engine.assemble.mockImplementationOnce(async () => {
799+throw new Error("engine assemble boom");
800+});
801+802+const failureResult = await callTransform(agent, afterFailureMessages);
803+expect(failureResult).toBe(afterFailureMessages);
804+805+const retryResult = await callTransform(agent, afterFailureMessages);
806+expect(retryResult).toBe(afterFailureMessages);
807+});
763808});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。