feat(registry,daemon): report registry stats; serve daemon doctor
This commit is contained in:
1 parent
e61eff7a8f
commit
1aaece3231
8 files changed
+230
-4
No files matched your search
+112
-2
@@ -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<bool>(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<void, Void::Result::Error> 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<bool>(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<JsonValue::Array>(&tools_value->value);
|
||||
Void::Testing::require(tools != nullptr);
|
||||
Void::Testing::expect(!tools->empty());
|
||||
|
||||
bool saw_gpp = false;
|
||||
bool saw_ar = false;
|
||||
std::vector<std::string> 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<bool>(required->value));
|
||||
const auto *found = field(*tool, "found");
|
||||
Void::Testing::require(found != nullptr);
|
||||
Void::Testing::expect(std::holds_alternative<bool>(found->value));
|
||||
const auto *path = field(*tool, "path");
|
||||
Void::Testing::require(path != nullptr);
|
||||
const auto *path_text = std::get_if<std::string>(&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<bool>(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<bool>(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<bool>(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());
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user