feat(test,explain,trace): repetition controls, action explanations, Chrome traces
VoidBuildSystem CI / 1 · Requirements (push) Successful in 5s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 1m54s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m50s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m48s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m8s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m1s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 40s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 16s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 19s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 6m56s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 7m3s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Successful in 4m31s
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Successful in 3m51s
VoidBuildSystem CI / 5 · Release (push) Skipped

Test runner gains CTest/Meson parity controls: --repeat
until-fail|until-pass|after-timeout[:N], --retry N, --shuffle
[--shuffle-seed N] and --stop-on-failure (which also skips the remaining
profiles).

`vbs explain` answers "why would this action run?" without executing
anything: Execution::explain_graph compares each selected action against
the CAS record (missing record, changed discovered inputs, changed or
missing outputs, restorable outputs, shared-remote-cache hits) and
reports text or JSON.

`vbs build|test --trace FILE` writes a Chrome trace (JSON) with build
phase spans (config, toolchain, eval, snapshot, graph, total) and
per-action spans from the scheduler events.

Verified: new FullV1Tests cases (repetition/shuffle/stop-on-failure and
explain/trace) pass, and the CLI contract suite passes.
This commit is contained in:
faumaray committed 2026-12-06 16:50:38 +03:00
1 parent a3afca0e5f
commit 2dec3e9259
5 files changed
+818 -33

No files matched your search

+11
View File
@@ -28,6 +28,17 @@ check_process(2 "" "unknown subcommand: invalid" invalid)
check_process(0 "Usage: vbs build .*--native-foreign.*--profile.*\\(repeatable\\)" "" build --help)
check_process(0 "Usage: vbs test " "" test --help)
check_process(2 "" "invalid --test-timeout" test --test-timeout 0)
check_process(0 "Usage: vbs test .*--repeat" "" test --help)
check_process(0 "--shuffle" "" test --help)
check_process(0 "--stop-on-failure" "" test --help)
check_process(0 "Usage: vbs explain " "" explain --help)
check_process(0 "--format" "" explain --help)
check_process(2 "" "unsupported --format" explain --format xml)
check_process(0 "--trace" "" build --help)
check_process(2 "" "invalid --repeat mode" test --repeat bogus)
check_process(2 "" "invalid --repeat count" test --repeat until-pass:0)
check_process(2 "" "invalid --retry value" test --retry 99)
check_process(2 "" "invalid --shuffle-seed" test --shuffle --shuffle-seed abc)
check_process(0 "Usage: vbs init " "" init --help)
check_process(0 "Usage: vbs clean " "" clean --help)
check_process(0 "Usage: vbs doctor " "" doctor --help)
+269
View File
@@ -3800,3 +3800,272 @@ class DemoPkg(ConanFile):
Void::Testing::expect(found_install_output);
}
}
// === Test-runner parity: repetition controls, shuffle and stop-on-failure ===
VOID_TEST(FullV1Tests, test_repeat_retry_shuffle_and_stop_on_failure) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_repeat_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.test("t_fail")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/fail.cpp"});
p.test("t_pass")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/pass.cpp"});
p.test("t_flaky")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/flaky.cpp"});
}
)cpp");
write_file(proj / "tests" / "fail.cpp",
"#include <fstream>\n"
"int main() {\n"
" std::ofstream log{\"order.log\", std::ios::app};\n"
" log << \"fail\\n\";\n"
" return 1;\n"
"}\n");
write_file(proj / "tests" / "pass.cpp",
"#include <fstream>\n"
"int main() {\n"
" std::ofstream log{\"order.log\", std::ios::app};\n"
" log << \"pass\\n\";\n"
" return 0;\n"
"}\n");
// Fails on its first invocation, passes afterwards (state in the project directory,
// which is the working directory of every test run).
write_file(proj / "tests" / "flaky.cpp",
"#include <fstream>\n"
"#include <string>\n"
"int main() {\n"
" int prior = 0;\n"
" { std::ifstream in{\"flaky.count\"}; std::string line; while (std::getline(in, line)) ++prior; }\n"
" { std::ofstream out{\"flaky.count\", std::ios::app}; out << \"run\\n\"; }\n"
" { std::ofstream log{\"order.log\", std::ios::app}; log << \"flaky\\n\"; }\n"
" return prior == 0 ? 1 : 0;\n"
"}\n");
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
req.timeout = std::chrono::seconds{300};
return Platform::run_supervised(req);
};
const auto count_in_log = [&](std::string_view needle) {
const auto text = Void::FileSystem::read_file(proj / "order.log");
if (!text) {
return std::size_t{0};
}
std::size_t count = 0;
for (std::size_t pos = text->find(needle); pos != std::string::npos;
pos = text->find(needle, pos + needle.size())) {
++count;
}
return count;
};
const auto reset_logs = [&] {
std::error_code ec;
std::filesystem::remove(proj / "order.log", ec);
std::filesystem::remove(proj / "flaky.count", ec);
};
// until-pass: the flaky test must be retried until it passes.
reset_logs();
auto until_pass = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "t_flaky", "--jobs", "1", "--repeat", "until-pass:3"});
Void::Testing::expect(until_pass.has_value() && until_pass->succeeded());
Void::Testing::expect_eq(count_in_log("flaky"), std::size_t{2});
// --retry: the same recovery without a repeat policy.
reset_logs();
auto retry = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "t_flaky", "--jobs", "1", "--retry", "2"});
Void::Testing::expect(retry.has_value() && retry->succeeded());
Void::Testing::expect_eq(count_in_log("flaky"), std::size_t{2});
// until-fail: a passing test must run N times.
reset_logs();
auto until_fail = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "t_pass", "--jobs", "1", "--repeat", "until-fail:3"});
Void::Testing::expect(until_fail.has_value() && until_fail->succeeded());
Void::Testing::expect_eq(count_in_log("pass"), std::size_t{3});
// --shuffle with a fixed seed is deterministic and still runs every selected test.
reset_logs();
auto shuffled = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "t_pass", "--target", "t_flaky", "--jobs", "1",
"--shuffle", "--shuffle-seed", "42", "--retry", "1"});
Void::Testing::expect(shuffled.has_value() && shuffled->succeeded());
const auto first_order = Void::FileSystem::read_file(proj / "order.log");
Void::Testing::require(first_order.has_value());
reset_logs();
auto shuffled_again = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--target", "t_pass", "--target", "t_flaky", "--jobs", "1",
"--shuffle", "--shuffle-seed", "42", "--retry", "1"});
Void::Testing::expect(shuffled_again.has_value() && shuffled_again->succeeded());
const auto second_order = Void::FileSystem::read_file(proj / "order.log");
Void::Testing::require(second_order.has_value());
Void::Testing::expect(*first_order == *second_order);
// --stop-on-failure: t_fail is declared first, so with one job nothing else runs.
reset_logs();
auto stopped = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--jobs", "1", "--stop-on-failure"});
Void::Testing::expect(stopped.has_value() && !stopped->succeeded());
Void::Testing::expect_eq(count_in_log("fail"), std::size_t{1});
Void::Testing::expect_eq(count_in_log("pass"), std::size_t{0});
Void::Testing::expect_eq(count_in_log("flaky"), std::size_t{0});
// Invalid values are rejected before any project work.
auto bad_repeat = run_vbs({"test", "--project", proj.string(), "--repeat", "bogus"});
Void::Testing::expect(bad_repeat.has_value() && bad_repeat->exit_code == 2);
auto bad_retry = run_vbs({"test", "--project", proj.string(), "--retry", "99"});
Void::Testing::expect(bad_retry.has_value() && bad_retry->exit_code == 2);
auto bad_seed = run_vbs({"test", "--project", proj.string(), "--shuffle", "--shuffle-seed",
"not-a-number"});
Void::Testing::expect(bad_seed.has_value() && bad_seed->exit_code == 2);
}
// === Explainability: why would an action run, and Chrome-trace output ===
VOID_TEST(FullV1Tests, explain_reports_stale_actions_and_trace_writes_chrome_json) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_explain_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.static_library("demo").sources({"src/a.cpp"});
p.executable("app").sources({"src/main.cpp"}).link(lib);
}
)cpp");
write_file(proj / "src" / "hdr.hpp", "#define EXPECT 3\nint a();\n");
write_file(proj / "src" / "a.cpp", "#include \"hdr.hpp\"\nint a() { return 1; }\n");
write_file(proj / "src" / "main.cpp",
"#include \"hdr.hpp\"\nint main() { return a() + 2 == EXPECT ? 0 : 1; }\n");
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
req.timeout = std::chrono::seconds{300};
return Platform::run_supervised(req);
};
const auto json_number = [](const Void::Json::Strict::Value &value) {
if (const auto *integer = std::get_if<std::int64_t>(&value.value)) {
return static_cast<long long>(*integer);
}
if (const auto *real = std::get_if<double>(&value.value)) {
return static_cast<long long>(*real);
}
return -1LL;
};
const auto json_field = [](const Void::Json::Strict::Value::Object &object,
std::string_view key) -> const Void::Json::Strict::Value * {
const auto it = object.find(std::string{key});
return it == object.end() ? nullptr : &it->second;
};
// First build: everything executes.
auto built = run_vbs({"build", "--project", proj.string(), "--build-dir", bdir.string(),
"--jobs", "2"});
Void::Testing::expect(built.has_value() && built->succeeded());
// Nothing changed: every action is up to date.
auto explained = run_vbs({"explain", "--project", proj.string(), "--build-dir",
bdir.string(), "--format", "json"});
Void::Testing::expect(explained.has_value() && explained->succeeded());
if (explained) {
auto parsed = Void::Json::Strict::parse(explained->stdout_data);
Void::Testing::require(parsed.has_value());
const auto *root = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
Void::Testing::require(root != nullptr);
const auto *total = json_field(*root, "total");
const auto *would_run = json_field(*root, "would_run");
Void::Testing::require(total != nullptr && would_run != nullptr);
Void::Testing::expect(json_number(*total) >= 3);
Void::Testing::expect_eq(json_number(*would_run), 0LL);
}
// A changed header must be reported as work to do.
write_file(proj / "src" / "hdr.hpp", "#define EXPECT 4\nint a();\n");
auto stale = run_vbs({"explain", "--project", proj.string(), "--build-dir", bdir.string(),
"--format", "json"});
Void::Testing::expect(stale.has_value() && stale->succeeded());
if (stale) {
auto parsed = Void::Json::Strict::parse(stale->stdout_data);
Void::Testing::require(parsed.has_value());
const auto *root = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
Void::Testing::require(root != nullptr);
const auto *would_run = json_field(*root, "would_run");
Void::Testing::require(would_run != nullptr);
Void::Testing::expect(json_number(*would_run) >= 1);
}
// Text output names the reason.
auto text = run_vbs({"explain", "--project", proj.string(), "--build-dir", bdir.string()});
Void::Testing::expect(text.has_value() && text->succeeded());
if (text) {
Void::Testing::expect(text->stdout_data.find("would run") != std::string::npos);
}
// An unsupported format is rejected before any work.
auto bad = run_vbs({"explain", "--project", proj.string(), "--format", "xml"});
Void::Testing::expect(bad.has_value() && bad->exit_code == 2);
// The rebuild writes a Chrome trace with phases and per-action spans.
const auto trace_path = tmp / "trace.json";
auto traced = run_vbs({"build", "--project", proj.string(), "--build-dir", bdir.string(),
"--jobs", "2", "--trace", trace_path.string()});
Void::Testing::expect(traced.has_value() && traced->succeeded());
auto trace_text = Void::FileSystem::read_file(trace_path);
Void::Testing::require(trace_text.has_value());
auto trace = Void::Json::Strict::parse(*trace_text);
Void::Testing::require(trace.has_value());
const auto *trace_root = std::get_if<Void::Json::Strict::Value::Object>(&trace->value);
Void::Testing::require(trace_root != nullptr);
const auto *events = json_field(*trace_root, "traceEvents");
Void::Testing::require(events != nullptr);
const auto *event_array = std::get_if<Void::Json::Strict::Value::Array>(&events->value);
Void::Testing::require(event_array != nullptr);
Void::Testing::expect(event_array->size() >= 6);
bool saw_phase = false;
bool saw_action = false;
for (const auto &event : *event_array) {
const auto *object = std::get_if<Void::Json::Strict::Value::Object>(&event.value);
if (object == nullptr) {
continue;
}
const auto *category = json_field(*object, "cat");
const auto *phase = json_field(*object, "ph");
if (category == nullptr || phase == nullptr) {
continue;
}
const auto *category_text = std::get_if<std::string>(&category->value);
const auto *phase_text = std::get_if<std::string>(&phase->value);
if (category_text == nullptr || phase_text == nullptr) {
continue;
}
Void::Testing::expect(*phase_text == "X");
if (*category_text == "phase") {
saw_phase = true;
}
if (*category_text == "action" || *category_text == "cache") {
saw_action = true;
}
}
Void::Testing::expect(saw_phase);
Void::Testing::expect(saw_action);
}