Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/**
* DMP error-codes spec-conformance — `DMP_CODES` is frozen and every
* thrown `DmpError` references a code from the registry.
*/
import { describe, expect, it } from "@suaveplan/testing/runner";
import { DMP_CODES, DmpError } from "../src/index.js";
describe("DMP_CODES is frozen", () => {
it("DMP_CODES is frozen", { timeout: 5000 }, () => {
expect(Object.isFrozen(DMP_CODES)).toBe(true);
});
it("every value is namespaced under DMP.", { timeout: 5000 }, () => {
for (const v of Object.values(DMP_CODES)) {
expect(v).toMatch(/^DMP\./);
}
});
it("every code can construct a DmpError that preserves it", {
timeout: 5000,
}, () => {
for (const code of Object.values(DMP_CODES)) {
const e = new DmpError(code, "ok");
expect(e.code).toBe(code);
}
});
it("registry contains the codes the codecs/trust modules throw", {
timeout: 5000,
}, () => {
const expected = [
"EMPTY_REQUEST",
"UNKNOWN_REQUEST_KIND",
"MAX_CHUNKS_EXCEEDED",
"BITSET_LENGTH_MISMATCH",
"BITSET_PADDING_NONZERO",
"UNORDERED_RESPONSE",
"GENERATION_STALE",
"CODEC_MISMATCH",
"ENVELOPE_MALFORMED",
"THROTTLE_EXCEEDED",
] as const;
for (const k of expected) {
expect(DMP_CODES).toHaveProperty(k);
}
});
});