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,67 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { DMP_CODES, DmpError, type DmpErrorCode } from "../src/error-codes.js";
describe("@suaveplan/drive-mesh-protocol — DMP_CODES registry", () => {
it("is frozen", { timeout: 5000 }, () => {
expect(Object.isFrozen(DMP_CODES)).toBe(true);
});
it("every code value starts with the DMP. namespace", {
timeout: 5000,
}, () => {
for (const value of Object.values(DMP_CODES)) {
expect(value).toMatch(/^DMP\./);
}
});
it("includes every documented rejection path", { timeout: 5000 }, () => {
const expected = [
"EMPTY_REQUEST",
"UNKNOWN_REQUEST_KIND",
"MAX_CHUNKS_EXCEEDED",
"BITSET_LENGTH_MISMATCH",
"BITSET_PADDING_NONZERO",
"UNORDERED_RESPONSE",
"GENERATION_STALE",
"CODEC_MISMATCH",
] as const;
for (const key of expected) {
expect(DMP_CODES).toHaveProperty(key);
}
});
});
describe("@suaveplan/drive-mesh-protocol — DmpError class", () => {
it("preserves the code", { timeout: 5000 }, () => {
const err = new DmpError(DMP_CODES.EMPTY_REQUEST, "test message");
expect(err.code).toBe(DMP_CODES.EMPTY_REQUEST);
expect(err.message).toBe("test message");
});
it("threads cause and context through SuaveplanError options", {
timeout: 5000,
}, () => {
const cause = new Error("inner");
const err = new DmpError(
DMP_CODES.MAX_CHUNKS_EXCEEDED,
"cap exceeded",
{
cause,
context: { requested: 4096, allowed: 1024 },
}
);
expect(err.cause).toBe(cause);
expect(err.context).toEqual({ requested: 4096, allowed: 1024 });
});
it("permits all codes via DmpErrorCode union", { timeout: 5000 }, () => {
// Type-level check: every code is assignable to the discriminator.
const codes: DmpErrorCode[] = Object.values(DMP_CODES);
expect(codes.length).toBeGreaterThanOrEqual(8);
for (const code of codes) {
const err = new DmpError(code, "ok");
expect(err.code).toBe(code);
}
});
});