Skip to content

Commit f05bb7c

Browse files
committed
fix: gate eval routes behind eval-only flag and fix flue() ordering
1 parent 9874c46 commit f05bb7c

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

.flue/app.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ setProvider(
4444
type WebhookEnv = PipelineEnv & {
4545
GITHUB_WEBHOOK_SECRET?: string;
4646
DOCS_FLUE_INTERNAL_TOKEN?: string;
47+
DOCS_FLUE_ENABLE_EVAL_ROUTES?: string;
4748
};
4849

4950
const app = new Hono();
@@ -142,10 +143,11 @@ app.post("/webhooks/github", async (c) => {
142143

143144
// ── Eval routes ─────────────────────────────────────────────────────────────
144145
// Mount each reviewable agent behind a shared internal-token gate so
145-
// vitest-evals can drive them over HTTP during CI. The token reuses
146-
// DOCS_FLUE_INTERNAL_TOKEN (same gate as /dev/review/:number). Routes return
147-
// 404 when the token is unset so they are invisible in production deploys
148-
// that have not opted in.
146+
// vitest-evals can drive them over HTTP during CI. Requires both
147+
// DOCS_FLUE_ENABLE_EVAL_ROUTES=1 and DOCS_FLUE_INTERNAL_TOKEN to be set in
148+
// the Worker env. The Vite config only injects these during eval runs
149+
// (DOCS_FLUE_AGENT_EVALS=1), so eval routes are never live in production or
150+
// normal dev.
149151
const EVAL_AGENTS = [
150152
CodeReviewFile,
151153
StyleGuideFile,
@@ -156,6 +158,7 @@ const EVAL_AGENTS = [
156158

157159
app.use("/eval/agents/*", async (c, next) => {
158160
const env = c.env as unknown as WebhookEnv;
161+
if (env.DOCS_FLUE_ENABLE_EVAL_ROUTES !== "1") return c.text("Not Found", 404);
159162
const secret = env.DOCS_FLUE_INTERNAL_TOKEN;
160163
if (!secret) return c.text("Not Found", 404);
161164
const provided = c.req.header("x-dev-secret");

.flue/bin/run-evals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async function main() {
5454
const env = {
5555
...process.env,
5656
DOCS_FLUE_INTERNAL_TOKEN: TOKEN,
57+
DOCS_FLUE_AGENT_EVALS: "1",
5758
};
5859

5960
// Start the dev server. The Vite config reads DOCS_FLUE_INTERNAL_TOKEN

.flue/vite.config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ import { defineConfig } from "vite";
1313
//
1414
// The wrapped customizer also forwards DOCS_FLUE_INTERNAL_TOKEN from
1515
// process.env into the Worker's vars so eval routes work in CI without .env.
16+
// This only activates when DOCS_FLUE_AGENT_EVALS=1 is set (by run-evals.ts),
17+
// so normal dev/build/deploy are unaffected.
18+
const fluePlugin = flue();
1619
const flueCustomizer = flueWorkerConfig();
1720

1821
export default defineConfig({
1922
plugins: [
20-
flue(),
23+
fluePlugin,
2124
cloudflare({
2225
config: (config) => {
2326
flueCustomizer(config);
24-
const token = process.env.DOCS_FLUE_INTERNAL_TOKEN;
25-
if (token) {
27+
if (
28+
process.env.DOCS_FLUE_AGENT_EVALS === "1" &&
29+
process.env.DOCS_FLUE_INTERNAL_TOKEN
30+
) {
2631
(config as Record<string, unknown>).vars = {
2732
...((config as Record<string, unknown>).vars ?? {}),
28-
DOCS_FLUE_INTERNAL_TOKEN: token,
33+
DOCS_FLUE_INTERNAL_TOKEN: process.env.DOCS_FLUE_INTERNAL_TOKEN,
34+
DOCS_FLUE_ENABLE_EVAL_ROUTES: "1",
2935
};
3036
}
3137
},

0 commit comments

Comments
 (0)