-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(webapp,rbac): REQUIRE_PLUGINS=1 fail-fast for required plugin loads [TRI-9852] #3734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matt-aitken
wants to merge
5
commits into
main
Choose a base branch
from
feature/require-plugins-fail-fast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e004b36
feat(webapp,rbac): REQUIRE_PLUGINS=1 fail-fast for required plugin loads
matt-aitken b37e712
test(rbac): cover REQUIRE_PLUGINS fail-fast paths in the lazy controller
matt-aitken 11efcd3
test(webapp): e2e verify /healthcheck returns 500 with REQUIRE_PLUGINS=1
matt-aitken b0f944c
fix(rbac,testcontainers): make e2e healthcheck-require-plugins actual…
matt-aitken 39fb313
fix(webapp): close two bypass paths around the REQUIRE_PLUGINS health…
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Add `REQUIRE_PLUGINS=1` env var. When set, the RBAC plugin loader throws instead of silently falling back to the default implementation if the plugin module fails to load (missing, broken transitive dep, etc.). The webapp's `/healthcheck` route now resolves the lazy plugin controller so the throw surfaces during readiness probes — a deploy where the plugin didn't load fails the probe and is rolled back. | ||
|
|
||
| Self-hosters leave `REQUIRE_PLUGINS` unset and continue to use the fallback when no plugin is installed. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * E2E verification that REQUIRE_PLUGINS=1 fails the rollout via /healthcheck. | ||
| * | ||
| * The unit tests in @trigger.dev/rbac cover the loader throw. This file | ||
| * closes the loop end-to-end: spawn a real webapp, hit /healthcheck via | ||
| * HTTP, and verify the route's catch turns the throw into a 500 — the | ||
| * status the ECS/k8s readiness probe rolls back on. | ||
| * | ||
| * Each case spawns its own webapp + Postgres + Redis container (~30s) so | ||
| * env can differ per case. Slow but isolated, matching api-auth.e2e.test.ts. | ||
| * | ||
| * Requires a pre-built webapp: pnpm run build --filter webapp | ||
| * | ||
| * The REQUIRE_PLUGINS=1 case relies on the plugin NOT being resolvable | ||
| * from the spawned webapp. CI satisfies this because the plugin isn't in | ||
| * pnpm-lock.yaml. Local devs who ran `pnpm dev:link-webapp` have the | ||
| * plugin symlinked into apps/webapp/node_modules — that case is detected | ||
| * and skipped below. | ||
| */ | ||
| import { existsSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; | ||
| import type { TestServer } from "@internal/testcontainers/webapp"; | ||
| import { startTestServer } from "@internal/testcontainers/webapp"; | ||
|
|
||
| const LINKED_PLUGIN_PATH = resolve( | ||
| __dirname, | ||
| "..", | ||
| "node_modules", | ||
| "@triggerdotdev", | ||
| "plugins" | ||
| ); | ||
| const pluginLocallyLinked = existsSync(LINKED_PLUGIN_PATH); | ||
|
|
||
| vi.setConfig({ testTimeout: 180_000 }); | ||
|
|
||
| describe("/healthcheck with REQUIRE_PLUGINS", () => { | ||
| describe.skipIf(pluginLocallyLinked)("REQUIRE_PLUGINS=1 + plugin missing", () => { | ||
| let server: TestServer; | ||
|
|
||
| beforeAll(async () => { | ||
| // requirePlugins: true implies forceRbacFallback: false, so the | ||
| // loader actually tries to dynamic-import the plugin. The plugin | ||
| // is not installed in this OSS repo, so the import fails and the | ||
| // loader throws (instead of falling back) because REQUIRE_PLUGINS=1. | ||
| // The throw surfaces on the first .isUsingPlugin() call from the | ||
| // /healthcheck route, which catches it and returns 500. | ||
| server = await startTestServer({ requirePlugins: true }); | ||
| }, 180_000); | ||
|
|
||
| afterAll(async () => { | ||
| await server?.stop(); | ||
| }, 120_000); | ||
|
|
||
| it("returns 500 so the readiness probe fails and the rollout is rolled back", async () => { | ||
| const res = await server.webapp.fetch("/healthcheck"); | ||
| expect(res.status).toBe(500); | ||
| expect(await res.text()).toBe("ERROR"); | ||
| }); | ||
| }); | ||
|
|
||
| // Surface the skip in dev so it doesn't go unnoticed. CI hits the real test above. | ||
| describe.runIf(pluginLocallyLinked)( | ||
| "REQUIRE_PLUGINS=1 + plugin LOCALLY LINKED (cross-repo dev setup)", | ||
| () => { | ||
| it.skip( | ||
| `skipped because ${LINKED_PLUGIN_PATH} exists — plugin would load successfully. Run \`pnpm dev:unlink-webapp\` to exercise this case locally; CI runs it without the link.`, | ||
| () => {} | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| describe("REQUIRE_PLUGINS unset + plugin missing", () => { | ||
| let server: TestServer; | ||
|
|
||
| beforeAll(async () => { | ||
| // Default: forceRbacFallback=true so the loader short-circuits to | ||
| // the fallback without trying to import. /healthcheck succeeds. | ||
| server = await startTestServer(); | ||
| }, 180_000); | ||
|
|
||
| afterAll(async () => { | ||
| await server?.stop(); | ||
| }, 120_000); | ||
|
|
||
| it("returns 200 (baseline — unchanged self-hoster behaviour)", async () => { | ||
| const res = await server.webapp.fetch("/healthcheck"); | ||
| expect(res.status).toBe(200); | ||
| expect(await res.text()).toBe("OK"); | ||
| }); | ||
| }); | ||
| }); |
|
devin-ai-integration[bot] marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type { PrismaClient } from "@trigger.dev/database"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import loader from "./index.js"; | ||
|
|
||
| // The plugin module `@triggerdotdev/plugins/rbac` is not installed in this | ||
| // repo (it lives in the cloud monorepo), so a real dynamic import inside | ||
| // the loader will reliably fail with ERR_MODULE_NOT_FOUND. These tests | ||
| // exercise the loader's branching on that natural failure — no module | ||
| // mocking required. | ||
|
|
||
| // The fallback's isUsingPlugin() returns false synchronously without | ||
| // touching prisma, so a placeholder client is fine for tests that only | ||
| // drive the loader path. | ||
| const prismaPlaceholder = {} as unknown as PrismaClient; | ||
|
|
||
| describe("LazyController plugin loading", () => { | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it("falls back silently when REQUIRE_PLUGINS is unset and the plugin is missing", async () => { | ||
| vi.stubEnv("REQUIRE_PLUGINS", ""); | ||
| const controller = loader.create(prismaPlaceholder); | ||
| await expect(controller.isUsingPlugin()).resolves.toBe(false); | ||
| }); | ||
|
|
||
| it("throws when REQUIRE_PLUGINS=1 and the plugin is missing", async () => { | ||
| vi.stubEnv("REQUIRE_PLUGINS", "1"); | ||
| const controller = loader.create(prismaPlaceholder); | ||
| await expect(controller.isUsingPlugin()).rejects.toThrow(/REQUIRE_PLUGINS=1/); | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it("forceFallback wins over REQUIRE_PLUGINS=1 (so tests inheriting the env aren't broken)", async () => { | ||
| vi.stubEnv("REQUIRE_PLUGINS", "1"); | ||
| const controller = loader.create(prismaPlaceholder, { forceFallback: true }); | ||
| await expect(controller.isUsingPlugin()).resolves.toBe(false); | ||
| }); | ||
|
|
||
| it("treats any non-'1' REQUIRE_PLUGINS value as unset (must be exactly '1' to enforce)", async () => { | ||
| vi.stubEnv("REQUIRE_PLUGINS", "true"); | ||
| const controller = loader.create(prismaPlaceholder); | ||
| await expect(controller.isUsingPlugin()).resolves.toBe(false); | ||
| }); | ||
| }); | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
matt-aitken marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.