Skip to content

Commit 6a29a19

Browse files
committed
fix(test-impact): build and run on Linux GCC, git before 2.44, LeakSanitizer
PR CI on the first push of these commits found what no local leg had built yet: - test_impact_result_validate.c: initialize the count GCC's -Wmaybe-uninitialized flags (-Werror on every Linux build: smoke, shadow, analyze). - tests: split one-line `if` chains GCC reports as misleading indentation, and drop a redundant `= {0}` it reads as missing braces (the GCC test runner did not compile). - tests/test_test_impact_engine.c: realpath() into a PATH_MAX buffer; glibc's _FORTIFY_SOURCE aborts on anything smaller, as test_index_resilience.c already notes. - test_impact_git.c: pass --no-lazy-fetch only when the git executable takes it (git 2.44+, probed once per session with the option on --version). Older git rejected it and every engine command failed; Ubuntu 24.04 ships git 2.43. `-c protocol.allow=never` already turns a lazy fetch into an error there, which is what the option asks for. - test_impact_engine.c: the selection and publish job threads release their thread-local node-type bitset cache before they end, as the parallel workers and the MCP index thread do. LeakSanitizer reported it (488 bytes in 13 allocations, test-diag); the Linux arm64 ASan leg reproduced exactly that and is clean with the fix. Signed-off-by: Martin Vogel <[email protected]>
1 parent 867e5f8 commit 6a29a19

7 files changed

Lines changed: 46 additions & 9 deletions

‎src/mcp/test_impact_engine.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "foundation/sha256.h"
1414
#include "store/store_graph_digest.h"
1515
#include "store/store_impact.h"
16+
#include "helpers.h" /* cbm_kind_in_set_free_cache — the job thread's cache teardown */
1617

1718
#include <stdio.h>
1819
#include <stdlib.h>
@@ -621,6 +622,10 @@ static void *te_job_main(void *arg) {
621622
status = CBM_TEST_IMPACT_CANCELLED;
622623
}
623624
te_free(&c);
625+
/* The snapshot build extracted on THIS thread, which ends here: its
626+
* thread-local node-type bitset cache goes with it (as the MCP index
627+
* thread and the parallel workers release theirs). */
628+
cbm_kind_in_set_free_cache();
624629
job->status = status;
625630
return NULL;
626631
}
@@ -678,6 +683,7 @@ static void *te_publish_main(void *arg) {
678683
bool ok = te_publish(&c, p);
679684
job->status = c.oom ? CBM_TEST_IMPACT_OOM : ok ? CBM_TEST_IMPACT_OK : CBM_TEST_IMPACT_INVALID;
680685
te_free(&c);
686+
cbm_kind_in_set_free_cache(); /* this thread's extraction cache, as in te_job_main */
681687
return NULL;
682688
}
683689

‎src/mcp/test_impact_git.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct cbm_git_facts {
6060
cbm_git_facts_error_t stopped;
6161
gf_batch_budget_t *batch_budget; /* borrowed stack state during one serialized call */
6262
gf_inventory_cache_t inventory_cache[2];
63+
bool no_lazy_fetch; /* the executable takes --no-lazy-fetch (gf_probe_no_lazy_fetch) */
6364
};
6465

6566
typedef struct {
@@ -486,7 +487,6 @@ static bool gf_run_input(cbm_git_facts_t *facts, const char *const *arguments, i
486487
"--no-replace-objects",
487488
"--no-pager",
488489
"--literal-pathspecs",
489-
"--no-lazy-fetch",
490490
"-C",
491491
facts->options.root,
492492
"-c",
@@ -496,11 +496,13 @@ static bool gf_run_input(cbm_git_facts_t *facts, const char *const *arguments, i
496496
size_t prefix_count = sizeof(prefix) / sizeof(prefix[0]);
497497
size_t directory_count = facts->command_git_dir ? 4 : 0;
498498
if (count < 1 || count >= GF_ARG_CAP ||
499-
(size_t)count + prefix_count + directory_count + (size_t)facts->git_pin_count + 1 >
499+
(size_t)count + prefix_count + directory_count + (size_t)facts->git_pin_count + 2 >
500500
GF_ARG_CAP)
501501
return gf_error(error, CBM_GIT_FACTS_INVALID, "Invalid internal Git command");
502502
for (size_t i = 0; i < prefix_count; i++)
503503
argv[argc++] = prefix[i];
504+
if (facts->no_lazy_fetch)
505+
argv[argc++] = "--no-lazy-fetch";
504506
if (facts->command_git_dir) {
505507
argv[argc++] = "--git-dir";
506508
argv[argc++] = facts->command_git_dir;
@@ -907,6 +909,22 @@ static bool gf_open_identity(cbm_git_facts_t *facts, cbm_git_facts_error_t *erro
907909
return gf_gate(facts, error);
908910
}
909911

912+
/* --no-lazy-fetch (git 2.44) keeps an object missing from a partial clone
913+
* from being fetched. Older git rejects the option, which failed every engine
914+
* command (Ubuntu 24.04 ships git 2.43). There `-c protocol.allow=never`
915+
* already turns such a fetch into an error, which is what the option asks
916+
* for, so it is passed only when the executable accepts it: one probe per
917+
* facts session, outside the command budget, output discarded. */
918+
static bool gf_probe_no_lazy_fetch(const char *git) {
919+
const char *argv[] = {git, "--no-lazy-fetch", "--version", NULL};
920+
cbm_proc_opts_t options = {.bin = git,
921+
.argv = argv,
922+
.cancel_grace_ms = CBM_SUBPROCESS_DEFAULT_CANCEL_GRACE_MS,
923+
.strip_git_repo_env = true};
924+
cbm_proc_result_t result = {0};
925+
return cbm_subprocess_run(&options, &result) == 0 && result.outcome == CBM_PROC_CLEAN;
926+
}
927+
910928
cbm_git_facts_t *cbm_git_facts_open(const cbm_git_facts_options_t *options,
911929
cbm_git_facts_error_t *error) {
912930
cbm_git_facts_error_t local;
@@ -959,6 +977,7 @@ cbm_git_facts_t *cbm_git_facts_open(const cbm_git_facts_options_t *options,
959977
cbm_git_facts_free(facts);
960978
return NULL;
961979
}
980+
facts->no_lazy_fetch = gf_probe_no_lazy_fetch(facts->options.git_executable);
962981
if (!gf_open_identity(facts, error)) {
963982
cbm_git_facts_free(facts);
964983
return NULL;

‎src/mcp/test_impact_result_validate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static bool tir_label(tir_context *c, const char *s, tir_bytes *out) {
2727

2828
static bool tir_string_array(tir_context *c, const char *const *strings, int count,
2929
tir_bytes **saved) {
30-
size_t n;
30+
size_t n = 0;
3131
if (!tir_count(c, strings, count, &n))
3232
return false;
3333
tir_bytes *copy = saved ? tir_alloc(c, n, sizeof(*copy)) : NULL;

‎tests/test_pipeline_frozen.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ static cbm_pipeline_frozen_inputs_t pf_inputs(pf_fixture_t *f, const char *confi
258258
.config_bytes = config,
259259
.config_len = config ? strlen(config) : 0,
260260
.pinned_git = git,
261-
.resource_policy = {0},
262261
.cancelled = cancelled};
263262
}
264263
static cbm_pipeline_frozen_status_t pf_create(pf_fixture_t *f, const char *config,

‎tests/test_store_graph_digest.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,12 @@ TEST(store_graph_digest_invalid_arguments_missing_project_and_initial_latches) {
420420
int opened=s && collation?cbm_store_read_scope_open(s,NULL,NULL,&scope):CBM_STORE_ERR;
421421
cbm_store_graph_digest_limits_t lim=gd_room;cbm_store_graph_digest_t out;memset(&out,0xa5,sizeof(out));
422422
const unsigned char *p=(const unsigned char *)"p";size_t len=1;
423-
if(which==2)p=NULL;if(which==3)len=0;if(which==4)len=(size_t)INT_MAX+1;
423+
if(which==2)p=NULL;
424+
if(which==3)len=0;
425+
if(which==4)len=(size_t)INT_MAX+1;
424426
if(which==5){p=(const unsigned char *)"p\0q";len=3;}
425-
if(which==7)lim.max_rows=0;if(which==8)lim.max_framed_bytes=0;
427+
if(which==7)lim.max_rows=0;
428+
if(which==8)lim.max_framed_bytes=0;
426429
if(which==9)lim.max_framed_bytes=UINT64_MAX/8+1;
427430
if(which==10)p=(const unsigned char *)"P";
428431
int rc=opened==CBM_STORE_OK?cbm_store_graph_digest(which==0?NULL:scope,p,len,which==6?NULL:&lim,which==1?NULL:&out):-1;

‎tests/test_test_impact_engine.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
#include "foundation/subprocess.h"
1717
#include "mcp/test_impact_engine.h"
1818

19+
#include <limits.h>
1920
#include <stdio.h>
2021
#include <stdlib.h>
2122
#include <string.h>
2223
#include <time.h>
2324

25+
/* glibc's _FORTIFY_SOURCE realpath() aborts unless the output buffer is at
26+
* least PATH_MAX bytes, independent of the actual path length. */
27+
#ifndef PATH_MAX
28+
#define PATH_MAX 4096
29+
#endif
30+
2431
typedef struct {
2532
char git[1024];
2633
char home[1024];
@@ -126,7 +133,7 @@ static bool tie_open_with(tie_fixture_t *fx, const char *extra_path, const char
126133
memset(fx, 0, sizeof(*fx));
127134
const char *git = cbm_find_cli("git", cbm_get_home_dir());
128135
const char *home = th_mktempdir("cbm-ti-engine");
129-
char real[1024];
136+
char real[PATH_MAX];
130137
if (!git || !home || !realpath(home, real) || strlen(git) >= sizeof(fx->git)) {
131138
return false;
132139
}

‎tests/test_test_impact_git.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,9 @@ TEST(test_git_blob_batch_validates_full_selection_and_empty_requests) {
20022002
gfb_error(facts,&request,NULL,CBM_GIT_FACTS_INVALID) && ok;
20032003
for(int i=0;control && i<3;i++) {
20042004
cbm_git_blob_batch_limits_t zero=limits;
2005-
if(i==0)zero.max_entries=0;if(i==1)zero.max_input_bytes=0;if(i==2)zero.max_arena_bytes=0;
2005+
if(i==0)zero.max_entries=0;
2006+
if(i==1)zero.max_input_bytes=0;
2007+
if(i==2)zero.max_arena_bytes=0;
20062008
ok=gfb_error(facts,&request,&zero,CBM_GIT_FACTS_INVALID) && ok;
20072009
}
20082010
bool no_out=control && !cbm_git_facts_read_blob_batch(facts,&request,&limits,NULL,&error) &&
@@ -2265,7 +2267,8 @@ static cbm_git_bytes_t gfb_concat(CBMArena *arena,cbm_git_bytes_t a,cbm_git_byte
22652267
if(a.length>SIZE_MAX-b.length)return (cbm_git_bytes_t){NULL,0};
22662268
size_t size=a.length+b.length;unsigned char *bytes=cbm_arena_alloc(arena,size?size:1);
22672269
if(!bytes)return (cbm_git_bytes_t){NULL,0};
2268-
if(a.length)memcpy(bytes,a.data,a.length);if(b.length)memcpy(bytes+a.length,b.data,b.length);
2270+
if(a.length)memcpy(bytes,a.data,a.length);
2271+
if(b.length)memcpy(bytes+a.length,b.data,b.length);
22692272
return (cbm_git_bytes_t){bytes,size};
22702273
}
22712274

0 commit comments

Comments
 (0)