diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78586a96d..fc40a3a89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,8 @@ env: jobs: microkernel: uses: ./.github/workflows/core-protocol.yml + with: + split_rust_targets: true web: name: Web checks and production build runs-on: ubuntu-24.04 diff --git a/.github/workflows/core-protocol.yml b/.github/workflows/core-protocol.yml index 371961fd6..6af424493 100644 --- a/.github/workflows/core-protocol.yml +++ b/.github/workflows/core-protocol.yml @@ -2,7 +2,12 @@ name: Microkernel implementation checks on: workflow_dispatch: workflow_call: -# ci.yml owns automatic push/PR runs so this expensive suite runs only once. + inputs: + split_rust_targets: + description: Run unit and integration targets on separate PostgreSQL services. + type: boolean + default: false +# Manual qualification keeps a single runner and the full Cargo target set. permissions: contents: read defaults: @@ -13,11 +18,17 @@ concurrency: cancel-in-progress: true jobs: protocol: + name: ${{ matrix.targets == 'integration' && 'Rust integration targets' || 'protocol' }} + strategy: + fail-fast: false + matrix: + targets: ${{ fromJSON(inputs.split_rust_targets && '["unit","integration"]' || '["all"]') }} runs-on: ubuntu-24.04 # Budget for cold builds, serial real PostgreSQL tests, and the following # payment, Go, and RPC checks while keeping the complete job bounded. timeout-minutes: 150 env: + RUST_TARGET_GROUP: ${{ matrix.targets }} GOWORK: "off" DATABASE_URL: postgres://postgres:postgres@127.0.0.1:5432/postgres CARGO_BUILD_JOBS: "2" @@ -76,7 +87,7 @@ jobs: - name: Preserve source before checks uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with: - name: microkernel-source-${{ github.sha }}-${{ github.run_id }} + name: microkernel-source-${{ github.sha }}-${{ github.run_id }}${{ matrix.targets == 'integration' && '-integration' || '' }} path: | ${{ runner.temp }}/core-source.tar.gz ${{ runner.temp }}/core-source-sha.txt @@ -196,7 +207,7 @@ jobs: if: ${{ !cancelled() && steps.rust_test_compile.outcome == 'success' }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with: - name: commerce-acceptance-driver-${{ github.sha }}-${{ github.run_id }} + name: commerce-acceptance-driver-${{ github.sha }}-${{ github.run_id }}${{ matrix.targets == 'integration' && '-integration' || '' }} path: ${{ runner.temp }}/commerce-acceptance-driver if-no-files-found: error compression-level: 0 @@ -232,9 +243,15 @@ jobs: LMM_PAYMENT_BOOTSTRAP_SHA256="$(sha256sum "$LMM_PAYMENT_BOOTSTRAP_BIN" | cut -d ' ' -f1)" export LMM_PAYMENT_CORE_BIN LMM_PAYMENT_CORE_SHA256 LMM_PAYMENT_GO_BIN LMM_PAYMENT_GO_SHA256 LMM_PAYMENT_BOOTSTRAP_BIN LMM_PAYMENT_BOOTSTRAP_SHA256 # Emit panic diagnostics immediately, including when the job times out. - cargo test --locked --all-targets --no-fail-fast -- --skip synthetic_live_proof_crosses_core_go_processes_and_posts_once --nocapture 2>&1 | tee "$RUNNER_TEMP/core-tests.log" + case "$RUST_TARGET_GROUP" in + all) targets=(--all-targets) ;; + unit) targets=(--lib --bins --examples --benches) ;; + integration) targets=(--test '*') ;; + *) echo "Unknown Rust target group: $RUST_TARGET_GROUP" >&2; exit 1 ;; + esac + cargo test --locked "${targets[@]}" --no-fail-fast -- --skip synthetic_live_proof_crosses_core_go_processes_and_posts_once --nocapture 2>&1 | tee "$RUNNER_TEMP/core-tests.log" - name: Repeat rejected event acknowledgement regression - if: ${{ !cancelled() && steps.rust_test_compile.outcome == 'success' }} + if: ${{ !cancelled() && matrix.targets != 'integration' && steps.rust_test_compile.outcome == 'success' }} working-directory: services/core run: | for attempt in {1..10}; do @@ -245,7 +262,7 @@ jobs: if: ${{ !cancelled() }} run: python3 -B scripts/ci-payment-live.py --output "$(realpath -m "$RUNNER_TEMP/payment-live")" 2>&1 | tee "$RUNNER_TEMP/payment-live-build.log" - name: Go contract and race tests - if: ${{ !cancelled() }} + if: ${{ !cancelled() && matrix.targets != 'integration' }} working-directory: services/extensions run: | bash ../../scripts/check-go-format.sh . @@ -254,7 +271,7 @@ jobs: go test -race ./... -count=1 -json | tee "$RUNNER_TEMP/extension-tests.jsonl" CGO_ENABLED=0 go build -mod=readonly -trimpath -o "$RUNNER_TEMP/lmm-extensions" ./cmd/extensions - name: Store and support real PostgreSQL acceptance - if: ${{ !cancelled() }} + if: ${{ !cancelled() && matrix.targets != 'integration' }} env: LMM_STORE_TEST_DSN: postgres://postgres:postgres@127.0.0.1:5432/lmm_store_test?sslmode=disable run: | @@ -265,13 +282,13 @@ jobs: go vet -mod=readonly ./... go test -mod=readonly -race -count=1 -json ./... | tee "$RUNNER_TEMP/store-postgres.jsonl" - name: Durable cross-language event process recovery - if: ${{ !cancelled() }} + if: ${{ !cancelled() && matrix.targets != 'integration' }} run: | (cd services/core && cargo build --locked --example protocol-events-fixture) (cd contracts/proto/tests/go && go vet -mod=readonly ./... && go build -mod=readonly -o "$RUNNER_TEMP/mk06-go-fixture" .) MK06_GO_FIXTURE="$RUNNER_TEMP/mk06-go-fixture" python3 contracts/proto/tests/process_recovery.py 2>&1 | tee "$RUNNER_TEMP/events-process.log" - name: Native protobuf round trips and failure recovery - if: ${{ !cancelled() }} + if: ${{ !cancelled() && matrix.targets != 'integration' }} run: | # Absolute, symlink-free, and absent: the fixture creates a private empty 0700 root. evidence="$(realpath -m -- "$RUNNER_TEMP/core-rpc-docker-evidence")" @@ -281,7 +298,7 @@ jobs: fi python3 -B scripts/test-core-rpc-docker.py --output-root "$evidence" --build-timeout-seconds 2400 2>&1 | tee "$RUNNER_TEMP/core-rpc-docker.log" - name: Stage readable core RPC evidence - if: ${{ always() }} + if: ${{ always() && matrix.targets != 'integration' }} run: | # Secret files are chowned to container uid 65532 and mode 0400. # upload-artifact fails the whole zip if any selected file is unreadable. @@ -313,7 +330,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with: - name: microkernel-checks-${{ github.sha }}-${{ github.run_id }} + name: microkernel-checks-${{ github.sha }}-${{ github.run_id }}${{ matrix.targets == 'integration' && '-integration' || '' }} path: | ${{ runner.temp }}/core-source-sha.txt ${{ runner.temp }}/core-format.log diff --git a/.github/workflows/linux-packages.yml b/.github/workflows/linux-packages.yml index 4c00cfbc3..98aa117a6 100644 --- a/.github/workflows/linux-packages.yml +++ b/.github/workflows/linux-packages.yml @@ -82,6 +82,7 @@ jobs: git rev-parse HEAD | tee out/evidence/revision.txt nfpm --version | tee out/evidence/nfpm-version.txt node --test scripts/workflow-topology.test.mjs + python3 -B packaging/linux/test_extore_receipts.py python3 -B packaging/linux/test_native.py -v 2>&1 | tee out/evidence/native-tests.log go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color .github/workflows/linux-packages.yml - name: Build the three product binaries for this architecture @@ -99,6 +100,7 @@ jobs: docker buildx build --platform "linux/$ARCH" -f deployment/docker/extensions.Dockerfile \ --target binaries-musl --output type=local,dest=out/extensions-musl . - name: Build verified source archives and native packages + id: packages run: | revision=$(git rev-parse HEAD) SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD) @@ -109,6 +111,7 @@ jobs: done python3 scripts/build-distribution.py build --component extensions \ --version 0.1.0-preview --revision "$revision" --platform "linux-musl-$ARCH" --input out/extensions-musl + package_paths=() for component in core extensions cli; do package="lmm-$component" if [[ "$component" == cli ]]; then package=lmm; fi @@ -118,12 +121,19 @@ jobs: archive="out/distributions/${package}-0.1.0-preview-${platform}.tar.gz" digest=$(sha256sum "$archive" | cut -d ' ' -f 1) for release in 1 2; do - python3 packaging/linux/build.py --archive "$archive" --sha256 "$digest" \ - --revision "$revision" --component "$component" --format "$format" --release "$release" + built=$(python3 packaging/linux/build.py --archive "$archive" --sha256 "$digest" \ + --revision "$revision" --component "$component" --format "$format" --release "$release") + package_paths+=("$built" "$built.sha256" "$built.buildinfo.json") done done done (cd out/linux-packages && sha256sum --check ./*.sha256) + for path in "${package_paths[@]}"; do test -s "$path"; done + { + echo 'paths<> "$GITHUB_OUTPUT" - name: Install, upgrade, run and remove in disposable distribution containers run: | set -o pipefail @@ -159,23 +169,39 @@ jobs: -f packages/extore/tests/native_plugin_alpine.Dockerfile --target fixture \ --build-arg "EXTORE_RUST_TARGET=$RUST_TARGET" -t lmm-extore-alpine-fixture packages/extore docker image inspect lmm-extore-alpine-fixture --format '{{.Id}}' > out/evidence/extore-fixture-image.txt + umask 077 + staging=$(mktemp -d "$RUNNER_TEMP/extore-receipts.XXXXXXXX") + report=extore-native-alpine.json + touch "$staging/$report" "$staging/$report.package.json" timeout 300 docker run --rm --network none --add-host localhost.localdomain:127.0.0.1 \ --cap-add NET_ADMIN --cpus 1 --memory 768m --pids-limit 256 \ --security-opt no-new-privileges:true -e LMM_PACKAGING_ISOLATED=1 \ -v "$PWD/out/linux-packages:/packages:ro" -v "$PWD/out/native-probe:/probe:ro" \ - -v "$PWD/out/evidence:/evidence" \ + -v "$staging/$report:/receipts/$report" \ + -v "$staging/$report.package.json:/receipts/$report.package.json" \ -v "$PWD/packaging/linux/extore-plugin-smoke.py:/package-probe.py:ro" \ --entrypoint python3 lmm-extore-alpine-fixture /package-probe.py \ --arch "$ARCH" --revision "$(git rev-parse HEAD)" \ --parent-netns "$(readlink /proc/self/ns/net)" \ - --report /evidence/extore-native-alpine.json 2>&1 | tee out/evidence/extore-native-alpine.log + --report "/receipts/$report" > "$staging/fixture.log" 2>&1 + for receipt in "$staging/$report" "$staging/$report.package.json"; do + test -s "$receipt" + test -O "$receipt" + done + mv -- "$staging/$report" "$staging/$report.package.json" out/evidence/ - name: Preserve preview packages and scoped evidence, never publish if: always() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with: name: native-linux-${{ matrix.arch }}-${{ github.sha }} path: | - out/linux-packages/ - out/evidence/ + ${{ steps.packages.outputs.paths }} + out/evidence/revision.txt + out/evidence/nfpm-version.txt + out/evidence/install-matrix.txt + out/evidence/image-digests.txt + out/evidence/extore-fixture-image.txt + out/evidence/extore-native-alpine.json + out/evidence/extore-native-alpine.json.package.json if-no-files-found: error retention-days: 7 diff --git a/.github/workflows/mk-01-identity.yml b/.github/workflows/mk-01-identity.yml index 7c9a53123..f33551f84 100644 --- a/.github/workflows/mk-01-identity.yml +++ b/.github/workflows/mk-01-identity.yml @@ -19,3 +19,5 @@ jobs: identity: # All merged modules use the same preserved executors and private fixtures. uses: ./.github/workflows/core-protocol.yml + with: + split_rust_targets: true diff --git a/packaging/linux/extore-plugin-smoke.py b/packaging/linux/extore-plugin-smoke.py index 35fc2a06b..22d97a4db 100644 --- a/packaging/linux/extore-plugin-smoke.py +++ b/packaging/linux/extore-plugin-smoke.py @@ -14,6 +14,34 @@ import urllib.request +def probe_receipt(report, host_sha256, plugin_sha256): + """Export only reviewed acceptance facts from the private probe report.""" + def confirmed(actual, expected): + for key, value in expected.items(): + if type(actual.get(key)) is not type(value) or actual[key] != value: + raise ValueError(f"unconfirmed native acceptance field: {key}") + return {key: actual[key] for key in expected} + + receipt = confirmed(report, { + "status": "passed", "consumer_exit_code": 0, + "host_library_sha256": host_sha256, "plugin_library_sha256": plugin_sha256, + "actual_rust_health": True, "isolated_network_namespace": True, + "tls_certificate_verification": True, "authorized_catalog": True, + "cross_shop_http_detail_denied": True, "revoked_token_denied": True, + "catalog_calls_did_not_issue_cards": True, "actual_sqlite_grant_usage_recorded": True, + }) + receipt["consumer"] = confirmed(report["consumer"], { + "status": "passed", "host_abi": 1, "interface": "extore.commerce", + "real_extore_https_sqlite": True, "native_digest_path_binding": True, + "native_repeated_open_call_release_close": True, "store_sync_persisted": True, + "http_catalog_fallback_calls": 0, "secret_values_logged": False, + "production_accounts_created": False, + "store_repository": "transactional memory test repository", + "core_authority": "existing Store test double; independent CoreSession acceptance not run", + }) + return receipt + + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--arch", choices=("amd64", "arm64"), required=True) @@ -104,7 +132,12 @@ def main(): time.sleep(0.1) if not ready: raise RuntimeError("installed extensions did not start without native configuration") - if os.readlink(f"/proc/{process.pid}/exe") != "/usr/bin/lmm-extensions": + # Procfs checks credentials; container root cannot inspect another UID. + identity = subprocess.run( + ["readlink", "-n", f"/proc/{process.pid}/exe"], + check=True, stdout=subprocess.PIPE, timeout=5, user=account.pw_uid, + group=account.pw_gid, extra_groups=[]) + if identity.stdout != b"/usr/bin/lmm-extensions": raise RuntimeError("default process is not the installed program") finally: process.terminate() @@ -127,15 +160,19 @@ def main(): "service_uid": account.pw_uid, "service_gid": account.pw_gid, "default_process_stopped": True, } + with tempfile.TemporaryDirectory(prefix="extore-private-probe-") as directory: + private_report = Path(directory) / "probe.json" + command = [sys.executable, "/work/tests/native_plugin_probe.py", + "--inside-netns", "--parent-netns", args.parent_netns, + "--binary", "/opt/extore/extore-server", + "--host-library", host, "--plugin-library", plugin, + "--report", str(private_report), "--consumer", str(args.consumer), + "-test.run", "^TestNativePluginCatalogStore$", "-test.v"] + subprocess.run(command, check=True) + accepted = probe_receipt(json.loads(private_report.read_text()), + info["files"][host]["sha256"], info["files"][plugin]["sha256"]) + args.report.write_text(json.dumps(accepted, indent=2) + "\n") Path(str(args.report) + ".package.json").write_text(json.dumps(receipt, indent=2) + "\n") - command = [sys.executable, "/work/tests/native_plugin_probe.py", - "--inside-netns", "--parent-netns", args.parent_netns, - "--binary", "/opt/extore/extore-server", - "--host-library", "/usr/lib/lmm/extensions/extore/libextore_plugin_host.so", - "--plugin-library", "/usr/lib/lmm/extensions/extore/libextore_commerce_plugin.so", - "--report", str(args.report), "--consumer", str(args.consumer), - "-test.run", "^TestNativePluginCatalogStore$", "-test.v"] - subprocess.run(command, check=True) if __name__ == "__main__": diff --git a/packaging/linux/test_extore_receipts.py b/packaging/linux/test_extore_receipts.py new file mode 100644 index 000000000..ebb8f6c83 --- /dev/null +++ b/packaging/linux/test_extore_receipts.py @@ -0,0 +1,47 @@ +"""Check the upload boundary with synthetic private probe output.""" +import runpy +import unittest +from pathlib import Path + + +probe_receipt = runpy.run_path(str(Path(__file__).with_name("extore-plugin-smoke.py")))["probe_receipt"] + + +class ProbeReceiptTests(unittest.TestCase): + def setUp(self): + self.host, self.plugin = "a" * 64, "b" * 64 + self.consumer = { + "status": "passed", "host_abi": 1, "interface": "extore.commerce", + "real_extore_https_sqlite": True, "native_digest_path_binding": True, + "native_repeated_open_call_release_close": True, "store_sync_persisted": True, + "http_catalog_fallback_calls": 0, "secret_values_logged": False, + "production_accounts_created": False, + "store_repository": "transactional memory test repository", + "core_authority": "existing Store test double; independent CoreSession acceptance not run", + } + self.report = { + "status": "passed", "consumer_exit_code": 0, "consumer": self.consumer, + "host_library_sha256": self.host, "plugin_library_sha256": self.plugin, + "actual_rust_health": True, "isolated_network_namespace": True, + "tls_certificate_verification": True, "authorized_catalog": True, + "cross_shop_http_detail_denied": True, "revoked_token_denied": True, + "catalog_calls_did_not_issue_cards": True, "actual_sqlite_grant_usage_recorded": True, + } + + def test_only_reviewed_fields_cross_the_boundary(self): + private = dict(self.report, stdout="private fixture output", + consumer=dict(self.consumer, credentials={"test": "private"})) + self.assertEqual(probe_receipt(private, self.host, self.plugin), self.report) + + def test_incomplete_failed_or_mistyped_facts_cannot_be_exported(self): + missing = self.report.copy() + del missing["consumer_exit_code"] + for raw in [missing, dict(self.report, status="failed"), dict(self.report, consumer_exit_code=False), + dict(self.report, host_library_sha256=self.plugin), + dict(self.report, consumer=dict(self.consumer, core_authority="unreviewed text"))]: + with self.subTest(raw=raw), self.assertRaises(ValueError): + probe_receipt(raw, self.host, self.plugin) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/workflow-topology.test.mjs b/scripts/workflow-topology.test.mjs index d01178071..bebad6fc6 100644 --- a/scripts/workflow-topology.test.mjs +++ b/scripts/workflow-topology.test.mjs @@ -390,6 +390,49 @@ test('Core CI uses the same pinned PostgreSQL catalog as the RPC fixture', () => }); +test('native package uploads keep raw Alpine fixture output private', () => { + const source = workflow('linux-packages'); + const upload = source.split(' - name: Preserve preview packages and scoped evidence, never publish\n')[1]; + const paths = upload?.match(/ path: \|\n((?: .+\n)+)/)?.[1]; + assert.ok(paths, 'the native package artifact must enumerate reviewed paths'); + assert.deepEqual(paths.trim().split('\n').map((path) => path.trim()), [ + '${{ steps.packages.outputs.paths }}', + 'out/evidence/revision.txt', + 'out/evidence/nfpm-version.txt', + 'out/evidence/install-matrix.txt', + 'out/evidence/image-digests.txt', + 'out/evidence/extore-fixture-image.txt', + 'out/evidence/extore-native-alpine.json', + 'out/evidence/extore-native-alpine.json.package.json', + ]); + assert.ok(source.includes('--report "/receipts/$report" > "$staging/fixture.log" 2>&1')); +}); + +test('automatic Core checks run both Cargo target groups on independent runners', () => { + const source = workflow('core-protocol'); + for (const caller of ['ci', 'mk-01-identity']) { + assert.match(workflow(caller), /uses: \.\/\.github\/workflows\/core-protocol\.yml\n with:\n split_rust_targets: true/); + } + assert.match(source, /split_rust_targets:[\s\S]*?type: boolean\n default: false/); + assert.match(source, /fail-fast: false\n matrix:\n targets: .*inputs\.split_rust_targets && '\["unit","integration"\]' \|\| '\["all"\]'/); + assert.ok(source.includes('RUST_TARGET_GROUP: ${{ matrix.targets }}')); + assert.match(source, /timeout-minutes: 150/); + assert.doesNotMatch(source, /continue-on-error:/); + const selector = source.match(/case "\$RUST_TARGET_GROUP" in[\s\S]*?\besac\b/)?.[0]; + assert.ok(selector); + function flags(group) { + return execFileSync('bash', ['-c', selector + '\nprintf "%s\\n" "${targets[@]}"'], { + env: { ...process.env, RUST_TARGET_GROUP: group }, + stdio: ['ignore', 'pipe', 'pipe'], + encoding: 'utf8', + }).trim().split('\n'); + } + assert.deepEqual(flags('all'), ['--all-targets']); + assert.deepEqual(flags('unit'), ['--lib', '--bins', '--examples', '--benches']); + assert.deepEqual(flags('integration'), ['--test', '*']); + assert.throws(() => flags('unknown'), { status: 1 }); +}); + test('Core CI freezes the process binary and private root before running all Rust tests', () => { const source = workflow('core-protocol'); const block = source.match(/ - name: Rust checks and real database tests\n([\s\S]*?)(?= - name:)/)?.[1]; @@ -410,7 +453,7 @@ test('Core CI freezes the process binary and private root before running all Rus const hash = block.indexOf('LMM_MODEL_PROCESS_CORE_SHA256="$(sha256sum "$LMM_MODEL_PROCESS_CORE_BIN"'); const root = block.indexOf('LMM_MODEL_PROCESS_ROOT="$(mktemp -d "$process_evidence_root/model-XXXXXXXX")"'); const exported = block.indexOf('export LMM_MODEL_PROCESS_CORE_BIN LMM_MODEL_PROCESS_CORE_SHA256 LMM_MODEL_PROCESS_ROOT'); - const execute = block.indexOf('cargo test --locked --all-targets --no-fail-fast'); + const execute = block.indexOf('cargo test --locked "${targets[@]}" --no-fail-fast'); assert.ok(binary >= 0 && hash > binary && root > hash && exported > root && execute > exported, 'freeze inputs after compiling, before executing'); // The separately required owning-runner step covers exactly this one case. @@ -424,7 +467,7 @@ test('Core CI isolates independent process evidence and cluster-wide role snapsh assert.match(source, /RUST_TEST_THREADS: "1"/); const block = source.match(/ - name: Rust checks and real database tests\n([\s\S]*?)(?= - name:)/)?.[1]; assert.ok(block); - const execute = block.indexOf('cargo test --locked --all-targets --no-fail-fast'); + const execute = block.indexOf('cargo test --locked "${targets[@]}" --no-fail-fast'); for (const name of [ 'LMM_CONTINUITY_DEV_ARTIFACTS', 'COMPACT_INDEPENDENT_ARTIFACTS',