diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df06f1..4929fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/); until 1.0, minor versions may contain breaking changes. +## [Unreleased] + +### Changed + +- **Test runner: the cache is now visible.** The runner logs for every environment how long it took until the app answered, whether the seed was a hit or a miss, and how long `install` took (e.g. `test env abc (git-…-penguin31) ready after 42 s; cache on; seed 07be…: hit; install took 3 s`). + ## [v202611-00075] – 2026-11-20 ### Changed @@ -12,16 +18,14 @@ until 1.0, minor versions may contain breaking changes. ## [v202611-00074] – 2026-11-20 -### Changed - -- **Factory: merge and close on the issue card.** A finished issue shows a *Merge* button on its card once the acceptance has passed (the pull request is open); after the merge the card shows *Close*. Before that neither button is shown. The server enforces the order: a pull request is merged only when the acceptance passed, an issue is closed only when its pull request is merged (a merge done on the forge itself counts). The issue also gets its version and tag right after a merge instead of at the next poll. - -## [v202611-00073] – 2026-11-20 - ### Added - **Test runner: cache between acceptance runs.** Every project gets a cache volume (`cc-cache-`) in the runner. Tool caches are shared automatically: npm and Yarn, pip, Go modules and build cache, the Cargo registry and the Cargo target directory (so the second build of a Rust project is incremental). `.factory/setup.json` can add `"cache": {"dirs": [...]}` for directories that persist (downloads – inputs only) and `"cache": {"seed": {"paths": [...], "key": [...]}}` for expensive *results* of `install`, such as a built disk image: the seed is stored after a successful install under a key made from the image, the install command, the seed paths and the contents of the `key` files, and copied into fresh containers only while the key matches – a run never sees changes of an earlier run, and a change of the listed sources builds it anew (the three newest seeds are kept). `"cache": false` turns everything off; `DELETE /v1/cache/` on the runner forgets a project's cache. +### Changed + +- **Factory: merge and close on the issue card.** A finished issue shows a *Merge* button on its card once the acceptance has passed (the pull request is open); after the merge the card shows *Close*. Before that neither button is shown. The server enforces the order: a pull request is merged only when the acceptance passed, an issue is closed only when its pull request is merged (a merge done on the forge itself counts). The issue also gets its version and tag right after a merge instead of at the next poll. + ## [v202611-00072] – 2026-11-20 ### Added diff --git a/server/src/testrunner.rs b/server/src/testrunner.rs index 525dfb9..cdabf9d 100644 --- a/server/src/testrunner.rs +++ b/server/src/testrunner.rs @@ -35,12 +35,16 @@ const CACHE_LABEL: &str = "codecraft.testrunner.cache=1"; /// What every environment container runs: link the shared directories, restore a matching seed, run /// `install`, store a new seed (only after a successful install, so it is pristine), start the app. const ENTRY_SCRIPT: &str = r#"cd /app +hit=0 if [ -d /cache ]; then for d in $CC_CACHE_DIRS; do mkdir -p "/cache/dirs/$d" "$(dirname "$d")" && rm -rf "$d" && ln -s "/cache/dirs/$d" "$d"; done if [ -d /usr/local/cargo ]; then for d in registry git; do mkdir -p "/cache/cargo/$d"; rm -rf "/usr/local/cargo/$d"; ln -s "/cache/cargo/$d" "/usr/local/cargo/$d"; done; fi - if [ -n "$CC_SEED_KEY" ]; then for p in $CC_SEED_PATHS; do if [ -e "/cache/seed/$CC_SEED_KEY/$p" ]; then mkdir -p "$(dirname "$p")" && cp -a "/cache/seed/$CC_SEED_KEY/$p" "$p" && echo "[runner] restored $p from the cache"; fi; done; fi + if [ -n "$CC_SEED_KEY" ]; then for p in $CC_SEED_PATHS; do if [ -e "/cache/seed/$CC_SEED_KEY/$p" ]; then mkdir -p "$(dirname "$p")" && cp -a "/cache/seed/$CC_SEED_KEY/$p" "$p" && hit=1 && echo "[runner] restored $p from the cache"; fi; done; fi fi +if [ -n "$CC_SEED_KEY" ]; then if [ "$hit" = 1 ]; then echo "[runner] seed $CC_SEED_KEY: hit"; else echo "[runner] seed $CC_SEED_KEY: miss"; fi; fi +t0=$(date +%s) if [ -n "$CC_INSTALL" ]; then sh -c "$CC_INSTALL" || exit 1; fi +echo "[runner] install took $(( $(date +%s) - t0 )) s" if [ -d /cache ] && [ -n "$CC_SEED_KEY" ] && [ ! -d "/cache/seed/$CC_SEED_KEY" ]; then t="/cache/seed/.tmp-$$"; rm -rf "$t"; mkdir -p "$t"; ok=1 for p in $CC_SEED_PATHS; do if [ -e "$p" ]; then mkdir -p "$t/$(dirname "$p")" && cp -a "$p" "$t/$p" || ok=0; fi; done @@ -434,6 +438,7 @@ async fn start_env(State(r): State>, h: HeaderMap, Json(req): Json, id: &str, req: &StartReq, work: &Path) -> Result { + let began = Instant::now(); let net = format!("cc-run-{id}"); let app = format!("cc-run-{id}"); // Register first, so a failure at any step is cleaned up by stop(). @@ -542,6 +547,11 @@ async fn create(r: &Arc, id: &str, req: &StartReq, work: &Path) -> Resul } tokio::time::sleep(Duration::from_millis(700)).await; } + // Report what the cache brought: seed hit/miss, install time, total time until the app answered. + let facts: Vec = logs(&app).await.lines().filter(|l| l.starts_with("[runner] seed ") || l.starts_with("[runner] install took")).map(|l| l.trim_start_matches("[runner] ").to_string()).collect(); + let took = began.elapsed().as_secs(); + let cache = if cached { "on" } else { "off" }; + tracing::info!("test env {id} ({}) ready after {took} s; cache {cache}{}{}", req.cache_id, if facts.is_empty() { "" } else { "; " }, facts.join("; ")); let (listener, port) = bind_forward(r).await?; let (target, tport) = (ip, req.port); let fwd = tokio::spawn(async move { diff --git a/web/src/whatsnew.ts b/web/src/whatsnew.ts index d4606f6..f4c4543 100644 --- a/web/src/whatsnew.ts +++ b/web/src/whatsnew.ts @@ -3,17 +3,17 @@ * under "unreleased"; scripts/release.sh renames the key to the release version. */ export const WHATS_NEW: Record = { + unreleased: { + en: ["Factory test runner: logs how long an environment took to start and whether the cache seed was a hit"], + de: ["Factory-Test-Runner: protokolliert, wie lange eine Umgebung zum Start brauchte und ob der Cache-Seed getroffen hat"], + }, "202611-00075": { en: ["Factory: the lamp of a phase being prepared now differs in colour from the accent in every theme"], de: ["Factory: die Lampe einer Phase in Vorbereitung unterscheidet sich in jedem Theme farblich vom Akzent"], }, "202611-00074": { - en: ["Factory: Merge and Close buttons on the issue card – merge after a positive acceptance, close after the merge"], - de: ["Factory: Merge- und Schließen-Knopf auf der Issue-Karte – Merge nach erfolgreicher Abnahme, Schließen nach dem Merge"], - }, - "202611-00073": { - en: ["Factory test runner: caches between acceptance runs (npm, Cargo, pip, Go and optional seeds of the install step) – the test environment starts much faster"], - de: ["Factory-Test-Runner: Caches zwischen Abnahmeläufen (npm, Cargo, pip, Go und optionale Seeds des Install-Schritts) – die Testumgebung startet deutlich schneller"], + en: ["Factory: Merge and Close buttons on the issue card – merge after a positive acceptance, close after the merge", "Factory test runner: caches between acceptance runs (npm, Cargo, pip, Go and optional seeds of the install step) – the test environment starts much faster"], + de: ["Factory: Merge- und Schließen-Knopf auf der Issue-Karte – Merge nach erfolgreicher Abnahme, Schließen nach dem Merge", "Factory-Test-Runner: Caches zwischen Abnahmeläufen (npm, Cargo, pip, Go und optionale Seeds des Install-Schritts) – die Testumgebung startet deutlich schneller"], }, "202611-00072": { en: ["Factory: a blinking blue lamp shows that a phase is being prepared (checkout, test environment) before its chat starts"],