Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(pre-push): read Vitest's verdict, not its count of failed tests
DeryFerd9870006e32df
diff --git a/scripts/pre-push-check.mjs b/scripts/pre-push-check.mjsindex 176d0c16ba..95be1aa27d 100644--- a/scripts/pre-push-check.mjs+++ b/scripts/pre-push-check.mjs@@ -39,6 +39,12 @@ const git = (...args) => execFileSync("git", args, { encoding: "utf8", stdio: ["/** Vitest's own verdict from its report, since a dependency out of step fails before any test runs. A guard reads the* whole tree, so a failure that names none of the push's files is main's own, and that is CI's to report. */+/** Vitest's own verdict, not a count of failed tests: a guard that cannot load - a renamed import, a syntax error, a+ * dependency out of step - is a failed suite with no failed test, and that is the failure a rename produces. */+export function guardsPassed(verdict) {+ return verdict?.success === true && (verdict.numFailedTests ?? 0) === 0;+}+function runGuards(guards, files, timeout) {const dir = mkdtempSync(join(tmpdir(), "omb-pre-push-"));const report = join(dir, "report.json");@@ -46,7 +52,13 @@ function runGuards(guards, files, timeout) {const run = spawnSync("node_modules/.bin/vitest", ["run", ...guards, "--reporter=default", "--reporter=json", `--outputFile.json=${report}`], { encoding: "utf8", timeout, maxBuffer: 16 * 1024 * 1024 });if (run.error) return { unknown: run.error.code === "ETIMEDOUT" ? `past ${BUDGET_MS / 1000} s` : run.error.code };if (!existsSync(report)) return { unknown: "it did not start" };- if (JSON.parse(readFileSync(report, "utf8")).numFailedTests === 0) return {};+ const verdict = JSON.parse(readFileSync(report, "utf8"));+ if (guardsPassed(verdict)) return {};+ // It failed without a failing test: the guard itself could not load, which is this push's to fix.+ if ((verdict.numFailedTests ?? 0) === 0) {+ console.error(`${run.stdout}${run.stderr}`);+ return { failed: true };+ }const output = `${run.stdout}${run.stderr}`;// The vocabulary test names a catalog's key, not the catalog.if (files.some((file) => output.includes(file) || file === "src/locales/en.json")) {diff --git a/scripts/pre-push-check.test.ts b/scripts/pre-push-check.test.tsindex a343d3a488..ad2e53bf99 100644--- a/scripts/pre-push-check.test.ts+++ b/scripts/pre-push-check.test.ts@@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";import { afterAll, describe, expect, it } from "vitest";import { removeTempDir } from "../server/testing/cleanup.ts";-import { checksFor, pushedCommits } from "./pre-push-check.mjs";+import { checksFor, guardsPassed, pushedCommits } from "./pre-push-check.mjs";const names = (files: string[]) => checksFor(files).map((check: { name: string }) => check.name);const guards = (files: string[]) => checksFor(files).find((check: { name: string }) => check.name === "source guards")?.guards ?? [];@@ -73,3 +73,18 @@ describe("the hook in a checkout without dependencies", () => {expect(run.stdout).toContain("skipped");});});++describe("what settles the guards", () => {+ it("passes only when Vitest itself says it passed", () => {+ expect(guardsPassed({ success: true, numFailedTests: 0, numFailedTestSuites: 0 })).toBe(true);+ });++ it("fails a suite that could not load, which has no failed test to count", () => {+ expect(guardsPassed({ success: false, numFailedTests: 0, numFailedTestSuites: 1 })).toBe(false);+ });++ it("fails when a test failed, and when the report carries no verdict", () => {+ expect(guardsPassed({ success: false, numFailedTests: 2, numFailedTestSuites: 1 })).toBe(false);+ expect(guardsPassed({ numFailedTests: 0 })).toBe(false);+ });+});