Merge b626ee75ae5c47057472edfef38707b4298d9fad into 598f1826d8b2bc969aace2c6459824737667218c

This commit is contained in:
Joseph Krug 2026-03-21 04:29:33 +00:00 committed by GitHub
commit de7f5e087e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 9 deletions

View File

@ -1490,7 +1490,7 @@ describe("compaction-safeguard extension model fallback", () => {
apiKey: null,
});
expect(result).toEqual({ cancel: true });
expect(result).toBeUndefined();
// KEY ASSERTION: Prove the fallback path was exercised
// The handler should have called getApiKey with runtime.model (via ctx.model ?? runtime?.model)
@ -1501,7 +1501,7 @@ describe("compaction-safeguard extension model fallback", () => {
expect(retrieved?.model).toEqual(model);
});
it("cancels compaction when both ctx.model and runtime.model are undefined", async () => {
it("falls back to built-in compaction when both ctx.model and runtime.model are undefined", async () => {
const sessionManager = stubSessionManager();
// Do NOT set runtime.model (both ctx.model and runtime.model will be undefined)
@ -1516,11 +1516,25 @@ describe("compaction-safeguard extension model fallback", () => {
apiKey: null,
});
expect(result).toEqual({ cancel: true });
expect(result).toBeUndefined();
// Verify early return: getApiKey should NOT have been called when both models are missing
expect(getApiKeyMock).not.toHaveBeenCalled();
});
it("falls back to built-in compaction when API key is missing (returns undefined, not cancel)", async () => {
const sessionManager = stubSessionManager();
const model = createAnthropicModelFixture();
setCompactionSafeguardRuntime(sessionManager, { model });
const mockEvent = createCompactionEvent({ messageText: "test", tokensBefore: 500 });
const { result, getApiKeyMock } = await runCompactionScenario({
sessionManager,
event: mockEvent,
apiKey: null,
});
expect(result).toBeUndefined();
expect(getApiKeyMock).toHaveBeenCalledWith(model);
});
});
describe("compaction-safeguard double-compaction guard", () => {
@ -1670,7 +1684,7 @@ describe("compaction-safeguard double-compaction guard", () => {
event: mockEvent,
apiKey: null,
});
expect(result).toEqual({ cancel: true });
expect(result).toBeUndefined();
expect(getApiKeyMock).toHaveBeenCalled();
});
});

View File

@ -761,15 +761,13 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
"was not called and model was not passed through runtime registry.",
);
}
return { cancel: true };
return undefined;
}
const apiKey = await ctx.modelRegistry.getApiKey(model);
if (!apiKey) {
log.warn(
"Compaction safeguard: no API key available; cancelling compaction to preserve history.",
);
return { cancel: true };
log.warn("Compaction safeguard: no API key available; falling back to built-in compaction.");
return undefined;
}
try {