Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

test-infra(vm): remove embedded SSH key, pin host identity and installer

Martin Vogeld82637457778
diff --git a/scripts/test.sh b/scripts/test.sh
index a992be2a9..3e1acc624 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -61,10 +61,13 @@ print_env "test.sh"
echo "=== Step 0a: Windows launcher bundle contract ==="
bash "$ROOT/tests/test_windows_bundle_contract.sh"
-echo "=== Step 0b: tree-sitter runtime Makefile dependencies ==="
+echo "=== Step 0b: Windows VM worktree sync contract ==="
+bash "$ROOT/tests/test_vm_worktree_manifest.sh"
+
+echo "=== Step 0c: tree-sitter runtime Makefile dependencies ==="
bash "$ROOT/tests/test_makefile_ts_runtime_dependencies.sh"
-echo "=== Step 0c: security fuzz harness self-test ==="
+echo "=== Step 0d: security fuzz harness self-test ==="
bash "$ROOT/tests/test_security_fuzz_harness.sh"
# Verify compiler supports target arch
diff --git a/test-infrastructure/run.sh b/test-infrastructure/run.sh
index c6396ac22..43c33d267 100755
--- a/test-infrastructure/run.sh
+++ b/test-infrastructure/run.sh
@@ -1,18 +1,14 @@
#!/usr/bin/env bash
-# Local CI — test all platforms before pushing.
+# Containerized local-CI legs. Before pushing, pair these with native macOS
+# tests and the real-Windows VM gate documented below.
#
# Coverage:
# Linux arm64: test (ASan+LeakSan) + build (-O2) [native, fast]
# Linux amd64: test + build [QEMU, slower]
# Linux portable: Alpine musl static build + smoke [portable binary]
-# Windows: cross-compile with mingw-w64 [compile-check; Wine
-# CANNOT reproduce real Windows ACL/token/owner semantics —
-# use the windows-vm leg for those]
+# Windows: cross-compile with mingw-w64 [compile-check; use
+# vm/win.sh for mandatory real-Windows verification]
# macOS: run natively (not in Docker)
-# windows-vm: OPT-IN real Windows (UTM) — kernel-real ACL/token/owner
-# semantics incl. the runner default-owner policy (vm/README.md)
-# mac-vm: OPT-IN GitHub-runner macOS environment (Tart) — the env
-# class where runner-only failures reproduce (vm/README.md)
#
# Speed first: test containers run unconstrained by default. Before pushing
# anything that touches timing, scheduling, or subprocess code, run ONE pass
@@ -24,8 +20,8 @@
# this script resides in.
#
# Usage:
-# ./test-infrastructure/run.sh # arm64 test+build + portable + Windows
-# ./test-infrastructure/run.sh all # above + amd64
+# ./test-infrastructure/run.sh # arm64 + portable + Windows cross-compile
+# ./test-infrastructure/run.sh all # above + amd64 + Windows Wine smoke
# ./test-infrastructure/run.sh portable # Alpine portable build + smoke only
# ./test-infrastructure/run.sh windows # Windows cross-compile only
# ./test-infrastructure/run.sh test # Linux arm64 test only (no perf)
@@ -55,6 +51,11 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
COMPOSE="docker compose -f $ROOT/test-infrastructure/docker-compose.yml"
+print_real_windows_gate() {
+ echo "=== Container/cross-compile legs passed ==="
+ echo "=== Real-Windows gate remains: vm/win.sh sync, test, guards, smoke-install ==="
+}
+
if ! docker info >/dev/null 2>&1; then
echo "ERROR: no Docker daemon reachable." >&2
echo " Start one first — on macOS: colima start --vm-type vz --vz-rosetta --cpu 12 --memory 16" >&2
@@ -78,7 +79,7 @@ case "${1:-full}" in
$COMPOSE run --rm smoke-portable
echo "=== Windows: cross-compile ==="
$COMPOSE run --rm build-windows
- echo "=== All passed ==="
+ print_real_windows_gate
;;
test)
echo "=== Linux arm64: test (ASan + LeakSanitizer, no perf) ==="
@@ -134,7 +135,7 @@ case "${1:-full}" in
$COMPOSE run --rm smoke-amd64
echo "=== Windows: cross-compile + smoke (Wine) ==="
$COMPOSE run --rm smoke-windows
- echo "=== All platforms passed ==="
+ print_real_windows_gate
;;
lint)
echo "=== Linters (clang-format-20 + cppcheck 2.20.0) ==="
@@ -148,50 +149,8 @@ case "${1:-full}" in
echo "=== Debug shell (Alpine) ==="
$COMPOSE run --rm --entrypoint bash test-portable
;;
- windows-vm)
- # OPT-IN: real Windows semantics (ACL/token/owner) — see vm/README.md.
- [ -f "$ROOT/test-infrastructure/vm/config.env" ] && . "$ROOT/test-infrastructure/vm/config.env"
- if [ -z "${CBM_WIN_VM_SSH:-}" ]; then
- echo "windows-vm leg not configured (opt-in)." >&2
- echo " Setup: test-infrastructure/vm/README.md — UTM + CrystalFetch," >&2
- echo " run vm/windows-bootstrap.ps1 in the VM, then set CBM_WIN_VM_SSH" >&2
- echo " in test-infrastructure/vm/config.env" >&2
- exit 2
- fi
- echo "=== Windows VM: sync + build + test (real ACL/token semantics) ==="
- SUITES="${2:-}"
- tar -C "$ROOT" --exclude build --exclude .git -cf - . | ssh "$CBM_WIN_VM_SSH" \
- "C:/msys64/usr/bin/bash.exe -lc 'rm -rf /c/cbm/src && mkdir -p /c/cbm/src && cd /c/cbm/src && tar -xf - && scripts/test.sh CC=clang CXX=clang++ ${SUITES:+TEST_SUITES=\"$SUITES\"}'"
- ;;
- mac-vm)
- # OPT-IN: GitHub-runner-equivalent macOS environment — see vm/README.md.
- if ! command -v tart >/dev/null 2>&1 || ! tart list 2>/dev/null | grep -q cbm-mac-runner; then
- echo "mac-vm leg not configured (opt-in)." >&2
- echo " Setup: brew trust cirruslabs/cli && brew install tart &&" >&2
- echo " tart clone ghcr.io/cirruslabs/macos-runner:sequoia cbm-mac-runner" >&2
- exit 2
- fi
- echo "=== macOS runner VM: sync + test (GitHub-runner environment) ==="
- tart run --no-graphics cbm-mac-runner >/dev/null 2>&1 &
- TART_PID=$!
- trap '{ kill "$TART_PID" 2>/dev/null || true; }' EXIT
- VM_IP=""
- for _ in $(seq 1 60); do
- VM_IP=$(tart ip cbm-mac-runner 2>/dev/null) && [ -n "$VM_IP" ] && break
- sleep 2
- done
- [ -n "$VM_IP" ] || { echo "ERROR: VM did not obtain an IP" >&2; exit 1; }
- if ! ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new "admin@$VM_IP" true 2>/dev/null; then
- echo "One-time: install your key in the VM (password: admin):" >&2
- echo " ssh-copy-id admin@$VM_IP" >&2
- exit 2
- fi
- tar -C "$ROOT" --exclude build --exclude .git -cf - . | \
- ssh -o BatchMode=yes "admin@$VM_IP" \
- 'rm -rf ~/cbm-src && mkdir -p ~/cbm-src && cd ~/cbm-src && tar -xf - && scripts/test.sh CC=cc CXX=c++'
- ;;
*)
- echo "Usage: $0 {full|test|build|smoke|portable|portable-test|windows|amd64|all|lint|shell|shell-alpine|windows-vm|mac-vm}"
+ echo "Usage: $0 {full|test|perf|build|smoke|portable|portable-test|windows|smoke-windows|soak-windows|amd64|all|lint|shell|shell-alpine}"
exit 1
;;
esac
diff --git a/test-infrastructure/vm/README.md b/test-infrastructure/vm/README.md
index 9f465e0da..3ea888a7f 100644
--- a/test-infrastructure/vm/README.md
+++ b/test-infrastructure/vm/README.md
@@ -1,9 +1,9 @@
-# VM test legs — real-Windows and runner-macOS
+# Real-Windows local-CI leg
-Two failure classes cannot be reproduced by the container legs and need real
-virtual machines. Both stacks are free. The Windows VM is a first-class part
-of the mandatory local-CI gate (see the repo's local-first workflow): it is
-driven entirely over ssh by reproducible scripts in this directory.
+Windows kernel semantics cannot be reproduced by the container/Wine legs. The
+UTM VM is a first-class part of the mandatory local-CI gate and is driven over
+local ssh by the reproducible scripts in this directory. The canonical macOS
+leg remains the native host; Linux runs through Colima.
## Windows VM — real ACL/token/owner semantics (script-driven)
@@ -21,10 +21,14 @@ seconds-fast local loop with full stderr/debugger visibility.
| `win.sh` | on the host | daily driver: build / test / guards / install-E2E / shell |
Host-local config (never committed): `~/.claude/cbm-vm/config` with
-`CBM_VM_HOST=<ip>` and `CBM_VM_USER=<user>`; ssh keypair at
+`CBM_VM_HOST=<ip>`, `CBM_VM_USER=<user>`, and the
+`CBM_VM_HOST_KEY_SHA256=<SHA256:...>` fingerprint printed by the bootstrap.
+`CBM_VM_BRANCH=<branch>` is optional; both drivers otherwise use the current
+local Git branch, falling back to `main` only for a detached worktree.
+The drivers verify that fingerprint before every connection. The ssh keypair is at
`~/.claude/cbm-vm/id_ed25519` (generate: `ssh-keygen -t ed25519 -N "" -C
-claude-cbm-vm -f ~/.claude/cbm-vm/id_ed25519`, public half goes into
-`windows-bootstrap.ps1`).
+claude-cbm-vm -f ~/.claude/cbm-vm/id_ed25519`; include the public half beside
+`windows-bootstrap.ps1` on the setup ISO as documented in that script).
### One-time VM creation (~30 min interactive, do it once, snapshot it)
@@ -58,7 +62,8 @@ claude-cbm-vm -f ~/.claude/cbm-vm/id_ed25519`, public half goes into
### Daily loop
```
-vm/win.sh update # sync VM repo to the pushed branch + rebuild
+vm/win.sh update # sync VM repo to the pushed current branch + rebuild
+vm/win.sh sync # mirror the uncommitted worktree and rebuild before local gates
vm/win.sh test cli daemon_ipc # run suites natively, seconds
vm/win.sh guards # the Windows guard scripts
vm/win.sh smoke-install # managed-install E2E, stderr VISIBLE
@@ -66,6 +71,10 @@ vm/win.sh sh "cd /c/cbm && gdb ..." # anything, interactively
vm/win.sh push-file src/cli/cli.c /c/cbm/src/cli/cli.c # WIP iteration
```
+`sync` requires the VM to already have the exact pushed base commit (`update`
+does that); it then mirrors the host's uncommitted tracked and untracked changes,
+cleans stale build outputs, and rebuilds.
+
### Toolchains & honest limits
- **CLANGARM64 (native, default)**: fast on all cores; OS-semantics bugs
@@ -91,20 +100,6 @@ vm/win.sh push-file src/cli/cli.c /c/cbm/src/cli/cli.c # WIP iteration
- Environment shape (runner temp paths, runneradmin profile) is
approximated, not identical — CI on the final SHA remains the proof.
-## macOS runner VM (`run.sh mac-vm`) — the GitHub-runner macOS environment
-
-A local Mac is not the GitHub macOS runner (different temp ancestry, ACLs,
-policies): failures like the index-supervisor worker exits reproduce only
-there. Cirrus Labs publishes runner-equivalent images.
-
-1. `brew trust cirruslabs/cli && brew install tart` (free OSS).
-2. `tart clone ghcr.io/cirruslabs/macos-runner:sequoia cbm-mac-runner`
- (tens of GB, one time).
-
-The leg boots the VM headless (`tart run --no-graphics cbm-mac-runner`),
-syncs the worktree over ssh (admin/admin inside the runner image), and
-executes `scripts/test.sh`.
-
## Honesty rules
- These legs never silently skip: absent tooling prints setup guidance and
diff --git a/test-infrastructure/vm/provision-windows.sh b/test-infrastructure/vm/provision-windows.sh
index 66b049a1f..31c3a3e52 100644
--- a/test-infrastructure/vm/provision-windows.sh
+++ b/test-infrastructure/vm/provision-windows.sh
@@ -8,10 +8,13 @@
# 1. UTM VM with Windows 11 ARM64 installed, CLONED as a backup before
# drivers, SPICE guest tools installed (network), and
# windows-bootstrap.ps1 run inside the VM (OpenSSH + authorized key).
-# 2. Host config in ~/.claude/cbm-vm/config (KEY=VALUE):
-# CBM_VM_HOST=192.168.64.4
-# CBM_VM_USER=test
-# Key at ~/.claude/cbm-vm/id_ed25519 (see README.md to generate).
+# 2. Host config in ~/.claude/cbm-vm/config (KEY=VALUE), values printed by
+# windows-bootstrap.ps1 at the end of its run:
+# CBM_VM_HOST=<vm ip>
+# CBM_VM_USER=<vm user>
+# CBM_VM_HOST_KEY_SHA256=<SHA256:... host-key fingerprint>
+# Key at ~/.claude/cbm-vm/id_ed25519 (see README.md to generate your own;
+# never commit keys or this config).
#
# Usage:
# test-infrastructure/vm/provision-windows.sh # full provision
@@ -20,20 +23,37 @@ set -euo pipefail
CONFIG="${HOME}/.claude/cbm-vm/config"
KEY="${HOME}/.claude/cbm-vm/id_ed25519"
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+# The fixed host-local config is intentionally outside this repository.
+# shellcheck source=/dev/null
[ -f "$CONFIG" ] && . "$CONFIG"
HOST="${CBM_VM_HOST:?set CBM_VM_HOST in ~/.claude/cbm-vm/config}"
USER_="${CBM_VM_USER:-test}"
-BRANCH="${CBM_VM_BRANCH:-feat/shared-coordination-daemon}"
+HOST_KEY="${CBM_VM_HOST_KEY_SHA256:?set CBM_VM_HOST_KEY_SHA256 in ~/.claude/cbm-vm/config}"
+LOCAL_BRANCH="$(git -C "$ROOT" branch --show-current)"
+BRANCH="${CBM_VM_BRANCH:-${LOCAL_BRANCH:-main}}"
REPO_URL="${CBM_VM_REPO:-https://github.com/DeusData/codebase-memory-mcp.git}"
-MSYS2_SFX_URL="https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe"
+MSYS2_SFX_URL="https://github.com/msys2/msys2-installer/releases/download/2026-06-11/msys2-base-x86_64-20260611.sfx.exe"
+MSYS2_SFX_SHA256="c105946e64e08f099ac0e4647461ce762b95333ad211777666476a9a41451d65"
-SSH=(ssh -i "$KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
- -o ConnectTimeout=10 -o BatchMode=yes "${USER_}@${HOST}")
+# shellcheck source=test-infrastructure/vm/ssh-common.sh
+source "$SCRIPT_DIR/ssh-common.sh"
+cbm_vm_require_safe_branch "$BRANCH"
+cbm_vm_prepare_known_hosts "$HOST" "$HOST_KEY"
+trap cbm_vm_cleanup_known_hosts EXIT
+SSH_OPTIONS=(-i "$KEY" -o IdentitiesOnly=yes -o HostKeyAlgorithms=ssh-ed25519 \
+ -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$CBM_VM_KNOWN_HOSTS" \
+ -o ConnectTimeout=10 -o BatchMode=yes)
+SSH=(ssh "${SSH_OPTIONS[@]}" "${USER_}@${HOST}")
+# Expand inside the remote MSYS2 shell, not on the macOS host.
+# shellcheck disable=SC2016
+JOBS='$(nproc)'
# Run a command inside the given msys2 environment (clangarm64|clang64|msys).
vm() { # vm <env> <command...>
local env="$1"; shift
- "${SSH[@]}" "C:\\msys64\\msys2_shell.cmd -defterm -no-start -${env} -c \"$*\""
+ "${SSH[@]}" "C:\\msys64\\msys2_shell.cmd -defterm -no-start -${env} -c \"set -e -o pipefail; $*\""
}
vm_cmd() { "${SSH[@]}" "$@"; } # plain cmd.exe
@@ -49,13 +69,15 @@ vm_cmd "echo VM_OK & ver" | grep -q VM_OK || {
if [ "${1:-}" != "--update" ]; then
step "1/6 msys2 base (skip if present)"
if ! vm_cmd "if exist C:\\msys64\\usr\\bin\\bash.exe echo MSYS2_PRESENT" | grep -q MSYS2_PRESENT; then
- vm_cmd "powershell -Command \"[Net.ServicePointManager]::SecurityProtocol='Tls12'; Invoke-WebRequest -Uri ${MSYS2_SFX_URL} -OutFile C:\\msys2.sfx.exe\""
+ vm_cmd "powershell -NoProfile -Command \"\$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol='Tls12'; Invoke-WebRequest -Uri '${MSYS2_SFX_URL}' -OutFile C:\\msys2.sfx.exe; \$actual=(Get-FileHash -LiteralPath C:\\msys2.sfx.exe -Algorithm SHA256).Hash.ToLowerInvariant(); if (\$actual -ne '${MSYS2_SFX_SHA256}') { Remove-Item -LiteralPath C:\\msys2.sfx.exe -Force; throw 'MSYS2 installer SHA-256 mismatch' }\""
vm_cmd "C:\\msys2.sfx.exe -y -oC:\\" >/dev/null
+ vm_cmd "del C:\\msys2.sfx.exe"
vm "msys" "pacman-key --init && pacman-key --populate msys2"
fi
- step "2/6 pacman update (repeat-safe)"
- vm "msys" "rm -f /var/lib/pacman/db.lck; pacman -Syu --noconfirm --noprogressbar" || true
+ step "2/6 pacman full update (official two-pass sequence)"
+ vm "msys" "pacman --noconfirm --noprogressbar -Syuu"
+ vm "msys" "pacman --noconfirm --noprogressbar -Syuu"
step "3/6 toolchains: CLANGARM64 (native, fast) + CLANG64 (x86_64 = CI arch, ASan)"
vm "msys" "pacman -S --noconfirm --noprogressbar --needed \
@@ -68,13 +90,13 @@ fi
step "4/6 repo clone/update -> /c/cbm @ ${BRANCH}"
if vm "clangarm64" "test -d /c/cbm/.git && echo REPO_PRESENT" | grep -q REPO_PRESENT; then
- vm "clangarm64" "cd /c/cbm && git fetch origin ${BRANCH} && git reset --hard FETCH_HEAD && git log --oneline -1"
+ vm "clangarm64" "cd /c/cbm && git fetch origin ${BRANCH} && git reset --hard FETCH_HEAD && git clean -fdx && git log --oneline -1"
else
vm "clangarm64" "git clone --branch ${BRANCH} --single-branch --depth 200 ${REPO_URL} /c/cbm && cd /c/cbm && git log --oneline -1"
fi
step "5/6 build: native ARM64 binary + launcher + test-runner (no ASan on arm64)"
-vm "clangarm64" "cd /c/cbm && make -j\\\$(nproc) -f Makefile.cbm CC=clang CXX=clang++ SANITIZE= cbm build/c/test-runner > /tmp/provision-build.log 2>&1 && echo BUILD_OK || (echo BUILD_FAIL; tail -15 /tmp/provision-build.log; exit 1)"
+vm "clangarm64" "cd /c/cbm && make -j${JOBS} -f Makefile.cbm CC=clang CXX=clang++ SANITIZE= cbm build/c/test-runner > /tmp/provision-build.log 2>&1 && echo BUILD_OK || (echo BUILD_FAIL; tail -15 /tmp/provision-build.log; exit 1)"
step "6/6 smoke: binary + test-runner start"
vm "clangarm64" "cd /c/cbm && ./build/c/codebase-memory-mcp.exe --version && ./build/c/test-runner --list-suites | head -3"
diff --git a/test-infrastructure/vm/ssh-common.sh b/test-infrastructure/vm/ssh-common.sh
new file mode 100644
index 000000000..8977e2b4e
--- /dev/null
+++ b/test-infrastructure/vm/ssh-common.sh
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+# Shared pinned-host verification for the local Windows VM drivers.
+
+cbm_vm_require_safe_branch() {
+ local branch="${1-}"
+ if [[ ! "$branch" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] ||
+ ! git check-ref-format --branch "$branch" >/dev/null 2>&1; then
+ echo "FATAL: CBM_VM_BRANCH is not a safe Git branch name: $branch" >&2
+ return 1
+ fi
+}
+
+cbm_vm_prepare_known_hosts() {
+ local host="$1"
+ local expected="$2"
+ local actual
+
+ if [[ ! "$expected" =~ ^SHA256:[A-Za-z0-9+/]{43}$ ]]; then
+ echo "FATAL: CBM_VM_HOST_KEY_SHA256 is missing or malformed." >&2
+ echo " Copy the SHA256:... Ed25519 fingerprint printed by windows-bootstrap.ps1." >&2
+ return 1
+ fi
+
+ CBM_VM_KNOWN_HOSTS="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-known-hosts.XXXXXX")"
+ chmod 600 "$CBM_VM_KNOWN_HOSTS"
+ if ! ssh-keyscan -T 10 -t ed25519 "$host" >"$CBM_VM_KNOWN_HOSTS" 2>/dev/null; then
+ echo "FATAL: could not read the Windows VM Ed25519 host key at $host." >&2
+ cbm_vm_cleanup_known_hosts
+ return 1
+ fi
+ actual="$(ssh-keygen -lf "$CBM_VM_KNOWN_HOSTS" -E sha256 2>/dev/null | awk '{print $2}')"
+ if [ "$actual" != "$expected" ]; then
+ echo "FATAL: Windows VM SSH host-key mismatch." >&2
+ echo " expected: $expected" >&2
+ echo " observed: ${actual:-unreadable}" >&2
+ echo " Stop: verify the fingerprint from the VM console; do not accept it blindly." >&2
+ cbm_vm_cleanup_known_hosts
+ return 1
+ fi
+}
+
+cbm_vm_cleanup_known_hosts() {
+ if [ -n "${CBM_VM_KNOWN_HOSTS:-}" ]; then
+ rm -f -- "$CBM_VM_KNOWN_HOSTS"
+ CBM_VM_KNOWN_HOSTS=""
+ fi
+}
+
+cbm_vm_write_untracked_manifest() {
+ local root="$1"
+ local manifest="$2"
+ local symlinks
+ local entry
+ local mode
+ local relative
+ local link
+ local nested
+
+ symlinks="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-symlinks.XXXXXX")"
+ : >"$manifest"
+ while IFS= read -r -d '' entry; do
+ mode="${entry%% *}"
+ relative="${entry#*$'\t'}"
+ if [ "$mode" = "120000" ]; then
+ printf '%s\0' "$relative" >>"$symlinks"
+ fi
+ done < <(git -C "$root" ls-files --stage -z)
+
+ while IFS= read -r -d '' relative; do
+ nested=false
+ while IFS= read -r -d '' link; do
+ case "$relative" in
+ "$link"/*) nested=true; break ;;
+ esac
+ done <"$symlinks"
+ if ! $nested && [ -L "$root/$relative" ]; then
+ echo "FATAL: untracked symlink cannot be mirrored to Windows: $relative" >&2
+ echo " Stage the symlink so the binary Git patch carries its platform semantics." >&2
+ rm -f -- "$symlinks"
+ return 1
+ fi
+ if ! $nested && [ -e "$root/$relative" ]; then
+ printf '%s\0' "$relative" >>"$manifest"
+ fi
+ done < <(git -C "$root" ls-files --others --exclude-standard -z)
+ rm -f -- "$symlinks"
+}
diff --git a/test-infrastructure/vm/vm-smoke.sh b/test-infrastructure/vm/vm-smoke.sh
index e3744fa7d..ae93affe6 100644
--- a/test-infrastructure/vm/vm-smoke.sh
+++ b/test-infrastructure/vm/vm-smoke.sh
@@ -9,7 +9,7 @@
#
# Run inside the VM's CLANGARM64 shell from the repo root:
# bash test-infrastructure/vm/vm-smoke.sh
-# Or from the host: test-infrastructure/vm/win.sh smoke
+# Or from the host: test-infrastructure/vm/win.sh smoke-install
set -euo pipefail
cd "$(dirname "$0")/../.."
diff --git a/test-infrastructure/vm/win.sh b/test-infrastructure/vm/win.sh
index f803f264c..6de6596a8 100644
--- a/test-infrastructure/vm/win.sh
+++ b/test-infrastructure/vm/win.sh
@@ -8,9 +8,10 @@
# Usage:
# win.sh status # reachability + repo + build state
# win.sh update # fetch+reset repo to pushed branch, rebuild
+# win.sh sync # mirror this uncommitted worktree + rebuild
# win.sh build # incremental native build (binary+runner)
# win.sh test <suite...> # run test-runner suites (native ARM64)
-# win.sh guards # run the Windows guard scripts (python)
+# win.sh guards # clean UI product build + Windows guards
# win.sh smoke-install # real managed-install E2E (Phase 8 class)
# win.sh sh <command...> # arbitrary command in CLANGARM64 env
# win.sh push-file <local> <vm> # scp one file into the VM (WIP iteration)
@@ -21,17 +22,42 @@ set -euo pipefail
CONFIG="${HOME}/.claude/cbm-vm/config"
KEY="${HOME}/.claude/cbm-vm/id_ed25519"
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+# The fixed host-local config is intentionally outside this repository.
+# shellcheck source=/dev/null
[ -f "$CONFIG" ] && . "$CONFIG"
HOST="${CBM_VM_HOST:?set CBM_VM_HOST in ~/.claude/cbm-vm/config}"
USER_="${CBM_VM_USER:-test}"
-BRANCH="${CBM_VM_BRANCH:-feat/shared-coordination-daemon}"
-JOBS='\$(nproc)'
+HOST_KEY="${CBM_VM_HOST_KEY_SHA256:?set CBM_VM_HOST_KEY_SHA256 in ~/.claude/cbm-vm/config}"
+LOCAL_BRANCH="$(git -C "$ROOT" branch --show-current)"
+BRANCH="${CBM_VM_BRANCH:-${LOCAL_BRANCH:-main}}"
+# Expand inside the remote MSYS2 shell, not on the macOS host.
+# shellcheck disable=SC2016
+JOBS='$(nproc)'
-SSH=(ssh -i "$KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
- -o ConnectTimeout=10 -o BatchMode=yes "${USER_}@${HOST}")
+# shellcheck source=test-infrastructure/vm/ssh-common.sh
+source "$SCRIPT_DIR/ssh-common.sh"
+cbm_vm_require_safe_branch "$BRANCH"
+cbm_vm_prepare_known_hosts "$HOST" "$HOST_KEY"
+WIN_MANIFEST=""
+WIN_ARCHIVE=""
+WIN_PATCH=""
+win_cleanup() {
+ [ -z "$WIN_MANIFEST" ] || rm -f -- "$WIN_MANIFEST"
+ [ -z "$WIN_ARCHIVE" ] || rm -f -- "$WIN_ARCHIVE"
+ [ -z "$WIN_PATCH" ] || rm -f -- "$WIN_PATCH"
+ cbm_vm_cleanup_known_hosts
+}
+trap win_cleanup EXIT
+SSH_OPTIONS=(-i "$KEY" -o IdentitiesOnly=yes -o HostKeyAlgorithms=ssh-ed25519 \
+ -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$CBM_VM_KNOWN_HOSTS" \
+ -o ConnectTimeout=10 -o BatchMode=yes)
+SSH=(ssh "${SSH_OPTIONS[@]}" "${USER_}@${HOST}")
+SCP=(scp "${SSH_OPTIONS[@]}")
vm() { local env="$1"; shift
- "${SSH[@]}" "C:\\msys64\\msys2_shell.cmd -defterm -no-start -${env} -c \"$*\""; }
+ "${SSH[@]}" "C:\\msys64\\msys2_shell.cmd -defterm -no-start -${env} -c \"set -e -o pipefail; $*\""; }
cmd="${1:-status}"; shift || true
case "$cmd" in
@@ -40,7 +66,38 @@ status)
vm clangarm64 "cd /c/cbm 2>/dev/null && git log --oneline -1 && ls -la build/c/codebase-memory-mcp.exe build/c/test-runner.exe 2>/dev/null || echo 'repo/build missing — run provision-windows.sh'"
;;
update)
- vm clangarm64 "cd /c/cbm && git fetch origin ${BRANCH} && git reset --hard FETCH_HEAD && git log --oneline -1"
+ vm clangarm64 "cd /c/cbm && git fetch origin ${BRANCH} && git reset --hard FETCH_HEAD && git clean -fdx && git log --oneline -1"
+ exec "$0" build
+ ;;
+sync)
+ local_head="$(git -C "$ROOT" rev-parse --verify HEAD)"
+ WIN_MANIFEST="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-manifest.XXXXXX")"
+ WIN_ARCHIVE="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-worktree.XXXXXX.tar")"
+ WIN_PATCH="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-worktree.XXXXXX.patch")"
+ git -C "$ROOT" diff --binary --full-index HEAD -- >"$WIN_PATCH"
+ cbm_vm_write_untracked_manifest "$ROOT" "$WIN_MANIFEST"
+ COPYFILE_DISABLE=1 tar --no-xattrs --no-mac-metadata \
+ -C "$ROOT" --null -T "$WIN_MANIFEST" -cf "$WIN_ARCHIVE"
+ remote_head="$(vm clangarm64 "cd /c/cbm && git rev-parse --verify HEAD")"
+ remote_head="${remote_head//$'\r'/}"
+ if [ "$remote_head" != "$local_head" ]; then
+ echo "FATAL: Windows VM is at $remote_head, expected local HEAD $local_head; run win.sh update first." >&2
+ exit 1
+ fi
+ vm clangarm64 \
+ "cd /c/cbm && git reset --hard '$local_head' && git clean -fdx"
+ if [ -s "$WIN_PATCH" ]; then
+ "${SSH[@]}" \
+ 'C:\msys64\msys2_shell.cmd -defterm -no-start -clangarm64 -c "cd /c/cbm && git apply --binary --whitespace=nowarn -"' \
+ <"$WIN_PATCH"
+ fi
+ if [ -s "$WIN_MANIFEST" ]; then
+ "${SSH[@]}" \
+ 'C:\msys64\msys2_shell.cmd -defterm -no-start -clangarm64 -c "cd /c/cbm && tar -xf -"' \
+ <"$WIN_ARCHIVE"
+ fi
+ vm clangarm64 "cd /c/cbm && git status --short --branch"
+ win_cleanup
exec "$0" build
;;
build)
@@ -51,12 +108,16 @@ test)
vm clangarm64 "cd /c/cbm && ./build/c/test-runner $* 2>&1 | tail -40"
;;
guards)
- vm clangarm64 "cd /c/cbm && for g in tests/windows/test_*.py; do echo \"== \\\$g ==\"; python \\\$g build/c/codebase-memory-mcp.exe 2>&1 | tail -6; done"
+ # Match the Windows CI product build: a clean, embedded-UI payload plus the
+ # permanent launcher. Passing those freshly built artifacts to the maintained
+ # PowerShell driver prevents an earlier non-UI `win.sh build` from silently
+ # turning product guards into precondition skips.
+ vm clangarm64 "cd /c/cbm && scripts/build.sh --with-ui CC=clang CXX=clang++ SANITIZE= && powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/test-windows.ps1 -GuardsOnly -Binary build/c/codebase-memory-mcp.exe -Launcher build/c/codebase-memory-mcp-launcher.exe"
;;
smoke-install)
# Real managed install E2E with FULL stderr visible — the exact class the
- # CI smoke Phase 8 exercises but cannot show (probe hides launcher stderr).
- vm clangarm64 "cd /c/cbm && ./build/c/codebase-memory-mcp.exe install 2>&1 | tail -25"
+ # CI smoke Phase 8 exercises, isolated beneath a disposable profile root.
+ vm clangarm64 "cd /c/cbm && bash test-infrastructure/vm/vm-smoke.sh"
;;
sh)
vm clangarm64 "$*"
@@ -65,7 +126,7 @@ push-file)
[ $# -eq 2 ] || { echo "usage: win.sh push-file <local-path> <vm-path>" >&2; exit 2; }
# Windows OpenSSH resolves scp targets natively: use C:/... not /c/...
dest="${2/#\/c\//C:\/}"
- scp -i "$KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$1" "${USER_}@${HOST}:${dest}"
+ "${SCP[@]}" "$1" "${USER_}@${HOST}:${dest}"
;;
ubsan-build)
# x86_64 (CI's exact arch) with UBSan, runs under Windows-on-ARM emulation.
diff --git a/test-infrastructure/vm/windows-bootstrap.ps1 b/test-infrastructure/vm/windows-bootstrap.ps1
index 61a00b057..336720c63 100644
--- a/test-infrastructure/vm/windows-bootstrap.ps1
+++ b/test-infrastructure/vm/windows-bootstrap.ps1
@@ -6,16 +6,37 @@
# Getting this file into a fresh VM (clipboard/shared folders are unreliable
# on Windows-ARM guests — the SPICE agent services do not exist there): build
# a small ISO on the host and mount it via UTM's CD drive:
-# mkdir /tmp/cbmiso && cp windows-bootstrap.ps1 /tmp/cbmiso/
-# printf '@echo off\r\npowershell -NoProfile -ExecutionPolicy Bypass -File "%%~dp0windows-bootstrap.ps1"\r\n' > /tmp/cbmiso/RUN-ME.bat
+# mkdir /tmp/cbmiso
+# cp windows-bootstrap.ps1 /tmp/cbmiso/
+# cp ~/.claude/cbm-vm/id_ed25519.pub /tmp/cbmiso/host-key.pub
+# printf '@echo off\r\npowershell -NoProfile -ExecutionPolicy Bypass -File "%%~dp0windows-bootstrap.ps1" -SshPublicKeyPath "%%~dp0host-key.pub"\r\n' > /tmp/cbmiso/RUN-ME.bat
# hdiutil makehybrid -iso -joliet -default-volume-name CBMSETUP -o ~/cbm-setup.iso /tmp/cbmiso
# Then in the VM: open the CD drive in Explorer and double-click RUN-ME.bat.
#
# Requires: SPICE guest tools already installed (network driver working).
+[CmdletBinding()]
+param(
+ [Parameter(Mandatory = $true)]
+ [ValidateNotNullOrEmpty()]
+ [string]$SshPublicKeyPath
+)
+
+$resolvedPublicKeyPath = (Resolve-Path -LiteralPath $SshPublicKeyPath -ErrorAction Stop).Path
+$publicKeyLines = @(
+ Get-Content -LiteralPath $resolvedPublicKeyPath -Encoding Ascii |
+ Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
+)
+if ($publicKeyLines.Count -ne 1 -or
+ $publicKeyLines[0] -notmatch '^ssh-ed25519 [A-Za-z0-9+/]+={0,3}(?: [^\r\n]+)?$') {
+ throw "SshPublicKeyPath must contain exactly one OpenSSH Ed25519 public key"
+}
+$drivingHostPublicKey = $publicKeyLines[0]
+
# Self-elevate so double-clicking RUN-ME.bat just works.
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
- Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
+ $elevationArguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -SshPublicKeyPath `"$resolvedPublicKeyPath`""
+ Start-Process powershell -Verb RunAs -ArgumentList $elevationArguments
exit
}
$ErrorActionPreference = "Stop"
@@ -29,13 +50,8 @@ New-NetFirewallRule -Name cbm-sshd -DisplayName "OpenSSH (cbm test VM)" `
-ErrorAction SilentlyContinue | Out-Null
Write-Host "=== 2/4: authorize the driving host's key ===" -ForegroundColor Cyan
-# Public key of the driving host (~/.claude/cbm-vm/id_ed25519.pub there).
-# If the host key pair is ever lost, regenerate and replace this line:
-# ssh-keygen -t ed25519 -N "" -C claude-cbm-vm -f ~/.claude/cbm-vm/id_ed25519
-$k = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTM/DHf7YldxSfSH5/WengKm/k1mYkPry9mBjZ8SRzG claude-cbm-vm'
$f = 'C:\ProgramData\ssh\administrators_authorized_keys'
-if (-not (Test-Path $f)) { New-Item -ItemType File -Path $f -Force | Out-Null }
-if (-not (Select-String -Path $f -Pattern 'claude-cbm-vm' -Quiet)) { Add-Content -Path $f -Value $k }
+Set-Content -LiteralPath $f -Value $drivingHostPublicKey -Encoding Ascii
icacls $f /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F' | Out-Null
Write-Host "=== 3/4: mirror the GitHub-runner default-owner policy ===" -ForegroundColor Cyan
@@ -55,10 +71,14 @@ Write-Host ""
Write-Host "==================== SSH READY ====================" -ForegroundColor Green
Write-Host (" user: " + $env:USERNAME) -ForegroundColor Yellow
Write-Host (" ip: " + $ip) -ForegroundColor Yellow
+$hostKeyFingerprint = (& "$env:WINDIR\System32\OpenSSH\ssh-keygen.exe" -lf `
+ 'C:\ProgramData\ssh\ssh_host_ed25519_key.pub' -E sha256) -join ' '
+Write-Host (" host key: " + $hostKeyFingerprint) -ForegroundColor Yellow
Write-Host "===================================================" -ForegroundColor Green
Write-Host "On the host, write ~/.claude/cbm-vm/config with:"
Write-Host " CBM_VM_HOST=$ip"
Write-Host (" CBM_VM_USER=" + $env:USERNAME)
+Write-Host " CBM_VM_HOST_KEY_SHA256=<copy the SHA256:... value above>"
Write-Host "Then run: test-infrastructure/vm/provision-windows.sh"
Write-Host "NOTE: reboot once so the default-owner policy applies."
Read-Host 'Press Enter to close'
diff --git a/tests/test_vm_worktree_manifest.sh b/tests/test_vm_worktree_manifest.sh
new file mode 100644
index 000000000..9d9d3e503
--- /dev/null
+++ b/tests/test_vm_worktree_manifest.sh
@@ -0,0 +1,130 @@
+#!/usr/bin/env bash
+# The Windows VM sync manifest must represent Git-visible files exactly once,
+# without walking through tracked symlinks.
+# Source-contract patterns intentionally retain shell variables literally.
+# shellcheck disable=SC2016
+
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+FIXTURE="$(mktemp -d "${TMPDIR:-/tmp}/cbm-vm-manifest-test.XXXXXX")"
+manifest="$(mktemp "${TMPDIR:-/tmp}/cbm-vm-manifest-output.XXXXXX")"
+trap 'rm -rf -- "$FIXTURE"; rm -f -- "$manifest"' EXIT
+
+git -C "$FIXTURE" init -q
+mkdir -p "$FIXTURE/target"
+printf 'tracked\n' >"$FIXTURE/target/tracked.txt"
+printf 'deleted\n' >"$FIXTURE/deleted.txt"
+ln -s target "$FIXTURE/Link"
+git -C "$FIXTURE" add Link target/tracked.txt deleted.txt
+rm "$FIXTURE/deleted.txt"
+printf 'untracked\n' >"$FIXTURE/new.txt"
+
+# shellcheck source=test-infrastructure/vm/ssh-common.sh
+source "$ROOT/test-infrastructure/vm/ssh-common.sh"
+cbm_vm_write_untracked_manifest "$FIXTURE" "$manifest"
+
+saw_untracked=false
+while IFS= read -r -d '' relative; do
+ case "$relative" in
+ Link)
+ echo "FAIL: manifest duplicated a tracked symlink" >&2
+ exit 1
+ ;;
+ Link/*)
+ echo "FAIL: manifest traversed tracked symlink: $relative" >&2
+ exit 1
+ ;;
+ target/tracked.txt)
+ echo "FAIL: manifest duplicated a tracked file" >&2
+ exit 1
+ ;;
+ new.txt) saw_untracked=true ;;
+ deleted.txt)
+ echo "FAIL: manifest retained deleted tracked file" >&2
+ exit 1
+ ;;
+ esac
+done <"$manifest"
+
+$saw_untracked || { echo "FAIL: ordinary untracked file missing" >&2; exit 1; }
+
+driver="$ROOT/test-infrastructure/vm/win.sh"
+provisioner="$ROOT/test-infrastructure/vm/provision-windows.sh"
+sync_block="$(sed -n '/^sync)/,/^ ;;/p' "$driver")"
+if ! grep -Fq 'exec "$0" build' <<<"$sync_block"; then
+ echo "FAIL: Windows VM sync must rebuild before returning" >&2
+ exit 1
+fi
+if ! grep -Fq -- '-c \"set -e -o pipefail; $*\"' "$driver"; then
+ echo "FAIL: Windows VM remote shell must propagate pipeline failures" >&2
+ exit 1
+fi
+if ! grep -Fq 'tests/test_vm_worktree_manifest.sh' "$ROOT/scripts/test.sh"; then
+ echo "FAIL: Windows VM sync contract is not wired into the test suite" >&2
+ exit 1
+fi
+for entrypoint in "$driver" "$provisioner"; do
+ if ! grep -Fq 'git -C "$ROOT" branch --show-current' "$entrypoint"; then
+ echo "FAIL: Windows VM driver must default to the current local branch: $entrypoint" >&2
+ exit 1
+ fi
+ if ! grep -Fq 'cbm_vm_require_safe_branch "$BRANCH"' "$entrypoint"; then
+ echo "FAIL: Windows VM driver must validate branch text before remote use: $entrypoint" >&2
+ exit 1
+ fi
+ if ! grep -Fq -- '-c \"set -e -o pipefail; $*\"' "$entrypoint"; then
+ echo "FAIL: Windows VM driver must propagate remote pipeline failures: $entrypoint" >&2
+ exit 1
+ fi
+done
+if ! grep -Fq "JOBS='\$(nproc)'" "$provisioner" ||
+ ! grep -Fq 'make -j${JOBS}' "$provisioner"; then
+ echo "FAIL: Windows VM provisioner must expand the remote core count exactly once" >&2
+ exit 1
+fi
+guards_block="$(sed -n '/^guards)/,/^ ;;/p' "$driver")"
+if ! grep -Fq 'scripts/build.sh --with-ui CC=clang CXX=clang++ SANITIZE= && powershell.exe' \
+ <<<"$guards_block" ||
+ ! grep -Fq 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/test-windows.ps1' \
+ <<<"$guards_block" ||
+ ! grep -Fq -- '-GuardsOnly -Binary build/c/codebase-memory-mcp.exe' <<<"$guards_block" ||
+ ! grep -Fq -- '-Launcher build/c/codebase-memory-mcp-launcher.exe' <<<"$guards_block"; then
+ echo "FAIL: Windows VM guards must delegate to the maintained native-Windows driver" >&2
+ exit 1
+fi
+if grep -Fq 'for g in tests/windows/test_*.py' <<<"$guards_block"; then
+ echo "FAIL: Windows VM guards must not duplicate the native-Windows driver loop" >&2
+ exit 1
+fi
+if [ "$(grep -c 'git clean -fdx' "$driver")" -lt 2 ]; then
+ echo "FAIL: Windows VM update and sync must clean the remote worktree" >&2
+ exit 1
+fi
+if ! grep -Fq 'git clean -fdx' "$provisioner"; then
+ echo "FAIL: Windows VM reprovision update must clean the remote worktree" >&2
+ exit 1
+fi
+if grep -Fq -- '-e build' "$driver" "$provisioner"; then
+ echo "FAIL: Windows VM synchronization must invalidate stale build outputs" >&2
+ exit 1
+fi
+if ! grep -Fq 'CBM_VM_BRANCH' "$ROOT/test-infrastructure/vm/README.md"; then
+ echo "FAIL: Windows VM branch override is undocumented" >&2
+ exit 1
+fi
+if ! grep -Fq 'pushed base commit' "$ROOT/test-infrastructure/vm/README.md"; then
+ echo "FAIL: Windows VM sync pushed-base prerequisite is undocumented" >&2
+ exit 1
+fi
+container_driver="$ROOT/test-infrastructure/run.sh"
+if grep -Fq 'All platforms passed' "$container_driver"; then
+ echo "FAIL: container/Wine driver must not claim the real-Windows gate passed" >&2
+ exit 1
+fi
+if ! grep -Fq 'Real-Windows gate remains' "$container_driver"; then
+ echo "FAIL: container/Wine driver must print the remaining real-Windows gate" >&2
+ exit 1
+fi
+
+echo "Windows VM worktree manifest contract passed"