Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

pre-push: a guard that cannot load blocks only a push it names

milind-soni269a959d989c
diff --git a/scripts/pre-push-check.mjs b/scripts/pre-push-check.mjs
index 95be1aa27d..e17894c649 100644
--- a/scripts/pre-push-check.mjs
+++ b/scripts/pre-push-check.mjs
@@ -37,14 +37,15 @@ export function checksFor(files) {
const git = (...args) => execFileSync("git", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
-/** 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. */
+ * dependency out of step - is a failed suite with no failed test. */
export function guardsPassed(verdict) {
return verdict?.success === true && (verdict.numFailedTests ?? 0) === 0;
}
+/** 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, or this checkout's dependencies, and that
+ * is CI's to report. */
function runGuards(guards, files, timeout) {
const dir = mkdtempSync(join(tmpdir(), "omb-pre-push-"));
const report = join(dir, "report.json");
@@ -54,18 +55,14 @@ function runGuards(guards, files, timeout) {
if (!existsSync(report)) return { unknown: "it did not start" };
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")) {
console.error(output);
return { failed: true };
}
- return { unknown: "a failure that names no file of this push, so main may be red" };
+ // A guard that could not load and names none of the push's files: main's, or this checkout's dependencies.
+ return { unknown: (verdict.numFailedTests ?? 0) === 0 ? "a guard could not load, naming no file of this push" : "a failure that names no file of this push, so main may be red" };
} catch (error) {
return { unknown: error.message };
} finally {