Skip to content

Commit 1ce122a

Browse files
matt-aitkenclaude
andcommitted
test(rbac): cover REQUIRE_PLUGINS fail-fast paths in the lazy controller
Four tests in require-plugins.test.ts driving the loader's branching: - REQUIRE_PLUGINS unset + plugin missing → falls back (resolves false) - REQUIRE_PLUGINS=1 + plugin missing → rejects on first method call - forceFallback: true beats REQUIRE_PLUGINS=1 (test escape hatch) - Any non-"1" value of REQUIRE_PLUGINS is treated as unset The plugin module isn't installed in this OSS repo, so the dynamic import naturally fails with ERR_MODULE_NOT_FOUND — no module mocking needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4009d0f commit 1ce122a

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { PrismaClient } from "@trigger.dev/database";
2+
import { afterEach, describe, expect, it, vi } from "vitest";
3+
import loader from "./index.js";
4+
5+
// The plugin module `@triggerdotdev/plugins/rbac` is not installed in this
6+
// repo (it lives in the cloud monorepo), so a real dynamic import inside
7+
// the loader will reliably fail with ERR_MODULE_NOT_FOUND. These tests
8+
// exercise the loader's branching on that natural failure — no module
9+
// mocking required.
10+
11+
// The fallback's isUsingPlugin() returns false synchronously without
12+
// touching prisma, so a placeholder client is fine for tests that only
13+
// drive the loader path.
14+
const prismaPlaceholder = {} as unknown as PrismaClient;
15+
16+
describe("LazyController plugin loading", () => {
17+
afterEach(() => {
18+
vi.unstubAllEnvs();
19+
});
20+
21+
it("falls back silently when REQUIRE_PLUGINS is unset and the plugin is missing", async () => {
22+
vi.stubEnv("REQUIRE_PLUGINS", "");
23+
const controller = loader.create(prismaPlaceholder);
24+
await expect(controller.isUsingPlugin()).resolves.toBe(false);
25+
});
26+
27+
it("throws when REQUIRE_PLUGINS=1 and the plugin is missing", async () => {
28+
vi.stubEnv("REQUIRE_PLUGINS", "1");
29+
const controller = loader.create(prismaPlaceholder);
30+
await expect(controller.isUsingPlugin()).rejects.toThrow(/REQUIRE_PLUGINS=1/);
31+
});
32+
33+
it("forceFallback wins over REQUIRE_PLUGINS=1 (so tests inheriting the env aren't broken)", async () => {
34+
vi.stubEnv("REQUIRE_PLUGINS", "1");
35+
const controller = loader.create(prismaPlaceholder, { forceFallback: true });
36+
await expect(controller.isUsingPlugin()).resolves.toBe(false);
37+
});
38+
39+
it("treats any non-'1' REQUIRE_PLUGINS value as unset (must be exactly '1' to enforce)", async () => {
40+
vi.stubEnv("REQUIRE_PLUGINS", "true");
41+
const controller = loader.create(prismaPlaceholder);
42+
await expect(controller.isUsingPlugin()).resolves.toBe(false);
43+
});
44+
});

0 commit comments

Comments
 (0)