test(core-dsr): cover dsrRouter singleton guard proxy path
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user