import { describe, expect, test } from "bun:test" import { toMessagePreview } from "./message-preview" describe("toMessagePreview", () => { test("leaves plain prose alone but for its whitespace", () => { expect(toMessagePreview(" make the sidebar labels shorter ")) .toBe("make the sidebar labels shorter") }) test("flattens the lines a clamp would otherwise spend", () => { // Two clamped lines used to buy two bullets and nothing that said what the // message was about. expect(toMessagePreview("Fix these:\n\n- the router\n- the store\n- the tests")) .toBe("Fix these: the router the store the tests") }) test("unwraps emphasis, strikethrough and inline code", () => { expect(toMessagePreview("**Done** — the ~~old~~ `parseTranscript` path is gone")) .toBe("Done — the old parseTranscript path is gone") expect(toMessagePreview("*maybe* _really_ ***very*** sure")).toBe("maybe really very sure") }) test("leaves double underscores alone, dunders and bold alike", () => { // `__init__` and `__bold__` are the same string; no rule tells them apart. // Showing the underscores is a blemish, turning `__init__` into `init` // changes what the message says — so doubles are left as written. expect(toMessagePreview("call __init__ first")).toBe("call __init__ first") expect(toMessagePreview("this is __bold__")).toBe("this is __bold__") }) test("keeps a link's words and drops its href", () => { expect(toMessagePreview("see [the docs](https://example.com/a_b) first")) .toBe("see the docs first") expect(toMessagePreview("![a diagram](x.png) explains it")).toBe("a diagram explains it") expect(toMessagePreview("see [the docs][docs]")).toBe("see the docs") expect(toMessagePreview("at ")).toBe("at https://example.com/x") }) test("drops headings, quotes, rules and task boxes but keeps their text", () => { expect(toMessagePreview("## Plan\n\n> quoting you\n\n---\n\n- [x] shipped")) .toBe("Plan quoting you shipped") }) test("keeps the code inside a fence and drops the fence", () => { // A message that is mostly code would otherwise preview as empty. expect(toMessagePreview("Try:\n```ts\nconst x = 1\n```")) .toBe("Try: const x = 1") }) test("does not eat underscores inside identifiers", () => { // The rule that would do real damage: these are names, not emphasis, and // CommonMark agrees — intraword underscores don't emphasise. expect(toMessagePreview("rename retry_count_ms today")).toBe("rename retry_count_ms today") expect(toMessagePreview("set last_turn_ended_at")).toBe("set last_turn_ended_at") }) test("does not eat a lone asterisk or a bare underscore", () => { expect(toMessagePreview("2 * 3 and a _ on its own")).toBe("2 * 3 and a _ on its own") expect(toMessagePreview("glob for *.ts files")).toBe("glob for *.ts files") }) test("leaves tags alone — an agent that wrote one meant it", () => { expect(toMessagePreview("wrap it in please")) .toBe("wrap it in please") }) test("survives text that is nothing but markup", () => { expect(toMessagePreview("---")).toBe("") expect(toMessagePreview("```\n```")).toBe("") expect(toMessagePreview("")).toBe("") }) })