初始提交:codebase-memory-mcp - Codebase Memory MCP Server
Fork from https://github.com/DeusData/codebase-memory-mcp Go 实现,提供代码库记忆功能的 MCP 服务器
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# scripts/ci/ — venue plumbing (single implementations)
|
||||
|
||||
Support scripts that keep the venues in the SAME shape. Each exists because
|
||||
the logic used to live inline in workflow YAML or was hand-duplicated between
|
||||
CI and the local infrastructure — both of which the venue-parity contract
|
||||
(`tests/test_venue_parity_contract.sh`) now forbids. Everything here answers
|
||||
`--help` (PowerShell: comment-based help, `Get-Help <script>`).
|
||||
|
||||
| script | job | called by |
|
||||
|---|---|---|
|
||||
| `new-protected-temp-root.ps1` | Create the owner-stamped, inheritance-protected per-user TEMP root the daemon/install suites require (shared `/tmp` and default runner TEMP grant Authenticated-Users mutation rights, which the trust policy correctly refuses — running there produces security refusals, not signal). `-ProtectDir` stamps build dirs the same way. | `_test.yml`, `_soak.yml`, `vm-run-tests.sh` |
|
||||
| `clean-test-residue.ps1` | Sweep `cbm-*` residue from the Windows VM and assert runner-like free disk (default 14 GB — the GitHub runner's SSD). Long-path `\\?\` fallback for the guard suites' adversarial trees; every removal VERIFIED (an earlier version counted attempts and reported 86 swept while 11 GB remained). BLOCKS below the floor: a disk that fills mid-run reads as a product bug. | `win.sh` before every build/run |
|
||||
| `preflight-docker.sh` | Same idea for Colima/docker: prune runner-unlike residue, assert free space on the filesystem backing the docker data root (not the VM's `/`). Build cache + named volumes KEPT (the local analogue of actions/cache); `--deep` drops them. | `test-infrastructure/run.sh` |
|
||||
| `check-glibc-compat.sh` | Run a linux binary in debian:bullseye (glibc 2.31) — the portable binary must start on old glibc. | `_smoke.yml` portable legs |
|
||||
| `generate-sbom.py` | The release SPDX SBOM (vendored versions reviewable here, diffable by vendoring PRs — was inline YAML). | `release.yml` |
|
||||
| `require-all-green.sh` | The aggregate gate: fail unless every needed job succeeded or legitimately skipped (was inline YAML). | `pr.yml ci-ok` |
|
||||
| `verify-shard-union.sh` | Prove sharded test legs lost nothing: shard count agreement, indices 1..n, identical suite lists, union of slices == full list (was inline YAML). | `_test.yml` shard-completeness |
|
||||
| `check-virustotal.sh` | Release-asset VirusTotal lookups. | `release.yml` |
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# Append the Security Verification section to the release notes: per-binary
|
||||
# sha256 + VirusTotal links. This step only runs after check-virustotal.sh
|
||||
# passed, and that gate is ZERO tolerance — any detection blocks the release —
|
||||
# so "0 detections" here is a verified statement, never an assumption.
|
||||
# Expects: GH_TOKEN, VERSION; run from the verify job workspace (binaries/).
|
||||
set -euo pipefail
|
||||
|
||||
TABLE="\n\n## Security Verification\n\n"
|
||||
TABLE+="All release binaries scanned with 70+ antivirus engines — **0 detections**.\n\n"
|
||||
TABLE+="| Binary | SHA-256 | VirusTotal |\n"
|
||||
TABLE+="|--------|---------|------------|\n"
|
||||
|
||||
for bin in binaries/codebase-memory-mcp-*; do
|
||||
[ -f "$bin" ] || continue
|
||||
name=$(basename "$bin")
|
||||
sha256=$(sha256sum "$bin" 2>/dev/null | awk '{print $1}' \
|
||||
|| shasum -a 256 "$bin" | awk '{print $1}')
|
||||
label=$(echo "$name" | sed 's/^codebase-memory-mcp-//' | sed 's/\.exe$//')
|
||||
short="${sha256:0:20}..."
|
||||
vt_url="https://www.virustotal.com/gui/file/${sha256}/detection"
|
||||
TABLE+="| \`${label}\` | \`${short}\` | [0 detections ✅](${vt_url}) |\n"
|
||||
done
|
||||
|
||||
CURRENT=$(gh release view "$VERSION" \
|
||||
--json body --jq '.body // ""' --repo "$GITHUB_REPOSITORY")
|
||||
printf '%s%b' "$CURRENT" "$TABLE" > /tmp/release_notes.md
|
||||
gh release edit "$VERSION" \
|
||||
--notes-file /tmp/release_notes.md --repo "$GITHUB_REPOSITORY"
|
||||
@@ -0,0 +1,404 @@
|
||||
#!/usr/bin/env bash
|
||||
# check-binary-composition.sh — release gate: assert what must NOT be inside a
|
||||
# shipped artifact.
|
||||
#
|
||||
# Microsoft Defender's ML classifier flagged the v0.9.1-rc.1 binaries. The
|
||||
# hardening pass that followed *removed capability* — an executable stack, an
|
||||
# in-process updater, test-only environment seams, the embedded HTTP/UI server
|
||||
# and its process enumerator in the standard build. Each of those regresses
|
||||
# invisibly: one restored #include, one Makefile source list edit, one revived
|
||||
# call site, and nothing else in CI notices — the binary just quietly gets its
|
||||
# malware-shaped surface back and the next release gets flagged again.
|
||||
#
|
||||
# This script is the proof that each removal stayed removed. It asserts only
|
||||
# NEGATIVE properties (needle absent), plus one canary string we know ships,
|
||||
# because an absence check aimed at the wrong file — a compressed artifact, a
|
||||
# stub, a truncated download — would otherwise pass vacuously and read green.
|
||||
# A missing tool is a hard error for the same reason: a skipped assertion must
|
||||
# never look like a satisfied one.
|
||||
#
|
||||
# Usage: scripts/ci/check-binary-composition.sh [--variant=auto|standard|ui] <binary-or-dir>...
|
||||
# Directories are scanned recursively; format (ELF / Mach-O / PE) is detected
|
||||
# per file from its magic bytes and each assertion runs where it is
|
||||
# meaningful. Exit 0 = every assertion passed, 1 = at least one failed,
|
||||
# 2 = usage error, missing tool, or nothing checkable was found (a vacuous
|
||||
# run is a failure, not a pass).
|
||||
set -euo pipefail
|
||||
|
||||
case "${1:-}" in
|
||||
-h | --help)
|
||||
sed -n '2,25p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# ── Needles ─────────────────────────────────────────────────────────
|
||||
# Every needle below was grep-verified against the tree it comes from: it
|
||||
# exists ONLY in the code the assertion is about, so a hit means that code is
|
||||
# linked in, not that some unrelated string happens to look similar.
|
||||
|
||||
# S6: worker/Windows test seams read these env vars. A release binary that
|
||||
# still honours them lets any process on the box steer the indexer's child
|
||||
# processes and file placement — and CBM_TEST_* in a shipped binary is exactly
|
||||
# the "debug/injection hooks" shape AV heuristics score on.
|
||||
SEAM_NEEDLES=(
|
||||
'CBM_TEST_WORKER_DESCENDANT_PID_FILE'
|
||||
'CBM_TEST_WINDOWS_USER_PATH_RUN_ID'
|
||||
)
|
||||
|
||||
# The in-process updater (download-and-replace-own-binary) is the single most
|
||||
# malware-shaped behaviour we ever shipped; updates now run from install.sh
|
||||
# out-of-process. These four needles cover both halves of what was removed:
|
||||
# the download base URL, the checksum URL built on top of it, the GitHub API
|
||||
# release query of the daemon's background version check, and that request's
|
||||
# Accept header (which survives even if the URL is ever assembled at runtime).
|
||||
UPDATER_NEEDLES=(
|
||||
'releases/latest/download'
|
||||
'api.github.com/repos'
|
||||
'releases/latest'
|
||||
'Accept: application/vnd.github+json'
|
||||
)
|
||||
|
||||
# SQLite loadable extensions = arbitrary code execution through a database
|
||||
# file. The amalgamation is built with SQLITE_OMIT_LOAD_EXTENSION; if that ever
|
||||
# drops out, dlopen()/LoadLibrary() re-enters the store layer.
|
||||
# NOTE: release binaries are stripped, so the two API symbol names only appear
|
||||
# when the surface is *exported*. The dlopen error text is the needle that
|
||||
# still works on a stripped build — it is compiled in only when the feature is.
|
||||
SQLITE_LOADEXT_NEEDLES=(
|
||||
'sqlite3_load_extension'
|
||||
'sqlite3_enable_load_extension'
|
||||
'unable to open shared library ['
|
||||
)
|
||||
|
||||
# The standard artifact must not contain the UI's HTTP server at all: an
|
||||
# unauthenticated localhost listener plus a process enumerator is precisely the
|
||||
# behaviour pair a classifier reads as a backdoor. Needles are split across
|
||||
# both UI translation units and are independent of each other, so a refactor of
|
||||
# any single one cannot silently disarm the assertion:
|
||||
# 'HTTP/1.1 %d %s' httpd.c response-status writer
|
||||
# 'Request Header Fields Too Large' httpd.c status-text table
|
||||
# '/api/ui-config', '/api/processes' http_server.c route dispatch
|
||||
# 'ps -eo …' / '[c]odebase-memory-mcp' the popen() process enumerator's
|
||||
# shell pipeline, both halves
|
||||
# Verified unique to src/ui/ across src/, vendored/ and internal/ — the only
|
||||
# other occurrences in the repo are tests/test_httpd.c and scripts/, neither of
|
||||
# which is ever linked into a release binary.
|
||||
UI_HTTP_NEEDLES=(
|
||||
'HTTP/1.1 %d %s'
|
||||
'Request Header Fields Too Large'
|
||||
'/api/ui-config'
|
||||
'/api/processes'
|
||||
'ps -eo pid,pcpu,rss,etime,comm'
|
||||
'[c]odebase-memory-mcp'
|
||||
)
|
||||
|
||||
# Canary: proves the needle scan can actually see this file's strings. Without
|
||||
# it, handing the gate a gzip, a stub or a 0-byte file would pass every
|
||||
# absence assertion. 168+ occurrences in a real artifact, 0 in anything else.
|
||||
CANARY_NEEDLE='codebase-memory-mcp'
|
||||
|
||||
# ── Args ────────────────────────────────────────────────────────────
|
||||
VARIANT=auto
|
||||
TARGETS=()
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--variant=*) VARIANT="${arg#--variant=}" ;;
|
||||
-*)
|
||||
echo "FAIL: unknown flag $arg (see --help)" >&2
|
||||
exit 2
|
||||
;;
|
||||
*) TARGETS+=("$arg") ;;
|
||||
esac
|
||||
done
|
||||
case "$VARIANT" in
|
||||
auto | standard | ui) ;;
|
||||
*)
|
||||
echo "FAIL: --variant must be auto, standard or ui (got '$VARIANT')" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
if [ "${#TARGETS[@]}" -eq 0 ]; then
|
||||
echo "FAIL: no binaries or directories given (see --help)" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# ── ELF program-header reader ───────────────────────────────────────
|
||||
# Resolved lazily: a Windows/macOS-only run must not fail for want of readelf,
|
||||
# but an ELF in scope with no reader available must fail loudly (exit 2) rather
|
||||
# than skip the executable-stack assertion.
|
||||
ELF_READER=''
|
||||
ELF_READER_KIND=''
|
||||
resolve_elf_reader() {
|
||||
[ -n "$ELF_READER" ] && return 0
|
||||
for cand in readelf llvm-readelf /opt/homebrew/opt/llvm/bin/llvm-readelf \
|
||||
/usr/local/opt/llvm/bin/llvm-readelf; do
|
||||
if command -v "$cand" >/dev/null 2>&1; then
|
||||
ELF_READER="$cand"
|
||||
ELF_READER_KIND=readelf
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
for cand in objdump llvm-objdump /opt/homebrew/opt/llvm/bin/llvm-objdump; do
|
||||
if command -v "$cand" >/dev/null 2>&1; then
|
||||
ELF_READER="$cand"
|
||||
ELF_READER_KIND=objdump
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Echoes the GNU_STACK flag field ("RWE", "RW", "rwx", "rw-"), empty if the
|
||||
# header is absent or unparseable.
|
||||
gnu_stack_flags() {
|
||||
case "$ELF_READER_KIND" in
|
||||
readelf)
|
||||
"$ELF_READER" -lW "$1" 2>/dev/null |
|
||||
awk '/GNU_STACK/ { print $(NF - 1); exit }'
|
||||
;;
|
||||
objdump)
|
||||
# objdump -p prints " STACK off ..." and the flags on the next line.
|
||||
"$ELF_READER" -p "$1" 2>/dev/null |
|
||||
awk '/STACK off/ { getline
|
||||
for (i = 1; i <= NF; i++)
|
||||
if ($i == "flags") { print $(i + 1); exit } }'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ── Reporting ───────────────────────────────────────────────────────
|
||||
# PASS and FAIL both go to stdout so the per-assertion sequence stays in order
|
||||
# in a CI log (stderr would interleave nondeterministically); only the final
|
||||
# verdict is echoed to stderr, which is what a failed step's tail shows.
|
||||
pass_count=0
|
||||
fail_count=0
|
||||
FAILURES=()
|
||||
|
||||
report() { # verdict, assertion-id, file-token, message
|
||||
printf '%-4s %-22s %s: %s\n' "$1" "$2" "$3" "$4"
|
||||
if [ "$1" = FAIL ]; then
|
||||
fail_count=$((fail_count + 1))
|
||||
FAILURES+=("$2 $3: $4")
|
||||
else
|
||||
pass_count=$((pass_count + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
assert_absent() { # file, token, assertion-id, needle
|
||||
if LC_ALL=C grep -a -q -F -e "$4" "$1"; then
|
||||
report FAIL "$3" "$2" "'$4' is PRESENT (must not ship)"
|
||||
else
|
||||
report PASS "$3" "$2" "'$4' absent"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_present() { # file, token, assertion-id, needle, why-pass, why-fail
|
||||
if LC_ALL=C grep -a -q -F -e "$4" "$1"; then
|
||||
report PASS "$3" "$2" "'$4' present ($5)"
|
||||
else
|
||||
report FAIL "$3" "$2" "'$4' is MISSING — $6"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Per-file checks ─────────────────────────────────────────────────
|
||||
detect_format() { # file → elf | macho | pe | other
|
||||
magic=$(LC_ALL=C od -An -N4 -tx1 "$1" 2>/dev/null | tr -d ' \n')
|
||||
case "$magic" in
|
||||
7f454c46) echo elf ;;
|
||||
cffaedfe | cefaedfe | feedface | feedfacf | cafebabe | bebafeca) echo macho ;;
|
||||
4d5a*) echo pe ;;
|
||||
*) echo other ;;
|
||||
esac
|
||||
}
|
||||
|
||||
checked_files=0
|
||||
skipped_files=0
|
||||
|
||||
check_file() {
|
||||
file="$1"
|
||||
# Two path components: both variants ship a binary literally named
|
||||
# "codebase-memory-mcp", so the parent directory is what tells them apart.
|
||||
token=$(printf '%s' "$file" | awk -F/ '{ if (NF > 1) print $(NF - 1) "/" $NF; else print $NF }')
|
||||
fmt=$(detect_format "$file")
|
||||
if [ "$fmt" = other ]; then
|
||||
printf 'skip %-22s %s: not an ELF/Mach-O/PE binary\n' '-' "$token"
|
||||
skipped_files=$((skipped_files + 1))
|
||||
return 0
|
||||
fi
|
||||
|
||||
is_ui=0
|
||||
case "$VARIANT" in
|
||||
ui) is_ui=1 ;;
|
||||
standard) is_ui=0 ;;
|
||||
auto)
|
||||
# The UI archive is codebase-memory-mcp-ui-<os>-<arch>, but the binary
|
||||
# inside it is just "codebase-memory-mcp" — so the whole path decides,
|
||||
# not the basename. Printed below so a misclassified path is visible in
|
||||
# the log instead of silently disarming the UI assertion.
|
||||
case "$file" in
|
||||
*-ui | *-ui.* | *-ui-* | *-ui/*) is_ui=1 ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
variant_label=standard
|
||||
[ "$is_ui" -eq 1 ] && variant_label='UI (A5-no-ui-http not applicable)'
|
||||
printf '\n── %s [%s, %s] ──\n' "$token" "$fmt" "$variant_label"
|
||||
checked_files=$((checked_files + 1))
|
||||
|
||||
# A0 — anti-vacuity canary; every assertion below is an absence check.
|
||||
assert_present "$file" "$token" A0-canary "$CANARY_NEEDLE" \
|
||||
'the needle scan can read this file' \
|
||||
'this is not one of our artifacts, or its strings are unreadable (packed/compressed/truncated) — every absence assertion below would pass vacuously'
|
||||
|
||||
# A1 — executable stack (ELF only). Every Linux artifact of v0.9.1-rc.1
|
||||
# shipped GNU_STACK RWE: a writable+executable stack, which no modern
|
||||
# binary has and which any classifier weighs heavily.
|
||||
if [ "$fmt" = elf ]; then
|
||||
if ! resolve_elf_reader; then
|
||||
echo "FAIL: no readelf/llvm-readelf/objdump available; cannot assert" \
|
||||
"the non-executable stack for $token — refusing to skip it" >&2
|
||||
exit 2
|
||||
fi
|
||||
flags=$(gnu_stack_flags "$file")
|
||||
# readelf spells the flags "RWE"/"RW", objdump "rwx"/"rw-" — match both.
|
||||
case "$flags" in
|
||||
'')
|
||||
report FAIL A1-noexec-stack "$token" \
|
||||
"no GNU_STACK program header found ($ELF_READER) — without PT_GNU_STACK the loader may fall back to READ_IMPLIES_EXEC"
|
||||
;;
|
||||
*E* | *X* | *e* | *x*)
|
||||
report FAIL A1-noexec-stack "$token" \
|
||||
"GNU_STACK is $flags — the stack is EXECUTABLE (link with -z noexecstack; check .S/asm objects for a missing .note.GNU-stack)"
|
||||
;;
|
||||
*)
|
||||
report PASS A1-noexec-stack "$token" "GNU_STACK is $flags (no execute bit)"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
printf 'n/a %-22s %s: executable-stack check is ELF-only\n' A1-noexec-stack "$token"
|
||||
fi
|
||||
|
||||
# A2 — test-only seams.
|
||||
for needle in "${SEAM_NEEDLES[@]}"; do
|
||||
assert_absent "$file" "$token" A2-no-test-seams "$needle"
|
||||
done
|
||||
# Sweep for seams nobody thought to pin: a new CBM_TEST_* env var added to
|
||||
# production code lands here on its first release, not on the next audit.
|
||||
# Two seams remain in release artifacts BY DECISION, so the wildcard is an
|
||||
# allowlist rather than a blanket ban: scripts/smoke-test.sh runs against the
|
||||
# real release artifact, and these are what let it do so honestly —
|
||||
# CRASH_ON/HANG_ON inject the faults that prove supervisor recovery, and
|
||||
# WINDOWS_USER_PATH_RUN_ID is what stops the PATH smoke from writing the
|
||||
# tester's actual PATH. Deleting them would trade genuine release-artifact
|
||||
# coverage for a cosmetic win. Anything NOT on this list is a novel seam and
|
||||
# fails, which is the property that matters: the list can only shrink by
|
||||
# decision, never grow by accident.
|
||||
seam_allowed='CBM_TEST_CRASH_ON CBM_TEST_HANG_ON CBM_TEST_WINDOWS_USER_PATH_RUN_ID'
|
||||
seam_unexpected=''
|
||||
for found in $(LC_ALL=C grep -a -o -E 'CBM_TEST_[A-Za-z0-9_]+' "$file" 2>/dev/null |
|
||||
sort -u || true); do
|
||||
case " $seam_allowed " in
|
||||
*" $found "*) ;;
|
||||
*) seam_unexpected="$seam_unexpected $found" ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$seam_unexpected" ]; then
|
||||
report FAIL A2-no-test-seams "$token" \
|
||||
"unexpected CBM_TEST_* seam(s):$seam_unexpected (allowlist: $seam_allowed)"
|
||||
else
|
||||
report PASS A2-no-test-seams "$token" 'no CBM_TEST_* seams beyond the smoke allowlist'
|
||||
fi
|
||||
|
||||
# A3 — updater/release URLs.
|
||||
for needle in "${UPDATER_NEEDLES[@]}"; do
|
||||
assert_absent "$file" "$token" A3-no-updater-urls "$needle"
|
||||
done
|
||||
|
||||
# A4 — SQLite loadable-extension surface.
|
||||
for needle in "${SQLITE_LOADEXT_NEEDLES[@]}"; do
|
||||
assert_absent "$file" "$token" A4-no-sqlite-loadext "$needle"
|
||||
done
|
||||
# Positive control for A4: the three needles above are all *absent* on a
|
||||
# stripped build even when the feature is compiled in, so on its own that
|
||||
# assertion can pass vacuously. SQLite's own compile-option table names
|
||||
# every OMIT_* it was built with — when that table is present (it ships
|
||||
# unless SQLITE_OMIT_COMPILEOPTION_DIAGS is set) it proves the omission
|
||||
# positively rather than by absence.
|
||||
if LC_ALL=C grep -a -q -F -e 'sqlite_compileoption_get' "$file"; then
|
||||
assert_present "$file" "$token" A4-no-sqlite-loadext 'OMIT_LOAD_EXTENSION' \
|
||||
'sqlite reports SQLITE_OMIT_LOAD_EXTENSION' \
|
||||
'sqlite was NOT built with SQLITE_OMIT_LOAD_EXTENSION, so the dlopen()/LoadLibrary() extension loader is linked in'
|
||||
else
|
||||
printf 'n/a %-22s %s: %s\n' A4-no-sqlite-loadext "$token" \
|
||||
"sqlite compile-option table absent; A4 rests on absence needles only"
|
||||
fi
|
||||
|
||||
# A5 — UI/HTTP subsystem, standard artifacts only.
|
||||
#
|
||||
# NOT YET ENFORCED. src/ui/{config,http_server,layout3d,httpd,embedded_stub}.c
|
||||
# are still in PROD_SRCS, and the standard build merely substitutes empty
|
||||
# embedded assets — so the HTTP server and its popen("ps … | grep") process
|
||||
# enumerator are linked into artifacts that can never serve a UI. Excluding
|
||||
# them is a real refactor: four files outside src/ui (src/main.c,
|
||||
# src/daemon/host.c, src/daemon/application.c, src/mcp/index_supervisor.c)
|
||||
# reference UI symbols, including the daemon that serves the UI.
|
||||
#
|
||||
# Until that lands, this assertion reports rather than fails. A gate everyone
|
||||
# knows is red teaches people to ignore gates, and a known-failing check has
|
||||
# no more enforcement value than this note — but the needles are kept live and
|
||||
# exercised so that the day the split lands, flipping CBM_CHECK_UI_ABSENT=1
|
||||
# (then making it the default) is a one-line change and not a rewrite.
|
||||
if [ "$is_ui" -eq 1 ]; then
|
||||
printf 'n/a %-22s %s: UI artifact, HTTP server ships here by design\n' \
|
||||
A5-no-ui-http "$token"
|
||||
elif [ "${CBM_CHECK_UI_ABSENT:-0}" = "1" ]; then
|
||||
for needle in "${UI_HTTP_NEEDLES[@]}"; do
|
||||
assert_absent "$file" "$token" A5-no-ui-http "$needle"
|
||||
done
|
||||
else
|
||||
ui_hits=0
|
||||
for needle in "${UI_HTTP_NEEDLES[@]}"; do
|
||||
if LC_ALL=C grep -a -q -F -e "$needle" "$file"; then
|
||||
ui_hits=$((ui_hits + 1))
|
||||
fi
|
||||
done
|
||||
printf 'INFO %-22s %s: %d/%d UI/HTTP needles present (no-UI split pending; set CBM_CHECK_UI_ABSENT=1 to enforce)\n' \
|
||||
A5-no-ui-http "$token" "$ui_hits" "${#UI_HTTP_NEEDLES[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Walk the targets ────────────────────────────────────────────────
|
||||
for target in "${TARGETS[@]}"; do
|
||||
if [ -d "$target" ]; then
|
||||
# "! -type d" rather than "-type f": a symlinked or otherwise unusual
|
||||
# artifact must produce a visible skip line, never vanish from the run.
|
||||
# sort keeps the report order stable across platforms (find order is not).
|
||||
while IFS= read -r f; do
|
||||
[ -n "$f" ] && check_file "$f"
|
||||
done <<EOF
|
||||
$(find "$target" ! -type d | LC_ALL=C sort)
|
||||
EOF
|
||||
elif [ -f "$target" ]; then
|
||||
check_file "$target"
|
||||
else
|
||||
echo "FAIL: $target is neither a file nor a directory" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
|
||||
printf '\n'
|
||||
if [ "$checked_files" -eq 0 ]; then
|
||||
echo "FAIL: no ELF/Mach-O/PE binary found in the given targets ($skipped_files file(s) skipped)" >&2
|
||||
echo " a gate that checked nothing is not a green gate" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ "$fail_count" -ne 0 ]; then
|
||||
echo "BINARY COMPOSITION GATE FAILED: $fail_count assertion(s) over $checked_files binary/binaries" >&2
|
||||
for f in "${FAILURES[@]}"; do
|
||||
echo " - $f" >&2
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
echo "BINARY COMPOSITION OK: $pass_count assertion(s) passed over $checked_files binary/binaries"
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression guard: the linux binary we ship must START on OLD glibc.
|
||||
#
|
||||
# The standard linux release binary dynamically links glibc 2.38+ / GLIBCXX
|
||||
# 3.4.32 and fails to start on Debian 11, RHEL/Rocky 8, Ubuntu 20.04, Amazon
|
||||
# Linux 2, etc. The fix points all linux install + self-update paths at the
|
||||
# fully-static "-portable" asset. This runs a given linux binary inside an
|
||||
# old-glibc container (debian:bullseye, glibc 2.31) and asserts it starts:
|
||||
# - RED for the dynamic standard binary (GLIBC_2.38 not found)
|
||||
# - GREEN for the static -portable binary (runs anywhere)
|
||||
#
|
||||
# Usage: check-glibc-compat.sh <path-to-linux-binary>
|
||||
# Env: GLIBC_TEST_IMAGE (default: debian:bullseye-slim, glibc 2.31)
|
||||
set -euo pipefail
|
||||
|
||||
BIN="${1:?usage: check-glibc-compat.sh <path-to-linux-binary>}"
|
||||
IMAGE="${GLIBC_TEST_IMAGE:-debian:bullseye-slim}"
|
||||
BIN_ABS="$(cd "$(dirname "$BIN")" && pwd)/$(basename "$BIN")"
|
||||
|
||||
echo "==> running $(basename "$BIN") --version inside ${IMAGE} (glibc 2.31)"
|
||||
docker run --rm -v "${BIN_ABS}:/cbm:ro" "${IMAGE}" /cbm --version
|
||||
echo "PASS: binary starts on old glibc (${IMAGE})"
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
# Wait for VirusTotal scans to complete and check results.
|
||||
# Expects: VT_API_KEY, VT_ANALYSIS (comma-separated "file=URL" pairs)
|
||||
set -euo pipefail
|
||||
|
||||
MIN_ENGINES=60
|
||||
rm -f /tmp/vt_gate_fail
|
||||
|
||||
echo "=== Waiting for VirusTotal scans to fully complete ==="
|
||||
|
||||
echo "$VT_ANALYSIS" | tr ',' '\n' | while IFS= read -r entry; do
|
||||
[ -z "$entry" ] && continue
|
||||
FILE=$(echo "$entry" | cut -d'=' -f1)
|
||||
URL=$(echo "$entry" | cut -d'=' -f2-)
|
||||
BASENAME=$(basename "$FILE")
|
||||
|
||||
# Extract base64 analysis ID from URL
|
||||
ANALYSIS_ID=$(echo "$URL" | sed -n 's|.*/file-analysis/\([^/]*\)/.*|\1|p')
|
||||
if [ -z "$ANALYSIS_ID" ]; then
|
||||
ANALYSIS_ID=$(echo "$URL" | grep -oE '[a-f0-9]{64}')
|
||||
if [ -z "$ANALYSIS_ID" ]; then
|
||||
echo "BLOCKED: Cannot parse VirusTotal URL: $URL"
|
||||
echo "FAIL" >> /tmp/vt_gate_fail
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Poll until completed (max 120 min)
|
||||
SCAN_COMPLETE=false
|
||||
for attempt in $(seq 1 720); do
|
||||
RESULT=$(curl -sf --max-time 10 \
|
||||
-H "x-apikey: $VT_API_KEY" \
|
||||
"https://www.virustotal.com/api/v3/analyses/$ANALYSIS_ID" 2>/dev/null || echo "")
|
||||
|
||||
if [ -z "$RESULT" ]; then
|
||||
echo " $BASENAME: waiting (attempt $attempt)..."
|
||||
sleep 10
|
||||
continue
|
||||
fi
|
||||
|
||||
STATS=$(echo "$RESULT" | python3 -c "
|
||||
import json, sys
|
||||
d = json.loads(sys.stdin.read())
|
||||
attrs = d.get('data', {}).get('attributes', {})
|
||||
status = attrs.get('status', 'queued')
|
||||
stats = attrs.get('stats', {})
|
||||
malicious = stats.get('malicious', 0)
|
||||
suspicious = stats.get('suspicious', 0)
|
||||
undetected = stats.get('undetected', 0)
|
||||
harmless = stats.get('harmless', 0)
|
||||
total = sum(stats.values())
|
||||
completed = malicious + suspicious + undetected + harmless
|
||||
print(f'{status},{malicious},{suspicious},{completed},{total}')
|
||||
" 2>/dev/null || echo "queued,0,0,0,0")
|
||||
|
||||
STATUS=$(echo "$STATS" | cut -d',' -f1)
|
||||
MALICIOUS=$(echo "$STATS" | cut -d',' -f2)
|
||||
SUSPICIOUS=$(echo "$STATS" | cut -d',' -f3)
|
||||
COMPLETED=$(echo "$STATS" | cut -d',' -f4)
|
||||
TOTAL=$(echo "$STATS" | cut -d',' -f5)
|
||||
|
||||
if [ "$STATUS" = "completed" ]; then
|
||||
SCAN_COMPLETE=true
|
||||
if [ "$COMPLETED" -lt "$MIN_ENGINES" ]; then
|
||||
echo "NOTE: $BASENAME completed with only $COMPLETED/$TOTAL engines (< $MIN_ENGINES)"
|
||||
fi
|
||||
if [ "$MALICIOUS" -gt 0 ] || [ "$SUSPICIOUS" -gt 0 ]; then
|
||||
echo "BLOCKED: $BASENAME flagged ($MALICIOUS malicious, $SUSPICIOUS suspicious / $COMPLETED engines)"
|
||||
echo " $URL"
|
||||
echo "FAIL" >> /tmp/vt_gate_fail
|
||||
else
|
||||
echo "OK: $BASENAME clean ($COMPLETED engines, 0 detections)"
|
||||
fi
|
||||
break
|
||||
fi
|
||||
|
||||
echo " $BASENAME: $COMPLETED/$TOTAL engines ($STATUS, attempt $attempt)..."
|
||||
sleep 10
|
||||
done
|
||||
|
||||
if [ "$SCAN_COMPLETE" != "true" ]; then
|
||||
echo "WARNING: $BASENAME scan did not complete in time"
|
||||
echo "FAIL" >> /tmp/vt_gate_fail
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -f /tmp/vt_gate_fail ]; then
|
||||
echo "BLOCKED: One or more VirusTotal checks failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "=== All VirusTotal scans passed ==="
|
||||
@@ -0,0 +1,84 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sweep cbm test residue from a Windows test host and assert a runner-like free
|
||||
disk, before any test/smoke/soak run.
|
||||
|
||||
.DESCRIPTION
|
||||
A GitHub-hosted runner is ephemeral: every job starts on a fresh image with a
|
||||
known-free disk. The local Windows VM is long-lived, so each run leaves temp
|
||||
roots, staged bundles and ~100 MB binary copies behind. Left alone that drift
|
||||
is not merely untidy - it changes the environment under test, and a disk that
|
||||
has quietly filled produces ERROR_DISK_FULL deep inside the install path, which
|
||||
reads as a product failure rather than an environment one. That misdiagnosis
|
||||
has already cost a full session.
|
||||
|
||||
So every run starts from the same shape the runner would give it: residue gone,
|
||||
free space asserted. Refusing to start is correct - an unusable environment is a
|
||||
run blocker to escalate, never something to quietly run anyway on a bad disk.
|
||||
|
||||
Sweeps only cbm-prefixed directories under the profile and TEMP. The checkout
|
||||
(C:\cbm) is not under either, and is never touched.
|
||||
|
||||
.PARAMETER MinFreeGB
|
||||
Free space required before a run. Defaults to 14, the SSD size a GitHub-hosted
|
||||
Windows runner advertises, so the local venue cannot run under conditions the
|
||||
CI venue would never see.
|
||||
|
||||
.PARAMETER SkipGate
|
||||
Sweep and report, but do not fail when free space is short. For inspection only.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[double]$MinFreeGB = 14,
|
||||
[switch]$SkipGate
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Get-FreeGB {
|
||||
[math]::Round((Get-PSDrive C).Free / 1GB, 2)
|
||||
}
|
||||
|
||||
# The guard suites deliberately build adversarial trees - names with spaces and
|
||||
# non-representable characters, deep .cbm-retired/generations nesting - whose
|
||||
# full paths exceed MAX_PATH. Remove-Item cannot address those and fails with
|
||||
# DirectoryNotFoundException, so `rd` under the \\?\ prefix (which bypasses the
|
||||
# 260-char limit) is the fallback. Every removal is then VERIFIED: an earlier
|
||||
# revision counted attempts, not successes, and cheerfully reported 86 swept
|
||||
# directories while 11 GB of them were still sitting on the disk.
|
||||
function Remove-ResidueDir([string]$Path) {
|
||||
Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue
|
||||
if (-not (Test-Path -LiteralPath $Path)) { return $true }
|
||||
& cmd.exe /c "rd /s /q `"\\?\$Path`"" 2>&1 | Out-Null
|
||||
return -not (Test-Path -LiteralPath $Path)
|
||||
}
|
||||
|
||||
$before = Get-FreeGB
|
||||
$removed = 0
|
||||
$failed = @()
|
||||
$roots = @($env:USERPROFILE, $env:TEMP) | Where-Object { $_ } | Select-Object -Unique
|
||||
|
||||
foreach ($root in $roots) {
|
||||
if (-not (Test-Path -LiteralPath $root)) { continue }
|
||||
Get-ChildItem -LiteralPath $root -Directory -Filter 'cbm-*' -ErrorAction SilentlyContinue |
|
||||
ForEach-Object {
|
||||
if (Remove-ResidueDir $_.FullName) {
|
||||
$removed++
|
||||
} else {
|
||||
$failed += $_.FullName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$after = Get-FreeGB
|
||||
Write-Output "residue-dirs-removed=$removed residue-dirs-failed=$($failed.Count) free-gb-before=$before free-gb-after=$after"
|
||||
foreach ($f in $failed) { Write-Warning "could not sweep: $f" }
|
||||
|
||||
if (-not $SkipGate -and $after -lt $MinFreeGB) {
|
||||
$msg = "BLOCKED: $after GB free, need $MinFreeGB GB. " +
|
||||
"A GitHub runner never starts this low, so a run here would not be " +
|
||||
"comparable - and a disk that fills mid-run surfaces as a bogus " +
|
||||
"product failure rather than an environment one. Free space, re-run."
|
||||
Write-Error $msg
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
# ensure-defender.ps1 — Windows Defender real-time protection must be ACTIVE
|
||||
# on every Windows venue: the local test VM and every GitHub Windows runner
|
||||
# alike. The AV interaction surface (file locks on fresh binaries, scan-on-
|
||||
# first-execute latency, quarantine behavior) is part of what the Windows legs
|
||||
# test; a venue with Defender off is testing a different operating system.
|
||||
#
|
||||
# GitHub's runner images ship with Defender disabled, so this script ENABLES
|
||||
# it, then VERIFIES it is actually running — and fails closed if it cannot be
|
||||
# made active. No silent skip: a leg that cannot get Defender on must go red,
|
||||
# not quietly measure the wrong environment. (Same doctrine as the smoke
|
||||
# no-skip rules: a gate that can be skipped is not a gate.)
|
||||
#
|
||||
# Canonical entry: local VM preflight (win.sh) and the Windows CI jobs all run
|
||||
# THIS file — venue parity by construction.
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Try-Step {
|
||||
param([string]$What, [scriptblock]$Action)
|
||||
try {
|
||||
& $Action
|
||||
Write-Host "ensure-defender: $What - ok"
|
||||
} catch {
|
||||
# Individual enable steps may legitimately no-op (already enabled,
|
||||
# service already running); only the final verification gates.
|
||||
Write-Host "ensure-defender: $What - $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
Try-Step "WinDefend service startup type" {
|
||||
Set-Service -Name WinDefend -StartupType Automatic
|
||||
}
|
||||
Try-Step "WinDefend service start" {
|
||||
Start-Service -Name WinDefend
|
||||
}
|
||||
Try-Step "enable real-time monitoring" {
|
||||
Set-MpPreference -DisableRealtimeMonitoring $false
|
||||
}
|
||||
|
||||
$status = $null
|
||||
try {
|
||||
$status = Get-MpComputerStatus
|
||||
} catch {
|
||||
Write-Host "ensure-defender: FAIL - Defender engine unavailable: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not $status.AntivirusEnabled) {
|
||||
Write-Host "ensure-defender: FAIL - antivirus engine is not enabled on this venue"
|
||||
exit 1
|
||||
}
|
||||
if (-not $status.RealTimeProtectionEnabled) {
|
||||
Write-Host "ensure-defender: FAIL - real-time protection is OFF and could not be enabled"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ("=== ensure-defender: ACTIVE (engine {0}, signatures {1}, RTP on) ===" -f `
|
||||
$status.AMEngineVersion, $status.AntivirusSignatureVersion)
|
||||
exit 0
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate the release SPDX SBOM (sbom.json).
|
||||
|
||||
Canonical release step (called by release.yml). Lived inline in workflow YAML
|
||||
until 2026-07-26 — vendored-dependency versions belong in a reviewable,
|
||||
venue-independent script, and the venue-parity contract forbids logic in
|
||||
workflow run-blocks.
|
||||
|
||||
Usage: scripts/ci/generate-sbom.py <version> (e.g. v0.9.1)
|
||||
|
||||
Keep versionInfo entries in sync with the vendored trees; the authoritative
|
||||
per-grammar license list is internal/cbm/vendored/grammars/MANIFEST.md.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2 or sys.argv[1] in {"-h", "--help"}:
|
||||
print(__doc__.strip(), file=sys.stderr)
|
||||
sys.exit(0 if len(sys.argv) == 2 else 2)
|
||||
|
||||
version = sys.argv[1]
|
||||
n_grammars = len(
|
||||
[d for d in glob.glob("internal/cbm/vendored/grammars/*") if os.path.isdir(d)]
|
||||
)
|
||||
sbom = {
|
||||
"spdxVersion": "SPDX-2.3",
|
||||
"dataLicense": "CC0-1.0",
|
||||
"SPDXID": "SPDXRef-DOCUMENT",
|
||||
"name": f"codebase-memory-mcp-{version}",
|
||||
"documentNamespace": f"https://github.com/DeusData/codebase-memory-mcp/releases/{version}",
|
||||
"creationInfo": {
|
||||
"created": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||
"creators": ["Tool: codebase-memory-mcp-release-pipeline"],
|
||||
},
|
||||
"packages": [
|
||||
{"SPDXID": "SPDXRef-Package-sqlite3", "name": "sqlite3", "versionInfo": "3.51.3", "licenseDeclared": "blessing", "downloadLocation": "https://sqlite.org", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-yyjson", "name": "yyjson", "versionInfo": "0.12.0", "licenseDeclared": "MIT", "downloadLocation": "https://github.com/ibireme/yyjson", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-mimalloc", "name": "mimalloc", "versionInfo": "3.3.2", "licenseDeclared": "MIT", "downloadLocation": "https://github.com/microsoft/mimalloc", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-xxhash", "name": "xxhash", "versionInfo": "0.8.3", "licenseDeclared": "BSD-2-Clause", "downloadLocation": "https://github.com/Cyan4973/xxHash", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-tre", "name": "tre", "versionInfo": "0.8.0", "licenseDeclared": "BSD-2-Clause", "downloadLocation": "https://github.com/laurikari/tre", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-tree-sitter", "name": "tree-sitter", "versionInfo": "0.24.4", "licenseDeclared": "MIT", "downloadLocation": "https://github.com/tree-sitter/tree-sitter", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-lz4", "name": "lz4", "versionInfo": "1.10.0", "licenseDeclared": "BSD-2-Clause", "downloadLocation": "https://github.com/lz4/lz4", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-zstd", "name": "zstd", "versionInfo": "1.5.7", "licenseDeclared": "BSD-3-Clause", "downloadLocation": "https://github.com/facebook/zstd", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-simplecpp", "name": "simplecpp", "versionInfo": "1.x", "licenseDeclared": "0BSD", "downloadLocation": "https://github.com/danmar/simplecpp", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-verstable", "name": "verstable", "versionInfo": "2.2.1", "licenseDeclared": "MIT", "downloadLocation": "https://github.com/JacksonAllan/Verstable", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-wyhash", "name": "wyhash", "versionInfo": "final-4.3", "licenseDeclared": "Unlicense", "downloadLocation": "https://github.com/wangyi-fudan/wyhash", "filesAnalyzed": False},
|
||||
{"SPDXID": "SPDXRef-Package-nomic-embed-code", "name": "nomic-embed-code-token-embeddings", "versionInfo": "1.0", "licenseDeclared": "Apache-2.0", "downloadLocation": "https://huggingface.co/nomic-ai/nomic-embed-code", "filesAnalyzed": False, "comment": "Derived int8 token embeddings; see vendored/nomic/NOTICE"},
|
||||
{"SPDXID": "SPDXRef-Package-tree-sitter-grammars", "name": "tree-sitter-grammars-aggregate", "versionInfo": f"{n_grammars}-grammars", "licenseDeclared": "MIT", "downloadLocation": "NOASSERTION", "filesAnalyzed": False, "comment": f"Aggregate of {n_grammars} vendored tree-sitter grammars, compiled statically. Predominantly MIT; non-MIT families present include CC0-1.0 (clojure, fennel), Apache-2.0 (elixir, erlang, gleam, hcl, ini, jinja2, just, pkl, sway, wit), ISC (pine, templ), Unlicense (fish); first-party grammars (c) DeusData, MIT. This summary is non-exhaustive; the authoritative complete per-grammar license list is internal/cbm/vendored/grammars/MANIFEST.md, and full license texts ship in THIRD_PARTY_NOTICES.md inside each archive."},
|
||||
],
|
||||
}
|
||||
json.dump(sbom, open("sbom.json", "w"), indent=2)
|
||||
print(f"sbom.json written ({n_grammars} grammars, version {version})")
|
||||
@@ -0,0 +1,74 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Create a protected per-user temp root and print its path.
|
||||
|
||||
.DESCRIPTION
|
||||
The daemon and install-flow suites fail closed on the MSYS-shared /tmp and on a
|
||||
runner's inherited LocalAppData\Temp ACLs: both grant mutation rights to
|
||||
Authenticated Users, which the launcher/daemon trust policy correctly refuses.
|
||||
Running them there produces security refusals, not test signal. Every venue
|
||||
therefore gives the harness a per-user root beneath the profile carrying an
|
||||
owner-stamped, protected current-SID DACL.
|
||||
|
||||
This is the single implementation. It was duplicated between
|
||||
.github/workflows/_test.yml and test-infrastructure/vm/vm-run-tests.sh - which
|
||||
let the two venues drift - and _soak.yml carried no copy at all, so CI soaked
|
||||
under the default runner TEMP while the local soak ran hardened.
|
||||
|
||||
.PARAMETER Prefix
|
||||
Directory-name prefix for the root. Also selects what -PruneStale sweeps, so
|
||||
each venue keeps its own namespace.
|
||||
|
||||
.PARAMETER ProtectDir
|
||||
Extra directories to create and stamp with the same protected DACL. The
|
||||
workspace drive root grants Authenticated Users Modify by inheritance - a shape
|
||||
real user checkouts under the profile do not have - so build outputs living
|
||||
there need the same treatment or the activation transaction's source-directory
|
||||
policy refuses them.
|
||||
|
||||
.PARAMETER PruneStale
|
||||
Remove earlier roots sharing this prefix before creating the new one. Intended
|
||||
for the long-lived VM, where roots accumulate; a fresh runner has none.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Prefix = 'cbm-tmp-',
|
||||
[string[]]$ProtectDir = @(),
|
||||
[switch]$PruneStale
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if ($PruneStale) {
|
||||
Get-ChildItem -LiteralPath $env:USERPROFILE -Directory -Filter "$Prefix*" `
|
||||
-ErrorAction SilentlyContinue |
|
||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
||||
$rule = [System.Security.AccessControl.FileSystemAccessRule]::new(
|
||||
$sid,
|
||||
[System.Security.AccessControl.FileSystemRights]::FullControl,
|
||||
([System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor
|
||||
[System.Security.AccessControl.InheritanceFlags]::ObjectInherit),
|
||||
[System.Security.AccessControl.PropagationFlags]::None,
|
||||
[System.Security.AccessControl.AccessControlType]::Allow)
|
||||
|
||||
function Set-ProtectedAcl([string]$Path) {
|
||||
$acl = [System.Security.AccessControl.DirectorySecurity]::new()
|
||||
$acl.SetOwner($sid)
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$acl.AddAccessRule($rule) | Out-Null
|
||||
Set-Acl -LiteralPath $Path -AclObject $acl
|
||||
}
|
||||
|
||||
$root = Join-Path $env:USERPROFILE ($Prefix + [guid]::NewGuid().ToString('N'))
|
||||
New-Item -ItemType Directory -Path $root | Out-Null
|
||||
Set-ProtectedAcl $root
|
||||
|
||||
foreach ($dir in $ProtectDir) {
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
Set-ProtectedAcl $dir
|
||||
}
|
||||
|
||||
Write-Output $root
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# Bring the container venue to the shape a GitHub runner would hand us, before
|
||||
# any docker-backed test/smoke run.
|
||||
#
|
||||
# A GitHub-hosted runner is ephemeral: fresh image, known-free disk, no leftover
|
||||
# containers or volumes from a previous job. Colima is long-lived, so exited
|
||||
# containers and orphaned volumes accumulate and the disk drifts down. That
|
||||
# drift is not cosmetic — a disk that fills mid-run fails deep inside the
|
||||
# install path and reads as a product bug rather than an environment one.
|
||||
#
|
||||
# Default sweep is the state a runner would never have carried in: stopped
|
||||
# containers, dangling images, unused volumes. The build cache is KEPT by
|
||||
# default — a runner restores an equivalent cache via actions/cache, so wiping
|
||||
# it locally would diverge from CI, not converge with it. --deep drops it too.
|
||||
#
|
||||
# Usage: preflight-docker.sh [--deep] [--min-free-gb N] [--skip-gate]
|
||||
set -euo pipefail
|
||||
|
||||
# A German (or any comma-decimal) locale makes awk print "76,38" and then parse
|
||||
# it back as 76, so the free-space gate would silently compare the wrong number.
|
||||
# Pin the numeric locale for every awk/df in this script.
|
||||
export LC_ALL=C
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: scripts/ci/preflight-docker.sh [--deep] [--min-free-gb N] [--skip-gate]
|
||||
|
||||
Bring the Colima/docker venue to the shape a GitHub runner would hand us,
|
||||
before any container-backed test/smoke/soak run (test-infrastructure/run.sh
|
||||
calls this automatically; CBM_SKIP_PREFLIGHT=1 opts out for a quick re-run).
|
||||
|
||||
Sweeps stopped containers, dangling images and unused anonymous volumes, then
|
||||
asserts free space on the filesystem backing the docker data root. The build
|
||||
cache and NAMED compose volumes are KEPT by default — they are this venue's
|
||||
analogue of actions/cache, so wiping them would diverge from CI, not converge.
|
||||
|
||||
Options:
|
||||
--deep Also drop the build cache, named volumes and every unused
|
||||
image (full cold start).
|
||||
--min-free-gb N Free-space floor (default 14 — the runner's SSD size).
|
||||
Below it the script BLOCKS with exit 1: a disk that fills
|
||||
mid-run fails deep inside the install path and reads as a
|
||||
product bug, so refusing to start is the correct outcome.
|
||||
--skip-gate Sweep and report, but never block (inspection only).
|
||||
-h, --help This text.
|
||||
EOF
|
||||
}
|
||||
|
||||
DEEP=0
|
||||
MIN_FREE_GB=14
|
||||
SKIP_GATE=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--deep) DEEP=1 ;;
|
||||
--min-free-gb) MIN_FREE_GB="${2:?--min-free-gb needs a value}"; shift ;;
|
||||
--skip-gate) SKIP_GATE=1 ;;
|
||||
-h | --help) usage; exit 0 ;;
|
||||
*) echo "preflight-docker: unknown argument '$1'. Please consult --help." >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
echo "preflight-docker: docker is not reachable — start Colima first" >&2
|
||||
echo " (Docker Desktop is broken on this machine; Colima is the runtime)" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
free_gb() {
|
||||
# Measure the filesystem that actually backs the docker data root, not the
|
||||
# VM's `/`: on Colima they are different mounts, and `/` reported 18 GB free
|
||||
# while 12.5 GB of images lived elsewhere. The host's own free space is
|
||||
# irrelevant to a container that fills the VM's disk.
|
||||
local root
|
||||
root="$(docker info --format '{{.DockerRootDir}}' 2>/dev/null || echo /var/lib/docker)"
|
||||
docker run --rm -v /:/hostroot alpine:3 \
|
||||
df -P "/hostroot${root}" 2>/dev/null |
|
||||
awk 'NR==2 {printf "%.2f", $4/1048576}'
|
||||
}
|
||||
|
||||
before="$(free_gb || echo 0)"
|
||||
echo "=== preflight-docker: sweeping runner-unlike residue ==="
|
||||
# Anonymous volumes only: the NAMED compose volumes are this venue's warm cache
|
||||
# (the local analogue of actions/cache), so dropping them would diverge from CI
|
||||
# rather than converge with it. --deep takes them too.
|
||||
docker container prune -f
|
||||
docker volume prune -f
|
||||
docker image prune -f
|
||||
if [ "$DEEP" -eq 1 ]; then
|
||||
echo "--- deep: dropping build cache, named volumes and every unused image ---"
|
||||
docker builder prune -af
|
||||
docker volume prune -af
|
||||
docker image prune -af
|
||||
fi
|
||||
after="$(free_gb || echo 0)"
|
||||
echo "preflight-docker: free-gb-before=${before} free-gb-after=${after}"
|
||||
docker system df
|
||||
|
||||
if [ "$SKIP_GATE" -eq 0 ] &&
|
||||
awk -v a="$after" -v m="$MIN_FREE_GB" 'BEGIN {exit !(a < m)}'; then
|
||||
echo "BLOCKED: ${after} GB free, need ${MIN_FREE_GB} GB. A GitHub runner never" >&2
|
||||
echo " starts this low, so this run would not be comparable. Re-run with" >&2
|
||||
echo " --deep to reclaim the build cache, or free space on the Colima VM." >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# require-all-green.sh — the aggregate gate step: fail unless every needed job
|
||||
# succeeded (or was legitimately skipped).
|
||||
#
|
||||
# Canonical CI step (called by pr.yml ci-ok with RESULTS = toJSON(needs)).
|
||||
# Lived inline in workflow YAML until 2026-07-26; the venue-parity contract
|
||||
# forbids logic in workflow run-blocks. `skipped` counts as OK because gated
|
||||
# jobs (e.g. pr-smoke on docs-only PRs) skip by design — a matrix rename can
|
||||
# still never silently deadlock a merge, which is this gate's purpose.
|
||||
#
|
||||
# Usage: RESULTS='<json of the needs context>' scripts/ci/require-all-green.sh
|
||||
set -euo pipefail
|
||||
|
||||
case "${1:-}" in
|
||||
-h | --help)
|
||||
sed -n '2,11p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
: "${RESULTS:?set RESULTS to the toJSON(needs) context}"
|
||||
|
||||
printf '%s' "$RESULTS" | python3 -c "
|
||||
import json, sys
|
||||
needs = json.load(sys.stdin)
|
||||
bad = {k: v['result'] for k, v in needs.items() if v['result'] not in ('success', 'skipped')}
|
||||
if bad:
|
||||
print('CI NOT OK:', bad)
|
||||
sys.exit(1)
|
||||
print('CI OK:', ', '.join(needs))
|
||||
"
|
||||
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# smoke-artifact.sh — the local ARTIFACT-FLOW smoke lane. The release venue
|
||||
# smokes the shipped archive (download → extract → canonical wrapper); before
|
||||
# this lane existed, local CI only ever smoked source builds, so the whole
|
||||
# packaging/archive-layout bug class could first appear in a release dry run.
|
||||
#
|
||||
# This driver reproduces the release flow end to end with local bytes:
|
||||
# scripts/build.sh → scripts/package-release.sh → extract →
|
||||
# the SAME canonical wrapper the remote venue runs, in artifact mode
|
||||
# (CBM_SMOKE_ARTIFACT_DIR), whose completeness checks make a broken or
|
||||
# incomplete archive a loud failure.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: scripts/ci/smoke-artifact.sh <goos> <goarch> [--variant standard|ui]
|
||||
[VAR=VAL ...]
|
||||
|
||||
Build → package (scripts/package-release.sh) → extract → smoke the EXTRACTED
|
||||
artifact through the canonical wrapper, exactly like the release venue:
|
||||
unix: scripts/smoke-local.sh with CBM_SMOKE_ARTIFACT_DIR
|
||||
windows: test-infrastructure/vm/vm-smoke.sh with CBM_SMOKE_ARTIFACT_DIR
|
||||
(run inside the VM/CI msys2 shell)
|
||||
|
||||
--variant ui builds --with-ui and smokes the ui archive (Phase 15 embedded
|
||||
assets become mandatory — a standard binary cannot pass a ui run).
|
||||
|
||||
Make passthrough (VAR=VAL): CC= CXX= STATIC=1 ... forwarded to build steps.
|
||||
Environment: BUILD_DIR (default build/c) — build tree used for the archive.
|
||||
On failure the work directory is preserved for post-mortem (path printed).
|
||||
EOF
|
||||
}
|
||||
|
||||
GOOS=""
|
||||
GOARCH=""
|
||||
VARIANT="standard"
|
||||
BUILD_ARGS=()
|
||||
expect_value=""
|
||||
for arg in "$@"; do
|
||||
if [ "$expect_value" = "variant" ]; then
|
||||
VARIANT="$arg"; expect_value=""; continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-h | --help) usage; exit 0 ;;
|
||||
--variant) expect_value="variant" ;;
|
||||
--variant=*) VARIANT="${arg#--variant=}" ;;
|
||||
-*)
|
||||
echo "smoke-artifact: unknown option '$arg'. Please consult --help." >&2
|
||||
exit 2
|
||||
;;
|
||||
*=*) BUILD_ARGS+=("$arg") ;;
|
||||
*)
|
||||
if [ -z "$GOOS" ]; then GOOS="$arg"
|
||||
elif [ -z "$GOARCH" ]; then GOARCH="$arg"
|
||||
else
|
||||
echo "smoke-artifact: unexpected argument '$arg'. Please consult --help." >&2
|
||||
exit 2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[ -n "$GOOS" ] && [ -n "$GOARCH" ] || { usage >&2; exit 2; }
|
||||
case "$VARIANT" in
|
||||
standard) SUFFIX=""; UI_FLAG=() ;;
|
||||
ui) SUFFIX="-ui"; UI_FLAG=(--with-ui) ;;
|
||||
*) echo "smoke-artifact: variant must be 'standard' or 'ui'. Please consult --help." >&2; exit 2 ;;
|
||||
esac
|
||||
case "$GOARCH" in
|
||||
*-portable) BUILD_ARGS+=("STATIC=1") ;;
|
||||
esac
|
||||
|
||||
BUILD_DIR="${BUILD_DIR:-build/c}"
|
||||
export BUILD_DIR
|
||||
|
||||
scripts/build.sh ${UI_FLAG[@]+"${UI_FLAG[@]}"} \
|
||||
BUILD_DIR="$BUILD_DIR" ${BUILD_ARGS[@]+"${BUILD_ARGS[@]}"}
|
||||
if [ "$GOOS" = "darwin" ]; then
|
||||
codesign --sign - --force "$BUILD_DIR/codebase-memory-mcp"
|
||||
fi
|
||||
|
||||
WORK_DIR="$(mktemp -d "${TMPDIR:-/tmp}/cbm-smoke-artifact.XXXXXX")"
|
||||
cleanup() {
|
||||
local status=$?
|
||||
trap - EXIT
|
||||
if [ "$status" -eq 0 ]; then
|
||||
rm -rf "$WORK_DIR"
|
||||
else
|
||||
echo "smoke-artifact: preserved failed lane root at $WORK_DIR" >&2
|
||||
fi
|
||||
exit "$status"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
scripts/package-release.sh "$GOOS" "$GOARCH" --variant "$VARIANT" \
|
||||
--out-dir "$WORK_DIR" ${BUILD_ARGS[@]+"${BUILD_ARGS[@]}"}
|
||||
|
||||
NAME="codebase-memory-mcp${SUFFIX}-${GOOS}-${GOARCH}"
|
||||
EXTRACT_DIR="$WORK_DIR/extract"
|
||||
mkdir -p "$EXTRACT_DIR"
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
unzip -q -o "$WORK_DIR/$NAME.zip" -d "$EXTRACT_DIR"
|
||||
test -s "$EXTRACT_DIR/codebase-memory-mcp.exe"
|
||||
# ONE binary per platform: a payload sibling means the AV-flagged launcher
|
||||
# stub came back.
|
||||
test ! -e "$EXTRACT_DIR/codebase-memory-mcp.payload.exe"
|
||||
echo "=== smoke-artifact: smoking EXTRACTED $NAME.zip via vm-smoke.sh ==="
|
||||
SMOKE_ARCH="$GOARCH" SMOKE_VARIANT="$VARIANT" \
|
||||
CBM_SMOKE_ARTIFACT_DIR="$EXTRACT_DIR" \
|
||||
bash test-infrastructure/vm/vm-smoke.sh
|
||||
else
|
||||
tar -xzf "$WORK_DIR/$NAME.tar.gz" -C "$EXTRACT_DIR"
|
||||
chmod +x "$EXTRACT_DIR/codebase-memory-mcp"
|
||||
echo "=== smoke-artifact: smoking EXTRACTED $NAME.tar.gz via smoke-local.sh ==="
|
||||
CBM_SMOKE_ARTIFACT_DIR="$EXTRACT_DIR" \
|
||||
scripts/smoke-local.sh "$EXTRACT_DIR/codebase-memory-mcp" "$VARIANT"
|
||||
fi
|
||||
echo "=== smoke-artifact: $NAME passed ==="
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
# verify-shard-union.sh — prove the sharded test legs lost nothing.
|
||||
#
|
||||
# Canonical CI step (called by _test.yml's shard-completeness job on the
|
||||
# downloaded shard-manifest-* artifacts). Lived inline in workflow YAML until
|
||||
# 2026-07-26; the venue-parity contract forbids logic in workflow run-blocks.
|
||||
#
|
||||
# For every leg it asserts: all shards agree on the shard count, indices form
|
||||
# exactly 1..n, every shard saw the same full suite list, and the UNION of the
|
||||
# shard slices equals that list — a rename/re-shard can never silently drop a
|
||||
# suite (gate-quality loss) without failing here.
|
||||
#
|
||||
# Usage: scripts/ci/verify-shard-union.sh <manifests-dir>
|
||||
set -eu
|
||||
|
||||
case "${1:-}" in
|
||||
-h | --help)
|
||||
sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
MANIFEST_DIR="${1:?usage: verify-shard-union.sh <manifests-dir> (see --help)}"
|
||||
|
||||
files=$(find "$MANIFEST_DIR" -name shard-manifest.txt | sort)
|
||||
if [ -z "$files" ]; then
|
||||
echo "FAIL: no shard manifests were uploaded" >&2
|
||||
exit 1
|
||||
fi
|
||||
rc=0
|
||||
for leg in $(grep -h '^leg=' $files | sort -u | sed 's/^leg=//'); do
|
||||
leg_files=$(grep -l "^leg=$leg\$" $files)
|
||||
n=$(grep -h '^shard=' $leg_files | sed 's|.*/||' | sort -u)
|
||||
if [ "$(printf '%s\n' "$n" | wc -l)" -ne 1 ]; then
|
||||
echo "FAIL: $leg shards disagree on shard count: $n" >&2
|
||||
rc=1
|
||||
continue
|
||||
fi
|
||||
indices=$(grep -h '^shard=' $leg_files | sed 's/^shard=//;s|/.*||' | sort -n)
|
||||
if [ "$indices" != "$(seq 1 "$n")" ]; then
|
||||
echo "FAIL: $leg shard indices [$indices] != 1..$n" >&2
|
||||
rc=1
|
||||
continue
|
||||
fi
|
||||
list_sha=$(grep -h '^list_sha256=' $leg_files | sed 's/^list_sha256=//' | sort -u)
|
||||
if [ "$(printf '%s\n' "$list_sha" | wc -l)" -ne 1 ]; then
|
||||
echo "FAIL: $leg shards saw different suite lists" >&2
|
||||
rc=1
|
||||
continue
|
||||
fi
|
||||
union_sha=$(for f in $leg_files; do
|
||||
sed -n '/^--- slice ---$/,$p' "$f" | tail -n +2
|
||||
done | sort | sha256sum | awk '{print $1}')
|
||||
if [ "$union_sha" != "$list_sha" ]; then
|
||||
echo "FAIL: $leg union of shard slices != full suite list (GATE-QUALITY LOSS)" >&2
|
||||
rc=1
|
||||
continue
|
||||
fi
|
||||
echo "OK: $leg — $n shard(s), union of slices == full suite list"
|
||||
done
|
||||
exit "$rc"
|
||||
Reference in New Issue
Block a user