From 3fa7ab086f6fc3510091d61deabf147502920208 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 05:16:57 +0300 Subject: [PATCH] feat(registry,daemon): answer HEAD without a body; mark editor generations stale --- docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 9 +++ docs/roadmap/21-expansion-roadmap.md | 2 +- registry/service/HttpServer.cpp | 21 ++++++- src/Daemon/Daemon.cpp | 46 ++++++++++++++ tests/DaemonTests.cpp | 93 ++++++++++++++++++++++++++++ tests/RegistryTests.cpp | 18 ++++++ 8 files changed, 190 insertions(+), 2 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index d6e0e01..dfc22ba 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -241,6 +241,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 74 (Self-Excluding Source Archives & Release-Detail Tests)**: `create_source_package` now skips its own output archive (and any stale copy at that path), so packing into a non-`build`-named directory no longer embeds the previous archive; asserted in `archive_security_determinism_binary_abi_and_redaction`. A swarm worker added a dedicated release-detail test (fields, signature metadata, 404, private auth) to `RegistryTests` (5/5 substantive tasks; its build task was stopped and re-run by the orchestrator). +- **Wave 75 (HEAD/Content-Length Support & Daemon `compdb_stale`)**: the registry server (both the POSIX loop and the `Void::Net` bridge) routes `HEAD` exactly like `GET` while suppressing the body and preserving `Content-Length`/content headers; asserted for release and binary downloads. A swarm worker (4/4 substantive tasks; build task stopped and re-run) added the `compdb_stale` daemon request (marks a profile generation stale with an optional reason) and `Daemon.compdb_stale_marks_generation_stale`. + ## 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 2e399df..195e149 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -78,4 +78,5 @@ Base HEAD: `fe0d1a6` | Wave 72 (Daemon target flags + registry search tests) | `target_flags` daemon request + `vbs daemon target flags`; swarm deepened RegistryTests search/pagination coverage | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon and Registry suites pass, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/{DaemonTests,RegistryTests}.cpp`, `tests/CliContracts.cmake`, docs | | Wave 73 (Actions kind filter + releases show) | daemon `actions --kind` filter; swarm added `fetch_release_detail` and `vbs releases show` with tests | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon and Registry suites pass, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `include/Void/Build/Package/RegistryClient.hpp`, `src/Package/RegistryClient.cpp`, `tests/{DaemonTests,RegistryTests}.cpp`, `tests/CliContracts.cmake`, docs | | Wave 74 (Self-excluding archives + release-detail tests) | `create_source_package` excludes its own output; swarm added release-detail RegistryTests coverage | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 8/8, full CTest 8/8) | `src/Package/Archive.cpp`, `tests/{FullV1Tests,RegistryTests}.cpp`, docs | +| Wave 75 (HEAD support + daemon compdb_stale) | registry HEAD routes like GET without a body (POSIX and Net); swarm added daemon `compdb_stale` with tests | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 8/8, Daemon suite passes, full CTest 8/8) | `registry/service/HttpServer.cpp`, `src/Daemon/Daemon.cpp`, `tests/{RegistryTests,DaemonTests}.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 2933d07..631fa72 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1171,6 +1171,15 @@ dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color build task was stopped and re-run by the orchestrator). - Registry suite: **8 / 8 passed** (10.91 s); full CTest: **8 / 8 passed** in 246.26 s. +## HEAD/Content-Length & Daemon `compdb_stale` (GCC 16.2, pin `0002e74`) + +- `HEAD` on release and binary downloads returns 200 with an empty body, a non-zero + `Content-Length`, and the content headers (asserted in the registry suites). +- Swarm `swarm_mx8cczer_eoac` (one worker) added `compdb_stale` (4/4 substantive tasks; its build + task was stopped and re-run by the orchestrator); `Daemon.compdb_stale_marks_generation_stale` + passes (2.23 s). +- Registry suite: **8 / 8 passed** (11.64 s); full CTest: **8 / 8 passed** in 273.63 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 0321dc4..5379140 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -46,7 +46,7 @@ flowchart LR | Phase | Concrete Scope | Acceptance Gate | | --- | --- | --- | -| **C1 — Platform Backend Split** *(Linux backend split implemented; macOS/Windows pending)* | Split `src/Platform/` into `Linux/`, `MacOS/`, and `Windows/` behind clean interfaces (`FileOps`, `ProcessSupervisor`, `DirectoryWatcher`), delegating to `Void::System` as upstream adds OS backends. Linux implementations now live under `src/Platform/Linux/` and `src/Watch/Linux/` (inotify watcher) with an explicit `HostOs`/`host_supported()` boundary in `include/Void/Build/Platform/Host.hpp`; macOS/Windows backends await real hosts (`vbs doctor` and the daemon `info` request report the detected host and enabled backends, `Platform::current_executable_path()` isolates the executable-path lookup across sources and tests, the daemon `describe` request can be scoped to one workspace member, `vbs daemon target flags` serves per-unit compile arguments, `vbs releases show` prints one release's detail, and source archives never embed themselves). | Zero Linux regressions; clean platform abstraction boundary. | +| **C1 — Platform Backend Split** *(Linux backend split implemented; macOS/Windows pending)* | Split `src/Platform/` into `Linux/`, `MacOS/`, and `Windows/` behind clean interfaces (`FileOps`, `ProcessSupervisor`, `DirectoryWatcher`), delegating to `Void::System` as upstream adds OS backends. Linux implementations now live under `src/Platform/Linux/` and `src/Watch/Linux/` (inotify watcher) with an explicit `HostOs`/`host_supported()` boundary in `include/Void/Build/Platform/Host.hpp`; macOS/Windows backends await real hosts (`vbs doctor` and the daemon `info` request report the detected host and enabled backends, `Platform::current_executable_path()` isolates the executable-path lookup across sources and tests, the daemon `describe` request can be scoped to one workspace member, `vbs daemon target flags` serves per-unit compile arguments, `vbs releases show` prints one release's detail, source archives never embed themselves, and registry downloads answer HEAD with full headers). | Zero Linux regressions; clean platform abstraction boundary. | | **C2 — macOS / Apple Clang & `ld64`** | Apple Clang toolchain probes, `.dylib` + `@rpath`/`@loader_path` install-name lowering, `FSEvents` watcher, Mach-O deterministic timestamps. | Real macOS CI runner passing all SDK, core, module, and install tests. | | **C3 — Windows / MSVC & `clang-cl`** | MSVC (`cl.exe`, `lib.exe`, `link.exe`, `/showIncludes`, `.pdb`, `/FS`, `.dll`/`.lib` import libraries), Job Object process-tree kill, `ReadDirectoryChangesW` watcher, case-insensitive path conflict detection. | Real Windows CI runner passing process-tree kill, header-shadowing, and install relocation tests. | | **C4 — True Host-vs-Target Cross-Compilation** | Dual-context evaluation (`host` profile for code generators and `build_dependency` tools vs `target` profile for cross-compiled products), sysroot & `--target=` triple propagation. | `linux-x86_64` host cross-compiling `linux-aarch64` fixture while executing host-compiled generator natively. | diff --git a/registry/service/HttpServer.cpp b/registry/service/HttpServer.cpp index 72e79f2..39b8168 100644 --- a/registry/service/HttpServer.cpp +++ b/registry/service/HttpServer.cpp @@ -219,8 +219,17 @@ Void::Result::Result HttpServer::start(const HttpServ } bridged.body = request.body; + // HEAD is routed exactly like GET; the body is dropped but Content-Length is preserved. + const bool head_only = request.method == Void::Net::Method::Head; + if (head_only) { + bridged.method = "GET"; + } HttpResponse response = handler(bridged); apply_default_security_headers(response); + if (head_only) { + response.headers["Content-Length"] = std::to_string(response.body.size()); + response.body.clear(); + } Void::Net::ServerResponse net_response; net_response.status = response.status; for (const auto &[name, value] : response.headers) { @@ -333,11 +342,13 @@ void HttpServer::handle_client(int client_fd) { (void)::setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); (void)::setsockopt(client_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + bool suppress_body = false; auto write_response = [&](HttpResponse resp) { if (resp.reason.empty()) { resp.reason = default_reason(resp.status); } apply_default_security_headers(resp); + // HEAD keeps the headers of the equivalent GET (including Content-Length) but no body. resp.headers["Content-Length"] = std::to_string(resp.body.size()); resp.headers["Connection"] = "close"; @@ -349,7 +360,9 @@ void HttpServer::handle_client(int client_fd) { wire += "Set-Cookie: " + cookie + "\r\n"; } wire += "\r\n"; - wire += resp.body; + if (!suppress_body) { + wire += resp.body; + } (void)send_all(client_fd, wire); }; @@ -446,6 +459,12 @@ void HttpServer::handle_client(int client_fd) { req.body.resize(content_length); } + // HEAD is routed exactly like GET; only the body is suppressed when writing. + if (req.method == "HEAD") { + suppress_body = true; + req.method = "GET"; + } + try { write_response(handler_(req)); } catch (const std::exception &ex) { diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 843e929..e6811cb 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -72,6 +72,7 @@ constexpr std::size_t kMaxCompdbArguments = 256U; constexpr std::size_t kMaxCompdbArgumentBytes = 1024U; constexpr std::size_t kMaxCompdbEntries = 500U; constexpr std::size_t kMaxCompdbGenerations = 128U; +constexpr std::size_t kMaxStaleReasonBytes = 512U; constexpr std::size_t kMaxActionOutputs = 8U; constexpr std::size_t kMaxActionLimit = 1000U; constexpr std::size_t kMaxPendingChanges = 4096U; @@ -1194,6 +1195,32 @@ std::string compdb_generations_project(const DaemonOptions &options, return serialize_response(JsonValue{std::move(object)}); } +// Marks a profile's editor metadata stale while retaining the last valid compile_commands.json. +std::string compdb_stale_project(const DaemonOptions &options, std::string_view profile_name, + std::string_view reason) { + const bool valid_profile = + !profile_name.empty() && profile_name.size() <= 128 && + std::ranges::all_of(profile_name, [](char c) { + return std::isalnum(static_cast(c)) || c == '.' || c == '_' || c == '-'; + }); + if (!valid_profile) { + return error_response("compdb_stale: profile must be 1-128 chars of [A-Za-z0-9._-]"); + } + + auto marked = Editor::mark_profile_stale(options.build_root, std::string{profile_name}, + Editor::GenerationStatus::Stale, reason); + if (!marked) { + return error_response(std::format("compdb_stale: {}", marked.error().format())); + } + + JsonValue::Object object; + object.emplace("ok", JsonValue{true}); + object.emplace("op", JsonValue{std::string{"compdb_stale"}}); + object.emplace("profile", JsonValue{std::string{profile_name}}); + object.emplace("status", JsonValue{std::string{"stale"}}); + return serialize_response(JsonValue{std::move(object)}); +} + std::string_view action_kind_label(Graph::ActionKind kind) noexcept { switch (kind) { case Graph::ActionKind::Compile: @@ -2186,6 +2213,25 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view } return {compdb_generations_project(options, *value), false}; } + if (*name == "compdb_stale") { + const auto entry = object->find("profile"); + if (entry == object->end()) { + return {error_response("compdb_stale requires \"profile\""), false}; + } + const auto *value = std::get_if(&entry->second.value); + if (value == nullptr || value->empty() || value->size() > kMaxDescribeProfileBytes) { + return {error_response("\"profile\" must be a bounded non-empty string"), false}; + } + std::string reason; + if (const auto reason_entry = object->find("reason"); reason_entry != object->end()) { + const auto *reason_value = std::get_if(&reason_entry->second.value); + if (reason_value == nullptr || reason_value->size() > kMaxStaleReasonBytes) { + return {error_response("\"reason\" must be a bounded string"), false}; + } + reason = *reason_value; + } + return {compdb_stale_project(options, *value, reason), false}; + } if (*name == "compdb_entries") { std::string file_filter; if (const auto entry = object->find("file"); entry != object->end()) { diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index 0226b5f..3e01a0f 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -1172,6 +1172,99 @@ void build(Void::Build::Project &project) { Void::Testing::expect(!bool_field(*invalid, "ok", true)); } +VOID_TEST(Daemon, compdb_stale_marks_generation_stale) { + auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); + Void::Testing::require(temp.has_value()); + const auto options = make_options(temp->path()); + + { + std::ofstream descriptor{options.project_root / "build.cpp"}; + descriptor << R"cpp(#include + +void build(Void::Build::Project &project) { + auto app = project.executable("app"); + app.sources({"main.cpp"}); +} +)cpp"; + Void::Testing::require(descriptor.good()); + } + { + std::ofstream source{options.project_root / "main.cpp"}; + source << "int main() { return 0; }\n"; + Void::Testing::require(source.good()); + } + + auto server = Void::Build::Daemon::DaemonServer::create(options); + Void::Testing::require(server.has_value()); + const auto socket = server->socket_path(); + + Void::Result::Result run_result; + std::jthread worker{[&] { run_result = server->run(); }}; + Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5})); + + auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120}); + Void::Testing::require(exported.has_value()); + Void::Testing::expect(bool_field(*exported, "ok")); + + std::string generation_id; + { + auto valid = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})", + std::chrono::seconds{120}); + Void::Testing::require(valid.has_value()); + Void::Testing::expect(bool_field(*valid, "ok")); + const auto *generations = field(*valid, "generations"); + Void::Testing::require(generations != nullptr); + const auto *array = std::get_if(&generations->value); + Void::Testing::require(array != nullptr && !array->empty()); + const auto *first = std::get_if(&array->front().value); + Void::Testing::require(first != nullptr); + Void::Testing::expect_eq(str_field(*first, "status"), std::string{"valid"}); + generation_id = str_field(*first, "id"); + } + + auto stale = + request_object(socket, R"({"op":"compdb_stale","profile":"debug","reason":"manual"})"); + Void::Testing::require(stale.has_value()); + Void::Testing::expect(bool_field(*stale, "ok")); + Void::Testing::expect_eq(str_field(*stale, "op"), std::string{"compdb_stale"}); + Void::Testing::expect_eq(str_field(*stale, "profile"), std::string{"debug"}); + Void::Testing::expect_eq(str_field(*stale, "status"), std::string{"stale"}); + + { + auto refreshed = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})", + std::chrono::seconds{120}); + Void::Testing::require(refreshed.has_value()); + Void::Testing::expect(bool_field(*refreshed, "ok")); + const auto *generations = field(*refreshed, "generations"); + Void::Testing::require(generations != nullptr); + const auto *array = std::get_if(&generations->value); + Void::Testing::require(array != nullptr && !array->empty()); + const auto *first = std::get_if(&array->front().value); + Void::Testing::require(first != nullptr); + Void::Testing::expect_eq(str_field(*first, "id"), generation_id); + Void::Testing::expect_eq(str_field(*first, "status"), std::string{"stale"}); + Void::Testing::expect(str_field(*first, "diagnostic").find("manual") != std::string::npos); + } + + auto invalid_profile = request_object(socket, R"({"op":"compdb_stale","profile":"../x"})"); + Void::Testing::require(invalid_profile.has_value()); + Void::Testing::expect(!bool_field(*invalid_profile, "ok", true)); + + auto missing_profile = request_object(socket, R"({"op":"compdb_stale"})"); + Void::Testing::require(missing_profile.has_value()); + Void::Testing::expect(!bool_field(*missing_profile, "ok", true)); + + auto invalid_reason = + request_object(socket, R"({"op":"compdb_stale","profile":"debug","reason":1})"); + Void::Testing::require(invalid_reason.has_value()); + Void::Testing::expect(!bool_field(*invalid_reason, "ok", true)); + + auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})"); + Void::Testing::expect(shutdown.has_value()); + worker.join(); + Void::Testing::expect(run_result.has_value()); +} + VOID_TEST(Daemon, info_reports_daemon_paths_and_host) { auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); Void::Testing::require(temp.has_value()); diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 293f8c2..21daf52 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -272,6 +272,17 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest auto anon_dl = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg/1.0.0/download"); Void::Testing::expect(anon_dl.has_value() && anon_dl->status == 401); + // HEAD returns the GET headers (including Content-Length) without a body. + auto head_dl = send_loopback_http(port, "HEAD", "/api/v1/packages/secret-pkg/1.0.0/download", + {{"Authorization", "Bearer " + *alice_tok}}); + Void::Testing::expect(head_dl.has_value() && head_dl->status == 200); + if (head_dl) { + Void::Testing::expect(head_dl->body.empty()); + Void::Testing::expect(head_dl->headers.contains("content-length")); + Void::Testing::expect(head_dl->headers.at("content-length") != "0"); + Void::Testing::expect(head_dl->headers.contains("x-content-sha256")); + } + // Idempotent same-bytes republish -> 200 OK! auto idemp = send_loopback_http( port, "PUT", "/api/v1/packages/secret-pkg/1.0.0", @@ -846,6 +857,13 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ if (downloaded) { Void::Testing::expect(downloaded->body == artifact); } + auto head_binary = send_loopback_http(port, "HEAD", binary_path + "/download"); + Void::Testing::expect(head_binary.has_value() && head_binary->status == 200); + if (head_binary) { + Void::Testing::expect(head_binary->body.empty()); + Void::Testing::expect_eq(head_binary->headers.at("content-length"), + std::to_string(artifact.size())); + } auto conflict = send_loopback_http( port, "PUT", binary_path,