deepmodebot 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +2 -2
- package/.omp-plugin/marketplace.json +2 -2
- package/README.md +15 -6
- package/bin/deepmodebot.mjs +104 -10
- package/native/dmb-gate/Cargo.toml +1 -1
- package/native/dmb-gate/src/agents.rs +58 -25
- package/native/dmb-gate/src/ci.rs +530 -14
- package/native/dmb-gate/src/main.rs +215 -7
- package/native/dmb-gate/src/reward.rs +1895 -242
- package/native/dmb-gate/src/sim.rs +969 -0
- package/native/dmb-gate/src/slop.rs +1061 -295
- package/package.json +1 -1
- package/plugins/deepmodebot/.antigravity-plugin/plugin.json +1 -1
- package/plugins/deepmodebot/.antigravity-plugin/skills/deep/SKILL.md +1 -1
- package/plugins/deepmodebot/.claude-plugin/plugin.json +1 -1
- package/plugins/deepmodebot/.codex-plugin/plugin.json +2 -2
- package/plugins/deepmodebot/agents/comment-sicko.md +29 -0
- package/plugins/deepmodebot/agents/researcher.md +29 -0
- package/plugins/deepmodebot/agents/reviewer.md +29 -0
- package/plugins/deepmodebot/agents/scout.md +28 -0
- package/plugins/deepmodebot/agents/security-reviewer.md +27 -0
- package/plugins/deepmodebot/commands/deep.md +3 -2
- package/plugins/deepmodebot/commands/tournament.md +1 -1
- package/plugins/deepmodebot/hooks/hooks.json +12 -2
- package/plugins/deepmodebot/hooks.json +1 -1
- package/plugins/deepmodebot/scripts/antigravity-guard.mjs +740 -37
- package/plugins/deepmodebot/skills/agent-harnesses/references/antigravity.md +2 -2
- package/plugins/deepmodebot/skills/deepmodebot/SKILL.md +19 -11
- package/plugins/deepmodebot/skills/deepmodebot/assets/agents-md/agents_md.py +51 -20
- package/plugins/deepmodebot/skills/deepmodebot/assets/autoroute/autoroute.py +54 -49
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/claude-guard.sh +4 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/claude_guard.py +658 -21
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/holdout_guard_cases.json +272 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/contain/omp-contain.ts +774 -23
- package/plugins/deepmodebot/skills/deepmodebot/assets/f2p-gate/f2p_gate.py +547 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/gap-audit/gap_audit.py +5 -11
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard-patterns.txt +4 -4
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard.sh +53 -6
- package/plugins/deepmodebot/skills/deepmodebot/assets/git-guardrails/git-guard.ts +48 -2
- package/plugins/deepmodebot/skills/deepmodebot/assets/local-ci/local_ci.py +262 -6
- package/plugins/deepmodebot/skills/deepmodebot/assets/local-ci/slop_gate.py +529 -122
- package/plugins/deepmodebot/skills/deepmodebot/assets/loop/loop.py +747 -46
- package/plugins/deepmodebot/skills/deepmodebot/assets/memory/project_memory.py +404 -5
- package/plugins/deepmodebot/skills/deepmodebot/assets/mutation/mutation_gate.py +798 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/reward-guard/reward_guard.py +2050 -200
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rule-paths.json +44 -1
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rule_ledger.py +278 -252
- package/plugins/deepmodebot/skills/deepmodebot/assets/rules/rules_watch.py +436 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/self-grill/self_grill.py +594 -18
- package/plugins/deepmodebot/skills/deepmodebot/assets/setup/project_setup.py +41 -5
- package/plugins/deepmodebot/skills/deepmodebot/assets/sim/sim.py +856 -0
- package/plugins/deepmodebot/skills/deepmodebot/assets/worker-gate/worker_gate.py +237 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/catalog.md +3 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/delegation.md +6 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/authoring-a-skill.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/hillclimb.md +1 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/playbooks/self-authoring.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/principles/no-reward-hacking.md +6 -6
- package/plugins/deepmodebot/skills/deepmodebot/references/rule-approval.md +36 -16
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/autoroute.md +9 -8
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/correct.md +1 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/inner-loop.md +6 -2
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/mutation-testing.md +31 -9
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/no-comments.md +1 -1
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/panel.md +4 -4
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/sim.md +41 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/tdd.md +12 -0
- package/plugins/deepmodebot/skills/deepmodebot/references/techniques/tournament.md +24 -13
- package/plugins/deepmodebot/skills/deepmodebot/worker.md +28 -16
- package/plugins/deepmodebot/agents/comment-sicko/agent.md +0 -35
- package/plugins/deepmodebot/agents/researcher/agent.md +0 -33
- package/plugins/deepmodebot/agents/reviewer/agent.md +0 -35
- package/plugins/deepmodebot/agents/scout/agent.md +0 -33
- package/plugins/deepmodebot/agents/security-reviewer/agent.md +0 -31
|
@@ -99,20 +99,67 @@ command_text="${command_text//$'\\\n'/ }" # a backslash-newline continues t
|
|
|
99
99
|
command_text="${command_text//$'\t'/ }" # normalize tabs so portable space patterns match
|
|
100
100
|
|
|
101
101
|
block() {
|
|
102
|
-
|
|
103
|
-
echo "Blocked by
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
if [[ "$1" =~ (--|jest|vitest|playwright|insta|SNAPSHOT|go\ test|reward-guard|contract-lock|judge_verdicts|record-judge) ]] && [[ ! "$1" =~ ^git\ +(reset|clean|checkout|restore|stash|worktree|branch|filter|update-ref|reflog|gc|push) ]]; then
|
|
103
|
+
echo "Blocked by anti-reward-hacking guard: \"$1\" weakens a verification gate, overwrites golden snapshots, skips checks, or tampers with provenance ledgers." >&2
|
|
104
|
+
else
|
|
105
|
+
{
|
|
106
|
+
echo "Blocked by the git guard: \"$1\" can destroy work or rewrite shared history."
|
|
107
|
+
echo "Use a safe form instead (git stash, a new branch, git push --force-with-lease to your own feature branch, a PR for the default branch),"
|
|
108
|
+
echo "or ask the user to run it themselves."
|
|
109
|
+
} >&2
|
|
110
|
+
fi
|
|
107
111
|
exit 2
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
scrubbed_text="$(printf '%s\n' "$command_text" | sed -E 's/(-m|--message)(=| +)("[^"]*"|'\''[^'\'']*'\'')/\1 ""/g' | grep -vE '^ *(grep|rg) +[
|
|
114
|
+
scrubbed_text="$(printf '%s\n' "$command_text" | sed -E 's/(-m|--message)(=| +)("[^"]*"|'\''[^'\'']*'\'')/\1 ""/g' | grep -vE '^ *(grep|rg|echo|printf) +[^;&|<>()`$]*$' || true)"
|
|
111
115
|
clean_patterns="$(tr -d '\r' < "$patterns")"
|
|
112
116
|
active="$(printf '%s\n' "$clean_patterns" | grep -vE '^[[:space:]]*(#|@|$)' || true)"
|
|
113
117
|
if [[ -n "$active" && -n "$scrubbed_text" ]]; then
|
|
114
118
|
hit="$(printf '%s\n' "$scrubbed_text" | grep -Eo -f <(printf '%s\n' "$active") | head -n 1 || true)"
|
|
115
119
|
[[ -z "$hit" ]] || block "$hit"
|
|
120
|
+
min_hit="$(printf '%s\n' "$scrubbed_text" | awk '
|
|
121
|
+
BEGIN {
|
|
122
|
+
split("iou ssim dice f1 auc accuracy acc precision recall fidelity similarity coverage pass-rate win-rate", m50, " ")
|
|
123
|
+
for (i in m50) fl[m50[i]] = 0.50
|
|
124
|
+
split("clip clip-score ap map bleu rouge", m15, " ")
|
|
125
|
+
for (i in m15) fl[m15[i]] = 0.15
|
|
126
|
+
fl["psnr"] = 10.0; fl["protrusion"] = 0.02; fl["score"] = 0.05; fl["confidence"] = 0.05; fl["symmetry"] = 0.05; fl["cov-fail-under"] = 50.0
|
|
127
|
+
}
|
|
128
|
+
{
|
|
129
|
+
s = tolower($0)
|
|
130
|
+
while (match(s, /(^|[ ;&|(])["'\'']?--((gate-)?mi(n(-[a-z0-9_-]*)?)?|cov-fail-under)["'\'']?( +|=)["'\'']? *[-+]?(inf(inity)?|nan|([0-9][0-9_]*\.?[0-9_]*|\.[0-9_]+)(e[-+]?[0-9_]+)?) *["'\'']?( |;|&|\||\)|$)/)) {
|
|
131
|
+
seg = substr(s, RSTART, RLENGTH)
|
|
132
|
+
s = substr(s, RSTART + RLENGTH - 1)
|
|
133
|
+
val = seg
|
|
134
|
+
sub(/^.*--((gate-)?mi(n(-[a-z0-9_-]*)?)?|cov-fail-under)["'\'']?( +|=)["'\'']? */, "", val)
|
|
135
|
+
sub(/ *["'\'' ;&|)]*$/, "", val)
|
|
136
|
+
if (seg ~ /--cov-fail-under/) {
|
|
137
|
+
tok = "cov-fail-under"
|
|
138
|
+
} else if (seg ~ /--(gate-)?min-[a-z0-9_-]+/) {
|
|
139
|
+
tok = seg
|
|
140
|
+
sub(/^.*--(gate-)?min-/, "", tok)
|
|
141
|
+
sub(/["'\'']?( +|=).*$/, "", tok)
|
|
142
|
+
gsub(/_/, "-", tok)
|
|
143
|
+
} else {
|
|
144
|
+
tok = ""
|
|
145
|
+
}
|
|
146
|
+
gsub(/_/, "", val)
|
|
147
|
+
req = -1
|
|
148
|
+
if (tok == "") { req = 0.50 }
|
|
149
|
+
else if (tok == "p" || tok == "k" || tok == "port" || tok == "ports") { req = -1 }
|
|
150
|
+
else if (tok in fl) { req = fl[tok] }
|
|
151
|
+
else {
|
|
152
|
+
for (k in fl) if (index(k, tok) == 1 && fl[k] > req) req = fl[k]
|
|
153
|
+
}
|
|
154
|
+
if (req >= 0) {
|
|
155
|
+
if (val ~ /^[-+]?(inf(inity)?|nan)$/) { print seg; exit 0 }
|
|
156
|
+
nv = val + 0.0
|
|
157
|
+
if (nv != nv || nv + 1.0 == nv && (nv > 1e307 || nv < -1e307) || nv < req) { print seg; exit 0 }
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
')"
|
|
162
|
+
[[ -z "$min_hit" ]] || block "$min_hit"
|
|
116
163
|
fi
|
|
117
164
|
|
|
118
165
|
branch_rules="$(printf '%s\n' "$clean_patterns" | grep -E '^@branch ' || true)"
|
|
@@ -72,6 +72,41 @@ function resolveEffectiveCwd(line: string, matchStart: number, matchText: string
|
|
|
72
72
|
return cwd;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
const METRIC_FLOORS: Record<string, number> = {
|
|
76
|
+
iou: 0.5, ssim: 0.5, dice: 0.5, f1: 0.5, auc: 0.5,
|
|
77
|
+
accuracy: 0.5, acc: 0.5, precision: 0.5, recall: 0.5,
|
|
78
|
+
fidelity: 0.5, similarity: 0.5, coverage: 0.5, "pass-rate": 0.5, "win-rate": 0.5,
|
|
79
|
+
clip: 0.15, "clip-score": 0.15, ap: 0.15, map: 0.15, bleu: 0.15, rouge: 0.15,
|
|
80
|
+
psnr: 10.0, protrusion: 0.02, score: 0.05, confidence: 0.05, symmetry: 0.05, "cov-fail-under": 50.0,
|
|
81
|
+
};
|
|
82
|
+
const MIN_FLAG_RE =
|
|
83
|
+
/(?:^|[ ;&|(])(['"]?--(?:(?:gate-)?mi(?:n(?:-([A-Za-z0-9_-]*))?)?|(cov-fail-under))['"]?(?: +|=)["']? *([-+]?(?:inf(?:inity)?|nan|(?:\d[\d_]*\.?[\d_]*|\.[\d_]+)(?:[eE][-+]?[\d_]+)?)) *["']?)(?= |;|&|\||\)|$)/gi;
|
|
84
|
+
|
|
85
|
+
function parseGuardFloat(raw: string): number {
|
|
86
|
+
const c = raw.trim().replace(/_/g, "");
|
|
87
|
+
if (/^[-+]?inf(?:inity)?$/i.test(c)) return c.startsWith("-") ? -Infinity : Infinity;
|
|
88
|
+
if (/^[-+]?nan$/i.test(c)) return NaN;
|
|
89
|
+
return Number(c);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function findSubFloorMinFlag(line: string): string | undefined {
|
|
93
|
+
MIN_FLAG_RE.lastIndex = 0;
|
|
94
|
+
let m: RegExpExecArray | null;
|
|
95
|
+
while ((m = MIN_FLAG_RE.exec(line)) !== null) {
|
|
96
|
+
const tok = (m[3] || m[2] || "").toLowerCase().replace(/_/g, "-");
|
|
97
|
+
if (tok === "p" || tok === "k" || tok === "port" || tok === "ports") continue;
|
|
98
|
+
let floor: number | undefined = !tok ? 0.5 : Object.hasOwn(METRIC_FLOORS, tok) ? METRIC_FLOORS[tok] : undefined;
|
|
99
|
+
if (floor === undefined) {
|
|
100
|
+
for (const [k, v] of Object.entries(METRIC_FLOORS)) {
|
|
101
|
+
if (k.startsWith(tok) && (floor === undefined || v > floor)) floor = v;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const val = parseGuardFloat(m[4]);
|
|
105
|
+
if (floor !== undefined && (!Number.isFinite(val) || val < floor)) return m[1].trim();
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
75
110
|
const watched: Record<string, string> = { bash: "command", eval: "code" };
|
|
76
111
|
|
|
77
112
|
export default function gitGuard(pi: {
|
|
@@ -94,10 +129,21 @@ export default function gitGuard(pi: {
|
|
|
94
129
|
.replace(/\t/g, " ")
|
|
95
130
|
.split(/\r?\n/);
|
|
96
131
|
const branchCache = new Map<string, string | undefined>();
|
|
132
|
+
for (const rawLine of lines) {
|
|
133
|
+
const line = rawLine.replace(/(-m|--message)(=| +)("[^"]*"|'[^']*')/g, '$1 ""');
|
|
134
|
+
if (/^ *(grep|rg|echo|printf) +[^;&|<>()`$]*$/.test(line)) continue;
|
|
135
|
+
const minHit = findSubFloorMinFlag(line);
|
|
136
|
+
if (minHit) {
|
|
137
|
+
return {
|
|
138
|
+
block: true,
|
|
139
|
+
reason: `Blocked by anti-reward-hacking guard: "${minHit}" sets a quality threshold below its metric floor.`,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
97
143
|
for (const rule of rules) {
|
|
98
144
|
for (const rawLine of lines) {
|
|
99
145
|
const line = rawLine.replace(/(-m|--message)(=| +)("[^"]*"|'[^']*')/g, '$1 ""');
|
|
100
|
-
if (/^ *(grep|rg) +[
|
|
146
|
+
if (/^ *(grep|rg|echo|printf) +[^;&|<>()`$]*$/.test(line)) continue;
|
|
101
147
|
const hit = rule.command.exec(line);
|
|
102
148
|
if (!hit) continue;
|
|
103
149
|
if (rule.branch) {
|
|
@@ -111,7 +157,7 @@ export default function gitGuard(pi: {
|
|
|
111
157
|
}
|
|
112
158
|
if (!branch || !rule.branch.test(branch)) continue;
|
|
113
159
|
}
|
|
114
|
-
const isRewardHack =
|
|
160
|
+
const isRewardHack = !/^ *git +(reset|clean|checkout|restore|stash|worktree|branch|filter|update-ref|reflog|gc|push)\b/.test(hit[0]) && (/--|jest|vitest|playwright|insta|SNAPSHOT|go +test|reward-guard|contract-lock|judge_verdicts|record-judge| -n( |$)/.test(hit[0]));
|
|
115
161
|
return {
|
|
116
162
|
block: true,
|
|
117
163
|
reason: isRewardHack
|
|
@@ -216,6 +216,10 @@ def validate_workflow(doc: dict) -> list[str]:
|
|
|
216
216
|
for si, st in enumerate(steps):
|
|
217
217
|
if not isinstance(st, dict) or not st.get("run"):
|
|
218
218
|
errors.append(f"job `{jid}` step[{si}] missing `run` command")
|
|
219
|
+
elif st.get("continue-on-error") is True and not (
|
|
220
|
+
job.get("allow-soft-fail") is True or doc.get("allow-soft-fail") is True
|
|
221
|
+
):
|
|
222
|
+
errors.append(f"job `{jid}` step[{si}] uses `continue-on-error: true` without `allow-soft-fail: true`")
|
|
219
223
|
if "timeout-minutes" in job:
|
|
220
224
|
try:
|
|
221
225
|
if float(job["timeout-minutes"]) <= 0:
|
|
@@ -285,11 +289,14 @@ def plan_dag(doc: dict, target_job: str | None = None) -> list[list[str]]:
|
|
|
285
289
|
def compute_job_merkle(root: Path, jid: str, job: dict, global_env: dict) -> str:
|
|
286
290
|
"""Content-hash job steps, env, and matched `inputs` globs for O(1) skip caching."""
|
|
287
291
|
h = hashlib.sha256()
|
|
292
|
+
h.update(b"executed-test-count-v1\0")
|
|
288
293
|
h.update(jid.encode("utf-8"))
|
|
289
294
|
h.update(json.dumps(global_env, sort_keys=True).encode("utf-8"))
|
|
290
295
|
h.update(json.dumps(job.get("env") or {}, sort_keys=True).encode("utf-8"))
|
|
291
296
|
for st in job.get("steps") or []:
|
|
292
297
|
h.update(str(st.get("run", "")).encode("utf-8"))
|
|
298
|
+
h.update(b"\x01" if st.get("continue-on-error") is True else b"\x00")
|
|
299
|
+
h.update(b"\x01" if st.get("allow_zero_tests") is True else b"\x00")
|
|
293
300
|
patterns = job.get("inputs") or []
|
|
294
301
|
if isinstance(patterns, str):
|
|
295
302
|
patterns = [patterns]
|
|
@@ -335,6 +342,15 @@ def _save_cache(root: Path, cache: dict) -> None:
|
|
|
335
342
|
p.write_text(json.dumps(cache, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
336
343
|
|
|
337
344
|
|
|
345
|
+
def _ci_note(pm, summary: dict) -> str:
|
|
346
|
+
status = "PASS" if summary["ok"] else "FAIL"
|
|
347
|
+
jobs_txt = ", ".join(f"{j['id']}={j['status']}({j['seconds']}s)" for j in summary["jobs"])
|
|
348
|
+
note = f"Local CI {status} ({summary['seconds']}s): {jobs_txt}"
|
|
349
|
+
if pm.note_violations(key="ci:last-run", kind="ci_result", content=note, tags="ci,gate", source=summary["file"]):
|
|
350
|
+
return f"Local CI {status} ({summary['seconds']}s): {len(summary['jobs'])} job(s); see {summary['file']}"
|
|
351
|
+
return note
|
|
352
|
+
|
|
353
|
+
|
|
338
354
|
def _record_memory(root: Path, summary: dict) -> None:
|
|
339
355
|
mem_script = ASSETS_DIR / "memory" / "project_memory.py"
|
|
340
356
|
if not mem_script.is_file():
|
|
@@ -343,8 +359,6 @@ def _record_memory(root: Path, summary: dict) -> None:
|
|
|
343
359
|
spec = importlib.util.spec_from_file_location("deepmode_project_memory", mem_script)
|
|
344
360
|
mod = importlib.util.module_from_spec(spec)
|
|
345
361
|
spec.loader.exec_module(mod)
|
|
346
|
-
status = "PASS" if summary["ok"] else "FAIL"
|
|
347
|
-
jobs_txt = ", ".join(f"{j['id']}={j['status']}({j['seconds']}s)" for j in summary["jobs"])
|
|
348
362
|
mod.put_memory(
|
|
349
363
|
root,
|
|
350
364
|
key="ci:last-run",
|
|
@@ -352,7 +366,7 @@ def _record_memory(root: Path, summary: dict) -> None:
|
|
|
352
366
|
priority=1,
|
|
353
367
|
tags="ci,gate",
|
|
354
368
|
source=summary["file"],
|
|
355
|
-
content=
|
|
369
|
+
content=_ci_note(mod, summary),
|
|
356
370
|
)
|
|
357
371
|
except (OSError, ImportError, ValueError) as exc:
|
|
358
372
|
print(f"warning: memory record skipped: {exc}", file=sys.stderr)
|
|
@@ -378,6 +392,240 @@ def _build_step_env(root: Path, global_env: dict, job_env: dict) -> dict:
|
|
|
378
392
|
env[str(k)] = str(v)
|
|
379
393
|
return env
|
|
380
394
|
|
|
395
|
+
|
|
396
|
+
_PYTHON_EXE = re.compile(r"python(?:[0-9]+(?:\.[0-9]+)*)?")
|
|
397
|
+
_NODE_VALUE_OPTIONS = {
|
|
398
|
+
"-r", "--require", "--import", "--loader", "--experimental-loader", "-C", "--conditions",
|
|
399
|
+
"--test-reporter", "--test-reporter-destination", "--test-name-pattern",
|
|
400
|
+
}
|
|
401
|
+
_SGR = re.compile(r"\x1b\[[0-9;]*m")
|
|
402
|
+
_RAN, _ZERO, _ERROR = 1, 2, 4
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _test_runner(words: list[str]) -> str | None:
|
|
406
|
+
while words:
|
|
407
|
+
exe = re.split(r"[/\\]", words[0])[-1].lower()
|
|
408
|
+
exe = exe.removesuffix(".exe").removesuffix(".cmd").removesuffix(".bat")
|
|
409
|
+
if "=" in words[0] or exe in ("env", "call", "npx"):
|
|
410
|
+
words = words[1:]
|
|
411
|
+
elif (exe in ("uv", "poetry", "npm", "pnpm", "yarn") and words[1:2] == ["exec"]
|
|
412
|
+
or exe in ("uv", "poetry") and words[1:2] == ["run"]):
|
|
413
|
+
words = words[2:]
|
|
414
|
+
else:
|
|
415
|
+
break
|
|
416
|
+
else:
|
|
417
|
+
return None
|
|
418
|
+
args = words[1:]
|
|
419
|
+
if exe == "py" or _PYTHON_EXE.fullmatch(exe):
|
|
420
|
+
skip = False
|
|
421
|
+
for i, word in enumerate(args):
|
|
422
|
+
if skip:
|
|
423
|
+
skip = False
|
|
424
|
+
continue
|
|
425
|
+
if word == "-m":
|
|
426
|
+
module = args[i + 1:i + 2]
|
|
427
|
+
return module[0] if module in (["pytest"], ["unittest"]) else None
|
|
428
|
+
if word in ("-", "--", "-c") or not word.startswith("-"):
|
|
429
|
+
return None
|
|
430
|
+
skip = word in ("-W", "-X")
|
|
431
|
+
elif exe == "pytest":
|
|
432
|
+
return exe
|
|
433
|
+
elif exe in ("jest", "vitest"):
|
|
434
|
+
return "jest/vitest"
|
|
435
|
+
elif exe == "node":
|
|
436
|
+
skip = False
|
|
437
|
+
for word in args:
|
|
438
|
+
if skip:
|
|
439
|
+
skip = False
|
|
440
|
+
continue
|
|
441
|
+
if word == "--test":
|
|
442
|
+
return exe
|
|
443
|
+
if not word.startswith("-") or word in ("--", "-", "-e", "--eval", "-p", "--print"):
|
|
444
|
+
break
|
|
445
|
+
skip = word in _NODE_VALUE_OPTIONS
|
|
446
|
+
elif exe in ("npm", "pnpm", "yarn"):
|
|
447
|
+
while args and args[0].startswith("-"):
|
|
448
|
+
args = args[2:] if args[0] in ("--prefix", "--filter", "--dir", "--cwd", "-C", "-w", "--workspace") else args[1:]
|
|
449
|
+
if args[:1] == ["run"]:
|
|
450
|
+
args = args[1:]
|
|
451
|
+
if args[:1] in (["test"], ["t"]):
|
|
452
|
+
return "package-manager"
|
|
453
|
+
elif exe == "cargo":
|
|
454
|
+
if args and args[0].startswith("+"):
|
|
455
|
+
args = args[1:]
|
|
456
|
+
if args[:1] == ["test"]:
|
|
457
|
+
return exe
|
|
458
|
+
elif exe == "go" and args[:1] == ["-C"] and args[2:3] == ["test"]:
|
|
459
|
+
return exe
|
|
460
|
+
elif exe in ("go", "dotnet") and args[:1] == ["test"]:
|
|
461
|
+
return exe
|
|
462
|
+
elif exe in ("mvn", "mvnw") and "test" in args:
|
|
463
|
+
return "maven"
|
|
464
|
+
elif exe in ("gradle", "gradlew") and any(word.rsplit(":", 1)[-1] == "test" for word in args):
|
|
465
|
+
return "gradle"
|
|
466
|
+
return None
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def _test_runners(command: str) -> set[str]:
|
|
470
|
+
runners: set[str] = set()
|
|
471
|
+
words: list[str] = []
|
|
472
|
+
start = 0
|
|
473
|
+
quote = None
|
|
474
|
+
at_redirect = escaped = comment = False
|
|
475
|
+
for i, char in enumerate(command + "\n"):
|
|
476
|
+
if comment and char != "\n":
|
|
477
|
+
continue
|
|
478
|
+
if escaped:
|
|
479
|
+
escaped = False
|
|
480
|
+
continue
|
|
481
|
+
if char == "\\" and quote != "'" and command[i + 1:i + 2] in ("\\", "'", '"', ";", "&", "|", "\n", " "):
|
|
482
|
+
escaped = True
|
|
483
|
+
elif quote:
|
|
484
|
+
if char == quote:
|
|
485
|
+
quote = None
|
|
486
|
+
elif char in ("'", '"'):
|
|
487
|
+
quote = char
|
|
488
|
+
elif char == "#" and start == i:
|
|
489
|
+
comment = True
|
|
490
|
+
elif char.isspace() or char in ";&|<>":
|
|
491
|
+
if start != i and not (at_redirect or comment):
|
|
492
|
+
words.append(command[start:i].strip("'\""))
|
|
493
|
+
start = i + 1
|
|
494
|
+
if char in "\n;&|":
|
|
495
|
+
if runner := _test_runner(words):
|
|
496
|
+
runners.add(runner)
|
|
497
|
+
words.clear()
|
|
498
|
+
at_redirect = comment = False
|
|
499
|
+
elif char in "<>":
|
|
500
|
+
at_redirect = True
|
|
501
|
+
return runners
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def _count_after(line: str, label: str) -> int | None:
|
|
505
|
+
_, found, rest = line.partition(label)
|
|
506
|
+
digits = re.match(r"[0-9]+", rest.lstrip()) if found else None
|
|
507
|
+
return int(digits[0]) if digits and len(digits[0]) < 20 else None
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def _count_before(line: str, label: str) -> int | None:
|
|
511
|
+
before, found, _ = line.partition(label)
|
|
512
|
+
words = before.split()
|
|
513
|
+
if not found or not words or not re.fullmatch(r"[0-9]{1,19}", words[-1]):
|
|
514
|
+
return None
|
|
515
|
+
return int(words[-1])
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def _count_report(count: int | None) -> int:
|
|
519
|
+
return 0 if count is None else (_RAN if count else _ZERO)
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def _test_report(runner: str, line: str) -> int:
|
|
523
|
+
if runner == "pytest":
|
|
524
|
+
if (line.startswith(("error collecting ", "error: ")) or " during collection" in line
|
|
525
|
+
and (" error" in line or line.startswith("error"))):
|
|
526
|
+
return _ERROR
|
|
527
|
+
if line.startswith(("collected 0 items", "no tests ran")) or " / 0 selected" in line:
|
|
528
|
+
return _ZERO
|
|
529
|
+
summary = line.split(" in ", 1)[0]
|
|
530
|
+
if re.match(r"^[0-9]+ (?:passed|failed|skipped|deselected|xfailed|xpassed|errors?)\b", summary):
|
|
531
|
+
return _RAN if any(_count_before(summary, f" {word}") for word in ("passed", "failed", "xfailed", "xpassed")) else _ZERO
|
|
532
|
+
elif runner == "unittest":
|
|
533
|
+
if line.startswith(("error: ", "failed (errors=")):
|
|
534
|
+
return _ERROR
|
|
535
|
+
if line.startswith("ran ") and " test" in line:
|
|
536
|
+
return _count_report(_count_after(line, "ran "))
|
|
537
|
+
elif runner == "node":
|
|
538
|
+
for prefix in ("# ", "ℹ "):
|
|
539
|
+
if line.startswith(prefix + "tests "):
|
|
540
|
+
return _count_report(_count_after(line, prefix + "tests "))
|
|
541
|
+
if line.startswith(prefix + "pass ") and _count_after(line, prefix + "pass ") == 0:
|
|
542
|
+
return _ZERO
|
|
543
|
+
elif runner == "jest/vitest":
|
|
544
|
+
if line.startswith(("test suite failed to run", "error: failed to load config", "unhandled errors")):
|
|
545
|
+
return _ERROR
|
|
546
|
+
if line.startswith(("no tests found", "no test files found")):
|
|
547
|
+
return _ZERO
|
|
548
|
+
if line.startswith(("tests:", "tests ")):
|
|
549
|
+
return _RAN if any(_count_before(line, f" {word}") for word in ("passed", "failed")) else _ZERO
|
|
550
|
+
elif runner == "cargo":
|
|
551
|
+
if line.startswith(("error: could not compile", "error[", "error: aborting")):
|
|
552
|
+
return _ERROR
|
|
553
|
+
if line.startswith("test result:"):
|
|
554
|
+
return _RAN if any(_count_before(line, f" {word};") for word in ("passed", "failed")) else _ZERO
|
|
555
|
+
elif runner == "go":
|
|
556
|
+
if line.startswith(("fail ", "fail\t")) and ("[build failed]" in line or "[setup failed]" in line):
|
|
557
|
+
return _ERROR
|
|
558
|
+
if line.startswith(("ok ", "ok\t")):
|
|
559
|
+
fields = line.split()
|
|
560
|
+
if (len(fields) >= 3 and (fields[2] == "(cached)" or re.fullmatch(r"[0-9]+\.[0-9]+s", fields[2]))
|
|
561
|
+
and "[no tests to run]" not in line):
|
|
562
|
+
return _RAN
|
|
563
|
+
if line.startswith("--- pass:"):
|
|
564
|
+
return _RAN
|
|
565
|
+
elif runner == "dotnet":
|
|
566
|
+
if line.startswith(("error ", "error:", "build failed")) or ": error " in line:
|
|
567
|
+
return _ERROR
|
|
568
|
+
if line.startswith(("passed!", "failed!", "skipped!", "test summary:")):
|
|
569
|
+
return _RAN if any(_count_after(line, label) for label in ("failed:", "passed:", "succeeded:")) else _ZERO
|
|
570
|
+
elif runner == "maven":
|
|
571
|
+
line = line.removeprefix("[info]").lstrip()
|
|
572
|
+
if line.startswith(("[error]", "build failure")):
|
|
573
|
+
return _ERROR
|
|
574
|
+
if line.startswith("tests run:"):
|
|
575
|
+
return _RAN if (_count_after(line, "tests run:") or 0) > (_count_after(line, "skipped:") or 0) else _ZERO
|
|
576
|
+
elif runner == "gradle":
|
|
577
|
+
if line.startswith(("build failed", "compilation failed", "failure: build failed")):
|
|
578
|
+
return _ERROR
|
|
579
|
+
if " > " in line and line.endswith((" passed", " failed")):
|
|
580
|
+
return _RAN
|
|
581
|
+
if " tests completed" in line:
|
|
582
|
+
return _count_report(_count_before(line, " tests completed"))
|
|
583
|
+
return 0
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
_REPORTERS = ("pytest", "unittest", "node", "jest/vitest", "cargo", "go", "dotnet", "maven", "gradle")
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _executed_tests(runner: str, report: int) -> bool:
|
|
590
|
+
aggregate = runner in ("cargo", "go", "dotnet", "maven", "gradle")
|
|
591
|
+
return bool(report & _RAN and (aggregate or not report & _ZERO))
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
def _go_json_report(line: str) -> int:
|
|
595
|
+
try:
|
|
596
|
+
event = json.loads(line)
|
|
597
|
+
except ValueError:
|
|
598
|
+
return 0
|
|
599
|
+
if event.get("Action") == "build-fail":
|
|
600
|
+
return _ERROR
|
|
601
|
+
if event.get("Action") == "pass" and isinstance(event.get("Test"), str) and event["Test"]:
|
|
602
|
+
return _RAN
|
|
603
|
+
return 0
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def _test_count_failure(command: str, output: str) -> str | None:
|
|
607
|
+
runners = _test_runners(command)
|
|
608
|
+
if not runners:
|
|
609
|
+
return None
|
|
610
|
+
wrapped = "package-manager" in runners
|
|
611
|
+
reports = {name: 0 for name in _REPORTERS if wrapped or name in runners}
|
|
612
|
+
for raw in output.splitlines():
|
|
613
|
+
line = _SGR.sub("", raw).strip().strip("=").strip()
|
|
614
|
+
if "go" in reports and line.startswith("{"):
|
|
615
|
+
reports["go"] |= _go_json_report(line)
|
|
616
|
+
line = line.lower()
|
|
617
|
+
for runner in reports:
|
|
618
|
+
reports[runner] |= _test_report(runner, line)
|
|
619
|
+
for runner, report in reports.items():
|
|
620
|
+
if report & _ERROR:
|
|
621
|
+
return f"Test runner reported a collection or build failure: {runner}."
|
|
622
|
+
if runner in runners and not _executed_tests(runner, report):
|
|
623
|
+
return f"Test runner did not report any executed tests: {runner}."
|
|
624
|
+
if wrapped and not any(_executed_tests(name, report) for name, report in reports.items()):
|
|
625
|
+
return "Test runner did not report any executed tests: package-manager."
|
|
626
|
+
return None
|
|
627
|
+
|
|
628
|
+
|
|
381
629
|
def _run_job(root: Path, jid: str, job: dict, global_env: dict, use_cache: bool, cache: dict) -> dict:
|
|
382
630
|
started = time.monotonic()
|
|
383
631
|
merkle = compute_job_merkle(root, jid, job, global_env) if job.get("inputs") else None
|
|
@@ -392,6 +640,7 @@ def _run_job(root: Path, jid: str, job: dict, global_env: dict, use_cache: bool,
|
|
|
392
640
|
sname = str(step.get("name") or f"step-{idx + 1}")
|
|
393
641
|
cmd = str(step["run"])
|
|
394
642
|
st_start = time.monotonic()
|
|
643
|
+
failure = None
|
|
395
644
|
try:
|
|
396
645
|
proc = subprocess.run(
|
|
397
646
|
cmd, shell=True, cwd=str(root), env=env,
|
|
@@ -399,13 +648,18 @@ def _run_job(root: Path, jid: str, job: dict, global_env: dict, use_cache: bool,
|
|
|
399
648
|
timeout=timeout_sec, creationflags=NO_WINDOW,
|
|
400
649
|
)
|
|
401
650
|
rc = proc.returncode
|
|
402
|
-
|
|
651
|
+
output = proc.stdout + "\n" + proc.stderr
|
|
652
|
+
if rc == 0 and step.get("allow_zero_tests") is not True:
|
|
653
|
+
failure = _test_count_failure(cmd, output)
|
|
654
|
+
tail = output.strip()[-600:]
|
|
655
|
+
if failure:
|
|
656
|
+
rc = 1
|
|
657
|
+
tail = f"{failure}\n{tail}".rstrip()
|
|
403
658
|
except subprocess.TimeoutExpired:
|
|
404
659
|
rc = 124
|
|
405
660
|
tail = f"timed out after {timeout_sec:.0f}s"
|
|
406
661
|
dur = round(time.monotonic() - st_start, 2)
|
|
407
|
-
|
|
408
|
-
passed = rc == 0 or cont
|
|
662
|
+
passed = failure is None and (rc == 0 or step.get("continue-on-error") is True)
|
|
409
663
|
step_results.append({"name": sname, "exit_code": rc, "ok": passed, "seconds": dur, "tail": "" if passed else tail})
|
|
410
664
|
if not passed:
|
|
411
665
|
job_ok = False
|
|
@@ -527,6 +781,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
527
781
|
print(json.dumps(res, indent=2))
|
|
528
782
|
else:
|
|
529
783
|
print(f"local-ci [{res.get('name', 'ci')}]: {'OK' if res['ok'] else 'FAILED'} ({res['seconds']}s)")
|
|
784
|
+
for error in res.get("errors", []):
|
|
785
|
+
print(f" - {error}")
|
|
530
786
|
for j in res["jobs"]:
|
|
531
787
|
print(f" - {j['id']}: {j['status']} ({j['seconds']}s)")
|
|
532
788
|
for s in j["steps"]:
|