70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { AREA_ALIASES, UPDATE_ALIASES, normalizeCliArea } from "./area-aliases.js";
|
|
import { KNOWN_AREAS } from "./runner.js";
|
|
|
|
/**
|
|
* Drift guard for the shared alias table.
|
|
*
|
|
* `read-only.ts` once hand-copied the alias pairs from `runner.ts` and the two
|
|
* silently diverged — the exact class of bug the 2026-10-17 architecture
|
|
* review called "two sources of truth". The tables now live in one module and
|
|
* are imported by dispatch, help, and the read-only gateway; these tests make
|
|
* the remaining cross-module contract explicit: an alias may only point at an
|
|
* area the dispatcher actually handles, may not chain into another alias, and
|
|
* must not shadow a real area name.
|
|
*/
|
|
|
|
describe("area alias integrity", () => {
|
|
test("every alias resolves to a dispatchable area", () => {
|
|
const dangling = Object.entries(AREA_ALIASES)
|
|
.filter(([, target]) => !KNOWN_AREAS.has(target))
|
|
.map(([alias, target]) => `${alias} -> ${target}`);
|
|
|
|
expect(dangling).toEqual([]);
|
|
});
|
|
|
|
test("no alias chains into another alias", () => {
|
|
// normalizeCliArea applies one lookup; a chained alias would dispatch the
|
|
// raw alias spelling as a command area and fail with "Unknown command".
|
|
const chained = Object.values(AREA_ALIASES).filter((target) => target in AREA_ALIASES);
|
|
|
|
expect(chained).toEqual([]);
|
|
});
|
|
|
|
test("alias spellings never shadow a real area name", () => {
|
|
// KNOWN_AREAS is the handler tables plus the alias keys; subtracting the
|
|
// alias keys recovers the real dispatch areas. An alias colliding with
|
|
// one of them would be dead weight at best and ambiguous at worst.
|
|
const realAreas = new Set([...KNOWN_AREAS].filter((area) => !(area in AREA_ALIASES)));
|
|
const shadowing = Object.keys(AREA_ALIASES).filter((alias) => realAreas.has(alias));
|
|
|
|
expect(shadowing).toEqual([]);
|
|
});
|
|
|
|
test("every update spelling normalizes onto the real update area", () => {
|
|
for (const spelling of UPDATE_ALIASES) {
|
|
expect(normalizeCliArea(spelling)).toBe("update");
|
|
}
|
|
expect(KNOWN_AREAS.has("update")).toBe(true);
|
|
});
|
|
|
|
test("normalization is idempotent and case-insensitive", () => {
|
|
expect(normalizeCliArea(normalizeCliArea("corp"))).toBe("corps");
|
|
expect(normalizeCliArea("CORP")).toBe("corps");
|
|
expect(normalizeCliArea("Self-Update")).toBe("update");
|
|
});
|
|
|
|
test("every alias and update spelling resolves through KNOWN_AREAS", () => {
|
|
// Alias keys must be members outright: help lookup and the read-only
|
|
// gateway resolve the raw spelling before any normalization. Update
|
|
// spellings are normalized first, so their canonical target is the
|
|
// dispatchable name.
|
|
for (const alias of Object.keys(AREA_ALIASES)) {
|
|
expect(KNOWN_AREAS.has(alias)).toBe(true);
|
|
}
|
|
for (const spelling of UPDATE_ALIASES) {
|
|
expect(KNOWN_AREAS.has(normalizeCliArea(spelling))).toBe(true);
|
|
}
|
|
});
|
|
});
|