Files
loki/scripts/test/fleet-refs-audit.ts
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

248 lines
8.2 KiB
TypeScript

/**
* Pins the fleet-refs-audit self-match bug: fleet-refs-audit.yml's own
* `RETIRED_HANDLES: maonakamoto` declaration made the audit flag itself on
* its first real run (2026-08-28) — the workflow that exists to catch a
* retired-owner reference failed on the one line that DEFINES what a retired
* owner is, not a line that USES one.
*
* Also covers USES and verdictFor — the mechanism that actually caught the
* three real outages this audit exists for (2026-08-26/27/28), and which had
* zero test coverage until this file: only the newer, less consequential
* retired-handle check was pinned. A regex bug in USES would silently miss
* exactly the class of breakage the whole tool was built to catch.
*/
import assert from "node:assert/strict";
import {
retiredHandleMatches,
USES,
verdictFor,
pathVerdictFor,
} from "../ci/fleet-refs-audit-lib.mjs";
const RETIRED = ["maonakamoto"];
// --- the exact production false positive ---------------------------------
const selfDeclaration = `
on:
workflow_dispatch: {}
jobs:
audit:
steps:
- env:
RETIRED_HANDLES: maonakamoto
run: node scripts/ci/fleet-refs-audit.mjs
`;
assert.deepEqual(
retiredHandleMatches(selfDeclaration, RETIRED),
[],
"the RETIRED_HANDLES declaration line must not flag itself",
);
// --- a genuine live reference must still be caught ------------------------
const staleUse = `
jobs:
x:
uses: maonakamoto/dotfiles/.github/workflows/thing.yml@master
`;
assert.deepEqual(
retiredHandleMatches(staleUse, RETIRED),
["maonakamoto"],
"a real uses: line naming the retired owner must still fail",
);
// --- documentation in a comment is intentional, not a bug -----------------
const documented = `
# 2026-08-26 the account maonakamoto was renamed to catomean
name: CI
`;
assert.deepEqual(
retiredHandleMatches(documented, RETIRED),
[],
"a comment explaining the outage must not be flagged",
);
// --- RETIRED_HANDLES stripping must not eat an unrelated live reference on
// a DIFFERENT line in the same file --------------------------------
const both = `
env:
RETIRED_HANDLES: maonakamoto
jobs:
x:
uses: maonakamoto/other-repo@main
`;
assert.deepEqual(
retiredHandleMatches(both, RETIRED),
["maonakamoto"],
"stripping the declaration line must not hide a genuine reference elsewhere in the same file",
);
// --- a clean file reports nothing ------------------------------------------
assert.deepEqual(
retiredHandleMatches(
"name: CI\non: push\njobs:\n x:\n uses: bitbaum/loki/.github/workflows/selfhost-deploy.yml@main\n",
RETIRED,
),
[],
"a file with no retired handle anywhere must report nothing",
);
// --- USES: what actually gets checked against GitHub -----------------------
const usesOf = (text: string) =>
[...text.matchAll(USES)].map(([, owner, name]) => `${owner}/${name}`);
assert.deepEqual(
usesOf("jobs:\n x:\n uses: bitbaum/loki@main\n"),
["bitbaum/loki"],
"a plain owner/repo@ref uses: line is matched",
);
assert.deepEqual(
usesOf("jobs:\n x:\n uses: bitbaum/loki/.github/workflows/selfhost-deploy.yml@main\n"),
["bitbaum/loki"],
"the owner/repo is extracted even with a path and filename after it",
);
assert.deepEqual(
usesOf("jobs:\n x:\n uses: ./.github/actions/local-thing\n"),
[],
"a local action (no owner, no @ref) is not matched",
);
assert.deepEqual(
usesOf("jobs:\n x:\n uses: docker://ghcr.io/owner/image:tag\n"),
[],
"a docker:// reference has no owner/repo to be wrong about and must not match",
);
assert.deepEqual(
usesOf("jobs:\n a:\n uses: bitbaum/one@v1\n b:\n uses: bitbaum/two@v2\n"),
["bitbaum/one", "bitbaum/two"],
"every uses: line in a file is matched independently",
);
assert.deepEqual(
usesOf(" uses: bitbaum/loki@main\n"),
["bitbaum/loki"],
"indentation before uses: does not prevent a match",
);
// --- verdictFor: the actual redirect-detection decision --------------------
assert.deepEqual(
verdictFor("bitbaum/loki", "bitbaum/loki"),
{ kind: "ok" },
"a reference already naming its canonical owner is fine",
);
assert.deepEqual(
verdictFor("catomean/loki", "bitbaum/loki"),
{
kind: "stale",
message: "uses catomean/loki — canonical is bitbaum/loki (Actions will NOT follow this)",
},
"REST resolving a DIFFERENT canonical name is the exact redirect gap Actions falls into",
);
assert.deepEqual(
verdictFor("catomean/does-not-exist", null),
{ kind: "stale", message: "uses catomean/does-not-exist — DOES NOT EXIST" },
"a 404 from REST is reported as stale, not silently skipped",
);
assert.deepEqual(
verdictFor("bitbaum/loki", undefined),
{ kind: "unreadable", message: "bitbaum/loki (lookup failed)" },
"a failed lookup (rate limit, 5xx) must be unreadable — never reported as clean, never as a false stale",
);
// --- USES now also yields the subpath and ref, so the FILE can be checked ---
const partsOf = (text: string) =>
[...text.matchAll(USES)].map(([, owner, name, subpath, ref]) => ({
slug: `${owner}/${name}`,
subpath,
ref,
}));
assert.deepEqual(
partsOf("jobs:\n x:\n uses: bitbaum/fleet/.github/workflows/auto-merge-sweep.yml@main\n"),
[{ slug: "bitbaum/fleet", subpath: "/.github/workflows/auto-merge-sweep.yml", ref: "main" }],
"a reusable-workflow reference yields owner/repo, the path, and the ref",
);
assert.deepEqual(
partsOf("jobs:\n x:\n uses: actions/checkout@v5\n"),
[{ slug: "actions/checkout", subpath: "", ref: "v5" }],
"a plain action has no subpath — there is no file to check beyond the repo",
);
assert.deepEqual(
partsOf("jobs:\n x:\n uses: bitbaum/fleet/.github/workflows/x.yml@abc1234\n")[0].ref,
"abc1234",
"a pinned sha is captured as the ref, not the branch name",
);
// --- pathVerdictFor: the repo can be canonical while the file is gone -------
// This is the dotfiles shim case. Sixteen repos called
// bitbaum/dotfiles/.github/workflows/auto-merge-sweep.yml; the shim was deleted
// once they migrated to bitbaum/fleet. `bitbaum/dotfiles` is and remains the
// canonical name, so the owner check passes and sees nothing wrong.
assert.deepEqual(
pathVerdictFor("bitbaum/dotfiles", "/.github/workflows/auto-merge-sweep.yml", "master", false),
{
kind: "stale",
message:
"uses bitbaum/dotfiles/.github/workflows/auto-merge-sweep.yml@master — the repo exists but THAT FILE DOES NOT (moved or deleted)",
},
"a deleted reusable workflow in a repo that still exists must be caught",
);
assert.deepEqual(
pathVerdictFor("bitbaum/fleet", "/.github/workflows/auto-merge-sweep.yml", "main", true),
{ kind: "ok" },
"a file that is still there is fine",
);
assert.deepEqual(
pathVerdictFor("actions/checkout", "", "v5", true),
{ kind: "ok" },
"no subpath means there is no file to check — never a finding",
);
assert.deepEqual(
pathVerdictFor("bitbaum/fleet", "/.github/workflows/x.yml", "main", undefined),
{
kind: "unreadable",
message: "bitbaum/fleet/.github/workflows/x.yml@main (path lookup failed)",
},
"a failed path lookup is unreadable — never clean, and never a false stale",
);
// --- the compact list form is a `uses:` too --------------------------------
// `^\s*uses:` does not match `- uses: …`. Steps are routinely written that
// way, so the audit skipped them while reporting a ref count that looked
// complete: 59 of 155 files held at least one reference it never checked.
assert.deepEqual(
usesOf("jobs:\n x:\n steps:\n - uses: actions/checkout@v5\n"),
["actions/checkout"],
"a step in the compact list form (- uses:) must be matched",
);
assert.deepEqual(
usesOf("jobs:\n x:\n steps:\n - name: Checkout\n uses: actions/checkout@v5\n"),
["actions/checkout"],
"the multi-line step form must still be matched",
);
assert.deepEqual(
partsOf("jobs:\n x:\n steps:\n - uses: bitbaum/fleet/.github/actions/thing@main\n"),
[{ slug: "bitbaum/fleet", subpath: "/.github/actions/thing", ref: "main" }],
"a fleet-owned action referenced as a step yields its path, so the file is checked too",
);
assert.deepEqual(
usesOf("jobs:\n x:\n steps:\n - run: echo not-a-uses\n"),
[],
"a list item that is not a uses: must not be matched",
);
console.log("OK: 26 assertions passed");