mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-12-05 04:47:43 +08:00
Windows shipped a PAIR: a small permanent launcher (codebase-memory-mcp.exe)
plus the real product binary (codebase-memory-mcp.payload.exe). The launcher
existed for exactly one reason — a running .exe cannot replace its own image
on Windows, so an in-process self-update needs a second resident binary to do
the swap.
That stub is statically indistinguishable from a dropper: a small, unsigned,
zero-prevalence PE whose whole job is verify-and-execute another binary.
Defender's ML scored it Trojan:Win32/Wacatac.B!ml and blocked the v0.9.1-rc.1
release at the VirusTotal gate. It is not fixable in our code on x64 —
bcrypt-free, stripped, VERSIONINFO'd, minimal-resource and even
resource-FREE builds on CI's own MSYS2 CLANG64 toolchain were all flagged,
while the product binary scans clean on every platform.
So remove the stub and move self-update OUT of the process into install.ps1,
which runs while cbm is NOT running: Windows' image lock only blocks a
process from replacing ITSELF. now prints the exact PowerShell
command (with the Unblock-File hint for Mark-of-the-Web); install.ps1 is
idempotent, so re-running it IS the update — it stops the daemon, renames the
running binary aside (the one mutation Windows permits on a running image),
publishes the new one, and sweeps retired copies.
Windows now matches Linux and macOS: ONE binary per platform.
* packaging, install.ps1, npm and PyPI wrappers all carry a single binary
* the launcher/payload ABI contract and ~2500 lines of stub state machinery
are deleted
* every daemon start, CLI call and hook fire loses a process spawn, a named
pipe handshake and an stdio relay
* test_windows_bundle_contract.sh is rewritten as an INVERTED contract: it
now asserts no shipped surface can reintroduce a launcher/payload pair,
and that install.ps1 retires the running binary before publishing
Verified: VirusTotal 0/67 on the packaged binary and 0/58 on install.ps1 (no
certificate involved); macOS and Linux full suites green; Windows guards all
green including the new update-handoff contract; npm 10/10; PyPI 3/3.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
166 lines
6.7 KiB
Bash
166 lines
6.7 KiB
Bash
#!/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 'cbm_vm_sync_windows_clock()' \
|
|
"$ROOT/test-infrastructure/vm/ssh-common.sh"; then
|
|
echo "FAIL: Windows VM drivers need a shared, verified host-to-guest clock sync" >&2
|
|
exit 1
|
|
fi
|
|
clock_helper=$(sed -n '/^cbm_vm_sync_windows_clock() {$/,/^}$/p' \
|
|
"$ROOT/test-infrastructure/vm/ssh-common.sh")
|
|
clock_retry_line=$(printf '%s\n' "$clock_helper" | grep -nF 'for attempt in 1 2 3; do' |
|
|
cut -d: -f1)
|
|
clock_capture_line=$(printf '%s\n' "$clock_helper" |
|
|
grep -nF "host_utc=\"\$(date -u '+%Y-%m-%dT%H:%M:%SZ')\"" | cut -d: -f1)
|
|
if [ -z "$clock_retry_line" ] || [ -z "$clock_capture_line" ] ||
|
|
[ "$clock_capture_line" -le "$clock_retry_line" ]; then
|
|
echo "FAIL: Windows VM clock sync must retry a bounded three times with a fresh host timestamp" >&2
|
|
exit 1
|
|
fi
|
|
for entrypoint in "$driver" "$provisioner"; do
|
|
if ! grep -Fq 'cbm_vm_sync_windows_clock "${SSH[@]}"' "$entrypoint"; then
|
|
echo "FAIL: Windows VM entry point must repair suspended-guest clock drift: $entrypoint" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if ! grep -Fq 'cbm_vm_run_powershell()' \
|
|
"$ROOT/test-infrastructure/vm/ssh-common.sh" ||
|
|
[ "$(grep -c 'vm_powershell ' "$provisioner")" -lt 3 ]; then
|
|
echo "FAIL: Windows provisioning must transport PowerShell as UTF-16LE encoded commands" >&2
|
|
exit 1
|
|
fi
|
|
if grep -Fq 'powershell -NoProfile -Command' "$provisioner"; then
|
|
echo "FAIL: Windows provisioning must not expose PowerShell metacharacters to remote shell parsing" >&2
|
|
exit 1
|
|
fi
|
|
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")"
|
|
# The guards leg builds the CI-shaped product binary (embedded UI) into an
|
|
# isolated BUILD_DIR, then hands that artifact to the maintained
|
|
# PowerShell driver through a plain cmd shell (CI's environment shape, not
|
|
# the MSYS2 login shell whose TMP ancestry the daemon correctly refuses).
|
|
if ! grep -Fq 'scripts/build.sh --with-ui CC=clang CXX=clang++ SANITIZE= BUILD_DIR=build/guards' \
|
|
<<<"$guards_block" ||
|
|
! grep -Fq 'powershell -NoProfile -ExecutionPolicy Bypass -File scripts\\test-windows.ps1' \
|
|
<<<"$guards_block" ||
|
|
! grep -Fq -- '-GuardsOnly -Binary build\\guards\\codebase-memory-mcp.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"
|