@@ -9,6 +9,7 @@ int tf_fail_count = 0;
99int tf_skip_count = 0 ;
1010
1111#include "test_framework.h"
12+ #include "test_helpers.h"
1213#include "foundation/compat.h" /* cbm_setenv — #845 supervisor kill switch */
1314#include "foundation/compat_fs.h" /* cbm_fopen — worker response file */
1415#include "foundation/mem.h" /* cbm_mem_init — worker budget */
@@ -24,6 +25,32 @@ int tf_skip_count = 0;
2425#include <winsock2.h> /* #798 follow-up: socket-isolation re-exec probe */
2526#endif
2627
28+ /* Test handlers that exercise the production index_repository flow must never
29+ * inherit the user's real cache. Individual tests may temporarily override
30+ * this sentinel and restore it; atexit removes anything left behind by an
31+ * assertion that returns before fixture cleanup. */
32+ static char tf_home_sentinel [512 ];
33+
34+ static void tf_cleanup_cache_sentinel (void ) {
35+ if (tf_home_sentinel [0 ]) {
36+ th_rmtree (tf_home_sentinel );
37+ }
38+ }
39+
40+ static bool tf_setup_cache_sentinel (void ) {
41+ snprintf (tf_home_sentinel , sizeof (tf_home_sentinel ), "/tmp/cbm-test-home-XXXXXX" );
42+ if (!cbm_mkdtemp (tf_home_sentinel )) {
43+ return false;
44+ }
45+ /* Legacy integration fixtures derive DB paths from HOME, while production
46+ * cache_dir() prefers CBM_CACHE_DIR. A private HOME plus no inherited cache
47+ * override keeps both conventions pointed at the same isolated tree. */
48+ cbm_setenv ("HOME" , tf_home_sentinel , 1 );
49+ cbm_unsetenv ("CBM_CACHE_DIR" );
50+ atexit (tf_cleanup_cache_sentinel );
51+ return true;
52+ }
53+
2754/* #832 guard support: when the index supervisor spawns THIS binary as
2855 * `<self> cli --index-worker index_repository <args_json> --response-out <file>`
2956 * (exactly the argv cbm_index_spawn_worker builds), act as a faithful in-process
@@ -276,6 +303,10 @@ int main(int argc, char **argv) {
276303 * binary as `<self> cli --index-worker …` and recursively re-run suites.
277304 * A test that exercises the supervisor must explicitly re-enable it. */
278305 cbm_setenv ("CBM_INDEX_SUPERVISOR" , "0" , 1 );
306+ if (!tf_setup_cache_sentinel ()) {
307+ fprintf (stderr , "failed to create isolated test cache\n" );
308+ return 2 ;
309+ }
279310
280311 g_suite_argc = argc ;
281312 g_suite_argv = argv ;
0 commit comments