#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Void::Build; namespace { void write_file(const std::filesystem::path &path, std::string_view content) { auto r = Platform::atomic_write_file(path, content, false); Void::Testing::expect(r.has_value()); } // Writes a raw malicious USTAR tar entry with arbitrary path/typeflag for security tests. void write_raw_tar(const std::filesystem::path &tar_path, const std::vector> &entries) { std::ofstream out(tar_path, std::ios::binary | std::ios::trunc); for (const auto &[name, typeflag, body] : entries) { std::array hdr{}; std::memcpy(hdr.data(), name.data(), std::min(name.size(), 100)); auto oct = [](char *dst, std::size_t w, std::uint64_t v) { std::memset(dst, '0', w - 1); dst[w - 1] = '\0'; for (std::size_t i = w - 1; i > 0; --i) { dst[i - 1] = static_cast('0' + (v & 7u)); v >>= 3; } }; oct(hdr.data() + 100, 8, 0644); oct(hdr.data() + 108, 8, 0); oct(hdr.data() + 116, 8, 0); oct(hdr.data() + 124, 12, body.size()); oct(hdr.data() + 136, 12, 0); std::memset(hdr.data() + 148, ' ', 8); hdr[156] = typeflag; std::memcpy(hdr.data() + 257, "ustar", 6); hdr[263] = '0'; hdr[264] = '0'; std::uint64_t sum = 0; for (const char c : hdr) sum += static_cast(c); oct(hdr.data() + 148, 7, sum); hdr[155] = ' '; out.write(hdr.data(), 512); if (!body.empty()) { out.write(body.data(), static_cast(body.size())); const std::size_t pad = (512 - (body.size() % 512)) % 512; if (pad > 0) { std::array z{}; out.write(z.data(), static_cast(pad)); } } } std::array end{}; out.write(end.data(), 1024); } std::filesystem::path locate_vbs_binary() { std::error_code ec; if (const auto self_exe = Platform::current_executable_path(); self_exe) { const auto sibling = self_exe->parent_path() / "vbs"; if (std::filesystem::exists(sibling, ec)) { return sibling; } } if (!Bootstrap::binary_dir.empty()) { return std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs"; } return {}; } } // namespace VOID_TEST(FullV1Tests, workspace_members_shared_build_and_member_selection) { 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_ws_"}; const auto ws = tmp / "ws"; write_file(ws / "workspace.cpp", R"cpp(#include void workspace(Void::Build::Workspace &ws) { ws.member("lib", "packages/lib"); ws.member("app", "packages/app"); ws.member("tests", "packages/tests"); } )cpp"); write_file(ws / "packages" / "lib" / "include" / "core.hpp", "#pragma once\nint ws_core();\n"); write_file(ws / "packages" / "lib" / "src" / "core.cpp", "#include \"core.hpp\"\nint ws_core() { return 7; }\n"); write_file(ws / "packages" / "lib" / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.static_library("libcore") .sources({"src/core.cpp"}) .include_directory("include", Void::Build::Visibility::Public); } )cpp"); write_file(ws / "packages" / "app" / "src" / "main.cpp", "#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n"); write_file(ws / "packages" / "app" / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { auto lib = p.workspace_dependency("lib").target("libcore"); p.executable("ws_app").sources({"src/main.cpp"}).link(lib); } )cpp"); write_file(ws / "packages" / "tests" / "src" / "test.cpp", "#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n"); write_file(ws / "packages" / "tests" / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { auto lib = p.workspace_dependency("lib").target("libcore"); p.test("ws_test").sources({"src/test.cpp"}).link(lib); } )cpp"); auto run_vbs = [&](std::vector args) { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = std::move(args); return Platform::run_supervised(req); }; const auto build_dir = tmp / "build"; auto full = run_vbs({"test", "--project", ws.string(), "--build-dir", build_dir.string()}); Void::Testing::expect(full.has_value() && full->succeeded()); if (!full || !full->succeeded()) { if (full) { std::cerr << full->stderr_data << '\n'; } return; } Platform::ProcessRequest app_req; app_req.executable = build_dir / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app"; auto app_run = Platform::run_supervised(app_req); Void::Testing::expect(app_run.has_value() && app_run->succeeded()); // The workspace root owns the unified lock; members never get their own lockfiles. std::error_code ec; Void::Testing::expect(std::filesystem::exists(ws / "vbs.lock", ec)); Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "app" / "vbs.lock", ec)); Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "lib" / "vbs.lock", ec)); const auto selected_build = tmp / "build_selected"; const auto sbom_path = tmp / "app.cdx.json"; auto selected = run_vbs({"build", "--project", ws.string(), "--build-dir", selected_build.string(), "--member", "app", "--sbom", sbom_path.string(), "--sbom-format", "cyclonedx"}); Void::Testing::expect(selected.has_value() && selected->succeeded()); auto sbom_text = Void::FileSystem::read_file(sbom_path); Void::Testing::expect(sbom_text.has_value() && sbom_text->find("CycloneDX") != std::string::npos); Void::Testing::expect(std::filesystem::exists(selected_build / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app")); Void::Testing::expect(!std::filesystem::exists(selected_build / "members" / "tests")); // --changed-since selects only the member owning the changed file. auto git = Platform::resolve_executable("git"); Void::Testing::expect(git.has_value()); if (git) { auto run_git = [&](std::vector args) { Platform::ProcessRequest req; req.executable = *git; req.arguments = {"-C", ws.string()}; req.arguments.insert(req.arguments.end(), args.begin(), args.end()); return Platform::run_supervised(req); }; auto init = run_git({"init"}); Void::Testing::expect(init.has_value() && init->succeeded()); auto added = run_git({"add", "-A"}); Void::Testing::expect(added.has_value() && added->succeeded()); auto committed = run_git({"-c", "user.email=ws@example.invalid", "-c", "user.name=Workspace", "commit", "-m", "init"}); Void::Testing::expect(committed.has_value() && committed->succeeded()); write_file(ws / "packages" / "app" / "src" / "main.cpp", "#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 2; }\n"); const auto changed_build = tmp / "build_changed"; auto changed = run_vbs({"build", "--project", ws.string(), "--build-dir", changed_build.string(), "--changed-since", "HEAD"}); Void::Testing::expect(changed.has_value() && changed->succeeded()); Void::Testing::expect(std::filesystem::exists( changed_build / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app")); Void::Testing::expect(!std::filesystem::exists(changed_build / "members" / "tests")); } } VOID_TEST(FullV1Tests, sbom_spdx_and_cyclonedx_are_deterministic_and_valid_json) { Provenance::SbomInput input; input.project_name = "demo"; input.project_version = "1.2.3"; input.tool_version = "0.1.0"; input.packages.push_back({"zlib", "1.3", "", "https://example.invalid/zlib", std::string(64, 'a'), "pkg:generic/zlib@1.3"}); input.files.push_back({"out/bin/demo", std::string(64, 'b')}); auto spdx = Provenance::generate_sbom(input, Provenance::SbomFormat::Spdx); Void::Testing::expect(spdx.has_value()); if (!spdx) { return; } Void::Testing::expect(Void::Json::Strict::parse(*spdx).has_value()); Void::Testing::expect(spdx->find("\"SPDX-2.3\"") != std::string::npos); Void::Testing::expect(spdx->find("zlib") != std::string::npos); Void::Testing::expect(spdx->find("out/bin/demo") != std::string::npos); auto spdx_again = Provenance::generate_sbom(input, Provenance::SbomFormat::Spdx); Void::Testing::expect(spdx_again.has_value() && *spdx_again == *spdx); auto cdx = Provenance::generate_sbom(input, Provenance::SbomFormat::CycloneDX); Void::Testing::expect(cdx.has_value()); if (cdx) { Void::Testing::expect(Void::Json::Strict::parse(*cdx).has_value()); Void::Testing::expect(cdx->find("CycloneDX") != std::string::npos); Void::Testing::expect(cdx->find("pkg:generic/zlib@1.3") != std::string::npos); } } // === Plan 09: CompDB projection, selection ticket races, user-file preservation, recovery === VOID_TEST(FullV1Tests, compdb_projection_ticket_races_and_user_file_preservation) { Void::FileSystem::TempDir tmp{"vbs_compdb_"}; const auto proj = tmp / "proj"; const auto build_dir = tmp / "build"; write_file(proj / "src" / "a.cpp", "int main() { return 0; }\n"); write_file(proj / "src" / "b.cpp", "int helper() { return 1; }\n"); // Unrelated user-owned compile_commands.json at project root MUST NEVER be overwritten! write_file(proj / "compile_commands.json", "[{\"user_owned\":true}]\n"); auto debug_ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto rel_ctx = default_profiles().resolve("release", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(debug_ctx, build_dir / ".vbs" / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; auto make_desc = [](const ProfileContext &ctx) { Graph::ProjectDescription d; d.profile = ctx; TargetRecord t1; t1.name = "app"; t1.kind = TargetKind::Executable; t1.sources.push_back({SourceKind::File, "src/a.cpp"}); t1.defines.push_back({"LITERAL_PATH=\"/snapshots/trees/untouched\"", Visibility::Private}); d.targets.push_back(t1); TargetRecord t2; t2.name = "other"; t2.kind = TargetKind::StaticLibrary; t2.sources.push_back({SourceKind::File, "src/b.cpp"}); d.targets.push_back(t2); return d; }; Snapshot::SnapshotOptions sopts; sopts.project_root = proj; sopts.snapshot_store_dir = build_dir / ".vbs" / "snapshots"; auto snap = Snapshot::capture_snapshot(sopts, {}, {proj / "src"}); Void::Testing::expect(snap.has_value()); if (!snap) return; auto g_dbg = Graph::lower_project_graph(make_desc(debug_ctx), *tc, {proj, build_dir, &(*snap), {}, 32768}); auto g_rel = Graph::lower_project_graph(make_desc(rel_ctx), *tc, {proj, build_dir, &(*snap), {}, 32768}); Void::Testing::expect(g_dbg.has_value() && g_rel.has_value()); if (!g_dbg || !g_rel) return; // 1. Reserve ticket 1 for debug, then ticket 2 for release -> release finishes FIRST, // debug finishes LATER (reverse-order race!). Ticket 1 MUST NOT overwrite Ticket 2! auto t1 = Editor::reserve_selection_ticket(proj, build_dir, "debug"); auto t2 = Editor::reserve_selection_ticket(proj, build_dir, "release"); Void::Testing::expect(t1.has_value() && t2.has_value() && *t2 > *t1); auto pub_rel = Editor::publish_profile_compdb(*g_rel, {proj, build_dir, true, *t2, true}); auto pub_dbg = Editor::publish_profile_compdb(*g_dbg, {proj, build_dir, true, *t1, true}); Void::Testing::expect(pub_rel.has_value() && pub_dbg.has_value()); // Selection MUST remain "release" (ticket 2)! auto sel = Editor::read_selection_state(proj); Void::Testing::expect(sel.has_value() && sel->has_value()); if (sel && *sel) { Void::Testing::expect_eq((*sel)->selected_profile, std::string{"release"}); Void::Testing::expect(!(*sel)->managed_root_alias_active); } // User-owned root compile_commands.json was NOT overwritten! auto user_file = Void::FileSystem::read_file(proj / "compile_commands.json"); Void::Testing::expect(user_file.has_value() && *user_file == "[{\"user_owned\":true}]\n"); // 2. Verify projected JSON covers BOTH targets, points to editable source path, // and did NOT corrupt literal macro definitions! auto compdb_text = Void::FileSystem::read_file(build_dir / "compile_commands.json"); Void::Testing::expect(compdb_text.has_value()); if (compdb_text) { auto parsed = Void::Json::Strict::parse(*compdb_text); Void::Testing::expect(parsed.has_value()); Void::Testing::expect(compdb_text->find("src/a.cpp") != std::string::npos); Void::Testing::expect(compdb_text->find("src/b.cpp") != std::string::npos); Void::Testing::expect( compdb_text->find("LITERAL_PATH=\\\"/snapshots/trees/untouched\\\"") != std::string::npos); } // 3. Manual switch to debug creates newer ticket; watcher refresh on release does NOT steal! auto switched = Editor::select_editor_profile(proj, build_dir, "debug", true); Void::Testing::expect(switched.has_value() && switched->selected_profile == "debug"); auto watch_pub = Editor::publish_profile_compdb(*g_rel, {proj, build_dir, false, std::nullopt, true}); Void::Testing::expect(watch_pub.has_value()); auto sel2 = Editor::read_selection_state(proj); Void::Testing::expect(sel2 && *sel2 && (*sel2)->selected_profile == "debug"); // 4. Crash recovery restores deleted build-root compile_commands.json symlink! std::filesystem::remove(build_dir / "compile_commands.json"); Void::Testing::expect(Editor::recover_editor_pointers(proj).has_value()); Void::Testing::expect(std::filesystem::exists(build_dir / "compile_commands.json")); } // === Plan 10: Inotify watcher + strict MetadataOnly watch boundary === VOID_TEST(FullV1Tests, watcher_inotify_and_metadata_only_forbids_foreign_configure) { Void::FileSystem::TempDir tmp{"vbs_watch_"}; const auto proj = tmp / "proj"; const auto build_dir = tmp / "build"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { auto app = p.executable("wapp"); app.sources({"src/main.cpp"}); } )cpp"); write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n"); // 1. Verify InotifyWatcher sees file edit and ignores excluded build/ directory. auto watcher = Watch::InotifyWatcher::create(proj); Void::Testing::expect(watcher.has_value()); if (watcher) { write_file(proj / "src" / "added.cpp", "int extra() { return 1; }\n"); auto batch = watcher->poll_events(std::chrono::milliseconds{200}, std::chrono::milliseconds{20}); Void::Testing::expect(batch.has_value() && !batch->changed_paths.empty()); } // 2. MetadataOnly cycle MUST NOT compile targets and MUST report stale provider cleanly! bool foreign_configure_called = false; Watch::WatchLoopOptions wopts; wopts.mode = Watch::WatchMode::MetadataOnly; wopts.frontend.project_root = proj; wopts.frontend.build_root = build_dir; wopts.frontend.sdk_include_dir = std::filesystem::path{Bootstrap::sdk_include_dir}; wopts.frontend.sdk_source_dir = std::filesystem::path{Bootstrap::sdk_source_dir}; wopts.explicit_profile = "debug"; wopts.max_cycles = 1; wopts.provider_reader = [&](const Graph::ProjectDescription &, Watch::WatchMode mode) { if (mode == Watch::WatchMode::FullBuild) { foreign_configure_called = true; } return Watch::CachedProviderSnapshot{true, "", {}}; }; auto cycles = Watch::run_watch_loop(wopts); Void::Testing::expect(cycles.has_value() && cycles->size() == 1); Void::Testing::expect(!foreign_configure_called); if (cycles && !cycles->empty()) { Void::Testing::expect(cycles->front().compdb_published); Void::Testing::expect_eq(cycles->front().executed_actions, std::size_t{0}); } // No binary built in MetadataOnly mode! Void::Testing::expect( !std::filesystem::exists(build_dir / "profiles" / "debug" / "out" / "bin" / "wapp")); } // === Plan 11: TOML 1.0, PubGrub solver (with exhaustive oracle), atomic CAS lockfile === VOID_TEST(FullV1Tests, toml_solver_oracle_and_atomic_cas_lockfile) { Void::FileSystem::TempDir tmp{"vbs_pkg_"}; const auto toml_file = tmp / "vbs.deps.toml"; write_file(toml_file, R"toml( [dependencies.VoidLibrary] git = "https://git.faumaray.com/Void/VoidLibrary.git" rev = "9931c5ffc4844a5e09e1b1db35b3d29c5097c3a5" builder = "cmake" [dependencies.VoidLibrary.options] VOID_ENABLED_MODULES = "Configuration" VOID_ENABLE_TESTING = false THREADS = 4 [dependencies.fmt] package = "fmt" version = "^11.0" registry = "https://registry.void.example" features = ["header-only"] )toml"); auto loaded = Package::load_dependencies_toml(toml_file); Void::Testing::expect(loaded.has_value()); if (!loaded) return; Void::Testing::expect_eq(loaded->size(), std::size_t{2}); // C++/TOML conflict rejection with BOTH origins diagnosed! DependencyRecord conflicting; conflicting.name = "fmt"; conflicting.source_kind = DependencySourceKind::Package; conflicting.package = "fmt"; conflicting.version = "^10.0"; // Conflicts with ^11.0 in TOML! auto merged_bad = Package::merge_dependencies({conflicting}, *loaded); Void::Testing::expect(!merged_bad.has_value()); if (!merged_bad) { Void::Testing::expect(merged_bad.error().message().find("build.cpp") != std::string::npos); Void::Testing::expect(merged_bad.error().message().find("vbs.deps.toml") != std::string::npos); } // PubGrub diamond resolution + pinned non-upgrade + registry authority isolation + conflict // trace. Package::PackageIndex index; const Package::PackageId regA_foo{"https://regA.example", "foo"}; const Package::PackageId regB_foo{"https://regB.example", "foo"}; const Package::PackageId regA_bar{"https://regA.example", "bar"}; const Package::PackageId regA_baz{"https://regA.example", "baz"}; auto ver = [](std::string_view s) { return *Void::Semver::parse_strict(s); }; index.add_release( {regA_foo, ver("1.0.0"), false, "sha_f10", "", {{regA_bar, "^1.0", {}, "foo"}}, {}}); index.add_release( {regA_foo, ver("1.1.0"), false, "sha_f11", "", {{regA_bar, "^1.2", {}, "foo"}}, {}}); index.add_release({regA_foo, ver("1.2.0"), true, "sha_f12_yanked", "", {}, {}}); // Yanked! index.add_release( {regB_foo, ver("9.0.0"), false, "sha_regB", "", {}, {}}); // Separate registry! index.add_release({regA_bar, ver("1.0.0"), false, "sha_b10", "", {}, {}}); index.add_release({regA_bar, ver("1.1.0"), false, "sha_b11", "", {}, {}}); index.add_release({regA_bar, ver("1.2.0"), false, "sha_b12", "", {}, {}}); index.add_release( {regA_baz, ver("1.0.0"), false, "sha_z10", "", {{regA_bar, "<1.2.0", {}, "baz"}}, {}}); // Diamond: root needs foo ^1.0 AND baz ^1.0. // foo 1.1.0 requires bar ^1.2, conflicting with baz 1.0.0 requiring bar <1.2.0. // Solver MUST backtrack from foo 1.1.0 to foo 1.0.0 + bar 1.1.0 (and skip yanked 1.2.0 & regB)! auto solved = Package::solve_dependencies( {{regA_foo, "^1.0", {}, "root"}, {regA_baz, "^1.0", {}, "root"}}, index); Void::Testing::expect(solved.has_value()); if (solved) { Void::Testing::expect_eq(solved->packages.at(regA_foo).version.to_string(), std::string{"1.0.0"}); Void::Testing::expect_eq(solved->packages.at(regA_bar).version.to_string(), std::string{"1.1.0"}); Void::Testing::expect(!solved->packages.contains(regB_foo)); } // Pinned compatible version (bar 1.0.0) must NOT silently upgrade to 1.1.0! Package::SolveOptions pin_opts; pin_opts.pinned_versions[regA_bar] = ver("1.0.0"); auto solved_pinned = Package::solve_dependencies( {{regA_foo, "^1.0", {}, "root"}, {regA_baz, "^1.0", {}, "root"}}, index, pin_opts); Void::Testing::expect(solved_pinned.has_value()); if (solved_pinned) { Void::Testing::expect_eq(solved_pinned->packages.at(regA_bar).version.to_string(), std::string{"1.0.0"}); } // Unsatisfiable conflict returns clear diagnostic naming packages. auto unsat = Package::solve_dependencies({{regA_bar, ">=2.0.0", {}, "root"}}, index); Void::Testing::expect(!unsat.has_value()); // Atomic CAS lockfile: multiple profiles coexist; --locked refuses mutation; mismatch fails! const auto lock_path = tmp / "vbs.lock"; auto dbg = default_profiles().resolve("debug", CompilerFamily::Gcc, "Linux", "x86_64"); auto rel = default_profiles().resolve("release", CompilerFamily::Gcc, "Linux", "x86_64"); Package::LockContextRecord ctx_dbg{ Package::make_lock_context_key(dbg, "target"), "debug", "gcc", "Linux", "x86_64", "target", Package::compute_declaration_fingerprint(dbg, "target", *loaded), {}}; Package::LockContextRecord ctx_rel{ Package::make_lock_context_key(rel, "target"), "release", "gcc", "Linux", "x86_64", "target", Package::compute_declaration_fingerprint(rel, "target", *loaded), {}}; // --locked refuses creating missing lock. Void::Testing::expect( !Package::publish_lock_context_cas(lock_path, "", ctx_dbg, true).has_value()); auto p1 = Package::publish_lock_context_cas(lock_path, "", ctx_dbg, false); Void::Testing::expect(p1.has_value()); if (!p1) return; // Concurrent release profile update merges cleanly without overwriting debug! auto p2 = Package::publish_lock_context_cas(lock_path, p1->revision_hash, ctx_rel, false); Void::Testing::expect(p2.has_value()); if (p2) { Void::Testing::expect(p2->document.contexts.contains(ctx_dbg.context_key)); Void::Testing::expect(p2->document.contexts.contains(ctx_rel.context_key)); // Changed declaration fingerprint fails validation! Void::Testing::expect( !Package::validate_locked_context(p2->document, ctx_dbg.context_key, "changed_fp") .has_value()); } } // === Plan 12: Deterministic tar, malicious archive security, binary ABI matching, redaction === VOID_TEST(FullV1Tests, archive_security_determinism_binary_abi_and_redaction) { Void::FileSystem::TempDir tmp{"vbs_arc_"}; const auto proj = tmp / "pkg_src"; write_file(proj / "build.cpp", "void build(Void::Build::Project&) {}\n"); write_file(proj / "build-support" / "Helper.hpp", "// helper\n"); write_file(proj / ".git" / "HEAD", "ref: refs/heads/main\n"); write_file(proj / ".env", "SECRET=123\n"); const auto tar1 = tmp / "pkg1.tar"; const auto tar2 = tmp / "pkg2.tar"; auto sha1 = Package::create_source_package(proj, tar1, 0); auto sha2 = Package::create_source_package(proj, tar2, 0); Void::Testing::expect(sha1.has_value() && sha2.has_value() && *sha1 == *sha2); const auto out_dir = tmp / "extracted"; auto stats = Package::extract_safe_tar(tar1, out_dir); Void::Testing::expect(stats.has_value()); Void::Testing::expect(std::filesystem::exists(out_dir / "build-support" / "Helper.hpp")); Void::Testing::expect(!std::filesystem::exists(out_dir / ".git" / "HEAD")); Void::Testing::expect(!std::filesystem::exists(out_dir / ".env")); // An archive written inside the project never contains itself on a later run. const auto inner_tar = proj / "dist" / "pkg.tar"; Void::Testing::expect(Package::create_source_package(proj, inner_tar, 0).has_value()); Void::Testing::expect(Package::create_source_package(proj, inner_tar, 0).has_value()); const auto inner_out = tmp / "inner_extracted"; Void::Testing::expect(Package::extract_safe_tar(inner_tar, inner_out).has_value()); Void::Testing::expect(!std::filesystem::exists(inner_out / "dist" / "pkg.tar")); // Malicious tar rejection: path traversal, absolute path, symlink, duplicate path, quota. const auto trav_tar = tmp / "trav.tar"; write_raw_tar(trav_tar, {{"../escape.txt", '0', "evil"}}); Void::Testing::expect(!Package::extract_safe_tar(trav_tar, tmp / "x1").has_value()); const auto abs_tar = tmp / "abs.tar"; write_raw_tar(abs_tar, {{"/tmp/evil.txt", '0', "evil"}}); Void::Testing::expect(!Package::extract_safe_tar(abs_tar, tmp / "x2").has_value()); const auto sym_tar = tmp / "sym.tar"; write_raw_tar(sym_tar, {{"link.txt", '2', ""}}); Void::Testing::expect(!Package::extract_safe_tar(sym_tar, tmp / "x3").has_value()); const auto dup_tar = tmp / "dup.tar"; write_raw_tar(dup_tar, {{"a.txt", '0', "1"}, {"a.txt", '0', "2"}}); Void::Testing::expect(!Package::extract_safe_tar(dup_tar, tmp / "x4").has_value()); // Secret redaction. const auto redacted = Package::redact_secrets("fetch https://alice:supersecret@reg.example/a Bearer tok_xyz123"); Void::Testing::expect(redacted.find("supersecret") == std::string::npos); Void::Testing::expect(redacted.find("tok_xyz123") == std::string::npos); // Binary ABI key rejects mismatched sanitizer/LTO/ABI. Package::BinaryCompatibilityKey key{"Linux", "x86_64", "gcc", "16.2", "libstdc++", "static", "", "address", "none", "dep_abc"}; Package::BinaryVariantMeta mismatch{"v1", "Linux", "x86_64", "gcc", "16.2", "libstdc++", "static", "", "", "none", "dep_abc", "sha", "url"}; Package::BinaryVariantMeta exact = mismatch; exact.sanitizers_key = "address"; Void::Testing::expect(!Package::select_compatible_binary(key, {mismatch}).has_value()); Void::Testing::expect(Package::select_compatible_binary(key, {mismatch, exact}).has_value()); } // === Plan 13, 14, 15: Real CMake provider, Meson provider, VbsDeps.cmake bridge, Install/Relocate // === VOID_TEST(FullV1Tests, foreign_cmake_meson_providers_bridge_and_relocatable_install) { Void::FileSystem::TempDir tmp{"vbs_foreign_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // 1. Real CMake dependency project built via CMake File API provider! const auto cm_src = tmp / "cm_dep"; write_file(cm_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(cm_dep LANGUAGES CXX) add_library(cm_math STATIC src/math.cpp) target_include_directories(cm_math PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_definitions(cm_math PUBLIC CM_DEP_DEFINED=1) )cmake"); write_file(cm_src / "include" / "cm_math.hpp", "#pragma once\nint cm_magic();\n"); write_file(cm_src / "src" / "math.cpp", "#include \"cm_math.hpp\"\nint cm_magic() { return 100; }\n"); DependencyRecord cm_dep; cm_dep.name = "cm_dep"; cm_dep.source_kind = DependencySourceKind::Path; cm_dep.location = cm_src.string(); cm_dep.builder = "cmake"; auto mat_cm = Package::materialize_dependency_source(cm_dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat_cm.has_value()); if (!mat_cm) return; // MetadataOnly BEFORE build MUST return stale_needs_build=true without invoking CMake! auto stale_cm = Provider::resolve_foreign_provider( {cm_dep, *mat_cm, ctx, *tc, tmp / "prov", Provider::ProviderMode::MetadataOnly, {}}); Void::Testing::expect(stale_cm.has_value() && stale_cm->stale_needs_build); // FullBuild invokes CMake + File API and imports cm_math! auto built_cm = Provider::resolve_foreign_provider( {cm_dep, *mat_cm, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}); Void::Testing::expect(built_cm.has_value() && built_cm->targets.contains("cm_dep::cm_math")); if (!built_cm) return; // MetadataOnly AFTER build reads validated cache with from_cache=true! auto cached_cm = Provider::resolve_foreign_provider( {cm_dep, *mat_cm, ctx, *tc, tmp / "prov", Provider::ProviderMode::MetadataOnly, {}}); Void::Testing::expect(cached_cm.has_value() && cached_cm->from_cache && !cached_cm->stale_needs_build); // Timestamp-preserved source edit invalidates provider input hash! auto old_meta = Platform::stat_lstat(cm_src / "src" / "math.cpp"); write_file(cm_src / "src" / "math.cpp", "#include \"cm_math.hpp\"\nint cm_magic() { return 200; }\n"); (void)Platform::set_canonical_mtime(cm_src / "src" / "math.cpp", old_meta->mtime_sec); auto mat_cm2 = Package::materialize_dependency_source(cm_dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat_cm2.has_value() && mat_cm2->content_identity_hash != mat_cm->content_identity_hash); auto built_cm2 = Provider::resolve_foreign_provider( {cm_dep, *mat_cm2, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}); Void::Testing::expect(built_cm2.has_value()); if (!built_cm2) return; // 2. Real Meson dependency project (if meson is in PATH)! if (Platform::resolve_executable("meson").has_value()) { const auto m_src = tmp / "meson_dep"; write_file(m_src / "meson.build", R"meson( project('meson_dep', 'cpp') inc = include_directories('include') static_library('m_helper', 'src/helper.cpp', include_directories: inc) )meson"); write_file(m_src / "include" / "m_helper.hpp", "#pragma once\nint m_magic();\n"); write_file(m_src / "src" / "helper.cpp", "#include \"m_helper.hpp\"\nint m_magic() { return 23; }\n"); DependencyRecord m_dep; m_dep.name = "meson_dep"; m_dep.source_kind = DependencySourceKind::Path; m_dep.location = m_src.string(); m_dep.builder = "meson"; auto mat_m = Package::materialize_dependency_source(m_dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat_m.has_value()); if (mat_m) { auto built_m = Provider::resolve_foreign_provider( {m_dep, *mat_m, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}); Void::Testing::expect(built_m.has_value() && built_m->targets.contains("meson_dep::m_helper")); } } // 3. Missing Conan fails explicitly (never empty success!). if (!Platform::resolve_executable("conan").has_value()) { DependencyRecord conan_dep; conan_dep.name = "zlib"; conan_dep.source_kind = DependencySourceKind::Conan; conan_dep.package = "zlib/1.3.1"; conan_dep.builder = "conan"; Package::MaterializedSource dummy{"zlib", cm_src, "dummy", true}; auto cres = Provider::resolve_foreign_provider( {conan_dep, dummy, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}); Void::Testing::expect(!cres.has_value()); } // 4. Native consumer links updated cm_dep::cm_math (returns 200!), installs & relocates prefix! const auto consumer_proj = tmp / "consumer"; write_file(consumer_proj / "include" / "wrap.hpp", "#pragma once\nint wrapped_magic();\n"); write_file(consumer_proj / "src" / "wrap.cpp", "#include \"wrap.hpp\"\n#include \"cm_math.hpp\"\nint wrapped_magic(){return " "cm_magic()+CM_DEP_DEFINED;}\n"); write_file(consumer_proj / "src" / "main.cpp", "#include \"wrap.hpp\"\nint main(){return wrapped_magic()==201 ? 0 : 1;}\n"); Graph::ProjectDescription desc; desc.profile = ctx; TargetRecord wlib; wlib.name = "wrap"; wlib.kind = TargetKind::StaticLibrary; wlib.sources.push_back({SourceKind::File, "src/wrap.cpp"}); wlib.include_directories.push_back({"include", Visibility::Public, false}); wlib.links.push_back({LinkKind::Imported, "cm_math", "cm_dep", Visibility::Private}); wlib.install_rule = InstallRule{"wrap", {}, "lib", "default", false}; desc.targets.push_back(wlib); TargetRecord app; app.name = "app"; app.kind = TargetKind::Executable; app.sources.push_back({SourceKind::File, "src/main.cpp"}); app.links.push_back({LinkKind::Local, "wrap", {}, Visibility::Private}); desc.targets.push_back(app); desc.install_rules.push_back({{}, "include", "include", "default", true}); auto graph = Graph::lower_project_graph( desc, *tc, {consumer_proj, tmp / "cbuild", nullptr, built_cm2->targets, 32768}); Void::Testing::expect(graph.has_value()); if (!graph) return; auto state = State::StateStore::open(tmp / "cbuild" / ".vbs"); Void::Testing::expect(state.has_value()); if (!state) return; auto exec = Execution::execute_graph(*graph, *state); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest app_req; app_req.executable = tmp / "cbuild" / "profiles" / "debug" / "out" / "bin" / "app"; auto run_app = Platform::run_supervised(app_req); Void::Testing::expect(run_app.has_value() && run_app->succeeded()); // Install -> Relocate prefix A to B -> Safe uninstall preserves unrelated user file! const auto prefix_a = tmp / "prefix_a"; const auto prefix_b = tmp / "prefix_b"; auto inst = Install::install_project(desc, *graph, {"WrapPkg", "1.2.3", prefix_a, std::nullopt, true, true}); Void::Testing::expect(inst.has_value() && inst->cmake_config_file.has_value()); if (inst && inst->cmake_config_file) { auto cm_cfg = Void::FileSystem::read_file(*inst->cmake_config_file); Void::Testing::expect(cm_cfg.has_value() && cm_cfg->find("cbuild") == std::string::npos); } std::filesystem::rename(prefix_a, prefix_b); write_file(prefix_b / "user_notes.txt", "keep me"); auto removed = Install::uninstall_prefix(prefix_b); Void::Testing::expect(removed.has_value() && *removed >= 3); Void::Testing::expect(std::filesystem::exists(prefix_b / "user_notes.txt")); Void::Testing::expect(!std::filesystem::exists(prefix_b / "lib" / "libwrap.a")); // 5. Real CMake Bridge (VbsDeps.cmake) consumer test! const auto vbs_bin = locate_vbs_binary(); const auto bridge_module = std::filesystem::path{Bootstrap::source_dir} / "cmake" / "bridge" / "VbsDeps.cmake"; if (!vbs_bin.empty() && std::filesystem::exists(vbs_bin) && Platform::resolve_executable("cmake").has_value()) { const auto br_proj = tmp / "bridge_consumer"; write_file(br_proj / "CMakeLists.txt", "cmake_minimum_required(VERSION 4.0)\n" "project(bridge_consumer LANGUAGES CXX)\n" "include(\"" + bridge_module.string() + "\")\n" "vbs_declare_dependency(cm_dep PATH \"" + cm_src.string() + "\" BUILDER cmake)\n" "vbs_make_available(cm_dep)\n" "add_executable(bapp main.cpp)\n" "target_link_libraries(bapp PRIVATE cm_dep::cm_math)\n"); write_file(br_proj / "main.cpp", "#include \"cm_math.hpp\"\nint main(){return cm_magic()==200 ? 0 : 1;}\n"); const auto br_build = tmp / "bridge_build"; Platform::ProcessRequest cfg_req; cfg_req.executable = "cmake"; cfg_req.arguments = {"-S", br_proj.string(), "-B", br_build.string(), "-G", "Ninja", "-DVBS_EXECUTABLE=" + vbs_bin.string()}; auto cfg_res = Platform::run_supervised(cfg_req); Void::Testing::expect(cfg_res.has_value() && cfg_res->succeeded()); if (cfg_res && cfg_res->succeeded()) { Platform::ProcessRequest bld_req; bld_req.executable = "cmake"; bld_req.arguments = {"--build", br_build.string()}; auto bld_res = Platform::run_supervised(bld_req); Void::Testing::expect(bld_res.has_value() && bld_res->succeeded()); Platform::ProcessRequest br_run_req; br_run_req.executable = br_build / "bapp"; auto run_res = Platform::run_supervised(br_run_req); Void::Testing::expect(run_res.has_value() && run_res->succeeded()); } // 6. Real `vbs install` and `vbs uninstall` CLI subcommands! const auto cli_proj = tmp / "cli_inst_proj"; const auto cli_build = tmp / "cli_inst_build"; const auto cli_prefix = tmp / "cli_inst_prefix"; write_file(cli_proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.executable("cli_hi").sources({"src/main.cpp"}).install("bin"); } )cpp"); write_file(cli_proj / "src" / "main.cpp", "int main() { return 0; }\n"); Platform::ProcessRequest inst_req; inst_req.executable = vbs_bin; const auto installer_archive = tmp / "cli_hi-installer.tar"; inst_req.arguments = {"install", "--project", cli_proj.string(), "--build-dir", cli_build.string(), "--prefix", cli_prefix.string(), "--package-name", "CliHiPkg", "--bundle-dependencies", "--archive", installer_archive.string()}; auto inst_cli = Platform::run_supervised(inst_req); Void::Testing::expect(inst_cli.has_value() && inst_cli->succeeded()); Void::Testing::expect(std::filesystem::exists(cli_prefix / "bin" / "cli_hi")); Void::Testing::expect( std::filesystem::exists(cli_prefix / "share" / "vbs" / "CliHiPkg" / "package.json")); // The installer archive is a deterministic, self-contained snapshot of the prefix. Void::Testing::expect(std::filesystem::exists(installer_archive)); const auto unpacked = tmp / "cli_inst_unpacked"; auto unpack = Package::extract_safe_tar(installer_archive, unpacked); Void::Testing::expect(unpack.has_value()); Void::Testing::expect(std::filesystem::exists(unpacked / "bin" / "cli_hi")); Void::Testing::expect( std::filesystem::exists(unpacked / "share" / "vbs" / "CliHiPkg" / "package.json")); const auto archive_a = tmp / "cli_hi-installer-a.tar"; const auto archive_b = tmp / "cli_hi-installer-b.tar"; auto req_a = inst_req; auto req_b = inst_req; for (auto &arg : req_a.arguments) { if (arg == installer_archive.string()) { arg = archive_a.string(); } } for (auto &arg : req_b.arguments) { if (arg == installer_archive.string()) { arg = archive_b.string(); } } Void::Testing::expect( Platform::run_supervised(req_a).value_or(Platform::ProcessResult{}).succeeded()); Void::Testing::expect( Platform::run_supervised(req_b).value_or(Platform::ProcessResult{}).succeeded()); const auto bytes_a = Void::FileSystem::read_file(archive_a); const auto bytes_b = Void::FileSystem::read_file(archive_b); Void::Testing::expect(bytes_a.has_value() && bytes_b.has_value() && *bytes_a == *bytes_b); // CPack-style self-extracting installer script. const auto script_archive = tmp / "cli_hi-installer.sh"; auto script_req = inst_req; for (auto &arg : script_req.arguments) { if (arg == installer_archive.string()) { arg = script_archive.string(); } } script_req.arguments.push_back("--archive-format"); script_req.arguments.push_back("sh"); auto script_res = Platform::run_supervised(script_req); Void::Testing::expect(script_res.has_value() && script_res->succeeded()); Void::Testing::expect(std::filesystem::exists(script_archive)); if (script_res && script_res->succeeded()) { const auto script_prefix = tmp / "cli_script_prefix"; Platform::ProcessRequest run_script; run_script.executable = "/bin/sh"; run_script.arguments = {script_archive.string(), "--prefix", script_prefix.string()}; auto run_res = Platform::run_supervised(run_script); Void::Testing::expect(run_res.has_value() && run_res->succeeded()); Void::Testing::expect(std::filesystem::exists(script_prefix / "bin" / "cli_hi")); Void::Testing::expect(std::filesystem::exists(script_prefix / "share" / "vbs" / "CliHiPkg" / "package.json")); } // Stored ZIP package generator. const auto zip_archive = tmp / "cli_hi.zip"; auto zip_req = inst_req; for (auto &arg : zip_req.arguments) { if (arg == installer_archive.string()) { arg = zip_archive.string(); } } zip_req.arguments.push_back("--archive-format"); zip_req.arguments.push_back("zip"); auto zip_res = Platform::run_supervised(zip_req); Void::Testing::expect(zip_res.has_value() && zip_res->succeeded()); auto zip_bytes = Void::FileSystem::read_file(zip_archive); Void::Testing::require(zip_bytes.has_value()); const std::string zip_local_sig = std::string{"PK"} + char(3) + char(4); const std::string zip_eocd_sig = std::string{"PK"} + char(5) + char(6); Void::Testing::expect(zip_bytes->find(zip_local_sig) != std::string::npos); Void::Testing::expect(zip_bytes->rfind(zip_eocd_sig) != std::string::npos); Void::Testing::expect(zip_bytes->find("bin/cli_hi") != std::string::npos); Void::Testing::expect(zip_bytes->find("share/vbs/CliHiPkg/package.json") != std::string::npos); // Debian package generator: ar(debian-binary, control.tar, data.tar). const auto deb_archive = tmp / "cli_hi.deb"; auto deb_req = inst_req; for (auto &arg : deb_req.arguments) { if (arg == installer_archive.string()) { arg = deb_archive.string(); } } deb_req.arguments.push_back("--archive-format"); deb_req.arguments.push_back("deb"); auto deb_res = Platform::run_supervised(deb_req); Void::Testing::expect(deb_res.has_value() && deb_res->succeeded()); auto deb_bytes = Void::FileSystem::read_file(deb_archive); Void::Testing::require(deb_bytes.has_value()); Void::Testing::expect(deb_bytes->starts_with("!\n")); std::vector> members; if (deb_bytes->starts_with("!\n")) { std::size_t pos = 8; while (pos + 60 <= deb_bytes->size()) { std::string member_name = deb_bytes->substr(pos, 16); const auto name_end = member_name.find(' '); if (name_end != std::string::npos) { member_name.resize(name_end); } if (!member_name.empty() && member_name.back() == '/') { member_name.pop_back(); } std::size_t member_size = 0; try { member_size = static_cast(std::stoul(deb_bytes->substr(pos + 48, 10))); } catch (...) { break; } members.emplace_back(member_name, deb_bytes->substr(pos + 60, member_size)); pos += 60 + member_size + (member_size % 2); } } Void::Testing::require(members.size() >= 3); Void::Testing::expect_eq(members.at(0).first, std::string{"debian-binary"}); Void::Testing::expect_eq(members.at(0).second, std::string{"2.0\n"}); const auto find_member = [&](std::string_view name) -> std::optional { for (const auto &[member_name, content] : members) { if (member_name == name) { return content; } } return std::nullopt; }; auto control_member = find_member("control.tar"); Void::Testing::require(control_member.has_value()); const auto control_out = tmp / "deb_control"; if (control_member) { const auto control_tar_path = tmp / "control.tar"; write_file(control_tar_path, *control_member); Void::Testing::expect( Package::extract_safe_tar(control_tar_path, control_out).has_value()); const auto control_text = Void::FileSystem::read_file(control_out / "control"); Void::Testing::require(control_text.has_value()); Void::Testing::expect(control_text->find("Package: CliHiPkg") != std::string::npos); Void::Testing::expect(control_text->find("Architecture: ") != std::string::npos); } auto data_member = find_member("data.tar"); Void::Testing::require(data_member.has_value()); const auto data_out = tmp / "deb_data"; if (data_member) { const auto data_tar_path = tmp / "data.tar"; write_file(data_tar_path, *data_member); Void::Testing::expect(Package::extract_safe_tar(data_tar_path, data_out).has_value()); Void::Testing::expect(std::filesystem::exists(data_out / "bin" / "cli_hi")); } // Signed installer archive: Ed25519 detached signature plus checksums. const auto signed_archive = tmp / "cli_hi-signed.tar"; const auto signing_seed = tmp / "install.seed"; auto sign_req = inst_req; for (auto &arg : sign_req.arguments) { if (arg == installer_archive.string()) { arg = signed_archive.string(); } } sign_req.arguments.push_back("--signing-key"); sign_req.arguments.push_back(signing_seed.string()); const bool signing_ready = Provenance::signing_available(); if (signing_ready) { Void::Testing::require(Provenance::generate_signing_seed(signing_seed).has_value()); } auto sign_res = Platform::run_supervised(sign_req); if (signing_ready) { Void::Testing::expect(sign_res.has_value() && sign_res->succeeded()); Void::Testing::expect(std::filesystem::exists(signed_archive.string() + ".sha256")); Void::Testing::expect(std::filesystem::exists(signed_archive.string() + ".sig")); Void::Testing::expect(std::filesystem::exists(signed_archive.string() + ".pub")); auto archive_bytes = Void::FileSystem::read_file(signed_archive); 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() && 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{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()); } // WiX source generator for MSI packaging on Windows. const auto wix_source = tmp / "cli_hi.wxs"; auto wix_req = inst_req; for (auto &arg : wix_req.arguments) { if (arg == installer_archive.string()) { arg = wix_source.string(); } } wix_req.arguments.push_back("--archive-format"); wix_req.arguments.push_back("wix"); auto wix_res = Platform::run_supervised(wix_req); Void::Testing::expect(wix_res.has_value() && wix_res->succeeded()); auto wix_text = Void::FileSystem::read_file(wix_source); Void::Testing::require(wix_text.has_value()); Void::Testing::expect(wix_text->starts_with("find("find("Version=\"0.1.0\"") != std::string::npos); Void::Testing::expect(wix_text->find("UpgradeCode=") != std::string::npos); Void::Testing::expect(wix_text->find("Source=\"bin/cli_hi\"") != std::string::npos); Void::Testing::expect(wix_text->find("ComponentGroup Id=\"ProductComponents\"") != std::string::npos); // UDIF (DMG-style) container: tar payload followed by a 512-byte koly trailer. const auto dmg_archive = tmp / "cli_hi.dmg"; auto dmg_req = inst_req; for (auto &arg : dmg_req.arguments) { if (arg == installer_archive.string()) { arg = dmg_archive.string(); } } dmg_req.arguments.push_back("--archive-format"); dmg_req.arguments.push_back("dmg"); auto dmg_res = Platform::run_supervised(dmg_req); Void::Testing::expect(dmg_res.has_value() && dmg_res->succeeded()); auto dmg_bytes = Void::FileSystem::read_file(dmg_archive); Void::Testing::require(dmg_bytes.has_value() && dmg_bytes->size() > 512); const auto dmg_length = dmg_bytes->size(); const std::string koly = dmg_bytes->substr(dmg_length - 512); const auto read_be32 = [](std::string_view bytes, std::size_t offset) { std::uint32_t value = 0; for (std::size_t i = 0; i < 4; ++i) { value = (value << 8) | static_cast(bytes[offset + i]); } return value; }; const auto read_be64 = [](std::string_view bytes, std::size_t offset) { std::uint64_t value = 0; for (std::size_t i = 0; i < 8; ++i) { value = (value << 8) | static_cast(bytes[offset + i]); } return value; }; Void::Testing::expect(koly.starts_with("koly")); Void::Testing::expect_eq(read_be32(koly, 8), std::uint32_t{512}); const std::uint64_t data_fork_length = read_be64(koly, 32); Void::Testing::expect_eq(data_fork_length, static_cast(dmg_length - 512)); Void::Testing::expect_eq(read_be32(koly, 80), std::uint32_t{2}); // CRC-32 std::uint32_t crc = 0xFFFFFFFFu; for (const char ch : dmg_bytes->substr(0, data_fork_length)) { crc ^= static_cast(static_cast(ch)); for (int bit = 0; bit < 8; ++bit) { crc = (crc >> 1) ^ (0xEDB88320u & (0u - (crc & 1u))); } } Void::Testing::expect_eq(read_be32(koly, 88), ~crc); Void::Testing::expect_eq(read_be64(koly, 492), (data_fork_length + 511) / 512); Void::Testing::expect(dmg_bytes->substr(257, 5) == "ustar"); // tar payload // NuGet package (.nupkg): OPC ZIP with the nuspec and native runtime assets. const auto nupkg_archive = tmp / "cli_hi.nupkg"; auto nuget_req = inst_req; for (auto &arg : nuget_req.arguments) { if (arg == installer_archive.string()) { arg = nupkg_archive.string(); } } nuget_req.arguments.push_back("--archive-format"); nuget_req.arguments.push_back("nuget"); auto nuget_res = Platform::run_supervised(nuget_req); Void::Testing::expect(nuget_res.has_value() && nuget_res->succeeded()); auto nupkg_bytes = Void::FileSystem::read_file(nupkg_archive); Void::Testing::require(nupkg_bytes.has_value()); Void::Testing::expect(nupkg_bytes->starts_with(std::string("PK\x03\x04", 4))); Void::Testing::expect(nupkg_bytes->find("CliHiPkg.nuspec") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("CliHiPkg") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("0.1.0") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("[Content_Types].xml") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("_rels/.rels") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("runtimes/") != std::string::npos); Void::Testing::expect(nupkg_bytes->find("/native/bin/cli_hi") != std::string::npos); // RPM package generator: lead + header magic + newc cpio payload. const auto rpm_archive = tmp / "cli_hi.rpm"; auto rpm_req = inst_req; for (auto &arg : rpm_req.arguments) { if (arg == installer_archive.string()) { arg = rpm_archive.string(); } } rpm_req.arguments.push_back("--archive-format"); rpm_req.arguments.push_back("rpm"); auto rpm_res = Platform::run_supervised(rpm_req); Void::Testing::expect(rpm_res.has_value() && rpm_res->succeeded()); auto rpm_bytes = Void::FileSystem::read_file(rpm_archive); Void::Testing::require(rpm_bytes.has_value()); Void::Testing::expect(rpm_bytes->starts_with(std::string("\xed\xab\xee\xdb", 4))); Void::Testing::expect(rpm_bytes->substr(96, 3) == std::string("\x8e\xad\xe8", 3)); Void::Testing::expect(rpm_bytes->find("CliHiPkg") != std::string::npos); Void::Testing::expect(rpm_bytes->find("070701") != std::string::npos); Void::Testing::expect(rpm_bytes->find("TRAILER!!!") != std::string::npos); Platform::ProcessRequest uninst_req; uninst_req.executable = vbs_bin; uninst_req.arguments = {"uninstall", "--prefix", cli_prefix.string()}; auto uninst_cli = Platform::run_supervised(uninst_req); Void::Testing::expect(uninst_cli.has_value() && uninst_cli->succeeded()); Void::Testing::expect(!std::filesystem::exists(cli_prefix / "bin" / "cli_hi")); } } // === Editor plugin asset export === VOID_TEST(FullV1Tests, ide_plugin_assets_export_vscode_extension) { Void::FileSystem::TempDir tmp{"vbs_plugin_"}; Editor::IdePluginOptions options; options.project_root = tmp / "proj"; options.build_root = tmp / "build"; options.vbs_executable = "/opt/vbs/bin/vbs"; options.editor = Editor::IdeKind::VsCode; options.output_dir = tmp / "vbs-tools"; options.force = true; auto report = Editor::generate_ide_plugin_assets(options); Void::Testing::require(report.has_value()); Void::Testing::expect_eq(report->written_files.size(), std::size_t{4}); Void::Testing::expect(std::filesystem::exists(options.output_dir / "package.json")); Void::Testing::expect(std::filesystem::exists(options.output_dir / "extension.js")); Void::Testing::expect( std::filesystem::exists(options.output_dir / "test" / "extension.test.js")); Void::Testing::expect(std::filesystem::exists(options.output_dir / "README.md")); auto manifest_text = Void::FileSystem::read_file(options.output_dir / "package.json"); Void::Testing::require(manifest_text.has_value()); auto manifest = Void::Json::Strict::parse(*manifest_text); Void::Testing::require(manifest.has_value()); const auto *manifest_object = std::get_if(&manifest->value); Void::Testing::require(manifest_object != nullptr); const auto contributes_it = manifest_object->find("contributes"); Void::Testing::require(contributes_it != manifest_object->end()); const auto *contributes = std::get_if(&contributes_it->second.value); Void::Testing::require(contributes != nullptr); const auto commands_it = contributes->find("commands"); Void::Testing::require(commands_it != contributes->end()); const auto *commands = std::get_if(&commands_it->second.value); Void::Testing::require(commands != nullptr); Void::Testing::expect_eq(commands->size(), std::size_t{6}); auto extension_text = Void::FileSystem::read_file(options.output_dir / "extension.js"); Void::Testing::require(extension_text.has_value()); Void::Testing::expect(extension_text->find("VBS_BIN || \"vbs\"") != std::string::npos); Void::Testing::expect(extension_text->find("workspaceFolders") != std::string::npos); Void::Testing::expect(extension_text->find("vbs.build") != std::string::npos); Void::Testing::expect(extension_text->find("vbs.package") != std::string::npos); auto test_text = Void::FileSystem::read_file(options.output_dir / "test" / "extension.test.js"); Void::Testing::require(test_text.has_value()); Void::Testing::expect(test_text->find("createTerminal") != std::string::npos); Void::Testing::expect(test_text->find("const expectedCommands = 6;") != std::string::npos); Void::Testing::expect(manifest_text->find("\"test\": \"node test/extension.test.js\"") != std::string::npos); // VSIX packaging: a ZIP with the VS Code extension layout and valid CRCs. { auto vsix_options = options; vsix_options.output_dir = tmp / "vbs-tools-vsix"; vsix_options.vsix_path = tmp / "dist" / "vbs-tools.vsix"; auto vsix_report = Editor::generate_ide_plugin_assets(vsix_options); Void::Testing::require(vsix_report.has_value()); auto vsix_bytes = Void::FileSystem::read_file(*vsix_options.vsix_path); Void::Testing::require(vsix_bytes.has_value()); const std::string_view zip = *vsix_bytes; const auto read_u16 = [&](std::size_t o) { return static_cast(static_cast(zip[o]) | (static_cast(zip[o + 1]) << 8)); }; const auto read_u32 = [&](std::size_t o) { std::uint32_t v = 0; for (int i = 3; i >= 0; --i) { v = (v << 8) | static_cast(zip[o + static_cast(i)]); } return v; }; const auto eocd = zip.rfind(std::string_view{"PK\x05\x06", 4}); Void::Testing::require(eocd != std::string_view::npos); const auto entry_count = read_u16(eocd + 10); std::size_t offset = read_u32(eocd + 16); std::vector names; std::size_t checked = 0; for (std::uint16_t i = 0; i < entry_count; ++i) { Void::Testing::require(zip.substr(offset, 4) == std::string_view{"PK\x01\x02", 4}); const auto crc_expected = read_u32(offset + 16); const auto name_len = read_u16(offset + 28); const auto extra_len = read_u16(offset + 30); const auto comment_len = read_u16(offset + 32); const auto local_offset = read_u32(offset + 42); names.emplace_back(zip.substr(offset + 46, name_len)); // Recompute the CRC from the local entry data. const auto local_name_len = read_u16(local_offset + 26); const auto local_extra_len = read_u16(local_offset + 28); const auto data_size = read_u32(local_offset + 22); const auto data_start = static_cast(local_offset) + 30 + local_name_len + local_extra_len; std::uint32_t crc = 0xFFFFFFFFu; for (std::size_t b = data_start; b < data_start + data_size; ++b) { crc ^= static_cast(zip[b]); for (int bit = 0; bit < 8; ++bit) { crc = (crc >> 1) ^ (0xEDB88320u & (0u - (crc & 1u))); } } Void::Testing::expect_eq(~crc, crc_expected); ++checked; offset += 46 + name_len + extra_len + comment_len; } Void::Testing::expect_eq(checked, std::size_t{6}); const auto has_entry = [&](std::string_view name) { return std::ranges::contains(names, name); }; Void::Testing::expect(has_entry("extension.vsixmanifest")); Void::Testing::expect(has_entry("[Content_Types].xml")); Void::Testing::expect(has_entry("extension/package.json")); Void::Testing::expect(has_entry("extension/extension.js")); Void::Testing::expect(has_entry("extension/test/extension.test.js")); Void::Testing::expect(zip.find("Id=\"vbs-tools\"") != std::string_view::npos); Void::Testing::expect(zip.find("Path=\"extension/package.json\"") != std::string_view::npos); Void::Testing::expect(!std::filesystem::exists(vsix_options.output_dir / ".vsix")); } auto zed_options = options; zed_options.editor = Editor::IdeKind::Zed; zed_options.output_dir = tmp / "vbs-zed"; auto zed_report = Editor::generate_ide_plugin_assets(zed_options); Void::Testing::require(zed_report.has_value()); Void::Testing::expect_eq(zed_report->written_files.size(), std::size_t{3}); Void::Testing::expect(std::filesystem::exists(zed_options.output_dir / "extension.toml")); auto zed_tasks = Void::FileSystem::read_file(zed_options.output_dir / "tasks.json"); Void::Testing::require(zed_tasks.has_value()); auto zed_tasks_json = Void::Json::Strict::parse(*zed_tasks); Void::Testing::require(zed_tasks_json.has_value()); const auto *zed_array = std::get_if(&zed_tasks_json->value); Void::Testing::require(zed_array != nullptr); Void::Testing::expect_eq(zed_array->size(), std::size_t{6}); auto clion_options = options; clion_options.editor = Editor::IdeKind::CLion; clion_options.output_dir = tmp / "vbs-clion"; auto clion_report = Editor::generate_ide_plugin_assets(clion_options); Void::Testing::require(clion_report.has_value()); Void::Testing::expect_eq(clion_report->written_files.size(), std::size_t{4}); auto plugin_xml = Void::FileSystem::read_file(clion_options.output_dir / "src" / "main" / "resources" / "META-INF" / "plugin.xml"); Void::Testing::require(plugin_xml.has_value()); Void::Testing::expect(plugin_xml->find("com.faumaray.vbs") != std::string::npos); Void::Testing::expect(std::filesystem::exists(clion_options.output_dir / "build.gradle.kts")); Void::Testing::expect(std::filesystem::exists(clion_options.output_dir / "src" / "main" / "kotlin" / "com" / "faumaray" / "vbs" / "VbsActions.kt")); } // === Migration tooling: CMakeLists.txt -> build.cpp scaffold === VOID_TEST(FullV1Tests, cmake_lists_import_renders_build_cpp_scaffold) { Void::FileSystem::TempDir tmp{"vbs_migrate_"}; write_file(tmp / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(demo LANGUAGES CXX) set(LIB_SRC src/lib.cpp) add_library(demo_lib STATIC ${LIB_SRC} src/extra.cpp) target_include_directories(demo_lib PUBLIC include PRIVATE src) target_compile_definitions(demo_lib PUBLIC DEMO_API=1 PRIVATE DEMO_INTERNAL) add_executable(demo_app src/main.cpp) target_link_libraries(demo_app PRIVATE demo_lib) install(TARGETS demo_app demo_lib DESTINATION bin) )cmake"); auto imported = Config::import_cmake_lists(tmp / "CMakeLists.txt", tmp.path()); Void::Testing::require(imported.has_value()); Void::Testing::expect_eq(imported->project_name, std::string{"demo"}); Void::Testing::expect_eq(imported->targets.size(), std::size_t{2}); const auto &library = imported->targets.at(0); Void::Testing::expect_eq(library.name, std::string{"demo_lib"}); Void::Testing::expect_eq(library.kind, std::string{"static"}); Void::Testing::expect_eq(library.sources.size(), std::size_t{2}); Void::Testing::expect_eq(library.sources.at(0), std::string{"src/lib.cpp"}); Void::Testing::expect_eq(library.public_includes.size(), std::size_t{1}); Void::Testing::expect_eq(library.private_includes.at(0), std::string{"src"}); Void::Testing::expect_eq(library.public_defines.at(0), std::string{"DEMO_API=1"}); Void::Testing::expect(library.installed); const auto &app = imported->targets.at(1); Void::Testing::expect_eq(app.kind, std::string{"executable"}); Void::Testing::expect_eq(app.private_links.at(0), std::string{"demo_lib"}); const std::string rendered = Config::render_build_cpp(*imported); Void::Testing::expect(rendered.find("static_library(\"demo_lib\")") != std::string::npos); Void::Testing::expect(rendered.find("executable(\"demo_app\")") != std::string::npos); Void::Testing::expect(rendered.find(".link(t_demo_lib") != std::string::npos); Void::Testing::expect(rendered.find(".install(\"bin\")") != std::string::npos); } // === IDE/migration ecosystem: CMakePresets import === VOID_TEST(FullV1Tests, cmake_presets_import_maps_inherits_and_cache) { Void::FileSystem::TempDir tmp{"vbs_presets_"}; const auto presets_file = tmp / "CMakePresets.json"; write_file(presets_file, R"json({ "version": 3, "configurePresets": [ {"name": "base", "hidden": true, "binaryDir": "${sourceDir}/out/base", "cacheVariables": {"CMAKE_BUILD_TYPE": "Debug"}}, {"name": "release-clang", "inherits": ["base"], "cacheVariables": {"CMAKE_BUILD_TYPE": "Release", "CMAKE_CXX_COMPILER": "/usr/bin/clang++"}, "generator": "Ninja"}, {"name": "plain", "generator": "Unix Makefiles"} ] })json"); auto presets = Config::load_cmake_presets(presets_file, tmp.path()); Void::Testing::require(presets.has_value()); Void::Testing::expect_eq(presets->size(), std::size_t{3}); const auto find = [&](std::string_view name) -> const Config::ImportedPreset * { for (const auto &preset : *presets) { if (preset.name == name) { return &preset; } } return nullptr; }; const auto *base = find("base"); Void::Testing::require(base != nullptr); Void::Testing::expect_eq(base->profile, std::string{"debug"}); Void::Testing::expect(base->build_dir.has_value()); if (base->build_dir) { Void::Testing::expect(base->build_dir->ends_with("out/base")); Void::Testing::expect(base->build_dir->starts_with(tmp.path().string())); } const auto *release = find("release-clang"); Void::Testing::require(release != nullptr); Void::Testing::expect_eq(release->profile, std::string{"release"}); Void::Testing::expect_eq(release->compiler, std::string{"clang"}); Void::Testing::expect_eq(release->generator, std::string{"Ninja"}); Void::Testing::expect(release->cache_variables.contains("CMAKE_BUILD_TYPE")); const auto command = Config::suggested_build_command(*release); Void::Testing::expect(command.find("--profile 'release'") != std::string::npos); Void::Testing::expect(command.find("--compiler 'clang'") != std::string::npos); Void::Testing::expect(command.find("--build-dir '") != std::string::npos); const auto *plain = find("plain"); Void::Testing::require(plain != nullptr); Void::Testing::expect_eq(plain->profile, std::string{"debug"}); Void::Testing::expect_eq(plain->compiler, std::string{"gcc"}); Void::Testing::expect(!plain->build_dir.has_value()); } // === Track C (Wine-first): cross-compile to Windows with MinGW-w64 and run tests under Wine === VOID_TEST(FullV1Tests, track_c_windows_target_cross_build_and_wine_test) { 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; } // Requires the MinGW-w64 cross toolchain and Wine; skipped in minimal shells. if (!Platform::resolve_executable("x86_64-w64-mingw32-g++").has_value() || !Platform::resolve_executable("wine").has_value()) { return; } Void::FileSystem::TempDir tmp{"vbs_win_"}; const auto proj = tmp / "win_proj"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.executable("winapp").cxx_standard(Void::Build::CxxStandard::Cxx26).sources({"main.cpp"}); p.test("win_test").cxx_standard(Void::Build::CxxStandard::Cxx26).sources({"test.cpp"}); } )cpp"); write_file(proj / "main.cpp", "#include \nint main() { return 0; }\n"); // Under Wine the Windows filesystem semantics apply: an upper-case open must find the file // created in lower case, proving PE path handling rather than Linux semantics. write_file(proj / "test.cpp", R"cpp(#include int main() { std::FILE *f = std::fopen("case_a.txt", "wb"); if (!f) return 2; std::fclose(f); std::FILE *g = std::fopen("CASE_A.TXT", "rb"); if (!g) { std::printf("case-insensitive open failed\n"); return 1; } std::fclose(g); return 0; } )cpp"); Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = {"test", "--project", proj.string(), "--build-dir", (tmp / "build").string(), "--target-os", "windows", "--target-arch", "x86_64", "--jobs", "4"}; req.timeout = std::chrono::seconds{600}; auto res = Platform::run_supervised(req); Void::Testing::expect_eq( res ? (res->succeeded() ? std::string{} : (res->stdout_data + res->stderr_data)) : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->succeeded()); if (res) { Void::Testing::expect(res->stdout_data.find("PASSED 'win_test'") != std::string::npos); } Void::Testing::expect(std::filesystem::exists(tmp / "build" / "profiles" / "debug" / "out" / "bin" / "winapp.exe")); // Case-insensitive output collisions and reserved device names are rejected for Windows. const auto collision_proj = tmp / "collision_proj"; write_file(collision_proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.executable("Tool").sources({"main.cpp"}); p.executable("tool").sources({"main.cpp"}); } )cpp"); write_file(collision_proj / "main.cpp", "int main() { return 0; }\n"); Platform::ProcessRequest collision_req = req; collision_req.arguments = {"build", "--project", collision_proj.string(), "--build-dir", (tmp / "collision_build").string(), "--target-os", "windows"}; auto collision_res = Platform::run_supervised(collision_req); Void::Testing::expect(collision_res.has_value() && !collision_res->succeeded()); if (collision_res) { Void::Testing::expect(collision_res->stderr_data.find("differ only by case") != std::string::npos); } const auto reserved_proj = tmp / "reserved_proj"; write_file(reserved_proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.executable("CON").sources({"main.cpp"}); } )cpp"); write_file(reserved_proj / "main.cpp", "int main() { return 0; }\n"); Platform::ProcessRequest reserved_req = req; reserved_req.arguments = {"build", "--project", reserved_proj.string(), "--build-dir", (tmp / "reserved_build").string(), "--target-os", "windows"}; auto reserved_res = Platform::run_supervised(reserved_req); Void::Testing::expect(reserved_res.has_value() && !reserved_res->succeeded()); if (reserved_res) { Void::Testing::expect(reserved_res->stderr_data.find("reserved Windows device name") != std::string::npos); } } // === Plan 08: Modern C++ (GCC16 P1689 named modules + partitions, cycle/dup checks, unity, PCH) // === VOID_TEST(FullV1Tests, modern_cpp_modules_scan_collation_cycles_and_unity_exclusion) { Void::FileSystem::TempDir tmp{"vbs_mod_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // 1. Real GCC 16 P1689 scanning + collation + compiling + linking + executing a C++20 named // module! const auto mod_src = tmp / "math_mod.cppm"; const auto main_src = tmp / "use_mod.cpp"; write_file(mod_src, "export module vbs.math;\nexport int triple(int x) { return x * 3; }\n"); write_file(main_src, "import vbs.math;\nint main() { return triple(14) == 42 ? 0 : 1; }\n"); auto u_mod = Modules::scan_translation_unit(*tc, mod_src, tmp / "scan", {}, {}, {}, CxxStandard::Cxx20); auto u_main = Modules::scan_translation_unit(*tc, main_src, tmp / "scan", {}, {}, {}, CxxStandard::Cxx20); Void::Testing::expect(u_mod.has_value() && u_main.has_value()); if (u_mod && u_main) { Void::Testing::expect(u_mod->provides.size() == 1 && u_mod->provides[0] == "vbs.math"); Void::Testing::expect(u_main->required_modules.size() == 1 && u_main->required_modules[0] == "vbs.math"); // Feed in reverse order (importer before provider!) to verify topological collation! auto plan = Modules::collate_modules({*u_main, *u_mod}, tmp / "bmi", tc->identity_hash); Void::Testing::expect(plan.has_value() && plan->ordered_units.size() == 2); if (plan) { Void::Testing::expect_eq(plan->ordered_units[0].source_file, mod_src); Void::Testing::expect_eq(plan->ordered_units[1].source_file, main_src); // Compile provider then importer with generated GCC module-mapper and link! std::vector objs; for (std::size_t i = 0; i < plan->ordered_units.size(); ++i) { const auto &node = plan->ordered_units[i]; const auto obj = tmp / ("m" + std::to_string(i) + ".o"); Toolchain::CompileRequest creq; creq.source_file = node.source_file; creq.output_object = obj; creq.cxx_standard = CxxStandard::Cxx20; creq.compile_options = {"-x", "c++"}; creq.is_module_interface = !node.provides.empty(); creq.module_mapper_file = node.module_mapper_path; auto cmd = Toolchain::lower_compile_command(*tc, creq); Void::Testing::expect(cmd.has_value()); if (cmd) { Platform::ProcessRequest creq_proc; creq_proc.executable = cmd->executable; creq_proc.arguments = cmd->arguments; auto p = Platform::run_supervised(creq_proc); Void::Testing::expect(p.has_value() && p->succeeded()); objs.push_back(obj); } } const auto exe = tmp / "mod_app"; auto lcmd = Toolchain::lower_link_command(*tc, {TargetKind::Executable, exe, std::nullopt, objs, {}, {}, {}, {}, LtoMode::None, {}}); Void::Testing::expect(lcmd.has_value()); if (lcmd) { Platform::ProcessRequest link_proc; link_proc.executable = lcmd->executable; link_proc.arguments = lcmd->arguments; auto lp = Platform::run_supervised(link_proc); Void::Testing::expect(lp.has_value() && lp->succeeded()); Platform::ProcessRequest run_proc; run_proc.executable = exe; auto rp = Platform::run_supervised(run_proc); Void::Testing::expect(rp.has_value() && rp->succeeded()); } } } // 2. Duplicate provider, missing provider, and module import cycles must fail clearly! Modules::ModuleScanUnit dup_a{tmp / "a.cppm", {"dup"}, {}, true}; Modules::ModuleScanUnit dup_b{tmp / "b.cppm", {"dup"}, {}, true}; Void::Testing::expect(!Modules::collate_modules({dup_a, dup_b}, tmp / "bmi", "k").has_value()); Modules::ModuleScanUnit cyc_a{tmp / "ca.cppm", {"A"}, {"B"}, true}; Modules::ModuleScanUnit cyc_b{tmp / "cb.cppm", {"B"}, {"A"}, true}; Void::Testing::expect(!Modules::collate_modules({cyc_a, cyc_b}, tmp / "bmi", "k").has_value()); Modules::ModuleScanUnit miss{tmp / "m.cpp", {}, {"GhostMod"}, false}; Void::Testing::expect(!Modules::collate_modules({miss}, tmp / "bmi", "k").has_value()); // 3. Unity batching MUST exclude .cppm module units and per-file-override sources! auto unity = Modules::generate_unity_batches( "lib", {tmp / "a.cpp", tmp / "b.cpp", tmp / "mod.cppm", tmp / "special.cpp"}, {tmp / "special.cpp"}, 2, tmp / "unity"); Void::Testing::expect(unity.has_value()); if (unity) { Void::Testing::expect_eq(unity->generated_unity_files.size(), std::size_t{1}); Void::Testing::expect_eq(unity->standalone_files.size(), std::size_t{2}); } } // === Plan 04/08/19 Matrix: Clang 23 target toolchain probe, build, and P1689 module scan === VOID_TEST(FullV1Tests, clang23_target_toolchain_and_p1689_module_scan) { if (!Platform::resolve_executable("clang++").has_value()) { return; // Only skip if Clang is genuinely absent from PATH. } Void::FileSystem::TempDir tmp{"vbs_clang23_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Clang, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; Void::Testing::expect(tc->family == CompilerFamily::Clang); Void::Testing::expect(tc->supports_cxx20); // Compile and execute a real C++20 binary via Clang 23 lowering. const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; write_file(proj / "src" / "main.cpp", "#ifdef __clang__\nint main() { return 0; }\n#else\n#error not clang\n#endif\n"); Graph::ProjectDescription desc; desc.profile = ctx; TargetRecord app; app.name = "clang_app"; app.kind = TargetKind::Executable; app.cxx_standard = CxxStandard::Cxx20; app.sources.push_back({SourceKind::File, "src/main.cpp"}); desc.targets.push_back(app); Snapshot::SnapshotOptions sopts; sopts.project_root = proj; sopts.snapshot_store_dir = bdir / ".vbs" / "snapshots"; auto snap = Snapshot::capture_snapshot(sopts, {}, {proj / "src"}); Void::Testing::expect(snap.has_value()); if (!snap) return; auto graph = Graph::lower_project_graph(desc, *tc, {proj, bdir, &(*snap), {}, 32768}); Void::Testing::expect(graph.has_value()); auto state = State::StateStore::open(bdir / ".vbs"); Void::Testing::expect(state.has_value()); if (!graph || !state) return; auto exec = Execution::execute_graph(*graph, *state); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest clang_run_req; clang_run_req.executable = bdir / "profiles" / "debug" / "out" / "bin" / "clang_app"; auto run_res = Platform::run_supervised(clang_run_req); Void::Testing::expect(run_res.has_value() && run_res->succeeded()); // Also verify full Clang 23 graph-lowered module partition + primary interface + consumer // build & run (two-step --precompile .pcm -> .o + -fmodule-file=) when clang-scan-deps exists! if (tc->supports_p1689_scan) { const auto mproj = tmp / "clang_mod_proj"; const auto mbdir = tmp / "clang_mod_build"; write_file( mproj / "src" / "part.cppm", "export module vbs.clangcalc:part;\nexport int part_mul(int x) { return x * 6; }\n"); write_file(mproj / "src" / "calc.cppm", "export module vbs.clangcalc;\nexport import :part;\n" "export int calc_val(int x) { return part_mul(x) + 6; }\n"); write_file(mproj / "src" / "main.cpp", "import vbs.clangcalc;\nint main() { return calc_val(6) == 42 ? 0 : 1; }\n"); Graph::ProjectDescription mdesc; mdesc.profile = ctx; TargetRecord mapp; mapp.name = "clang_mod_app"; mapp.kind = TargetKind::Executable; mapp.cxx_standard = CxxStandard::Cxx20; // Intentionally reverse order (importer before primary before partition). mapp.sources.push_back({SourceKind::File, "src/main.cpp"}); mapp.sources.push_back({SourceKind::ModuleInterface, "src/calc.cppm"}); mapp.sources.push_back({SourceKind::ModulePartition, "src/part.cppm"}); mdesc.targets.push_back(mapp); auto mgraph = Graph::lower_project_graph(mdesc, *tc, {mproj, mbdir, nullptr, {}, 32768}); Void::Testing::expect(mgraph.has_value()); auto mstate = State::StateStore::open(mbdir / ".vbs"); Void::Testing::expect(mstate.has_value()); if (mgraph && mstate) { std::size_t bmi_actions = 0; for (const auto &a : mgraph->actions) { if (a.kind == Graph::ActionKind::ModuleBmi) { ++bmi_actions; } } Void::Testing::expect_eq(bmi_actions, std::size_t{2}); auto mexec = Execution::execute_graph(*mgraph, *mstate); Void::Testing::expect(mexec.has_value() && mexec->succeeded); Platform::ProcessRequest mrun; mrun.executable = mbdir / "profiles" / "debug" / "out" / "bin" / "clang_mod_app"; auto mres = Platform::run_supervised(mrun); Void::Testing::expect(mres.has_value() && mres->succeeded()); } } } // === Plan 08 Full Graph Integration: Modules+Partitions, Unity+PerFile, HeaderUnit, Sanitizers === VOID_TEST(FullV1Tests, graph_lowering_modules_partitions_unity_header_units_and_sanitizers) { Void::FileSystem::TempDir tmp{"vbs_plan08_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // 1. Incompatible sanitizer combination (ASan + TSan) MUST be rejected during lowering! { const auto sproj = tmp / "san_proj"; write_file(sproj / "src" / "main.cpp", "int main() { return 0; }\n"); Graph::ProjectDescription sdesc; sdesc.profile = ctx; TargetRecord bad_san; bad_san.name = "bad_san"; bad_san.kind = TargetKind::Executable; bad_san.sources.push_back({SourceKind::File, "src/main.cpp"}); bad_san.sanitizers = {Sanitizer::Address, Sanitizer::Thread}; sdesc.targets.push_back(bad_san); auto bad_graph = Graph::lower_project_graph(sdesc, *tc, {sproj, tmp / "san_build", nullptr, {}, 32768}); Void::Testing::expect(!bad_graph.has_value()); if (!bad_graph) { Void::Testing::expect(bad_graph.error().message().find("incompatible sanitizers") != std::string::npos); } } // 2. Full GCC 16 graph-lowered module partition + primary interface + consumer (reverse order)! { const auto mproj = tmp / "mod_proj"; const auto mbdir = tmp / "mod_build"; write_file(mproj / "src" / "calc_impl.cppm", "export module vbs.calc:impl;\nexport int add_two(int x) { return x + 2; }\n"); write_file(mproj / "src" / "calc.cppm", "export module vbs.calc;\nexport import :impl;\n" "export int compute(int x) { return add_two(x * 4); }\n"); write_file(mproj / "src" / "main.cpp", "import vbs.calc;\nint main() { return compute(10) == 42 ? 0 : 1; }\n"); Graph::ProjectDescription mdesc; mdesc.profile = ctx; TargetRecord app; app.name = "mod_part_app"; app.kind = TargetKind::Executable; app.cxx_standard = CxxStandard::Cxx20; app.sources.push_back({SourceKind::File, "src/main.cpp"}); app.sources.push_back({SourceKind::ModuleInterface, "src/calc.cppm"}); app.sources.push_back({SourceKind::ModulePartition, "src/calc_impl.cppm"}); mdesc.targets.push_back(app); auto mgraph = Graph::lower_project_graph(mdesc, *tc, {mproj, mbdir, nullptr, {}, 32768}); Void::Testing::expect(mgraph.has_value()); auto mstate = State::StateStore::open(mbdir / ".vbs"); Void::Testing::expect(mstate.has_value()); if (mgraph && mstate) { auto exec = Execution::execute_graph(*mgraph, *mstate); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest run; run.executable = mbdir / "profiles" / "debug" / "out" / "bin" / "mod_part_app"; auto res = Platform::run_supervised(run); Void::Testing::expect(res.has_value() && res->succeeded()); } } // 3. Unity batching through Graph lowering + per-file-option exclusion! { const auto uproj = tmp / "unity_proj"; const auto ubdir = tmp / "unity_build"; write_file(uproj / "src" / "u1.cpp", "int u1_val() { return 10; }\n"); write_file(uproj / "src" / "u2.cpp", "int u2_val() { return 20; }\n"); write_file(uproj / "src" / "special.cpp", "int u3_val() { return SPECIAL_VAL; }\n"); write_file(uproj / "src" / "main.cpp", "int u1_val(); int u2_val(); int u3_val();\n" "int main() { return (u1_val() + u2_val() + u3_val()) == 42 ? 0 : 1; }\n"); Graph::ProjectDescription udesc; udesc.profile = ctx; TargetRecord uapp; uapp.name = "unity_app"; uapp.kind = TargetKind::Executable; uapp.unity_enabled = true; uapp.unity_batch_size = 2; uapp.sources.push_back({SourceKind::File, "src/u1.cpp"}); uapp.sources.push_back({SourceKind::File, "src/u2.cpp"}); uapp.sources.push_back({SourceKind::File, "src/special.cpp"}); uapp.sources.push_back({SourceKind::File, "src/main.cpp"}); uapp.per_file_options.push_back({"src/special.cpp", "-DSPECIAL_VAL=12"}); udesc.targets.push_back(uapp); auto ugraph = Graph::lower_project_graph(udesc, *tc, {uproj, ubdir, nullptr, {}, 32768}); Void::Testing::expect(ugraph.has_value()); auto ustate = State::StateStore::open(ubdir / ".vbs"); Void::Testing::expect(ustate.has_value()); if (ugraph && ustate) { std::size_t compile_count = 0; for (const auto &a : ugraph->actions) { if (a.kind == Graph::ActionKind::Compile) { ++compile_count; } } // 3 batchable files (batch_size=2 -> 2 unity files) + 1 excluded special.cpp = 3! Void::Testing::expect_eq(compile_count, std::size_t{3}); auto exec = Execution::execute_graph(*ugraph, *ustate); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest run; run.executable = ubdir / "profiles" / "debug" / "out" / "bin" / "unity_app"; auto res = Platform::run_supervised(run); Void::Testing::expect(res.has_value() && res->succeeded()); } } // 4. Explicit HeaderUnit lowering + build + import execution! { const auto hproj = tmp / "hu_proj"; const auto hbdir = tmp / "hu_build"; write_file(hproj / "include" / "hu_math.hpp", "#pragma once\ninline int hu_magic() { return 77; }\n"); write_file(hproj / "src" / "main.cpp", "import \"hu_math.hpp\";\nint main() { return hu_magic() == 77 ? 0 : 1; }\n"); Graph::ProjectDescription hdesc; hdesc.profile = ctx; TargetRecord happ; happ.name = "hu_app"; happ.kind = TargetKind::Executable; happ.cxx_standard = CxxStandard::Cxx20; happ.include_directories.push_back({"include", Visibility::Private, false}); happ.sources.push_back({SourceKind::HeaderUnit, "include/hu_math.hpp"}); happ.sources.push_back({SourceKind::File, "src/main.cpp"}); hdesc.targets.push_back(happ); auto hgraph = Graph::lower_project_graph(hdesc, *tc, {hproj, hbdir, nullptr, {}, 32768}); Void::Testing::expect(hgraph.has_value()); auto hstate = State::StateStore::open(hbdir / ".vbs"); Void::Testing::expect(hstate.has_value()); if (hgraph && hstate) { std::size_t hu_actions = 0; for (const auto &a : hgraph->actions) { if (a.kind == Graph::ActionKind::HeaderUnit) { ++hu_actions; } } Void::Testing::expect_eq(hu_actions, std::size_t{1}); auto exec = Execution::execute_graph(*hgraph, *hstate); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest run; run.executable = hbdir / "profiles" / "debug" / "out" / "bin" / "hu_app"; auto res = Platform::run_supervised(run); Void::Testing::expect(res.has_value() && res->succeeded()); } } } // === Plan 20 Slice 1: Bounded native CMake graph translation, equivalence, mutations & fallback // === VOID_TEST(FullV1Tests, plan20_bounded_cmake_translation_equivalence_mutations_and_fallback) { Void::FileSystem::TempDir tmp{"vbs_plan20_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // 1. Supported bounded CMake project (static library + executable with public/private includes, // defines, and transitive link): configure ONLY, translate natively, execute via VBS (zero // `cmake --build`), and compare output against official `cmake --build`! const auto cm_src = tmp / "supported_cmake"; write_file(cm_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(p20_math LANGUAGES CXX) add_library(p20_core STATIC src/core.cpp) target_include_directories(p20_core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_definitions(p20_core PUBLIC P20_BONUS=7) add_executable(p20_cli src/main.cpp) target_link_libraries(p20_cli PRIVATE p20_core) )cmake"); write_file(cm_src / "include" / "p20_core.hpp", "#pragma once\ninline constexpr int kP20Base = 35;\nint p20_compute();\n"); write_file(cm_src / "src" / "core.cpp", "#include \"p20_core.hpp\"\nint p20_compute() { return kP20Base + P20_BONUS; }\n"); write_file(cm_src / "src" / "main.cpp", "#include \"p20_core.hpp\"\n#include \n" "int main() { std::cout << p20_compute() << '\\n'; return 0; }\n"); DependencyRecord dep; dep.name = "p20_math"; dep.source_kind = DependencySourceKind::Path; dep.location = cm_src.string(); dep.builder = "cmake"; auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) return; auto state = State::StateStore::open(tmp / "native_state"); Void::Testing::expect(state.has_value()); if (!state) return; Provider::ProviderRequest preq{ dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto native_res = Provider::resolve_cmake_with_translation( preq, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect(native_res.has_value()); if (!native_res) return; Void::Testing::expect(native_res->executed_natively); Void::Testing::expect(native_res->audit.is_supported()); Void::Testing::expect(native_res->exported.targets.contains("p20_math::p20_core")); // Run the natively translated executable (built with ZERO `cmake --build`!) and verify stdout! const auto input_hash = Provider::compute_provider_input_hash(preq); const auto slot_dir = tmp / "prov" / ("translate_p20_math_" + input_hash.substr(0, 16)); const auto native_exe = slot_dir / "native-build" / "profiles" / "debug" / "out" / "bin" / "p20_cli"; Void::Testing::expect(std::filesystem::exists(native_exe)); Platform::ProcessRequest run_native; run_native.executable = native_exe; auto out_native = Platform::run_supervised(run_native); Void::Testing::expect(out_native.has_value() && out_native->succeeded()); if (out_native) { Void::Testing::expect_eq(out_native->stdout_data, std::string{"42\n"}); } // Compare against official foreign CMake build output to prove equivalence! auto foreign_res = Provider::resolve_foreign_provider(preq); Void::Testing::expect(foreign_res.has_value() && foreign_res->targets.contains("p20_math::p20_core")); // 2. Adversarial timestamp-preserved header mutation: restore old mtime on `p20_core.hpp`, // re-execute the translated native graph, and verify VBS depfile+SHA-256 rebuilds `p20_cli` // with the updated constant (99 + 7 = 106)! const auto hdr = cm_src / "include" / "p20_core.hpp"; auto old_meta = Platform::stat_lstat(hdr); Void::Testing::expect(old_meta.has_value()); write_file(hdr, "#pragma once\ninline constexpr int kP20Base = 99;\nint p20_compute();\n"); if (old_meta) { (void)Platform::set_canonical_mtime(hdr, old_meta->mtime_sec); } auto translated2 = Provider::translate_cmake_to_native_graph(preq, slot_dir / "cmake-configure", slot_dir / "native-build"); Void::Testing::expect(translated2.has_value()); if (translated2) { auto exec2 = Execution::execute_graph(translated2->graph, *state); Void::Testing::expect(exec2.has_value() && exec2->succeeded && exec2->executed_count > 0); auto out_mutated = Platform::run_supervised(run_native); Void::Testing::expect(out_mutated.has_value() && out_mutated->succeeded()); if (out_mutated) { Void::Testing::expect_eq(out_mutated->stdout_data, std::string{"106\n"}); } } // 3. Unsupported CMake construct (`USES_TERMINAL` console-pool custom target): // audit MUST detect and report explicitly (never silently drop!), `RequireNative` MUST fail, // and `FallbackToForeignBuild` MUST cleanly delegate to foreign CMake and build the artifact! const auto unsup_src = tmp / "unsupported_cmake"; write_file(unsup_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(p20_gen LANGUAGES CXX) add_custom_target(run_console COMMAND ${CMAKE_COMMAND} -E echo p20_console USES_TERMINAL) add_library(p20_genlib STATIC src/genlib.cpp) add_dependencies(p20_genlib run_console) )cmake"); write_file(unsup_src / "src" / "genlib.cpp", "int p20_gen_fn() { return 55; }\n"); DependencyRecord udep; udep.name = "p20_gen"; udep.source_kind = DependencySourceKind::Path; udep.location = unsup_src.string(); udep.builder = "cmake"; auto umat = Package::materialize_dependency_source(udep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(umat.has_value()); if (!umat) return; Provider::ProviderRequest ureq{ udep, *umat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; // RequireNative MUST fail with explicit unsupported-construct diagnostics! auto req_native = Provider::resolve_cmake_with_translation( ureq, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect(!req_native.has_value()); if (!req_native) { Void::Testing::expect(req_native.error().message().find("unsupported") != std::string::npos); } // FallbackToForeignBuild MUST audit unsupported, log, and cleanly build via foreign CMake! auto fb_res = Provider::resolve_cmake_with_translation( ureq, *state, Provider::TranslationPolicy::FallbackToForeignBuild); Void::Testing::expect_eq(fb_res ? std::string{} : fb_res.error().message(), std::string{}); Void::Testing::expect(fb_res.has_value()); if (fb_res) { Void::Testing::expect(!fb_res->executed_natively); Void::Testing::expect(!fb_res->audit.is_supported()); Void::Testing::expect(!fb_res->audit.unsupported.empty()); Void::Testing::expect(fb_res->exported.targets.contains("p20_gen::p20_genlib")); } } // === Plan 20 Slice 2A: Bounded native Meson graph translation + unsupported custom_target fallback // === VOID_TEST(FullV1Tests, plan20_bounded_meson_translation_equivalence_and_fallback) { if (!Platform::resolve_executable("meson").has_value()) { return; } Void::FileSystem::TempDir tmp{"vbs_plan20_meson_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; auto state = State::StateStore::open(tmp / "state"); Void::Testing::expect(state.has_value()); if (!state) return; // 1. Supported C++ Meson project (static library + executable): configure ONLY (`meson setup`, // zero `meson compile`!), audit, translate natively, execute via VBS, verify stdout + header // mutation! const auto m_src = tmp / "meson_supported"; write_file(m_src / "meson.build", R"meson( project('p20m', 'cpp', default_options: ['cpp_std=c++20']) inc = include_directories('include') lib = static_library('mcore', 'src/core.cpp', include_directories: inc, cpp_args: ['-DM_DELTA=5']) executable('mapp', 'src/main.cpp', include_directories: inc, link_with: lib) )meson"); write_file(m_src / "include" / "mcore.hpp", "#pragma once\ninline constexpr int kMBase = 37;\nint m_answer();\n"); write_file(m_src / "src" / "core.cpp", "#include \"mcore.hpp\"\nint m_answer() { return kMBase + M_DELTA; }\n"); write_file(m_src / "src" / "main.cpp", "#include \"mcore.hpp\"\n#include \n" "int main() { std::cout << m_answer() << '\\n'; return 0; }\n"); DependencyRecord mdep; mdep.name = "p20m"; mdep.source_kind = DependencySourceKind::Path; mdep.location = m_src.string(); mdep.builder = "meson"; auto mat = Package::materialize_dependency_source(mdep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) return; Provider::ProviderRequest req{ mdep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto native_res = Provider::resolve_foreign_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(native_res ? std::string{} : native_res.error().message(), std::string{}); Void::Testing::expect(native_res.has_value()); if (!native_res) return; Void::Testing::expect(native_res->executed_natively); Void::Testing::expect(native_res->audit.is_supported()); Void::Testing::expect(native_res->exported.targets.contains("p20m::mcore")); const auto hash = Provider::compute_provider_input_hash(req); const auto slot_dir = tmp / "prov" / ("translate_meson_p20m_" + hash.substr(0, 16)); const auto native_exe = slot_dir / "native-build" / "profiles" / "debug" / "out" / "bin" / "mapp"; Void::Testing::expect(std::filesystem::exists(native_exe)); Platform::ProcessRequest run_req; run_req.executable = native_exe; auto run_out = Platform::run_supervised(run_req); Void::Testing::expect(run_out.has_value() && run_out->succeeded()); if (run_out) { Void::Testing::expect_eq(run_out->stdout_data, std::string{"42\n"}); } // 2. Unsupported Meson `console: true` custom_target: RequireNative MUST fail cleanly; // FallbackToForeignBuild MUST build via foreign Meson provider! const auto u_src = tmp / "meson_custom"; write_file(u_src / "meson.build", R"meson( project('p20m_custom', 'cpp') gen = custom_target('gen_hdr', output: 'gen_num.hpp', console: true, command: ['/bin/sh', '-c', 'printf "#define M_GEN_NUM 88\n" > "$1"', '--', '@OUTPUT@']) static_library('mgenlib', ['src/gen.cpp', gen]) )meson"); write_file(u_src / "src" / "gen.cpp", "#include \"gen_num.hpp\"\nint m_gen_fn() { return M_GEN_NUM; }\n"); DependencyRecord udep; udep.name = "p20m_custom"; udep.source_kind = DependencySourceKind::Path; udep.location = u_src.string(); udep.builder = "meson"; auto umat = Package::materialize_dependency_source(udep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(umat.has_value()); if (!umat) return; Provider::ProviderRequest ureq{ udep, *umat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto strict = Provider::resolve_foreign_with_translation( ureq, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect(!strict.has_value()); auto fallback = Provider::resolve_foreign_with_translation( ureq, *state, Provider::TranslationPolicy::FallbackToForeignBuild); Void::Testing::expect_eq(fallback ? std::string{} : fallback.error().message(), std::string{}); Void::Testing::expect(fallback.has_value()); if (fallback) { Void::Testing::expect(!fallback->executed_natively); Void::Testing::expect(!fallback->audit.is_supported()); Void::Testing::expect(fallback->exported.targets.contains("p20m_custom::mgenlib")); } } // === Wave 8 DX CLI: vbs init -> vbs test -> vbs graph -> vbs doctor -> vbs clean === VOID_TEST(FullV1Tests, cli_init_graph_clean_doctor_end_to_end) { const auto vbs_bin = locate_vbs_binary(); if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) { return; } Void::FileSystem::TempDir tmp{"vbs_dx_"}; const auto proj = tmp / "hello_vbs"; const auto bdir = tmp / "hello_build"; auto run_vbs = [&](std::vector args) { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = std::move(args); req.timeout = std::chrono::seconds{120}; return Platform::run_supervised(req); }; // 1. `vbs init` scaffolds a ready-to-build-and-test C++26 project. auto r_init = run_vbs({"init", "--dir", proj.string(), "--name", "hello_vbs"}); Void::Testing::expect(r_init.has_value() && r_init->succeeded()); Void::Testing::expect(std::filesystem::exists(proj / "build.cpp")); Void::Testing::expect(std::filesystem::exists(proj / "src" / "main.cpp")); Void::Testing::expect(std::filesystem::exists(proj / "tests" / "test_main.cpp")); // 2. `vbs test` builds & passes the freshly scaffolded project out of the box! auto r_test = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string()}); Void::Testing::expect(r_test.has_value() && r_test->succeeded()); if (r_test) { Void::Testing::expect(r_test->stdout_data.find("PASSED 'hello_vbs_tests'") != std::string::npos); } // 3. `vbs graph --format dot` & `--format json` emit valid target dependency graphs. auto r_dot = run_vbs( {"graph", "--project", proj.string(), "--build-dir", bdir.string(), "--format", "dot"}); Void::Testing::expect(r_dot.has_value() && r_dot->succeeded()); if (r_dot) { Void::Testing::expect(r_dot->stdout_data.find("digraph vbs_targets") != std::string::npos); Void::Testing::expect(r_dot->stdout_data.find("\"hello_vbs\" -> \"hello_vbs_lib\"") != std::string::npos); } auto r_json = run_vbs( {"graph", "--project", proj.string(), "--build-dir", bdir.string(), "--format", "json"}); Void::Testing::expect(r_json.has_value() && r_json->succeeded()); if (r_json) { auto parsed = Void::Json::Strict::parse(r_json->stdout_data); Void::Testing::expect(parsed.has_value()); } // 4. `vbs doctor` succeeds and reports GCC + Void::Crypto + Void::Archive. auto r_doc = run_vbs({"doctor"}); Void::Testing::expect(r_doc.has_value() && r_doc->succeeded()); if (r_doc) { Void::Testing::expect(r_doc->stdout_data.find("Void::Crypto") != std::string::npos); Void::Testing::expect(r_doc->stdout_data.find("GCC probe:") != std::string::npos); } // 5. `vbs clean` removes profile outputs while preserving .vbs/state; `--all` removes all. auto r_clean = run_vbs({"clean", "--build-dir", bdir.string()}); Void::Testing::expect(r_clean.has_value() && r_clean->succeeded()); Void::Testing::expect(!std::filesystem::exists(bdir / "profiles")); Void::Testing::expect(std::filesystem::exists(bdir / ".vbs")); auto r_clean_all = run_vbs({"clean", "--build-dir", bdir.string(), "--all"}); Void::Testing::expect(r_clean_all.has_value() && r_clean_all->succeeded()); Void::Testing::expect(!std::filesystem::exists(bdir)); } // === Test-runner parity: labels filter and exclusive resource locks === VOID_TEST(FullV1Tests, test_labels_filter_and_resource_locks_serialize) { 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_labels_"}; const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.test("lab_a") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/a.cpp"}) .label("fast") .resource("shared"); p.test("lab_b") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/b.cpp"}) .label("slow") .resource("shared"); p.test("lab_c") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/c.cpp"}) .label("fast"); } )cpp"); for (const char name : {'a', 'b', 'c'}) { write_file(proj / "tests" / (std::string{name} + ".cpp"), "#include \n" "#include \n" "#include \n" "int main() {\n" " { std::ofstream out{\"order.log\", std::ios::app}; out << \"" + std::string{name} + "-start\\n\"; }\n" " std::this_thread::sleep_for(std::chrono::milliseconds{150});\n" " { std::ofstream out{\"order.log\", std::ios::app}; out << \"" + std::string{name} + "-end\\n\"; }\n" " return 0;\n" "}\n"); } auto run_vbs = [&](std::vector args) { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = std::move(args); req.timeout = std::chrono::seconds{300}; return Platform::run_supervised(req); }; // Label filtering: only 'fast' tests run. auto filtered = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(), "--label", "fast", "--jobs", "4"}); Void::Testing::expect(filtered.has_value() && filtered->succeeded()); if (filtered) { Void::Testing::expect(filtered->stdout_data.find("PASSED 'lab_a'") != std::string::npos); Void::Testing::expect(filtered->stdout_data.find("PASSED 'lab_c'") != std::string::npos); Void::Testing::expect(filtered->stdout_data.find("lab_b") == std::string::npos); } // Resource serialization: lab_a and lab_b share 'shared', so their start/end intervals // must never overlap even with 4 parallel jobs. std::filesystem::remove(proj / "order.log"); auto all = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(), "--jobs", "4"}); Void::Testing::expect(all.has_value() && all->succeeded()); auto order_text = Void::FileSystem::read_file(proj / "order.log"); Void::Testing::require(order_text.has_value()); std::set running; bool overlapped = false; std::size_t starts = 0; for (std::size_t pos = 0; pos < order_text->size();) { const auto eol = order_text->find('\n', pos); const std::string line = order_text->substr(pos, eol - pos); pos = eol == std::string::npos ? order_text->size() : eol + 1; if (line.size() < 5) { continue; } const std::string who = line.substr(0, 1); const bool is_start = line.ends_with("-start"); if (is_start) { ++starts; if (who == "a" || who == "b") { if (running.contains("a") || running.contains("b")) { overlapped = true; } running.insert(who); } } else if (who == "a" || who == "b") { running.erase(who); } } Void::Testing::expect_eq(starts, std::size_t{3}); Void::Testing::expect(!overlapped); } // === Test-runner parity: CTest-style fixtures (setup/required/cleanup) === VOID_TEST(FullV1Tests, test_fixtures_setup_required_cleanup_ordering) { 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_fixtures_"}; const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.test("db_setup") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/setup.cpp"}) .fixture_setup("db"); p.test("db_use_a") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/use_a.cpp"}) .fixture_required("db") .label("uses"); p.test("db_use_b") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/use_b.cpp"}) .fixture_required("db") .label("uses"); p.test("db_cleanup") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/cleanup.cpp"}) .fixture_cleanup("db"); p.test("bad_setup") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/bad_setup.cpp"}) .fixture_setup("bad"); p.test("bad_use") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"tests/bad_use.cpp"}) .fixture_required("bad") .label("baduse"); } )cpp"); const std::pair sources[] = {{"setup.cpp", "setup"}, {"use_a.cpp", "use_a"}, {"use_b.cpp", "use_b"}, {"cleanup.cpp", "cleanup"}, {"bad_use.cpp", "bad_use"}}; for (const auto &[file, name] : sources) { write_file(proj / "tests" / file, "#include \n" "int main() {\n" " { std::ofstream out{\"order.log\", std::ios::app}; out << \"" + std::string{name} + "\\n\"; }\n" " return 0;\n" "}\n"); } write_file(proj / "tests" / "bad_setup.cpp", "#include \n" "int main() {\n" " { std::ofstream out{\"order.log\", std::ios::app}; out << \"bad_setup\\n\"; }\n" " return 1;\n" "}\n"); auto run_vbs = [&](std::vector args) { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = std::move(args); req.timeout = std::chrono::seconds{300}; return Platform::run_supervised(req); }; // Only labeled users are selected; setup/cleanup are pulled in automatically and ordered. auto fixtures = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(), "--label", "uses", "--jobs", "4"}); Void::Testing::expect(fixtures.has_value() && fixtures->succeeded()); if (fixtures) { Void::Testing::expect(fixtures->stdout_data.find("PASSED 'db_setup'") != std::string::npos); Void::Testing::expect(fixtures->stdout_data.find("PASSED 'db_use_a'") != std::string::npos); Void::Testing::expect(fixtures->stdout_data.find("PASSED 'db_use_b'") != std::string::npos); Void::Testing::expect(fixtures->stdout_data.find("PASSED 'db_cleanup'") != std::string::npos); } auto order_text = Void::FileSystem::read_file(proj / "order.log"); Void::Testing::require(order_text.has_value()); std::vector order; for (std::size_t pos = 0; pos < order_text->size();) { const auto eol = order_text->find('\n', pos); order.push_back(order_text->substr(pos, eol - pos)); pos = eol == std::string::npos ? order_text->size() : eol + 1; } Void::Testing::require(order.size() == 4); Void::Testing::expect_eq(order.front(), std::string{"setup"}); Void::Testing::expect_eq(order.back(), std::string{"cleanup"}); // A failing fixture setup skips its dependents (and the run fails). std::filesystem::remove(proj / "order.log"); auto broken = run_vbs({"test", "--project", proj.string(), "--build-dir", bdir.string(), "--label", "baduse", "--jobs", "4"}); Void::Testing::expect(broken.has_value()); if (broken) { Void::Testing::expect(!broken->succeeded()); Void::Testing::expect(broken->stdout_data.find("PASSED 'bad_use'") == std::string::npos); Void::Testing::expect(broken->stderr_data.find("SKIPPED 'bad_use'") != std::string::npos); } } // === pkg-config dependency discovery === VOID_TEST(FullV1Tests, pkgconfig_dependency_resolves_flags_requires_and_versions) { 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_pkgcfg_"}; const auto prefix = tmp / "prefix"; const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; const auto pc_dir = prefix / "lib" / "pkgconfig"; std::filesystem::create_directories(pc_dir); std::filesystem::create_directories(prefix / "include"); std::filesystem::create_directories(prefix / "childinclude"); std::filesystem::create_directories(proj / "src"); write_file(prefix / "include" / "mylib.hpp", "#pragma once\nint mylib_answer_impl();\n" "inline int mylib_answer() { return mylib_answer_impl(); }\n"); write_file(prefix / "childinclude" / "child_flag.hpp", "#pragma once\n#define CHILD_FLAG_PRESENT 1\n"); write_file(tmp / "lib.cpp", "int mylib_answer_impl() { return 42; }\n"); write_file(pc_dir / "child.pc", "Name: child\nDescription: child module\nVersion: 0.7.1\n" "Cflags: -I" + (prefix / "childinclude").string() + "\n"); write_file(pc_dir / "mylib.pc", "prefix=" + prefix.string() + "\nincludedir=${prefix}/include\nlibdir=${prefix}/lib\n\n" "Name: mylib\nDescription: test library\nVersion: 1.2.3\n" "Requires: child >= 0.5\n" "Cflags: -I${includedir} -DMYLIB_ENABLED=1\n" "Libs: -L${libdir} -lmylib\n"); // Build the library the .pc file advertises (needs a real compiler and archiver). const auto run_tool = [&](const std::string &exe, std::vector args) { Platform::ProcessRequest req; req.executable = exe; req.arguments = std::move(args); req.timeout = std::chrono::seconds{120}; return Platform::run_supervised(req); }; const auto object = tmp / "lib.o"; auto compiled_lib = run_tool("g++", {"-c", (tmp / "lib.cpp").string(), "-o", object.string()}); if (!compiled_lib || !compiled_lib->succeeded()) { return; // No host compiler in PATH: nothing to link against. } auto archived = run_tool("ar", {"rcs", (prefix / "lib" / "libmylib.a").string(), object.string()}); if (!archived || !archived->succeeded()) { return; } write_file(proj / "build.cpp", "#include \n" "void build(Void::Build::Project &p) {\n" " auto dep = p.dependency(\"mylib\").pkgconfig(\"mylib >= 1.0\");\n" " p.executable(\"app\")\n" " .cxx_standard(Void::Build::CxxStandard::Cxx26)\n" " .sources({\"src/main.cpp\"})\n" " .link(dep.target(\"mylib\"));\n" "}\n"); write_file(proj / "src" / "main.cpp", "#include \n" "#include \n" "#ifndef MYLIB_ENABLED\n" "#error MYLIB_ENABLED missing\n" "#endif\n" "#ifndef CHILD_FLAG_PRESENT\n" "#error Requires chain not merged\n" "#endif\n" "int main() { return mylib_answer() == 42 ? 0 : 1; }\n"); const auto run_vbs = [&]() { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = {"build", "--project", proj.string(), "--build-dir", bdir.string()}; req.environment.set_vars["PKG_CONFIG_PATH"] = pc_dir.string(); req.timeout = std::chrono::seconds{300}; return Platform::run_supervised(req); }; auto built = run_vbs(); Void::Testing::expect(built.has_value() && built->succeeded()); if (built) { Void::Testing::expect(built->stderr_data.find("Resolved pkg-config 'mylib >= 1.0'") != std::string::npos); } const auto app = bdir / "profiles" / "debug" / "out" / "bin" / "app"; if (std::filesystem::exists(app)) { auto ran = run_tool(app.string(), {}); Void::Testing::expect(ran.has_value() && ran->succeeded()); } // A version the root module cannot satisfy is a clear configuration error. write_file(proj / "build.cpp", "#include \n" "void build(Void::Build::Project &p) {\n" " auto dep = p.dependency(\"mylib\").pkgconfig(\"mylib >= 2.0\");\n" " (void)dep;\n" "}\n"); auto too_new = run_vbs(); Void::Testing::expect(too_new.has_value() && !too_new->succeeded()); if (too_new) { Void::Testing::expect( too_new->stderr_data.find("is required, but version 1.2.3 is installed") != std::string::npos); } // A version the Requires chain cannot satisfy is reported too. write_file(proj / "build.cpp", "#include \n" "void build(Void::Build::Project &p) {\n" " auto dep = p.dependency(\"mylib\").pkgconfig(\"mylib >= 1.0\");\n" " (void)dep;\n" "}\n"); write_file(pc_dir / "mylib.pc", "prefix=" + prefix.string() + "\nincludedir=${prefix}/include\nlibdir=${prefix}/lib\n\n" "Name: mylib\nDescription: test library\nVersion: 1.2.3\n" "Requires: child >= 0.8\n" "Cflags: -I${includedir}\n" "Libs: -L${libdir} -lmylib\n"); auto child_too_new = run_vbs(); Void::Testing::expect(child_too_new.has_value() && !child_too_new->succeeded()); if (child_too_new) { Void::Testing::expect( child_too_new->stderr_data.find("pkg-config module 'child' >= 0.8 is required") != std::string::npos); } } // === Assembly sources (.S through the C preprocessor) === VOID_TEST(FullV1Tests, asm_preprocessed_source_compiles_and_links) { if (Toolchain::host_architecture_name() != "x86_64") { return; // The fixture is x86-64 assembly. } 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_asm_"}; const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.executable("asm_app") .cxx_standard(Void::Build::CxxStandard::Cxx26) .sources({"src/main.cpp", "src/answer.S", "src/twice.s"}); } )cpp"); write_file(proj / "src" / "main.cpp", R"cpp(#include extern "C" int asm_answer(); extern "C" int asm_twice(int); int main() { if (asm_answer() != 42 || asm_twice(21) != 42) { std::fprintf(stderr, "asm mismatch: %d %d\n", asm_answer(), asm_twice(21)); return 1; } return 0; } )cpp"); // `.S` is preprocessed: the answer comes from a #define. write_file(proj / "src" / "answer.S", R"asm(#define ASM_ANSWER 42 .text .globl asm_answer .type asm_answer, @function asm_answer: mov $ASM_ANSWER, %eax ret )asm"); // `.s` is assembled verbatim. write_file(proj / "src" / "twice.s", R"asm( .text .globl asm_twice .type asm_twice, @function asm_twice: lea (%rdi,%rdi), %eax ret )asm"); Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = {"build", "--project", proj.string(), "--build-dir", bdir.string()}; req.timeout = std::chrono::seconds{300}; auto res = Platform::run_supervised(req); Void::Testing::expect(res.has_value() && res->succeeded()); if (res && !res->succeeded()) { std::fprintf(stderr, "%s\n", (res->stdout_data + res->stderr_data).c_str()); } const auto app = bdir / "profiles" / "debug" / "out" / "bin" / "asm_app"; Void::Testing::expect(std::filesystem::exists(app)); if (std::filesystem::exists(app)) { Platform::ProcessRequest run; run.executable = app; run.timeout = std::chrono::seconds{60}; auto ran = Platform::run_supervised(run); Void::Testing::expect(ran.has_value() && ran->succeeded()); } } // === Shader sources compile to SPIR-V === VOID_TEST(FullV1Tests, shader_bundle_compiles_sources_to_spirv) { if (!Platform::resolve_executable("glslangValidator")) { return; // No shader compiler in this environment. } 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_shader_"}; const auto proj = tmp / "proj"; const auto bdir = tmp / "build"; write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.shader_bundle("shaders") .shader("shaders/tri.vert") .shader("shaders/tri.frag"); } )cpp"); write_file(proj / "shaders" / "tri.vert", "#version 450\nlayout(location = 0) in vec3 pos;\n" "void main() { gl_Position = vec4(pos, 1.0); }\n"); write_file(proj / "shaders" / "tri.frag", "#version 450\nlayout(location = 0) out vec4 color;\n" "void main() { color = vec4(1.0); }\n"); Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = {"build", "--project", proj.string(), "--build-dir", bdir.string()}; req.timeout = std::chrono::seconds{300}; auto res = Platform::run_supervised(req); Void::Testing::expect(res.has_value() && res->succeeded()); if (res && !res->succeeded()) { std::fprintf(stderr, "%s\n", (res->stdout_data + res->stderr_data).c_str()); } // Each shader produced a SPIR-V module (magic 0x07230203, little-endian on disk). std::size_t modules = 0; for (const auto &entry : std::filesystem::recursive_directory_iterator( bdir / "profiles" / "debug" / "shaders", std::filesystem::directory_options::skip_permission_denied)) { if (!entry.is_regular_file() || entry.path().extension() != ".spv") { continue; } auto bytes = Void::FileSystem::read_file(entry.path()); Void::Testing::require(bytes.has_value() && bytes->size() >= 20); Void::Testing::expect(std::string_view{*bytes}.substr(0, 4) == std::string_view{"\x03\x02\x23\x07", 4}); ++modules; } Void::Testing::expect_eq(modules, std::size_t{2}); // A shader with an unknown stage and no compiler hint is rejected with a clear error. write_file(proj / "shaders" / "mystery.glsl", "#version 450\nvoid main() {}\n"); write_file(proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { p.shader_bundle("shaders").shader("shaders/mystery.glsl"); } )cpp"); auto bad = Platform::run_supervised(req); Void::Testing::expect(bad.has_value() && !bad->succeeded()); if (bad) { Void::Testing::expect(bad->stderr_data.find("cannot infer the stage") != std::string::npos); } } // === Track A1: Native VBS subproject dependency (builder == "native", zero CMake!) === VOID_TEST(FullV1Tests, native_vbs_subproject_dependency_builds_without_cmake) { 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_native_subproj_"}; const auto trap_bin = tmp / "trap_bin"; write_file(trap_bin / "cmake", "#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN NATIVE DEP BUILD' >&2\nexit 99\n"); std::filesystem::permissions(trap_bin / "cmake", std::filesystem::perms::owner_exec | std::filesystem::perms::owner_read | std::filesystem::perms::owner_write | std::filesystem::perms::group_exec | std::filesystem::perms::others_exec); std::string trapped_path = trap_bin.string(); if (const char *old_path = std::getenv("PATH")) { trapped_path += ":"; trapped_path += old_path; } // 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"}) .include_directory("include", Void::Build::Visibility::Public); } )cpp"); write_file(dep_dir / "include" / "sub_math.hpp", "#pragma once\nint sub_math_answer();\n"); write_file(dep_dir / "src" / "math.cpp", "#include \"sub_math.hpp\"\nint sub_math_answer() { return 42; }\n"); const auto cons_dir = tmp / "consumer"; const auto cons_build = tmp / "consumer_build"; write_file(cons_dir / "build.cpp", "#include \n" "void build(Void::Build::Project &p) {\n" " auto dep = p.dependency(\"math\").path(\"" + dep_dir.string() + "\").native_builder({{\"SUB_MATH_ENABLED\", \"yes\"}});\n" " p.test(\"consumer_test\")\n" " .cxx_standard(Void::Build::CxxStandard::Cxx26)\n" " .sources({\"tests/main.cpp\"})\n" " .link(dep.target(\"sub_math\"));\n" "}\n"); write_file( cons_dir / "tests" / "main.cpp", "#include \"sub_math.hpp\"\nint main() { return sub_math_answer() == 42 ? 0 : 1; }\n"); Platform::ProcessRequest req; req.executable = vbs_bin; 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); Void::Testing::expect_eq( res ? (res->succeeded() ? std::string{} : (res->stdout_data + res->stderr_data)) : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->succeeded()); 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 === VOID_TEST(FullV1Tests, track_b1_native_c_driver_and_mixed_c_cpp_cmake_meson_translation) { Void::FileSystem::TempDir tmp{"vbs_track_b1_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) { return; } Void::Testing::expect(!tc->c_compiler.empty()); Void::Testing::expect(tc->supports_c11 && tc->supports_c17 && tc->supports_c23); auto state = State::StateStore::open(tmp / "state"); Void::Testing::expect(state.has_value()); if (!state) { return; } // 1. Pure VBS native C17 static library + C++23 executable + CompDB separation. { const auto proj = tmp / "native_mixed"; const auto bdir = tmp / "native_mixed_build"; write_file(proj / "include" / "c_math.h", "#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" "int vbs_c_add(int a, int b);\n#ifdef __cplusplus\n}\n#endif\n"); write_file(proj / "src" / "c_math.c", "#include \"c_math.h\"\n" "_Static_assert(sizeof(int) >= 4, \"C11 _Static_assert check\");\n" "int vbs_c_add(int a, int b) { return a + b; }\n"); write_file(proj / "src" / "main.cpp", "#include \"c_math.h\"\n#include \n" "int main() { std::cout << \"c17+cxx23=\" << vbs_c_add(19, 23) << '\\n'; " "return 0; }\n"); Graph::ProjectDescription desc; desc.profile = ctx; TargetRecord clib; clib.name = "c_core"; clib.kind = TargetKind::StaticLibrary; clib.c_standard = CStandard::C17; clib.sources.push_back({SourceKind::File, "src/c_math.c"}); clib.include_directories.push_back({"include", Visibility::Public, false}); desc.targets.push_back(clib); TargetRecord app; app.name = "mixed_app"; app.kind = TargetKind::Executable; app.cxx_standard = CxxStandard::Cxx23; app.sources.push_back({SourceKind::File, "src/main.cpp"}); app.links.push_back({LinkKind::Local, "c_core", {}, Visibility::Private}); desc.targets.push_back(app); auto graph = Graph::lower_project_graph(desc, *tc, {proj, bdir, nullptr, {}, 32768}); Void::Testing::expect(graph.has_value()); if (!graph) { return; } const auto cmds = Editor::project_editor_commands(*graph); bool checked_c_entry = false; bool checked_cxx_entry = false; for (const auto &e : cmds) { if (e.file.filename() == "c_math.c") { checked_c_entry = true; Void::Testing::expect(std::ranges::contains(e.arguments, std::string{"-std=c17"})); Void::Testing::expect( !std::ranges::contains(e.arguments, std::string{"-std=c++23"})); Void::Testing::expect_eq(e.arguments.front(), tc->c_compiler.string()); } else if (e.file.filename() == "main.cpp") { checked_cxx_entry = true; Void::Testing::expect( std::ranges::contains(e.arguments, std::string{"-std=c++23"})); Void::Testing::expect_eq(e.arguments.front(), tc->cxx_compiler.string()); } } Void::Testing::expect(checked_c_entry && checked_cxx_entry); auto exec = Execution::execute_graph(*graph, *state); Void::Testing::expect(exec.has_value() && exec->succeeded); Platform::ProcessRequest r; r.executable = bdir / "profiles" / "debug" / "out" / "bin" / "mixed_app"; auto out = Platform::run_supervised(r); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"c17+cxx23=42\n"}); } } // 2. CMake mixed C11 + C++20 native translation (zero cmake --build). { const auto cm_src = tmp / "cmake_mixed"; write_file(cm_src / "include" / "cmix.h", "#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" "int cmix_c_base(void);\n#ifdef __cplusplus\n}\n#endif\n" "#ifdef __cplusplus\nint cmix_cxx_total();\n#endif\n"); write_file(cm_src / "src" / "helper.c", "#include \"cmix.h\"\nint cmix_c_base(void) { return 30 + C_EXTRA; }\n"); write_file(cm_src / "src" / "wrapper.cpp", "#include \"cmix.h\"\nint cmix_cxx_total() { return cmix_c_base() + CXX_EXTRA; " "}\n"); write_file(cm_src / "src" / "cli.cpp", "#include \"cmix.h\"\n#include \n" "int main() { std::cout << \"cmix=\" << cmix_cxx_total() << '\\n'; return 0; " "}\n"); write_file(cm_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(tb1_cmake LANGUAGES C CXX) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) add_library(cmix STATIC src/helper.c src/wrapper.cpp) target_include_directories(cmix PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_definitions(cmix PRIVATE $<$:C_EXTRA=5> $<$:CXX_EXTRA=7>) add_executable(cmix_cli src/cli.cpp) target_link_libraries(cmix_cli PRIVATE cmix) )cmake"); DependencyRecord dep; dep.name = "tb1_cm"; dep.source_kind = DependencySourceKind::Path; dep.location = cm_src.string(); dep.builder = "cmake"; auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) { return; } Provider::ProviderRequest req{ dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto res = Provider::resolve_cmake_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->executed_natively && res->audit.is_supported()); const auto hash = Provider::compute_provider_input_hash(req); const auto exe = tmp / "prov" / ("translate_tb1_cm_" + hash.substr(0, 16)) / "native-build" / "profiles" / "debug" / "out" / "bin" / "cmix_cli"; Platform::ProcessRequest rr; rr.executable = exe; auto out = Platform::run_supervised(rr); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"cmix=42\n"}); } } // 3. Meson mixed C17 + C++20 native translation (zero meson compile). if (Platform::resolve_executable("meson").has_value()) { const auto m_src = tmp / "meson_mixed"; write_file(m_src / "include" / "mmix.h", "#pragma once\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n" "int mmix_c_base(void);\n#ifdef __cplusplus\n}\n#endif\n" "#ifdef __cplusplus\nint mmix_cxx_total();\n#endif\n"); write_file(m_src / "src" / "helper.c", "#include \"mmix.h\"\nint mmix_c_base(void) { return 20 + MC_ADD; }\n"); write_file(m_src / "src" / "wrap.cpp", "#include \"mmix.h\"\nint mmix_cxx_total() { return mmix_c_base() + 15; }\n"); write_file(m_src / "src" / "main.cpp", "#include \"mmix.h\"\n#include \n" "int main() { std::cout << \"mmix=\" << mmix_cxx_total() << '\\n'; return 0; " "}\n"); write_file(m_src / "meson.build", R"meson( project('tb1_meson', ['c', 'cpp'], default_options: ['c_std=c17', 'cpp_std=c++20']) inc = include_directories('include') lib = static_library('mmix', ['src/helper.c', 'src/wrap.cpp'], include_directories: inc, c_args: ['-DMC_ADD=7']) executable('mmix_cli', ['src/main.cpp'], include_directories: inc, link_with: lib) )meson"); DependencyRecord dep; dep.name = "tb1_me"; dep.source_kind = DependencySourceKind::Path; dep.location = m_src.string(); dep.builder = "meson"; auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) { return; } Provider::ProviderRequest req{ dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto res = Provider::resolve_meson_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->executed_natively && res->audit.is_supported()); const auto hash = Provider::compute_provider_input_hash(req); const auto exe = tmp / "prov" / ("translate_meson_tb1_me_" + hash.substr(0, 16)) / "native-build" / "profiles" / "debug" / "out" / "bin" / "mmix_cli"; Platform::ProcessRequest rr; rr.executable = exe; auto out = Platform::run_supervised(rr); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"mmix=42\n"}); } } } // === Track B2: Bounded build.ninja CUSTOM_COMMAND translation & unsafe-rule rejection === VOID_TEST(FullV1Tests, track_b2_bounded_ninja_custom_command_cmake_and_meson_translation) { Void::FileSystem::TempDir tmp{"vbs_track_b2_"}; auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) { return; } auto state = State::StateStore::open(tmp / "state"); Void::Testing::expect(state.has_value()); if (!state) { return; } // 1. CMake hermetic custom command (generated header + generated .cpp + UTILITY DEPENDS). { const auto src = tmp / "cm_gen"; write_file(src / "gen_hdr.cmake", "file(WRITE \"${OUT}\" \"#pragma once\\n#define B2_CM_HDR 50\\n\")\n"); write_file(src / "gen_cpp.cmake", "file(WRITE \"${OUT}\" \"#include \\\"gen_val.hpp\\\"\\n" "int b2_cm_val() { return B2_CM_HDR + 27; }\\n\")\n"); write_file(src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(tb2_cmake LANGUAGES CXX) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp" COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp -P ${CMAKE_CURRENT_SOURCE_DIR}/gen_hdr.cmake DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_hdr.cmake" ) add_custom_target(run_gen DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp") add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp" COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp -P ${CMAKE_CURRENT_SOURCE_DIR}/gen_cpp.cmake DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_cpp.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp" ) add_library(b2_lib STATIC "${CMAKE_CURRENT_BINARY_DIR}/gen_src.cpp" "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp") add_dependencies(b2_lib run_gen) target_include_directories(b2_lib PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") add_executable(b2_app src/main.cpp) target_link_libraries(b2_app PRIVATE b2_lib) )cmake"); write_file(src / "src" / "main.cpp", "#include \"gen_val.hpp\"\n#include \n" "int b2_cm_val();\n" "int main() { std::cout << \"cm_gen=\" << b2_cm_val() << '\\n'; return 0; }\n"); DependencyRecord dep; dep.name = "tb2_cm"; dep.source_kind = DependencySourceKind::Path; dep.location = src.string(); dep.builder = "cmake"; auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) { return; } Provider::ProviderRequest req{ dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto res = Provider::resolve_cmake_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->executed_natively && res->audit.is_supported()); const auto hash = Provider::compute_provider_input_hash(req); const auto exe = tmp / "prov" / ("translate_tb2_cm_" + hash.substr(0, 16)) / "native-build" / "profiles" / "debug" / "out" / "bin" / "b2_app"; Platform::ProcessRequest rr; rr.executable = exe; auto out = Platform::run_supervised(rr); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"cm_gen=77\n"}); } } // 2. CMake negative checks: side-effect-only .util target AND out-of-tree OUTPUT MUST fail // RequireNative! { const auto bad_util_src = tmp / "cm_bad_util"; write_file(bad_util_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.20) project(tb2_bad_util LANGUAGES CXX) add_custom_target(side_effect COMMAND ${CMAKE_COMMAND} -E echo side_effect_only) add_library(b2_u_lib STATIC src/lib.cpp) add_dependencies(b2_u_lib side_effect) )cmake"); write_file(bad_util_src / "src" / "lib.cpp", "int b2_u() { return 1; }\n"); DependencyRecord bdep; bdep.name = "tb2_bad_u"; bdep.source_kind = DependencySourceKind::Path; bdep.location = bad_util_src.string(); bdep.builder = "cmake"; auto bmat = Package::materialize_dependency_source(bdep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(bmat.has_value()); if (bmat) { Provider::ProviderRequest breq{ bdep, *bmat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto bad = Provider::resolve_cmake_with_translation( breq, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect(!bad.has_value()); } const auto bad_oot_src = tmp / "cm_bad_oot"; const auto outside_file = tmp / "outside_generated.hpp"; write_file(bad_oot_src / "CMakeLists.txt", "cmake_minimum_required(VERSION 3.20)\nproject(tb2_bad_oot LANGUAGES CXX)\n" "add_custom_command(OUTPUT \"" + outside_file.string() + "\" COMMAND ${CMAKE_COMMAND} -E touch \"" + outside_file.string() + "\")\n" "add_library(b2_oot_lib STATIC src/lib.cpp \"" + outside_file.string() + "\")\n"); write_file(bad_oot_src / "src" / "lib.cpp", "int b2_oot() { return 1; }\n"); DependencyRecord odep; odep.name = "tb2_bad_oot"; odep.source_kind = DependencySourceKind::Path; odep.location = bad_oot_src.string(); odep.builder = "cmake"; auto omat = Package::materialize_dependency_source(odep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(omat.has_value()); if (omat) { Provider::ProviderRequest oreq{ odep, *omat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto ocfg = Provider::configure_cmake_for_translation(oreq, tmp / "oot_cfg"); Void::Testing::expect(ocfg.has_value()); auto oaudit = Provider::audit_cmake_codemodel(tmp / "oot_cfg"); Void::Testing::expect(oaudit.has_value() && !oaudit->is_supported()); } } // 3. Meson hermetic custom_target (generated header + generated .cpp) under RequireNative, // plus negative rejection on Meson run_target. if (Platform::resolve_executable("meson").has_value()) { const auto m_src = tmp / "meson_gen_native"; write_file(m_src / "meson.build", R"meson( project('tb2_meson', 'cpp') gen_hdr = custom_target('gen_hdr', output: 'gen_num.hpp', command: ['/bin/sh', '-c', 'printf "#pragma once\n#define M_GEN_NUM 80\n" > "$1"', '--', '@OUTPUT@']) gen_cpp = custom_target('gen_cpp', output: 'gen_num.cpp', command: ['/bin/sh', '-c', 'printf "int m_gen_extra() { return 8; }\n" > "$1"', '--', '@OUTPUT@']) lib = static_library('mgenlib', ['src/gen.cpp', gen_hdr, gen_cpp]) executable('mgen_app', ['src/main.cpp', gen_hdr], link_with: lib) )meson"); write_file(m_src / "src" / "gen.cpp", "#include \"gen_num.hpp\"\nint m_gen_extra();\n" "int m_gen_fn() { return M_GEN_NUM + m_gen_extra(); }\n"); write_file(m_src / "src" / "main.cpp", "#include \"gen_num.hpp\"\n#include \n" "int m_gen_fn();\n" "int main() { std::cout << \"m_gen=\" << m_gen_fn() << '\\n'; return 0; }\n"); DependencyRecord mdep; mdep.name = "tb2_me"; mdep.source_kind = DependencySourceKind::Path; mdep.location = m_src.string(); mdep.builder = "meson"; auto mat = Package::materialize_dependency_source(mdep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) { return; } Provider::ProviderRequest req{ mdep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto res = Provider::resolve_meson_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->executed_natively && res->audit.is_supported()); const auto hash = Provider::compute_provider_input_hash(req); const auto exe = tmp / "prov" / ("translate_meson_tb2_me_" + hash.substr(0, 16)) / "native-build" / "profiles" / "debug" / "out" / "bin" / "mgen_app"; Platform::ProcessRequest rr; rr.executable = exe; auto out = Platform::run_supervised(rr); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"m_gen=88\n"}); } const auto run_src = tmp / "meson_run_tgt"; write_file(run_src / "meson.build", R"meson( project('tb2_m_run', 'cpp') run_target('do_run', command: ['echo', 'hi']) static_library('mrunlib', ['src/a.cpp']) )meson"); write_file(run_src / "src" / "a.cpp", "int m_run_a() { return 1; }\n"); DependencyRecord rdep; rdep.name = "tb2_m_run"; rdep.source_kind = DependencySourceKind::Path; rdep.location = run_src.string(); rdep.builder = "meson"; auto rmat = Package::materialize_dependency_source(rdep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(rmat.has_value()); if (rmat) { Provider::ProviderRequest rreq{ rdep, *rmat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto rstrict = Provider::resolve_meson_with_translation( rreq, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect(!rstrict.has_value()); } } } // === Track B3: Foreign CMake C++20 CXX_MODULES native translation & cross-target import === VOID_TEST(FullV1Tests, track_b3_foreign_cmake_cxx20_modules_native_translation) { Void::FileSystem::TempDir tmp{"vbs_track_b3_"}; auto state = State::StateStore::open(tmp / "state"); Void::Testing::expect(state.has_value()); if (!state) { return; } auto verify_for_family = [&](CompilerFamily family, std::string_view label) { auto ctx = default_profiles().resolve("debug", family, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / ("probes_" + std::string{label})); Void::Testing::expect(tc.has_value()); if (!tc || !tc->supports_p1689_scan) { return; } const auto cm_src = tmp / ("cm_mods_" + std::string{label}); write_file(cm_src / "src" / "math_mod.cppm", "export module vbs.trackb3.math;\n" "export int b3_mul7(int x) { return x * 7; }\n"); write_file(cm_src / "src" / "app.cpp", "import vbs.trackb3.math;\n#include \n" "int main() { std::cout << b3_mul7(6) << '\\n'; return 0; }\n"); write_file(cm_src / "CMakeLists.txt", R"cmake( cmake_minimum_required(VERSION 3.28) project(tb3_mods LANGUAGES CXX) add_library(mod_math STATIC) target_sources(mod_math PUBLIC FILE_SET CXX_MODULES FILES src/math_mod.cppm) target_compile_features(mod_math PUBLIC cxx_std_20) add_executable(mod_app src/app.cpp) target_link_libraries(mod_app PRIVATE mod_math) target_compile_features(mod_app PRIVATE cxx_std_20) )cmake"); DependencyRecord dep; dep.name = std::string{"tb3_cm_"} + std::string{label}; dep.source_kind = DependencySourceKind::Path; dep.location = cm_src.string(); dep.builder = "cmake"; auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}}); Void::Testing::expect(mat.has_value()); if (!mat) { return; } Provider::ProviderRequest req{ dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}; auto res = Provider::resolve_cmake_with_translation( req, *state, Provider::TranslationPolicy::RequireNative); Void::Testing::expect_eq(res ? std::string{} : res.error().message(), std::string{}); Void::Testing::expect(res.has_value() && res->executed_natively && res->audit.is_supported()); if (!res) { return; } const auto hash = Provider::compute_provider_input_hash(req); const auto mod_exe = tmp / "prov" / ("translate_" + dep.name + "_" + hash.substr(0, 16)) / "native-build" / "profiles" / "debug" / "out" / "bin" / "mod_app"; Platform::ProcessRequest rr; rr.executable = mod_exe; auto out = Platform::run_supervised(rr); Void::Testing::expect(out.has_value() && out->succeeded()); if (out) { Void::Testing::expect_eq(out->stdout_data, std::string{"42\n"}); } // Verify cross-target / imported BMI propagation: a native VBS executable importing // `vbs.trackb3.math` from the translated CMake module library! const auto iface_it = res->exported.targets.find(dep.name + "::mod_math"); Void::Testing::expect(iface_it != res->exported.targets.end()); if (iface_it != res->exported.targets.end()) { Void::Testing::expect(iface_it->second.module_bmis.contains("vbs.trackb3.math")); const auto cons_root = tmp / ("vbs_cons_" + std::string{label}); const auto cons_build = tmp / ("vbs_cons_build_" + std::string{label}); write_file(cons_root / "src" / "cons.cpp", "import vbs.trackb3.math;\n#include \n" "int main() { std::cout << (b3_mul7(7) + 1) << '\\n'; return 0; }\n"); Graph::ProjectDescription cdesc; cdesc.profile = ctx; TargetRecord capp; capp.name = "vbs_mod_consumer"; capp.kind = TargetKind::Executable; capp.cxx_standard = CxxStandard::Cxx20; capp.sources.push_back({SourceKind::File, "src/cons.cpp"}); capp.links.push_back({LinkKind::Imported, "mod_math", dep.name, Visibility::Private}); cdesc.targets.push_back(capp); Graph::GraphLowerOptions gopts{cons_root, cons_build, nullptr, res->exported.targets, 32768}; auto cgraph = Graph::lower_project_graph(cdesc, *tc, gopts); Void::Testing::expect_eq(cgraph ? std::string{} : cgraph.error().message(), std::string{}); Void::Testing::expect(cgraph.has_value()); if (cgraph) { auto cexec = Execution::execute_graph(*cgraph, *state); Void::Testing::expect(cexec.has_value() && cexec->succeeded); Platform::ProcessRequest cr; cr.executable = cons_build / "profiles" / "debug" / "out" / "bin" / "vbs_mod_consumer"; auto cout = Platform::run_supervised(cr); Void::Testing::expect(cout.has_value() && cout->succeeded()); if (cout) { Void::Testing::expect_eq(cout->stdout_data, std::string{"50\n"}); } } } }; if (Platform::resolve_executable("g++").has_value()) { verify_for_family(CompilerFamily::Gcc, "gcc16"); } if (Platform::resolve_executable("clang++").has_value()) { verify_for_family(CompilerFamily::Clang, "clang23"); } } // === IDE Integration: `build.cpp` CompDB indexing + `vbs ide generate` & `vbs ide query` === VOID_TEST(FullV1Tests, ide_integration_compdb_build_cpp_and_editor_configs_end_to_end) { 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_ide_"}; const auto proj = tmp / "ide_proj"; const auto bdir = tmp / "ide_build"; auto run_vbs = [&](std::vector args) { Platform::ProcessRequest req; req.executable = vbs_bin; req.arguments = std::move(args); req.timeout = std::chrono::seconds{120}; return Platform::run_supervised(req); }; // 1. Scaffold a C++26 project via `vbs init`. auto r_init = run_vbs({"init", "--dir", proj.string(), "--name", "ide_demo"}); Void::Testing::expect(r_init.has_value() && r_init->succeeded()); // 2. Generate all IDE configs (`--editor all`) BEFORE any full build has run. auto r_gen = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir", bdir.string(), "--editor", "all"}); Void::Testing::expect_eq( r_gen ? (r_gen->succeeded() ? std::string{} : (r_gen->stdout_data + r_gen->stderr_data)) : r_gen.error().message(), std::string{}); Void::Testing::expect(r_gen.has_value() && r_gen->succeeded()); // Check every generated file exists and every JSON file parses strictly. Void::Testing::expect(std::filesystem::exists(proj / ".clangd")); Void::Testing::expect(std::filesystem::exists(proj / ".idea" / "customTargets.xml")); for (const auto &json_file : {proj / ".vscode" / "tasks.json", proj / ".vscode" / "launch.json", proj / ".vscode" / "settings.json", proj / ".zed" / "tasks.json", proj / ".zed" / "debug.json"}) { Void::Testing::expect(std::filesystem::exists(json_file)); auto content = Void::FileSystem::read_file(json_file); Void::Testing::expect(content.has_value()); if (content) { auto parsed = Void::Json::Strict::parse(*content); Void::Testing::expect(parsed.has_value()); } } // The CMake File API shim emits a codemodel-v2 reply tree from the lowered graph. { const auto reply_dir = bdir / ".cmake" / "api" / "v1" / "reply"; Void::Testing::expect(std::filesystem::exists(reply_dir)); std::filesystem::path index_file; if (std::filesystem::exists(reply_dir)) { for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) { if (entry.path().filename().string().starts_with("index-")) { index_file = entry.path(); } } } Void::Testing::require(!index_file.empty()); const auto read_json = [](const std::filesystem::path &path) -> std::optional { auto text = Void::FileSystem::read_file(path); if (!text) { return std::nullopt; } auto parsed = Void::Json::Strict::parse(*text); if (!parsed) { return std::nullopt; } return std::move(*parsed); }; using JsonObject = Void::Json::Strict::Value::Object; const auto get_object = [](const JsonObject &object, std::string_view key) -> const JsonObject * { const auto it = object.find(key); return it == object.end() ? nullptr : std::get_if(&it->second.value); }; const auto get_string = [](const JsonObject &object, std::string_view key) -> std::string { const auto it = object.find(key); if (it == object.end()) { return {}; } const auto *text = std::get_if(&it->second.value); return text ? *text : std::string{}; }; const auto index_json = read_json(index_file); Void::Testing::require(index_json.has_value()); const auto *index_object = std::get_if(&index_json->value); Void::Testing::require(index_object != nullptr); const auto *reply = get_object(*index_object, "reply"); Void::Testing::require(reply != nullptr); const auto *codemodel_entry = get_object(*reply, "codemodel-v2"); Void::Testing::require(codemodel_entry != nullptr); const auto codemodel_file = get_string(*codemodel_entry, "jsonFile"); Void::Testing::require(!codemodel_file.empty()); // The full reply set an IDE needs to load the project: cache, cmake files, toolchains. for (const auto &kind : {"cache-v2", "cmakeFiles-v1", "toolchains-v1"}) { const auto *entry = get_object(*reply, kind); Void::Testing::require(entry != nullptr); const auto file = get_string(*entry, "jsonFile"); Void::Testing::require(!file.empty()); const auto parsed = read_json(reply_dir / file); Void::Testing::require(parsed.has_value()); const auto *object = std::get_if(&parsed->value); Void::Testing::require(object != nullptr); Void::Testing::expect(!get_string(*object, "kind").empty()); } const auto cache_file = get_string(*get_object(*reply, "cache-v2"), "jsonFile"); const auto cache_json = read_json(reply_dir / cache_file); Void::Testing::require(cache_json.has_value()); auto cache_text = Void::FileSystem::read_file(reply_dir / cache_file); Void::Testing::require(cache_text.has_value()); Void::Testing::expect(cache_text->find("CMAKE_BUILD_TYPE") != std::string::npos); Void::Testing::expect(cache_text->find("CMAKE_CXX_COMPILER") != std::string::npos); const auto codemodel_json = read_json(reply_dir / codemodel_file); Void::Testing::require(codemodel_json.has_value()); const auto *codemodel_object = std::get_if(&codemodel_json->value); Void::Testing::require(codemodel_object != nullptr); const auto configs_it = codemodel_object->find("configurations"); Void::Testing::require(configs_it != codemodel_object->end()); const auto *configs = std::get_if(&configs_it->second.value); Void::Testing::require(configs != nullptr && !configs->empty()); const auto *configuration = std::get_if(&configs->front().value); Void::Testing::require(configuration != nullptr); const auto targets_it = configuration->find("targets"); Void::Testing::require(targets_it != configuration->end()); const auto *targets = std::get_if(&targets_it->second.value); Void::Testing::require(targets != nullptr && !targets->empty()); const auto *first_target = std::get_if(&targets->front().value); Void::Testing::require(first_target != nullptr); const auto target_file = get_string(*first_target, "jsonFile"); Void::Testing::require(!target_file.empty()); const auto target_json = read_json(reply_dir / target_file); Void::Testing::require(target_json.has_value()); const auto *target_object = std::get_if(&target_json->value); Void::Testing::require(target_object != nullptr); Void::Testing::expect_eq(get_string(*target_object, "kind"), std::string{"target"}); Void::Testing::expect(!get_string(*target_object, "type").empty()); Void::Testing::expect(!get_string(*target_object, "name").empty()); auto target_text = Void::FileSystem::read_file(reply_dir / target_file); Void::Testing::require(target_text.has_value()); // At least one emitted target is the executable, with artifacts and compile groups. bool saw_executable = false; for (const auto &entry : std::filesystem::directory_iterator(reply_dir)) { const auto name = entry.path().filename().string(); if (!name.starts_with("target-")) { continue; } auto text = Void::FileSystem::read_file(entry.path()); if (text && text->find("\"type\":\"EXECUTABLE\"") != std::string::npos) { saw_executable = true; Void::Testing::expect(text->find("\"artifacts\":[{") != std::string::npos); Void::Testing::expect(text->find("\"compileGroups\":[{") != std::string::npos); } } Void::Testing::expect(saw_executable); } // The generated IDE tasks include install/package entries. if (auto tasks = Void::FileSystem::read_file(proj / ".vscode" / "tasks.json"); tasks) { Void::Testing::expect(tasks->find("vbs: install") != std::string::npos); Void::Testing::expect(tasks->find("vbs: package installer") != std::string::npos); } if (auto zed_tasks = Void::FileSystem::read_file(proj / ".zed" / "tasks.json"); zed_tasks) { Void::Testing::expect(zed_tasks->find("vbs: install") != std::string::npos); } // 3. Non-destructive overwrite preservation without `--force`, and overwrite with `--force`. write_file(proj / ".clangd", "# user-customized clangd\n"); auto r_keep = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir", bdir.string(), "--editor", "clangd"}); Void::Testing::expect(r_keep.has_value() && r_keep->succeeded()); Void::Testing::expect_eq(Void::FileSystem::read_file(proj / ".clangd").value_or(""), std::string{"# user-customized clangd\n"}); auto r_force = run_vbs({"ide", "generate", "--project", proj.string(), "--build-dir", bdir.string(), "--editor", "clangd", "--force"}); Void::Testing::expect(r_force.has_value() && r_force->succeeded()); const auto refreshed_clangd = Void::FileSystem::read_file(proj / ".clangd").value_or(""); Void::Testing::expect(refreshed_clangd.find("CompilationDatabase:") != std::string::npos); Void::Testing::expect(refreshed_clangd.find("-freflection") != std::string::npos); // 4. Verify `compile_commands.json` contains a real, valid compiler invocation for `build.cpp` // and syntax-check `build.cpp` using that exact CompDB entry! const auto compdb_text = Void::FileSystem::read_file(bdir / "compile_commands.json"); Void::Testing::expect(compdb_text.has_value()); if (compdb_text) { auto parsed_db = Void::Json::Strict::parse(*compdb_text); Void::Testing::expect(parsed_db.has_value()); bool checked_build_cpp = false; if (parsed_db) { if (const auto *arr = std::get_if(&parsed_db->value)) { for (const auto &ev : *arr) { const auto *eo = std::get_if(&ev.value); if (!eo) { continue; } const auto fit = eo->find("file"); const auto ait = eo->find("arguments"); if (fit == eo->end() || ait == eo->end()) { continue; } const auto *fs = std::get_if(&fit->second.value); const auto *aarr = std::get_if(&ait->second.value); if (!fs || !aarr || std::filesystem::path{*fs}.filename() != "build.cpp") { continue; } checked_build_cpp = true; std::vector argv; for (const auto &av : *aarr) { if (const auto *as = std::get_if(&av.value)) { argv.push_back(*as); } } Void::Testing::expect(!argv.empty()); Void::Testing::expect(std::ranges::contains(argv, std::string{"-std=c++26"})); Platform::ProcessRequest check_req; check_req.executable = argv.front(); for (std::size_t i = 1; i < argv.size(); ++i) { if (argv[i] == "-c") { check_req.arguments.push_back("-fsyntax-only"); } else if (argv[i] == "-o" && i + 1 < argv.size()) { ++i; } else { check_req.arguments.push_back(argv[i]); } } check_req.timeout = std::chrono::seconds{30}; auto syntax_ok = Platform::run_supervised(check_req); Void::Testing::expect(syntax_ok.has_value() && syntax_ok->succeeded()); } } } Void::Testing::expect(checked_build_cpp); } // 5. Verify `vbs ide query` emits valid JSON workspace & target metadata. auto r_query = run_vbs({"ide", "query", "--project", proj.string(), "--build-dir", bdir.string()}); Void::Testing::expect(r_query.has_value() && r_query->succeeded()); if (r_query) { auto pq = Void::Json::Strict::parse(r_query->stdout_data); Void::Testing::expect(pq.has_value()); Void::Testing::expect(r_query->stdout_data.find("\"ide_demo\"") != std::string::npos); Void::Testing::expect(r_query->stdout_data.find("\"ide_demo_lib\"") != std::string::npos); Void::Testing::expect(r_query->stdout_data.find("\"ide_demo_tests\"") != std::string::npos); Void::Testing::expect(r_query->stdout_data.find("\"compdb_path\"") != std::string::npos); Void::Testing::expect(r_query->stdout_data.find("\"sdk_include_dir\"") != std::string::npos); } } // Live Conan2 verification (Track B3): a real local package is built into an isolated // CONAN_HOME and the provider performs a real `conan install`. VOID_TEST(FullV1Tests, track_b3_live_conan_provider_install) { if (!Platform::resolve_executable("conan").has_value()) { return; } Void::FileSystem::TempDir tmp{"vbs_conan_live_"}; const auto conan_home = tmp / "conan_home"; const auto profile = tmp / "conan.profile"; write_file(profile, "[settings]\nos=Linux\narch=x86_64\ncompiler=gcc\nbuild_type=Debug\n"); // Isolate the global conan cache and restore the environment afterwards. const char *previous_home = std::getenv("CONAN_HOME"); const std::string saved_home = previous_home == nullptr ? std::string{} : previous_home; const bool had_home = previous_home != nullptr; (void)::setenv("CONAN_HOME", conan_home.c_str(), 1); const auto restore_home = Void::Scope::on_exit([&] { if (had_home) { (void)::setenv("CONAN_HOME", saved_home.c_str(), 1); } else { (void)::unsetenv("CONAN_HOME"); } }); write_file(tmp / "pkg" / "conanfile.py", R"py(from conan import ConanFile from conan.tools.files import copy class DemoPkg(ConanFile): name = "vbs-demo" version = "1.0.0" package_type = "header-library" def package(self): copy(self, "*.hpp", self.source_folder, self.package_folder + "/include") )py"); write_file(tmp / "pkg" / "demo.hpp", "#pragma once\ninline int vbs_demo_value() { return 5; }\n"); Platform::ProcessRequest create; auto conan = Platform::resolve_executable("conan"); Void::Testing::require(conan.has_value()); create.executable = *conan; create.arguments = { "create", (tmp / "pkg").string(), "--name", "vbs-demo", "--version", "1.0.0", "--profile:host", profile.string(), "--profile:build", profile.string()}; create.timeout = std::chrono::seconds{240}; auto created = Platform::run_supervised(create); Void::Testing::expect(created.has_value() && created->succeeded()); if (!created || !created->succeeded()) { return; } auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) { return; } DependencyRecord conan_dep; conan_dep.name = "demo"; conan_dep.source_kind = DependencySourceKind::Conan; conan_dep.package = "vbs-demo/1.0.0"; conan_dep.builder = "conan"; Package::MaterializedSource dummy{"demo", tmp / "src", "dummy", true}; auto exported = Provider::resolve_foreign_provider( {conan_dep, dummy, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}}); Void::Testing::expect(exported.has_value()); if (exported) { Void::Testing::expect_eq(exported->builder, std::string{"conan"}); std::error_code ec; bool found_profile = false; bool found_install_output = false; for (const auto &entry : std::filesystem::recursive_directory_iterator(tmp / "prov", ec)) { if (entry.path().filename() == "conan_host.profile") { found_profile = true; } if (entry.path().filename() == "conanbuild.sh") { found_install_output = true; } } Void::Testing::expect(found_profile); // Generated env scripts prove `conan install` really executed. Void::Testing::expect(found_install_output); } }