feat(daemon): build and run declared test targets
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 18s

This commit is contained in:
faumaray committed 2026-12-03 22:47:12 +03:00
1 parent ae57ee7666
commit afea6f3fad
9 files changed
+177 -21

No files matched your search

+84 -13
View File
@@ -9,6 +9,7 @@
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/Resolver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provenance/TrustedKeys.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/State/StateStore.hpp>
@@ -612,6 +613,23 @@ Void::Result::Result<std::size_t, std::string> materialize_project_dependencies(
// Bounded build-serving request: resolves dependencies, lowers the project graph, and executes it
// in-process against the daemon's warm StateStore.
struct TestOutcome {
std::string name;
bool passed{false};
int exit_code{-1};
std::string stdout_tail;
std::string stderr_tail;
};
constexpr std::size_t kMaxTestOutputBytes = 4096U;
std::string bounded_tail(const std::string &text) {
if (text.size() <= kMaxTestOutputBytes) {
return text;
}
return text.substr(text.size() - kMaxTestOutputBytes);
}
struct BuildOutcome {
std::string profile;
std::size_t targets{0};
@@ -623,13 +641,15 @@ struct BuildOutcome {
bool succeeded{false};
std::string diagnostic;
JsonValue::Array failed_actions;
std::vector<TestOutcome> tests;
std::size_t tests_passed{0};
std::size_t tests_failed{0};
};
Void::Result::Result<BuildOutcome, std::string>
execute_project_build(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs) {
Void::Result::Result<BuildOutcome, std::string> execute_project_build(
const DaemonOptions &options, State::StateStore &state, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs, bool run_tests) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "build");
if (!evaluated) {
return std::unexpected{evaluated.error()};
@@ -673,6 +693,43 @@ execute_project_build(const DaemonOptions &options, State::StateStore &state,
outcome.failed_actions.emplace_back(std::move(failure));
}
}
// Runs declared test targets after a successful build, mirroring `vbs test`.
if (run_tests && report->succeeded) {
for (const auto &target : graph->targets) {
if (target.kind != TargetKind::Test || target.primary_outputs.empty()) {
continue;
}
if (!selected_targets.empty() &&
!std::ranges::contains(selected_targets, target.name)) {
continue;
}
Void::Build::Platform::ProcessRequest test_request;
test_request.executable = target.primary_outputs.front();
test_request.working_directory = options.project_root;
test_request.timeout = std::chrono::seconds{300};
auto test_result = Void::Build::Platform::run_supervised(test_request);
TestOutcome test;
test.name = target.name;
if (!test_result) {
test.stderr_tail = test_result.error().message();
} else {
test.passed = test_result->succeeded();
test.exit_code = test_result->exit_code;
test.stdout_tail = bounded_tail(test_result->stdout_data);
test.stderr_tail = bounded_tail(test_result->stderr_data);
}
if (test.passed) {
++outcome.tests_passed;
} else {
++outcome.tests_failed;
}
outcome.tests.push_back(std::move(test));
}
if (outcome.tests_failed > 0) {
outcome.succeeded = false;
}
}
return outcome;
}
@@ -687,6 +744,19 @@ JsonValue::Object build_outcome_json(const BuildOutcome &outcome) {
object.emplace("failed", JsonValue{static_cast<std::int64_t>(outcome.failed)});
object.emplace("diagnostic", JsonValue{outcome.diagnostic});
object.emplace("failed_actions", JsonValue{outcome.failed_actions});
object.emplace("tests_passed", JsonValue{static_cast<std::int64_t>(outcome.tests_passed)});
object.emplace("tests_failed", JsonValue{static_cast<std::int64_t>(outcome.tests_failed)});
JsonValue::Array tests;
for (const auto &test : outcome.tests) {
JsonValue::Object entry;
entry.emplace("name", JsonValue{test.name});
entry.emplace("passed", JsonValue{test.passed});
entry.emplace("exit_code", JsonValue{static_cast<std::int64_t>(test.exit_code)});
entry.emplace("stdout", JsonValue{test.stdout_tail});
entry.emplace("stderr", JsonValue{test.stderr_tail});
tests.emplace_back(std::move(entry));
}
object.emplace("tests", JsonValue{std::move(tests)});
return object;
}
@@ -694,7 +764,7 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs,
std::string_view selected_member) {
std::string_view selected_member, bool run_tests) {
const bool workspace = Config::is_workspace_root(options.project_root);
// Workspace-wide build: every member in declared order, sharing the root lock and CAS.
@@ -710,8 +780,9 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
bool all_ok = true;
for (const auto &member : *members) {
const auto member_opts = member_options(options, member.path);
auto outcome = execute_project_build(member_opts, state, profile_name,
compiler_override, selected_targets, jobs);
auto outcome =
execute_project_build(member_opts, state, profile_name, compiler_override,
selected_targets, jobs, run_tests);
if (!outcome) {
return error_response(
std::format("build: member '{}': {}", member.name, outcome.error()));
@@ -727,7 +798,7 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
}
JsonValue::Object object;
object.emplace("ok", JsonValue{all_ok});
object.emplace("op", JsonValue{std::string{"build"}});
object.emplace("op", JsonValue{std::string{run_tests ? "test" : "build"}});
object.emplace("workspace", JsonValue{true});
object.emplace("members", JsonValue{std::move(member_array)});
object.emplace("executed", JsonValue{static_cast<std::int64_t>(executed)});
@@ -741,13 +812,13 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return error_response(std::format("build: {}", effective_result.error()));
}
auto outcome = execute_project_build(*effective_result, state, profile_name, compiler_override,
selected_targets, jobs);
selected_targets, jobs, run_tests);
if (!outcome) {
return error_response(outcome.error());
}
JsonValue::Object object = build_outcome_json(*outcome);
object.emplace("ok", JsonValue{outcome->succeeded});
object.emplace("op", JsonValue{std::string{"build"}});
object.emplace("op", JsonValue{std::string{run_tests ? "test" : "build"}});
if (workspace) {
object.emplace("member", JsonValue{std::string{selected_member}});
}
@@ -1310,7 +1381,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
object.emplace("timed_out", JsonValue{timed_out});
return {serialize_response(JsonValue{std::move(object)}), false};
}
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
if (*name == "describe" || *name == "build" || *name == "test" || *name == "ide_query" ||
*name == "ide_generate" || *name == "compdb_export" || *name == "graph") {
std::string profile_name{"debug"};
if (const auto entry = object->find("profile"); entry != object->end()) {
@@ -1417,7 +1488,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
jobs = static_cast<std::size_t>(*value);
}
return {build_project(options, state_store, profile_name, compiler_override,
selected_targets, jobs, member),
selected_targets, jobs, member, *name == "test"),
false};
}
if (*name == "shutdown") {
+14 -5
View File
@@ -1608,21 +1608,22 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
R"({{"op":"ide_query","profile":{}{}}})", Util::json_quote(opts.profile_arg),
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
: std::string{});
} else if (sub == "build") {
} else if (sub == "build" || sub == "test") {
std::size_t jobs = 0;
const auto [ptr, ec] = std::from_chars(opts.jobs_arg.data(),
opts.jobs_arg.data() + opts.jobs_arg.size(), jobs);
if (ec != std::errc{} || ptr != opts.jobs_arg.data() + opts.jobs_arg.size() || jobs > 256) {
std::cerr << "vbs daemon build: invalid --jobs value '" << opts.jobs_arg << "'\n";
std::cerr << "vbs daemon " << sub << ": invalid --jobs value '" << opts.jobs_arg
<< "'\n";
return 2;
}
if (opts.profile_arg.empty()) {
std::cerr << "vbs daemon build: --profile must not be empty\n";
std::cerr << "vbs daemon " << sub << ": --profile must not be empty\n";
return 2;
}
const std::string targets_json = Util::json_array(
opts.targets, [](const std::string &target) { return Util::json_quote(target); });
request_json = std::format(R"({{"op":"build","profile":{},"targets":{},"jobs":{}}})",
request_json = std::format(R"({{"op":"{}","profile":{},"targets":{},"jobs":{}}})", sub,
Util::json_quote(opts.profile_arg), targets_json, jobs);
} else {
std::cerr << "vbs daemon: unknown command '" << sub << "'\n";
@@ -1632,7 +1633,7 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
// Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering),
// which can exceed the 2 s default; the daemon bounds evaluation at 10 s.
const auto request_timeout =
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
(sub == "build" || sub == "test") ? std::chrono::milliseconds{std::chrono::hours{1}}
: (sub == "watch_poll" || sub == "editor_status") ? std::chrono::milliseconds{5000}
: sub == "compdb_use" ? std::chrono::milliseconds{10000}
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
@@ -2618,6 +2619,14 @@ int main(int argc, char **argv) {
.option_many("--target", "-t", "Target to build", daemon_opts.targets)
.option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)",
daemon_opts.jobs_arg, "0");
auto &daemon_test_cmd =
daemon_cmd.subcommand("test", "Build and run declared test targets via the daemon");
configure_daemon_common(daemon_test_cmd);
daemon_test_cmd
.option_default("--profile", "-p", "Profile to build", daemon_opts.profile_arg, "debug")
.option_many("--target", "-t", "Target to build/test", daemon_opts.targets)
.option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)",
daemon_opts.jobs_arg, "0");
auto &daemon_compdb_cmd =
daemon_cmd.subcommand("compdb", "Editor compilation database served by the daemon");
auto &daemon_compdb_use_cmd =