功能修改

This commit is contained in:
npc0-hue
2026-07-20 16:42:33 +08:00
parent 48b8ad8d6c
commit a0e69417db
224 changed files with 22015 additions and 884 deletions
@@ -0,0 +1,59 @@
import { describe, expect, it } from "vitest";
import { parseSafeClientManagerLifecycle, parseSafeClientManagerLifecycleList } from "./clientManagerLifecycle";
export const safeClientManagerLifecycleFixture = {
id: "client-manager-installation-1",
serverInstanceId: "server-1",
pluginId: "game.scum",
profileKey: "scum-client-manager",
targetOs: "windows",
targetArch: "amd64",
status: "online",
phase: "component heartbeat healthy",
desiredVersion: "2.0.0",
activeVersion: "2.0.0",
previousVersion: "1.0.0",
desiredRevision: "rev-2",
activeRevision: "rev-2",
previousRevision: "rev-1",
desiredArtifactId: "artifact-2",
activeArtifactId: "artifact-2",
previousArtifactId: "artifact-1",
keyGeneration: 3,
deploymentGeneration: 4,
currentJobId: "job-update-1",
lastSuccessfulJobId: "job-deploy-1",
lastOperation: "update",
health: "healthy",
healthReason: "component heartbeat healthy",
lastSeenAt: "2026-07-18T08:00:00Z",
retryable: false,
requiresRedeploy: false,
updatedAt: "2026-07-18T08:00:00Z",
distribution: { id: "distribution-2", artifactId: "artifact-2", sourceRevision: "rev-2", targetOs: "windows", targetArch: "amd64", checksum: `sha256:${"a".repeat(64)}`, keyGeneration: 3, status: "available" },
job: { id: "job-update-1", state: "running", progress: { percent: 65, message: "health confirmation" }, attempt: 1, createdAt: "2026-07-18T07:59:00Z", updatedAt: "2026-07-18T08:00:00Z" },
actions: [
{ operation: "start", available: false, reason: "already online" },
{ operation: "stop", available: true },
{ operation: "rollback", available: true }
]
} as const;
describe("Client Manager lifecycle schema", () => {
it("preserves safe lifecycle, job progress, versions and action availability", () => {
const parsed = parseSafeClientManagerLifecycle(safeClientManagerLifecycleFixture);
expect(parsed).toMatchObject({ status: "online", health: "healthy", activeVersion: "2.0.0", previousVersion: "1.0.0", job: { state: "running", progress: { percent: 65 } } });
expect(parseSafeClientManagerLifecycleList({ items: [safeClientManagerLifecycleFixture], count: 1 })).toMatchObject({ count: 1, items: [{ profileKey: "scum-client-manager" }] });
});
it.each([
{ runEndpointId: "run-private" },
{ pid: 4124 },
{ secretRef: "redacted" },
{ healthReason: "/Users/operator/client-manager" },
{ healthReason: "unix://private.sock" }
])("rejects machine and credential projection %#", (unsafe) => {
expect(() => parseSafeClientManagerLifecycle({ ...safeClientManagerLifecycleFixture, ...unsafe })).toThrow(/forbidden|sensitive/i);
});
});