feat(housekeeping): deliver system vertical

This commit is contained in:
Simo committed 2026-08-28 23:31:47 +02:00
1 parent 0117b45d74
commit 3788ecd9f1
33 files changed
+4548 -423

No files matched your search

@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { z } from "zod";
import { SYSTEM_COMMAND_IDS } from "../../domains/system/commands/system-commands";
import { anyCapability, ok } from "../contracts";
import {
defineHousekeepingCommands,
@@ -7,6 +8,7 @@ import {
registerHousekeepingCommands,
} from "./bootstrap";
import {
getHousekeepingCommand,
type HousekeepingCommand,
registerHousekeepingCommand,
} from "./registry";
@@ -55,6 +57,9 @@ describe("housekeeping command bootstrap", () => {
});
it("registers the complete current list and seals during module initialization", () => {
expect(housekeepingCommandRegistryReady).toBe(true);
expect(
SYSTEM_COMMAND_IDS.map((id) => getHousekeepingCommand(id)?.id),
).toEqual(SYSTEM_COMMAND_IDS);
expect(() =>
registerHousekeepingCommand({
id: "system.bootstrap.too-late",
@@ -1,5 +1,6 @@
import "server-only";
import { SYSTEM_COMMANDS } from "../../domains/system/commands/system-commands";
import type { HousekeepingCommand } from "./registry";
import {
registerHousekeepingCommand,
@@ -34,7 +35,9 @@ export function registerHousekeepingCommands<
}
}
const currentHousekeepingCommands = defineHousekeepingCommands();
const currentHousekeepingCommands = defineHousekeepingCommands(
...SYSTEM_COMMANDS,
);
registerHousekeepingCommands(currentHousekeepingCommands);
sealHousekeepingCommandRegistry();
@@ -4,6 +4,7 @@ import { join, posix } from "node:path";
import { createElement, type ReactElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { SYSTEM_ROUTE_IDS } from "../domains/system/routes";
import { HOUSEKEEPING_MANIFESTS } from "../manifests";
import { discoverLegacyPages } from "../migration/discover-legacy-pages";
import { HOUSEKEEPING_MIGRATION_MATRIX } from "../migration/matrix";
@@ -17,6 +18,81 @@ const SERVER_CAPABILITY_CONTEXT =
"src/features/housekeeping/foundation/server-capability-context.ts";
const PERMISSIONS_ADAPTER = "src/lib/permissions";
const DOMAIN_MODULE_ROOT = "src/features/housekeeping/domains";
const approvedSystemRuntimeImports = new Map<string, ReadonlySet<string>>([
[
"src/features/housekeeping/domains/system/commands/system-commands.ts",
new Set(["src/features/housekeeping/domains/system/services/mutations"]),
],
[
"src/features/housekeeping/domains/system/pages/access.tsx",
new Set(["src/features/housekeeping/domains/system/queries/access"]),
],
[
"src/features/housekeeping/domains/system/pages/configuration.tsx",
new Set(["src/features/housekeeping/domains/system/queries/configuration"]),
],
[
"src/features/housekeeping/domains/system/pages/observability.tsx",
new Set(["src/features/housekeeping/domains/system/queries/observability"]),
],
[
"src/features/housekeeping/domains/system/pages/operations.tsx",
new Set(["src/features/housekeeping/domains/system/queries/operations"]),
],
[
"src/features/housekeeping/domains/system/queries/access.ts",
new Set(["src/lib/db", "drizzle-orm"]),
],
[
"src/features/housekeeping/domains/system/queries/configuration.ts",
new Set(["src/lib/db", "drizzle-orm"]),
],
[
"src/features/housekeeping/domains/system/queries/observability.ts",
new Set(["src/lib/db", "drizzle-orm"]),
],
[
"src/features/housekeeping/domains/system/queries/operations.ts",
new Set([
"src/features/housekeeping/domains/system/queries/observability",
"src/lib/db",
"drizzle-orm",
]),
],
[
"src/features/housekeeping/domains/system/services/mutations.ts",
new Set([
"src/app/admin/settings/cms-settings-config",
"src/lib/db",
"drizzle-orm",
"mysql2",
]),
],
[
"src/features/housekeeping/domains/system/manifest.ts",
new Set(["src/features/housekeeping/domains/system/routes"]),
],
[
"src/features/housekeeping/domains/system/route-handlers.ts",
new Set([
"src/features/housekeeping/domains/system/pages/access",
"src/features/housekeeping/domains/system/pages/configuration",
"src/features/housekeeping/domains/system/pages/observability",
"src/features/housekeeping/domains/system/pages/operations",
"src/features/housekeeping/domains/system/routes",
]),
],
[
"src/features/housekeeping/foundation/commands/bootstrap.ts",
new Set([
"src/features/housekeeping/domains/system/commands/system-commands",
]),
],
[
"src/features/housekeeping/route-handlers.ts",
new Set(["src/features/housekeeping/domains/system/route-handlers"]),
],
]);
const forbiddenModuleRoots = [
"src/lib/db",
"src/lib/db-pool",
@@ -358,6 +434,17 @@ function isAllowedPermissionSetTypeImport(
);
}
function isApprovedSystemRuntimeImport(
canonical: CanonicalModuleSpecifier,
sourceFile: string,
): boolean {
const allowed = approvedSystemRuntimeImports.get(sourceFile);
return (
allowed !== undefined &&
canonical.candidates.some((candidate) => allowed.has(candidate))
);
}
function findHousekeepingImportBoundaryViolations(
source: string,
sourceFile: string,
@@ -370,6 +457,7 @@ function findHousekeepingImportBoundaryViolations(
if (canonical.violation) violations.push(canonical.violation);
if (isAllowedPermissionSetTypeImport(access, canonical, sourceFile))
continue;
if (isApprovedSystemRuntimeImport(canonical, sourceFile)) continue;
const forbiddenPath = canonical.candidates.find((candidate) =>
isForbiddenModulePath(candidate, sourceFile),
);
@@ -398,6 +486,33 @@ describe("housekeeping runtime import boundary", () => {
}
});
it("allows only the approved System vertical runtime edges", () => {
expect(
findHousekeepingImportBoundaryViolations(
'import { systemMutationService } from "../services/mutations";',
"src/features/housekeeping/domains/system/commands/system-commands.ts",
),
).toEqual([]);
expect(
findHousekeepingImportBoundaryViolations(
'import { db } from "@/lib/db";',
"src/features/housekeeping/domains/system/queries/access.ts",
),
).toEqual([]);
expect(
findHousekeepingImportBoundaryViolations(
'import { db } from "@/lib/db";',
"src/features/housekeeping/domains/system/commands/system-commands.ts",
),
).toEqual(["src/lib/db"]);
expect(
findHousekeepingImportBoundaryViolations(
'import service from "../system/services/mutations";',
"src/features/housekeeping/domains/people/manifest.ts",
),
).toEqual(["src/features/housekeeping/domains/system/services/mutations"]);
});
it.each([
[
"aliased database import",
@@ -561,7 +676,7 @@ describe("housekeeping foundation completion contracts", () => {
}
});
it("creates the real six-domain registry in locked order without workflows", () => {
it("creates the real six-domain registry with only the System routes enabled", () => {
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
expect(registry.domains.map((domain) => domain.id)).toEqual([
@@ -572,9 +687,16 @@ describe("housekeeping foundation completion contracts", () => {
"hotel",
"system",
]);
expect(registry.domains.every((domain) => domain.routes.length === 0)).toBe(
true,
);
expect(
registry.domains
.filter((domain) => domain.id !== "system")
.every((domain) => domain.routes.length === 0),
).toBe(true);
expect(
registry.domains
.find((domain) => domain.id === "system")
?.routes.map((route) => route.id),
).toEqual(SYSTEM_ROUTE_IDS);
});
it("keeps production preview disabled even when the flag is true", () => {
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { PERMS } from "@/lib/permission-slugs";
import { SYSTEM_ROUTES } from "../domains/system/routes";
import { HOUSEKEEPING_MANIFESTS } from "../manifests";
import { HOUSEKEEPING_MIGRATION_MATRIX } from "../migration/matrix";
import {
@@ -353,7 +354,9 @@ describe("housekeeping registry", () => {
labelKey: expected.labelKey,
descriptionKey: expected.descriptionKey,
});
expect(actual.routes).toEqual([]);
expect(actual.routes).toEqual(
expected.id === "system" ? SYSTEM_ROUTES : [],
);
expect(actual.searchProviders).toEqual([]);
expect(actual.inboxSources).toEqual([]);
expect(actual.widgets).toEqual([]);