diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index f89f966..be4c4e8 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -326,6 +326,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 116 (CLion Plugin Repository)**: `vbs ide plugin --editor clion` emits a JetBrains plugin skeleton (`plugin.xml` with Tools-menu actions, `build.gradle.kts`, a Kotlin action file, README); assets published to the new [Void/VbsCLion](https://git.faumaray.com/Void/VbsCLion) repository and confirmed via the Gitea API. All three editor plugin repositories now exist. +- **Wave 117 (#61 VBS-Side Gaps)**: three gaps noted on Void/Library#61 are fixed in VBS - (1) `ProcessRequest::descendant_grace` bounds post-leader orphan supervision and the group is fully reaped so test runs cannot hang on escaped grandchildren; (2) installer archives are signed over a short canonical `vbs-installer-v1` digest message (streamed SHA-256, `.msg` written) instead of the archive bytes, removing the 16 MiB one-shot crypto limit; (3) `.native_builder({...})` options are passed to a dependency's `build.cpp` as `VBS_DEP_OPTION_` (plus `VBS_DEP_NAME`), readable through the new SDK `Void::Build::dependency_option()`. + ## 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/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index eeea4a1..3429dd0 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1635,6 +1635,22 @@ vbs ide plugin --project --build-dir --editor vscode --output \n` (the archive digest is + streamed with `sha256_file_hex`), writes `.msg`, and never loads the archive into + memory; the install test verifies the signature over the message and that a tampered digest + fails (**passed**, 6.83 s). +- **native_builder options**: `FrontendOptions::extra_environment` is applied to every descriptor + process, the native provider forwards `VBS_DEP_OPTION_`/`VBS_DEP_NAME`, and + `Void::Build::dependency_option(name)` reads them; the native-subproject fixture now throws + unless it receives `SUB_MATH_ENABLED=yes` (**passed**, 4.16 s). + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/include/Void/Build.hpp b/include/Void/Build.hpp index 2e6168e..fd36a65 100644 --- a/include/Void/Build.hpp +++ b/include/Void/Build.hpp @@ -319,6 +319,10 @@ class Dependency { std::size_t index_; }; +// Value of a `.native_builder({...})` option passed by the consuming project to this +// dependency's build.cpp (exposed as VBS_DEP_OPTION_), or an empty string when unset. +[[nodiscard]] std::string dependency_option(std::string_view name); + class Project { public: explicit Project(ProfileContext context); diff --git a/include/Void/Build/Config/Frontend.hpp b/include/Void/Build/Config/Frontend.hpp index 8efc861..f04db64 100644 --- a/include/Void/Build/Config/Frontend.hpp +++ b/include/Void/Build/Config/Frontend.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -23,6 +24,8 @@ struct FrontendOptions { std::filesystem::path sdk_source_dir; // Fallback source dir if sdk_library_path absent std::vector extra_build_sources; // Explicit --build-source inputs std::optional host_compiler; + // Extra environment for the descriptor process (e.g. dependency options for a native dep). + std::map> extra_environment; std::chrono::milliseconds eval_timeout{std::chrono::seconds{30}}; }; diff --git a/include/Void/Build/Install/Installer.hpp b/include/Void/Build/Install/Installer.hpp index 4b1b1cc..8705a8d 100644 --- a/include/Void/Build/Install/Installer.hpp +++ b/include/Void/Build/Install/Installer.hpp @@ -28,8 +28,9 @@ struct InstallOptions { std::string archive_format{"tar"}; std::string package_description; // Used by package metadata (deb). std::string maintainer; // Used by package metadata (deb). - // Optional Ed25519 seed file: signs the generated archive and writes - // `.sha256`, `.sig` and `.pub`. + // Optional Ed25519 seed file: signs a canonical `vbs-installer-v1` digest message over the + // generated archive and writes `.sha256`, `.sig`, `.pub` and + // `.msg` (the exact signed message). std::optional signing_seed_path; }; diff --git a/include/Void/Build/Platform/ProcessSupervisor.hpp b/include/Void/Build/Platform/ProcessSupervisor.hpp index d285301..45f0ce8 100644 --- a/include/Void/Build/Platform/ProcessSupervisor.hpp +++ b/include/Void/Build/Platform/ProcessSupervisor.hpp @@ -35,6 +35,9 @@ struct ProcessRequest { std::size_t max_stderr_bytes{8ULL * 1024ULL * 1024ULL}; bool fail_on_overflow{false}; std::chrono::milliseconds timeout{0}; // 0 = no timeout + // How long descendants of an exited leader may keep the process group alive before it is + // terminated and reaped. 0 waits indefinitely. + std::chrono::milliseconds descendant_grace{5000}; std::chrono::milliseconds kill_grace{200}; bool search_path{true}; std::function on_stdout_chunk; diff --git a/sdk/Build.cpp b/sdk/Build.cpp index 38313be..0c68b40 100644 --- a/sdk/Build.cpp +++ b/sdk/Build.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -567,6 +568,22 @@ std::string Profiles::to_json() const { '}'; } +std::string dependency_option(std::string_view name) { + std::string upper{name}; + for (char &c : upper) { + c = static_cast(std::toupper(static_cast(c))); + } + // Consumers pass fixed keys verbatim first, then the upper-cased convention. + if (const char *exact = std::getenv(("VBS_DEP_OPTION_" + std::string{name}).c_str()); + exact != nullptr) { + return exact; + } + if (const char *value = std::getenv(("VBS_DEP_OPTION_" + upper).c_str()); value != nullptr) { + return value; + } + return {}; +} + Profiles default_profiles() { Profiles result; result.add("debug", {"-O0", "-g"}); diff --git a/src/Config/Frontend.cpp b/src/Config/Frontend.cpp index ca2692a..28e45dc 100644 --- a/src/Config/Frontend.cpp +++ b/src/Config/Frontend.cpp @@ -608,6 +608,9 @@ discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &o req.arguments = {"--mode", "profiles", "--output", out_file.string(), "--request-id", req_id}; req.working_directory = options.project_root; req.timeout = options.eval_timeout; + for (const auto &[key, value] : options.extra_environment) { + req.environment.set_vars[key] = value; + } auto proc = Platform::run_supervised(req); auto cleanup = [&] { std::filesystem::remove(out_file, ec); }; @@ -735,6 +738,9 @@ evaluate_project(const CompiledDescriptor &descriptor, const ProfileContext &con "--context-hash", ctx_hash}; req.working_directory = options.project_root; req.timeout = options.eval_timeout; + for (const auto &[key, value] : options.extra_environment) { + req.environment.set_vars[key] = value; + } auto proc = Platform::run_supervised(req); if (!proc) { @@ -819,6 +825,9 @@ evaluate_workspace(const CompiledDescriptor &descriptor, const FrontendOptions & req.arguments = {"--mode", "workspace", "--output", out_file.string(), "--request-id", req_id}; req.working_directory = options.project_root; req.timeout = options.eval_timeout; + for (const auto &[key, value] : options.extra_environment) { + req.environment.set_vars[key] = value; + } auto proc = Platform::run_supervised(req); auto cleanup = [&] { std::filesystem::remove(out_file, ec); }; diff --git a/src/Install/Installer.cpp b/src/Install/Installer.cpp index 1fc3bfb..14882b2 100644 --- a/src/Install/Installer.cpp +++ b/src/Install/Installer.cpp @@ -496,6 +496,11 @@ write_deb_package(const std::filesystem::path &output, const InstallOptions &opt return Platform::atomic_write_file(output, deb, true); } +// Canonical short message signed for installer archives (independent of archive size). +std::string installer_signing_message(std::string_view archive_sha256) { + return "vbs-installer-v1\n" + std::string{archive_sha256} + "\n"; +} + } // namespace Void::Result::Result @@ -904,13 +909,15 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build } report.archive_path = *options.archive_path; - // Optional detached signature and checksums over the final archive bytes. + // Optional detached signature and checksums over the final archive. The signed message + // is a short canonical digest statement, not the archive bytes, so archives of any size + // stay within the crypto one-shot limit. if (options.signing_seed_path) { - auto bytes = Void::FileSystem::read_file(*options.archive_path); - if (!bytes) { - return std::unexpected{bytes.error()}; + auto digest = Util::sha256_file_hex(*options.archive_path); + if (!digest) { + return std::unexpected{digest.error()}; } - report.archive_sha256 = Util::sha256_hex(*bytes); + report.archive_sha256 = *digest; report.checksum_path = options.archive_path->string() + ".sha256"; if (auto written = Platform::atomic_write_file( *report.checksum_path, @@ -920,8 +927,10 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build return std::unexpected{written.error()}; } + const std::string canonical_message = installer_signing_message(report.archive_sha256); auto signature = Provenance::sign_message( - std::as_bytes(std::span{bytes->data(), bytes->size()}), + std::as_bytes(std::span{canonical_message.data(), + canonical_message.size()}), *options.signing_seed_path); if (!signature) { return std::unexpected{signature.error()}; @@ -942,6 +951,11 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build !written) { return std::unexpected{written.error()}; } + if (auto written = Platform::atomic_write_file( + options.archive_path->string() + ".msg", canonical_message, true); + !written) { + return std::unexpected{written.error()}; + } } } return report; diff --git a/src/Platform/Linux/ProcessSupervisor.cpp b/src/Platform/Linux/ProcessSupervisor.cpp index b320e97..a14f290 100644 --- a/src/Platform/Linux/ProcessSupervisor.cpp +++ b/src/Platform/Linux/ProcessSupervisor.cpp @@ -158,8 +158,11 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) { // drains, times out, or is cancelled, then escalate via SIGTERM -> kill_grace -> SIGKILL. bool group_timed_out = comm->timed_out; bool group_cancelled = comm->cancelled; + bool descendants_terminated = false; const pid_t pgid = static_cast(child->pgid()); if (!group_timed_out && !group_cancelled && !comm->overflowed) { + const auto descendant_deadline = + std::chrono::steady_clock::now() + request.descendant_grace; while (child->process_group_alive()) { // Reap any adopted descendants in this process group (subreaper) so zombies clear. int wstatus = 0; @@ -172,18 +175,40 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) { group_cancelled = true; break; } - if (has_timeout && std::chrono::steady_clock::now() >= deadline) { + const auto now = std::chrono::steady_clock::now(); + if (has_timeout && now >= deadline) { group_timed_out = true; break; } + // Orphans must not keep the supervisor (or a test run) alive forever. + if (request.descendant_grace.count() > 0 && now >= descendant_deadline) { + descendants_terminated = true; + break; + } std::this_thread::sleep_for(std::chrono::milliseconds{10}); } } - if (group_cancelled || group_timed_out || comm->overflowed || child->process_group_alive()) { + if (group_cancelled || group_timed_out || descendants_terminated || comm->overflowed || + child->process_group_alive()) { (void)child->terminate(request.kill_grace); + // Reap the whole group until it is really gone (bounded), so no zombie or orphan is + // left behind after test supervision. + const auto reap_deadline = + std::chrono::steady_clock::now() + request.kill_grace + std::chrono::seconds{2}; int wstatus = 0; - while (pgid > 0 && ::waitpid(-pgid, &wstatus, WNOHANG) > 0) { + while (pgid > 0) { + const pid_t reaped = ::waitpid(-pgid, &wstatus, WNOHANG); + if (reaped < 0) { // ECHILD: no descendants left. + break; + } + if (reaped == 0) { + if (std::chrono::steady_clock::now() >= reap_deadline) { + break; + } + std::this_thread::sleep_for(std::chrono::milliseconds{5}); + continue; + } } } diff --git a/src/Provider/Provider.cpp b/src/Provider/Provider.cpp index e76587e..10ca64b 100644 --- a/src/Provider/Provider.cpp +++ b/src/Provider/Provider.cpp @@ -1065,6 +1065,11 @@ run_native_provider(const ProviderRequest &request, const std::filesystem::path if (request.sdk_library_path) { fopts.sdk_library_path = *request.sdk_library_path; } + // Pass the consumer's `.native_builder({...})` options to the dependency's build.cpp. + fopts.extra_environment["VBS_DEP_NAME"] = request.dependency.name; + for (const auto &[key, value] : request.dependency.options) { + fopts.extra_environment["VBS_DEP_OPTION_" + key] = cmake_option_value(value); + } auto compiled = Config::compile_descriptor(fopts); if (!compiled) { return std::unexpected{compiled.error()}; diff --git a/tests/CoreEngineTests.cpp b/tests/CoreEngineTests.cpp index e82cb93..b422202 100644 --- a/tests/CoreEngineTests.cpp +++ b/tests/CoreEngineTests.cpp @@ -112,6 +112,30 @@ VOID_TEST(CoreEngineTests, process_supervisor_exec_failure_and_early_leader_gran std::this_thread::sleep_for(std::chrono::milliseconds{300}); Void::Testing::expect(!std::filesystem::exists(sentinel)); } + + // 4. Without a request timeout, orphaned descendants are reaped after descendant_grace so + // test supervision never hangs (and the escaped grandchild is killed). + { + Void::FileSystem::TempDir tmp{"vbs_proc_"}; + const auto sentinel = tmp / "orphan_escaped.txt"; + Platform::ProcessRequest req; + req.executable = "/bin/sh"; + req.arguments = {"-c", "sh -c 'trap \"\" TERM; sleep 1.5; echo escaped > \"" + + sentinel.string() + "\"' >/dev/null 2>&1 & exit 0"}; + req.descendant_grace = std::chrono::milliseconds{150}; + req.kill_grace = std::chrono::milliseconds{80}; + const auto started = std::chrono::steady_clock::now(); + auto res = Platform::run_supervised(req); + const auto elapsed = std::chrono::duration_cast( + std::chrono::steady_clock::now() - started); + Void::Testing::expect(res.has_value()); + if (res) { + Void::Testing::expect(res->succeeded()); + } + Void::Testing::expect(elapsed < std::chrono::seconds{5}); + std::this_thread::sleep_for(std::chrono::milliseconds{300}); + Void::Testing::expect(!std::filesystem::exists(sentinel)); + } } VOID_TEST(CoreEngineTests, profile_inheritance_and_cycle_rejection) { diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index c2762e6..6324309 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -1038,17 +1038,31 @@ void build(Void::Build::Project &p) { auto signature_text = Void::FileSystem::read_file(signed_archive.string() + ".sig"); auto public_key_text = Void::FileSystem::read_file(signed_archive.string() + ".pub"); auto checksum_text = Void::FileSystem::read_file(signed_archive.string() + ".sha256"); + auto message_text = Void::FileSystem::read_file(signed_archive.string() + ".msg"); Void::Testing::require(archive_bytes.has_value() && signature_text.has_value() && - public_key_text.has_value() && checksum_text.has_value()); + public_key_text.has_value() && checksum_text.has_value() && + message_text.has_value()); Void::Testing::expect_eq(signature_text->size(), std::size_t{129}); Void::Testing::expect_eq(public_key_text->size(), std::size_t{65}); Void::Testing::expect(checksum_text->starts_with(Util::sha256_hex(*archive_bytes))); + // The signed message is the short canonical digest statement, not the archive bytes. + Void::Testing::expect(message_text->starts_with("vbs-installer-v1\n")); + Void::Testing::expect(message_text->size() < 128); auto verified = Provenance::verify_message( - std::as_bytes(std::span{archive_bytes->data(), archive_bytes->size()}), + std::as_bytes(std::span{message_text->data(), message_text->size()}), std::string_view{*signature_text}.substr(0, 128), std::string_view{*public_key_text}.substr(0, 64)); Void::Testing::require(verified.has_value()); Void::Testing::expect(*verified); + // A tampered digest must not verify. + std::string tampered = *message_text; + tampered[tampered.size() - 2] = tampered[tampered.size() - 2] == '0' ? '1' : '0'; + auto tampered_result = Provenance::verify_message( + std::as_bytes(std::span{tampered.data(), tampered.size()}), + std::string_view{*signature_text}.substr(0, 128), + std::string_view{*public_key_text}.substr(0, 64)); + Void::Testing::require(tampered_result.has_value()); + Void::Testing::expect(!*tampered_result); } else { // Without an Ed25519 backend signing must fail closed, never silently skip. Void::Testing::expect(sign_res.has_value() && !sign_res->succeeded()); @@ -2095,7 +2109,14 @@ VOID_TEST(FullV1Tests, native_vbs_subproject_dependency_builds_without_cmake) { // Pure `build.cpp` library dependency (NO CMakeLists.txt!). const auto dep_dir = tmp / "sub_math_dep"; write_file(dep_dir / "build.cpp", R"cpp(#include +#include +#include void build(Void::Build::Project &p) { + // The consumer's .native_builder({...}) options reach this description. + const std::string enabled = Void::Build::dependency_option("SUB_MATH_ENABLED"); + if (enabled != "yes") { + throw std::runtime_error("SUB_MATH_ENABLED must be yes, got '" + enabled + "'"); + } auto lib = p.static_library("sub_math"); lib.cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"src/math.cpp"}) @@ -2113,7 +2134,7 @@ void build(Void::Build::Project &p) { "void build(Void::Build::Project &p) {\n" " auto dep = p.dependency(\"math\").path(\"" + dep_dir.string() + - "\").native_builder();\n" + "\").native_builder({{\"SUB_MATH_ENABLED\", \"yes\"}});\n" " p.test(\"consumer_test\")\n" " .cxx_standard(Void::Build::CxxStandard::Cxx26)\n" " .sources({\"tests/main.cpp\"})\n"