Files
loki/scripts/test/loki-project-ranking.ts
CatoandClaude Opus 5 baa8e2e6fb chore(aoz): follow bitbaum/aoz-housing -> bitbaum/aoz-begleitung (#732)
The repo was renamed today. It was the last place the product was still called
Housing: the name row in fleet's registers/retired.json retired "AOZ Housing" as
the PRODUCT name on 2026-09-10, but the repo kept it, and the repo is public.

The deploy name `aoz-wohnen` is deliberately NOT renamed with it. It is an
infrastructure identifier — systemd unit, /opt path, database — nothing on the
box keys on the repo name, and moving it would touch a live site for no visible
gain. apps.conf's comment block already said as much and still does.

The load-bearing change is apps.conf's fourth field. repo-metadata-audit.mjs
keys the register on that path's BASENAME, so while it read /home/g/dev/
aoz-housing the join against GitHub missed and every metadata check for this
repo was silently skipped — the audit went green by not looking at it. The local
checkout was moved to match and its three worktrees repaired (`git worktree
repair`), not pruned: they hold branches.

Two test failures worth keeping, because both were the rename telling the truth:

  - project-mention asserted that "the AOZ housing rebuild" resolves to the
    project. With the slug renamed it does not, and should not. The case exists
    to prove "a slug with a hyphen, typed with a space" matches, so the INPUT
    moved to the current name rather than the expectation being loosened.
  - tab-match asserted a terminal tab literally named "AOZ Housing" matches the
    slug. Same thing: the fixture now uses the name the tab would actually have.

Consequence worth naming: someone who types "aoz housing" at Loki will no longer
be understood. There is an alias mechanism for exactly this shape
(register/build.ts maps the deploy name to the repo), but wiring the retired
name into mention-matching is a product decision, not a rename chore.

Left alone on purpose: scripts/db/retire-stale-projects.ts, whose data row
records the project names the database actually held when that migration ran;
and content/thoughts/*.md, published essays — one of which quotes a filesystem
path observed during a debugging session, so rewriting it would falsify the
anecdote.

The production user_projects row was updated too (name and git_url), because the
database is a second copy of the repo identity and a past rename left 21 rows
pointing at a dead account. New URL proven to resolve: 431bae7.

Tests green: fleet-register 44, project-mention 28, tab-match 10, fleet-map 7,
loki-project-ranking all.


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

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 12:17:25 -07:00

102 lines
2.9 KiB
TypeScript

/**
* The project the operator NAMED must survive the slice.
*
* Production: asked "what do you think about heidi", Loki answered about two
* contacts named Heidi and never mentioned the `Heidi` PROJECT — which is
* registered. The people source searched by message; the project source did
* not. It returned projects in table order and the caller head-sliced to a
* limit, so with ~30 registered projects the one being asked about simply fell
* off the end.
*
* No prompt rule can recover a record that was never retrieved, which is why
* this is tested at the retrieval layer rather than left to the contract.
*
* Pure: no database, no model.
*/
import { rankProjectsByMessage } from "@/lib/agent/project-ranking";
let failures = 0;
function check(name: string, actual: unknown, expected: unknown) {
const a = JSON.stringify(actual);
const e = JSON.stringify(expected);
if (a === e) {
console.log(` ✓ ${name}`);
} else {
console.error(` ✗ ${name}\n expected: ${e}\n actual: ${a}`);
failures++;
}
}
const names = (rows: Array<{ name: string }>) => rows.map((r) => r.name);
const projects = [
"aoz-begleitung",
"BiasLens",
"botsmann",
"datacat",
"evig",
"loki",
"Zeitkastli",
"ivy-portal",
"orangecat",
"Heidi",
].map((name) => ({ name }));
console.log("loki project ranking");
check(
"the named project is ranked first, so a slice cannot drop it",
names(rankProjectsByMessage(projects, "what do you think about heidi")).slice(0, 1),
["Heidi"],
);
check(
"matching is case-insensitive",
names(rankProjectsByMessage(projects, "HEIDI status?")).slice(0, 1),
["Heidi"],
);
check(
"a slug is found when typed with a space",
names(rankProjectsByMessage(projects, "how is aoz housing doing")).slice(0, 1),
["aoz-begleitung"],
);
check(
"a slug part is enough — 'aoz' finds aoz-begleitung",
names(rankProjectsByMessage(projects, "anything new on aoz?")).slice(0, 1),
["aoz-begleitung"],
);
check(
"several named projects all come first, original order among them kept",
names(rankProjectsByMessage(projects, "compare evig and datacat")).slice(0, 2),
["datacat", "evig"],
);
check(
"a message naming nothing leaves the order untouched",
names(rankProjectsByMessage(projects, "what needs my attention today")),
names(projects),
);
// Guard against the obvious false positive: a two-letter project name must not
// match every word that happens to contain it.
check(
"names under three characters never match",
names(rankProjectsByMessage([{ name: "ai" }, { name: "datacat" }], "said it again")).slice(0, 1),
["ai"],
);
check(
"no project is lost or duplicated by ranking",
names(rankProjectsByMessage(projects, "heidi and evig")).slice().sort(),
names(projects).slice().sort(),
);
if (failures > 0) {
console.error(`\n${failures} check(s) failed`);
process.exit(1);
}
console.log("✓ loki project ranking: all checks passed");