Phase 6D pass 1. The shell's navigation was a flat list of module ids, which is not a usable experience — and the obvious fix carries an obvious trap. Letting a module declare its folder, or modelling "Media" as something Livestream and Video belong to, turns a rendering preference into architecture: a folder becomes an owner, membership starts to look like a dependency, and the flat module graph acquires a hierarchy nobody decided on. So the rule comes first: a Dashboard group is a label on a rendering bucket. No manifest, no version, no artifact, no API, no lifecycle; nothing depends on it. Livestream depends on Video because it calls Video's functionality, and that orders startup. Livestream is shown under Media, and that orders nothing. No parent module, child module, owning module, or group-derived dependency appears anywhere in the contracts. No manifest change and no version 5. `manifest.name` has been required since version 1 and already is the module's product identity, so the shell renders "Livestream" instead of `livestream` with nothing added. `suggestedGroup` is deliberately deferred rather than shipped: it would force a hard manifest-version cutover for a hint, and its only correct semantics needs initialization logic that risks a suggestion overwriting an administrator's decision. Defaulting and ownership are different things. Two Core tables (migration 0003) hold groups and placements — server-side, because a church configures its Dashboard rather than one browser; platform-global, because no organization model exists to scope them to. `group_id` is `on delete set null`, so deleting a group ungroups its modules and a dangling reference is impossible. `module_id` carries no foreign key, because modules are packages rather than rows, so a placement for an uninstalled module is retained and restores its position on reinstall. `resolveDashboardNavigation` is a pure function of configuration plus the mountable set: an unplaced module is ungrouped and visible with no initialization write, an absent module renders nothing, empty groups are kept, and ordering is total with the module id as final tie-break. `GET /api/v1/dashboard/navigation` returns the resolved view, layered on top of the host-neutral module UI inventory rather than merged into it — each generic descriptor is embedded untouched, so a standalone host never inherits Dashboard semantics. Reading needs the permission the inventory already needs; organizing needs the new platform permission `core.dashboard.navigation.manage` through a narrow, idempotent, closed-validation mutation contract. No editor UI. The flatness rule is executable: a test discovers real fixtures with a genuine dependency, arranges them four ways including both in one folder and the dependency inverted in presentation, and asserts discovery order, dependency declarations, and the module set stay byte-identical. The end-to-end test organizes a real installation through the real API, mounts a module from inside a group, moves it, and asserts the navigation entry is byte-identical across the move and still mounts the same artifact. The shell's client for the generic inventory became dead code and was removed rather than kept speculatively; the endpoint itself is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
151 lines
6.1 KiB
TypeScript
151 lines
6.1 KiB
TypeScript
import { parsePermissionId } from "@ekklesia/contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
CORE_AUTHORIZATION_GRANTS_MANAGE,
|
|
CORE_DASHBOARD_NAVIGATION_MANAGE,
|
|
CORE_MODULES_UI_READ,
|
|
CORE_PERMISSION_DECLARATIONS,
|
|
CORE_PERMISSION_REGISTRY,
|
|
createPermissionRegistry,
|
|
PermissionRegistryError,
|
|
} from "../src/authorization/index.js";
|
|
|
|
describe("createPermissionRegistry", () => {
|
|
it("builds an immutable registry from a fixed declaration list", () => {
|
|
const id = parsePermissionId("test.example.read");
|
|
const registry = createPermissionRegistry([
|
|
{ baseline: "public", description: "An example permission.", id },
|
|
]);
|
|
|
|
expect(registry.has(id)).toBe(true);
|
|
expect(registry.get(id)).toEqual({
|
|
baseline: "public",
|
|
description: "An example permission.",
|
|
id,
|
|
});
|
|
expect(Object.isFrozen(registry)).toBe(true);
|
|
expect(Object.isFrozen(registry.declarations)).toBe(true);
|
|
expect(Object.isFrozen(registry.get(id))).toBe(true);
|
|
});
|
|
|
|
it("rejects a duplicate permission id at composition time, not per request", () => {
|
|
const id = parsePermissionId("test.example.read");
|
|
expect(() =>
|
|
createPermissionRegistry([
|
|
{ baseline: "public", description: "First.", id },
|
|
{ baseline: "restricted", description: "Second.", id },
|
|
]),
|
|
).toThrow(PermissionRegistryError);
|
|
});
|
|
|
|
it("carries the offending permission id on the duplicate-declaration error (a composition-time, developer-facing detail, not a runtime response)", () => {
|
|
const id = parsePermissionId("test.example.read");
|
|
let captured: unknown;
|
|
try {
|
|
createPermissionRegistry([
|
|
{ baseline: "public", description: "First.", id },
|
|
{ baseline: "restricted", description: "Second.", id },
|
|
]);
|
|
} catch (error) {
|
|
captured = error;
|
|
}
|
|
expect(captured).toBeInstanceOf(PermissionRegistryError);
|
|
expect(captured).toMatchObject({
|
|
code: "PERMISSION_REGISTRY_DUPLICATE_DECLARATION",
|
|
permissionId: id,
|
|
});
|
|
});
|
|
|
|
it("treats an unregistered permission the same as a malformed one: get/has both fail closed", () => {
|
|
const registered = parsePermissionId("test.example.read");
|
|
const unregistered = parsePermissionId("test.example.unregistered");
|
|
const registry = createPermissionRegistry([
|
|
{ baseline: "public", description: "Registered.", id: registered },
|
|
]);
|
|
|
|
expect(registry.has(unregistered)).toBe(false);
|
|
expect(registry.get(unregistered)).toBeUndefined();
|
|
});
|
|
|
|
it("fails closed for a malformed permission id passed to get/has, without throwing", () => {
|
|
const registry = createPermissionRegistry([]);
|
|
|
|
expect(registry.has("not a valid permission")).toBe(false);
|
|
expect(registry.get(null)).toBeUndefined();
|
|
expect(registry.get(undefined)).toBeUndefined();
|
|
expect(registry.get(42)).toBeUndefined();
|
|
expect(registry.get("media.*")).toBeUndefined();
|
|
});
|
|
|
|
it("builds an empty registry from an empty list without error", () => {
|
|
const registry = createPermissionRegistry([]);
|
|
expect(registry.declarations).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("CORE_PERMISSION_REGISTRY", () => {
|
|
it("registers exactly core.authorization.grants.manage as restricted", () => {
|
|
const declaration = CORE_PERMISSION_REGISTRY.get(CORE_AUTHORIZATION_GRANTS_MANAGE);
|
|
expect(declaration).toBeDefined();
|
|
expect(declaration?.baseline).toBe("restricted");
|
|
expect(declaration?.id).toBe("core.authorization.grants.manage");
|
|
});
|
|
|
|
it("registers core.modules.ui.read as authenticated, not restricted", () => {
|
|
const declaration = CORE_PERMISSION_REGISTRY.get(CORE_MODULES_UI_READ);
|
|
expect(declaration).toBeDefined();
|
|
// Any signed-in user may learn which module UIs the browser host can mount; a shell that
|
|
// rendered nothing until an operator granted each user a permission would be unusable, and the
|
|
// module UIs gate their own content on their own permissions regardless (ADR 0026).
|
|
expect(declaration?.baseline).toBe("authenticated");
|
|
expect(declaration?.id).toBe("core.modules.ui.read");
|
|
});
|
|
|
|
it("registers core.dashboard.navigation.manage as restricted", () => {
|
|
const declaration = CORE_PERMISSION_REGISTRY.get(CORE_DASHBOARD_NAVIGATION_MANAGE);
|
|
expect(declaration).toBeDefined();
|
|
// Reorganizing the Dashboard is administrative, not something every signed-in user may do —
|
|
// unlike merely reading which module UIs exist (ADR 0027).
|
|
expect(declaration?.baseline).toBe("restricted");
|
|
expect(declaration?.id).toBe("core.dashboard.navigation.manage");
|
|
});
|
|
|
|
it("contains exactly these three permissions and no others", () => {
|
|
expect(CORE_PERMISSION_REGISTRY.declarations.map((declaration) => declaration.id)).toEqual([
|
|
CORE_AUTHORIZATION_GRANTS_MANAGE,
|
|
CORE_MODULES_UI_READ,
|
|
CORE_DASHBOARD_NAVIGATION_MANAGE,
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("CORE_PERMISSION_DECLARATIONS", () => {
|
|
it("is Core's own declaration list, exported separately from the registry in deeply immutable form", () => {
|
|
expect(CORE_PERMISSION_DECLARATIONS).toEqual([
|
|
{
|
|
baseline: "restricted",
|
|
description: "Create, list, and revoke another user's explicit authorization grants.",
|
|
id: CORE_AUTHORIZATION_GRANTS_MANAGE,
|
|
},
|
|
{
|
|
baseline: "authenticated",
|
|
description: "List the installed module UIs a browser host may mount.",
|
|
id: CORE_MODULES_UI_READ,
|
|
},
|
|
{
|
|
baseline: "restricted",
|
|
description: "Organize the Dashboard: create, rename, order, and delete navigation groups.",
|
|
id: CORE_DASHBOARD_NAVIGATION_MANAGE,
|
|
},
|
|
]);
|
|
expect(Object.isFrozen(CORE_PERMISSION_DECLARATIONS)).toBe(true);
|
|
expect(Object.isFrozen(CORE_PERMISSION_DECLARATIONS[0])).toBe(true);
|
|
expect(Object.isFrozen(CORE_PERMISSION_DECLARATIONS[1])).toBe(true);
|
|
expect(Object.isFrozen(CORE_PERMISSION_DECLARATIONS[2])).toBe(true);
|
|
});
|
|
|
|
it("matches exactly what CORE_PERMISSION_REGISTRY exposes as its own declarations, so a composer building on top of it never diverges from what Core itself registers", () => {
|
|
expect(CORE_PERMISSION_DECLARATIONS).toEqual(CORE_PERMISSION_REGISTRY.declarations);
|
|
});
|
|
});
|