#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); } } // namespace // === Plan 09: CompDB projection, selection ticket races, user-file preservation, recovery === Void::Testing::Test 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::Testing::Test 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::Testing::Test 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::Testing::Test 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")); // 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::Testing::Test 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 = std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs"; const auto bridge_module = std::filesystem::path{Bootstrap::source_dir} / "cmake" / "bridge" / "VbsDeps.cmake"; if (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; inst_req.arguments = {"install", "--project", cli_proj.string(), "--build-dir", cli_build.string(), "--prefix", cli_prefix.string(), "--package-name", "CliHiPkg"}; 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")); 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")); } } // === Plan 08: Modern C++ (GCC16 P1689 named modules + partitions, cycle/dup checks, unity, PCH) // === Void::Testing::Test 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::Testing::Test 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::Testing::Test 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()); } } }