changelog.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, test } from "vitest";
  2. import { type ChangelogEntry, normalizeChangelogLinks } from "../src/utils/changelog.ts";
  3. const entry: ChangelogEntry = {
  4. major: 0,
  5. minor: 79,
  6. patch: 0,
  7. content: "",
  8. };
  9. describe("normalizeChangelogLinks", () => {
  10. test("rewrites package-relative changelog links to tag-pinned GitHub source links", () => {
  11. const markdown = [
  12. "[Project Trust](README.md#project-trust)",
  13. "[Extensions](docs/extensions.md#project_trust)",
  14. "[Examples](examples/extensions/)",
  15. "[Root README](../../README.md#supply-chain-hardening)",
  16. ].join("\n");
  17. expect(normalizeChangelogLinks(markdown, entry)).toBe(
  18. [
  19. "[Project Trust](https://github.com/earendil-works/pi/blob/v0.79.0/packages/coding-agent/README.md#project-trust)",
  20. "[Extensions](https://github.com/earendil-works/pi/blob/v0.79.0/packages/coding-agent/docs/extensions.md#project_trust)",
  21. "[Examples](https://github.com/earendil-works/pi/tree/v0.79.0/packages/coding-agent/examples/extensions/)",
  22. "[Root README](https://github.com/earendil-works/pi/blob/v0.79.0/README.md#supply-chain-hardening)",
  23. ].join("\n"),
  24. );
  25. });
  26. test("canonicalizes old repository URLs without changing external links", () => {
  27. const markdown = [
  28. "[#5167](https://github.com/earendil-works/pi-mono/pull/5167)",
  29. "[#4163](https://github.com/badlogic/pi-mono/issues/4163)",
  30. "[Agent README](https://github.com/badlogic/pi-mono/blob/main/packages/agent/README.md)",
  31. "[External](https://example.com/docs)",
  32. "[Local anchor](#settings)",
  33. ].join("\n");
  34. expect(normalizeChangelogLinks(markdown, "0.79.0")).toBe(
  35. [
  36. "[#5167](https://github.com/earendil-works/pi/pull/5167)",
  37. "[#4163](https://github.com/earendil-works/pi/issues/4163)",
  38. "[Agent README](https://github.com/earendil-works/pi/blob/v0.79.0/packages/agent/README.md)",
  39. "[External](https://example.com/docs)",
  40. "[Local anchor](#settings)",
  41. ].join("\n"),
  42. );
  43. });
  44. });