From c96e06f0e2201fb64c6167b3d7e8c6214bc60dc6 Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Mon, 26 Oct 2026 07:33:28 -0700 Subject: [PATCH 1/5] fix: isolate local validation and guard empty extraction data Signed-off-by: DavidHLP --- internal/cbm/doclink_perl.c | 7 ++++++- src/mcp/mcp.c | 12 ++++++++---- src/pipeline/doc_links_perl.c | 4 +++- tests/test_main.c | 12 +++++------- tests/test_mcp.c | 3 ++- tests/test_smoke_fixture_contract.sh | 4 +++- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/internal/cbm/doclink_perl.c b/internal/cbm/doclink_perl.c index 42bdb72de0..192dfff4e9 100644 --- a/internal/cbm/doclink_perl.c +++ b/internal/cbm/doclink_perl.c @@ -1538,6 +1538,9 @@ static int pl_pkg_order_cmp(const void *a, const void *b) { /* Give every declaration the index of its name's P record (names in order of * their first declaration) and write the P records. */ static void pl_number_packages(pl_walk_t *w, pl_sb_t *sb) { + if (w->npkgs == 0) { + return; + } qsort(w->pkgs, (size_t)w->npkgs, sizeof(pl_pkg_t), pl_pkg_name_cmp); for (int i = 0; i < w->npkgs; i++) { /* index = order of the name's first declaration */ bool repeat = @@ -1572,7 +1575,9 @@ static int pl_subdecl_cmp(const void *a, const void *b) { /* One S record per sub definition of the file, with the package the tree * places it in. */ static void pl_put_subs(CBMExtractCtx *ctx, pl_walk_t *w, pl_sb_t *sb) { - qsort(w->subs, (size_t)w->nsubs, sizeof(pl_subdecl_t), pl_subdecl_cmp); + if (w->nsubs > SKIP_ONE) { + qsort(w->subs, (size_t)w->nsubs, sizeof(pl_subdecl_t), pl_subdecl_cmp); + } const CBMDefArray *defs = &ctx->result->defs; for (int i = 0; i < defs->count; i++) { const CBMDefinition *d = &defs->items[i]; diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c index 419ed0d1fb..7e495a84be 100644 --- a/src/mcp/mcp.c +++ b/src/mcp/mcp.c @@ -20753,13 +20753,17 @@ static char *handle_detect_changes(cbm_mcp_server_t *srv, const char *args) { char hunk_cmd[CBM_SZ_2K]; #ifdef _WIN32 snprintf(hunk_cmd, sizeof(hunk_cmd), - "git -C \"%s\" diff --relative --unified=0 \"%s\" \"%s\" -- 2>NUL && " - "git -C \"%s\" diff --relative --unified=0 -- 2>NUL", + "git -C \"%s\" " CBM_TEST_IMPACT_GIT_PINS + " diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " \"%s\" \"%s\" -- 2>NUL && " + "git -C \"%s\" " CBM_TEST_IMPACT_GIT_PINS + " diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " -- 2>NUL", root_path, merge_base, head_oid, root_path); #else snprintf(hunk_cmd, sizeof(hunk_cmd), - "git -C '%s' diff --relative --unified=0 '%s' '%s' -- 2>/dev/null && " - "git -C '%s' diff --relative --unified=0 -- 2>/dev/null", + "git -C '%s' " CBM_TEST_IMPACT_GIT_PINS + " diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " '%s' '%s' -- 2>/dev/null && " + "git -C '%s' " CBM_TEST_IMPACT_GIT_PINS + " diff --relative " CBM_TEST_IMPACT_DIFF_FLAGS " -- 2>/dev/null", root_path, merge_base, head_oid, root_path); #endif char hunk_output_path[CBM_SZ_2K] = {0}; diff --git a/src/pipeline/doc_links_perl.c b/src/pipeline/doc_links_perl.c index 27ba5a9eb2..2c542d6e7e 100644 --- a/src/pipeline/doc_links_perl.c +++ b/src/pipeline/doc_links_perl.c @@ -244,7 +244,9 @@ static bool pr_index_packages(pr_index_t *ix, const cbm_doclink_build_in_t *in) if (ix->oom) { return false; } - qsort(ix->decls, (size_t)ix->ndecls, sizeof(pr_decl_t), pr_decl_cmp); + if (ix->ndecls > SKIP_ONE) { + qsort(ix->decls, (size_t)ix->ndecls, sizeof(pr_decl_t), pr_decl_cmp); + } ix->pkg = cbm_ht_create_in(CBM_MEM_CLASS_OTHER, (uint32_t)(ix->ndecls + SKIP_ONE)); if (!ix->pkg) { return false; diff --git a/tests/test_main.c b/tests/test_main.c index 4b3716c50c..1c812ea78b 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -212,14 +212,12 @@ static void tf_cleanup_cache_sentinel(void) { } } -/* Client home overrides the CLI honours BEFORE $HOME, so redirecting HOME alone - * does not isolate them: cbm_codex_config_dir() and its siblings return the - * ambient path and the suite resolves against the developer's real config — - * reading its state and writing to it. Same inventory the shell fixtures are - * already required to neutralize (tests/test_smoke_fixture_contract.sh), kept - * in one place so a new client cannot be isolated in the smoke scripts and - * forgotten here. A test that exercises one of these sets it after setup. */ +/* These paths take precedence over HOME and can escape the private fixture. + * A test that exercises an override sets it after setup. */ static const char *const tf_client_home_overrides[] = { + "XDG_CONFIG_HOME", + "XDG_DATA_HOME", + "XDG_CACHE_HOME", "CLAUDE_CONFIG_DIR", "CODEX_HOME", "KIRO_HOME", diff --git a/tests/test_mcp.c b/tests/test_mcp.c index 225d3e6fdd..455a40a581 100644 --- a/tests/test_mcp.c +++ b/tests/test_mcp.c @@ -20478,7 +20478,8 @@ static bool dc_walk_fixture_open(dc_walk_fixture_t *fx) { } /* Same git invocation rules as the #1363 fixture above. */ char cmd[1200]; - const char *steps[] = {"init -q", "add -A", "commit -q -m init"}; + const char *steps[] = {"init -q", "config diff.mnemonicPrefix true", "add -A", + "commit -q -m init"}; for (size_t s = 0; s < sizeof(steps) / sizeof(steps[0]); s++) { snprintf(cmd, sizeof(cmd), "git -C \"%s\" -c user.name=t -c user.email=t@t.io -c init.defaultBranch=main " diff --git a/tests/test_smoke_fixture_contract.sh b/tests/test_smoke_fixture_contract.sh index fd705b9348..244bf16c02 100755 --- a/tests/test_smoke_fixture_contract.sh +++ b/tests/test_smoke_fixture_contract.sh @@ -118,7 +118,9 @@ CLIENT_HOME_OVERRIDES = ( # so it needs the same neutralization — otherwise a green run on a developer # machine only proves the ambient config happened to be writable. test_main = read("tests/test_main.c") -for variable in CLIENT_HOME_OVERRIDES: +for variable in CLIENT_HOME_OVERRIDES + ( + "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME" +): require( f'"{variable}"' in test_main, f"tests/test_main.c must neutralize ambient {variable}", From bf7176aee671ee5c62333dff5edba4d20d243921 Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Mon, 26 Oct 2026 07:37:04 -0700 Subject: [PATCH 2/5] fix(test): dispatch Python help probes without invoking Bash first Signed-off-by: DavidHLP --- tests/test_venue_parity_contract.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_venue_parity_contract.sh b/tests/test_venue_parity_contract.sh index 8b4b8b6392..12507cba7d 100755 --- a/tests/test_venue_parity_contract.sh +++ b/tests/test_venue_parity_contract.sh @@ -409,9 +409,9 @@ test-infrastructure/vm/vm-run-tests.sh test-infrastructure/vm/win.sh " for entry in $HELP_ENTRIES; do - out=$(cd "$ROOT" && bash "$entry" --help 2>&1) && rc=0 || rc=$? case "$entry" in *.py) out=$(cd "$ROOT" && python3 "$entry" --help 2>&1) && rc=0 || rc=$? ;; + *) out=$(cd "$ROOT" && bash "$entry" --help 2>&1) && rc=0 || rc=$? ;; esac # Substring test in-shell: piping into `grep -q` is unsafe under # `set -o pipefail` because grep exits at the first match and the From c22e62ddd313603f1a425bcca807f6fbe4f0de13 Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Mon, 26 Oct 2026 08:05:24 -0700 Subject: [PATCH 3/5] fix: guard empty signature buffers and RST configuration lookups Signed-off-by: DavidHLP --- src/pipeline/doc_links_rst.c | 3 +++ tests/test_extraction.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/pipeline/doc_links_rst.c b/src/pipeline/doc_links_rst.c index e5b9cf40d8..1824770845 100644 --- a/src/pipeline/doc_links_rst.c +++ b/src/pipeline/doc_links_rst.c @@ -405,6 +405,9 @@ static void rr_destroy(void *index) { /* The documentation set a document belongs to: the nearest conf.py at or * above its directory; NULL for none. */ static const rr_conf_t *rr_conf_for(const rr_index_t *x, const char *doc) { + if (x->nconfs == 0) { + return NULL; + } char dir[RR_PATH_CAP]; const char *b = rr_base(doc); size_t dl = b > doc ? (size_t)(b - doc - SKIP_ONE) : 0; diff --git a/tests/test_extraction.c b/tests/test_extraction.c index 041c6db513..7f1daac0f9 100644 --- a/tests/test_extraction.c +++ b/tests/test_extraction.c @@ -12612,6 +12612,12 @@ TEST(doc_perl_module_doc_is_the_pod_no_sub_holds) { ASSERT_NOT_NULL(r); ASSERT_NULL(r->module_doc); cbm_free_result(r); + /* POD without any declarations leaves both scope sort inputs empty. */ + r = extract("=head1 NAME\n\nStandalone module.\n\n=cut\n", CBM_LANG_PERL, "t", "Standalone.pm"); + ASSERT_NOT_NULL(r); + ASSERT_EQ(count_defs_with_label(r, "Function"), 0); + ASSERT_STR_EQ(r->module_doc, "=head1 NAME\n\nStandalone module.\n\n=cut"); + cbm_free_result(r); PASS(); } From 657092cfa9214ad0e66e6042c4731587789b33fe Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Mon, 26 Oct 2026 09:19:09 -0700 Subject: [PATCH 4/5] test(mem): retain pre-initialization coverage with current mimalloc Keep the pre-main free(NULL) regression and test-object dependencies. Main already contains the allocator fix in mimalloc 3.5.3, so retain its implementation and vendored checksums instead of applying the old backport. Signed-off-by: DavidHLP --- Makefile.cbm | 6 ++++-- scripts/test.sh | 1 + tests/test_mimalloc_preinit.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 tests/test_mimalloc_preinit.sh diff --git a/Makefile.cbm b/Makefile.cbm index 66cccffe28..ca49479248 100644 --- a/Makefile.cbm +++ b/Makefile.cbm @@ -1114,10 +1114,12 @@ MIMALLOC_OBJ_TEST = $(BUILD_DIR)/mimalloc.o MIMALLOC_OBJ_TSAN = $(BUILD_DIR)/tsan_mimalloc.o MIMALLOC_OBJ_PROD = $(BUILD_DIR)/prod_mimalloc.o -$(BUILD_DIR)/mimalloc.o: $(MIMALLOC_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \ + $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR) $(CC) $(MIMALLOC_CFLAGS_TEST) -c -o $@ $< -$(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) | $(BUILD_DIR) +$(BUILD_DIR)/tsan_mimalloc.o: $(MIMALLOC_SRC) $(wildcard vendored/mimalloc/src/*.c) \ + $(wildcard vendored/mimalloc/include/*.h) Makefile.cbm | $(BUILD_DIR) $(CC) $(MIMALLOC_CFLAGS_TEST) $(TSAN_SANITIZE) -c -o $@ $< # static.c is an AMALGAMATION: it #includes options.c and friends, none of which diff --git a/scripts/test.sh b/scripts/test.sh index a2bb59aead..c62e5f21ed 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -501,6 +501,7 @@ fi # release artifacts free of it; scripts/ci/check-binary-composition.sh proves # they stay that way. echo "=== Step 5: parent-death watchdog regression (#406/#407) ===" +CC="$CC" bash "$ROOT/tests/test_mimalloc_preinit.sh" make -j"$NPROC" -f Makefile.cbm cbm TEST_SEAMS=1 ${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"} WATCHDOG_BINARY="$ROOT/$BUILD_DIR/codebase-memory-mcp" CBM_TEST_BINARY="$WATCHDOG_BINARY" bash "$ROOT/tests/test_parent_watchdog.sh" diff --git a/tests/test_mimalloc_preinit.sh b/tests/test_mimalloc_preinit.sh new file mode 100755 index 0000000000..7ea4f22a8c --- /dev/null +++ b/tests/test_mimalloc_preinit.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ELF preinitializers run before allocator constructors, independent of libc version. +if [[ "$(uname -s)" != Linux ]]; then + echo "mimalloc pre-init regression: ELF-only check not applicable" + exit 0 +fi +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +probe_dir="$(mktemp -d "${TMPDIR:-/tmp}/cbm-mi-preinit.XXXXXX")" +trap 'rm -rf "$probe_dir"' EXIT + +cat >"$probe_dir/probe.c" <<'C' +#include +#include "mimalloc.h" +static void before_init(void) { mi_free(NULL); } +__attribute__((used, section(".preinit_array"))) +static void (*const preinit)(void) = before_init; +int main(void) { + void *p = mi_malloc(16); + if (!p) return 1; + mi_free(p); + return 0; +} +C +"${CC:-cc}" -O2 -DMI_DEBUG=0 -DMI_OVERRIDE=0 \ + -I"$ROOT/vendored/mimalloc/include" -I"$ROOT/vendored/mimalloc/src" \ + "$probe_dir/probe.c" "$ROOT/vendored/mimalloc/src/static.c" \ + -lpthread -lm -o "$probe_dir/probe" +"$probe_dir/probe" +echo "mimalloc pre-init free(NULL) regression passed" From fd7dfaf865d43f0c7285d7e6afce4f44ab82e4d8 Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Sun, 15 Nov 2026 23:24:20 -0800 Subject: [PATCH 5/5] fix(ci): skip shadow indexing for full test selections Pass the existing lane selection to the graph-need probe. When every suite is already required, emit the unchanged all-suite prediction without indexing the repository with the released binary. Keep graph analysis for narrowed C changes and cover both decisions in the prediction contract. Signed-off-by: DavidHLP --- scripts/ci/test-impact-shadow.sh | 6 ++++-- scripts/test-impact/predict.py | 10 ++++++---- tests/test_test_impact_predict.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/ci/test-impact-shadow.sh b/scripts/ci/test-impact-shadow.sh index a6f6f369a9..f6d8eab07f 100755 --- a/scripts/ci/test-impact-shadow.sh +++ b/scripts/ci/test-impact-shadow.sh @@ -24,7 +24,8 @@ # scripts/test-impact/predict.py map it to suites with the lane # selector's run-all triggers. Writes DIR/prediction.json and # DIR/summary.md (appended to $GITHUB_STEP_SUMMARY when set). The -# graph is only consulted when C sources changed. +# graph is only consulted when C sources changed and the lane +# selector has not already required every suite. # Exit: 0 = prediction written · 1 = the tooling broke · 2 = usage error. set -euo pipefail @@ -135,7 +136,8 @@ VERSION=$("$BINARY" --version 2>/dev/null | head -1 || true) DETECT_ARGS=() T_INDEX="-" T_DETECT="-" -if [ "$(python3 "$PREDICT" --needs-graph --changed "$OUT/changed-files.txt")" = yes ]; then +if [ "$(python3 "$PREDICT" --needs-graph --changed "$OUT/changed-files.txt" \ + --selection "$OUT/selection.json")" = yes ]; then python3 -c 'import json, sys; json.dump({"repo_path": sys.argv[1]}, open(sys.argv[2], "w"))' \ "$ROOT" "$WORK/index-args.json" t0=$(date +%s) diff --git a/scripts/test-impact/predict.py b/scripts/test-impact/predict.py index 7658ea2b29..776f2d2c5b 100644 --- a/scripts/test-impact/predict.py +++ b/scripts/test-impact/predict.py @@ -18,7 +18,7 @@ Usage: predict.py --root DIR --changed FILE --selection FILE [--detect FILE] [--depth N] [--meta JSON] --out FILE [--summary FILE] - predict.py --needs-graph --changed FILE (prints yes|no) + predict.py --needs-graph --changed FILE [--selection FILE] (prints yes|no) """ import argparse import json @@ -205,13 +205,15 @@ def main(): a = ap.parse_args() with open(a.changed, encoding="utf-8") as fh: changed = sorted({line.strip() for line in fh if line.strip()}) + selection = {} + if a.selection: + with open(a.selection, encoding="utf-8") as fh: + selection = json.load(fh) if a.needs_graph: - print("yes" if needs_graph(changed) else "no") + print("yes" if needs_graph(changed) and not selection.get("full") else "no") return 0 if not (a.root and a.selection and a.out): ap.error("--root, --selection and --out are required") - with open(a.selection, encoding="utf-8") as fh: - selection = json.load(fh) detect = None if a.detect: with open(a.detect, encoding="utf-8") as fh: diff --git a/tests/test_test_impact_predict.sh b/tests/test_test_impact_predict.sh index 5989888301..864d07f90b 100755 --- a/tests/test_test_impact_predict.sh +++ b/tests/test_test_impact_predict.sh @@ -130,6 +130,18 @@ for changed, want in ((["README.md"], "no"), (["src/store/store.c"], "yes"), if out != want: failures.append(f"--needs-graph for {changed}: {out!r}, expected {want!r}") +for selection, want in ((NARROW, "yes"), ({"tier": "T5-core", "full": True}, "no")): + (work / "needs.txt").write_text("src/store/store.c\n") + (work / "selection.json").write_text(json.dumps(selection)) + proc = subprocess.run([sys.executable, predict, "--needs-graph", "--changed", + str(work / "needs.txt"), "--selection", str(work / "selection.json")], + capture_output=True, text=True) + if proc.returncode != 0 or proc.stdout.strip() != want: + failures.append(f"--needs-graph with {selection}: {proc.stdout!r}, expected {want!r}") +expect("run-all without indexing still selects every suite", + predict_for("full-no-graph", ["Makefile.cbm", "src/store/store.c"], + {"tier": "T5-core", "full": True}), "all", ALL) + if failures: print("TEST-IMPACT PREDICTION CONTRACT VIOLATED:") for failure in failures: