google-thinking-signature.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { describe, expect, it } from "vitest";
  2. import { isThinkingPart, retainThoughtSignature } from "../src/providers/google-shared.ts";
  3. describe("Google thinking detection (thoughtSignature)", () => {
  4. it("treats part.thought === true as thinking", () => {
  5. expect(isThinkingPart({ thought: true, thoughtSignature: undefined })).toBe(true);
  6. expect(isThinkingPart({ thought: true, thoughtSignature: "opaque-signature" })).toBe(true);
  7. });
  8. it("does not treat thoughtSignature alone as thinking", () => {
  9. // Per Google docs, thoughtSignature is for context replay and can appear on any part type.
  10. // Only thought === true indicates thinking content.
  11. // See: https://ai.google.dev/gemini-api/docs/thought-signatures
  12. expect(isThinkingPart({ thought: undefined, thoughtSignature: "opaque-signature" })).toBe(false);
  13. expect(isThinkingPart({ thought: false, thoughtSignature: "opaque-signature" })).toBe(false);
  14. });
  15. it("does not treat empty/missing signatures as thinking if thought is not set", () => {
  16. expect(isThinkingPart({ thought: undefined, thoughtSignature: undefined })).toBe(false);
  17. expect(isThinkingPart({ thought: false, thoughtSignature: "" })).toBe(false);
  18. });
  19. it("preserves the existing signature when subsequent deltas omit thoughtSignature", () => {
  20. const first = retainThoughtSignature(undefined, "sig-1");
  21. expect(first).toBe("sig-1");
  22. const second = retainThoughtSignature(first, undefined);
  23. expect(second).toBe("sig-1");
  24. const third = retainThoughtSignature(second, "");
  25. expect(third).toBe("sig-1");
  26. });
  27. it("updates the signature when a new non-empty signature arrives", () => {
  28. const updated = retainThoughtSignature("sig-1", "sig-2");
  29. expect(updated).toBe("sig-2");
  30. });
  31. });