scopedServicePortPayload.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { describe, expect, it } from "vitest";
  2. import { scopedServicePortPayloadSchema } from "../src/validation.js";
  3. const validPayload = {
  4. attachmentId: "attachment-project",
  5. sessionId: "project-session",
  6. target: { kind: "docker", container: "dev" } as const,
  7. sourceServerId: "source-1",
  8. workspacePath: "/remote/project",
  9. workspaceIdentity: "remote:server:source-1:/remote/project",
  10. workspacePurpose: "project" as const,
  11. };
  12. describe("scopedServicePortPayloadSchema", () => {
  13. it("保留完整 remote workspace scope", () => {
  14. expect(scopedServicePortPayloadSchema.parse(validPayload)).toEqual(validPayload);
  15. });
  16. it("拒绝缺失 scope 或携带未知字段的 payload", () => {
  17. const { workspaceIdentity: _workspaceIdentity, ...missingScope } = validPayload;
  18. expect(scopedServicePortPayloadSchema.safeParse(missingScope).success).toBe(false);
  19. expect(
  20. scopedServicePortPayloadSchema.safeParse({
  21. ...validPayload,
  22. unexpectedScope: "remote:server:other:/remote/project",
  23. }).success,
  24. ).toBe(false);
  25. });
  26. });