From 6fd0a7ad4b3764c0f5c9f8a4513ad0f06e14d3d4 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Tue, 19 May 2026 20:36:42 +0000 Subject: [PATCH] test(core-dsr): cover dsrRouter singleton guard proxy path Co-Authored-By: Claude Sonnet 4.6 --- coverage/summary.json | 40 +++++++++---------- .../core-dsr/src/__tests__/dsr.router.test.ts | 15 ++++++- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/coverage/summary.json b/coverage/summary.json index b95c1ef..ab19ffe 100644 --- a/coverage/summary.json +++ b/coverage/summary.json @@ -1,18 +1,18 @@ { - "generatedAt": "2026-05-19T20:12:30.651Z", - "commit": "6606b59", + "generatedAt": "2026-05-19T20:36:42.351Z", + "commit": "46e575a", "repo": { - "statements": 97.08, - "branches": 92.03, - "functions": 96.87, - "lines": 97.08, + "statements": 97.17, + "branches": 92.15, + "functions": 96.93, + "lines": 97.17, "counts": { - "lf": 5172, - "lh": 5021, - "brf": 1016, - "brh": 935, - "fnf": 319, - "fnh": 309 + "lf": 5329, + "lh": 5178, + "brf": 1045, + "brh": 963, + "fnf": 326, + "fnh": 316 } }, "byPackage": { @@ -74,16 +74,16 @@ }, "@repo/core-dsr": { "statements": 100, - "branches": 91.35, - "functions": 96.88, + "branches": 92.48, + "functions": 97.44, "lines": 100, "counts": { - "lf": 540, - "lh": 540, - "brf": 104, - "brh": 95, - "fnf": 32, - "fnh": 31 + "lf": 697, + "lh": 697, + "brf": 133, + "brh": 123, + "fnf": 39, + "fnh": 38 } }, "@repo/core-shared": { diff --git a/packages/core-dsr/src/__tests__/dsr.router.test.ts b/packages/core-dsr/src/__tests__/dsr.router.test.ts index 1c8ef40..063642b 100644 --- a/packages/core-dsr/src/__tests__/dsr.router.test.ts +++ b/packages/core-dsr/src/__tests__/dsr.router.test.ts @@ -1,5 +1,5 @@ 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 { DsrBinding } from "@/di/bind-production"; import { @@ -207,3 +207,16 @@ describe("dsrRouter.restrict", () => { ).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); + await expect( + caller.export({ subjectId: "alice", format: "json" }), + ).rejects.toThrow(/dsrRouter singleton/); + }); +});