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.
| One kind of access token; presence and status; usernames keep their case; the tour is a miniature of the real app; icons for password managers | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { USERNAME_PATTERN, canonicalUsername, isReservedName, isValidNamespace, isValidUsername, shownUsername } from "./names.ts"; | |
| 5 | ||
| 6 | test("usernames take letters of either case, digits and single hyphens, up to 39", () => { | |
| 7 | for (const good of ["ana", "Ana", "ANA-Lopez", "a", "A1", "x".repeat(39)]) assert.ok(isValidUsername(good), good); | |
| 8 | for (const bad of ["", "-Ana", "Ana-", "An--a", "An_a", "Ana.B", "Ana B", "x".repeat(40), "Ána"]) assert.ok(!isValidUsername(bad), bad); | |
| 9 | }); | |
| 10 | ||
| 11 | test("reserved names are reserved in any case", () => { | |
| 12 | for (const name of ["G1T", "G1t-Agent", "Ghost", "Settings", "API"]) { | |
| 13 | assert.ok(isReservedName(name), name); | |
| 14 | assert.ok(!isValidUsername(name), name); | |
| 15 | } | |
| 16 | }); | |
| 17 | ||
| 18 | test("a username is found lowercased and shown as written", () => { | |
| 19 | assert.equal(canonicalUsername(" Ana-Lopez "), "ana-lopez"); | |
| 20 | assert.equal(shownUsername({ username: "ana", display_username: "Ana" }), "Ana"); | |
| 21 | assert.equal(shownUsername({ username: "ana", displayUsername: "ANA" }), "ANA"); | |
| 22 | assert.equal(shownUsername({ username: "ana" }), "ana"); | |
| 23 | // A display form that is some other name is never shown. | |
| 24 | assert.equal(shownUsername({ username: "ana", display_username: "Bob" }), "ana"); | |
| 25 | // Workspace slugs stay lowercase. | |
| 26 | assert.ok(!isValidNamespace("Acme")); | |
| 27 | }); | |
| 28 | ||
| 29 | test("the form's pattern says what the rule says", () => { | |
| 30 | const pattern = new RegExp(`^(?:${USERNAME_PATTERN})$`); | |
| 31 | for (const name of ["Ana", "ana-lopez", "A1"]) assert.ok(pattern.test(name), name); | |
| 32 | for (const name of ["-ana", "ana-", "an--a", "an_a"]) assert.ok(!pattern.test(name), name); | |
| 33 | }); |