Skip to content

Commit 3c8730e

Browse files
committed
fix(installer): accept legacy release archive layout
Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com>
1 parent 10cb0e0 commit 3c8730e

2 files changed

Lines changed: 175 additions & 16 deletions

File tree

‎install.sh‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,12 @@ if [ "$EXPECTED" != "$ACTUAL" ]; then
231231
fi
232232
echo "Checksum verified."
233233

234-
# Validate the complete archive namespace before extraction. Standard releases
235-
# are the canonical five files; UI releases add exactly one root-level,
236-
# content-addressed pack. Anything else is a release-integrity failure, not a
234+
# Validate the complete archive namespace before extraction. Current standard
235+
# releases are the canonical five files; UI releases add exactly one root-level,
236+
# content-addressed pack. The v0.9.x release assets predate those runtime
237+
# sidecars and contain only the four core members, so keep that exact legacy
238+
# shape installable until the next canonical release is published. Anything
239+
# outside one of those closed member sets is a release-integrity failure, not a
237240
# sidecar to ignore.
238241
if [ "$OS" = "windows" ]; then
239242
ARCHIVE_BINARY="codebase-memory-mcp.exe"
@@ -284,14 +287,25 @@ while IFS= read -r member || [ -n "$member" ]; do
284287
esac
285288
done < "$ARCHIVE_MEMBERS_FILE"
286289

287-
EXPECTED_MEMBER_COUNT=5
288-
if [ "$VARIANT" = "ui" ]; then
289-
EXPECTED_MEMBER_COUNT=6
290+
CORE_MEMBER_SET=false
291+
CANONICAL_MEMBER_SET=false
292+
if [ "$BINARY_MEMBERS" -eq 1 ] && [ "$LICENSE_MEMBERS" -eq 1 ] &&
293+
[ "$INSTALLER_MEMBERS" -eq 1 ] && [ "$NOTICE_MEMBERS" -eq 1 ]; then
294+
if [ "$INTEGRATION_MEMBERS" -eq 0 ] && [ "$UI_PACK_MEMBERS" -eq 0 ] &&
295+
[ "$ARCHIVE_MEMBER_COUNT" -eq 4 ]; then
296+
CORE_MEMBER_SET=true
297+
fi
298+
if [ "$VARIANT" = "ui" ]; then
299+
if [ "$INTEGRATION_MEMBERS" -eq 1 ] && [ "$UI_PACK_MEMBERS" -eq 1 ] &&
300+
[ "$ARCHIVE_MEMBER_COUNT" -eq 6 ]; then
301+
CANONICAL_MEMBER_SET=true
302+
fi
303+
elif [ "$INTEGRATION_MEMBERS" -eq 1 ] && [ "$UI_PACK_MEMBERS" -eq 0 ] &&
304+
[ "$ARCHIVE_MEMBER_COUNT" -eq 5 ]; then
305+
CANONICAL_MEMBER_SET=true
306+
fi
290307
fi
291-
if [ "$BINARY_MEMBERS" -ne 1 ] || [ "$INTEGRATION_MEMBERS" -ne 1 ] ||
292-
[ "$LICENSE_MEMBERS" -ne 1 ] || [ "$INSTALLER_MEMBERS" -ne 1 ] ||
293-
[ "$NOTICE_MEMBERS" -ne 1 ] || [ "$UI_PACK_MEMBERS" -ne $((EXPECTED_MEMBER_COUNT - 5)) ] ||
294-
[ "$ARCHIVE_MEMBER_COUNT" -ne "$EXPECTED_MEMBER_COUNT" ]; then
308+
if [ "$CORE_MEMBER_SET" != true ] && [ "$CANONICAL_MEMBER_SET" != true ]; then
295309
echo "error: release archive does not match the exact $VARIANT member set" >&2
296310
exit 1
297311
fi
@@ -304,13 +318,18 @@ else
304318
tar -xzf "$DLDIR/$ARCHIVE" -C "$DLDIR"
305319
fi
306320

307-
for extracted_member in "$ARCHIVE_BINARY" cbm-integrations.json LICENSE \
308-
"$ARCHIVE_INSTALLER" THIRD_PARTY_NOTICES.md; do
321+
for extracted_member in "$ARCHIVE_BINARY" LICENSE "$ARCHIVE_INSTALLER" \
322+
THIRD_PARTY_NOTICES.md; do
309323
if [ ! -f "$DLDIR/$extracted_member" ] || [ -L "$DLDIR/$extracted_member" ]; then
310324
echo "error: release member is not a regular file: $extracted_member" >&2
311325
exit 1
312326
fi
313327
done
328+
if [ "$INTEGRATION_MEMBERS" -eq 1 ] &&
329+
{ [ ! -f "$DLDIR/cbm-integrations.json" ] || [ -L "$DLDIR/cbm-integrations.json" ]; }; then
330+
echo "error: release member is not a regular file: cbm-integrations.json" >&2
331+
exit 1
332+
fi
314333

315334
DLBIN="$DLDIR/$ARCHIVE_BINARY"
316335
if [ ! -f "$DLBIN" ] || [ -L "$DLBIN" ]; then
@@ -319,7 +338,7 @@ if [ ! -f "$DLBIN" ] || [ -L "$DLBIN" ]; then
319338
fi
320339

321340
DL_UI_PACK=""
322-
if [ "$VARIANT" = "ui" ]; then
341+
if [ "$VARIANT" = "ui" ] && [ -n "$UI_PACK_NAME" ]; then
323342
DL_UI_PACK="$DLDIR/$UI_PACK_NAME"
324343
if [ ! -f "$DL_UI_PACK" ] || [ -L "$DL_UI_PACK" ]; then
325344
echo "error: UI asset pack not found after extraction" >&2

‎tests/test_smoke_fixture_contract.sh‎

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ require(
380380
needle in unix_installer
381381
for needle in (
382382
"ARCHIVE_MEMBER_COUNT",
383-
"EXPECTED_MEMBER_COUNT=5",
384-
"EXPECTED_MEMBER_COUNT=6",
383+
"CORE_MEMBER_SET",
384+
"CANONICAL_MEMBER_SET",
385385
"^cbm-ui-[0-9a-f]{64}\\.pack$",
386386
"release archive contains unexpected member",
387387
)
388388
),
389-
"install.sh must validate the exact five-member standard or six-member UI archive",
389+
"install.sh must validate exact legacy four-member or canonical runtime-asset archives",
390390
)
391391
unix_binary_publish = unix_installer.find('"$DLBIN" install "${INSTALL_ARGS[@]}"')
392392
require(
@@ -830,6 +830,146 @@ if os.name != "nt" and helper.is_file():
830830
fixture_server.kill()
831831
fixture_server.wait(timeout=3)
832832
833+
def exercise_installer_member_set(variant: str, legacy_four_member: bool) -> None:
834+
with tempfile.TemporaryDirectory(prefix=f"cbm-installer-members-{variant}-") as install_temp:
835+
install_root = pathlib.Path(install_temp)
836+
fixture = install_root / "fixture"
837+
stage = install_root / "stage"
838+
fake_bin = install_root / "fake-bin"
839+
install_dir = install_root / "installed"
840+
fake_home = install_root / "home"
841+
for directory in (fixture, stage, fake_bin, install_dir, fake_home):
842+
directory.mkdir()
843+
844+
candidate = stage / "codebase-memory-mcp"
845+
candidate.write_text(
846+
"#!/usr/bin/env bash\n"
847+
"set -euo pipefail\n"
848+
"case \"${1:-}\" in\n"
849+
" --version) echo 'codebase-memory-mcp member-set fixture';;\n"
850+
" install)\n"
851+
" install_dir=''\n"
852+
" for arg in \"$@\"; do\n"
853+
" case \"$arg\" in --dir=*) install_dir=${arg#--dir=};; esac\n"
854+
" done\n"
855+
" test -n \"$install_dir\"\n"
856+
" cp \"$0\" \"$install_dir/codebase-memory-mcp\"\n"
857+
" chmod 755 \"$install_dir/codebase-memory-mcp\";;\n"
858+
" *) exit 2;;\n"
859+
"esac\n",
860+
encoding="utf-8",
861+
)
862+
candidate.chmod(0o755)
863+
(stage / "LICENSE").write_bytes(b"fixture license\n")
864+
(stage / "THIRD_PARTY_NOTICES.md").write_bytes(b"fixture notices\n")
865+
(stage / "install.sh").write_bytes(b"#!/bin/sh\n# fixture installer\n")
866+
(stage / "cbm-integrations.json").write_bytes(b"{}\n")
867+
pack = b"fixture ui asset pack\n"
868+
pack_name = f"cbm-ui-{hashlib.sha256(pack).hexdigest()}.pack"
869+
(stage / pack_name).write_bytes(pack)
870+
871+
prefix = "codebase-memory-mcp-ui" if variant == "ui" else "codebase-memory-mcp"
872+
archive_name = f"{prefix}-linux-amd64-portable.tar.gz"
873+
archive_path = fixture / archive_name
874+
members = [
875+
"codebase-memory-mcp",
876+
"LICENSE",
877+
"install.sh",
878+
"THIRD_PARTY_NOTICES.md",
879+
]
880+
if not legacy_four_member:
881+
members.append("cbm-integrations.json")
882+
if variant == "ui":
883+
members.append(pack_name)
884+
with tarfile.open(archive_path, "w:gz") as archive:
885+
for name in members:
886+
archive.add(stage / name, arcname=name)
887+
archive_digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
888+
(fixture / "checksums.txt").write_text(
889+
f"{archive_digest} {archive_name}\n", encoding="ascii"
890+
)
891+
892+
fake_uname = fake_bin / "uname"
893+
fake_uname.write_text(
894+
"#!/bin/sh\n"
895+
"case \"${1:-}\" in\n"
896+
" -s) echo Linux;;\n"
897+
" -m) echo x86_64;;\n"
898+
" *) echo Linux;;\n"
899+
"esac\n",
900+
encoding="utf-8",
901+
)
902+
fake_uname.chmod(0o755)
903+
904+
port_file = install_root / "port"
905+
server_log = install_root / "server.log"
906+
with server_log.open("wb") as log_handle:
907+
fixture_server = subprocess.Popen(
908+
[
909+
sys.executable,
910+
str(helper),
911+
"--directory",
912+
str(fixture),
913+
"--port-file",
914+
str(port_file),
915+
],
916+
stdout=log_handle,
917+
stderr=subprocess.STDOUT,
918+
)
919+
try:
920+
port = 0
921+
deadline = time.monotonic() + 30
922+
while time.monotonic() < deadline:
923+
if port_file.is_file():
924+
port_text = port_file.read_text(encoding="ascii").strip()
925+
if port_text:
926+
port = int(port_text)
927+
break
928+
if fixture_server.poll() is not None:
929+
break
930+
time.sleep(0.02)
931+
require(port > 0, "installer member-set fixture server did not publish a port")
932+
if port > 0:
933+
environment = os.environ.copy()
934+
environment["HOME"] = str(fake_home)
935+
environment["PATH"] = (
936+
str(fake_bin) + os.pathsep + environment.get("PATH", "")
937+
)
938+
environment["CBM_DOWNLOAD_URL"] = f"http://127.0.0.1:{port}"
939+
command = [
940+
str(bash_executable),
941+
str(root / "install.sh"),
942+
f"--{variant}",
943+
f"--dir={install_dir}",
944+
"--skip-config",
945+
]
946+
installed = subprocess.run(
947+
command,
948+
env=environment,
949+
text=True,
950+
stdout=subprocess.PIPE,
951+
stderr=subprocess.STDOUT,
952+
timeout=60,
953+
check=False,
954+
)
955+
shape = "legacy four-member" if legacy_four_member else "canonical"
956+
require(
957+
installed.returncode == 0,
958+
f"install.sh rejected {shape} {variant} release fixture: "
959+
+ installed.stdout.strip(),
960+
)
961+
finally:
962+
fixture_server.terminate()
963+
try:
964+
fixture_server.wait(timeout=3)
965+
except subprocess.TimeoutExpired:
966+
fixture_server.kill()
967+
fixture_server.wait(timeout=3)
968+
969+
exercise_installer_member_set("standard", legacy_four_member=True)
970+
exercise_installer_member_set("ui", legacy_four_member=True)
971+
exercise_installer_member_set("ui", legacy_four_member=False)
972+
833973
# The complete canonical-matrix extraction, pack parsing, association retention,
834974
# byte-exact deduplication and fail-closed malformed-pack cases run above via
835975
# test_release_archive_extractor_contract.sh. Keep the packaging-side digest

0 commit comments

Comments
 (0)