From 1e670cb96b71726f286b4d3e87cc1f3b9e839ff6 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 07:25:33 +0300 Subject: [PATCH] feat(test): write JUnit reports and honour a per-test timeout --- docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 9 ++ docs/roadmap/22-superiority-and-gaps.md | 2 +- src/Main.cpp | 122 +++++++++++++++++++++++- tests/CliContracts.cmake | 1 + tests/FullV1Tests.cpp | 13 ++- 7 files changed, 147 insertions(+), 3 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 8399fa4..7446120 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -298,6 +298,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 102 (VoidLibrary Migration Trial)**: in a separate VoidLibrary clone at the pin (`0002e74`), a native `build.cpp` (using the shared module-closure logic) built VoidLibrary entirely with VBS - 23 actions, module archives plus `void_smoke` - and `vbs test` reported `PASSED 'void_smoke'` with no CMake. The reusable assets live in `contrib/voidlibrary-migration/` (outside the globbed source trees), and the missing first-class upstream build description was filed as [Void/Library#61](https://git.faumaray.com/Void/Library/issues/61). +- **Wave 103 (Test-Runner Parity: JUnit XML & Test Timeout)**: `vbs test` gained `--test-timeout SECONDS` (1..86400, validated before any project work) and `--junit FILE`, which writes a JUnit XML report aggregating every executed test target across profiles (`testcase` with classname/name/time, `failure` with exit status and captured output, escaped). Covered by `FullV1Tests.native_vbs_subproject_dependency_builds_without_cmake` (asserts the suite/testcase/failures fields) and a CLI contract for invalid timeouts. + ## Remaining future scope - **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index f149747..bf0f890 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -106,4 +106,5 @@ Base HEAD: `fe0d1a6` | Wave 100 (CMakePresets import) | `Config::load_cmake_presets` (inherits, `${sourceDir}`, cache merge, profile/compiler mapping) + `vbs presets` CLI | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; presets test passes, full CTest 8/8) | `include/Void/Build/Config/Presets.hpp`, `src/Config/Presets.cpp`, `src/Main.cpp`, `tests/{FullV1Tests,CliContracts}.cpp/cmake`, docs | | Wave 101 (CMake File API shim) | `vbs ide generate` emits `.cmake/api/v1/reply` codemodel-v2 + directory + per-target JSON from the lowered graph | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; IDE integration test passes, full CTest 8/8) | `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 102 (VoidLibrary migration trial) | Separate-clone `build.cpp` builds and tests VoidLibrary with VBS; assets in `contrib/voidlibrary-migration/`; upstream issue #61 | VERIFIED IN CLONE (23 actions, `vbs test` PASSED; no CMake) | `contrib/voidlibrary-migration/`, docs | +| Wave 103 (JUnit & test timeout) | `vbs test --junit FILE --test-timeout SECONDS` with aggregated JUnit XML | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; JUnit assertions and CLI contract pass, full CTest 8/8) | `src/Main.cpp`, `tests/{FullV1Tests,CliContracts}.cpp/cmake`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 396e5ef..f44599c 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1447,6 +1447,15 @@ vbs test --project /tmp/opencode/vl-migrate --build-dir /tmp/opencode/vl-migrat - Upstream gap filed as [Void/Library#61](https://git.faumaray.com/Void/Library/issues/61) because VoidLibrary lacks an in-repo VBS build description and many modules have no native entry. +## Test-Runner Parity: JUnit XML & Test Timeout (GCC 16.2, pin `0002e74`) + +- `vbs test --junit report.xml --test-timeout 120` on the native subproject fixture writes a JUnit + report containing ` &inline_keys, return combined; } +struct TestRunRecord { + std::string profile; + std::string name; + bool passed{false}; + int exit_code{-1}; + double elapsed_ms{0}; + std::string output; +}; + struct BuildCmdOptions { std::string project_arg; std::optional build_arg; @@ -377,6 +386,8 @@ struct BuildCmdOptions { std::vector trusted_key_files; std::optional target_os_arg; std::optional target_arch_arg; + std::optional junit_arg; + std::string test_timeout_arg{"300"}; bool publish_editor_selection{true}; bool no_cache{false}; bool locked{false}; @@ -386,6 +397,14 @@ struct BuildCmdOptions { int execute_build_or_test(BuildCmdOptions opts, bool run_tests) { const std::string cmd_name = run_tests ? "vbs test" : "vbs build"; + int test_timeout_seconds = 300; + if (!Void::Str::to_int(opts.test_timeout_arg, test_timeout_seconds) || + test_timeout_seconds <= 0 || test_timeout_seconds > 86400) { + std::cerr << cmd_name << ": invalid --test-timeout value '" << opts.test_timeout_arg + << "' (expected 1..86400 seconds)\n"; + return 2; + } + std::vector test_records; const auto total_sw = Void::Time::Stopwatch::started(); std::optional compiler_override; @@ -495,6 +514,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) { return 1; } + const std::string target_os = opts.target_os_arg.value_or(Toolchain::host_os_name()); const std::string target_arch = opts.target_arch_arg.value_or(Toolchain::host_architecture_name()); @@ -834,8 +854,20 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) { treq.executable = t.primary_outputs.front(); } treq.working_directory = project_root; - treq.timeout = std::chrono::seconds{300}; + treq.timeout = std::chrono::seconds{test_timeout_seconds}; auto tres = Platform::run_supervised(treq); + TestRunRecord record; + record.profile = prof_name; + record.name = t.name; + record.passed = tres.has_value() && tres->succeeded(); + record.elapsed_ms = tsw.elapsed_ms(); + if (tres) { + record.output = tres->stdout_data + tres->stderr_data; + record.exit_code = tres->exit_code; + } else { + record.output = tres.error().message(); + } + test_records.push_back(std::move(record)); if (!tres || !tres->succeeded()) { Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name, t.name, tsw.elapsed_ms()); @@ -856,6 +888,91 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) { } } + // JUnit XML report for CI systems (aggregated across selected profiles). + if (opts.junit_arg && !opts.junit_arg->empty() && !test_records.empty()) { + const auto xml_escape = [](std::string_view text) { + std::string out; + out.reserve(text.size()); + for (const char c : text) { + switch (c) { + case '&': + out += "&"; + break; + case '<': + out += "<"; + break; + case '>': + out += ">"; + break; + case '"': + out += """; + break; + case '\'': + out += "'"; + break; + default: + if (static_cast(c) >= 0x20 || c == '\n' || c == '\t') { + out.push_back(c); + } + break; + } + } + return out; + }; + std::size_t failures = 0; + for (const auto &record : test_records) { + if (!record.passed) { + ++failures; + } + } + std::string xml = "\n"; + xml += std::format("\n", + test_records.size(), failures); + std::string current_profile; + auto open_suite = [&] { + if (!current_profile.empty()) { + xml += " \n"; + } + std::size_t suite_tests = 0; + std::size_t suite_failures = 0; + for (const auto &record : test_records) { + if (record.profile == current_profile) { + ++suite_tests; + if (!record.passed) { + ++suite_failures; + } + } + } + xml += std::format(" \n", + xml_escape(current_profile), suite_tests, suite_failures); + }; + for (const auto &record : test_records) { + if (record.profile != current_profile) { + current_profile = record.profile; + open_suite(); + } + xml += std::format(" \n {}\n \n", + record.exit_code, xml_escape(record.output)); + } + } + if (!current_profile.empty()) { + xml += " \n"; + } + xml += "\n"; + if (auto written = Platform::atomic_write_file(*opts.junit_arg, xml, false); !written) { + std::cerr << "vbs test: cannot write JUnit report: " << written.error().message() + << '\n'; + all_ok = false; + } + } + Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0); return all_ok ? 0 : 1; } @@ -2798,6 +2915,9 @@ int main(int argc, char **argv) { build_opts.target_os_arg) .option("--target-arch", "", "Target architecture (default: host, e.g. x86_64)", build_opts.target_arch_arg) + .option_default("--test-timeout", "", "Per-test timeout in seconds (1..86400)", + build_opts.test_timeout_arg, "300") + .option("--junit", "", "Write a JUnit XML report of test results", build_opts.junit_arg) .option("--editor-profile", "", "Editor profile for compile_commands.json", build_opts.editor_profile) .option_many("--build-source", "", "Additional build description source", diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 34742fa..aeefe76 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -24,6 +24,7 @@ check_process(2 "" "--version cannot be combined with subcommands" --version bui 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 init " "" init --help) check_process(0 "Usage: vbs clean " "" clean --help) check_process(0 "Usage: vbs doctor " "" doctor --help) diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index c7ed724..7e16f92 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -1988,7 +1988,10 @@ void build(Void::Build::Project &p) { Platform::ProcessRequest req; req.executable = vbs_bin; - req.arguments = {"test", "--project", cons_dir.string(), "--build-dir", cons_build.string()}; + const auto junit_report = tmp / "consumer-junit.xml"; + req.arguments = {"test", "--project", cons_dir.string(), + "--build-dir", cons_build.string(), "--test-timeout", + "120", "--junit", junit_report.string()}; req.environment.set_vars["PATH"] = trapped_path; req.timeout = std::chrono::seconds{120}; auto res = Platform::run_supervised(req); @@ -2000,6 +2003,14 @@ void build(Void::Build::Project &p) { if (res) { Void::Testing::expect(res->stdout_data.find("PASSED 'consumer_test'") != std::string::npos); } + + // JUnit XML report for CI consumption. + auto junit = Void::FileSystem::read_file(junit_report); + Void::Testing::require(junit.has_value()); + Void::Testing::expect(junit->find("find("find("name=\"consumer_test\"") != std::string::npos); + Void::Testing::expect(junit->find("failures=\"0\"") != std::string::npos); } // === Track B1: First-class C driver & mixed C/C++ native CMake + Meson translation ===