|
| 1 | +import { readFile, unlink } from "node:fs/promises"; |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import type { SessionEntry } from "../../config/sessions.js"; |
3 | 4 | import { buildContextReply } from "./commands-context-report.js"; |
@@ -155,4 +156,30 @@ describe("buildContextReply", () => {
|
155 | 156 | expect(result.text).toContain("Session tokens (cached): 900 total / ctx=8,192"); |
156 | 157 | expect(result.text).not.toContain("Actual context usage (cached): 111 tok"); |
157 | 158 | }); |
| 159 | + |
| 160 | +it("renders context map as sensitive local PNG media", async () => { |
| 161 | +const result = await buildContextReply( |
| 162 | +makeParams("/context map", false, { |
| 163 | +contextTokens: 8_192, |
| 164 | +totalTokens: 900, |
| 165 | +}), |
| 166 | +); |
| 167 | +if (!result.mediaUrl) { |
| 168 | +throw new Error("missing context map media path"); |
| 169 | +} |
| 170 | +try { |
| 171 | +const png = await readFile(result.mediaUrl); |
| 172 | +expect(result.text).toContain("Context treemap"); |
| 173 | +expect(result.text).toContain("Source: run"); |
| 174 | +expect(result.text).toContain("Actual cached context: 900 tok"); |
| 175 | +expect(result.trustedLocalMedia).toBe(true); |
| 176 | +expect(result.sensitiveMedia).toBe(true); |
| 177 | +expect(png.subarray(0, 8)).toEqual(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])); |
| 178 | +expect(png.subarray(12, 16).toString("ascii")).toBe("IHDR"); |
| 179 | +expect(png.readUInt32BE(16)).toBe(1280); |
| 180 | +expect(png.readUInt32BE(20)).toBe(860); |
| 181 | +} finally { |
| 182 | +await unlink(result.mediaUrl); |
| 183 | +} |
| 184 | +}); |
158 | 185 | }); |