workspace-hook-trust-phase0.test.ts 973 B

123456789101112131415161718192021222324
  1. import { describe, expect, it } from "vitest";
  2. import { WORKSPACE_HOOK_SCHEMA_FIELDS } from "../../contracts/src/hooks/index.js";
  3. import {
  4. hookCommandSchema,
  5. hookMatcherSchema,
  6. hookProcessSchema,
  7. hooksSchema,
  8. } from "../src/config/schema.js";
  9. function schemaKeys(schema: { shape: Record<string, unknown> }): string[] {
  10. return Object.keys(schema.shape);
  11. }
  12. describe("workspace hook trust phase 0", () => {
  13. it("真实 Hook file schema 与 canonical exhaustive lock 保持一致", () => {
  14. expect(schemaKeys(hooksSchema)).toEqual(WORKSPACE_HOOK_SCHEMA_FIELDS.root);
  15. expect(schemaKeys(hookMatcherSchema)).toEqual(WORKSPACE_HOOK_SCHEMA_FIELDS.matcher);
  16. expect(schemaKeys(hooksSchema.shape.events.unwrap())).toEqual(
  17. WORKSPACE_HOOK_SCHEMA_FIELDS.events,
  18. );
  19. expect(schemaKeys(hookProcessSchema)).toEqual(WORKSPACE_HOOK_SCHEMA_FIELDS.process);
  20. expect(schemaKeys(hookCommandSchema)).toEqual(WORKSPACE_HOOK_SCHEMA_FIELDS.command);
  21. });
  22. });