Files
2026-11-27 07:50:54 +03:00

2163 lines
102 KiB
C++

#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Bridge/CMakeBridge.hpp>
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Install/Installer.hpp>
#include <Void/Build/Modules/ModuleScanner.hpp>
#include <Void/Build/Package/Archive.hpp>
#include <Void/Build/Package/Fetch.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/Solver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Provider/Translator.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Watch/Watcher.hpp>
#include <Void/Data/StrictJson.hpp>
#include <Void/System/Path.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <thread>
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<std::tuple<std::string, char, std::string>> &entries) {
std::ofstream out(tar_path, std::ios::binary | std::ios::trunc);
for (const auto &[name, typeflag, body] : entries) {
std::array<char, 512> hdr{};
std::memcpy(hdr.data(), name.data(), std::min<std::size_t>(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<char>('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<unsigned char>(c);
oct(hdr.data() + 148, 7, sum);
hdr[155] = ' ';
out.write(hdr.data(), 512);
if (!body.empty()) {
out.write(body.data(), static_cast<std::streamsize>(body.size()));
const std::size_t pad = (512 - (body.size() % 512)) % 512;
if (pad > 0) {
std::array<char, 512> z{};
out.write(z.data(), static_cast<std::streamsize>(pad));
}
}
}
std::array<char, 1024> end{};
out.write(end.data(), 1024);
}
std::filesystem::path locate_vbs_binary() {
std::error_code ec;
if (const auto self = std::filesystem::read_symlink("/proc/self/exe", ec);
!ec && !self.empty()) {
const auto sibling = self.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
// === 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.hpp>
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"));
// 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.hpp>
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_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<std::filesystem::path> 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 <iostream>\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 <iostream>\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<std::string> 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));
}
// === 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 <Void/Build.hpp>
void build(Void::Build::Project &p) {
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 <Void/Build.hpp>\n"
"void build(Void::Build::Project &p) {\n"
" auto dep = p.dependency(\"math\").path(\"" +
dep_dir.string() +
"\").native_builder();\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;
req.arguments = {"test", "--project", cons_dir.string(), "--build-dir", cons_build.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);
}
}
// === 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 <iostream>\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 <iostream>\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
$<$<COMPILE_LANGUAGE:C>:C_EXTRA=5>
$<$<COMPILE_LANGUAGE:CXX>: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 <iostream>\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 <iostream>\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 <iostream>\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 <iostream>\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 <iostream>\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<std::string> 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());
}
}
// 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<Void::Json::Strict::Value::Array>(&parsed_db->value)) {
for (const auto &ev : *arr) {
const auto *eo = std::get_if<Void::Json::Strict::Value::Object>(&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<std::string>(&fit->second.value);
const auto *aarr =
std::get_if<Void::Json::Strict::Value::Array>(&ait->second.value);
if (!fs || !aarr || std::filesystem::path{*fs}.filename() != "build.cpp") {
continue;
}
checked_build_cpp = true;
std::vector<std::string> argv;
for (const auto &av : *aarr) {
if (const auto *as = std::get_if<std::string>(&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);
}
}