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") {