test(core-dsr): cover dsrRouter singleton guard proxy path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 20:36:42 +00:00
parent 46e575a5a6
commit 6fd0a7ad4b
2 changed files with 34 additions and 21 deletions

View File

@@ -1,18 +1,18 @@
{ {
"generatedAt": "2026-05-19T20:12:30.651Z", "generatedAt": "2026-05-19T20:36:42.351Z",
"commit": "6606b59", "commit": "46e575a",
"repo": { "repo": {
"statements": 97.08, "statements": 97.17,
"branches": 92.03, "branches": 92.15,
"functions": 96.87, "functions": 96.93,
"lines": 97.08, "lines": 97.17,
"counts": { "counts": {
"lf": 5172, "lf": 5329,
"lh": 5021, "lh": 5178,
"brf": 1016, "brf": 1045,
"brh": 935, "brh": 963,
"fnf": 319, "fnf": 326,
"fnh": 309 "fnh": 316
} }
}, },
"byPackage": { "byPackage": {
@@ -74,16 +74,16 @@
}, },
"@repo/core-dsr": { "@repo/core-dsr": {
"statements": 100, "statements": 100,
"branches": 91.35, "branches": 92.48,
"functions": 96.88, "functions": 97.44,
"lines": 100, "lines": 100,
"counts": { "counts": {
"lf": 540, "lf": 697,
"lh": 540, "lh": 697,
"brf": 104, "brf": 133,
"brh": 95, "brh": 123,
"fnf": 32, "fnf": 39,
"fnh": 31 "fnh": 38
} }
}, },
"@repo/core-shared": { "@repo/core-shared": {

View File

@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from "vitest"; import { describe, it, expect, vi } from "vitest";
import { createDsrRouter } from "@/dsr.router"; import { createDsrRouter, dsrRouter } from "@/dsr.router";
import type { DsrTrpcUser } from "@/dsr.router"; import type { DsrTrpcUser } from "@/dsr.router";
import type { DsrBinding } from "@/di/bind-production"; import type { DsrBinding } from "@/di/bind-production";
import { import {
@@ -207,3 +207,16 @@ describe("dsrRouter.restrict", () => {
).rejects.toMatchObject({ code: "UNAUTHORIZED" }); ).rejects.toMatchObject({ code: "UNAUTHORIZED" });
}); });
}); });
describe("dsrRouter singleton guard", () => {
it("throws when procedures are called without a real DsrBinding", async () => {
// The singleton uses a Proxy that throws on any binding property access.
// Procedures access binding lazily, so the Proxy error surfaces at call time.
const caller = dsrRouter.createCaller({
user: authenticatedUser,
} as Record<string, unknown>);
await expect(
caller.export({ subjectId: "alice", format: "json" }),
).rejects.toThrow(/dsrRouter singleton/);
});
});