test(app): R47 — bindAll instrumentation orthogonality matrix

Extends bind-production.test.ts with a vi.mock for @repo/core-shared/instrumentation
that wraps bindSentryInstrumentation and bindNoopInstrumentation in vi.fn (so call
counts are observable while real implementations still run). Adds 4 orthogonality
tests covering: DSN absent + production env, DSN set + dev env, Sentry + dev seed,
Noop + production — verifying instrumentation choice is independent of repo mode.
Total: 6 original + 4 new = 10 passing tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 00:04:26 +02:00
parent efacb0e072
commit 07e8b2e2e7

View File

@@ -11,6 +11,14 @@ vi.mock("@repo/auth/di/bind-dev-seed", () => ({ bindDevSeedAuth: vi.fn() }));
vi.mock("@repo/marketing-pages/di/bind-dev-seed", () => ({ bindDevSeedMarketingPages: vi.fn() }));
vi.mock("@repo/navigation/di/bind-dev-seed", () => ({ bindDevSeedNavigation: vi.fn() }));
vi.mock("@repo/media/di/bind-dev-seed", () => ({ bindDevSeedMedia: vi.fn() }));
vi.mock("@repo/core-shared/instrumentation", async (importOriginal) => {
const actual = await importOriginal<typeof import("@repo/core-shared/instrumentation")>();
return {
...actual,
bindSentryInstrumentation: vi.fn(actual.bindSentryInstrumentation),
bindNoopInstrumentation: vi.fn(actual.bindNoopInstrumentation),
};
});
describe("bindAllProduction", () => {
beforeEach(() => {
@@ -105,3 +113,69 @@ describe("bindAll dispatcher", () => {
expect(bindDevSeedBlog).not.toHaveBeenCalled();
});
});
describe("bindAll instrumentation orthogonality (Rule 0, R47)", () => {
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
vi.unstubAllEnvs();
});
afterEach(() => {
vi.unstubAllEnvs();
});
it("DSN absent → bindNoopInstrumentation regardless of NODE_ENV (R48)", async () => {
vi.stubEnv("WEB_NEXT_SENTRY_DSN", "");
vi.stubEnv("NODE_ENV", "production");
const { bindAll } = await import("./bind-production");
const { bindNoopInstrumentation, bindSentryInstrumentation } = await import(
"@repo/core-shared/instrumentation"
);
await bindAll();
expect(bindNoopInstrumentation).toHaveBeenCalledOnce();
expect(bindSentryInstrumentation).not.toHaveBeenCalled();
});
it("DSN set → bindSentryInstrumentation regardless of NODE_ENV", async () => {
vi.stubEnv("WEB_NEXT_SENTRY_DSN", "https://x@y/1");
vi.stubEnv("NODE_ENV", "development");
const { bindAll } = await import("./bind-production");
const { bindNoopInstrumentation, bindSentryInstrumentation } = await import(
"@repo/core-shared/instrumentation"
);
await bindAll();
expect(bindSentryInstrumentation).toHaveBeenCalledOnce();
expect(bindNoopInstrumentation).not.toHaveBeenCalled();
});
it("Sentry instrumentation works alongside dev seed (USE_DEV_SEED=true)", async () => {
vi.stubEnv("USE_DEV_SEED", "true");
vi.stubEnv("WEB_NEXT_SENTRY_DSN", "https://x@y/1");
const { bindAll } = await import("./bind-production");
const { bindSentryInstrumentation } = await import("@repo/core-shared/instrumentation");
const { bindDevSeedBlog } = await import("@repo/blog/di/bind-dev-seed");
await bindAll();
expect(bindSentryInstrumentation).toHaveBeenCalledOnce();
expect(bindDevSeedBlog).toHaveBeenCalledOnce();
});
it("Noop instrumentation works alongside production binding (DSN unset, NODE_ENV=production)", async () => {
vi.stubEnv("WEB_NEXT_SENTRY_DSN", "");
vi.stubEnv("NODE_ENV", "production");
const { bindAll } = await import("./bind-production");
const { bindNoopInstrumentation } = await import("@repo/core-shared/instrumentation");
const { bindProductionBlog } = await import("@repo/blog/di/bind-production");
await bindAll();
expect(bindNoopInstrumentation).toHaveBeenCalledOnce();
expect(bindProductionBlog).toHaveBeenCalledOnce();
});
});