Skip to content

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

Go
24.6 KB
Raw Blame
import assert from "node:assert/strict";
import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, matchesGlob, posix, sep } from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import test from "node:test";
import { checkGate, decideScopes, filters } from "./ci-scope.mjs";

// The filters use only literal paths, * and **; Node's matcher exercises those
// against realistic changes, including files removed or renamed by a PR.
function filterFiles(files) {
  return Object.fromEntries(Object.entries(filters).map(([scope, patterns]) => [
    scope, String(files.some((file) => patterns.some((pattern) => matchesGlob(file, pattern)))),
  ]));
}

for (const [name, files, selected] of [
  ["readme only", ["README.md"], ["docs"]],
  ["translated readme", ["README.ja.md"], ["docs"]],
  ["stable release promotion", [".github/workflows/promote-release.yml"], ["scripts"]],
  ["release orchestration", [".github/workflows/release.yml"], ["scripts"]],
  ["release creation", [".goreleaser.yml"], ["scripts"]],
  ["docs only", ["apps/docs/content/docs/guide.mdx"], ["quality", "docs"]],
  ["docs test", ["apps/docs/lib/unrendered-bold.test.ts"], ["quality", "docs"]],
  ["AI traffic classifier", ["packages/core/ai-traffic/index.ts"], ["frontend", "quality", "docs", "e2e"]],
  ["self-hosting guide for agents", ["SELF_HOSTING_AI.md"], ["docs"]],
  ["Vercel upload filter", [".vercelignore"], ["docs"]],
  ["web changelog", ["apps/web/features/landing/i18n/en.ts"], ["frontend", "quality", "docs", "e2e"]],
  ["landing site copy", ["apps/web/features/landing/i18n/site-ko.ts"], ["frontend", "quality", "docs", "e2e"]],
  ["cloud page", ["apps/web/features/landing/site/cloud-page.tsx"], ["frontend", "quality", "docs", "e2e"]],
  ["landing demo copy", ["apps/web/features/landing/i18n/demo-en.ts"], ["frontend", "quality", "e2e"]],
  ["mobile UI", ["apps/mobile/app/index.tsx"], ["quality"]],
  ["collaboration service", ["apps/collab/src/documents.ts"], ["frontend", "quality"]],
  ["migration only", ["server/migrations/999_example.up.sql"], ["backend", "sqlc", "e2e"]],
  ["agent process code", ["server/pkg/agent/cursor_background.go"], ["backend", "runtime", "e2e"]],
  ["runtime env variables", ["server/internal/daemon/agents_probe.go"], ["backend", "runtime", "docs", "e2e"]],
  ["built-in runtime registry", ["server/pkg/agent/builtin_runtimes.go"], ["backend", "runtime", "docs", "e2e"]],
  ["daemon config", ["server/internal/daemon/config.go"], ["backend", "runtime", "docs", "e2e"]],
  ["feature flag keys", ["server/internal/featureflags/keys.go"], ["backend", "runtime", "docs", "e2e"]],
  ["runtime protocol families", ["server/pkg/agent/agent.go"], ["backend", "runtime", "docs", "e2e"]],
  ["steering support", ["server/pkg/agent/version.go"], ["backend", "runtime", "docs", "e2e"]],
  ["daemon dependency", ["server/internal/skill/service.go"], ["backend", "runtime", "e2e"]],
  ["process-group control", ["server/internal/daemon/processtree/controller_unix.go"], ["backend", "runtime", "processtree", "e2e"]],
  ["process-group caller", ["server/internal/daemon/gc.go"], ["backend", "runtime", "e2e"]],
  ["native test compilation dependency", ["server/pkg/db/generated/issues.sql.go"], ["backend", "sqlc", "runtime", "e2e"]],
  ["Go dependencies", ["server/go.mod", "server/go.sum"], ["backend", "runtime", "e2e"]],
  ["Helm only", ["deploy/helm/multica/templates/deployment.yaml"], ["scripts"]],
  ["container entrypoint", ["docker/entrypoint.sh"], ["scripts"]],
  ["selfhost config", [".env.example"], ["backend", "scripts", "installer"]],
  ["selfhost compose", ["docker-compose.selfhost.yml"], ["backend", "scripts", "installer"]],
  ["local environment config", [".multica/environments.toml"], ["backend", "scripts"]],
  ["plugin example", ["examples/plugins/hello-panel/multica.plugin.json"], ["backend"]],
  ["shell installer", ["scripts/install.sh"], ["scripts", "installer"]],
  ["PowerShell installer", ["scripts/install.ps1.test.ps1"], ["installer"]],
  ["cleanup script", ["scripts/drop-database.sh"], ["scripts"]],
  ["check script regression tests", ["scripts/check.test.sh"], ["scripts"]],
  ["performance harness", ["scripts/perf-compare.test.sh"], ["scripts"]],
  ["attachment preview source", ["server/internal/handler/attachment_text_preview.json"], ["backend", "runtime", "scripts", "e2e"]],
  ["attachment preview output", ["packages/views/editor/utils/text-preview-whitelist.generated.ts"], ["frontend", "quality", "scripts", "e2e"]],
  ["reserved slug source", ["server/internal/handler/reserved_slugs.json"], ["backend", "runtime", "scripts", "e2e"]],
  ["reserved slug output", ["packages/core/paths/reserved-slugs.ts"], ["frontend", "quality", "scripts", "e2e"]],
  ["integration key gates", ["server/cmd/server/router.go"], ["backend", "runtime", "scripts", "e2e"]],
  ["brand source", ["packages/ui/lib/multica-brand.ts"], ["frontend", "quality", "e2e"]],
  ["CLI brand copy", ["server/cmd/multica/cmd_auth.go"], ["backend", "runtime", "quality", "e2e"]],
  ["mobile brand copy", ["apps/mobile/components/brand/multica-logo.tsx"], ["quality"]],
  ["README logo", ["docs/assets/logo-dark.svg"], ["quality"]],
  ["brand generator", ["scripts/brand/sync.mjs"], ["quality"]],
  ["motion checks", ["scripts/motion/checks.test.mjs"], ["quality"]],
  ["PR evidence uploader", ["scripts/pr-shots"], ["quality"]],
  ["cross-module runtime contract", ["packages/core/runtimes/cli-version.ts"], ["frontend", "backend", "runtime", "quality", "e2e"]],
  ["inbox type contract", ["packages/core/types/inbox.ts"], ["frontend", "backend", "quality", "e2e"]],
  ["theming reference generated by views tests", ["docs/theming.md"], ["frontend"]],
  ["app manifest checked by views tests", ["apps/mobile/package.json"], ["frontend", "quality"]],
  ["shared quick action body contract", ["server/internal/handler/testdata/quick_action_bodies.json"], ["frontend", "backend", "runtime", "e2e"]],
  ["lockfile", ["pnpm-lock.yaml"], ["frontend", "quality", "docs", "e2e"]],
  ["workspace catalog", ["pnpm-workspace.yaml"], ["frontend", "quality", "docs", "e2e"]],
  ["workspace package patch", ["patches/example.patch"], ["frontend", "quality", "docs", "e2e"]],
  ["mobile package patch", ["apps/mobile/patches/example.patch"], ["quality"]],
  ["radius policy", ["scripts/check-ui-radius-tokens.mjs"], ["quality"]],
  ["shared quality action", [".github/actions/frontend-quality/action.yml"], ["frontend", "quality"]],
  ["new bitmap", ["apps/web/public/hero.png"], ["frontend", "quality", "images", "e2e"]],
  ["mixed docs and migration", ["apps/docs/content/guide.mdx", "server/migrations/999_example.up.sql"], ["quality", "docs", "backend", "sqlc", "e2e"]],
  ["E2E spec", ["e2e/guest.spec.ts"], ["e2e"]],
  ["Playwright config", ["playwright.config.ts"], ["e2e"]],
  ["dev fixtures", ["scripts/dev-fixtures.mjs"], ["quality", "e2e"]],
  ["fake Composio", ["scripts/fake-composio.mjs"], ["quality", "scripts"]],
  ["Composio spec tooling", ["scripts/composio-spec.mjs"], ["quality", "scripts"]],
  ["Composio OpenAPI snapshot", ["server/pkg/composio/composiotest/openapi-v3.1.json"], ["backend", "runtime", "scripts", "e2e"]],
  ["CI configuration", [".github/ci-paths.json"], Object.keys(filters)],
]) {
  test(`PR and main select only affected scopes: ${name}`, () => {
    for (const event of ["pull_request", "push"]) {
      const outputs = decideScopes(event, filterFiles(files));
      assert.equal(outputs.full, "false");
      assert.deepEqual(Object.keys(filters).filter((scope) => outputs[scope] === "true").sort(),
        [...selected].sort());
      assert.equal(outputs.quality_only, String(selected.includes("quality") && !selected.includes("frontend")));
    }
  });
}

test("scheduled and manual runs select every scope without a path-filter result", () => {
  for (const event of ["schedule", "workflow_dispatch"]) {
    const { quality_only, ...scopes } = decideScopes(event, {});
    assert.ok(Object.values(scopes).every((value) => value === "true"));
    assert.equal(quality_only, "false", "the full frontend build owns quality checks");
  }
});

test("missing, malformed and unsupported filter results fail closed", () => {
  for (const value of [undefined, "", "unknown", true]) {
    assert.throws(() => decideScopes("push", { ...filterFiles([]), backend: value }), /backend/);
  }
  assert.throws(() => decideScopes("unknown", filterFiles([])), /Unsupported/);
});

// Read the production wiring without installing workspace dependencies in the
// lightweight changes job. These fields deliberately use single-line syntax;
// unsupported formatting fails the assertions instead of being silently ignored.
const workflow = readFileSync(new URL("../.github/workflows/ci.yml", import.meta.url), "utf8");
const jobSource = workflow.slice(workflow.indexOf("\njobs:\n") + "\njobs:\n".length);
const headings = [...jobSource.matchAll(/^  ([\w-]+):$/gm)];
const jobs = Object.fromEntries(headings.map((match, index) => [
  match[1], jobSource.slice(match.index, headings[index + 1]?.index),
]));
function field(source, pattern) {
  const match = source.match(pattern);
  assert.ok(match, `Missing production field: ${pattern}`);
  return match[1];
}
function productionMapping(gate) {
  return JSON.parse(field(jobs[gate], /^          JOB_SCOPES: '(.+)'$/m));
}
function productionNeeds(gate, outputs) {
  const dependencies = field(jobs[gate], /^    needs: \[(.+)\]$/m).split(", ");
  return Object.fromEntries(dependencies.map((job) => {
    if (job === "changes") return [job, { result: "success", outputs }];
    const scope = field(jobs[job], /^    if: \$\{\{ needs\.changes\.outputs\.(\w+) == 'true' \}\}$/m);
    return [job, { result: outputs[scope] === "true" ? "success" : "skipped" }];
  }));
}

for (const gate of ["frontend", "backend"]) {
  test(`production ${gate} gate matches every dependency, condition and scope output`, () => {
    const mapping = productionMapping(gate);
    assert.match(jobs[gate], /^    if: \$\{\{ !cancelled\(\) \}\}$/m);
    assert.match(jobs[gate], /^          NEEDS_JSON: \$\{\{ toJSON\(needs\) \}\}$/m);
    assert.match(jobs[gate], /^        run: node scripts\/ci-scope\.mjs gate$/m);
    for (const scope of Object.values(mapping)) {
      assert.ok(jobs.changes.includes(`      ${scope}: \${{ steps.decide.outputs.${scope} }}`));
    }
    const scopes = Object.keys(filters);
    // Exercise mixed scopes too: installers and quality may run without the
    // corresponding product backend/frontend suite being selected.
    for (let mask = 0; mask < 2 ** scopes.length; mask++) {
      const filtered = Object.fromEntries(scopes.map((scope, bit) => [scope, String(Boolean(mask & (1 << bit)))]));
      const outputs = decideScopes("pull_request", filtered);
      checkGate(productionNeeds(gate, outputs), mapping);
    }
    for (const event of ["schedule", "workflow_dispatch"]) {
      checkGate(productionNeeds(gate, decideScopes(event, {})), mapping);
    }
  });

  test(`production ${gate} gate rejects unsuccessful or missing selected jobs`, () => {
    const mapping = productionMapping(gate);
    for (const job of Object.keys(mapping)) {
      // A docs-only run selects the standalone quality runner; a full run
      // selects every other dependency, including the installer matrix.
      const outputs = job === "frontend-quality"
        ? decideScopes("pull_request", filterFiles(["apps/docs/content/guide.mdx"]))
        : decideScopes("workflow_dispatch", {});
      for (const result of ["failure", "cancelled", "skipped", undefined]) {
        const input = productionNeeds(gate, outputs);
        assert.equal(input[job].result, "success");
        input[job].result = result;
        assert.throws(() => checkGate(input, mapping), new RegExp(job));
      }
      const missing = productionNeeds(gate, outputs);
      delete missing[job];
      assert.throws(() => checkGate(missing, mapping), new RegExp(job));
    }
  });

  test(`production ${gate} gate rejects invalid filtering and unchecked dependencies`, () => {
    const mapping = productionMapping(gate);
    const unselected = () => productionNeeds(gate, decideScopes("pull_request", filterFiles([])));
    for (const result of ["failure", "cancelled", "skipped", undefined]) {
      const input = unselected();
      input.changes.result = result;
      assert.throws(() => checkGate(input, mapping), /Path filtering/);
    }
    for (const [job, scope] of Object.entries(mapping)) {
      const failed = unselected();
      failed[job].result = "failure";
      assert.throws(() => checkGate(failed, mapping), new RegExp(job));
      for (const value of [undefined, "", "unknown"]) {
        const invalid = unselected();
        invalid.changes.outputs[scope] = value;
        assert.throws(() => checkGate(invalid, mapping), /scope/);
      }
    }
    const extra = unselected();
    extra.extra = { result: "failure" };
    assert.throws(() => checkGate(extra, mapping), /Unchecked dependency/);
  });
}

// The gates trust job results, and continue-on-error reports a failed step as
// a success, so a gate cannot see a failure behind it.
test("no gated job or shared quality step continues past a failure", () => {
  const action = readFileSync(new URL("../.github/actions/frontend-quality/action.yml", import.meta.url), "utf8");
  assert.doesNotMatch(workflow, /continue-on-error:/);
  assert.doesNotMatch(action, /continue-on-error:/);
});

// A push only checks the paths it changed, so a main run that is cancelled or
// left pending behind a newer push skips its commit for good.
test("path-filtered workflows never cancel or supersede a main run", () => {
  for (const name of ["ci.yml", "mobile-verify.yml"]) {
    const source = readFileSync(new URL(`../.github/workflows/${name}`, import.meta.url), "utf8");
    const block = field(source, /^concurrency:\n((?:  .+\n)+)/m);
    assert.match(block, /^  group: .*\$\{\{ github\.event\.pull_request\.number \|\| github\.run_id \}\}$/m, name);
    assert.match(block, /^  cancel-in-progress: \$\{\{ github\.event_name == 'pull_request' \}\}$/m, name);
  }
});

test("quality checks have exactly one runner", () => {
  const invocation = "uses: ./.github/actions/frontend-quality";
  const owners = Object.entries(jobs).filter(([, source]) => source.includes(invocation)).map(([job]) => job);
  assert.deepEqual(owners.sort(), ["frontend-build", "frontend-quality"]);
  assert.equal(productionMapping("frontend")["frontend-quality"], "quality_only");
  for (const frontend of ["true", "false"]) {
    for (const quality of ["true", "false"]) {
      const outputs = decideScopes("pull_request", { ...filterFiles([]), frontend, quality });
      const results = productionNeeds("frontend", outputs);
      const runners = owners.filter((job) => results[job].result === "success");
      assert.equal(runners.length, frontend === "true" || quality === "true" ? 1 : 0);
    }
  }
});

test("docs run their test suite on one runner and are never built", () => {
  const owners = Object.entries(jobs).filter(([, source]) => source.includes("--filter @multica/docs test")).map(([job]) => job);
  assert.deepEqual(owners, ["docs-test"]);
  assert.equal(productionMapping("frontend")["docs-test"], "docs");
  for (const [job, source] of Object.entries(jobs)) {
    for (const [run] of source.matchAll(/turbo build[^\n]*/g)) {
      assert.match(run, /--filter='!@multica\/docs'/, `${job} builds docs`);
    }
  }
});

test("the CLI writes real Actions outputs and exits nonzero on a failed gate", (t) => {
  const dir = mkdtempSync(join(tmpdir(), "ci-scope-"));
  t.after(() => rmSync(dir, { recursive: true, force: true }));
  const output = join(dir, "output");
  const script = fileURLToPath(new URL("./ci-scope.mjs", import.meta.url));
  const run = spawnSync(process.execPath, [script, "decide"], {
    env: { ...process.env, EVENT_NAME: "push", FILTER_RESULTS: JSON.stringify(filterFiles(["README.md"])), GITHUB_OUTPUT: output },
    encoding: "utf8",
  });
  assert.equal(run.status, 0, run.stderr);
  assert.match(readFileSync(output, "utf8"), /^backend=false$/m);
  const failed = productionNeeds("backend", decideScopes("workflow_dispatch", {}));
  failed["backend-tests"].result = "failure";
  const gate = spawnSync(process.execPath, [script, "gate"], {
    env: { ...process.env, NEEDS_JSON: JSON.stringify(failed), JOB_SCOPES: JSON.stringify(productionMapping("backend")) },
    encoding: "utf8",
  });
  assert.equal(gate.status, 1);
  assert.match(gate.stderr, /backend-tests/);
});

// A Go test that reads a repository file outside server/ only runs on a PR
// touching that file if the backend filter names it; otherwise the PR skips
// backend-tests and the broken test lands on main. The scan is heuristic: it
// follows the shapes the suite uses (filepath.Join from "..", "../" literals,
// package string constants, a repo-root constant joined with a path literal)
// and keeps only paths that exist, which drops traversal fixtures like
// "../../etc/passwd".
function goTokens(source) {
  const tokens = [];
  for (const [text] of source.matchAll(/\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:[^"\\\n]|\\.)*"|`[^`]*`|'(?:[^'\\\n]|\\.)*'|\w+|\S/g)) {
    if (text[0] === '"') {
      try { tokens.push({ value: JSON.parse(text) }); } catch { tokens.push({ value: text.slice(1, -1) }); }
    } else if (text[0] === "`") {
      tokens.push({ value: text.slice(1, -1) });
    } else if (!/^(\/\/|\/\*|')/.test(text)) {
      tokens.push(text);
    }
  }
  return tokens;
}

const opening = new Set(["(", "[", "{"]);
const closingBrackets = new Set([")", "]", "}"]);
function closing(tokens, open) {
  for (let depth = 0, i = open; i < tokens.length; i++) {
    if (opening.has(tokens[i])) depth++;
    else if (closingBrackets.has(tokens[i]) && --depth === 0) return i;
  }
  return tokens.length;
}
function splitTopLevel(tokens, separator) {
  const parts = [[]];
  let depth = 0;
  for (const token of tokens) {
    if (opening.has(token)) depth++;
    if (closingBrackets.has(token)) depth--;
    if (token === separator && depth === 0) parts.push([]);
    else parts.at(-1).push(token);
  }
  return parts;
}

function goStringConstants(tokens, constants) {
  for (let i = 0; i < tokens.length; i++) {
    if (tokens[i] !== "const" && tokens[i] !== "var") continue;
    const end = tokens[i + 1] === "(" ? closing(tokens, i + 1) : i + 4;
    for (let j = i + 2; j < end; j++) {
      const value = tokens[j + 1]?.value;
      if (tokens[j] !== "=" || value === undefined || tokens[j + 2] === "+") continue;
      constants.set(tokens[j - 1] === "string" ? tokens[j - 2] : tokens[j - 1], value);
    }
  }
}

const pathFunctions = new Set(["Join", "Clean", "FromSlash", "ToSlash"]);
function pathCall(tokens, i) {
  if ((tokens[i] !== "filepath" && tokens[i] !== "path") || tokens[i + 1] !== "."
    || !pathFunctions.has(tokens[i + 2]) || tokens[i + 3] !== "(") return undefined;
  const end = closing(tokens, i + 3);
  return { name: tokens[i + 2], args: splitTopLevel(tokens.slice(i + 4, end), ","), end };
}
// The leading arguments that resolve statically; a Join stops being known at
// its first dynamic argument, which still leaves the directory it reads under.
function knownPrefix(args, constants) {
  const known = [];
  for (const arg of args) {
    const value = evaluate(arg, constants);
    if (value === undefined) break;
    known.push(value);
  }
  return known;
}
function evaluate(tokens, constants) {
  let result = "";
  for (const part of splitTopLevel(tokens, "+")) {
    const call = pathCall(part, 0);
    let value = part.length === 1 ? part[0].value ?? constants.get(part[0]) : undefined;
    if (call?.end === part.length - 1) {
      const known = knownPrefix(call.args, constants);
      if (known.length === call.args.length && known.length > 0) {
        value = call.name === "Join" ? posix.join(...known) : posix.normalize(known[0]);
      }
    }
    if (value === undefined) return undefined;
    result += value;
  }
  return result;
}

function goTestRepoReads(root) {
  const reads = new Map();
  const goFiles = readdirSync(join(root, "server"), { recursive: true })
    .map((file) => posix.join("server", file.split(sep).join("/")))
    .filter((file) => file.endsWith(".go"));
  for (const [dir, files] of Map.groupBy(goFiles, posix.dirname)) {
    const sources = new Map(files.map((file) => [file, goTokens(readFileSync(join(root, file), "utf8"))]));
    const constants = new Map();
    for (const tokens of sources.values()) goStringConstants(tokens, constants);
    for (const [file, tokens] of sources) {
      if (!file.endsWith("_test.go")) continue;
      const bases = new Set();
      const resolve = (path, { directories = true } = {}) => {
        if (path === ".." || path.startsWith("../") || path === "server" || path.startsWith("server/")) return;
        const stat = statSync(join(root, path), { throwIfNoEntry: false });
        if (!stat || (stat.isDirectory() && !directories)) return;
        if (stat.isDirectory()) bases.add(path);
        if (path === ".") return;
        if (!reads.has(path)) reads.set(path, { directory: stat.isDirectory(), readers: new Set() });
        reads.get(path).readers.add(file);
      };
      for (let i = 0; i < tokens.length; i++) {
        const call = pathCall(tokens, i);
        const relative = call?.name === "Join"
          ? posix.join(...knownPrefix(call.args, constants), ".")
          : tokens[i].value ?? constants.get(tokens[i]);
        if (relative === ".." || relative?.startsWith("../")) resolve(posix.join(dir, relative));
      }
      // readRepoFile(t, ".env.example") style: a helper joins the literal onto
      // a repository directory resolved above.
      for (const base of [...bases]) {
        for (const { value } of tokens) {
          if (/^(?!\.\.)[\w.@+-]+(\/[\w.@+-]+)*$/.test(value ?? "")) resolve(posix.join(base, value), { directories: false });
        }
      }
    }
  }
  return reads;
}

function uncoveredReads(root, reads, patterns) {
  const covered = (file) => patterns.some((pattern) => matchesGlob(file, pattern));
  return [...reads].filter(([path, { directory }]) => !(directory
    ? readdirSync(join(root, path), { recursive: true }).some((file) => covered(posix.join(path, file.split(sep).join("/"))))
    : covered(path)));
}

function missingFilterMessage(missing) {
  return "Go tests read these files outside server/, but a PR changing them skips backend-tests.\n"
    + 'Add each path to the "backend" group in .github/ci-paths.json:\n'
    + missing.map(([path, { directory, readers }]) =>
      `  "${directory ? `${path}/**` : path}"  (read by ${[...readers].sort().join(", ")})`).join("\n");
}

test("every repository file a Go test reads outside server/ selects backend-tests", () => {
  const root = fileURLToPath(new URL("..", import.meta.url));
  const reads = goTestRepoReads(root);
  assert.ok(reads.size > 0, "The scan found no reads outside server/; it no longer recognizes how Go tests load repository files.");
  const missing = uncoveredReads(root, reads, filters.backend);
  assert.deepEqual(missing.map(([path]) => path), [], missingFilterMessage(missing));
});

test("the Go test scan follows relative paths, constants and repo-root helpers", (t) => {
  const root = mkdtempSync(join(tmpdir(), "ci-scope-go-"));
  t.after(() => rmSync(root, { recursive: true, force: true }));
  const files = {
    "server/pkg/a/config.go": 'package a\n\nconst ConfigPath = ".multica/environments.toml"\n',
    "server/pkg/a/a_test.go": [
      "package a",
      'const repoRoot = "../../.."',
      "func readRepoFile(name string) { os.ReadFile(filepath.Join(repoRoot, name)) }",
      "func TestA(t *testing.T) {",
      '\treadRepoFile(".env.example")',
      '\tos.ReadFile(filepath.Join("..", "..", "..", filepath.FromSlash(ConfigPath)))',
      '\tos.ReadFile("../../../scripts/check.sh")',
      '\tos.ReadDir(filepath.Join("..", "..", "..", "examples", "plugins", entry.Name()))',
      '\tos.ReadFile("../../migrations/1.up.sql")',
      '\tstore.Get("../../../etc/passwd")',
      '\t// os.ReadFile("../../../docs/commented.md")',
      "}",
    ].join("\n"),
    ".multica/environments.toml": "",
    ".env.example": "",
    "scripts/check.sh": "",
    "examples/plugins/demo/multica.plugin.json": "",
    "server/migrations/1.up.sql": "",
    "docs/commented.md": "",
  };
  for (const [file, body] of Object.entries(files)) {
    mkdirSync(dirname(join(root, file)), { recursive: true });
    writeFileSync(join(root, file), body);
  }
  const reads = goTestRepoReads(root);
  assert.deepEqual([...reads.keys()].sort(),
    [".env.example", ".multica/environments.toml", "examples/plugins", "scripts/check.sh"]);
  const missing = uncoveredReads(root, reads, [".env.example", "examples/plugins/**", "scripts/*.sh"]);
  assert.equal(missingFilterMessage(missing).split("\n").at(-1),
    '  ".multica/environments.toml"  (read by server/pkg/a/a_test.go)');
});