diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 1fd02c9..15958cd 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -251,6 +251,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 79 (Registry Metadata PATCH & Daemon `workspace_info`)**: `PATCH /api/v1/packages/` updates mutable `description`/`private` metadata (auth + CSRF, publish authority, validated body, audited `package.update`), covered in the RBAC test with a dedicated private package. A swarm worker added the `workspace_info` daemon request (members plus root lockfile presence/size, `workspace:false` for plain projects) with tests (5/5 substantive tasks; build task stopped and re-run). +- **Wave 80 (Watch Prefix Filter & Registry OPTIONS)**: `watch_poll`/`watch_wait` accept a bounded `prefix` filter that returns only matching buffered changes while retaining non-matching ones for later requests (`vbs daemon ide poll|wait --prefix`), covered in the watch test. A swarm worker added an `OPTIONS` preflight (204 + `Allow`) to the registry with a dedicated test (4/4 substantive tasks; build task stopped and re-run). + ## 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))**: Track C (macOS/Windows ports + dual-profile cross-compilation) and dedicated external editor plugins remain planned; Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement/distribution, binary-variant signing/distribution) and Track E3 daemon capabilities are implemented, and Track E4 now uses `Void::Net` for the registry client/server and remote cache plus `Void::Sqlite` for the StateStore when available. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 1b66a7d..2f2634c 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -83,4 +83,5 @@ Base HEAD: `fe0d1a6` | Wave 77 (ETag/304 + deps offline) | registry read endpoints emit ETag and answer If-None-Match with 304; swarm added daemon `deps` `offline` flag | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 8/8, Daemon suite passes, full CTest 8/8) | `registry/service/RegistryService.cpp`, `src/Daemon/Daemon.cpp`, `tests/{RegistryTests,DaemonTests}.cpp`, docs | | Wave 78 (Download ETag + status pending changes) | download ETag/If-None-Match 304 before reads; swarm added daemon `status` `pending_changes` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 8/8, Daemon suite passes, full CTest 8/8) | `registry/service/RegistryService.cpp`, `src/Daemon/Daemon.cpp`, `tests/{RegistryTests,DaemonTests}.cpp`, docs | | Wave 79 (Registry metadata PATCH + workspace_info) | `PATCH /api/v1/packages/` for description/private (audited); swarm added daemon `workspace_info` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 8/8, Daemon suite passes, full CTest 8/8) | `registry/service/RegistryService.cpp`, `src/Daemon/Daemon.cpp`, `tests/{RegistryTests,DaemonTests}.cpp`, docs | +| Wave 80 (Watch prefix + registry OPTIONS) | daemon watch `prefix` filter retaining non-matching events; swarm added registry OPTIONS 204 + Allow | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 9/9, Daemon suite passes, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `registry/service/RegistryService.cpp`, `tests/{DaemonTests,RegistryTests}.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] 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 5c82662..877b654 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1218,6 +1218,14 @@ dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color passes (2.28 s). - Registry suite: **8 / 8 passed** (11.00 s); full CTest: **8 / 8 passed** in 276.04 s. +## Watch Prefix Filter & Registry OPTIONS (GCC 16.2, pin `0002e74`) + +- A `watch_poll` with a non-matching `prefix` returns no changes and retains the buffered event; a + poll with the project prefix then returns `probe.txt` (`watch_poll_reports_changed_paths`, 67 ms). +- Swarm `swarm_mx8etp10_joyc` (one worker) added registry `OPTIONS` preflight (204 + `Allow`) with a + dedicated test (4/4 substantive tasks; build task stopped and re-run by the orchestrator). +- Registry suite: **9 / 9 passed** (11.27 s); full CTest: **8 / 8 passed** in 262.39 s. + ## 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 d94c2da..84779e8 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -73,7 +73,7 @@ flowchart LR | --- | --- | --- | | **E1 — Everyday CLI Ergonomics (Implemented in Wave 8)** | `vbs init` project scaffolding, `vbs clean`, `vbs doctor` environment diagnostics, `vbs graph --format dot|json`, and `vbs build --native-foreign`. | End-to-end CLI & integration tests passing in `vbs_cli_contract` and `vbs_v1_tests`. | | **E2 — Multi-Package Workspaces (`workspace.cpp`)** *(verified in Docker GCC 16)* | Shared root `vbs.lock` and `build/.vbs` CAS, `workspace_dependency()` cross-member native linking, and affected-member selection (`vbs build/test --member ` / `--changed-since `). | 3-package workspace fixture (shared library + app + tests) builds/tests with one root lockfile; member selection and `--changed-since` verified in `FullV1Tests.workspace_members_shared_build_and_member_selection`. | -| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), `vbs daemon ide wait` adds a bounded long-poll variant, `vbs daemon ide status` reports the active editor selection and compdb state, `vbs daemon compdb use` switches the active editor profile under the selection lock, `vbs daemon graph` exports the target dependency graph (DOT/JSON), `vbs daemon test` builds and runs declared test targets, `vbs daemon clean` removes generated outputs while preserving the shared cache, `vbs daemon target info` reports per-target sources/outputs, `vbs daemon actions` lists bounded lowered actions, `vbs daemon pack` creates a confined deterministic source archive, `vbs daemon install` stages an install prefix (and `uninstall` removes only manifest-owned files), `vbs daemon gen-tests` generates the native test registration unit, `vbs daemon init` scaffolds confined projects, `vbs daemon compdb entries` serves bounded per-file compile arguments to editor extensions, `vbs daemon workspace members` lists workspace members cheaply, `vbs daemon ide configs` reports which editor configuration files exist, `vbs daemon compdb generations` lists editor generation history with the active selection, `vbs daemon info` exposes the daemon environment, `vbs daemon deps` resolves/materializes dependencies over the socket, registry package search and audit queries support bounded pagination/filters, releases expose a version-specific detail endpoint, package ownership and mutable metadata are managed through audited APIs, and `RegistryClient::fetch_package_owners` reads owners. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | +| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), `vbs daemon ide wait` adds a bounded long-poll variant, `vbs daemon ide status` reports the active editor selection and compdb state, watch requests can be filtered by path prefix, `vbs daemon compdb use` switches the active editor profile under the selection lock, `vbs daemon graph` exports the target dependency graph (DOT/JSON), `vbs daemon test` builds and runs declared test targets, `vbs daemon clean` removes generated outputs while preserving the shared cache, `vbs daemon target info` reports per-target sources/outputs, `vbs daemon actions` lists bounded lowered actions, `vbs daemon pack` creates a confined deterministic source archive, `vbs daemon install` stages an install prefix (and `uninstall` removes only manifest-owned files), `vbs daemon gen-tests` generates the native test registration unit, `vbs daemon init` scaffolds confined projects, `vbs daemon compdb entries` serves bounded per-file compile arguments to editor extensions, `vbs daemon workspace members` lists workspace members cheaply, `vbs daemon ide configs` reports which editor configuration files exist, `vbs daemon compdb generations` lists editor generation history with the active selection, `vbs daemon info` exposes the daemon environment, `vbs daemon deps` resolves/materializes dependencies over the socket, registry package search and audit queries support bounded pagination/filters, releases expose a version-specific detail endpoint, package ownership and mutable metadata are managed through audited APIs, and `RegistryClient::fetch_package_owners` reads owners. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | | **E4 — Transport & Storage Upstream Alignment** *(Sqlite and Net client adopted)* | Adopt `Void::Net` (`VL-004`/`VL-005`) and `Void::Sqlite` (`VL-011b`) when lightweight/bundled builds become available in minimal Nix toolchains, reducing VBS transport code further. `Void::Sqlite` backs the `StateStore` when SQLite3 is present, `Void::Net` backs the `RegistryClient`, remote-cache, and registry-server HTTP transports (TLS-verifying `HttpClient`/`HttpServer`) when `Net` is enabled (`-p openssl -p boost`), keeping the pure-POSIX fallbacks. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains (verified: registry 7/7 on the Net transport; default and SQLite builds 8/8). | --- diff --git a/registry/service/RegistryService.cpp b/registry/service/RegistryService.cpp index 60902d8..775c014 100644 --- a/registry/service/RegistryService.cpp +++ b/registry/service/RegistryService.cpp @@ -204,6 +204,51 @@ std::vector split_path(std::string_view path) { return segs; } +// OPTIONS is a CORS-style preflight: the advertised methods depend only on the route shape, so +// this never authenticates or inspects package/release metadata. +std::optional allowed_methods_for(const std::vector &segs) { + if (segs.size() < 3 || segs[0] != "api" || segs[1] != "v1" || segs[2] != "packages") { + return std::nullopt; + } + switch (segs.size()) { + case 3: + return "GET, HEAD, OPTIONS"; + case 4: + return "GET, HEAD, PATCH, OPTIONS"; // + case 5: + if (segs[4] == "owners") { + return "GET, HEAD, PUT, POST, DELETE, OPTIONS"; + } + return "GET, HEAD, PUT, OPTIONS"; // + case 6: + if (segs[4] == "owners") { + return "PUT, POST, DELETE, OPTIONS"; + } + if (segs[5] == "download" || segs[5] == "binaries") { + return "GET, HEAD, OPTIONS"; + } + if (segs[5] == "yank") { + return "POST, OPTIONS"; + } + return std::nullopt; + case 7: + if (segs[5] == "binaries") { + return "GET, HEAD, PUT, OPTIONS"; + } + return std::nullopt; + case 8: + if (segs[5] == "binaries" && segs[7] == "download") { + return "GET, HEAD, OPTIONS"; + } + if (segs[5] == "binaries" && segs[7] == "yank") { + return "POST, OPTIONS"; + } + return std::nullopt; + default: + return std::nullopt; + } +} + const JsonVal *find_key(const JsonVal::Object &obj, const std::string &k) { const auto it = obj.find(k); return it == obj.end() ? nullptr : &it->second; @@ -723,9 +768,22 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { return serve_static_web_asset(req.path); } - std::lock_guard lk{mu_}; const auto segs = split_path(req.path); + // OPTIONS preflight: answer from the route shape alone, before authentication. + if (req.method == "OPTIONS") { + if (const auto allow = allowed_methods_for(segs)) { + HttpResponse resp; + resp.status = 204; + resp.reason = "No Content"; + resp.headers["Allow"] = std::string{*allow}; + return resp; + } + return HttpResponse::error_json(404, "not_found", "unknown API endpoint"); + } + + std::lock_guard lk{mu_}; + // Health endpoint. if (req.method == "GET" && req.path == "/api/v1/health") { return HttpResponse::json(200, "{\"status\":\"ok\",\"schema_version\":1}\n"); diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 7594cb5..db0d8c9 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -1894,6 +1894,9 @@ struct DaemonServer::Impl { [[nodiscard]] std::string status_response() const; DispatchResult dispatch(std::string_view line); void record_watch_batch(const Watch::WatchBatch &batch); + // Removes and returns buffered changes matching `prefix` (all when empty); non-matching + // entries stay buffered for later requests. + std::vector take_pending(std::string_view prefix); void close_socket() noexcept { if (listen_fd >= 0) { @@ -1961,6 +1964,25 @@ void DaemonServer::Impl::record_watch_batch(const Watch::WatchBatch &batch) { } } +std::vector DaemonServer::Impl::take_pending(std::string_view prefix) { + if (prefix.empty()) { + std::vector taken; + taken.swap(pending_changes); + return taken; + } + std::vector taken; + std::vector kept; + for (auto &path : pending_changes) { + if (std::string_view{path.string()}.starts_with(prefix)) { + taken.push_back(std::move(path)); + } else { + kept.push_back(std::move(path)); + } + } + pending_changes = std::move(kept); + return taken; +} + std::string DaemonServer::Impl::status_response() const { const DaemonStatus status = current_status(); JsonValue::Object object; @@ -2010,11 +2032,18 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view return {error_response(std::format("watch_poll: {}", batch.error().format())), false}; } record_watch_batch(*batch); + std::string prefix; + if (const auto entry = object->find("prefix"); entry != object->end()) { + const auto *value = std::get_if(&entry->second.value); + if (value == nullptr || value->size() > 4096) { + return {error_response("\"prefix\" must be a bounded string"), false}; + } + prefix = *value; + } JsonValue::Array changed; - for (const auto &path : pending_changes) { + for (const auto &path : take_pending(prefix)) { changed.emplace_back(path.string()); } - pending_changes.clear(); JsonValue::Object object; object.emplace("ok", JsonValue{true}); object.emplace("op", JsonValue{std::string{"watch_poll"}}); @@ -2328,6 +2357,15 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view timeout_ms = *value; } + std::string prefix; + if (const auto entry = object->find("prefix"); entry != object->end()) { + const auto *value = std::get_if(&entry->second.value); + if (value == nullptr || value->size() > 4096) { + return {error_response("\"prefix\" must be a bounded string"), false}; + } + prefix = *value; + } + bool timed_out = false; if (pending_changes.empty() && timeout_ms > 0) { auto batch = watcher.poll_events(std::chrono::milliseconds{timeout_ms}, @@ -2341,10 +2379,12 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view record_watch_batch(*batch); } JsonValue::Array changed; - for (const auto &path : pending_changes) { + for (const auto &path : take_pending(prefix)) { changed.emplace_back(path.string()); } - pending_changes.clear(); + if (!prefix.empty() && changed.empty()) { + timed_out = true; + } JsonValue::Object object; object.emplace("ok", JsonValue{true}); object.emplace("op", JsonValue{std::string{"watch_wait"}}); diff --git a/src/Main.cpp b/src/Main.cpp index 20a78f4..1f25444 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1747,7 +1747,11 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { ? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg)) : std::string{}); } else if (sub == "watch_poll") { - request_json = R"({"op":"watch_poll"})"; + request_json = + opts.prefix_arg + ? std::format(R"({{"op":"watch_poll","prefix":{}}})", + Util::json_quote(*opts.prefix_arg)) + : std::string{R"({"op":"watch_poll"})"}; } else if (sub == "watch_wait") { std::int64_t timeout_ms = 0; const auto [ptr, ec] = @@ -1759,7 +1763,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { << "' (0..5000)\n"; return 2; } - request_json = std::format(R"({{"op":"watch_wait","timeout_ms":{}}})", timeout_ms); + request_json = std::format( + R"({{"op":"watch_wait","timeout_ms":{}{}}})", timeout_ms, + opts.prefix_arg ? std::format(",\"prefix\":{}", Util::json_quote(*opts.prefix_arg)) + : std::string{}); } else if (sub == "ide_generate") { if (opts.profile_arg.empty()) { std::cerr << "vbs daemon ide generate: --profile must not be empty\n"; @@ -2863,11 +2870,16 @@ int main(int argc, char **argv) { auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand( "poll", "Poll pending project file changes (editor extension protocol)"); configure_daemon_common(daemon_ide_poll_cmd); + daemon_ide_poll_cmd.option("--prefix", "", "Only report changed paths under this prefix", + daemon_opts.prefix_arg); auto &daemon_ide_wait_cmd = daemon_ide_cmd.subcommand( "wait", "Long-poll for project file changes (bounded, editor extension protocol)"); configure_daemon_common(daemon_ide_wait_cmd); - daemon_ide_wait_cmd.option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)", - daemon_opts.timeout_ms_arg, "2000"); + daemon_ide_wait_cmd + .option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)", + daemon_opts.timeout_ms_arg, "2000") + .option("--prefix", "", "Only report changed paths under this prefix", + daemon_opts.prefix_arg); auto &daemon_ide_generate_cmd = daemon_ide_cmd.subcommand("generate", "Write editor configuration files"); configure_daemon_common(daemon_ide_generate_cmd); diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index 39dce91..e263ec6 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -704,8 +704,19 @@ VOID_TEST(Daemon, watch_poll_reports_changed_paths) { std::this_thread::sleep_for(std::chrono::milliseconds{50}); bool saw_probe = false; + bool non_matching_prefix_seen = false; for (int attempt = 0; attempt < 100 && !saw_probe; ++attempt) { - auto poll = request_object(socket, R"({"op":"watch_poll"})"); + if (!non_matching_prefix_seen) { + // A non-matching prefix must not consume the buffered event. + auto non_matching = request_object( + socket, R"({"op":"watch_poll","prefix":"/nonexistent-prefix/"})"); + Void::Testing::require(non_matching.has_value()); + Void::Testing::expect(string_array_field(*non_matching, "changed").empty()); + non_matching_prefix_seen = true; + } + auto poll = request_object( + socket, std::format(R"({{"op":"watch_poll","prefix":{}}})", + Void::Build::Util::json_quote(options.project_root.string()))); Void::Testing::require(poll.has_value()); for (const auto &path : string_array_field(*poll, "changed")) { if (path.find("probe.txt") != std::string::npos) { diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 351c2f5..387e6d9 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -134,6 +134,14 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest auto trav = send_loopback_http(port, "GET", "/../CMakeLists.txt"); Void::Testing::expect(trav.has_value() && trav->status == 403); + // OPTIONS preflight advertises the supported API methods with a bodyless 204. + auto options_resp = send_loopback_http(port, "OPTIONS", "/api/v1/packages"); + Void::Testing::expect(options_resp.has_value() && options_resp->status == 204); + if (options_resp) { + Void::Testing::expect(options_resp->headers.contains("allow")); + Void::Testing::expect(options_resp->headers.at("allow").find("GET") != std::string::npos); + } + // 2. Build a valid deterministic package tar and publish as Publisher Alice. const auto pkg_src = tmp / "pkg_src"; (void)Platform::atomic_write_file(pkg_src / "build.cpp", @@ -1626,3 +1634,60 @@ VOID_TEST(RegistryTests, registry_release_detail_fields_signature_404_and_privat (*svc)->stop_http(); } + +// OPTIONS preflight: metadata and download routes answer 204 + Allow from the path shape alone, +// without authentication or a published release. +VOID_TEST(RegistryTests, options_preflight_metadata_and_download_endpoints) { + Void::FileSystem::TempDir tmp{"vbs_reg_options_"}; + RegistryConfig cfg; + cfg.data_dir = tmp / "data"; + 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::require((*svc)->start_http().has_value()); + const auto port = (*svc)->bound_port(); + + const auto expect_options = [port](const std::string &path, const std::string &expected_allow) { + auto resp = send_loopback_http(port, "OPTIONS", path); + Void::Testing::require(resp.has_value()); + Void::Testing::expect_eq(static_cast(resp->status), 204); + Void::Testing::expect(resp->body.empty()); + Void::Testing::expect(resp->headers.contains("allow")); + if (resp->headers.contains("allow")) { + Void::Testing::expect_eq(resp->headers.at("allow"), expected_allow); + } + }; + + expect_options("/api/v1/packages", "GET, HEAD, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg", "GET, HEAD, PATCH, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/owners", "GET, HEAD, PUT, POST, DELETE, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0", "GET, HEAD, PUT, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/download", "GET, HEAD, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries", "GET, HEAD, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64", + "GET, HEAD, PUT, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64/download", + "GET, HEAD, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/yank", "POST, OPTIONS"); + expect_options("/api/v1/packages/demo-pkg/1.0.0/binaries/linux-x86_64/yank", "POST, OPTIONS"); + + // Preflight never demands authentication, even for a private package's download route. + expect_options("/api/v1/packages/secret-pkg/1.0.0/download", "GET, HEAD, OPTIONS"); + + // Unknown API shapes keep the existing 404 behaviour. + auto unknown = send_loopback_http(port, "OPTIONS", "/api/v1/does-not-exist"); + Void::Testing::expect(unknown.has_value() && unknown->status == 404); + + // The OPTIONS branch must not regress ordinary GET routing. + auto list = send_loopback_http(port, "GET", "/api/v1/packages"); + Void::Testing::expect(list.has_value() && list->status == 200); + + (*svc)->stop_http(); +}