Skip to content

Commit 00fcea9

Browse files
committed
fix(cache): scope gc's summary figure to package entries
gc deliberately never evicts std entries — one is shared by every project on the machine and costs ~30 s to rebuild, so trading it for a little disk is the wrong trade. But its summary reported the remaining PACKAGE bytes as the cache size, so a run that freed everything in scope printed "cache now 0.0 B" with tens of MB of std BMIs sitting right next to it. e2e now pins both halves: the budget is met, std survives, and the figure says what it measured.
1 parent 20f5ceb commit 00fcea9

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/bmi_cache/maintenance.cppm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,11 @@ export int cache_gc(const std::string& maxSizeArg, const std::string& olderThanA
460460
e.label, human_bytes(e.size), format_age(e.accessed)));
461461
}
462462
std::println("");
463-
std::println("Collected {} entries, freed {} (cache now {})",
463+
// "package entries", not "cache": `live` only ever counted package entries,
464+
// because std entries are deliberately out of scope here. Reporting it as
465+
// the cache size would read as "the cache is now empty" while tens of MB of
466+
// std BMIs sit right next to it.
467+
std::println("Collected {} entries, freed {} (package entries now {})",
464468
removed, human_bytes(freed), human_bytes(live));
465469
if (maxSize && live > *maxSize) {
466470
// Say it rather than silently under-delivering: a size target that

tests/e2e/174_cache_modes_and_commands.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ rc=0
280280
"$MCPP" cache gc > gcnoargs.log 2>&1 || rc=$?
281281
[[ "$rc" -ne 0 ]] || { echo "FAIL: gc with no budget succeeded"; cat gcnoargs.log; exit 1; }
282282

283+
# gc --max-size evicts package entries to hit a budget, and leaves std entries
284+
# alone: a std BMI is shared by every project on the machine and costs ~30 s to
285+
# rebuild, so trading it for a little disk is the wrong trade. The summary must
286+
# therefore talk about PACKAGE entries — reporting it as "cache now 0 B" would
287+
# read as an empty cache while tens of MB of std BMIs sit next to it.
288+
[[ "$(entry_count)" -eq 1 ]] || { echo "FAIL: expected one package entry before gc"; exit 1; }
289+
[[ -d "$MCPP_HOME/build-cache/v1/std" ]] || { echo "FAIL: no std entries to protect"; exit 1; }
290+
"$MCPP" cache gc --max-size 1B > gcsize.log 2>&1 || { cat gcsize.log; exit 1; }
291+
[[ "$(entry_count)" -eq 0 ]] || { echo "FAIL: gc --max-size kept package entries"; cat gcsize.log; exit 1; }
292+
[[ -d "$MCPP_HOME/build-cache/v1/std" ]] || {
293+
echo "FAIL: gc --max-size evicted std entries"
294+
cat gcsize.log
295+
exit 1
296+
}
297+
grep -q 'package entries now' gcsize.log || {
298+
cat gcsize.log
299+
echo "FAIL: gc summary must scope its figure to package entries"
300+
exit 1
301+
}
302+
303+
# Refill for the clean tests below.
304+
rm -rf target
305+
"$MCPP" build > refill2.log 2>&1 || { cat refill2.log; exit 1; }
306+
283307
# ── clean --std / --all / --legacy ─────────────────────────────────────────
284308
[[ -d "$MCPP_HOME/build-cache/v1/std" ]] || { echo "FAIL: no std cache dir"; exit 1; }
285309
"$MCPP" cache clean --std > cleanstd.log 2>&1

0 commit comments

Comments
 (0)