diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 876da52..70f613f 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -128,6 +128,10 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - Added the `watch_wait` daemon request (`vbs daemon ide wait [--timeout-ms]`): a bounded long poll (0–5000 ms, default 2000) that returns buffered changes immediately or waits on the warm inotify watcher, then reports `changed`, `sequence`, `watch_events`, and `timed_out`. Because the daemon is single-threaded the wait is bounded; other requests queue behind it. - Added `Daemon.watch_wait_long_polls_until_change_and_times_out` (quiet timeout, then a writer thread wakes the poll) and a CLI help contract; Daemon suite is now 13 cases. +- **Wave 28 (Registry Binary-Variant Storage & Download Endpoints)**: + - `vbs-registry` now stores per-release binary variants (`BinaryReleaseMeta` in `ReleaseMeta`): `PUT /api/v1/packages///binaries/` (publish scope + CSRF, 128-byte bounded variant ids, upload/quota limits, optional `X-Binary-Signature`/`X-Binary-Public-Key` with 128/64-hex validation, idempotent same-digest and 409 immutable conflicts) and `GET .../binaries//download` (read permission, CAS integrity re-verification). Metadata persists in the registry database and is listed in package detail JSON. + - `RegistryTests.registry_binary_variant_publish_download_and_materialize`: unauthorized publish rejected, malformed signature rejected, signed artifact published and listed, downloaded byte-for-byte, conflicting digest rejected, and the registry-served artifact materialized through the signed `materialize_binary_variant` path. + ## Remaining future scope - **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, daemon-backed IDE metadata, compdb export, IDE config generation, editor watch poll and bounded long-poll done; dedicated external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 950e0b6..0e584a4 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -34,4 +34,5 @@ Base HEAD: `fe0d1a6` | Wave 25 (Track E3 daemon IDE generate) | `ide_generate` daemon request + `vbs daemon ide generate` CLI: lowers the graph, publishes compdb, writes editor presets, returns written/skipped lists | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 11/11, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 26 (Track E3 editor watch protocol) | `watch_poll` daemon request + `vbs daemon ide poll`: drains the warm watcher, buffers bounded changed paths, returns sequence/events/changed/overflow state | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 12/12, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 27 (Track E3 editor long-poll watch) | `watch_wait` daemon request + `vbs daemon ide wait --timeout-ms`: bounded 0-5000 ms long poll over the warm watcher returning changed paths/sequence/timed_out | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 13/13, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | +| Wave 28 (Registry binary-variant endpoints) | `BinaryReleaseMeta` storage, `PUT .../binaries/` + `GET .../binaries//download`, metadata persistence/detail listing, signature header validation, immutable conflicts | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry suite 6/6, full CTest 8/8) | `registry/include/Void/Build/Registry/RegistryService.hpp`, `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 0b81c05..d91a96b 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -507,6 +507,22 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - Full CTest: **8 / 8 passed** in 202.84 s. - `clang-format --dry-run --Werror` passes on the changed C++ files. +## Registry Binary-Variant Endpoints (GCC 16.2, pin `0002e74`, built-in Ed25519) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_registry_tests --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Registry suite: **6 / 6 passed** in 11.75 s, including + `registry_binary_variant_publish_download_and_materialize`: unauthenticated publish -> 401, + 127-hex signature header -> 400, signed artifact publish -> 201 and listed in package detail, + download returns the exact bytes, a different digest for the same variant -> 409, and the + registry-served artifact is materialized through the signed `materialize_binary_variant` path. +- Full CTest: **8 / 8 passed** in 223.58 s. +- `clang-format --dry-run --Werror` passes on the changed C++ files. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/21-expansion-roadmap.md b/docs/roadmap/21-expansion-roadmap.md index 737c8d6..70f0092 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -61,7 +61,7 @@ flowchart LR | --- | --- | --- | | **D1 — Shared HTTP Content-Addressed Action Cache (CAS)** *(verified: cross-build-directory 100% cache hit)* | Push/pull action records and output blobs (`PUT/GET /api/v1/cas/blobs/{sha256}`, `/api/v1/cas/actions/{action_key}`) against `vbs-registry` or any compatible HTTP CAS server with bearer auth and digest verification on every read. Action keys are normalized to be build-directory independent; `vbs build/test --remote-cache URL [--remote-cache-token-env VAR]` (or `VBS_REMOTE_CACHE` / `VBS_REMOTE_CACHE_TOKEN`). | Cold CI build populates remote CAS; second clean machine achieves 100% cache hit with verified SHA-256 outputs. | | **D2 — Fast Hashing & Parallel Snapshot Pipeline** *(verified: 5,001-file warm no-op 374 ms)* | Adopt `Void::Crypto` BLAKE2b / hardware-accelerated SHA-256 (when available) + parallel snapshot hashing across `Void::Concurrency::ThreadPool` + optional `Void::Sqlite` indexed state store for >10k-file monorepos. Snapshot capture revalidation now hashes on a bounded thread pool for trees of 32+ files. | Sub-second warm no-op on 5,000-file synthetic benchmark fixture (`vbs_benchmarks`). | -| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, and `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation. | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). | +| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation, and `vbs-registry` stores/serves per-release binary variants with optional signature metadata. | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). | --- diff --git a/registry/include/Void/Build/Registry/RegistryService.hpp b/registry/include/Void/Build/Registry/RegistryService.hpp index 1592c09..c441c30 100644 --- a/registry/include/Void/Build/Registry/RegistryService.hpp +++ b/registry/include/Void/Build/Registry/RegistryService.hpp @@ -42,6 +42,16 @@ struct SessionRecord { std::int64_t expires_epoch{0}; }; +struct BinaryReleaseMeta { + std::string variant_id; + std::string sha256; + std::uint64_t size_bytes{0}; + std::string signature; // Ed25519 signature hex; empty = unsigned artifact. + std::string public_key; // Ed25519 public key hex; empty = unsigned artifact. + std::string publisher; + std::int64_t published_epoch{0}; +}; + struct ReleaseMeta { std::string version; std::string sha256; @@ -51,6 +61,7 @@ struct ReleaseMeta { std::int64_t published_epoch{0}; std::string signature; // Ed25519 signature hex; empty = unsigned release. std::string public_key; // Ed25519 public key hex; empty = unsigned release. + std::map> binaries; }; struct PackageMeta { diff --git a/registry/service/RegistryService.cpp b/registry/service/RegistryService.cpp index 679f01f..11e1d7e 100644 --- a/registry/service/RegistryService.cpp +++ b/registry/service/RegistryService.cpp @@ -299,6 +299,29 @@ Void::Result::Result RegistryService::load_locked() { rm.published_epoch = get_i64(*ro, "published_epoch", 0); rm.signature = get_str(*ro, "signature"); rm.public_key = get_str(*ro, "public_key"); + if (const auto *bv = find_key(*ro, "binaries")) { + if (const auto *barr = + std::get_if(&bv->value)) { + for (const auto &b : *barr) { + if (const auto *bo = + std::get_if(&b.value)) { + BinaryReleaseMeta bm; + bm.variant_id = get_str(*bo, "variant_id"); + bm.sha256 = get_str(*bo, "sha256"); + bm.size_bytes = static_cast( + get_i64(*bo, "size_bytes", 0)); + bm.signature = get_str(*bo, "signature"); + bm.public_key = get_str(*bo, "public_key"); + bm.publisher = get_str(*bo, "publisher"); + bm.published_epoch = + get_i64(*bo, "published_epoch", 0); + if (!bm.variant_id.empty()) { + rm.binaries[bm.variant_id] = std::move(bm); + } + } + } + } + } p.releases[rm.version] = std::move(rm); } } @@ -382,6 +405,21 @@ Void::Result::Result RegistryService::save_locked() { (r->public_key.empty() ? std::string{} : ",\"public_key\":" + json_quote(r->public_key)) + + ",\"binaries\":" + + json_array( + r->binaries, + [](const auto &entry) { + const auto &b = entry.second; + return "{\"variant_id\":" + json_quote(b.variant_id) + + ",\"sha256\":" + json_quote(b.sha256) + + ",\"size_bytes\":" + + std::to_string(b.size_bytes) + + ",\"signature\":" + json_quote(b.signature) + + ",\"public_key\":" + json_quote(b.public_key) + + ",\"publisher\":" + json_quote(b.publisher) + + ",\"published_epoch\":" + + std::to_string(b.published_epoch) + '}'; + }) + '}'; }) + '}'; @@ -792,22 +830,35 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { ",\"description\":" + json_quote(pit->second.description) + ",\"is_private\":" + std::string{pit->second.is_private ? "true" : "false"} + ",\"owners\":" + json_array(pit->second.owners, json_quote) + ",\"releases\":" + - json_array(rlist, - [](const ReleaseMeta *r) { - return "{\"version\":" + json_quote(r->version) + - ",\"sha256\":" + json_quote(r->sha256) + - ",\"size_bytes\":" + std::to_string(r->size_bytes) + - ",\"yanked\":" + - std::string{r->yanked ? "true" : "false"} + - ",\"publisher\":" + json_quote(r->publisher) + - (r->signature.empty() - ? std::string{} - : ",\"signature\":" + json_quote(r->signature)) + - (r->public_key.empty() - ? std::string{} - : ",\"public_key\":" + json_quote(r->public_key)) + - '}'; - }) + + json_array( + rlist, + [](const ReleaseMeta *r) { + return "{\"version\":" + json_quote(r->version) + + ",\"sha256\":" + json_quote(r->sha256) + + ",\"size_bytes\":" + std::to_string(r->size_bytes) + + ",\"yanked\":" + std::string{r->yanked ? "true" : "false"} + + ",\"publisher\":" + json_quote(r->publisher) + + (r->signature.empty() + ? std::string{} + : ",\"signature\":" + json_quote(r->signature)) + + (r->public_key.empty() + ? std::string{} + : ",\"public_key\":" + json_quote(r->public_key)) + + ",\"binaries\":" + + json_array( + r->binaries, + [](const auto &entry) { + const auto &b = entry.second; + return "{\"variant_id\":" + json_quote(b.variant_id) + + ",\"sha256\":" + json_quote(b.sha256) + + ",\"size_bytes\":" + + std::to_string(b.size_bytes) + + ",\"signature\":" + json_quote(b.signature) + + ",\"public_key\":" + json_quote(b.public_key) + + '}'; + }) + + '}'; + }) + "}\n"); } @@ -979,6 +1030,154 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { return resp; } + // Publish a prebuilt binary variant: + // PUT /api/v1/packages///binaries/ + if (segs.size() == 7 && segs[5] == "binaries" && req.method == "PUT") { + if (!principal) { + return HttpResponse::error_json(401, "unauthorized", "authentication required"); + } + if (!check_csrf_locked(req, *principal)) { + return HttpResponse::error_json(403, "csrf_failed", + "missing or invalid CSRF token"); + } + const std::string &ver_str = segs[4]; + const std::string &variant_id = segs[6]; + const bool valid_variant = !variant_id.empty() && variant_id.size() <= 128 && + std::ranges::all_of(variant_id, [](char c) { + return std::isalnum(static_cast(c)) || + c == '.' || c == '_' || c == '-'; + }); + if (!valid_variant) { + return HttpResponse::error_json(400, "invalid_variant_id", + "variant id must be 1-128 chars of " + "[A-Za-z0-9._-]"); + } + const auto pit = packages_.find(pkg_name); + if (pit == packages_.end()) { + return HttpResponse::error_json(404, "not_found", "package not found"); + } + if (!can_publish_pkg(&pit->second)) { + return HttpResponse::error_json(403, "forbidden", + "insufficient publish authority or ownership"); + } + const auto rit = pit->second.releases.find(ver_str); + if (rit == pit->second.releases.end()) { + return HttpResponse::error_json(404, "not_found", "release not found"); + } + const std::string actual_sha = Util::sha256_hex(req.body); + if (const auto claimed = req.header("x-content-sha256"); + claimed && *claimed != actual_sha) { + return HttpResponse::error_json(400, "digest_mismatch", + "X-Content-SHA256 does not match uploaded bytes"); + } + if (req.body.size() > config_.max_upload_bytes) { + return HttpResponse::error_json(413, "too_large", "binary artifact exceeds limit"); + } + if (total_storage_bytes_locked() + req.body.size() > config_.max_storage_bytes) { + return HttpResponse::error_json(413, "quota_exceeded", + "registry storage quota exceeded"); + } + std::string binary_signature; + std::string binary_public_key; + if (const auto sig = req.header("x-binary-signature"); sig) { + binary_signature = std::string{*sig}; + } + if (const auto key = req.header("x-binary-public-key"); key) { + binary_public_key = std::string{*key}; + } + if (binary_signature.empty() != binary_public_key.empty()) { + return HttpResponse::error_json( + 400, "invalid_signature", + "X-Binary-Signature and X-Binary-Public-Key must be provided together"); + } + auto is_hex = [](std::string_view text) { + return std::ranges::all_of(text, [](char c) { + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F'); + }); + }; + if (!binary_signature.empty() && + (binary_signature.size() != 128 || !is_hex(binary_signature))) { + return HttpResponse::error_json(400, "invalid_signature", + "X-Binary-Signature must be 128 hex characters"); + } + if (!binary_public_key.empty() && + (binary_public_key.size() != 64 || !is_hex(binary_public_key))) { + return HttpResponse::error_json(400, "invalid_signature", + "X-Binary-Public-Key must be 64 hex characters"); + } + if (const auto bit = rit->second.binaries.find(variant_id); + bit != rit->second.binaries.end()) { + if (bit->second.sha256 == actual_sha) { + return HttpResponse::json(200, "{\"status\":\"already_published\",\"sha256\":" + + json_quote(actual_sha) + "}\n"); + } + return HttpResponse::error_json( + 409, "immutable_conflict", + "binary variant already exists with different content digest"); + } + + Void::FileSystem::TempDir probe_tmp{"vbs_reg_binary_"}; + const auto staged = probe_tmp / "binary"; + if (auto w = Platform::atomic_write_file(staged, req.body, false); !w) { + return HttpResponse::error_json(500, "stage_error", w.error().message()); + } + const auto dst_blob = blob_path(actual_sha); + std::error_code ec; + if (!std::filesystem::exists(dst_blob, ec)) { + auto copied = Platform::copy_isolated(staged, dst_blob, 0444u); + if (!copied) { + return HttpResponse::error_json(500, "blob_publish_failed", + copied.error().message()); + } + } + rit->second.binaries[variant_id] = BinaryReleaseMeta{ + variant_id, actual_sha, req.body.size(), binary_signature, + binary_public_key, principal->username, now_epoch()}; + append_audit_locked(principal->username, "binary.publish", + pkg_name + "@" + ver_str + "/" + variant_id, "ok", + "sha256=" + actual_sha); + if (auto s = save_locked(); !s) { + return HttpResponse::error_json(500, "metadata_commit_failed", s.error().message()); + } + return HttpResponse::json(201, "{\"variant_id\":" + json_quote(variant_id) + + ",\"sha256\":" + json_quote(actual_sha) + "}\n"); + } + + // Download a prebuilt binary variant: + // GET /api/v1/packages///binaries//download + if (segs.size() == 8 && segs[5] == "binaries" && segs[7] == "download" && + req.method == "GET") { + const auto pit = packages_.find(pkg_name); + if (pit == packages_.end()) { + return HttpResponse::error_json(404, "not_found", "package not found"); + } + if (!can_read_pkg(pit->second)) { + return HttpResponse::error_json(principal ? 403 : 401, "forbidden", + "private package requires authorization"); + } + const auto rit = pit->second.releases.find(segs[4]); + if (rit == pit->second.releases.end()) { + return HttpResponse::error_json(404, "not_found", "release not found"); + } + const auto bit = rit->second.binaries.find(segs[6]); + if (bit == rit->second.binaries.end()) { + return HttpResponse::error_json(404, "not_found", "binary variant not found"); + } + const auto bpath = blob_path(bit->second.sha256); + auto bytes = Void::FileSystem::read_file_bounded(bpath, {256ULL * 1024ULL * 1024ULL}); + if (!bytes || Util::sha256_hex(*bytes) != bit->second.sha256) { + return HttpResponse::error_json(500, "integrity_error", + "stored binary blob missing or corrupted"); + } + HttpResponse resp; + resp.status = 200; + resp.headers["Content-Type"] = "application/octet-stream"; + resp.headers["X-Content-SHA256"] = bit->second.sha256; + resp.body = std::move(*bytes); + return resp; + } + // Yank/unyank release: POST /api/v1/packages///yank if (segs.size() == 6 && segs[5] == "yank" && req.method == "POST") { if (!principal) { diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index fe442ed..976df7f 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -488,6 +488,136 @@ VOID_TEST(RegistryTests, binary_variant_distribution_downloads_and_verifies) { Void::Testing::expect(!mismatched.has_value()); } +VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materialize) { + if (!Provenance::signing_available()) { + return; + } + Void::FileSystem::TempDir tmp{"vbs_reg_binary_"}; + RegistryConfig cfg; + cfg.data_dir = tmp / "reg_data"; + cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web"; + cfg.bind_address = "127.0.0.1"; + cfg.port = 0; + cfg.bootstrap_admin_user = "admin"; + cfg.bootstrap_admin_password = "admin_pw"; + + auto svc = RegistryService::open(cfg); + Void::Testing::expect(svc.has_value()); + if (!svc) { + return; + } + Void::Testing::expect((*svc)->create_user("bin_pub", "bin_pass", Role::Publisher).has_value()); + auto tok = (*svc)->create_token("bin_pub", "publish", {"read", "publish"}); + Void::Testing::expect(tok.has_value()); + if (!tok) { + return; + } + Void::Testing::expect((*svc)->start_http().has_value()); + const auto port = (*svc)->bound_port(); + const std::string reg_url = "http://127.0.0.1:" + std::to_string(port); + + // The binary variant belongs to an existing source release. + const auto pkg_src = tmp / "src_pkg"; + (void)Platform::atomic_write_file(pkg_src / "payload.txt", "SOURCE_PAYLOAD", false); + const auto tar = tmp / "src.tar"; + auto source_sha = Package::create_source_package(pkg_src, tar, 0); + Void::Testing::require(source_sha.has_value()); + auto source_bytes = Void::FileSystem::read_file(tar); + Void::Testing::require(source_bytes.has_value()); + auto src_pub = send_loopback_http( + port, "PUT", "/api/v1/packages/demo-bin/1.0.0", + {{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *source_sha}}, *source_bytes); + Void::Testing::require(src_pub.has_value() && src_pub->status == 201); + + const std::string artifact = "PREBUILT_BINARY_VARIANT_BYTES"; + const std::string artifact_sha = Util::sha256_hex(artifact); + const std::string variant_id = "linux-x86_64-gcc16-static"; + const std::string binary_path = "/api/v1/packages/demo-bin/1.0.0/binaries/" + variant_id; + + auto unauthorized = send_loopback_http(port, "PUT", binary_path, + {{"X-Content-SHA256", artifact_sha}}, artifact); + Void::Testing::expect(unauthorized.has_value() && unauthorized->status == 401); + + const auto seed_path = tmp / "binary.seed"; + Void::Testing::require(Provenance::generate_signing_seed(seed_path).has_value()); + auto public_key = Provenance::public_key_from_seed(seed_path); + Void::Testing::require(public_key.has_value()); + const std::string message = Provenance::canonical_binary_message(variant_id, artifact_sha); + auto signature = Provenance::sign_message( + std::as_bytes(std::span{message.data(), message.size()}), seed_path); + Void::Testing::require(signature.has_value()); + + auto bad_signature = send_loopback_http(port, "PUT", binary_path, + {{"Authorization", "Bearer " + *tok}, + {"X-Content-SHA256", artifact_sha}, + {"X-Binary-Signature", std::string(127, 'a')}, + {"X-Binary-Public-Key", *public_key}}, + artifact); + Void::Testing::expect(bad_signature.has_value() && bad_signature->status == 400); + + auto published = send_loopback_http(port, "PUT", binary_path, + {{"Authorization", "Bearer " + *tok}, + {"X-Content-SHA256", artifact_sha}, + {"X-Binary-Signature", *signature}, + {"X-Binary-Public-Key", *public_key}}, + artifact); + Void::Testing::expect(published.has_value() && published->status == 201); + + auto detail = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin"); + Void::Testing::expect(detail.has_value() && detail->status == 200); + if (detail) { + Void::Testing::expect(detail->body.find(variant_id) != std::string::npos); + Void::Testing::expect(detail->body.find(artifact_sha) != std::string::npos); + } + + auto downloaded = send_loopback_http(port, "GET", binary_path + "/download"); + Void::Testing::expect(downloaded.has_value() && downloaded->status == 200); + if (downloaded) { + Void::Testing::expect(downloaded->body == artifact); + } + + auto conflict = send_loopback_http( + port, "PUT", binary_path, + {{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", Util::sha256_hex("different")}}, + "different"); + Void::Testing::expect(conflict.has_value() && conflict->status == 409); + + // The registry-served artifact materializes through the signed binary-variant path. + Package::BinaryVariantMeta variant; + variant.variant_id = variant_id; + variant.os = "Linux"; + variant.architecture = "x86_64"; + variant.compiler_family = "gcc"; + variant.compiler_abi = "gcc-16"; + variant.stdlib_abi = "libstdc++"; + variant.linkage = "static"; + variant.lto_mode = "off"; + variant.dependency_closure_hash = "closure"; + variant.sha256 = artifact_sha; + variant.download_url = reg_url + binary_path + "/download"; + variant.signature = *signature; + variant.public_key = *public_key; + + Package::BinaryCompatibilityKey key; + key.os = variant.os; + key.architecture = variant.architecture; + key.compiler_family = variant.compiler_family; + key.compiler_abi = variant.compiler_abi; + key.stdlib_abi = variant.stdlib_abi; + key.linkage = variant.linkage; + key.lto_mode = variant.lto_mode; + key.dependency_closure_hash = variant.dependency_closure_hash; + + Package::BinaryFetchOptions options{tmp / "binary_cache", {*public_key}}; + auto materialized = Package::materialize_binary_variant(key, {variant}, options); + Void::Testing::require(materialized.has_value()); + auto cached = Void::FileSystem::read_file(tmp / "binary_cache" / "binaries" / artifact_sha); + Void::Testing::require(cached.has_value()); + Void::Testing::expect(*cached == artifact); + + (*svc)->stop_http(); +} + // End-to-end live client <-> server test: `vbs publish` -> `vbs deps resolve` -> `vbs build // --locked`! VOID_TEST(RegistryTests, cli_publish_deps_resolve_and_locked_build_against_live_registry) {