Stage 1 PR 7 (ADR 0063). A module becomes a first-class part of the Dashboard. - Manifest v9 = v8 plus optional `navigation`: a Lucide icon from the curated MODULE_NAVIGATION_ICONS set, and up to 12 primary pages (stable id, safe label, kebab-case path relative to the module root; no traversal, schemes, queries, duplicates, or nesting). Validated before activation. - Version 8 stays accepted beside version 9, each read strictly as itself (discriminated union); no released manifest is rewritten. The template moves to v9; the released Signage 0.1.5 manifest is a test fixture. - Real module routes: /<id> is the landing view, /<id>/<page> a declared page, anything beneath a page a module-owned detail route; anything else is not-found and mounts nothing. api/assets/display are never pages. - Sidebar: declared icons, pages nested under an open module, one aria-current, collapsed and drawer behaviour; v8 modules unchanged. - module-ui-sdk: ModuleUiHostContext.navigation (location, subscribe, navigate, link, settings), refusing anything outside the module's routes; undefined on the display host. Mount ABI unchanged. - Return-to-origin: one `?return=` carrier on Settings URLs, validated by parseReturnTarget and against running modules' declared routes; Settings Back returns to exactly the originating module page, across refreshes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
139 lines
4.3 KiB
TypeScript
139 lines
4.3 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { dashboardBack } from "../src/browser/dashboard-back.js";
|
|
import { createMemoryHostHistory } from "../src/browser/host-history.js";
|
|
import { parseReturnTarget } from "../src/return-target.js";
|
|
|
|
describe("parseReturnTarget", () => {
|
|
it("accepts a Dashboard page on this origin, as its canonical destination", () => {
|
|
expect(parseReturnTarget("/")).toEqual({ kind: "overview" });
|
|
expect(parseReturnTarget("/signage")).toEqual({
|
|
kind: "module",
|
|
moduleId: "signage",
|
|
path: "",
|
|
});
|
|
expect(parseReturnTarget("/signage/")).toEqual({
|
|
kind: "module",
|
|
moduleId: "signage",
|
|
path: "",
|
|
});
|
|
// Settings pages are Dashboard pages too (ADR 0061).
|
|
expect(parseReturnTarget("/settings")).toEqual({ kind: "settings" });
|
|
expect(parseReturnTarget("/settings/signage")).toEqual({
|
|
kind: "module-settings",
|
|
moduleId: "signage",
|
|
});
|
|
});
|
|
|
|
it("refuses anything that is not a string, or is empty or enormous", () => {
|
|
for (const value of [undefined, null, 42, {}, ["/signage"], "", `/${"a".repeat(3000)}`]) {
|
|
expect(parseReturnTarget(value), JSON.stringify(value)).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("refuses every way of naming another origin", () => {
|
|
for (const value of [
|
|
"https://evil.example/signage",
|
|
"http://localhost/signage",
|
|
"//evil.example/signage",
|
|
"/\\evil.example",
|
|
"\\\\evil.example",
|
|
"javascript:alert(1)",
|
|
"data:text/html,hi",
|
|
" /signage",
|
|
"/signage\n",
|
|
"/sign\tage",
|
|
"signage",
|
|
]) {
|
|
expect(parseReturnTarget(value), value).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("refuses traversal and encoded separators that would normalize into something else", () => {
|
|
for (const value of [
|
|
"/signage/../settings",
|
|
"/./signage",
|
|
"/signage/%2e%2e/api",
|
|
"/%2F%2Fevil.example",
|
|
"/%5Cevil.example",
|
|
"/signage%2Fx",
|
|
]) {
|
|
expect(parseReturnTarget(value), value).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("refuses a query or fragment, and any path the Dashboard has no page for", () => {
|
|
for (const value of [
|
|
"/signage?x=1",
|
|
"/signage#top",
|
|
"/api/v1/principal",
|
|
"/api/auth/sign-out",
|
|
"/assets/ekklesia-dashboard/app.js",
|
|
"/display/signage",
|
|
"/settings/displays/add",
|
|
"/signage//",
|
|
"/signage/a//b",
|
|
]) {
|
|
expect(parseReturnTarget(value), value).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("accepts a module's own deeper route, whose page the host then checks (ADR 0063)", () => {
|
|
expect(parseReturnTarget("/signage/timelines")).toEqual({
|
|
kind: "module",
|
|
moduleId: "signage",
|
|
path: "timelines",
|
|
});
|
|
expect(parseReturnTarget("/media/sermons/123")).toEqual({
|
|
kind: "module",
|
|
moduleId: "media",
|
|
path: "sermons/123",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("dashboardBack", () => {
|
|
it("goes back to a validated origin when one was supplied", () => {
|
|
const history = createMemoryHostHistory("/calendar");
|
|
const back = dashboardBack(history, {
|
|
fallback: { kind: "overview" },
|
|
label: (destination) => (destination.kind === "module" ? "Back to Signage" : "Back"),
|
|
returnTarget: "/signage",
|
|
});
|
|
|
|
expect(back.href).toBe("/signage");
|
|
expect(back.label).toBe("Back to Signage");
|
|
back.onBack();
|
|
expect(history.entries).toEqual(["/calendar", "/signage"]);
|
|
});
|
|
|
|
it("falls back to the page's own parent when the target is missing or unsafe", () => {
|
|
for (const returnTarget of [
|
|
undefined,
|
|
"https://evil.example/",
|
|
"//evil.example",
|
|
"/api/v1/principal",
|
|
"/signage//",
|
|
]) {
|
|
const history = createMemoryHostHistory("/calendar");
|
|
const back = dashboardBack(history, {
|
|
fallback: { kind: "overview" },
|
|
returnTarget,
|
|
});
|
|
expect(back.href, String(returnTarget)).toBe("/");
|
|
expect(back.label, String(returnTarget)).toBe("Back");
|
|
back.onBack();
|
|
expect(history.entries, String(returnTarget)).toEqual(["/calendar", "/"]);
|
|
}
|
|
});
|
|
|
|
it("never leaves the Dashboard through the browser's own history", () => {
|
|
const history = createMemoryHostHistory("/calendar");
|
|
const go = vi.spyOn(history, "go");
|
|
|
|
dashboardBack(history, { fallback: { kind: "overview" } }).onBack();
|
|
|
|
expect(go).not.toHaveBeenCalled();
|
|
});
|
|
});
|