@@ -207,4 +207,65 @@ describe("codex cli node sessions", () => {
|
207 | 207 | }), |
208 | 208 | ).rejects.toThrow("Codex CLI node command returned malformed payloadJSON."); |
209 | 209 | }); |
| 210 | + |
| 211 | +it("keeps Codex history session previews on UTF-16 code point boundaries", async () => { |
| 212 | +const sessionId = "019e2007-1f7e-7eb1-a42b-8c01f4b9b5ce"; |
| 213 | +const text = `${"a".repeat(136)}🤖tail`; |
| 214 | +await fs.writeFile( |
| 215 | +path.join(tempDir, "history.jsonl"), |
| 216 | +JSON.stringify({ session_id: sessionId, ts: 1778678322, text }), |
| 217 | +); |
| 218 | + |
| 219 | +const command = createCodexCliSessionNodeHostCommands().find( |
| 220 | +(entry) => entry.command === CODEX_CLI_SESSIONS_LIST_COMMAND, |
| 221 | +); |
| 222 | +const raw = await command?.handle(JSON.stringify({ filter: "", limit: 5 })); |
| 223 | +const parsed = JSON.parse(raw ?? "{}") as { |
| 224 | +sessions?: Array<{ lastMessage?: string }>; |
| 225 | +}; |
| 226 | + |
| 227 | +expect(parsed.sessions?.[0]?.lastMessage).toBe(`${"a".repeat(136)}...`); |
| 228 | +expect(parsed.sessions?.[0]?.lastMessage).not.toContain("\ud83e"); |
| 229 | +expect(parsed.sessions?.[0]?.lastMessage).not.toContain("\udd16"); |
| 230 | +}); |
| 231 | + |
| 232 | +it("keeps Codex session-file previews on UTF-16 code point boundaries", async () => { |
| 233 | +const sessionId = "019e23d1-f33d-78e3-959e-0f56f30a5248"; |
| 234 | +const sessionDir = path.join(tempDir, "sessions", "2026", "05", "14"); |
| 235 | +const sessionFile = path.join(sessionDir, `rollout-2026-05-14T00-10-22-${sessionId}.jsonl`); |
| 236 | +const text = `${"b".repeat(136)}🤖tail`; |
| 237 | + |
| 238 | +await fs.mkdir(sessionDir, { recursive: true }); |
| 239 | +await fs.writeFile( |
| 240 | +sessionFile, |
| 241 | +[ |
| 242 | +JSON.stringify({ |
| 243 | +timestamp: "2026-05-14T00:10:23.618Z", |
| 244 | +type: "session_meta", |
| 245 | +payload: { id: sessionId, cwd: "/tmp/codex-work" }, |
| 246 | +}), |
| 247 | +JSON.stringify({ |
| 248 | +timestamp: "2026-05-14T00:10:23.619Z", |
| 249 | +type: "response_item", |
| 250 | +payload: { |
| 251 | +type: "message", |
| 252 | +role: "user", |
| 253 | +content: [{ type: "input_text", text }], |
| 254 | +}, |
| 255 | +}), |
| 256 | +].join("\n"), |
| 257 | +); |
| 258 | + |
| 259 | +const command = createCodexCliSessionNodeHostCommands().find( |
| 260 | +(entry) => entry.command === CODEX_CLI_SESSIONS_LIST_COMMAND, |
| 261 | +); |
| 262 | +const raw = await command?.handle(JSON.stringify({ filter: "", limit: 5 })); |
| 263 | +const parsed = JSON.parse(raw ?? "{}") as { |
| 264 | +sessions?: Array<{ lastMessage?: string }>; |
| 265 | +}; |
| 266 | + |
| 267 | +expect(parsed.sessions?.[0]?.lastMessage).toBe(`${"b".repeat(136)}...`); |
| 268 | +expect(parsed.sessions?.[0]?.lastMessage).not.toContain("\ud83e"); |
| 269 | +expect(parsed.sessions?.[0]?.lastMessage).not.toContain("\udd16"); |
| 270 | +}); |
210 | 271 | }); |