| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { distinctFacts, sameFact } from "./memory-facts.ts"; |
| 5 | |
| 6 | test("a fact remembered twice is shown once, the first kept", () => { |
| 7 | const facts = [ |
| 8 | { id: "a", text: "Run tests with npm test." }, |
| 9 | { id: "b", text: "We use pnpm everywhere" }, |
| 10 | { id: "c", text: "run tests with npm test" }, |
| 11 | { id: "d", text: "We use pnpm everywhere." }, |
| 12 | ]; |
| 13 | assert.deepEqual(distinctFacts(facts).map((fact) => fact.id), ["a", "b"]); |
| 14 | assert.deepEqual(distinctFacts([]), []); |
| 15 | }); |
| 16 | |
| 17 | test("near-duplicates collapse: a list that grew, a sentence cut short", () => { |
| 18 | const facts = [ |
| 19 | { id: "a", text: "g1t is a Cargo workspace (apps/api, crates/*, services/actions, services/billing); `cargo test` runs its tests." }, |
| 20 | { id: "b", text: "g1t is a Cargo workspace (apps/api, crates/*, services/actions, services/billing, services/work); `cargo test` runs its tests." }, |
| 21 | { id: "c", text: "Roles. Viewer, commenter, planner and approver map onto" }, |
| 22 | { id: "d", text: "Roles. Viewer, commenter, planner and approver map onto the five repository roles." }, |
| 23 | { id: "e", text: "Use npm to install." }, |
| 24 | { id: "f", text: "Use pnpm to install." }, |
| 25 | ]; |
| 26 | assert.deepEqual(distinctFacts(facts).map((fact) => fact.id), ["a", "c", "e", "f"]); |
| 27 | assert.ok(!sameFact("Run cargo test in the crate you changed.", "Run npm test in the app you changed.")); |
| 28 | assert.ok(!sameFact("use pnpm", "use pnpm in the web app and npm in the docs, which predates it")); |
| 29 | }); |