From 7bd04718dfa97633a9ff869bd4fb26576956067b Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Thu, 3 Dec 2026 23:49:07 +0300 Subject: [PATCH] feat(registry): paginate package search results --- docs/agent-workflow/STATE.md | 2 +- docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 13 ++++++++ docs/roadmap/21-expansion-roadmap.md | 2 +- registry/service/RegistryService.cpp | 47 ++++++++++++++++++++++++---- tests/RegistryTests.cpp | 16 ++++++++++ 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 9d34ab8..d6af301 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- **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 +- **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- **Wave 46 (Registry Package Search Pagination)**:\n - `GET /api/v1/packages` now supports bounded `limit` (0-500, default 100) and `offset` (0-1,000,000) pagination with a `total`/`limit`/`offset` envelope; malformed values return 400.\n - The registry RBAC test asserts a `limit=1` page contains exactly one package and that `limit=501` is rejected.\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 3771692..0f0c4e6 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -52,4 +52,5 @@ Base HEAD: `fe0d1a6` | 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 | +| Wave 46 (Registry search pagination) | `GET /api/v1/packages?limit&offset` with total envelope and 400 validation | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 7/7, full CTest 8/8) | `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 35993a7..f4109c9 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -773,6 +773,19 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - Full CTest: **8 / 8 passed** in 227.61 s. - `clang-format --dry-run --Werror` passes on the changed C++ files. +## Registry Package Search Pagination (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_registry_tests --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Registry suite: **7 / 7 passed** in 12.57 s; `GET /api/v1/packages?limit=1` + returns exactly one package with `total`/`limit`/`offset`, and `limit=501` returns 400. +- Full CTest: **8 / 8 passed** in 225.74 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 bec8efd..41f328b 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, `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`. | +| **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, `vbs daemon compdb generations` lists editor generation history with the active selection, and registry package search supports bounded pagination. 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/registry/service/RegistryService.cpp b/registry/service/RegistryService.cpp index c135ab5..6b5f29e 100644 --- a/registry/service/RegistryService.cpp +++ b/registry/service/RegistryService.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -797,13 +798,47 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { } visible.push_back(&p); } + + std::size_t limit = 100; + std::size_t offset = 0; + const auto parse_size = [](const std::string &text, std::size_t max, std::size_t &out) { + std::size_t value = 0; + const auto [ptr, ec] = std::from_chars(text.data(), text.data() + text.size(), value); + if (ec != std::errc{} || ptr != text.data() + text.size() || value > max) { + return false; + } + out = value; + return true; + }; + if (const auto it = req.query.find("limit"); + it != req.query.end() && !parse_size(it->second, 500, limit)) { + return HttpResponse::error_json(400, "invalid_limit", + "limit must be an integer in [0, 500]"); + } + if (const auto it = req.query.find("offset"); + it != req.query.end() && !parse_size(it->second, 1000000, offset)) { + return HttpResponse::error_json(400, "invalid_offset", + "offset must be a non-negative integer"); + } + + const std::size_t total = visible.size(); + std::vector page; + for (std::size_t i = offset; i < total && page.size() < limit; ++i) { + page.push_back(visible[i]); + } return HttpResponse::json( - 200, "{\"packages\":" + json_array(visible, [](const PackageMeta *p) { - return "{\"name\":" + json_quote(p->name) + - ",\"description\":" + json_quote(p->description) + - ",\"is_private\":" + std::string{p->is_private ? "true" : "false"} + - ",\"release_count\":" + std::to_string(p->releases.size()) + '}'; - }) + "}\n"); + 200, "{\"packages\":" + + json_array(page, + [](const PackageMeta *p) { + return "{\"name\":" + json_quote(p->name) + + ",\"description\":" + json_quote(p->description) + + ",\"is_private\":" + + std::string{p->is_private ? "true" : "false"} + + ",\"release_count\":" + + std::to_string(p->releases.size()) + '}'; + }) + + ",\"total\":" + std::to_string(total) + ",\"limit\":" + std::to_string(limit) + + ",\"offset\":" + std::to_string(offset) + "}\n"); } // /api/v1/packages/[/[/download|/yank]] diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index d17bf11..89fd693 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -230,6 +230,22 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest Void::Testing::expect(audit->body.find(*alice_tok) == std::string::npos); } + // Package search pagination: bounded page plus total/limit/offset envelope. + auto page = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=0"); + Void::Testing::expect(page.has_value() && page->status == 200); + if (page) { + Void::Testing::expect(page->body.find("\"total\":") != std::string::npos); + Void::Testing::expect(page->body.find("\"limit\":1") != std::string::npos); + std::size_t name_occurrences = 0; + for (std::size_t pos = page->body.find("\"name\":"); pos != std::string::npos; + pos = page->body.find("\"name\":", pos + 1)) { + ++name_occurrences; + } + Void::Testing::expect(name_occurrences == 1); + } + auto bad_limit = send_loopback_http(port, "GET", "/api/v1/packages?limit=501"); + Void::Testing::expect(bad_limit.has_value() && bad_limit->status == 400); + // 4. Consistent backup & restore into a brand-new registry instance preserves releases & // download! const auto backup_dir = tmp / "backup";