Blame · Line-by-line history
ai-flywheel.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 40e7738 | 1 | /** |
| 2 | * Pure-function tests for the AI flywheel layer. | |
| 3 | * recordAi/persist exercise the DB; covered by integration smoke elsewhere. | |
| 4 | */ | |
| 5 | ||
| 6 | import { describe, it, expect } from "bun:test"; | |
| 7 | import { __test } from "../lib/ai-flywheel"; | |
| 8 | ||
| 9 | const { redact, clamp, clampInt } = __test; | |
| 10 | ||
| 11 | describe("ai-flywheel — redact", () => { | |
| 12 | it("strips bearer tokens", () => { | |
| 13 | const out = redact("Authorization: Bearer abcdef.ghijkl"); | |
| 14 | expect(out).toContain("[REDACTED]"); | |
| 15 | expect(out).not.toContain("abcdef"); | |
| 16 | }); | |
| 17 | ||
| 18 | it("strips Anthropic-style sk- keys", () => { | |
| 19 | const out = redact("error sk-ant-api01-AAAA-BBBB-CCCC"); | |
| 20 | expect(out).toContain("[REDACTED]"); | |
| 21 | }); | |
| 22 | ||
| 23 | it("strips gluecron PATs", () => { | |
| 24 | const out = redact("token glc_abcd1234efgh5678 leaked"); | |
| 25 | expect(out).toContain("[REDACTED]"); | |
| 26 | }); | |
| 27 | ||
| 28 | it("returns the input unchanged when nothing matches", () => { | |
| 29 | const out = redact("plain message with no secret"); | |
| 30 | expect(out).toBe("plain message with no secret"); | |
| 31 | }); | |
| 32 | }); | |
| 33 | ||
| 34 | describe("ai-flywheel — clamp", () => { | |
| 35 | it("returns input untouched when short", () => { | |
| 36 | expect(clamp("hello", 100)).toBe("hello"); | |
| 37 | }); | |
| 38 | it("truncates with ellipsis when too long", () => { | |
| 39 | const result = clamp("a".repeat(50), 10); | |
| 40 | expect(result.length).toBe(10); | |
| 41 | expect(result.endsWith("…")).toBe(true); | |
| 42 | }); | |
| 43 | }); | |
| 44 | ||
| 45 | describe("ai-flywheel — clampInt", () => { | |
| 46 | it("clamps below lo", () => { | |
| 47 | expect(clampInt(-5, 1, 100)).toBe(1); | |
| 48 | }); | |
| 49 | it("clamps above hi", () => { | |
| 50 | expect(clampInt(500, 1, 100)).toBe(100); | |
| 51 | }); | |
| 52 | it("floors fractional", () => { | |
| 53 | expect(clampInt(2.7, 1, 100)).toBe(2); | |
| 54 | }); | |
| 55 | it("passes through valid values", () => { | |
| 56 | expect(clampInt(42, 1, 100)).toBe(42); | |
| 57 | }); | |
| 58 | }); |