|
1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | +import { createHash } from "node:crypto"; |
2 | 3 | import { |
3 | 4 | DEFAULT_LOG_FILTER_STATE, |
4 | 5 | extractLogFilterOptions, |
5 | 6 | filterLogs, |
6 | 7 | hasActiveLogFilters, |
7 | 8 | } from "../src/pages/logs-filter"; |
| 9 | +import { hashLogConversationQuery, unwrapLogConversationQuery } from "../src/log-conversation-id"; |
8 | 10 |
|
9 | 11 | const NOW = 2_000_000_000_000; |
10 | 12 | const logs = [ |
@@ -189,3 +191,35 @@ test("exact model choices distinguish prefix siblings and compose with a provide |
189 | 191 | expect(filterLogs(rows, { ...DEFAULT_LOG_FILTER_STATE, model: "model-a", provider: "openai" }).map(row => row.id)) |
190 | 192 | .toEqual(["exact", "resolved", "attempt"]); |
191 | 193 | }); |
| 194 | + |
| 195 | +const digest32 = (raw: string) => createHash("sha256").update(raw).digest("hex").slice(0, 32); |
| 196 | +const CODEX_THREAD_ID = "019f6482-67d5-77c2-a643-02daddaa7115"; |
| 197 | + |
| 198 | +describe("codex://threads paste in the conversation filter", () => { |
| 199 | + test("unwraps the deep link to the bare thread id and hashes the unwrapped value", async () => { |
| 200 | + expect(unwrapLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`)).toBe(CODEX_THREAD_ID); |
| 201 | + expect(unwrapLogConversationQuery(` CODEX://THREADS/${CODEX_THREAD_ID}/ `)).toBe(CODEX_THREAD_ID); |
| 202 | + expect(unwrapLogConversationQuery(CODEX_THREAD_ID)).toBe(CODEX_THREAD_ID); |
| 203 | + expect(unwrapLogConversationQuery("codex://other/x")).toBe("codex://other/x"); |
| 204 | + expect(unwrapLogConversationQuery("codex://threads/")).toBe("codex://threads/"); |
| 205 | + expect(await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`)).toBe(digest32(CODEX_THREAD_ID)); |
| 206 | + }); |
| 207 | + |
| 208 | + test("filterLogs matches a stored digest or raw id behind the pasted link", async () => { |
| 209 | + const rows = [ |
| 210 | + { id: "hashed", conversationId: digest32(CODEX_THREAD_ID) }, |
| 211 | + { id: "raw", conversationId: "raw-thread" }, |
| 212 | + { id: "other", conversationId: digest32("other") }, |
| 213 | + ]; |
| 214 | + const queryHash = await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`); |
| 215 | + expect(filterLogs(rows, { |
| 216 | + ...DEFAULT_LOG_FILTER_STATE, |
| 217 | + conversationId: `codex://threads/${CODEX_THREAD_ID}`, |
| 218 | + conversationQueryHash: queryHash, |
| 219 | + }, NOW).map(row => row.id)).toEqual(["hashed"]); |
| 220 | + expect(filterLogs(rows, { |
| 221 | + ...DEFAULT_LOG_FILTER_STATE, |
| 222 | + conversationId: "codex://threads/raw-thread", |
| 223 | + }, NOW).map(row => row.id)).toEqual(["raw"]); |
| 224 | + }); |
| 225 | +}); |
0 commit comments