2026-07-14 23:47:30 +01:00
|
|
|
import test from "node:test";
|
|
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
|
One typed owner of document-payload reads and writes: DocumentPayload is opaque, the definition is required
DocumentPayload is an opaque object type over the same runtime Uint8Array, keyed by a string
property, and types CultCacheEnvelope.payload, CultNetRawDocumentRecord.payload and
CultMeshRealtimeFrame.payload. decodeDocumentPayload(definition, payload) and
encodeDocumentPayload(definition, value) are the only reader and writer; documentPayloadFromBytes
and documentPayloadBytes are the two named escapes at the edges where bytes enter and leave.
resolveDocumentFormatter leaves the package index. The cache, cultnet replication, the mesh read
paths, the provider command (now a CultCache document), and the browser's decodeCultNetPayload
(definition required, cultcache-ts/document entry) all go through the owner.
Compile-fail fixtures per payload-carrying package pin the type with expect-error lines.
check-typescript-tests-wired.mjs fails when a test file is run by no script; cultcache-ts now
runs dist-test/test/*.test.js, and the portability workflow runs the check and the cache suite.
Builds in every package (tsc, src and tests); the suites run once, at the end of the pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 19:33:42 +02:00
|
|
|
import { documentPayloadBytes, documentPayloadFromBytes, encodeDocumentPayload, type DocumentPayload } from "@gamecult/cultcache-ts";
|
|
|
|
|
import { encodeWireValue } from "cultnet-ts/wire";
|
|
|
|
|
|
2026-07-19 00:49:41 +01:00
|
|
|
import {
|
One typed owner of document-payload reads and writes: DocumentPayload is opaque, the definition is required
DocumentPayload is an opaque object type over the same runtime Uint8Array, keyed by a string
property, and types CultCacheEnvelope.payload, CultNetRawDocumentRecord.payload and
CultMeshRealtimeFrame.payload. decodeDocumentPayload(definition, payload) and
encodeDocumentPayload(definition, value) are the only reader and writer; documentPayloadFromBytes
and documentPayloadBytes are the two named escapes at the edges where bytes enter and leave.
resolveDocumentFormatter leaves the package index. The cache, cultnet replication, the mesh read
paths, the provider command (now a CultCache document), and the browser's decodeCultNetPayload
(definition required, cultcache-ts/document entry) all go through the owner.
Compile-fail fixtures per payload-carrying package pin the type with expect-error lines.
check-typescript-tests-wired.mjs fails when a test file is run by no script; cultcache-ts now
runs dist-test/test/*.test.js, and the portability workflow runs the check and the cache suite.
Builds in every package (tsc, src and tests); the suites run once, at the end of the pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 19:33:42 +02:00
|
|
|
cultMeshProviderSessionSchemas,
|
|
|
|
|
decodeProviderCommandDocument,
|
2026-07-19 00:49:41 +01:00
|
|
|
decodeProviderConnectEvidence,
|
|
|
|
|
encodeProviderConnectEvidence,
|
|
|
|
|
encodeProviderSessionPayload,
|
One typed owner of document-payload reads and writes: DocumentPayload is opaque, the definition is required
DocumentPayload is an opaque object type over the same runtime Uint8Array, keyed by a string
property, and types CultCacheEnvelope.payload, CultNetRawDocumentRecord.payload and
CultMeshRealtimeFrame.payload. decodeDocumentPayload(definition, payload) and
encodeDocumentPayload(definition, value) are the only reader and writer; documentPayloadFromBytes
and documentPayloadBytes are the two named escapes at the edges where bytes enter and leave.
resolveDocumentFormatter leaves the package index. The cache, cultnet replication, the mesh read
paths, the provider command (now a CultCache document), and the browser's decodeCultNetPayload
(definition required, cultcache-ts/document entry) all go through the owner.
Compile-fail fixtures per payload-carrying package pin the type with expect-error lines.
check-typescript-tests-wired.mjs fails when a test file is run by no script; cultcache-ts now
runs dist-test/test/*.test.js, and the portability workflow runs the check and the cache suite.
Builds in every package (tsc, src and tests); the suites run once, at the end of the pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 19:33:42 +02:00
|
|
|
providerCommandDocument,
|
2026-07-19 00:49:41 +01:00
|
|
|
} from "../src/provider-session-wire";
|
2026-07-14 23:47:30 +01:00
|
|
|
|
|
|
|
|
const REGISTRATION_GOLDEN = "hqpwcm92aWRlcklkqGFldGhlcmlhsXNlcnZpY2VJbnN0YW5jZUlkq2FldGhlcmlhLTQyqmVuZHBvaW50SWSvYWV0aGVyaWEtcHVibGljp3ZlcnNlSWSmcHVibGljuHJlcXVlc3RlZExlYXNlRHVyYXRpb25Nc811MLBhdXRob3JpdHlMZWFzZUlkq2F1dGhvcml0eS03";
|
2026-07-19 00:49:41 +01:00
|
|
|
const CONNECT_EVIDENCE_GOLDEN = "gq9jbGllbnRTZXNzaW9uSWSyYWV0aGVyaWEtY2xpZW50LTQyrHNlc3Npb25Ub2tlbrJvZGluLXNlc3Npb24tdG9rZW4=";
|
|
|
|
|
const TOKENLESS_CONNECT_EVIDENCE_GOLDEN = "gq9jbGllbnRTZXNzaW9uSWSyYWV0aGVyaWEtY2xpZW50LTQyrHNlc3Npb25Ub2tlbsA=";
|
2026-07-14 23:47:30 +01:00
|
|
|
|
|
|
|
|
test("provider registration matches the shared C# MessagePack golden payload", () => {
|
|
|
|
|
assert.equal(encodeProviderSessionPayload({
|
|
|
|
|
providerId: "aetheria",
|
|
|
|
|
serviceInstanceId: "aetheria-42",
|
|
|
|
|
endpointId: "aetheria-public",
|
|
|
|
|
verseId: "public",
|
|
|
|
|
requestedLeaseDurationMs: 30_000,
|
|
|
|
|
authorityLeaseId: "authority-7",
|
|
|
|
|
}), REGISTRATION_GOLDEN);
|
|
|
|
|
});
|
2026-07-19 00:49:41 +01:00
|
|
|
|
|
|
|
|
test("provider Connect evidence keeps transport generation separate from authority", () => {
|
|
|
|
|
const evidence = {
|
|
|
|
|
clientSessionId: "aetheria-client-42",
|
|
|
|
|
sessionToken: "odin-session-token",
|
|
|
|
|
};
|
|
|
|
|
const encoded = encodeProviderConnectEvidence(evidence);
|
|
|
|
|
assert.equal(Buffer.from(encoded).toString("base64"), CONNECT_EVIDENCE_GOLDEN);
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
decodeProviderConnectEvidence(encoded),
|
|
|
|
|
evidence,
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
Buffer.from(encodeProviderConnectEvidence({
|
|
|
|
|
clientSessionId: "aetheria-client-42",
|
|
|
|
|
sessionToken: null,
|
|
|
|
|
})).toString("base64"),
|
|
|
|
|
TOKENLESS_CONNECT_EVIDENCE_GOLDEN,
|
|
|
|
|
);
|
|
|
|
|
});
|
One typed owner of document-payload reads and writes: DocumentPayload is opaque, the definition is required
DocumentPayload is an opaque object type over the same runtime Uint8Array, keyed by a string
property, and types CultCacheEnvelope.payload, CultNetRawDocumentRecord.payload and
CultMeshRealtimeFrame.payload. decodeDocumentPayload(definition, payload) and
encodeDocumentPayload(definition, value) are the only reader and writer; documentPayloadFromBytes
and documentPayloadBytes are the two named escapes at the edges where bytes enter and leave.
resolveDocumentFormatter leaves the package index. The cache, cultnet replication, the mesh read
paths, the provider command (now a CultCache document), and the browser's decodeCultNetPayload
(definition required, cultcache-ts/document entry) all go through the owner.
Compile-fail fixtures per payload-carrying package pin the type with expect-error lines.
check-typescript-tests-wired.mjs fails when a test file is run by no script; cultcache-ts now
runs dist-test/test/*.test.js, and the portability workflow runs the check and the cache suite.
Builds in every package (tsc, src and tests); the suites run once, at the end of the pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 19:33:42 +02:00
|
|
|
|
|
|
|
|
test("a provider command is a CultCache document: written and read by its definition, and a refusal names no value", () => {
|
|
|
|
|
const command = { commandId: "c1", commandKind: "k", providerId: "p", serviceInstanceId: "s", payload: { n: 1 } };
|
|
|
|
|
const payload = encodeDocumentPayload(providerCommandDocument, command);
|
|
|
|
|
assert.deepEqual(documentPayloadBytes(payload), encodeWireValue(command), "the wire bytes are the plain map they always were");
|
|
|
|
|
const record = (bytes: DocumentPayload) => ({
|
|
|
|
|
schemaId: cultMeshProviderSessionSchemas.command, recordKey: "p/s/c1", storedAt: "2026-10-11T00:00:00Z",
|
|
|
|
|
payloadEncoding: "messagepack" as const, payload: bytes,
|
|
|
|
|
});
|
|
|
|
|
assert.deepEqual(decodeProviderCommandDocument(record(payload)), command);
|
|
|
|
|
|
|
|
|
|
const refused = documentPayloadFromBytes(encodeWireValue({ ...command, providerId: "canary-provider-5d2e", commandKind: "" }));
|
|
|
|
|
assert.throws(
|
|
|
|
|
() => decodeProviderCommandDocument(record(refused)),
|
|
|
|
|
(error: Error) => /commandKind/.test(error.message) && !error.message.includes("canary-provider-5d2e"),
|
|
|
|
|
);
|
|
|
|
|
assert.throws(() => encodeDocumentPayload(providerCommandDocument, { ...command, commandId: " " }), /commandId/);
|
|
|
|
|
});
|
2026-10-11 19:51:08 +02:00
|
|
|
|
|
|
|
|
test("a provider command that is not a map, or lacks a required field, is refused naming the field and none of its values", () => {
|
|
|
|
|
const command = { commandId: "c1", commandKind: "k", providerId: "p", serviceInstanceId: "s", payload: 1 };
|
|
|
|
|
const record = (value: unknown) => ({
|
|
|
|
|
schemaId: cultMeshProviderSessionSchemas.command, recordKey: "p/s/c1", storedAt: "2026-10-11T00:00:00Z",
|
|
|
|
|
payloadEncoding: "messagepack" as const, payload: documentPayloadFromBytes(encodeWireValue(value)),
|
|
|
|
|
});
|
|
|
|
|
for (const field of ["commandId", "commandKind", "providerId", "serviceInstanceId"] as const) {
|
|
|
|
|
assert.throws(
|
|
|
|
|
() => decodeProviderCommandDocument(record({ ...command, [field]: "" })),
|
|
|
|
|
(error: Error) => error.message === `CultMesh provider-session ${field} must be non-empty.`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
assert.throws(
|
|
|
|
|
() => decodeProviderCommandDocument(record(["canary-not-a-map"])),
|
|
|
|
|
(error: Error) => error.message === "CultMesh provider command must be a MessagePack map.",
|
|
|
|
|
);
|
|
|
|
|
});
|