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,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<string, unknown>);
await expect(
caller.export({ subjectId: "alice", format: "json" }),
).rejects.toThrow(/dsrRouter singleton/);
});
});