Files
crosscode-platform/packages/contracts/tests/samples.test.ts
T
joshuaandClaude Opus 5.5 90a98a4306 contracts 1.3.0: agent jobs, reports, stats, join/poll, env templates, church export
Jobs of fixed types with strict argument schemas, signed by the Hub with
Ed25519 over canonical JSON. Agent requests signed with the server's
Ed25519 key. Config sealed to the server's X25519 key (X25519 + HKDF +
AES-256-GCM; Node has no XSalsa20). Exports encrypted with a key that
only travels in the download link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:02:24 +02:00

58 lines
2.0 KiB
TypeScript

import { readdirSync } from "node:fs";
import type { z } from "zod";
import {
accountsCallSchema,
churchExportSchema,
churchSchema,
eventChangedSchema,
eventFeedSchema,
eventSchema,
hub,
identityClaimsSchema,
userDeletedReplySchema,
userExportReplySchema,
} from "../src";
import { SAMPLES, sample } from "./helpers";
/** Every sample file and the schema it must pass. A new sample without an entry fails the test. */
const SCHEMAS: Record<string, z.ZodType> = {
"event.json": eventSchema,
"event-simple.json": eventSchema,
"event-feed.json": eventFeedSchema,
"event-changed.json": eventChangedSchema,
"church.json": churchSchema,
"identity-claims.json": identityClaimsSchema,
"user-updated.json": accountsCallSchema,
"user-deleted.json": accountsCallSchema,
"user-deleted-reply.json": userDeletedReplySchema,
"user-export.json": accountsCallSchema,
"user-export-reply.json": userExportReplySchema,
"hub-register-request.json": hub.registerRequestSchema,
"hub-register-response.json": hub.registerResponseSchema,
"hub-heartbeat-events.json": hub.heartbeatRequestSchema,
"hub-heartbeat-website.json": hub.heartbeatRequestSchema,
"hub-heartbeat-app.json": hub.heartbeatRequestSchema,
"hub-heartbeat-accounts.json": hub.heartbeatRequestSchema,
"hub-heartbeat-response.json": hub.heartbeatResponseSchema,
"hub-licence-payload.json": hub.licencePayloadSchema,
"church-export.json": churchExportSchema,
};
describe("samples", () => {
const files = readdirSync(SAMPLES).filter((f) => f.endsWith(".json"));
it("every sample has a schema", () => {
expect(files.filter((f) => !(f in SCHEMAS))).toEqual([]);
});
it.each(Object.entries(SCHEMAS))("%s is valid", (file, schema) => {
const result = schema.safeParse(sample(file));
expect(result.success ? [] : result.error.issues).toEqual([]);
});
it.each(Object.entries(SCHEMAS))("%s keeps every field it sends (no field is silently dropped)", (file, schema) => {
const input = sample(file);
expect(schema.parse(input)).toEqual(input);
});
});