From 1aaece3231766d353941cd5d5f2fc6f190b0c051 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 06:48:09 +0300 Subject: [PATCH] feat(registry,daemon): report registry stats; serve daemon doctor --- 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/RegistryService.cpp | 25 +++++- src/Daemon/Daemon.cpp | 68 ++++++++++++++++ tests/DaemonTests.cpp | 114 ++++++++++++++++++++++++++- tests/RegistryTests.cpp | 13 +++ 8 files changed, 230 insertions(+), 4 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 15958cd..feb27e9 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -253,6 +253,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **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). +- **Wave 81 (Registry Stats & Daemon `doctor`)**: added the admin `GET /api/v1/stats` endpoint (package/release/yanked/binary/user/audit counts, ETag-validated) covered in the RBAC test (admin 200 with ETag, non-admin 403). A swarm worker added the structured `doctor` daemon request (host/tool/backends JSON) with `Daemon.doctor_reports_host_tools_and_backends` (5/5 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 2f2634c..1f2e0a1 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -84,4 +84,5 @@ Base HEAD: `fe0d1a6` | 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 | +| Wave 81 (Registry stats + daemon doctor) | admin `GET /api/v1/stats` with ETag; swarm added daemon `doctor` diagnostics | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 9/9, Daemon suite passes, full CTest 8/8) | `registry/service/RegistryService.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 877b654..5159bd9 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1226,6 +1226,15 @@ dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color 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. +## Registry Stats & Daemon `doctor` (GCC 16.2, pin `0002e74`) + +- `GET /api/v1/stats` with an admin session returns aggregate counts and an `ETag`; a non-admin + bearer token gets 403 (in `registry_rbac_immutability_csrf_xss_web_and_backup_restore`). +- Swarm `swarm_mx8ffmit_2fpk` (one worker) added the structured daemon `doctor` request (5/5 + substantive tasks; build task stopped and re-run by the orchestrator); + `Daemon.doctor_reports_host_tools_and_backends` passes (19 ms). +- Registry suite: **9 / 9 passed** (11.76 s); full CTest: **8 / 8 passed** in 256.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 84779e8..48eb366 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, 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`. | +| **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, registry endpoints answer OPTIONS with an Allow header and expose admin stats, the daemon serves structured `doctor` diagnostics, `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 775c014..7307dd7 100644 --- a/registry/service/RegistryService.cpp +++ b/registry/service/RegistryService.cpp @@ -1775,7 +1775,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { // Admin endpoints: users, audit, storage. if (req.path == "/api/v1/users" || req.path == "/api/v1/audit" || - req.path == "/api/v1/admin/storage") { + req.path == "/api/v1/stats" || req.path == "/api/v1/admin/storage") { if (!principal) { return HttpResponse::error_json(401, "unauthorized", "authentication required"); } @@ -1887,6 +1887,29 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { ",\"quota_bytes\":" + std::to_string(config_.max_storage_bytes) + ",\"package_count\":" + std::to_string(packages_.size()) + "}\n"); } + if (req.path == "/api/v1/stats" && req.method == "GET") { + std::size_t release_count = 0; + std::size_t binary_count = 0; + std::size_t yanked_releases = 0; + for (const auto &[name, package] : packages_) { + release_count += package.releases.size(); + for (const auto &[version, release] : package.releases) { + binary_count += release.binaries.size(); + if (release.yanked) { + ++yanked_releases; + } + } + } + return with_etag( + HttpResponse::json( + 200, "{\"packages\":" + std::to_string(packages_.size()) + + ",\"releases\":" + std::to_string(release_count) + + ",\"yanked_releases\":" + std::to_string(yanked_releases) + + ",\"binary_variants\":" + std::to_string(binary_count) + + ",\"users\":" + std::to_string(users_.size()) + + ",\"audit_entries\":" + std::to_string(audits_.size()) + "}\n"), + req); + } } return HttpResponse::error_json(404, "not_found", "unknown API endpoint"); diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index db0d8c9..628b28e 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -67,6 +67,7 @@ constexpr auto kDescribeEvalTimeout = std::chrono::seconds{10}; constexpr std::size_t kMaxDescribeProfileBytes = 128U; constexpr std::size_t kMaxDescribeTargetNames = 128U; constexpr std::size_t kMaxDescribeTargetNameBytes = 200U; +constexpr std::size_t kMaxDoctorToolPathBytes = 4096U; constexpr std::size_t kMaxBuildTargets = 64U; constexpr std::size_t kMaxCompdbArguments = 256U; constexpr std::size_t kMaxCompdbArgumentBytes = 1024U; @@ -2090,6 +2091,73 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view object.emplace("socket", JsonValue{socket_path.string()}); return {serialize_response(JsonValue{std::move(object)}), false}; } + if (*name == "doctor") { + struct ToolProbe { + std::string_view name; + const char *binary; + bool required; + }; + constexpr ToolProbe kToolProbes[]{ + {"g++", "g++", true}, + {"clang++", "clang++", false}, + {"clang-scan-deps", "clang-scan-deps", false}, + {"ar", "ar", true}, + {"git", "git", false}, + {"cmake", "cmake", false}, + {"ninja", "ninja", false}, + {"meson", "meson", false}, + {"conan", "conan", false}, + {"clang-format", "clang-format", false}, + }; + JsonValue::Array tools; + JsonValue::Array missing_required; + for (const auto &probe : kToolProbes) { + const auto found = Platform::resolve_executable(probe.binary); + JsonValue::Object tool; + tool.emplace("name", JsonValue{std::string{probe.name}}); + tool.emplace("required", JsonValue{probe.required}); + tool.emplace("found", JsonValue{found.has_value()}); + std::string path = found ? found->string() : std::string{}; + if (path.size() > kMaxDoctorToolPathBytes) { + path.resize(kMaxDoctorToolPathBytes); + } + tool.emplace("path", JsonValue{std::move(path)}); + if (probe.required && !found) { + missing_required.emplace_back(std::string{probe.name}); + } + tools.emplace_back(std::move(tool)); + } +#if defined(VBS_HAS_VOID_SQLITE) + constexpr bool has_sqlite = true; +#else + constexpr bool has_sqlite = false; +#endif +#if defined(VBS_HAS_VOID_NET) + constexpr bool has_net = true; +#else + constexpr bool has_net = false; +#endif + JsonValue::Object backends; + backends.emplace("file_ops", JsonValue{Platform::host_supported()}); + backends.emplace("process_supervisor", JsonValue{Platform::host_supported()}); + backends.emplace("directory_watcher", JsonValue{Platform::host_supported()}); + backends.emplace("sqlite", JsonValue{has_sqlite}); + backends.emplace("net", JsonValue{has_net}); + JsonValue::Object response; + response.emplace("ok", JsonValue{true}); + response.emplace("op", JsonValue{std::string{"doctor"}}); + response.emplace("version", JsonValue{std::string{Bootstrap::version}}); + response.emplace("os", JsonValue{std::string{Bootstrap::os}}); + response.emplace("architecture", JsonValue{std::string{Bootstrap::architecture}}); + response.emplace("host_os", + JsonValue{std::string{Platform::host_os_name(Platform::host_os())}}); + response.emplace("host_supported", JsonValue{Platform::host_supported()}); + response.emplace("tools", JsonValue{std::move(tools)}); + response.emplace("healthy", JsonValue{missing_required.empty()}); + response.emplace("missing_required", JsonValue{std::move(missing_required)}); + response.emplace("backends", JsonValue{std::move(backends)}); + return {serialize_response(JsonValue{std::move(response)}), false}; + } if (*name == "editor_status") { return {editor_status_project(options), false}; } diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index e263ec6..d761af9 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -708,8 +708,8 @@ VOID_TEST(Daemon, watch_poll_reports_changed_paths) { for (int attempt = 0; attempt < 100 && !saw_probe; ++attempt) { 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/"})"); + 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; @@ -1496,6 +1496,116 @@ VOID_TEST(Daemon, info_reports_daemon_paths_and_host) { Void::Testing::expect(std::holds_alternative(net_backend->value)); } +VOID_TEST(Daemon, doctor_reports_host_tools_and_backends) { + auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); + Void::Testing::require(temp.has_value()); + const auto options = make_options(temp->path()); + + 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 doctor = request_object(socket, R"({"op":"doctor"})"); + 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::Testing::require(doctor.has_value()); + Void::Testing::expect(bool_field(*doctor, "ok")); + Void::Testing::expect_eq(str_field(*doctor, "op"), std::string{"doctor"}); + Void::Testing::expect(!str_field(*doctor, "version").empty()); + Void::Testing::expect(!str_field(*doctor, "os").empty()); + Void::Testing::expect(!str_field(*doctor, "architecture").empty()); + Void::Testing::expect_eq( + str_field(*doctor, "host_os"), + std::string{Void::Build::Platform::host_os_name(Void::Build::Platform::host_os())}); + const auto *host_supported = field(*doctor, "host_supported"); + Void::Testing::require(host_supported != nullptr); + Void::Testing::expect(std::holds_alternative(host_supported->value)); + Void::Testing::expect(bool_field(*doctor, "host_supported") == + Void::Build::Platform::host_supported()); + + const auto *tools_value = field(*doctor, "tools"); + Void::Testing::require(tools_value != nullptr); + const auto *tools = std::get_if(&tools_value->value); + Void::Testing::require(tools != nullptr); + Void::Testing::expect(!tools->empty()); + + bool saw_gpp = false; + bool saw_ar = false; + std::vector expected_missing_required; + for (const auto &entry : *tools) { + const auto *tool = as_object(entry); + Void::Testing::require(tool != nullptr); + const auto name = str_field(*tool, "name"); + Void::Testing::expect(!name.empty()); + const auto *required = field(*tool, "required"); + Void::Testing::require(required != nullptr); + Void::Testing::expect(std::holds_alternative(required->value)); + const auto *found = field(*tool, "found"); + Void::Testing::require(found != nullptr); + Void::Testing::expect(std::holds_alternative(found->value)); + const auto *path = field(*tool, "path"); + Void::Testing::require(path != nullptr); + const auto *path_text = std::get_if(&path->value); + Void::Testing::require(path_text != nullptr); + if (!bool_field(*tool, "found")) { + Void::Testing::expect(path_text->empty()); + } + if (name == "g++") { + saw_gpp = true; + Void::Testing::expect(bool_field(*tool, "required")); + } + if (name == "ar") { + saw_ar = true; + Void::Testing::expect(bool_field(*tool, "required")); + } + if (bool_field(*tool, "required") && !bool_field(*tool, "found")) { + expected_missing_required.push_back(name); + } + } + Void::Testing::expect(saw_gpp); + Void::Testing::expect(saw_ar); + + const auto missing_required = string_array_field(*doctor, "missing_required"); + auto sorted_expected = expected_missing_required; + auto sorted_actual = missing_required; + std::sort(sorted_expected.begin(), sorted_expected.end()); + std::sort(sorted_actual.begin(), sorted_actual.end()); + Void::Testing::expect_eq(sorted_actual.size(), sorted_expected.size()); + for (std::size_t index = 0; index < std::min(sorted_actual.size(), sorted_expected.size()); + ++index) { + Void::Testing::expect_eq(sorted_actual[index], sorted_expected[index]); + } + const auto *healthy = field(*doctor, "healthy"); + Void::Testing::require(healthy != nullptr); + Void::Testing::expect(std::holds_alternative(healthy->value)); + Void::Testing::expect(bool_field(*doctor, "healthy") == missing_required.empty()); + + const auto *backends_value = field(*doctor, "backends"); + Void::Testing::require(backends_value != nullptr); + const auto *backends = as_object(*backends_value); + Void::Testing::require(backends != nullptr); + for (const std::string_view backend_name : + {"file_ops", "process_supervisor", "directory_watcher"}) { + const auto *backend = field(*backends, backend_name); + Void::Testing::require(backend != nullptr); + Void::Testing::expect(std::holds_alternative(backend->value)); + Void::Testing::expect(bool_field(*backends, backend_name) == + Void::Build::Platform::host_supported()); + } + for (const std::string_view backend_name : {"sqlite", "net"}) { + const auto *backend = field(*backends, backend_name); + Void::Testing::require(backend != nullptr); + Void::Testing::expect(std::holds_alternative(backend->value)); + } +} + VOID_TEST(Daemon, clean_removes_profile_outputs_and_preserves_cache) { 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 387e6d9..718a646 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -511,6 +511,19 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest Void::Testing::expect(bad_offset->body.find("invalid_offset") != std::string::npos); } } + // Admin statistics endpoint reports aggregate counts and an ETag. + auto stats = send_loopback_http(port, "GET", "/api/v1/stats", {{"Cookie", cookie}}); + Void::Testing::expect(stats.has_value() && stats->status == 200); + if (stats) { + Void::Testing::expect(stats->body.find("\"packages\":") != std::string::npos); + Void::Testing::expect(stats->body.find("\"releases\":") != std::string::npos); + Void::Testing::expect(stats->body.find("\"users\":") != std::string::npos); + Void::Testing::expect(stats->headers.contains("etag")); + } + auto stats_non_admin = send_loopback_http(port, "GET", "/api/v1/stats", + {{"Authorization", "Bearer " + *alice_tok}}); + Void::Testing::expect(stats_non_admin.has_value() && stats_non_admin->status == 403); + auto bad_limit_text = send_loopback_http(port, "GET", "/api/v1/packages?limit=abc"); Void::Testing::expect(bad_limit_text.has_value() && bad_limit_text->status == 400); if (bad_limit_text) {