Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ test-repro: $(BUILD_DIR)/test-repro-runner
# written by the configuring thread, read AND CALLED by connection
# workers), now fixed with atomics in log.c. Excluding the suite is what
# had hidden it.
TEST_TSAN_SUITES ?= mem slab_alloc parallel worker_pool watcher httpd pipeline \
diagnostics mcp mcp_mutation_guard subprocess daemon daemon_application \
TEST_TSAN_SUITES ?= mem slab_alloc parallel worker_pool watcher httpd pipeline pipeline_d \
diagnostics mcp mcp_supervisor mcp_mutation_guard subprocess daemon daemon_application \
daemon_runtime daemon_ipc daemon_frontend
# halt_on_error: a race is a bug, stop at the first one.
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/msan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ echo "=== MSan lane: $(clang --version | head -1) ==="
# LESSON FROM (A): an MSan abort that is not a use-of-uninitialized-value
# report is a reporting failure until proven otherwise. Look for the read
# first (fast unwinding prints it), not for a stack limit.
MSAN_EXCLUDE="${MSAN_EXCLUDE-cli}"
MSAN_EXCLUDE="${MSAN_EXCLUDE-cli cli_b}"

if [ "$#" -gt 0 ]; then
./build/msan/test-runner "$@"
Expand Down
11 changes: 8 additions & 3 deletions scripts/run-tests-parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,14 @@ fi
shard_filter() {
awk -v idx="$SHARD_INDEX" -v total="$SHARD_TOTAL" '
BEGIN {
nh = split("store_arch daemon_runtime incremental cli extraction " \
nh = split("store_arch daemon_runtime incremental cli cli_b extraction " \
"watcher daemon_ipc subprocess httpd py_lsp_stress " \
"grammar_regression mcp daemon_frontend pipeline pipeline_b", h, " ")
"grammar_regression mcp mcp_supervisor daemon_frontend " \
"pipeline pipeline_b pipeline_c pipeline_d " \
"c_lsp c_lsp_b doc_mentions doc_mentions_b doc_mentions_d doc_mentions_e " \
"test_impact_git test_impact_git_b test_impact_git_c " \
"complexity complexity_b grammar_probe_f grammar_probe_f_b " \
"java_type_scope java_type_scope_b pipeline_semantic_manifest_repro_b", h, " ")
}
{ present[$0] = NR; lines[NR] = $0 }
END {
Expand Down Expand Up @@ -261,7 +266,7 @@ shard_filter() {
# that 40 sits >=2x from both the linear and quadratic signals, so inflating it
# would move the test toward the very thing it exists to catch. Quiet is the
# fix, and at ~22s the suite is cheap to run alone.
SERIAL_SUITES="cli subprocess watcher incremental httpd ui index_resilience mcp \
SERIAL_SUITES="cli cli_b subprocess watcher incremental httpd ui index_resilience mcp_supervisor \
extraction \
stack_overflow_a stack_overflow_b stack_overflow_c \
index_supervisor daemon_application daemon_runtime daemon_frontend \
Expand Down
114 changes: 114 additions & 0 deletions tests/image_probe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,120 @@
* test runner. Its roles live in tests/image_probe_roles.c.
*/
#include "test_image_probe.h"
#include "foundation/compat.h"
#include "foundation/compat_fs.h"
#include "foundation/platform.h"

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <signal.h>
#include <unistd.h>
#endif

#define PROBE_BLOCKING_GIT_MARKER_ENV "CBM_TEST_RUNTIME_BLOCKING_GIT_PID_FILE"

#ifdef _WIN32
static bool probe_invoked_as_windows_git_module(void) {
wchar_t image[32768];
DWORD image_length = GetModuleFileNameW(NULL, image, (DWORD)(sizeof(image) / sizeof(image[0])));
if (image_length == 0 || image_length >= (DWORD)(sizeof(image) / sizeof(image[0]))) {
return false;
}
const wchar_t *base = image;
for (const wchar_t *cursor = image; *cursor; cursor++) {
if (*cursor == L'/' || *cursor == L'\\') {
base = cursor + 1;
}
}
return CompareStringOrdinal(base, -1, L"git.exe", -1, TRUE) == CSTR_EQUAL;
}

static BOOL WINAPI probe_blocking_git_control_handler(DWORD event) {
return event == CTRL_C_EVENT || event == CTRL_BREAK_EVENT;
}
#endif

static bool probe_invoked_as_blocking_git(const char *argv0) {
if (!getenv(PROBE_BLOCKING_GIT_MARKER_ENV)) {
return false;
}
#ifdef _WIN32
(void)argv0;
return probe_invoked_as_windows_git_module();
#else
if (!argv0 || !argv0[0]) {
return false;
}
const char *base = argv0;
for (const char *cursor = argv0; *cursor; cursor++) {
if (*cursor == '/' || *cursor == '\\') {
base = cursor + 1;
}
}
return strcmp(base, "git") == 0 || strcmp(base, "git.exe") == 0 || strcmp(base, "GIT.EXE") == 0;
#endif
}

static int probe_maybe_run_blocking_git(int argc, char **argv) {
(void)argc;
#ifdef _WIN32
bool windows_git_module = probe_invoked_as_windows_git_module();
if (windows_git_module && !getenv(PROBE_BLOCKING_GIT_MARKER_ENV)) {
(void)puts("TF_BLOCKING_GIT_DIAGNOSTIC marker_environment_missing");
(void)fflush(stdout);
return 32;
}
#endif
if (!argv || !probe_invoked_as_blocking_git(argv[0])) {
return -1;
}
const char *marker_path = getenv(PROBE_BLOCKING_GIT_MARKER_ENV);
errno = 0;
#ifdef _WIN32
SetLastError(ERROR_SUCCESS);
#endif
FILE *marker = cbm_fopen(marker_path, "wbx");
if (!marker) {
#ifdef _WIN32
int marker_errno = errno;
DWORD marker_error = GetLastError();
bool marker_exists = cbm_file_exists(marker_path);
(void)printf("TF_BLOCKING_GIT_DIAGNOSTIC marker_open_failed errno=%d win_error=%lu "
"exists=%d\n",
marker_errno, (unsigned long)marker_error, marker_exists ? 1 : 0);
(void)fflush(stdout);
return marker_exists ? 0 : 30;
#else
return cbm_file_exists(marker_path) ? 0 : 30;
#endif
}
#ifdef _WIN32
unsigned long long process_id = (unsigned long long)GetCurrentProcessId();
#else
unsigned long long process_id = (unsigned long long)getpid();
#endif
bool published =
fprintf(marker, "%llu\n", process_id) > 0 && fflush(marker) == 0 && fclose(marker) == 0;
if (!published) {
return 31;
}
#ifdef _WIN32
(void)SetConsoleCtrlHandler(probe_blocking_git_control_handler, TRUE);
#else
(void)signal(SIGTERM, SIG_IGN);
(void)signal(SIGINT, SIG_IGN);
#endif
for (;;) {
cbm_usleep(100000);
}
}

#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
#define PROBE_MSAN_MIMALLOC_OUTPUT 1
Expand Down Expand Up @@ -41,6 +151,10 @@ int main(int argc, char **argv) {
mi_register_output(probe_msan_mi_output, NULL);
probe_msan_mi_output_live = true;
#endif
int git_rc = probe_maybe_run_blocking_git(argc, argv);
if (git_rc >= 0) {
return git_rc;
}
/* An install verifies the candidate it staged by running it with
* --version (src/cli/cli.c); the probe stands in for that binary. */
if (argc == 2 && strcmp(argv[1], "--version") == 0) {
Expand Down
18 changes: 18 additions & 0 deletions tests/image_probe_roles.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ static int probe_role_serve(int argc, char **argv) {
return freed ? 0 : 34;
}

static int probe_role_git_facts_diff_probe(int argc, char **argv) {
if (argc < 3 || !argv[2]) {
return 96;
}
FILE *file = cbm_fopen(argv[2], "wb");
if (!file) {
return 96;
}
bool ok = fwrite("invoked\n", 1, 8, file) == 8;
if (fclose(file) != 0) {
ok = false;
}
return ok ? 0 : 96;
}

int tf_image_probe_dispatch(int argc, char **argv) {
if (argc < 2 || !argv || !argv[1]) {
return -1;
Expand All @@ -338,5 +353,8 @@ int tf_image_probe_dispatch(int argc, char **argv) {
if (strcmp(role, "__cbm_runtime_mapped_hello_client") == 0) {
return probe_role_mapped_hello(argc, argv);
}
if (strcmp(role, "__cbm_git_facts_diff_probe") == 0) {
return probe_role_git_facts_diff_probe(argc, argv);
}
return -1;
}
6 changes: 6 additions & 0 deletions tests/test_c_lsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17168,6 +17168,12 @@ SUITE(c_lsp) {
RUN_TEST(clsp_issue1527_cross_file_memo_failures_propagate);
RUN_TEST(clsp_issue1546_cross_entry_points_read_crlf_string_splice);
RUN_TEST(clsp_issue1527_long_binary_chain_is_not_nesting);
}

/* Second half of the C/C++ LSP suite, run as its own parallel unit so the
* two heaviest chain-resolution stress tests execute on separate workers
* instead of serializing in one suite (matches pipeline_b). */
SUITE(c_lsp_b) {
RUN_TEST(clsp_issue1527_long_receiver_chain_is_not_nesting);
RUN_TEST(clsp_c_reassigned_function_pointer_calls_join_exact_occurrences);
RUN_TEST(clsp_c_nested_function_pointer_shadow_restores_outer_target);
Expand Down
90 changes: 63 additions & 27 deletions tests/test_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,11 @@ TEST(cli_activation_quiesce_does_not_wait_on_bootstrap_startup) {
cbm_version_cohort_lease_t *lease = NULL;
cbm_daemon_conflict_t conflict;
cbm_daemon_ipc_startup_lock_t *startup = NULL;
#ifdef CBM_ENABLE_TEST_SEAMS
static const char participant_stub_digest[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] =
"4444444444444444444444444444444444444444444444444444444444444444";
cbm_daemon_runtime_fingerprint_cache_set_hash_stub_for_testing(participant_stub_digest);
#endif
bool setup =
endpoint && manager &&
cbm_daemon_runtime_process_build_fingerprint((uint64_t)getpid(), fingerprint) &&
Expand Down Expand Up @@ -1673,8 +1678,9 @@ typedef struct {
char *old_home;
char *old_cache;
char *old_shell;
bool env_saved; /* HOME, CBM_CACHE_DIR and SHELL were saved for finish */
char failed_step[160]; /* the setup step that failed, "" when ready */
bool env_saved; /* HOME, CBM_CACHE_DIR and SHELL were saved for finish */
bool fingerprint_stub_armed; /* runtime hash stub active for this fixture */
char failed_step[160]; /* the setup step that failed, "" when ready */
} cli_scope_fixture_t;

static _Noreturn void cli_scope_host_child(const cli_scope_fixture_t *fixture, int ready_fd,
Expand Down Expand Up @@ -1791,6 +1797,12 @@ static char cli_scope_wait_ready(int fd) {
* ASSERT_TRUE(ready) is never a silent failure. Returns false. */
static bool cli_scope_setup_failed(cli_scope_fixture_t *fixture, const char *tag, const char *step,
int os_error) {
#ifdef CBM_ENABLE_TEST_SEAMS
if (fixture->fingerprint_stub_armed) {
cbm_daemon_runtime_fingerprint_cache_reset_for_testing();
fixture->fingerprint_stub_armed = false;
}
#endif
snprintf(fixture->failed_step, sizeof(fixture->failed_step), "%s", step);
if (os_error != 0) {
(void)fprintf(stderr, "cli scope fixture %s: setup failed at %s: %s\n", tag, step,
Expand Down Expand Up @@ -1878,6 +1890,16 @@ static bool cli_scope_fixture_start(cli_scope_fixture_t *fixture, const char *ta
}
cbm_normalize_path_sep(canonical_cache);
cbm_sha256_hex(canonical_cache, strlen(canonical_cache), fixture->host_cache_fingerprint);
#ifdef CBM_ENABLE_TEST_SEAMS
/* Both the parent and the forked host child execute this same runner
* binary; stubbing only the full-image SHA-256 avoids hashing hundreds of
* MB per cli_scope fixture while keeping all kernel PID/path/cohort checks. */
static const char scope_stub_digest[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] =
"5555555555555555555555555555555555555555555555555555555555555555";
cbm_daemon_runtime_fingerprint_cache_reset_for_testing();
cbm_daemon_runtime_fingerprint_cache_set_hash_stub_for_testing(scope_stub_digest);
fixture->fingerprint_stub_armed = true;
#endif
if (!cbm_daemon_runtime_process_build_fingerprint((uint64_t)getpid(), fixture->self_build)) {
/* Fails when the runner's file no longer matches its running image,
* e.g. a rebuild replaced it mid-run. */
Expand Down Expand Up @@ -2018,6 +2040,12 @@ static int cli_scope_fixture_finish(cli_scope_fixture_t *fixture) {
if (fixture->previous_supervisor_build[0]) {
cbm_index_supervisor_set_build_fingerprint_for_test(fixture->previous_supervisor_build);
}
#ifdef CBM_ENABLE_TEST_SEAMS
if (fixture->fingerprint_stub_armed) {
cbm_daemon_runtime_fingerprint_cache_reset_for_testing();
fixture->fingerprint_stub_armed = false;
}
#endif
/* Restore only what start saved: a setup that failed before saving left
* HOME, CBM_CACHE_DIR and SHELL untouched, and restoring "nothing saved"
* would unset them for every later test in the suite. */
Expand Down Expand Up @@ -3840,22 +3868,13 @@ TEST(cli_update_agent_configs_finish_before_guard_release) {
const char *asset_name = "codebase-memory-mcp-linux-amd64-portable.tar.gz";
#endif
#endif
#ifdef __APPLE__
/* Use the structurally real test runner rather than re-signing an Apple
* platform binary. Turning /usr/bin/true's arm64e/platform signature into
* an ad-hoc signature is OS-policy-dependent on older macOS runners. */
char native_fixture_path[CBM_SZ_4K] = {0};
uint32_t native_fixture_size = (uint32_t)sizeof(native_fixture_path);
ASSERT_EQ(_NSGetExecutablePath(native_fixture_path, &native_fixture_size), 0);
const char *native_fixture = native_fixture_path;
#else
/* The image probe built beside this runner (tests/test_image_probe.h)
* answers --version under any name. /bin/true does not on every host: a
* multicall coreutils (Nix) or BusyBox (Alpine) selects its applet from
* argv[0], so a copy staged as codebase-memory-mcp fails the check. */
/* Use the small image probe built beside this runner (tests/test_image_probe.h)
* on both Linux and macOS: it is a real, locally built executable that
* answers --version under any name (unlike multicall /bin/true or Apple
* platform binaries) without gzipping, SHA-256 hashing, and re-signing the
* ~500 MB sanitized test runner. */
char native_fixture[1024] = {0};
ASSERT_TRUE(th_image_probe_path(native_fixture, sizeof(native_fixture)));
#endif
FILE *native_file = fopen(native_fixture, "rb");
ASSERT_NOT_NULL(native_file);
ASSERT_EQ(fseek(native_file, 0, SEEK_END), 0);
Expand Down Expand Up @@ -3990,20 +4009,16 @@ TEST(cli_update_names_the_failing_staging_step_and_os_error) {
#else
const char *asset_name = "codebase-memory-mcp-darwin-amd64.tar.gz";
#endif
char native_fixture_path[CBM_SZ_4K] = {0};
uint32_t native_fixture_size = (uint32_t)sizeof(native_fixture_path);
ASSERT_EQ(_NSGetExecutablePath(native_fixture_path, &native_fixture_size), 0);
const char *native_fixture = native_fixture_path;
#else
#if defined(__aarch64__)
const char *asset_name = "codebase-memory-mcp-linux-arm64-portable.tar.gz";
#else
const char *asset_name = "codebase-memory-mcp-linux-amd64-portable.tar.gz";
#endif
#endif
/* The image probe, as in cli_update_agent_configs_finish_before_guard_release. */
char native_fixture[1024] = {0};
ASSERT_TRUE(th_image_probe_path(native_fixture, sizeof(native_fixture)));
#endif
FILE *native_file = fopen(native_fixture, "rb");
ASSERT_NOT_NULL(native_file);
ASSERT_EQ(fseek(native_file, 0, SEEK_END), 0);
Expand Down Expand Up @@ -21795,15 +21810,28 @@ TEST(cli_index_exit_partial_without_denominator_is_not_graded) {
PASS();
}

SUITE(cli) {
static bool cli_suite_setup(const char *tag) {
if (!th_secure_runtime_parent_new(g_cli_suite_runtime_parent,
sizeof(g_cli_suite_runtime_parent), "cli-suite")) {
sizeof(g_cli_suite_runtime_parent), tag)) {
printf(" %sFAIL%s: could not create private CLI activation runtime\n", tf_red(),
tf_reset());
tf_fail_count++;
return;
return false;
}
cbm_cli_set_activation_runtime_parent_for_test(g_cli_suite_runtime_parent);
return true;
}

static void cli_suite_teardown(void) {
cbm_cli_set_activation_runtime_parent_for_test(NULL);
test_rmdir_r(g_cli_suite_runtime_parent);
g_cli_suite_runtime_parent[0] = '\0';
}

SUITE(cli) {
if (!cli_suite_setup("cli-suite")) {
return;
}

RUN_TEST(cli_suite_uses_private_activation_runtime);
RUN_TEST(cli_update_only_names_an_installer_that_exists_issue1632);
Expand Down Expand Up @@ -21897,6 +21925,16 @@ SUITE(cli) {
RUN_TEST(cli_windows_update_hands_off_to_install_script);
RUN_TEST(cli_uninstall_removes_only_its_own_windows_user_path_entry_issue2117);
#endif
cli_suite_teardown();
}

/* Second half of the CLI suite, split right after the daemon-activation
* battery so both halves balance evenly across x86, arm64, and Intel macOS
* CI shards instead of serializing all 415 CLI tests onto one runner. */
SUITE(cli_b) {
if (!cli_suite_setup("cli-suite-b")) {
return;
}

/* Version (2 tests — selfupdate_test.go) */
RUN_TEST(cli_compare_versions);
Expand Down Expand Up @@ -22329,7 +22367,5 @@ SUITE(cli) {
RUN_TEST(cli_index_exit_negative_threshold_disables_the_check);
RUN_TEST(cli_index_exit_unreadable_threshold_falls_back_to_default);
RUN_TEST(cli_index_exit_partial_without_denominator_is_not_graded);
cbm_cli_set_activation_runtime_parent_for_test(NULL);
test_rmdir_r(g_cli_suite_runtime_parent);
g_cli_suite_runtime_parent[0] = '\0';
cli_suite_teardown();
}
Loading
Loading