feat(daemon): report per-unit compile arguments; deepen registry search tests
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 8s

This commit is contained in:
faumaray committed 2026-12-04 04:38:05 +03:00
1 parent 2b18a0331a
commit 624016d904
9 files changed
+335 -27

No files matched your search

+1
View File
@@ -76,6 +76,7 @@ check_process(0 "Usage: vbs daemon deps .*--profile" "" daemon deps --help)
check_process(0 "Usage: vbs daemon info " "" daemon info --help)
check_process(0 "Usage: vbs daemon clean " "" daemon clean --help)
check_process(0 "Usage: vbs daemon target info .*--name" "" daemon target info --help)
check_process(0 "Usage: vbs daemon target flags .*--name.*--file" "" daemon target flags --help)
check_process(0 "Usage: vbs daemon pack .*--output" "" daemon pack --help)
check_process(0 "Usage: vbs daemon actions .*--limit" "" daemon actions --help)
check_process(0 "Usage: vbs daemon install .*--prefix" "" daemon install --help)
+69
View File
@@ -1631,6 +1631,75 @@ VOID_TEST(Daemon, init_scaffolds_project_confined_to_root) {
Void::Testing::expect(!bool_field(*escaped, "ok", true));
}
VOID_TEST(Daemon, target_flags_reports_compile_units) {
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.hpp>
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<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 all = request_object(socket, R"({"op":"target_flags","target":"app"})",
std::chrono::seconds{120});
auto filtered = request_object(
socket, R"({"op":"target_flags","target":"app","file":"nope.cpp"})",
std::chrono::seconds{120});
auto unknown = request_object(socket, R"({"op":"target_flags","target":"nope"})",
std::chrono::seconds{120});
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(all.has_value());
Void::Testing::expect(bool_field(*all, "ok"));
Void::Testing::expect_eq(str_field(*all, "target"), std::string{"app"});
const auto *units = field(*all, "units");
Void::Testing::require(units != nullptr);
const auto *unit_array = std::get_if<JsonValue::Array>(&units->value);
Void::Testing::require(unit_array != nullptr && !unit_array->empty());
const auto *first = std::get_if<JsonObject>(&unit_array->front().value);
Void::Testing::require(first != nullptr);
Void::Testing::expect(str_field(*first, "source").find("main.cpp") != std::string::npos);
const auto *arguments = field(*first, "arguments");
Void::Testing::require(arguments != nullptr);
const auto *argument_array = std::get_if<JsonValue::Array>(&arguments->value);
Void::Testing::require(argument_array != nullptr && !argument_array->empty());
Void::Testing::require(filtered.has_value());
Void::Testing::expect(bool_field(*filtered, "ok"));
const auto *filtered_units = field(*filtered, "units");
Void::Testing::require(filtered_units != nullptr);
const auto *filtered_array = std::get_if<JsonValue::Array>(&filtered_units->value);
Void::Testing::require(filtered_array != nullptr);
Void::Testing::expect(filtered_array->empty());
Void::Testing::require(unknown.has_value());
Void::Testing::expect(!bool_field(*unknown, "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());
+111
View File
@@ -320,6 +320,117 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
}
Void::Testing::expect(name_occurrences == 1);
}
const auto first_package_name = [](const std::string &body) {
const std::string key = "\"name\":\"";
const auto start = body.find(key);
if (start == std::string::npos) {
return std::string{};
}
const auto value_start = start + key.size();
const auto end = body.find('"', value_start);
return end == std::string::npos ? std::string{}
: body.substr(value_start, end - value_start);
};
const auto envelope_value = [](const std::string &body, const std::string &key) {
const std::string token = "\"" + key + "\":";
const auto start = body.find(token);
if (start == std::string::npos) {
return std::string{};
}
const auto value_start = start + token.size();
const auto end = body.find_first_of(",}", value_start);
return body.substr(value_start, end - value_start);
};
const auto count_occurrences = [](const std::string &body, const std::string &token) {
std::size_t count = 0;
for (std::size_t pos = body.find(token); pos != std::string::npos;
pos = body.find(token, pos + 1)) {
++count;
}
return count;
};
// Offset pagination moves to a different package while preserving the total.
auto page_first = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=0");
auto page_second = send_loopback_http(port, "GET", "/api/v1/packages?limit=1&offset=1");
Void::Testing::expect(page_first.has_value() && page_first->status == 200);
Void::Testing::expect(page_second.has_value() && page_second->status == 200);
if (page_first && page_second) {
const auto first_name = first_package_name(page_first->body);
const auto second_name = first_package_name(page_second->body);
Void::Testing::expect(!first_name.empty() && !second_name.empty());
Void::Testing::expect(first_name != second_name);
Void::Testing::expect_eq(envelope_value(page_first->body, "total"), std::string{"2"});
Void::Testing::expect_eq(envelope_value(page_first->body, "limit"), std::string{"1"});
Void::Testing::expect_eq(envelope_value(page_first->body, "offset"), std::string{"0"});
Void::Testing::expect_eq(envelope_value(page_second->body, "total"), std::string{"2"});
Void::Testing::expect_eq(envelope_value(page_second->body, "limit"), std::string{"1"});
Void::Testing::expect_eq(envelope_value(page_second->body, "offset"), std::string{"1"});
Void::Testing::expect(count_occurrences(page_first->body, "\"name\":") == 1);
Void::Testing::expect(count_occurrences(page_second->body, "\"name\":") == 1);
}
// Search filtering matches the package name...
auto name_search =
send_loopback_http(port, "GET", "/api/v1/packages?q=secret", {{"Cookie", cookie}});
Void::Testing::expect(name_search.has_value() && name_search->status == 200);
if (name_search) {
Void::Testing::expect(name_search->body.find("secret-pkg") != std::string::npos);
Void::Testing::expect(name_search->body.find("demo-pkg") == std::string::npos);
Void::Testing::expect(name_search->body.find("\"total\":") != std::string::npos);
}
auto public_name_search = send_loopback_http(port, "GET", "/api/v1/packages?q=signed");
Void::Testing::expect(public_name_search.has_value() && public_name_search->status == 200);
if (public_name_search) {
Void::Testing::expect(public_name_search->body.find("signed-pkg") != std::string::npos);
Void::Testing::expect(public_name_search->body.find("\"total\":1") != std::string::npos);
std::size_t name_occurrences = 0;
for (std::size_t pos = public_name_search->body.find("\"name\":"); pos != std::string::npos;
pos = public_name_search->body.find("\"name\":", pos + 1)) {
++name_occurrences;
}
Void::Testing::expect(name_occurrences == 1);
}
// ...and the package description.
auto description_search =
send_loopback_http(port, "GET", "/api/v1/packages?q=alert", {{"Cookie", cookie}});
Void::Testing::expect(description_search.has_value() && description_search->status == 200);
if (description_search) {
Void::Testing::expect(description_search->body.find("secret-pkg") != std::string::npos);
Void::Testing::expect(description_search->body.find("\"total\":1") != std::string::npos);
}
// A query matching neither a name nor a description yields an empty page.
auto no_match_search = send_loopback_http(port, "GET", "/api/v1/packages?q=does-not-exist");
Void::Testing::expect(no_match_search.has_value() && no_match_search->status == 200);
if (no_match_search) {
Void::Testing::expect(no_match_search->body.find("\"packages\":[]") != std::string::npos);
Void::Testing::expect(no_match_search->body.find("\"total\":0") != std::string::npos);
}
// An offset past the last package yields an empty page with the total intact.
auto far_page = send_loopback_http(port, "GET", "/api/v1/packages?offset=99");
Void::Testing::expect(far_page.has_value() && far_page->status == 200);
if (far_page) {
Void::Testing::expect(far_page->body.find("\"packages\":[]") != std::string::npos);
Void::Testing::expect_eq(envelope_value(far_page->body, "total"), std::string{"2"});
Void::Testing::expect_eq(envelope_value(far_page->body, "offset"), std::string{"99"});
}
for (const std::string bad_offset_url :
{"/api/v1/packages?offset=abc", "/api/v1/packages?offset=-1",
"/api/v1/packages?offset=1000001"}) {
auto bad_offset = send_loopback_http(port, "GET", bad_offset_url);
Void::Testing::expect(bad_offset.has_value() && bad_offset->status == 400);
if (bad_offset) {
Void::Testing::expect(bad_offset->body.find("invalid_offset") != std::string::npos);
}
}
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) {
Void::Testing::expect(bad_limit_text->body.find("invalid_limit") != std::string::npos);
}
auto bad_limit = send_loopback_http(port, "GET", "/api/v1/packages?limit=501");
Void::Testing::expect(bad_limit.has_value() && bad_limit->status == 400);