@memnexus-ai/mx-agent-cli 0.1.267 → 0.1.269
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.
|
@@ -108,7 +108,22 @@ trap '_mxht_emit || :' EXIT
|
|
|
108
108
|
# Fail-open: any unexpected error → let the push through. NOTE: the two
|
|
109
109
|
# deliberately fail-CLOSED paths (lock timeout, confirmed real regression) use
|
|
110
110
|
# explicit `exit 2` inside conditionals, so the ERR trap never downgrades them.
|
|
111
|
-
|
|
111
|
+
#
|
|
112
|
+
# #4575 Phase 1: the trap now REPORTS before exiting. The fail-open posture is
|
|
113
|
+
# unchanged (still `exit 0`) — this only removes the silence. Previously an
|
|
114
|
+
# untrapped non-zero at top level (e.g. a failing `jq` in a command
|
|
115
|
+
# substitution) exited 0 with no output at all, so "the hook passed" was
|
|
116
|
+
# indistinguishable from "the hook never ran". $LINENO inside an ERR trap
|
|
117
|
+
# resolves to the line of the command that fired it.
|
|
118
|
+
#
|
|
119
|
+
# SCOPE — this trap is NOT `set -E`, so it is not inherited by shell functions,
|
|
120
|
+
# subshells, or command substitutions. It fires only on a non-zero returned at
|
|
121
|
+
# TOP LEVEL. A command that fails inside a function body (including inside
|
|
122
|
+
# run_validate) returns normally and the trap never sees it. Do not read this
|
|
123
|
+
# trap as blanket internal-error coverage; it covers the top-level script only.
|
|
124
|
+
# Verified, not assumed: with this exact trap and no `set -E`, `((V++))` at V=0
|
|
125
|
+
# inside a function does not fire it, while the same statement at top level does.
|
|
126
|
+
trap 'echo "ci-validate: INTERNAL ERROR at line $LINENO — validation SKIPPED, push NOT gated." >&2; exit 0' ERR
|
|
112
127
|
set -u # Catch undefined variable references (typos silently expand to empty otherwise)
|
|
113
128
|
|
|
114
129
|
# ── State directory (SF-3: no predictable /tmp paths) ─────────────────────────
|
|
@@ -159,19 +174,41 @@ LOCK_TIMEOUT="${MX_VALIDATE_LOCK_TIMEOUT:-900}" # seconds to wait in qu
|
|
|
159
174
|
# + first pass CV_VALIDATE_TIMEOUT_SECS 600s (fail-closed, below)
|
|
160
175
|
# + isolation retry CV_VALIDATE_TIMEOUT_SECS 600s (fail-closed, below)
|
|
161
176
|
# + devlog check CV_DEVLOG_TIMEOUT_SECS 60s (advisory, warn only)
|
|
162
|
-
# +
|
|
177
|
+
# + git acquisition CV_GIT_TIMEOUT_SECS x3 45s (fail-open)
|
|
163
178
|
# ────────────────────────────────────────────────
|
|
164
|
-
#
|
|
165
|
-
#
|
|
179
|
+
# 2205s floor, 1395s of headroom under the 3600s harness cap.
|
|
180
|
+
# The acquisition block is a chain of THREE bounded git invocations, not two: the
|
|
181
|
+
# primary `diff origin/main...HEAD`, plus BOTH halves of the union fallback
|
|
182
|
+
# (`show HEAD` and `diff HEAD`), each separately wrapped in `timeout`.
|
|
183
|
+
# 2205 is a LOWER BOUND, not an exact total: the shared push-target resolver adds
|
|
166
184
|
# up to MXPT_GIT_TIMEOUT_SECS (10s) per rev-parse and the segment count scales
|
|
167
185
|
# with the pushed command, so a pathological command adds more. It would take
|
|
168
|
-
# ~
|
|
186
|
+
# ~139 segments to close the 1395s of headroom, which is why the cap is 3600.
|
|
169
187
|
CV_VALIDATE_TIMEOUT_SECS="${MX_VALIDATE_TIMEOUT:-600}"
|
|
170
188
|
CV_DEVLOG_TIMEOUT_SECS="${MX_VALIDATE_DEVLOG_TIMEOUT:-60}"
|
|
171
189
|
FLAKE_LOG="${MX_VALIDATE_FLAKE_LOG:-$MX_VALIDATE_DIR/flakes.log}"
|
|
172
190
|
MAX_ISOLATE_FILES="${MX_VALIDATE_MAX_ISOLATE_FILES:-10}" # >this many failed files ⇒ real breakage
|
|
173
191
|
|
|
174
192
|
FAILED=0
|
|
193
|
+
# #4575 Phase 1: count of validate scripts we actually EXECUTED. The success
|
|
194
|
+
# banner is conditional on this being non-zero, so the hook can no longer report
|
|
195
|
+
# "all checks passed" having validated nothing.
|
|
196
|
+
#
|
|
197
|
+
# Assignment form (not `((x++))`). An earlier version of this comment gave the
|
|
198
|
+
# wrong reason: it claimed `((VALIDATED++))` would fire the ERR trap at
|
|
199
|
+
# VALIDATED=0. The post-increment does evaluate to 0 and so returns status 1,
|
|
200
|
+
# but the increment lives inside run_validate — a function — and the ERR trap is
|
|
201
|
+
# not `set -E`, so it is not inherited there and does not fire. The real reason
|
|
202
|
+
# to keep the assignment form is that it cannot return non-zero at all, so it
|
|
203
|
+
# stays correct if the increment is ever moved to top level, where the trap
|
|
204
|
+
# WOULD fire on it.
|
|
205
|
+
VALIDATED=0
|
|
206
|
+
# #4575 SF-2: count of routed packages that matched a route but were NOT
|
|
207
|
+
# validated (their validate script is missing). VALIDATED alone cannot separate
|
|
208
|
+
# "everything routed passed" from "some routed packages passed and the rest were
|
|
209
|
+
# skipped" — both leave VALIDATED non-zero, and the success banner claimed the
|
|
210
|
+
# first in both cases.
|
|
211
|
+
SKIPPED=0
|
|
175
212
|
|
|
176
213
|
# ── Parse failed test files from a runner's captured output ───────────────────
|
|
177
214
|
# jest and vitest both print "FAIL <path>" for each failing test file. Strip ANSI
|
|
@@ -272,11 +309,14 @@ run_validate() {
|
|
|
272
309
|
esac
|
|
273
310
|
if [[ ! -f "$script_path" ]]; then
|
|
274
311
|
echo "⚠ $label: $script not found — skipping" >&2
|
|
312
|
+
echo "ci-validate: WARN $label was NOT validated (validate script missing) — push NOT gated for $label." >&2
|
|
313
|
+
SKIPPED=$((SKIPPED + 1))
|
|
275
314
|
return
|
|
276
315
|
fi
|
|
277
316
|
|
|
278
317
|
echo "" >&2
|
|
279
318
|
echo "Running $label validation..." >&2
|
|
319
|
+
VALIDATED=$((VALIDATED + 1))
|
|
280
320
|
|
|
281
321
|
local out; out="$(mktemp)"
|
|
282
322
|
local rc=0
|
|
@@ -479,6 +519,21 @@ if [[ -n "${MX_VALIDATE_SELFTEST:-}" ]]; then
|
|
|
479
519
|
echo "ci-validate(selftest): FAILED" >&2
|
|
480
520
|
exit 2
|
|
481
521
|
fi
|
|
522
|
+
if [[ "$VALIDATED" -eq 0 ]]; then
|
|
523
|
+
echo "ci-validate(selftest): WARN no packages validated — nothing ran, push NOT gated." >&2
|
|
524
|
+
exit 0
|
|
525
|
+
fi
|
|
526
|
+
# #4575 NF-2: mirror the production partial-coverage banner at the bottom of
|
|
527
|
+
# this file. Before this, the seam printed the per-label WARN for a missing
|
|
528
|
+
# script and then "all checks passed" — the exact contradiction the
|
|
529
|
+
# production path was just fixed to stop emitting. The seam and production
|
|
530
|
+
# share run_validate (and therefore the SKIPPED global it increments), so
|
|
531
|
+
# the result logic must agree too, or the seam stops being a faithful
|
|
532
|
+
# stand-in for the thing it tests. Posture unchanged — still exit 0.
|
|
533
|
+
if [[ "$SKIPPED" -ne 0 ]]; then
|
|
534
|
+
echo "ci-validate(selftest): $VALIDATED of $((VALIDATED+SKIPPED)) specs validated — the rest were NOT gated (listed above)." >&2
|
|
535
|
+
exit 0
|
|
536
|
+
fi
|
|
482
537
|
echo "ci-validate(selftest): all checks passed." >&2
|
|
483
538
|
exit 0
|
|
484
539
|
fi
|
|
@@ -850,11 +905,43 @@ fi
|
|
|
850
905
|
# hold the Bash tool call open. On timeout the substitution is empty and we take
|
|
851
906
|
# the existing no-changed-files branch below: fail-open, unchanged.
|
|
852
907
|
CV_GIT_TIMEOUT_SECS="${CV_GIT_TIMEOUT_SECS:-15}"
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
908
|
+
# #4575 Phase 2: the fallback used to be `git diff --name-only HEAD`, which
|
|
909
|
+
# lists UNCOMMITTED working-tree changes — not the branch's commits. At push
|
|
910
|
+
# time the tree is normally clean, so it returned empty BY CONSTRUCTION and the
|
|
911
|
+
# gate degraded to no check at all, silently. `git show` reads the commit, so it
|
|
912
|
+
# is correct on a clean tree. `--first-parent` keeps a merge commit at HEAD from
|
|
913
|
+
# producing an empty combined diff; `-m` because `--first-parent` alone did not
|
|
914
|
+
# imply it on older git.
|
|
915
|
+
#
|
|
916
|
+
# The fallback is the UNION of both sources, not `git show` alone. They do NOT
|
|
917
|
+
# report the same files: `git show` reads the commit and cannot see uncommitted
|
|
918
|
+
# work, so a HEAD touching only docs/ with an uncommitted cli/ edit in the tree
|
|
919
|
+
# is routed by the old form and NOT by `git show`. Committed-but-unpushed work
|
|
920
|
+
# and uncommitted work are both about to matter, so both are collected and
|
|
921
|
+
# deduped rather than one replacing the other.
|
|
922
|
+
#
|
|
923
|
+
# `core.quotePath=false` on EVERY invocation: git C-quotes non-ASCII paths by
|
|
924
|
+
# default ("cli/caf\303\251.ts"), which then matches no route glob and the
|
|
925
|
+
# package is skipped. Paths with embedded newlines are still C-quoted and still
|
|
926
|
+
# unmatchable — the matcher is line-based, so that residual stays in the known
|
|
927
|
+
# issues entry rather than being chased here.
|
|
928
|
+
# `--` terminates options on each command so a path literally named `HEAD` in
|
|
929
|
+
# the tree cannot make the revision argument ambiguous.
|
|
930
|
+
#
|
|
931
|
+
# `LC_ALL=C` on the dedupe: with quotePath=false the byte stream can contain
|
|
932
|
+
# invalid-UTF-8 runs, and glibc strcoll reports two distinct such paths as EQUAL
|
|
933
|
+
# under a UTF-8 locale, so `sort -u` drops one. No coverage loss was reachable
|
|
934
|
+
# (a collapse needs a shared ASCII skeleton, and those paths match the same
|
|
935
|
+
# route glob anyway) — this pins byte ordering so the class cannot come back.
|
|
936
|
+
CHANGED_FILES=$(
|
|
937
|
+
timeout "$CV_GIT_TIMEOUT_SECS" git -C "$REPO_ROOT" -c core.quotePath=false diff --name-only "origin/main...HEAD" -- 2>/dev/null \
|
|
938
|
+
|| { timeout "$CV_GIT_TIMEOUT_SECS" git -C "$REPO_ROOT" -c core.quotePath=false show --pretty=format: --name-only --first-parent -m HEAD -- 2>/dev/null
|
|
939
|
+
timeout "$CV_GIT_TIMEOUT_SECS" git -C "$REPO_ROOT" -c core.quotePath=false diff --name-only HEAD -- 2>/dev/null; } | LC_ALL=C sort -u \
|
|
940
|
+
|| true
|
|
941
|
+
)
|
|
856
942
|
|
|
857
943
|
if [[ -z "$CHANGED_FILES" ]]; then
|
|
944
|
+
echo "ci-validate: WARN no changed files detected — validation SKIPPED, push NOT gated." >&2
|
|
858
945
|
exit 0 # No changed files detected — nothing to validate
|
|
859
946
|
fi
|
|
860
947
|
|
|
@@ -891,6 +978,7 @@ HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || echo "")"
|
|
|
891
978
|
ROUTES_FILE="${MX_CI_VALIDATE_ROUTES:-$HOOK_DIR/ci-validate-routes.conf}"
|
|
892
979
|
if [[ ! -f "$ROUTES_FILE" ]]; then
|
|
893
980
|
echo "ci-validate: routing table not found ($ROUTES_FILE) — skipping validation (fail-open, no packages routed)." >&2
|
|
981
|
+
echo "ci-validate: WARN validation SKIPPED, push NOT gated." >&2
|
|
894
982
|
exit 0
|
|
895
983
|
fi
|
|
896
984
|
|
|
@@ -924,8 +1012,14 @@ for ((ri=0; ri<${#R_PREFIX[@]}; ri++)); do
|
|
|
924
1012
|
done <<< "$CHANGED_FILES"
|
|
925
1013
|
done
|
|
926
1014
|
|
|
927
|
-
# Nothing relevant changed
|
|
1015
|
+
# Nothing relevant changed. This was the last remaining SILENT fail-open: it
|
|
1016
|
+
# covers both "the change genuinely touches no routed package" and "every
|
|
1017
|
+
# changed path failed to match for a reason the hook cannot see" (a C-quoted
|
|
1018
|
+
# path, a route glob that no longer matches the tree layout). The two are
|
|
1019
|
+
# indistinguishable from here, and the second one is a gate that did not run, so
|
|
1020
|
+
# say so instead of exiting with no output. Posture unchanged — still exit 0.
|
|
928
1021
|
if [[ ${#MATCHED_IDX[@]} -eq 0 ]]; then
|
|
1022
|
+
echo "ci-validate: WARN no changed file matched any route — validation SKIPPED, push NOT gated." >&2
|
|
929
1023
|
exit 0
|
|
930
1024
|
fi
|
|
931
1025
|
|
|
@@ -953,5 +1047,22 @@ if [[ $FAILED -ne 0 ]]; then
|
|
|
953
1047
|
fi
|
|
954
1048
|
|
|
955
1049
|
echo "" >&2
|
|
1050
|
+
# #4575 Phase 1: only claim success if at least one validate script actually
|
|
1051
|
+
# ran. Every route can match and still validate NOTHING (e.g. the routed script
|
|
1052
|
+
# is missing), and the old unconditional banner reported "all checks passed" on
|
|
1053
|
+
# exactly that path. Posture is unchanged — still exit 0 either way.
|
|
1054
|
+
if [[ "$VALIDATED" -eq 0 ]]; then
|
|
1055
|
+
echo "ci-validate: WARN no packages validated — nothing ran, push NOT gated." >&2
|
|
1056
|
+
exit 0
|
|
1057
|
+
fi
|
|
1058
|
+
# #4575 SF-2: the VALIDATED-eq-0 guard above only catches the all-skipped case.
|
|
1059
|
+
# With two routes matched, one script present and passing and one missing,
|
|
1060
|
+
# VALIDATED is 1 and the banner claimed "all checks passed" — the per-label WARN
|
|
1061
|
+
# was printed three lines earlier and then contradicted. Report the coverage
|
|
1062
|
+
# instead of a blanket pass. Posture unchanged — still exit 0.
|
|
1063
|
+
if [[ "$SKIPPED" -ne 0 ]]; then
|
|
1064
|
+
echo "ci-validate: $VALIDATED of $((VALIDATED+SKIPPED)) routed packages validated — the rest were NOT gated (listed above)." >&2
|
|
1065
|
+
exit 0
|
|
1066
|
+
fi
|
|
956
1067
|
echo "ci-validate: all checks passed." >&2
|
|
957
1068
|
exit 0
|