diff --git a/.github/workflows/_lint.yml b/.github/workflows/_lint.yml index bddcee7df2..85a5f5d57d 100644 --- a/.github/workflows/_lint.yml +++ b/.github/workflows/_lint.yml @@ -30,6 +30,16 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Exclude 1.28 GB of generated grammar parser.c tables and tools/graph-ui + # while keeping scanner.c + headers for lint-vendored-scanners. + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/internal/cbm/vendored/grammars/*/parser.c + !/tools/ + !/graph-ui/ # Tests must pass or fail — no SKIPs except genuinely platform-specific # ones (SKIP_PLATFORM / #ifdef). Fails the lint phase on any plain SKIP(). @@ -37,16 +47,13 @@ jobs: run: bash scripts/check-no-test-skips.sh - name: Install build deps - timeout-minutes: 10 - run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev cmake - - - name: Install LLVM 20 timeout-minutes: 10 run: | - wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" | sudo tee /etc/apt/sources.list.d/llvm-20.list - APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update - sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y clang-format-20 + APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0 + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc >/dev/null + echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" | sudo tee /etc/apt/sources.list.d/llvm-20.list >/dev/null + sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update + sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev cmake clang-format-20 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 id: cppcheck-cache @@ -81,18 +88,23 @@ jobs: timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/internal/cbm/vendored/grammars/ + !/tools/ + !/graph-ui/ - name: Install build deps - timeout-minutes: 10 - run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev - - - name: Install LLVM 21 (pinned analyzer toolchain) timeout-minutes: 10 run: | - wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list - APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update - sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y clang-tidy-21 + APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0 + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc >/dev/null + echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list >/dev/null + sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update + sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev clang-tidy-21 - name: Memory-analyzer gate run: scripts/ci/lint-mem.sh clang-tidy-21 diff --git a/.github/workflows/_memwaste.yml b/.github/workflows/_memwaste.yml index cb5c508440..7fe1a8be77 100644 --- a/.github/workflows/_memwaste.yml +++ b/.github/workflows/_memwaste.yml @@ -38,8 +38,19 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install deps timeout-minutes: 10 - run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev python3 clang llvm + run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev python3 clang llvm ccache + - name: Compiler cache (content-verified) + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-memwaste-event-linux-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-memwaste-event-linux-${{ github.ref }}- + ccache-memwaste-event-linux- - name: Event lane on this repository + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1500M run: | # `cmd | tee` reports TEE's status: without this a failing lane # (a missing exec bit, a build error) passes the step and only @@ -66,12 +77,30 @@ jobs: timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/tools/ + !/graph-ui/ - name: Install deps timeout-minutes: 10 - run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev python3 clang llvm + run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev python3 clang llvm ccache + - name: Compiler cache (content-verified) + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-memwaste-scaling-linux-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-memwaste-scaling-linux-${{ github.ref }}- + ccache-memwaste-scaling-linux- - name: CPU scaling lane (src/ at 2x against 4x) # Report-only: the script exits 1 when it flags a super-linear function. continue-on-error: true + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1500M run: | # `cmd | tee` reports TEE's status: without this a failing lane # (a missing exec bit, a build error) passes the step and only diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 48e4533ea2..9c4b3178ad 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -204,6 +204,11 @@ jobs: - name: Install ccache (macOS) if: startsWith(matrix.os, 'macos') + env: + HOMEBREW_NO_AUTO_UPDATE: "1" + HOMEBREW_NO_INSTALL_CLEANUP: "1" + HOMEBREW_NO_ENV_HINTS: "1" + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "1" run: command -v ccache >/dev/null 2>&1 || brew install ccache # Verified compiler cache: CCACHE_COMPILERCHECK=content keys every entry @@ -315,6 +320,14 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/internal/cbm/vendored/ + !/tools/ + !/graph-ui/ - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 with: @@ -347,10 +360,19 @@ jobs: timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/internal/cbm/vendored/ + !/tools/ - uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7.2.0 with: node-version: "22" + cache: npm + cache-dependency-path: graph-ui/package-lock.json - name: CodeAtlasWeb leg (install, unit, style, promises, acceptance, build) env: @@ -360,6 +382,9 @@ jobs: # the whole leg whenever NuGet is unreachable. Its own switch skips it # (the Nix flake sets the same). ONNXRUNTIME_NODE_INSTALL: skip + # Hosted Ubuntu runners intermittently advertise unreachable IPv6 + # routes to registry.npmjs.org (ENETUNREACH); prefer IPv4 first. + NODE_OPTIONS: "--dns-result-order=ipv4first" run: scripts/ci/test-ui.sh # ThreadSanitizer data-race gate. The threaded production surfaces (watcher, @@ -502,7 +527,18 @@ jobs: # runner drew the 23 bottle, and passed on the ones that drew 22). A # test verdict must be a function of the code, not of the image snapshot; # moving to a newer major is a deliberate one-line bump here. + - name: Homebrew bottle cache + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/Library/Caches/Homebrew + key: brew-lsan-llvm22-macos-arm64-v1 + - name: Install LSan-capable toolchain + env: + HOMEBREW_NO_AUTO_UPDATE: "1" + HOMEBREW_NO_INSTALL_CLEANUP: "1" + HOMEBREW_NO_ENV_HINTS: "1" + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "1" run: brew install llvm@22 ccache - name: Compiler cache (content-verified, restore) @@ -557,7 +593,12 @@ jobs: - name: Install deps (macOS) if: runner.os == 'macOS' - run: brew install ccache + env: + HOMEBREW_NO_AUTO_UPDATE: "1" + HOMEBREW_NO_INSTALL_CLEANUP: "1" + HOMEBREW_NO_ENV_HINTS: "1" + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "1" + run: command -v ccache >/dev/null 2>&1 || brew install ccache - name: Compiler cache (content-verified) uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 @@ -749,6 +790,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: path: repo + sparse-checkout: scripts/ci - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: diff --git a/.github/workflows/cache-warm.yml b/.github/workflows/cache-warm.yml index 736ce0ef02..3fb8d57f05 100644 --- a/.github/workflows/cache-warm.yml +++ b/.github/workflows/cache-warm.yml @@ -52,14 +52,14 @@ jobs: ccache-test-${{ matrix.os }}-${{ matrix.cc }}-${{ github.ref }}- ccache-test-${{ matrix.os }}-${{ matrix.cc }}- - - name: Build (test runner + product, no tests) + - name: Build (test runner + product with test seams, no tests) run: | source scripts/env.sh make -j"$(getconf _NPROCESSORS_ONLN)" -f Makefile.cbm \ - build/c/test-runner cbm CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} + build/c/test-runner cbm TEST_SEAMS=1 CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M - name: ccache stats run: ccache -sv || ccache -s @@ -103,13 +103,13 @@ jobs: ccache-test-windows-latest-CLANG64-${{ github.ref }}- ccache-test-windows-latest-CLANG64- - - name: Build (test runner + product, no tests) + - name: Build (test runner + product with test seams, no tests) run: | source scripts/env.sh - make -j"$(nproc)" -f Makefile.cbm build/c/test-runner cbm CC=clang CXX=clang++ + make -j"$(nproc)" -f Makefile.cbm build/c/test-runner cbm TEST_SEAMS=1 CC=clang CXX=clang++ env: CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1500M + CCACHE_MAXSIZE: 2500M - name: ccache stats run: ccache -sv || ccache -s diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ac0f9d9a95..6930a971c5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -87,16 +87,48 @@ jobs: # only what a traced compiler invocation actually compiles. CBM_NO_CCACHE: "1" steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Checkout (c-cpp) + if: ${{ matrix.language == 'c-cpp' }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # The PR scan reads the merge commit's first parent (the base) to # find the vendored files the PR changes. fetch-depth: ${{ inputs.light && 2 || 1 }} + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/tools/ + + - name: Checkout (non-C languages) + if: ${{ matrix.language != 'c-cpp' }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 1 + filter: blob:none + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/internal/cbm/vendored/ + !/tools/ - name: Install build dependencies if: ${{ matrix.language == 'c-cpp' }} timeout-minutes: 10 - run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev + run: APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev ccache + + # Compiler cache ONLY for the untraced vendored prebuild below; the traced + # CodeQL build step keeps job-level CBM_NO_CCACHE=1 so every traced unit + # actually invokes the compiler. + - name: Compiler cache for untraced third-party prebuild + if: ${{ matrix.language == 'c-cpp' && inputs.light }} + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-codeql-vendored-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ccache-codeql-vendored-${{ github.ref }}- + ccache-codeql-vendored- # PR c-cpp: compile the third-party objects (tree-sitter grammars, # sqlite, mimalloc, lz4, zstd, the tree-sitter runtime: ~1.3 GB of @@ -104,6 +136,10 @@ jobs: # traced build below compiles first-party code only ... - name: Build third-party objects (PR scan, untraced) if: ${{ matrix.language == 'c-cpp' && inputs.light }} + env: + CBM_NO_CCACHE: "0" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1500M run: scripts/build.sh --vendored-only # ... except the vendored files this PR changes: those are rebuilt @@ -132,6 +168,8 @@ jobs: uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4 with: category: "/language:${{ matrix.language }}" + upload-database: ${{ !inputs.light }} + wait-for-processing: true # Alert policy: the default branch carries ZERO open code-scanning # alerts. Any open alert on the analysed ref fails this leg: on main the diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 653529878f..1ef3524828 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -75,8 +75,24 @@ jobs: persist-credentials: false - name: Check out the merge base's selection tooling run: git worktree add --detach "$RUNNER_TEMP/base-tooling" HEAD^1 - - name: Build the merge base's engine + - name: Fetch the merge base's engine (verified main artifact) + id: engine + env: + GH_TOKEN: ${{ github.token }} + run: | + base_sha="$(git rev-parse HEAD^1)" + if "$RUNNER_TEMP/base-tooling/scripts/ci/test-impact-bundle.sh" --fetch-engine "$base_sha" "$RUNNER_TEMP/base-tooling/build/c"; then + echo "hit=true" >> "$GITHUB_OUTPUT" + else + echo "hit=false" >> "$GITHUB_OUTPUT" + fi + - name: Build the merge base's engine (fallback when no main artifact exists) + if: ${{ steps.engine.outputs.hit != 'true' }} timeout-minutes: 20 + env: + # Never use ccache in select-tests: the merge-base engine must come + # solely from a verified main artifact or a clean base-tooling build. + CBM_NO_CCACHE: "1" run: | APT_RETRIES=3; [ -f /etc/apt/apt-mirrors.txt ] && APT_RETRIES=0; sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 --error-on=any update && sudo apt-get -o Acquire::Retries=$APT_RETRIES -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y zlib1g-dev cd "$RUNNER_TEMP/base-tooling" diff --git a/.github/workflows/test-impact-artifact.yml b/.github/workflows/test-impact-artifact.yml index a0a53061c5..bf0e118ef1 100644 --- a/.github/workflows/test-impact-artifact.yml +++ b/.github/workflows/test-impact-artifact.yml @@ -86,3 +86,21 @@ jobs: include-hidden-files: true # the graph lives in .codebase-memory/ retention-days: 30 if-no-files-found: error + + # Publish the main-built selection engine binary alongside its SHA-256 + # receipt so PR select-tests can fetch a provenance-verified base engine + # directly from this main workflow run (no PR cache scope, no ccache). + - name: Stage the main selection engine artifact + run: | + mkdir -p "$RUNNER_TEMP/engine" + cp build/c/codebase-memory-mcp "$RUNNER_TEMP/engine/codebase-memory-mcp" + digest="$(sha256sum "$RUNNER_TEMP/engine/codebase-memory-mcp" | awk '{print $1}')" + printf '{"commit":"%s","sha256":"%s"}\n' "${{ github.sha }}" "$digest" > "$RUNNER_TEMP/engine/engine.json" + + - name: Upload the main selection engine + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: test-impact-engine-${{ github.sha }} + path: ${{ runner.temp }}/engine + retention-days: 30 + if-no-files-found: error diff --git a/scripts/ci/test-impact-bundle.sh b/scripts/ci/test-impact-bundle.sh index bc83e01a09..ef2441b65b 100755 --- a/scripts/ci/test-impact-bundle.sh +++ b/scripts/ci/test-impact-bundle.sh @@ -12,7 +12,10 @@ # Download the bundle of SHA into DIR (created). Needs GH_TOKEN with # actions:read; $GH overrides the gh command, $GITHUB_REPOSITORY the # repository (OWNER/NAME). -# Exit: 0 = fetched and verified · 3 = no admissible bundle for SHA · +# scripts/ci/test-impact-bundle.sh --fetch-engine SHA DIR +# Download the main-built selection engine binary for SHA into DIR and +# verify its commit and SHA-256 against the producer's engine.json. +# Exit: 0 = fetched and verified · 3 = no admissible artifact for SHA · # 1 = the tooling broke · 2 = usage error. set -euo pipefail @@ -20,9 +23,19 @@ GH="${GH:-gh}" REPO="${GITHUB_REPOSITORY:-DeusData/codebase-memory-mcp}" WORKFLOW="test-impact-artifact.yml" -usage() { sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//'; } +usage() { sed -n '2,23p' "$0" | sed 's/^# \{0,1\}//'; } -[ $# -eq 3 ] && [ "$1" = "--fetch" ] || { usage >&2; exit 2; } +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then + usage + exit 0 +fi + +[ $# -eq 3 ] || { usage >&2; exit 2; } +MODE="$1" +case "$MODE" in + --fetch | --fetch-engine) ;; + *) usage >&2; exit 2 ;; +esac SHA="$2" DIR="$3" case "$SHA" in @@ -45,6 +58,37 @@ if [ -z "$run" ]; then exit 3 fi mkdir -p "$DIR" +if [ "$MODE" = "--fetch-engine" ]; then + if ! "$GH" run download "$run" --repo "$REPO" --name "test-impact-engine-$SHA" --dir "$DIR"; then + echo "test-impact-bundle: run $run has no artifact test-impact-engine-$SHA" >&2 + exit 3 + fi + if ! python3 - "$DIR/engine.json" "$DIR/codebase-memory-mcp" "$SHA" <<'PY' +import hashlib, json, os, sys +meta_path, bin_path, want_sha = sys.argv[1], sys.argv[2], sys.argv[3] +if not os.path.isfile(meta_path) or not os.path.isfile(bin_path): + sys.exit(1) +meta = json.load(open(meta_path, encoding="utf-8")) +if meta.get("commit") != want_sha: + sys.exit(1) +want_digest = meta.get("sha256", "") +if not isinstance(want_digest, str) or len(want_digest) != 64: + sys.exit(1) +h = hashlib.sha256() +with open(bin_path, "rb") as f: + for chunk in iter(lambda: f.read(1 << 20), b""): + h.update(chunk) +sys.exit(0 if h.hexdigest() == want_digest else 1) +PY + then + rm -f "$DIR/codebase-memory-mcp" + echo "test-impact-bundle: engine metadata or SHA-256 verification failed for $SHA" >&2 + exit 3 + fi + chmod +x "$DIR/codebase-memory-mcp" + echo "test-impact-bundle: run $run, verified engine of $SHA in $DIR" + exit 0 +fi if ! "$GH" run download "$run" --repo "$REPO" --name "test-impact-$SHA" --dir "$DIR"; then echo "test-impact-bundle: run $run has no artifact test-impact-$SHA" >&2 exit 3 diff --git a/scripts/smoke-local.sh b/scripts/smoke-local.sh index 888348ae9c..19ded7bd95 100755 --- a/scripts/smoke-local.sh +++ b/scripts/smoke-local.sh @@ -131,9 +131,10 @@ fi # Member set and ORDER mirror scripts/package-release.sh (the Windows # single-binary contract locks that order); a fixture with a different inventory -# would smoke a release layout we never ship. +# would smoke a release layout we never ship. Use fast gzip level 1 for the +# ephemeral local fixture archive (~5-8x faster compression on ~300 MB binaries). EXPECTED_ARTIFACT="codebase-memory-mcp-${OS}-${ARCH}.tar.gz" -tar -czf "$FIXTURE_DIR/$EXPECTED_ARTIFACT" -C "$FIXTURE_DIR" \ +COPYFILE_DISABLE=1 GZIP=-1 tar -czf "$FIXTURE_DIR/$EXPECTED_ARTIFACT" -C "$FIXTURE_DIR" \ codebase-memory-mcp LICENSE install.sh THIRD_PARTY_NOTICES.md # Linux install/update resolves the portable release asset even when this local diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.sh index 8a9017495e..5faec3c6d6 100755 --- a/scripts/smoke-test.sh +++ b/scripts/smoke-test.sh @@ -110,10 +110,15 @@ smoke_rmtree() { } # Every platform ships ONE binary, Windows included: a fixture copy is complete -# with nothing beside it. +# with nothing beside it. Prefer copy-on-write clones where supported (APFS / +# Btrfs / XFS) to avoid repeatedly copying ~300 MB binaries during smoke runs. copy_smoke_binary() { local destination="$1" - cp "$BINARY" "$destination" + if [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then + cp -c "$BINARY" "$destination" 2>/dev/null || cp "$BINARY" "$destination" + else + cp --reflink=auto "$BINARY" "$destination" 2>/dev/null || cp "$BINARY" "$destination" + fi } # A fixture home that belongs to a Claude Code user. An empty ~/.claude is not @@ -651,6 +656,12 @@ fi rm -rf "$CFG_HOME" echo "OK: config get returns defaults and errors on unknown keys" +# Keep a warm account daemon across Phases 3b-5 (all use the main smoke cache +# namespace) so ~25 sequential CLI/MCP probes reuse one daemon instead of +# paying 2-3 s of cold bootstrap + self-image hashing per command. Phases 1b, +# 2, 3z3, 6-14, 15, and 16 still run cold; retired cleanly before Phase 6. +"$BINARY" daemon start >/dev/null 2>&1 || true + echo "OK: search_graph found $TOTAL result(s) for 'compute'" # 3b: trace_path — verify compute has callers @@ -1191,6 +1202,8 @@ echo "OK: Content-Length framing works (OpenCode compatible)" rm -f "$MCP_CL_INPUT" "$MCP_CL_OUTPUT" "$MCP_TOOL_OUTPUT" +retire_account_daemon "phase5-warm-cleanup" + echo "" echo "=== Phase 6: CLI subcommands ===" @@ -3750,18 +3763,11 @@ if [ -n "${SMOKE_DOWNLOAD_URL:-}" ]; then # copy is immediately able to render and remove its own integrations. if [[ "$BINARY" == *.exe ]]; then cp "$BINARY" "$UPDATE_HOME/.local/bin/codebase-memory-mcp.exe" - mkdir -p "$UPDATE_HOME/retired-install" - cp "$BINARY" "$UPDATE_HOME/retired-install/codebase-memory-mcp.exe" else - cp "$BINARY" "$UPDATE_HOME/.local/bin/codebase-memory-mcp" + copy_smoke_binary "$UPDATE_HOME/.local/bin/codebase-memory-mcp" chmod 755 "$UPDATE_HOME/.local/bin/codebase-memory-mcp" - mkdir -p "$UPDATE_HOME/retired-install" - cp "$BINARY" "$UPDATE_HOME/retired-install/codebase-memory-mcp" - chmod 755 "$UPDATE_HOME/retired-install/codebase-memory-mcp" if [ "$(uname -s)" = "Darwin" ]; then codesign --sign - --force "$UPDATE_HOME/.local/bin/codebase-memory-mcp" 2>/dev/null || true - codesign --sign - --force "$UPDATE_HOME/retired-install/codebase-memory-mcp" \ - 2>/dev/null || true fi fi @@ -4223,30 +4229,58 @@ UI_PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0 # the UI does not pin the process, so stdio EOF ends it cleanly (rc=0) before # the poll can see it serve — the drive-listing guard holds a pipe for the # same reason. Equals-form flags match that guard's proven invocation. -sleep 300 | "$BINARY" --ui=true --port="$UI_PORT" > /dev/null 2>&1 & +# Track the stdin-holder sleep PID so cleanup stops it immediately instead of +# leaving `wait "$UI_PID"` blocked for the full 300 s sleep after the server +# exits or is killed. +UI_SLEEP_PID_FILE=$(smoke_mktemp_file) +UI_STDERR_FILE=$(smoke_mktemp_file) +rm -f "$UI_SLEEP_PID_FILE" +( + sleep 300 & + echo "$!" > "$UI_SLEEP_PID_FILE" + wait +) | "$BINARY" --ui=true --port="$UI_PORT" > /dev/null 2>"$UI_STDERR_FILE" & UI_PID=$! -# Readiness poll instead of a fixed sleep: SKIP is legitimate ONLY when the -# process exited (the documented no-embedded-assets case); a slow start on a -# loaded runner must not masquerade as it. The UI binds ~6s after launch even -# on a fast host (measured against the release artifact), so the window -# matches the drive-listing guard's 25s, not a 10s sprint. + +stop_ui_server() { + kill "$UI_PID" 2>/dev/null || true + if [ -s "$UI_SLEEP_PID_FILE" ]; then + kill "$(cat "$UI_SLEEP_PID_FILE")" 2>/dev/null || true + fi + wait "$UI_PID" 2>/dev/null || true + rm -f "$UI_SLEEP_PID_FILE" "$UI_STDERR_FILE" +} + +# Readiness poll with a real 30 s wall-clock deadline (not an iteration count: +# on Windows a refused localhost connect takes ~2 s, turning 150 iterations +# into 300 s). SKIP is legitimate ONLY when the process exited or serves no +# embedded UI; a slow start on a loaded runner still gets the full 30 s window. +# When SMOKE_REQUIRE_UI != 1 and the binary already logged that it was built +# without UI support, stop polling immediately instead of waiting out 30 s. UI_READY=0 -for _ in $(seq 1 150); do +UI_DEADLINE=$((SECONDS + 30)) +while [ "$SECONDS" -lt "$UI_DEADLINE" ]; do if ! kill -0 "$UI_PID" 2>/dev/null; then break; fi - if curl --noproxy '*' -sf "http://127.0.0.1:$UI_PORT/" -o /dev/null 2>/dev/null; then UI_READY=1; break; fi + if [ "$SMOKE_REQUIRE_UI" != "1" ] && grep -qi "without UI support" "$UI_STDERR_FILE" 2>/dev/null; then + break + fi + if curl --noproxy '*' --connect-timeout 1 --max-time 2 -sf "http://127.0.0.1:$UI_PORT/" -o /dev/null 2>/dev/null; then UI_READY=1; break; fi sleep 0.2 done if [ "$UI_READY" -eq 1 ] || kill -0 "$UI_PID" 2>/dev/null; then # 15a: GET / returns 200 with HTML content - UI_BODY=$(curl --noproxy '*' -sf "http://127.0.0.1:$UI_PORT/" 2>/dev/null || echo "") + UI_BODY=$(curl --noproxy '*' --connect-timeout 1 --max-time 2 -sf "http://127.0.0.1:$UI_PORT/" 2>/dev/null || echo "") if echo "$UI_BODY" | grep -qi "/dev/null || true + stop_ui_server exit 1 fi @@ -4255,20 +4289,23 @@ if [ "$UI_READY" -eq 1 ] || kill -0 "$UI_PID" 2>/dev/null; then # old probe POSTed an MCP initialize at /rpc, but the UI's /rpc speaks the # UI's own narrow query protocol, not MCP — the probe asserted a request # the endpoint never answered; protocol depth belongs to the UI guards.) - RPC_BODY=$(curl --noproxy '*' -sf "http://127.0.0.1:$UI_PORT/api/ui-config" 2>/dev/null || echo "") + RPC_BODY=$(curl --noproxy '*' --connect-timeout 1 --max-time 2 -sf "http://127.0.0.1:$UI_PORT/api/ui-config" 2>/dev/null || echo "") if echo "$RPC_BODY" | grep -q "{"; then echo "OK 15b: /api/ui-config returns JSON" elif [ -z "$RPC_BODY" ]; then + if [ "$SMOKE_REQUIRE_UI" = "1" ]; then + stop_ui_server + fi smoke_ui_missing "15b" "/api/ui-config not reachable" else echo "FAIL 15b: /api/ui-config did not return JSON" - kill "$UI_PID" 2>/dev/null || true + stop_ui_server exit 1 fi - kill "$UI_PID" 2>/dev/null || true - wait "$UI_PID" 2>/dev/null || true + stop_ui_server else + stop_ui_server smoke_ui_missing "Phase 15" "binary exited immediately (no UI assets embedded)" fi diff --git a/scripts/smoke-wrappers.sh b/scripts/smoke-wrappers.sh index 99a385ea26..23f359cd22 100644 --- a/scripts/smoke-wrappers.sh +++ b/scripts/smoke-wrappers.sh @@ -155,12 +155,47 @@ smoke_go() { ran go "$dir/run.log" "$rc" } -for wrapper in "${WRAPPERS[@]}"; do - case "$wrapper" in - npm) smoke_npm ;; - pypi) smoke_pypi ;; - go) smoke_go ;; - *) echo "unknown wrapper: $wrapper" >&2; exit 2 ;; - esac -done +# Each wrapper uses its own isolated workdir ($WORK/) and talks to the +# multi-threaded smoke fixture server; run them concurrently when multiple +# wrappers are selected. +if [ "${#WRAPPERS[@]}" -le 1 ]; then + for wrapper in "${WRAPPERS[@]}"; do + case "$wrapper" in + npm) smoke_npm ;; + pypi) smoke_pypi ;; + go) smoke_go ;; + *) echo "unknown wrapper: $wrapper" >&2; exit 2 ;; + esac + done +else + PIDS=() + NAMES=() + for wrapper in "${WRAPPERS[@]}"; do + case "$wrapper" in + npm|pypi|go) ;; + *) echo "unknown wrapper: $wrapper" >&2; exit 2 ;; + esac + done + for wrapper in "${WRAPPERS[@]}"; do + ( + FAILED=0 + case "$wrapper" in + npm) smoke_npm ;; + pypi) smoke_pypi ;; + go) smoke_go ;; + esac + exit "$FAILED" + ) >"$WORK/$wrapper.out" 2>&1 & + PIDS+=("$!") + NAMES+=("$wrapper") + done + for i in "${!PIDS[@]}"; do + wrc=0 + wait "${PIDS[$i]}" || wrc=$? + cat "$WORK/${NAMES[$i]}.out" + if [ "$wrc" -ne 0 ]; then + FAILED=1 + fi + done +fi exit "$FAILED"