Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

test(docs): enforce env var docs coverage for every built-in runtime (MUL-9829) (#11173)

Jiayuan Zhangb62398190e83
diff --git a/.github/ci-paths.json b/.github/ci-paths.json
index f10952d29d..e1fbd40687 100644
--- a/.github/ci-paths.json
+++ b/.github/ci-paths.json
@@ -19,6 +19,10 @@
],
"docs": [
"apps/docs/**",
+ "server/internal/daemon/agents_probe.go",
+ "server/internal/daemon/config.go",
+ "server/pkg/agent/builtin_runtimes.go",
+ "server/internal/featureflags/keys.go",
"package.json",
".npmrc",
"pnpm-lock.yaml",
diff --git a/AGENTS.md b/AGENTS.md
index fd335bf606..6a19dcabcd 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -146,5 +146,6 @@ Workspace-scoped queries filter by `workspace_id`; membership gates access and `
- Do not add internal compatibility shims, dual writes, fallback paths, or legacy adapters unless requested. This does not relax API response compatibility above.
- Use names, types, and tests to express behavior. Code comments are English and kept for non-obvious rationale and constraints; remove superseded plans and incident narratives when updating code. Preserve tool directives and mixed-version contracts.
- When a change alters user-visible behavior, a setting, a default, a shortcut, or an entry point, `rg` `apps/docs/content/docs` for the feature's name and the terms of the old behavior; a newly added label is not in the docs yet. In the same PR, update every affected page and its locale siblings (`inbox.mdx`, `inbox.zh.mdx`, ...). Text the change makes wrong is always fixed here; if the docs only lack the new behavior, you may link a docs follow-up issue from the PR description instead. Exception: do not document features gated behind a default-off flag in `server/internal/featureflags/keys.go` (permanently enabled compat keys do not count) in `apps/docs/content/docs/` or root `README*.md`; note why docs were skipped in the PR description instead. When a PR flips a flag to default-on or removes it for general availability, add the docs across all locales in the same PR (content removed earlier can be recovered from the diff of PR #11111).
+- A new built-in runtime prefix (`MULTICA_<PREFIX>_PATH`/`_ENDPOINT`) or `MULTICA_<PREFIX>_ARGS` variable must appear in every `apps/docs/content/docs/environment-variables*.mdx`; `apps/docs/lib/env-var-coverage.test.ts` enforces this, and its exemption list is for runtimes deliberately kept out of the docs.
- New global pre-workspace routes use a single word or `/{noun}/{verb}`, not hyphenated root names. Update `server/internal/handler/reserved_slugs.json`, run `pnpm generate:reserved-slugs`, and commit `packages/core/paths/reserved-slugs.ts` when changing reserved slugs.
- Use atomic conventional commits and the repository PR template. Follow the [pull request requirements](CONTRIBUTING.md#pull-request-requirements): Problem, Goal, Proposal (high-level design understandable without much background), Alternatives (optional), and Screenshots. Attach screenshots or a screen recording for UI or interaction changes (missing both means rejection by default). For releases, follow [.github/RELEASING.md](.github/RELEASING.md); default to a patch bump unless specified otherwise.
diff --git a/apps/docs/lib/env-var-coverage.test.ts b/apps/docs/lib/env-var-coverage.test.ts
new file mode 100644
index 0000000000..89cb20ba7a
--- /dev/null
+++ b/apps/docs/lib/env-var-coverage.test.ts
@@ -0,0 +1,230 @@
+// @vitest-environment node
+import { existsSync, readFileSync } from "node:fs";
+import path from "node:path";
+import { describe, expect, it } from "vitest";
+import { i18n, type Lang } from "./i18n";
+
+// The per-tool tables on the environment variables page are hand-written in
+// every locale, so a new built-in runtime used to land without its
+// `MULTICA_<PREFIX>` or `MULTICA_<PREFIX>_ARGS` entry and only got caught by a
+// later docs sweep. This reads the daemon sources that define those variables
+// and requires each one in every locale. The sources are listed in the "docs"
+// group of .github/ci-paths.json so a server-only runtime PR still runs it.
+
+const repoRoot = path.resolve(__dirname, "../../..");
+const docsDir = path.resolve(__dirname, "../content/docs");
+
+const sources = {
+ probe: "server/internal/daemon/agents_probe.go",
+ registry: "server/pkg/agent/builtin_runtimes.go",
+ config: "server/internal/daemon/config.go",
+ flags: "server/internal/featureflags/keys.go",
+} as const;
+
+type Exemption = {
+ reason: string;
+ // A key in server/internal/featureflags/keys.go that defaults to off.
+ // AGENTS.md keeps features behind such a flag out of the public docs.
+ flag?: string;
+};
+
+// Runtimes the daemon registers that the docs deliberately leave out.
+// Remove an entry once the runtime is documented in every locale.
+const undocumentedPrefixes: Record<string, Exemption> = {
+ MULTICA_MUSEAPP: {
+ reason:
+ "Muse app remote receptionist (#9155). Whether it is publicly documented awaits a product decision.",
+ },
+};
+
+type Variable = { name: string; source: string };
+
+function readRepoFile(rel: string): string {
+ return readFileSync(path.join(repoRoot, rel), "utf8");
+}
+
+function matchAll(source: string, pattern: RegExp): string[] {
+ return [...source.matchAll(pattern)].map((match) => match[1]!);
+}
+
+// A runtime is detected through MULTICA_<PREFIX>_PATH (a CLI) or
+// MULTICA_<PREFIX>_ENDPOINT (a remote service such as museapp).
+function extractProbePrefixes(goSource: string): string[] {
+ return matchAll(goSource, /"(MULTICA_[A-Z0-9]+)_(?:PATH|ENDPOINT)"/g);
+}
+
+function extractRegistryPrefixes(goSource: string): string[] {
+ return matchAll(goSource, /\bEnvPrefix:\s*"(MULTICA_[A-Z0-9]+)"/g);
+}
+
+function extractArgsVariables(goSource: string): string[] {
+ return matchAll(goSource, /\bshellArgsFromEnv\("(MULTICA_[A-Z0-9]+_ARGS)"\)/g);
+}
+
+function defaultOffFlags(goSource: string): Set<string> {
+ const keyByConst = new Map(
+ [...goSource.matchAll(/^\s*([A-Z]\w*)\s*=\s*"([a-z0-9_]+)"/gm)].map(
+ (match) => [match[1]!, match[2]!] as const,
+ ),
+ );
+ const off = new Set<string>();
+ for (const name of matchAll(goSource, /\bIsEnabled\(ctx,\s*([A-Z]\w*),\s*false\)/g)) {
+ const key = keyByConst.get(name);
+ if (key) off.add(key);
+ }
+ return off;
+}
+
+function unique(variables: Variable[]): Variable[] {
+ const seen = new Map<string, Variable>();
+ for (const variable of variables) {
+ if (!seen.has(variable.name)) seen.set(variable.name, variable);
+ }
+ return [...seen.values()].sort((a, b) => a.name.localeCompare(b.name));
+}
+
+function escapeRegExp(value: string): string {
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+}
+
+// A prefix counts only as its own inline-code token (`MULTICA_QWEN`), so
+// `MULTICA_QWENPAW` or `MULTICA_QWEN_ARGS` cannot stand in for it.
+function documentsPrefix(mdx: string, prefix: string): boolean {
+ return mdx.includes(`\`${prefix}\``);
+}
+
+function documentsVariable(mdx: string, name: string): boolean {
+ return new RegExp(`(?<![A-Z0-9_])${escapeRegExp(name)}(?![A-Z0-9_])`).test(mdx);
+}
+
+function localeFile(lang: Lang): string {
+ return lang === i18n.defaultLanguage
+ ? "environment-variables.mdx"
+ : `environment-variables.${lang}.mdx`;
+}
+
+describe("extractors", () => {
+ it("finds CLI and endpoint prefixes, but not other _PATH variables", () => {
+ const go = [
+ 'if e, ok := probe("MULTICA_QWEN_PATH", "qwen", "MULTICA_QWEN_MODEL"); ok {',
+ 'if e, ok := probe("MULTICA_QWENPAW_PATH", "qwenpaw", ""); ok {',
+ 'if strings.TrimSpace(os.Getenv("MULTICA_MUSEAPP_ENDPOINT")) != "" {',
+ 'os.Getenv("MULTICA_DSH_PLUGIN_PATH")',
+ ].join("\n");
+ expect(extractProbePrefixes(go)).toEqual([
+ "MULTICA_QWEN",
+ "MULTICA_QWENPAW",
+ "MULTICA_MUSEAPP",
+ ]);
+ });
+
+ it("finds registry prefixes and _ARGS variables", () => {
+ expect(extractRegistryPrefixes('\t\tEnvPrefix: "MULTICA_OMP",')).toEqual([
+ "MULTICA_OMP",
+ ]);
+ expect(
+ extractArgsVariables('ampArgs, err := shellArgsFromEnv("MULTICA_AMP_ARGS")'),
+ ).toEqual(["MULTICA_AMP_ARGS"]);
+ });
+
+ it("treats only flags whose IsEnabled default is false as default-off", () => {
+ const go = [
+ "const (",
+ '\tDocsV1 = "docs_v1"',
+ '\tLocalSearchIndex = "local_search_index"',
+ '\tagentBuilderCompat = "agents_agent_builder"',
+ ")",
+ "return flags.IsEnabled(ctx, DocsV1, false)",
+ "return flags.IsEnabled(ctx, LocalSearchIndex, true)",
+ ].join("\n");
+ expect([...defaultOffFlags(go)]).toEqual(["docs_v1"]);
+ });
+
+ it("matches prefixes and variables as whole tokens", () => {
+ const mdx = "| Qwen | `MULTICA_QWENPAW` |\n`MULTICA_QWEN_ARGS`";
+ expect(documentsPrefix(mdx, "MULTICA_QWEN")).toBe(false);
+ expect(documentsPrefix(mdx, "MULTICA_QWENPAW")).toBe(true);
+ expect(documentsVariable(mdx, "MULTICA_QWEN_ARGS")).toBe(true);
+ expect(documentsVariable(mdx, "MULTICA_QWENPAW_ARGS")).toBe(false);
+ });
+});
+
+describe("environment variables docs", () => {
+ const prefixes = unique([
+ ...extractProbePrefixes(readRepoFile(sources.probe)).map((name) => ({
+ name,
+ source: sources.probe,
+ })),
+ ...extractRegistryPrefixes(readRepoFile(sources.registry)).map((name) => ({
+ name,
+ source: sources.registry,
+ })),
+ ]);
+ const argsVariables = unique(
+ extractArgsVariables(readRepoFile(sources.config)).map((name) => ({
+ name,
+ source: sources.config,
+ })),
+ );
+ const locales = i18n.languages.map((lang) => {
+ const file = localeFile(lang);
+ const full = path.join(docsDir, file);
+ return { file, mdx: existsSync(full) ? readFileSync(full, "utf8") : null };
+ });
+
+ it("still recognizes how the daemon declares runtime variables", () => {
+ const names = prefixes.map((p) => p.name);
+ expect(names).toContain("MULTICA_CLAUDE");
+ expect(names).toContain("MULTICA_OMP");
+ expect(names).toContain("MULTICA_MUSEAPP");
+ expect(argsVariables.map((v) => v.name)).toContain("MULTICA_CLAUDE_ARGS");
+ });
+
+ it("has a page for every locale", () => {
+ expect(locales.filter((l) => l.mdx === null).map((l) => l.file)).toEqual([]);
+ });
+
+ it("lists every built-in runtime prefix and _ARGS variable in every locale", () => {
+ const missing: string[] = [];
+ for (const { file, mdx } of locales) {
+ if (mdx === null) continue;
+ for (const { name, source } of prefixes) {
+ if (name in undocumentedPrefixes) continue;
+ if (!documentsPrefix(mdx, name)) {
+ missing.push(`${file}: \`${name}\` missing from the tool prefix table (declared in ${source})`);
+ }
+ }
+ for (const { name, source } of argsVariables) {
+ if (name.replace(/_ARGS$/, "") in undocumentedPrefixes) continue;
+ if (!documentsVariable(mdx, name)) {
+ missing.push(`${file}: ${name} missing from the MULTICA_<PREFIX>_ARGS list (read in ${source})`);
+ }
+ }
+ }
+ expect(
+ missing,
+ `Add these to apps/docs/content/docs/environment-variables*.mdx in the same PR, or list the prefix in undocumentedPrefixes in ${path.relative(repoRoot, __filename)} with a reason.`,
+ ).toEqual([]);
+ });
+
+ it("keeps every exemption current", () => {
+ const offFlags = defaultOffFlags(readRepoFile(sources.flags));
+ const known = new Set(prefixes.map((p) => p.name));
+ const stale: string[] = [];
+ for (const [prefix, { reason, flag }] of Object.entries(undocumentedPrefixes)) {
+ if (!reason.trim()) stale.push(`${prefix}: exemption needs a reason`);
+ if (!known.has(prefix)) {
+ stale.push(`${prefix}: no longer declared by the daemon; remove the exemption`);
+ }
+ if (flag !== undefined && !offFlags.has(flag)) {
+ stale.push(
+ `${prefix}: flag "${flag}" is not a default-off key in ${sources.flags}; document the runtime and remove the exemption`,
+ );
+ }
+ if (locales.every(({ mdx }) => mdx !== null && documentsPrefix(mdx, prefix))) {
+ stale.push(`${prefix}: documented in every locale; remove the exemption`);
+ }
+ }
+ expect(stale).toEqual([]);
+ });
+});
diff --git a/apps/docs/turbo.json b/apps/docs/turbo.json
new file mode 100644
index 0000000000..49f3621c1d
--- /dev/null
+++ b/apps/docs/turbo.json
@@ -0,0 +1,14 @@
+{
+ "extends": ["//"],
+ "tasks": {
+ "test": {
+ "inputs": [
+ "$TURBO_DEFAULT$",
+ "$TURBO_ROOT$/server/internal/daemon/agents_probe.go",
+ "$TURBO_ROOT$/server/internal/daemon/config.go",
+ "$TURBO_ROOT$/server/pkg/agent/builtin_runtimes.go",
+ "$TURBO_ROOT$/server/internal/featureflags/keys.go"
+ ]
+ }
+ }
+}
diff --git a/scripts/ci-scope.test.mjs b/scripts/ci-scope.test.mjs
index b47f8241cf..3c944325bb 100644
--- a/scripts/ci-scope.test.mjs
+++ b/scripts/ci-scope.test.mjs
@@ -27,6 +27,10 @@ for (const [name, files, selected] of [
["collaboration service", ["apps/collab/src/documents.ts"], ["frontend", "quality"]],
["migration only", ["server/migrations/999_example.up.sql"], ["backend", "sqlc"]],
["agent process code", ["server/pkg/agent/cursor_background.go"], ["backend", "runtime"]],
+ ["runtime env variables", ["server/internal/daemon/agents_probe.go"], ["backend", "runtime", "docs"]],
+ ["built-in runtime registry", ["server/pkg/agent/builtin_runtimes.go"], ["backend", "runtime", "docs"]],
+ ["daemon config", ["server/internal/daemon/config.go"], ["backend", "runtime", "docs"]],
+ ["feature flag keys", ["server/internal/featureflags/keys.go"], ["backend", "runtime", "docs"]],
["daemon dependency", ["server/internal/skill/service.go"], ["backend", "runtime"]],
["process-group control", ["server/internal/daemon/processtree/controller_unix.go"], ["backend", "runtime", "processtree"]],
["process-group caller", ["server/internal/daemon/gc.go"], ["backend", "runtime"]],