From 56d955690ba8514202f195f668d8889988ae170a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 00:04:07 +0100 Subject: [PATCH] Playtest launcher: build the test binary once on Yggdrasil, run it detached under a transient unit with the connector key; turns, worlds and wall time are arguments Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/playtest.rs | 6 +- scripts/playtest-yggdrasil.sh | 88 +++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 scripts/playtest-yggdrasil.sh diff --git a/crates/ghostlight-dungeon/src/playtest.rs b/crates/ghostlight-dungeon/src/playtest.rs index ed7cb32..5f8f12b 100644 --- a/crates/ghostlight-dungeon/src/playtest.rs +++ b/crates/ghostlight-dungeon/src/playtest.rs @@ -142,6 +142,8 @@ pub(crate) struct Options { worlds: Option>, wall_minutes: Option, plan: Option, + /// The dated directory's name, so a launcher can print it before the run makes it. + stamp: Option, } impl Options { @@ -161,6 +163,7 @@ impl Options { .map(|text| text.split(',').map(|id| id.trim().to_owned()).collect()), wall_minutes: number("GHOSTLIGHT_PLAYTEST_WALL_MINUTES")?, plan: std::env::var_os("GHOSTLIGHT_PLAYTEST_PLAN").map(PathBuf::from), + stamp: std::env::var("GHOSTLIGHT_PLAYTEST_STAMP").ok().filter(|text| !text.trim().is_empty()), }) } } @@ -976,7 +979,8 @@ pub(crate) async fn run(options: Options) -> anyhow::Result { } let turns = options.turns.unwrap_or(plan.turns_per_character); let wall = Duration::from_secs(options.wall_minutes.unwrap_or(plan.wall_minutes) * 60); - let root = options.out.join(Utc::now().format("%Y-%m-%dT%H%MZ").to_string()); + let stamp = options.stamp.clone().unwrap_or_else(|| Utc::now().format("%Y-%m-%dT%H%MZ").to_string()); + let root = options.out.join(stamp); std::fs::create_dir_all(root.join("state"))?; let root = std::fs::canonicalize(&root)?; let state_root = root.join("state"); diff --git a/scripts/playtest-yggdrasil.sh b/scripts/playtest-yggdrasil.sh new file mode 100644 index 0000000..773c6f8 --- /dev/null +++ b/scripts/playtest-yggdrasil.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# Run the Dungeon playtest on Yggdrasil: build the test binary once, then run it +# detached under a transient systemd unit that loads the Ghostlight connector key. +# +# scripts/playtest-yggdrasil.sh [--turns N] [--worlds id,id] [--wall-minutes M] +# [--out DIR] [--rev REV] +# +# Defaults: every world in crates/ghostlight-dungeon/playtest/plan.json, 12 turns +# per character, 240 minutes of wall time. Run it from a worktree with the +# Eureka skill's ygg-verify.sh reachable as $YGG_VERIFY (default +# ~/.claude/skills/eureka/tools/stopgap/ygg-verify.sh). The launcher clones REV on +# Yggdrasil, builds there, and exits once the unit is running; the unit keeps going. +# Vault copies live under $VAULT_BASE (default ~/ghostlight-playtest/vaults, holding +# AetheriaLore/Aetheria and Delvehold/Delvehold); output goes under $OUT_BASE. +set -euo pipefail + +IMAGE=${IMAGE:-eureka-verify-rust:b99d30ec441e} +KEY=${KEY:-/etc/gamecult/claude-connector/connection-ghostlight.key} +CONNECTOR_ADDR=${CONNECTOR_ADDR:-127.0.0.1:4110} +turns=""; worlds=""; wall=""; out=""; rev=""; on_host=0; stamp="" +while [ $# -gt 0 ]; do + case "$1" in + --turns) turns=$2; shift 2 ;; + --worlds) worlds=$2; shift 2 ;; + --wall-minutes) wall=$2; shift 2 ;; + --out) out=$2; shift 2 ;; + --rev) rev=$2; shift 2 ;; + --on-host) on_host=1; shift ;; + --stamp) stamp=$2; shift 2 ;; + *) echo "unknown argument $1" >&2; exit 2 ;; + esac +done + +if [ "$on_host" = 0 ]; then + here=$(cd "$(dirname "$0")/.." && pwd) + rev=${rev:-$(git -C "$here" rev-parse --short HEAD)} + stamp=$(date -u +%Y-%m-%dT%H%MZ) + verify=${YGG_VERIFY:-$HOME/.claude/skills/eureka/tools/stopgap/ygg-verify.sh} + args="--on-host --rev $rev --stamp $stamp" + [ -n "$turns" ] && args="$args --turns $turns" + [ -n "$worlds" ] && args="$args --worlds $worlds" + [ -n "$wall" ] && args="$args --wall-minutes $wall" + [ -n "$out" ] && args="$args --out $out" + RUN_ON_HOST=1 TIMEOUT=3000 bash "$verify" "$here" "$rev" "$IMAGE" "bash scripts/playtest-yggdrasil.sh $args" + exit $? +fi + +# On the Yggdrasil host, inside the clone of REV. +base=${PLAYTEST_BASE:-$HOME/ghostlight-playtest} +out=${out:-$base/out} +bin_dir=$base/bin +mkdir -p "$bin_dir" "$out" +bin=$bin_dir/ghostlight-dungeon-$rev +if [ ! -x "$bin" ]; then + sudo docker run --rm --cpus=4 --memory=6g \ + -v "$PWD:/src" -v eureka-cargo-home:/cargo-home -e CARGO_HOME=/cargo-home \ + -e GHOSTLIGHT_BUILD_COMMIT="$rev" -v "$bin_dir:/out" -w /src "$IMAGE" bash -c ' + set -euo pipefail + exe=$(cargo test --locked -p ghostlight-dungeon --no-run --message-format=json 2>/dev/null \ + | grep "\"test\":true" | grep "\"executable\":\"[^\"]*/ghostlight_dungeon-" \ + | sed "s/.*\"executable\":\"\([^\"]*\)\".*/\1/" | tail -1) + test -n "$exe" + cp "$exe" /out/ghostlight-dungeon-'"$rev"' + ' +fi +test -x "$bin" + +unit=ghostlight-playtest-$stamp +env_args=(--setenv=GHOSTLIGHT_CONNECTOR_ADDR="$CONNECTOR_ADDR" + --setenv=GHOSTLIGHT_CONNECTOR_KEY_FILE="/run/credentials/$unit.service/connector-key" + --setenv=GHOSTLIGHT_VAULT_BASE="${VAULT_BASE:-$base/vaults}" + --setenv=GHOSTLIGHT_PLAYTEST_OUT="$out" --setenv=GHOSTLIGHT_PLAYTEST_STAMP="$stamp") +[ -n "$turns" ] && env_args+=(--setenv=GHOSTLIGHT_PLAYTEST_TURNS="$turns") +[ -n "$worlds" ] && env_args+=(--setenv=GHOSTLIGHT_PLAYTEST_WORLDS="$worlds") +[ -n "$wall" ] && env_args+=(--setenv=GHOSTLIGHT_PLAYTEST_WALL_MINUTES="$wall") +[ -n "${GHOSTLIGHT_CONTROLLER_MAX_CONCURRENT:-}" ] && env_args+=(--setenv=GHOSTLIGHT_CONTROLLER_MAX_CONCURRENT="$GHOSTLIGHT_CONTROLLER_MAX_CONCURRENT") + +sudo systemd-run --unit "$unit" --collect --quiet \ + -p User="$(id -un)" -p LoadCredential=connector-key:"$KEY" \ + -p StandardOutput=append:"$out/$stamp.run.log" -p StandardError=append:"$out/$stamp.run.log" \ + "${env_args[@]}" \ + "$bin" --ignored --exact playtest::live_playtest --nocapture --test-threads=1 + +echo "unit: $unit" +echo "output: $out/$stamp" +echo "run log: $out/$stamp.run.log" +echo "progress: tail -f $out/$stamp/progress.log" +echo "status: systemctl status $unit"