Skip to content
31 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Docs: a workspace knowledge base people and agents write together1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { freeSlug, linkedPageIds, pageIdFrom, pageSlug, slugify, validSpaceSlug } from "./slugs.ts";
5
6const id = "pag_01jb2k7x9hfq0b3zj0f5s2m8ra";
7
8test("page slugs carry the id, so renames keep links working", () => {
9 assert.equal(pageSlug("Release checklist: v2!", id), `release-checklist-v2-${id}`);
10 assert.equal(pageSlug("", id), id);
11 assert.equal(pageIdFrom(`anything-${id}`), id);
12 assert.equal(pageIdFrom(id), id);
13 assert.equal(pageIdFrom("no-id-here"), null);
14});
15
16test("slugify drops accents and punctuation", () => {
17 assert.equal(slugify("Café Ops — Runbooks"), "cafe-ops-runbooks");
18});
19
20test("space slugs avoid taken and reserved names", () => {
21 assert.equal(freeSlug("Engineering", new Set()), "engineering");
22 assert.equal(freeSlug("Engineering", new Set(["engineering"])), "engineering-2");
23 assert.equal(freeSlug("Search", new Set()), "search-2");
24 assert.equal(validSpaceSlug("eng-docs"), "eng-docs");
25 assert.equal(validSpaceSlug("-bad"), null);
26 assert.equal(validSpaceSlug("trash"), null);
27});
28
29test("links to pages are found by their ids", () => {
30 assert.deepEqual(linkedPageIds(`See [the plan](/acme/-/docs/eng/plan-${id}) and [again](${id}).`), [id]);
31});