diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 0d3c107..9d34ab8 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -173,7 +173,7 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - Added the `compdb_entries` daemon request (`vbs daemon compdb entries [--file SUFFIX] [--limit N]`): reads the active published compilation database (selection state or root alias), returns bounded projected entries (`file`, `directory`, `output`, `command`, bounded `arguments`), reports `total`/`returned`, and errors explicitly when nothing is published. - Added `Daemon.compdb_entries_queries_published_database` (unpublished → error, then all entries, a `main.cpp` filter with `limit:1`, and an invalid limit) and a CLI help contract; Daemon suite is now 18 cases. -- **Wave 40 (Authenticated Binary-Variant Downloads)**:\n - `download_binary_artifact` now accepts `RegistryAuth` and sends the bearer token, so private registry binary artifacts can be fetched; `BinaryFetchOptions` gained `bearer_token` and `materialize_binary_variant` forwards it; `vbs binaries fetch` passes the configured token.\n - Added `RegistryTests.private_binary_variant_download_requires_auth`: anonymous download of a private binary → 401, authenticated client download and signed materialization succeed.\n\n- **Wave 41 (Yanked Binary Variants in Listing)**:\n - `fetch_binary_variants` gained `include_yanked` (default false, so selection/materialization still never sees yanked variants); `vbs binaries list` opts in and marks yanked entries while `binaries fetch` keeps the filtered view.\n - Extended the registry binary-variant test to assert the yanked variant is returned with `yanked=true` only when requested.\n\n- **Wave 42 (Registry Binary-Variant Listing Endpoint)**:\n - Added `GET /api/v1/packages///binaries` returning the release's binary variants (`variant_id`, `sha256`, `size_bytes`, `yanked`, optional signature/public key) under normal read permissions; `RegistryClient::fetch_binary_variants` now queries this endpoint directly instead of parsing package detail JSON.\n - The registry binary-variant test asserts the listing endpoint returns the published variant with `yanked:false`.\n\n- **Wave 43 (Workspace Members Request)**:\n - Added the `workspace_members` daemon request (`vbs daemon workspace members`): lists declared workspace members (`name`, canonical `path`) without evaluating member build descriptions; non-workspace roots return `workspace:false` with an empty list.\n - Added `Daemon.workspace_members_lists_declared_members` and a CLI help contract; Daemon suite is now 19 cases.\n\n- **Wave 44 (IDE Configs Request)**:\n - Added the `ide_configs` daemon request (`vbs daemon ide configs`): reports presence of `.clangd`, `.vscode/tasks.json`, `.zed/tasks.json`, and `.idea/customTargets.xml` so editor extensions can see what is configured.\n - Added `Daemon.ide_configs_reports_generated_files` (absent before generation, present after `ide_generate`) and a CLI help contract; Daemon suite is now 20 cases.\n\n## Remaining future scope +- **Wave 40 (Authenticated Binary-Variant Downloads)**:\n - `download_binary_artifact` now accepts `RegistryAuth` and sends the bearer token, so private registry binary artifacts can be fetched; `BinaryFetchOptions` gained `bearer_token` and `materialize_binary_variant` forwards it; `vbs binaries fetch` passes the configured token.\n - Added `RegistryTests.private_binary_variant_download_requires_auth`: anonymous download of a private binary → 401, authenticated client download and signed materialization succeed.\n\n- **Wave 41 (Yanked Binary Variants in Listing)**:\n - `fetch_binary_variants` gained `include_yanked` (default false, so selection/materialization still never sees yanked variants); `vbs binaries list` opts in and marks yanked entries while `binaries fetch` keeps the filtered view.\n - Extended the registry binary-variant test to assert the yanked variant is returned with `yanked=true` only when requested.\n\n- **Wave 42 (Registry Binary-Variant Listing Endpoint)**:\n - Added `GET /api/v1/packages///binaries` returning the release's binary variants (`variant_id`, `sha256`, `size_bytes`, `yanked`, optional signature/public key) under normal read permissions; `RegistryClient::fetch_binary_variants` now queries this endpoint directly instead of parsing package detail JSON.\n - The registry binary-variant test asserts the listing endpoint returns the published variant with `yanked:false`.\n\n- **Wave 43 (Workspace Members Request)**:\n - Added the `workspace_members` daemon request (`vbs daemon workspace members`): lists declared workspace members (`name`, canonical `path`) without evaluating member build descriptions; non-workspace roots return `workspace:false` with an empty list.\n - Added `Daemon.workspace_members_lists_declared_members` and a CLI help contract; Daemon suite is now 19 cases.\n\n- **Wave 44 (IDE Configs Request)**:\n - Added the `ide_configs` daemon request (`vbs daemon ide configs`): reports presence of `.clangd`, `.vscode/tasks.json`, `.zed/tasks.json`, and `.idea/customTargets.xml` so editor extensions can see what is configured.\n - Added `Daemon.ide_configs_reports_generated_files` (absent before generation, present after `ide_generate`) and a CLI help contract; Daemon suite is now 20 cases.\n\n- **Wave 45 (Compdb Generations Request)**:\n - Added the `compdb_generations` daemon request (`vbs daemon compdb generations --profile`): lists immutable editor generations (bounded 128) with active flag, per-generation entry counts, and the per-profile status/diagnostic record; profile names are validated against `[A-Za-z0-9._-]` to prevent traversal.\n - Added `Daemon.compdb_generations_lists_history_and_active_generation` (empty before export, then a valid generation with entries and an active selection; invalid profile rejected) and a CLI help contract; Daemon suite is now 21 cases.\n\n## 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 87207be..3771692 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -51,4 +51,5 @@ Base HEAD: `fe0d1a6` | Wave 42 (Registry binary listing endpoint) | `GET .../binaries` listing endpoint; client queries it directly | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 7/7, full CTest 8/8) | `registry/service/RegistryService.cpp`, `src/Package/RegistryClient.cpp`, `tests/RegistryTests.cpp`, docs | | Wave 43 (Workspace members request) | `workspace_members` daemon request + `vbs daemon workspace members`: lightweight member listing | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 19/19, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 44 (IDE configs request) | `ide_configs` daemon request + `vbs daemon ide configs`: presence of editor config files | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 20/20, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | +| Wave 45 (Compdb generations request) | `compdb_generations` daemon request + `vbs daemon compdb generations --profile`: generation history, active id, status/entry counts, validated profile names | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 21/21, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, 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 ef8ef31..35993a7 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -759,6 +759,20 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - Full CTest: **8 / 8 passed** in 228.03 s. - `clang-format --dry-run --Werror` passes on the changed C++ files. +## Compdb Generations Request (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Daemon suite: **21 / 21 passed** in 42.89 s, including + `compdb_generations_lists_history_and_active_generation`: empty before export, then one valid + generation with `entries >= 1` and an active selection; `profile:"../x"` is rejected. +- Full CTest: **8 / 8 passed** in 227.61 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 3005a09..bec8efd 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 compdb entries` serves bounded per-file compile arguments to editor extensions, `vbs daemon workspace members` lists workspace members cheaply, and `vbs daemon ide configs` reports which editor configuration files exist. 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, `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 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, and `vbs daemon compdb generations` lists editor generation history with the active selection. 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** | 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. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains. | --- diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 2e21e56..2bff37b 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,7 @@ constexpr std::size_t kMaxBuildTargets = 64U; 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 kMaxPendingChanges = 4096U; constexpr std::int64_t kMaxWatchWaitMs = 5000; constexpr std::int64_t kDefaultWatchWaitMs = 2000; @@ -950,6 +952,109 @@ std::string graph_project(const DaemonOptions &options, std::string_view profile ",\"graph\":" + Util::json_quote(rendered) + '}'; } +// Lists immutable editor generations for a profile, including the active selection. +std::string compdb_generations_project(const DaemonOptions &options, + std::string_view profile_name) { + 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_generations: profile must be 1-128 chars of [A-Za-z0-9._-]"); + } + + const auto profile_dir = options.build_root / "profiles" / std::string{profile_name} / "editor"; + const auto generation_root = profile_dir / "generations"; + std::string active_generation; + auto selection = Editor::read_selection_state(options.project_root); + if (selection && selection->has_value()) { + active_generation = (*selection)->selected_generation_id; + } + + // The per-profile status record describes the most recently published generation. + std::string status_generation; + std::string status_value{"unknown"}; + std::string status_diagnostic; + std::int64_t status_entries = 0; + if (auto text = Void::FileSystem::read_file(profile_dir / "status.json"); text) { + if (auto parsed = Void::Json::Strict::parse(*text); parsed) { + if (const auto *object = std::get_if(&parsed->value)) { + const auto read_string = [&](std::string_view key, std::string &out) { + if (const auto it = object->find(key); it != object->end()) { + if (const auto *value = std::get_if(&it->second.value)) { + out = *value; + } + } + }; + read_string("generation_id", status_generation); + read_string("status", status_value); + read_string("diagnostic", status_diagnostic); + if (const auto it = object->find("entry_count"); it != object->end()) { + if (const auto *value = std::get_if(&it->second.value)) { + status_entries = *value; + } + } + } + } + } + + JsonValue::Array generations; + std::error_code ec; + if (std::filesystem::is_directory(generation_root, ec)) { + std::vector directories; + for (const auto &entry : std::filesystem::directory_iterator(generation_root, ec)) { + if (entry.is_directory()) { + directories.push_back(entry.path()); + } + } + std::ranges::sort(directories); + for (const auto &directory : directories) { + if (generations.size() >= kMaxCompdbGenerations) { + break; + } + const auto compdb = directory / "compile_commands.json"; + if (!std::filesystem::is_regular_file(compdb, ec)) { + continue; + } + const std::string generation_id = directory.filename().string(); + const bool is_status_generation = generation_id == status_generation; + JsonValue::Object generation; + generation.emplace("id", JsonValue{generation_id}); + generation.emplace("active", JsonValue{generation_id == active_generation}); + generation.emplace( + "status", JsonValue{is_status_generation ? status_value : std::string{"archived"}}); + generation.emplace("diagnostic", + JsonValue{is_status_generation ? status_diagnostic : std::string{}}); + + std::int64_t entry_count = is_status_generation ? status_entries : 0; + if (!is_status_generation) { + if (auto text = Void::FileSystem::read_file(compdb); text) { + if (auto parsed = Void::Json::Strict::parse(*text); parsed) { + if (const auto *array = std::get_if(&parsed->value)) { + entry_count = static_cast(array->size()); + } + } + } + } + generation.emplace("entries", JsonValue{entry_count}); + generations.emplace_back(std::move(generation)); + } + } + + JsonValue::Object object; + object.emplace("ok", JsonValue{true}); + object.emplace("op", JsonValue{std::string{"compdb_generations"}}); + object.emplace("profile", JsonValue{std::string{profile_name}}); + if (active_generation.empty()) { + object.emplace("active", JsonValue{nullptr}); + } else { + object.emplace("active", JsonValue{active_generation}); + } + object.emplace("generations", JsonValue{std::move(generations)}); + return serialize_response(JsonValue{std::move(object)}); +} + // Reports which editor configuration files are present for the project. std::string ide_configs_project(const DaemonOptions &options) { struct ConfigEntry { @@ -1502,6 +1607,17 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view if (*name == "ide_configs") { return {ide_configs_project(options), false}; } + if (*name == "compdb_generations") { + const auto entry = object->find("profile"); + if (entry == object->end()) { + return {error_response("compdb_generations 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}; + } + return {compdb_generations_project(options, *value), false}; + } if (*name == "compdb_entries") { std::string file_filter; if (const auto entry = object->find("file"); entry != object->end()) { diff --git a/src/Main.cpp b/src/Main.cpp index 686963d..0765919 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1569,6 +1569,13 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { request_json = R"({"op":"workspace_members"})"; } else if (sub == "ide_configs") { request_json = R"({"op":"ide_configs"})"; + } else if (sub == "compdb_generations") { + if (opts.profile_arg.empty()) { + std::cerr << "vbs daemon compdb generations: --profile must not be empty\n"; + return 2; + } + request_json = std::format(R"({{"op":"compdb_generations","profile":{}}})", + Util::json_quote(opts.profile_arg)); } else if (sub == "compdb_entries") { request_json = std::format(R"({{"op":"compdb_entries","limit":{}{}}})", opts.limit_arg, @@ -2646,6 +2653,11 @@ int main(int argc, char **argv) { daemon_opts.jobs_arg, "0"); auto &daemon_compdb_cmd = daemon_cmd.subcommand("compdb", "Editor compilation database served by the daemon"); + auto &daemon_compdb_generations_cmd = daemon_compdb_cmd.subcommand( + "generations", "List immutable editor generations for a profile"); + configure_daemon_common(daemon_compdb_generations_cmd); + daemon_compdb_generations_cmd.option_default("--profile", "-p", "Profile to inspect", + daemon_opts.profile_arg, "debug"); auto &daemon_compdb_entries_cmd = daemon_compdb_cmd.subcommand( "entries", "Query bounded compile_commands entries for editor extensions"); configure_daemon_common(daemon_compdb_entries_cmd); @@ -2839,6 +2851,9 @@ int main(int argc, char **argv) { } else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 && parsed.matched_command_path[2] == "configs") { daemon_sub = "ide_configs"; + } else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 && + parsed.matched_command_path[2] == "generations") { + daemon_sub = "compdb_generations"; } return execute_daemon_command(daemon_sub, daemon_opts); } diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 73d830f..07fd50e 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -67,6 +67,7 @@ check_process(0 "Usage: vbs daemon graph .*--format" "" daemon graph --help) check_process(0 "Usage: vbs daemon test .*--profile.*--target.*--jobs" "" daemon test --help) check_process(0 "Usage: vbs daemon workspace members " "" daemon workspace members --help) check_process(0 "Usage: vbs daemon ide configs " "" daemon ide configs --help) +check_process(0 "Usage: vbs daemon compdb generations .*--profile" "" daemon compdb generations --help) check_process(0 "Usage: vbs daemon ide wait .*--timeout-ms" "" daemon ide wait --help) check_process(2 "" "missing subcommand for 'vbs daemon'" daemon) diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index b178c2e..46c6537 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -1088,6 +1088,74 @@ void build(Void::Build::Project &project) { Void::Testing::expect(run_result.has_value()); } +VOID_TEST(Daemon, compdb_generations_lists_history_and_active_generation) { + 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 empty = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})"); + Void::Testing::require(empty.has_value()); + Void::Testing::expect(bool_field(*empty, "ok")); + Void::Testing::expect(string_array_field(*empty, "generations").empty()); + + 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")); + + auto raw = Void::Build::Daemon::request( + socket, R"({"op":"compdb_generations","profile":"debug"})", std::chrono::seconds{120}); + auto invalid = request_object(socket, R"({"op":"compdb_generations","profile":"../x"})"); + 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(raw.has_value()); + const auto parsed = parse_json(*raw); + Void::Testing::require(parsed.has_value()); + const auto *object = as_object(*parsed); + Void::Testing::require(object != nullptr); + Void::Testing::expect(bool_field(*object, "ok")); + Void::Testing::expect_eq(str_field(*object, "profile"), std::string{"debug"}); + const auto *generations = field(*object, "generations"); + Void::Testing::require(generations != nullptr); + const auto *generation_array = std::get_if(&generations->value); + Void::Testing::require(generation_array != nullptr && !generation_array->empty()); + const auto *first = std::get_if(&generation_array->front().value); + Void::Testing::require(first != nullptr); + Void::Testing::expect(str_field(*first, "status") == "valid"); + Void::Testing::expect(int_field(*first, "entries") >= 1); + Void::Testing::expect(raw->find("\"active\":\"") != std::string::npos); + + Void::Testing::require(invalid.has_value()); + Void::Testing::expect(!bool_field(*invalid, "ok", true)); +} + VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) { auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); Void::Testing::require(temp.has_value());