Files
pikasTech-unidesk/scripts/d601-host-compose-status-contract-test.ts
T
2026-06-10 19:45:43 +00:00

49 lines
3.7 KiB
TypeScript

import { readConfig } from "./src/config";
import { deprecatedD601HostComposeEntryForTest, type ComposeRuntimeEnv, type ContainerStatus } from "./src/docker";
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
}
const runtimeEnv: ComposeRuntimeEnv = {
envFile: "/home/ubuntu/workspace/unidesk-dev/.state/docker-compose.env",
logDir: "not-created-on-deprecated-d601-host-compose-entry",
logDay: "20260610",
logPrefix: "20260610_120000",
};
const config = readConfig();
const deprecated = deprecatedD601HostComposeEntryForTest(config, runtimeEnv, [], "/home/ubuntu/workspace/unidesk-dev");
assertCondition(deprecated?.ok === false, "D601 host compose entry should be a controlled failure", deprecated);
assertCondition(deprecated.error === "deprecated-host-compose-entry", "D601 host compose entry should expose the deprecation classifier", deprecated);
assertCondition(deprecated.runnerDisposition === "business-failed", "D601 host compose entry should be classified as business-failed", deprecated);
assertCondition(deprecated.decision.hostComposeRetained === false, "D601 host compose entry should be explicitly deprecated", deprecated.decision);
assertCondition(deprecated.correctEntrypoints.d601NativeK3s.includes("trans D601:k3s"), "D601 status should point to native k3s as the D601 acceptance entry", deprecated.correctEntrypoints);
assertCondition(deprecated.correctEntrypoints.mainServerStatus.includes("/root/unidesk"), "D601 status should point main-server compose checks at /root/unidesk", deprecated.correctEntrypoints);
assertCondition(deprecated.evidence.logDir === runtimeEnv.logDir, "D601 status should preserve repo-local runtime evidence", deprecated.evidence);
assertCondition(!JSON.stringify(deprecated).includes("/workspace/unidesk/logs"), "D601 status should not surface the stale /workspace/unidesk/logs permission path", deprecated);
assertCondition(deprecated.evidence.conflictingListeners.every((item) => item.expected === "ignored-on-deprecated-d601-host-compose-entry"), "D601 status should mark occupied public ports as ignored for this deprecated entry", deprecated.evidence.conflictingListeners);
const legacyOperatorPath = deprecatedD601HostComposeEntryForTest(config, runtimeEnv, [], "/home/ubuntu/unidesk");
assertCondition(legacyOperatorPath?.error === "deprecated-host-compose-entry", "legacy D601 operator checkout should receive the same deprecation classifier", legacyOperatorPath);
const staleWorkspacePath = deprecatedD601HostComposeEntryForTest(config, runtimeEnv, [], "/workspace/unidesk");
assertCondition(staleWorkspacePath?.error === "deprecated-host-compose-entry", "stale /workspace D601 checkout should be classified before log directory writes", staleWorkspacePath);
assertCondition(!JSON.stringify(staleWorkspacePath).includes("/workspace/unidesk/logs"), "stale /workspace D601 checkout should not surface the stale log permission path", staleWorkspacePath);
const canonicalMainServer = deprecatedD601HostComposeEntryForTest(config, runtimeEnv, [], "/root/unidesk");
assertCondition(canonicalMainServer === null, "canonical main-server checkout should keep the normal compose path", canonicalMainServer);
const existingContainer: ContainerStatus = {
id: "abc123",
name: "unidesk-backend-core",
image: "unidesk/backend-core:test",
status: "Up",
ports: "",
};
const activeCompose = deprecatedD601HostComposeEntryForTest(config, runtimeEnv, [existingContainer], "/home/ubuntu/workspace/unidesk-dev");
assertCondition(activeCompose === null, "D601 checkout with compose containers should keep the normal compose path", activeCompose);
console.log(JSON.stringify({ ok: true, contract: "d601-host-compose-status" }, null, 2));