Files
elizaos--eliza/packages/scripts/ci-path-gate.self-test.mjs
wehub-resource-sync 426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:43:05 +08:00

340 lines
9.0 KiB
JavaScript

#!/usr/bin/env node
// Exercises ci path gate.self test automation behavior with deterministic script fixtures.
import { spawnSync } from "node:child_process";
import {
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const script = fileURLToPath(new URL("./ci-path-gate.mjs", import.meta.url));
function runGate({ config, files = [], labels = "" }) {
const dir = mkdtempSync(join(tmpdir(), "ci-path-gate-"));
const changedFiles = join(dir, "changed-files.txt");
const output = join(dir, "github-output.txt");
const summary = join(dir, "summary.md");
writeFileSync(changedFiles, `${files.join("\n")}\n`);
const result = spawnSync(
process.execPath,
[
script,
"--config",
config,
"--event",
"pull_request",
"--changed-files",
changedFiles,
"--labels",
labels,
"--output",
output,
"--summary",
summary,
],
{ encoding: "utf8" },
);
if (result.status !== 0) {
throw new Error(
result.stderr || result.stdout || `ci-path-gate exited ${result.status}`,
);
}
const values = Object.fromEntries(
readOutput(output).map((line) => {
const [key, value] = line.split("=");
return [key, value];
}),
);
rmSync(dir, { recursive: true, force: true });
return values;
}
function readOutput(path) {
return readFileSync(path, "utf8").split(/\r?\n/).filter(Boolean);
}
function assertEqual(actual, expected, message) {
if (actual !== expected) {
throw new Error(`${message}: expected ${expected}, got ${actual}`);
}
}
function assertGate(name, actual, expected) {
for (const [key, value] of Object.entries(expected)) {
assertEqual(actual[key], value, `${name} ${key}`);
}
}
assertGate(
"app changes",
runGate({ config: "test", files: ["packages/app/src/App.tsx"] }),
{
server: "false",
client: "true",
plugins: "false",
desktop: "false",
zero_key: "true",
cloud: "false",
},
);
assertGate("full label", runGate({ config: "test", labels: "ci:full" }), {
server: "true",
client: "true",
plugins: "true",
desktop: "true",
zero_key: "true",
cloud: "true",
});
assertGate(
"android label",
runGate({ config: "mobile", labels: "ci:android" }),
{
ios: "false",
android: "true",
},
);
assertGate(
"docker runtime",
runGate({ config: "docker", files: ["plugins/plugin-openai/src/index.ts"] }),
{
docker: "true",
},
);
// The elizaos CLI suite runs under `test:server`; a CLI-only PR must trigger the
// server lane (it previously matched no rule and skipped every test lane).
assertGate(
"elizaos CLI changes",
runGate({ config: "test", files: ["packages/elizaos/src/scaffold.ts"] }),
{
server: "true",
client: "false",
plugins: "false",
desktop: "false",
zero_key: "false",
cloud: "false",
},
);
// Runtime skills also run under `test:server`.
assertGate(
"runtime skills changes",
runGate({ config: "test", files: ["packages/skills/src/index.ts"] }),
{
server: "true",
client: "false",
},
);
// Fail-safe: a novel/unmapped code package must never skip every lane. It routes
// to the server lane rather than passing green with zero tests.
assertGate(
"unmapped code path fail-safe",
runGate({ config: "test", files: ["packages/inference/src/router.ts"] }),
{
server: "true",
client: "false",
plugins: "false",
desktop: "false",
zero_key: "false",
cloud: "false",
},
);
// A second unmapped package proves the fail-safe branch, not a one-off pattern.
assertGate(
"unmapped registry package fail-safe",
runGate({ config: "test", files: ["packages/registry/src/index.ts"] }),
{
server: "true",
},
);
// Pure docs/marketing surfaces are exempt and still skip cleanly (no fail-safe).
assertGate(
"docs-only changes skip cleanly",
runGate({ config: "test", files: ["packages/docs/pages/intro.mdx"] }),
{
server: "false",
client: "false",
plugins: "false",
desktop: "false",
zero_key: "false",
cloud: "false",
},
);
// Non-code changes (top-level files) are outside the code roots - no fail-safe.
assertGate(
"top-level non-code changes skip cleanly",
runGate({ config: "test", files: ["README.md"] }),
{
server: "false",
client: "false",
plugins: "false",
desktop: "false",
zero_key: "false",
cloud: "false",
},
);
// An ignored docs path alongside a real orphan code path still trips the
// fail-safe - the orphan is what matters.
assertGate(
"mixed docs + orphan code trips fail-safe",
runGate({
config: "test",
files: ["packages/docs/pages/x.mdx", "packages/inference/src/y.ts"],
}),
{
server: "true",
},
);
// --- git-diff path (--base/--head, no --changed-files) ---------------------
// The base SHA the workflows pass is the base branch TIP, which advances as
// other PRs merge. The gate must diff from the MERGE-BASE so a PR trailing its
// base branch is not charged with develop-side files it never touched, which
// over-triggered unrelated heavy lanes (#16125). Exercised against a real
// throwaway git history: base branch advances with an app (client-lane) file
// after the PR branches; the PR itself only touches a docs file.
function gitIn(cwd, ...args) {
const result = spawnSync("git", args, { cwd, encoding: "utf8" });
if (result.status !== 0) {
throw new Error(`git ${args.join(" ")} failed: ${result.stderr}`);
}
return result.stdout.trim();
}
function writeIn(cwd, relPath, contents) {
const full = join(cwd, relPath);
mkdirSync(dirname(full), { recursive: true });
writeFileSync(full, contents);
}
function runGateGit({ config, cwd, base, head }) {
const dir = mkdtempSync(join(tmpdir(), "ci-path-gate-git-"));
const output = join(dir, "github-output.txt");
const summary = join(dir, "summary.md");
const result = spawnSync(
process.execPath,
[
script,
"--config",
config,
"--event",
"pull_request",
"--base",
base,
"--head",
head,
"--labels",
"",
"--output",
output,
"--summary",
summary,
],
{ cwd, encoding: "utf8" },
);
if (result.status !== 0) {
rmSync(dir, { recursive: true, force: true });
return { status: result.status, stderr: result.stderr };
}
const values = Object.fromEntries(
readOutput(output).map((line) => {
const [key, value] = line.split("=");
return [key, value];
}),
);
rmSync(dir, { recursive: true, force: true });
return { status: 0, values };
}
const repo = mkdtempSync(join(tmpdir(), "ci-path-gate-repo-"));
try {
gitIn(repo, "init", "-q");
gitIn(repo, "config", "user.email", "test@example.com");
gitIn(repo, "config", "user.name", "test");
gitIn(repo, "checkout", "-q", "-b", "develop");
// Merge-base commit: the point the PR branch forks from.
writeIn(repo, "README.md", "base\n");
gitIn(repo, "add", ".");
gitIn(repo, "commit", "-q", "-m", "base");
// PR branch changes only a docs page (matches no test lane).
gitIn(repo, "checkout", "-q", "-b", "pr");
writeIn(repo, "packages/docs/pages/only.mdx", "# docs\n");
gitIn(repo, "add", ".");
gitIn(repo, "commit", "-q", "-m", "docs-only PR change");
const headSha = gitIn(repo, "rev-parse", "HEAD");
// develop advances past the branch point with an app file (client lane).
gitIn(repo, "checkout", "-q", "develop");
writeIn(repo, "packages/app/src/App.tsx", "export default 1;\n");
gitIn(repo, "add", ".");
gitIn(repo, "commit", "-q", "-m", "develop advances with app change");
const baseTipSha = gitIn(repo, "rev-parse", "HEAD");
const stale = runGateGit({
config: "test",
cwd: repo,
base: baseTipSha,
head: headSha,
});
assertEqual(stale.status, 0, "stale-base git diff run exit status");
assertGate(
"stale base is not charged with develop-side files",
stale.values,
{
server: "false",
client: "false",
plugins: "false",
desktop: "false",
zero_key: "false",
cloud: "false",
},
);
// No merge-base (unrelated histories / bad fetch depth) must fail loud, not
// silently diff the entire tree.
gitIn(repo, "checkout", "-q", "--orphan", "unrelated");
gitIn(repo, "rm", "-rfq", "--cached", ".");
writeIn(repo, "orphan.txt", "no shared history\n");
gitIn(repo, "add", "orphan.txt");
gitIn(repo, "commit", "-q", "-m", "orphan root");
const orphanSha = gitIn(repo, "rev-parse", "HEAD");
const noMergeBase = runGateGit({
config: "test",
cwd: repo,
base: orphanSha,
head: headSha,
});
if (noMergeBase.status === 0) {
throw new Error("expected the gate to fail when no merge-base exists");
}
if (!/no merge-base/.test(noMergeBase.stderr)) {
throw new Error(
`expected a 'no merge-base' error, got: ${noMergeBase.stderr}`,
);
}
} finally {
rmSync(repo, { recursive: true, force: true });
}
console.log("ci-path-gate self-test passed");