Skip to content

Commit f1beaec

Browse files
committed
test: cache the incremental fixture and index the CI-shaped corpus everywhere
The incremental suite cloned fastapi from the network on every run and indexed a DIFFERENT corpus per environment: CI used a sparse checkout without docs/ and tests/ (the assertion thresholds are sized for it) while local runs indexed the full tree — twice the files for the same assertions, a per-run network dependency, and the suite's dominant cost on the sanitized container leg. The fixture is now cloned from the network at most once per machine into a persistent cache (committed with an atomic rename so a torn download can never pose as a valid cache; CBM_TEST_FIXTURE_CACHE overrides the location), every run local-clones from it offline, and docs/ plus tests/ are trimmed everywhere — the portable equivalent of CI's historical sparse profile, so all environments now index the same corpus the assertions were written against. Same 163 tests, same assertions: 74s -> 31s native, with the container leg's cut scaling with the halved indexing volume, and the "network offline" flake source reduced to first-run-per-machine. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 664058e commit f1beaec

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

‎tests/test_incremental.c‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,57 @@ static int incremental_setup(void) {
209209

210210
snprintf(g_repodir, sizeof(g_repodir), "%s/fastapi", g_tmpdir);
211211

212-
/* On CI, use sparse checkout to skip docs/ and tests/ (~62% of files).
213-
* Cuts indexing time roughly in half on slow shared runners. */
214-
char cmd[1024];
215-
if (getenv("CI")) {
216-
snprintf(cmd, sizeof(cmd),
217-
"git clone --depth=1 --branch 0.99.1 --quiet --filter=blob:none "
218-
"--sparse https://github.com/fastapi/fastapi.git '%s' 2>&1 && "
219-
"cd '%s' && git sparse-checkout set --no-cone '/*' '!/docs' '!/tests' 2>&1",
220-
g_repodir, g_repodir);
212+
/* The fixture is cloned from the network at most once per machine, into a
213+
* persistent cache; every run local-clones from there (seconds, offline).
214+
* The one-time clone is staged and committed with an atomic rename so a
215+
* torn download can never masquerade as a valid cache. */
216+
const char *cache_home = getenv("CBM_TEST_FIXTURE_CACHE");
217+
char cache_root[512];
218+
if (cache_home && cache_home[0]) {
219+
snprintf(cache_root, sizeof(cache_root), "%s", cache_home);
221220
} else {
221+
const char *home = getenv("HOME");
222+
if (!home || !home[0])
223+
home = ".";
224+
snprintf(cache_root, sizeof(cache_root), "%s/.cache/cbm-test-fixtures", home);
225+
}
226+
char cache_repo[640];
227+
snprintf(cache_repo, sizeof(cache_repo), "%s/fastapi-0.99.1", cache_root);
228+
char cmd[1600];
229+
if (!cbm_is_dir(cache_repo)) {
230+
(void)cbm_mkdir_p(cache_root, 0700);
231+
char cache_stage[700];
232+
snprintf(cache_stage, sizeof(cache_stage), "%s.stage", cache_repo);
233+
th_rmtree(cache_stage);
222234
snprintf(cmd, sizeof(cmd),
223235
"git clone --depth=1 --branch 0.99.1 --quiet "
224236
"https://github.com/fastapi/fastapi.git '%s' 2>&1",
225-
g_repodir);
237+
cache_stage);
238+
int fetch_rc = system(cmd);
239+
if (fetch_rc != 0 || rename(cache_stage, cache_repo) != 0) {
240+
th_rmtree(cache_stage);
241+
if (!cbm_is_dir(cache_repo)) {
242+
printf(" fixture clone failed (rc=%d) — network offline?\n", fetch_rc);
243+
return -1;
244+
}
245+
}
226246
}
247+
snprintf(cmd, sizeof(cmd), "git clone --quiet '%s' '%s' 2>&1", cache_repo, g_repodir);
227248
int rc = system(cmd);
228249
if (rc != 0) {
229-
printf(" clone failed (rc=%d) — network offline?\n", rc);
250+
printf(" fixture local clone failed (rc=%d)\n", rc);
230251
return -1;
231252
}
253+
/* Index the same corpus everywhere: CI historically indexed a sparse
254+
* checkout without docs/ and tests/ (the assertion thresholds are sized
255+
* for it) while local runs indexed the full tree — twice the files for
256+
* the identical assertions, and a local/CI divergence. Trimming the two
257+
* directories is the portable equivalent of that sparse profile. */
258+
char trim[600];
259+
snprintf(trim, sizeof(trim), "%s/docs", g_repodir);
260+
th_rmtree(trim);
261+
snprintf(trim, sizeof(trim), "%s/tests", g_repodir);
262+
th_rmtree(trim);
232263

233264
g_project = cbm_project_name_from_path(g_repodir);
234265
if (!g_project)

0 commit comments

Comments
 (0)