cultnet-ts: refuse a write_admitted messageId without a letter or number or with a Default_Ignorable code point

Raw compare, no trim. The platform's regex property tables carry both properties; no table embedded.
D800 vector now driven from wireHex.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-09 14:42:01 +00:00
commit 4c1537885d
2 changed files with 18 additions and 3 deletions

View file

@ -950,6 +950,10 @@ export function parseCultNetMessage(input: unknown, wireContract: CultNetWireCon
return input as CultNetDatabaseChangeRawMessage;
}
if (schemaVersion === "cultnet.write_admitted.v0" && !isValidAdmittedMessageId((input as { messageId?: unknown }).messageId)) {
throw new Error("Validation failed for cultnet.write_admitted.v0: /messageId: must contain a letter or number and no Default_Ignorable code point");
}
if (!validator(input)) {
const keys = Object.keys(input as Record<string, unknown>).join(",");
throw new Error(`${renderValidationErrors(schemaVersion, validator)}; keys=${keys}`);
@ -1460,6 +1464,15 @@ function validateRawDocumentRecord(
requireOptionalStringArray(candidate.tags, `${instancePath}/tags`);
}
/**
* A write_admitted messageId is valid iff it holds a Unicode letter or number and no Default_Ignorable_Code_Point, compared raw
* (write-receipt.md; the id is echoed byte for byte, so nothing is trimmed). The platform's regex tables carry both properties,
* so this runtime embeds no table; the Kotlin, Python, C# and Rust decoders embed DerivedCoreProperties ranges.
*/
function isValidAdmittedMessageId(value: unknown): boolean {
return typeof value === "string" && /[\p{L}\p{N}]/u.test(value) && !/\p{Default_Ignorable_Code_Point}/u.test(value);
}
/** Blank is empty or only Unicode White_Space (write-receipt.md, rule 5), not `trim()`: JS trims U+FEFF and keeps U+0085. */
function isBlank(value: string): boolean {
return /^\p{White_Space}*$/u.test(value);

View file

@ -5,6 +5,7 @@ import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { decode } from "@msgpack/msgpack";
import {
CULTNET_ERROR_CODES,
CULTNET_ERROR_V1_CODES,
@ -282,17 +283,18 @@ test("a blank messageId, record key or tag is exactly Unicode White_Space, not t
});
// `admittedMessageId` vectors: a write_admitted messageId needs a letter or number and no Default_Ignorable code point,
// compared raw (never trimmed). JavaScript strings hold a lone surrogate, so the D800 vector is built from its code point.
// compared raw (never trimmed). The D800 vector is the frame's bytes (wireHex), decoded by the msgpack library like the others.
test("write_admitted messageId: every admittedMessageId vector is refused or accepted raw", () => {
const vectorsPath = join(__dirname, "..", "..", "..", "..", "contracts", "cultnet", "interop", "write-receipt-vectors.json");
const vectors = JSON.parse(readFileSync(vectorsPath, "utf8"));
assert.equal(vectors.counts.admittedMessageIdCases, vectors.admittedMessageId.cases.length);
const failures: string[] = [];
for (const vector of vectors.admittedMessageId.cases as { name: string; codePoints: string[]; repeat?: number; expect: "refuse" | "accept" }[]) {
for (const vector of vectors.admittedMessageId.cases as { name: string; codePoints: string[]; repeat?: number; wireHex?: string; expect: "refuse" | "accept" }[]) {
const id = vector.codePoints.map((cp) => String.fromCodePoint(parseInt(cp, 16))).join("").repeat(vector.repeat ?? 1);
let decodedId: string | undefined;
try {
decodedId = (parseCultNetMessage(admitted(id)) as CultNetWriteAdmittedMessage).messageId;
const frame = vector.wireHex ? decode(Uint8Array.from(Buffer.from(vector.wireHex, "hex"))) : admitted(id);
decodedId = (parseCultNetMessage(frame) as CultNetWriteAdmittedMessage).messageId;
} catch {
decodedId = undefined;
}