Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
This commit is contained in:
1 parent
3cac890ce9
commit
ab64147f9d
114 files changed
+23777
-1392
No files matched your search
+37
-2
@@ -1,15 +1,50 @@
|
||||
add_executable(vbs_sdk_tests SdkDeclarations.cpp ExampleContexts.cpp)
|
||||
target_link_libraries(vbs_sdk_tests PRIVATE vbs_example_description)
|
||||
target_link_libraries(vbs_sdk_tests PRIVATE VoidBuild_ExampleDescription)
|
||||
set_target_properties(vbs_sdk_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_sdk_tests COMMAND "${CMAKE_COMMAND}"
|
||||
"-DSDK_TESTS=$<TARGET_FILE:vbs_sdk_tests>" -P "${CMAKE_CURRENT_SOURCE_DIR}/RunSdkTests.cmake")
|
||||
void_add_tests(vbs_sdk_tests)
|
||||
|
||||
add_executable(vbs_core_tests CoreEngineTests.cpp)
|
||||
target_include_directories(vbs_core_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
|
||||
target_link_libraries(vbs_core_tests PRIVATE Void::BuildCore Void::Testing)
|
||||
set_target_properties(vbs_core_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_core_tests COMMAND "$<TARGET_FILE:vbs_core_tests>" --no-color)
|
||||
void_add_tests(vbs_core_tests)
|
||||
|
||||
add_executable(vbs_v1_tests FullV1Tests.cpp)
|
||||
target_include_directories(vbs_v1_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
|
||||
target_link_libraries(vbs_v1_tests PRIVATE Void::BuildCore Void::Testing)
|
||||
set_target_properties(vbs_v1_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_v1_tests COMMAND "$<TARGET_FILE:vbs_v1_tests>" --no-color)
|
||||
void_add_tests(vbs_v1_tests)
|
||||
|
||||
add_executable(vbs_registry_tests RegistryTests.cpp)
|
||||
target_include_directories(vbs_registry_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
|
||||
target_link_libraries(vbs_registry_tests PRIVATE Void::BuildRegistry Void::Testing)
|
||||
set_target_properties(vbs_registry_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_registry_tests COMMAND "$<TARGET_FILE:vbs_registry_tests>" --no-color)
|
||||
void_add_tests(vbs_registry_tests)
|
||||
|
||||
add_executable(vbs_selfhost_tests SelfHostTests.cpp)
|
||||
target_include_directories(vbs_selfhost_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
|
||||
target_compile_definitions(vbs_selfhost_tests PRIVATE
|
||||
"VBS_VOID_SOURCE_PATH=\"${VBS_VOID_RESOLVED_SOURCE_DIR}\"")
|
||||
target_link_libraries(vbs_selfhost_tests PRIVATE Void::BuildCore Void::Testing)
|
||||
set_target_properties(vbs_selfhost_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_selfhost_tests COMMAND "$<TARGET_FILE:vbs_selfhost_tests>" --no-color)
|
||||
void_add_tests(vbs_selfhost_tests)
|
||||
|
||||
add_test(NAME vbs_sdk_registration COMMAND "${CMAKE_COMMAND}"
|
||||
"-DSDK_TESTS=$<TARGET_FILE:vbs_sdk_tests>" -P "${CMAKE_CURRENT_SOURCE_DIR}/SdkRegistration.cmake")
|
||||
add_test(NAME vbs_cli_contract COMMAND "${CMAKE_COMMAND}"
|
||||
"-DVBS=$<TARGET_FILE:vbs>" "-DVBS_VERSION=${PROJECT_VERSION}"
|
||||
"-DVBS=$<TARGET_FILE:vbs>" "-DVBS_REGISTRY=$<TARGET_FILE:vbs-registry>"
|
||||
"-DVBS_VERSION=${PROJECT_VERSION}"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/CliContracts.cmake")
|
||||
add_test(NAME vbs_description_contract COMMAND "${CMAKE_COMMAND}"
|
||||
"-DDESCRIBE=$<TARGET_FILE:vbs_describe>"
|
||||
|
||||
+38
-21
@@ -1,28 +1,45 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
function(check_process expected_code expected_stdout expected_stderr)
|
||||
function(check_process expected_code expected_out_regex expected_err_regex)
|
||||
execute_process(COMMAND "${VBS}" ${ARGN}
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 10)
|
||||
if(NOT "${code}" STREQUAL "${expected_code}" OR
|
||||
NOT "${out}" STREQUAL "${expected_stdout}" OR
|
||||
NOT "${err}" STREQUAL "${expected_stderr}")
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 15)
|
||||
if(NOT "${code}" STREQUAL "${expected_code}")
|
||||
message(FATAL_ERROR "vbs ${ARGN}: expected exit ${expected_code}, got ${code}\nstdout=[${out}]\nstderr=[${err}]")
|
||||
endif()
|
||||
if(NOT "${expected_out_regex}" STREQUAL "" AND NOT out MATCHES "${expected_out_regex}")
|
||||
message(FATAL_ERROR "vbs ${ARGN}: stdout did not match [${expected_out_regex}]\nactual=[${out}]")
|
||||
endif()
|
||||
if(NOT "${expected_err_regex}" STREQUAL "" AND NOT err MATCHES "${expected_err_regex}")
|
||||
message(FATAL_ERROR "vbs ${ARGN}: stderr did not match [${expected_err_regex}]\nactual=[${err}]")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(help "Usage: vbs [--version]\n\nVoidBuildSystem bootstrap: help and version only.\nNative build, test, compdb, deps and watch commands are planned and unavailable.\n\nFlags:\n --version, -V show bootstrap version\n --help, -h show this help\n")
|
||||
check_process(0 "${help}" "")
|
||||
check_process(0 "${help}" "" --help)
|
||||
check_process(0 "${help}" "" -h)
|
||||
check_process(0 "vbs ${VBS_VERSION} (bootstrap)\n" "" --version)
|
||||
check_process(0 "vbs ${VBS_VERSION} (bootstrap)\n" "" -V)
|
||||
check_process(2 "" "vbs: unknown option: --invalid\n" --invalid)
|
||||
check_process(2 "" "vbs: unknown option: --invalid\n" --version --invalid)
|
||||
check_process(2 "" "vbs: unexpected positional argument: invalid\n" invalid)
|
||||
check_process(2 "" "vbs: --help must be used alone\n" --help --invalid)
|
||||
foreach(command IN ITEMS build test compdb deps watch)
|
||||
check_process(2 "" "vbs: native command '${command}' is not implemented in this bootstrap\n" "${command}")
|
||||
endforeach()
|
||||
check_process(2 "" "vbs: native command 'build' is not implemented in this bootstrap\n" build --profile debug)
|
||||
check_process(2 "" "vbs: native command 'compdb' is not implemented in this bootstrap\n" compdb watch)
|
||||
message(STATUS "16 CLI process contracts verified")
|
||||
check_process(0 "Usage: vbs <command>" "" )
|
||||
check_process(0 "Usage: vbs <command>" "" --help)
|
||||
check_process(0 "Usage: vbs <command>" "" -h)
|
||||
check_process(0 "^vbs ${VBS_VERSION}\n$" "" --version)
|
||||
check_process(0 "^vbs ${VBS_VERSION}\n$" "" -V)
|
||||
check_process(2 "" "--help must be used alone" --help --invalid)
|
||||
check_process(2 "" "unexpected argument after --version" --version --invalid)
|
||||
check_process(2 "" "unknown command 'invalid'" invalid)
|
||||
check_process(0 "Usage: vbs build" "" build --help)
|
||||
check_process(0 "Usage: vbs test" "" test --help)
|
||||
check_process(2 "" "multi-profile build requires --editor-profile" build --profile debug --profile release)
|
||||
check_process(2 "" "must be one of the requested profiles" build --profile debug --profile release --editor-profile custom)
|
||||
check_process(2 "" "expected subcommand" compdb)
|
||||
check_process(2 "" "unknown subcommand" compdb bogus)
|
||||
check_process(2 "" "expected 'resolve' or 'update'" deps)
|
||||
check_process(2 "" "--request and --output are required" bridge)
|
||||
check_process(0 "Usage: vbs install" "" install --help)
|
||||
check_process(2 "" "--prefix is required" install)
|
||||
check_process(2 "" "--prefix is required" uninstall)
|
||||
check_process(2 "" "--input and --output-dir are required" gen-tests)
|
||||
check_process(0 "Usage: vbs publish" "" publish --help)
|
||||
check_process(2 "" "--registry, --name, and --version are required" publish)
|
||||
|
||||
execute_process(COMMAND "${VBS_REGISTRY}" --help
|
||||
RESULT_VARIABLE reg_code OUTPUT_VARIABLE reg_out ERROR_VARIABLE reg_err TIMEOUT 15)
|
||||
if(NOT "${reg_code}" STREQUAL "0" OR NOT reg_out MATCHES "Usage: vbs-registry")
|
||||
message(FATAL_ERROR "vbs-registry --help failed: code=${reg_code}\nstdout=[${reg_out}]\nstderr=[${reg_err}]")
|
||||
endif()
|
||||
message(STATUS "23 native CLI contracts verified")
|
||||
@@ -0,0 +1,490 @@
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Config/Frontend.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <stop_token>
|
||||
#include <sys/stat.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace Void::Build;
|
||||
|
||||
namespace {
|
||||
|
||||
void write_text_file(const std::filesystem::path &path, std::string_view content) {
|
||||
std::error_code ec;
|
||||
if (path.has_parent_path()) {
|
||||
std::filesystem::create_directories(path.parent_path(), ec);
|
||||
}
|
||||
auto r = Platform::atomic_write_file(path, content, false);
|
||||
Void::Testing::expect(r.has_value());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test sha256_nist_vectors_and_files() {
|
||||
Void::Testing::expect_eq(
|
||||
Util::sha256_hex(""),
|
||||
std::string{"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"});
|
||||
Void::Testing::expect_eq(
|
||||
Util::sha256_hex("abc"),
|
||||
std::string{"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"});
|
||||
Void::Testing::expect_eq(
|
||||
Util::sha256_hex("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
|
||||
std::string{"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"});
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_sha_"};
|
||||
const auto f = tmp / "sample.bin";
|
||||
write_text_file(f, "abc");
|
||||
auto fh = Util::sha256_file_hex(f);
|
||||
Void::Testing::expect(fh.has_value());
|
||||
if (fh) {
|
||||
Void::Testing::expect_eq(
|
||||
*fh, std::string{"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"});
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test process_supervisor_exec_failure_and_early_leader_grandchild_kill() {
|
||||
// 1. Distinguish exec failure from exit code 127.
|
||||
{
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = "/nonexistent/vbs_definitely_missing_binary_xyz";
|
||||
req.search_path = false;
|
||||
auto res = Platform::run_supervised(req);
|
||||
Void::Testing::expect(res.has_value());
|
||||
if (res) {
|
||||
Void::Testing::expect(res->exec_failed);
|
||||
Void::Testing::expect(!res->succeeded());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Program explicitly exiting 127 is NOT exec_failed.
|
||||
{
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = "/bin/sh";
|
||||
req.arguments = {"-c", "exit 127"};
|
||||
auto res = Platform::run_supervised(req);
|
||||
Void::Testing::expect(res.has_value());
|
||||
if (res) {
|
||||
Void::Testing::expect(!res->exec_failed);
|
||||
Void::Testing::expect(res->exited);
|
||||
Void::Testing::expect_eq(res->exit_code, 127);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Adversarial VL-001 test: leader spawns stubborn grandchild ignoring SIGTERM and exits
|
||||
// immediately; timeout escalates to SIGKILL and prevents grandchild from writing sentinel file.
|
||||
{
|
||||
Void::FileSystem::TempDir tmp{"vbs_proc_"};
|
||||
const auto sentinel = tmp / "grandchild_escaped.txt";
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = "/bin/sh";
|
||||
req.arguments = {"-c", "sh -c 'trap \"\" TERM; sleep 1.5; echo escaped > \"" +
|
||||
sentinel.string() + "\"' >/dev/null 2>&1 & exit 0"};
|
||||
req.timeout = std::chrono::milliseconds{180};
|
||||
req.kill_grace = std::chrono::milliseconds{80};
|
||||
auto res = Platform::run_supervised(req);
|
||||
Void::Testing::expect(res.has_value());
|
||||
if (res) {
|
||||
Void::Testing::expect(res->timed_out);
|
||||
Void::Testing::expect(!res->succeeded());
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{300});
|
||||
Void::Testing::expect(!std::filesystem::exists(sentinel));
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test profile_inheritance_and_cycle_rejection() {
|
||||
Profiles p = default_profiles();
|
||||
p.inherit("debug-asan", "debug", {"-fno-omit-frame-pointer"});
|
||||
auto resolved = p.resolve("debug-asan", CompilerFamily::Gcc, "Linux", "x86_64");
|
||||
Void::Testing::expect_eq(resolved.compile_options.size(), std::size_t{3});
|
||||
Void::Testing::expect_eq(resolved.compile_options.at(0), std::string{"-O0"});
|
||||
Void::Testing::expect_eq(resolved.compile_options.at(2),
|
||||
std::string{"-fno-omit-frame-pointer"});
|
||||
|
||||
Profiles cyclic;
|
||||
cyclic.inherit("a", "b");
|
||||
cyclic.inherit("b", "a");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)cyclic.resolve("a", CompilerFamily::Gcc, "Linux", "x86_64"); });
|
||||
|
||||
Profiles missing_parent;
|
||||
missing_parent.inherit("child", "ghost");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)missing_parent.resolve("child", CompilerFamily::Gcc, "Linux", "x86_64"); });
|
||||
}
|
||||
|
||||
Void::Testing::Test snapshot_content_mutations_symlinks_shadowing_and_isolation() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_snap_"};
|
||||
const auto proj = tmp / "project";
|
||||
const auto store = tmp / "store";
|
||||
const auto outside = tmp / "outside_secret.txt";
|
||||
|
||||
write_text_file(outside, "TOP_SECRET");
|
||||
write_text_file(proj / "src" / "main.cpp", "int main() { return 0; }\n");
|
||||
write_text_file(proj / "inc2" / "cfg.hpp", "#define CFG_VAL 1\n");
|
||||
write_text_file(proj / ".env", "API_KEY=do_not_capture\n");
|
||||
write_text_file(proj / ".git" / "config", "[core]\n");
|
||||
std::filesystem::create_directories(proj / "inc1");
|
||||
|
||||
Snapshot::SnapshotOptions opts;
|
||||
opts.project_root = proj;
|
||||
opts.snapshot_store_dir = store;
|
||||
opts.reproducibility_epoch = 0;
|
||||
|
||||
auto snap1 =
|
||||
Snapshot::capture_snapshot(opts, {proj / "src" / "main.cpp"},
|
||||
{proj / "inc1", proj / "inc2"}, {{{"inc1", "inc2"}, "cfg.hpp"}});
|
||||
Void::Testing::expect(snap1.has_value());
|
||||
if (!snap1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Secrets and .git are excluded.
|
||||
Void::Testing::expect(!snap1->entries.contains(".env"));
|
||||
Void::Testing::expect(!snap1->entries.contains(".git/config"));
|
||||
|
||||
// Verify private copy / no hardlinks: distinct inode and nlink == 1.
|
||||
const auto &main_entry = snap1->entries.at("src/main.cpp");
|
||||
auto src_meta = Platform::stat_lstat(proj / "src" / "main.cpp");
|
||||
auto mat_meta = Platform::stat_lstat(main_entry.materialized_path);
|
||||
Void::Testing::expect(src_meta.has_value() && mat_meta.has_value());
|
||||
if (src_meta && mat_meta) {
|
||||
Void::Testing::expect(src_meta->ino != mat_meta->ino);
|
||||
Void::Testing::expect_eq(mat_meta->nlink, std::uint64_t{1});
|
||||
Void::Testing::expect_eq(mat_meta->mtime_sec, std::int64_t{0});
|
||||
}
|
||||
|
||||
// 1. Fresh before edits.
|
||||
auto fresh0 = Snapshot::is_snapshot_fresh(*snap1, opts);
|
||||
Void::Testing::expect(fresh0.has_value() && *fresh0);
|
||||
|
||||
// 2. Same-size edit with restored mtime MUST be detected!
|
||||
auto orig_meta = Platform::stat_lstat(proj / "src" / "main.cpp");
|
||||
write_text_file(proj / "src" / "main.cpp", "int main() { return 1; }\n");
|
||||
(void)Platform::set_canonical_mtime(proj / "src" / "main.cpp", orig_meta->mtime_sec);
|
||||
auto fresh1 = Snapshot::is_snapshot_fresh(*snap1, opts);
|
||||
Void::Testing::expect(fresh1.has_value() && !*fresh1);
|
||||
// Sealed snapshot file was NOT mutated by editing live source!
|
||||
auto sealed_bytes = Void::FileSystem::read_file(main_entry.materialized_path);
|
||||
Void::Testing::expect(sealed_bytes.has_value() &&
|
||||
*sealed_bytes == "int main() { return 0; }\n");
|
||||
|
||||
// 3. Restore main.cpp, then create a shadowing header in earlier include dir inc1!
|
||||
write_text_file(proj / "src" / "main.cpp", "int main() { return 0; }\n");
|
||||
auto fresh2 = Snapshot::is_snapshot_fresh(*snap1, opts);
|
||||
Void::Testing::expect(fresh2.has_value() && *fresh2);
|
||||
|
||||
write_text_file(proj / "inc1" / "cfg.hpp", "#define CFG_VAL 99\n");
|
||||
auto fresh3 = Snapshot::is_snapshot_fresh(*snap1, opts);
|
||||
Void::Testing::expect(fresh3.has_value() && !*fresh3);
|
||||
|
||||
// 4. Symlink escape outside project root must be rejected.
|
||||
std::filesystem::create_symlink(outside, proj / "src" / "escape.hpp");
|
||||
auto esc_snap = Snapshot::capture_snapshot(opts, {proj / "src" / "escape.hpp"}, {});
|
||||
Void::Testing::expect(!esc_snap.has_value());
|
||||
|
||||
// 5. Symlink loop must be rejected.
|
||||
std::filesystem::create_symlink(proj / "src" / "loop_b.hpp", proj / "src" / "loop_a.hpp");
|
||||
std::filesystem::create_symlink(proj / "src" / "loop_a.hpp", proj / "src" / "loop_b.hpp");
|
||||
auto loop_snap = Snapshot::capture_snapshot(opts, {proj / "src" / "loop_a.hpp"}, {});
|
||||
Void::Testing::expect(!loop_snap.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test state_store_cas_corruption_recovery_and_gc() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_state_"};
|
||||
auto store = State::StateStore::open(tmp / ".vbs");
|
||||
Void::Testing::expect(store.has_value());
|
||||
if (!store) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto artifact = tmp / "out.o";
|
||||
write_text_file(artifact, "ELF_OBJECT_BYTES_1");
|
||||
auto blob1 = store->store_blob_from_file(artifact);
|
||||
Void::Testing::expect(blob1.has_value());
|
||||
if (!blob1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Store an unpinned blob to test GC removal.
|
||||
const auto orphan_src = tmp / "orphan.o";
|
||||
write_text_file(orphan_src, "ORPHAN_BYTES");
|
||||
auto orphan_blob = store->store_blob_from_file(orphan_src);
|
||||
Void::Testing::expect(orphan_blob.has_value());
|
||||
|
||||
// Refuse committing action referencing fake/missing blob.
|
||||
State::ActionSuccessRecord bad_rec;
|
||||
bad_rec.action_key = "bad_key";
|
||||
bad_rec.outputs["x"] = State::BlobRef{std::string(64, 'a'), 10, 0644};
|
||||
Void::Testing::expect(!store->record_action_success(bad_rec).has_value());
|
||||
|
||||
// Commit valid action referencing blob1.
|
||||
State::ActionSuccessRecord good_rec;
|
||||
good_rec.action_key = "good_key";
|
||||
good_rec.profile_identity = "prof1";
|
||||
good_rec.target_name = "app";
|
||||
good_rec.outputs[artifact.string()] = *blob1;
|
||||
Void::Testing::expect(store->record_action_success(good_rec).has_value());
|
||||
|
||||
// Simulate uncommitted staging debris + dead-PID lease.
|
||||
write_text_file(tmp / ".vbs" / "staging" / "partial.stage", "half-written");
|
||||
auto gc_stats = store->gc();
|
||||
Void::Testing::expect(gc_stats.has_value());
|
||||
if (gc_stats) {
|
||||
Void::Testing::expect(gc_stats->removed_blobs >= 1);
|
||||
Void::Testing::expect(gc_stats->retained_blobs >= 1);
|
||||
}
|
||||
Void::Testing::expect(store->verify_blob(blob1->sha256).value_or(false));
|
||||
Void::Testing::expect(!store->verify_blob(orphan_blob->sha256).value_or(true));
|
||||
|
||||
// Corrupt blob1 on disk and verify lookup detects corruption!
|
||||
const auto blob_path = store->cas_blob_path(blob1->sha256);
|
||||
(void)::chmod(blob_path.c_str(), 0644);
|
||||
write_text_file(blob_path, "CORRUPTED_BYTES!!");
|
||||
Void::Testing::expect(!store->verify_blob(blob1->sha256).value_or(true));
|
||||
auto lookup = store->lookup_action("good_key");
|
||||
Void::Testing::expect(lookup.has_value() && !lookup->has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test end_to_end_native_frontend_graph_execution_and_archive_member_removal() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_e2e_"};
|
||||
const auto proj = tmp / "app_proj";
|
||||
const auto build_dir = tmp / "build";
|
||||
|
||||
// Notice: NO .git directory exists in `proj` (archive-without-Git requirement!).
|
||||
write_text_file(proj / "build-support" / "Flags.hpp", R"cpp(#pragma once
|
||||
#include <Void/Build.hpp>
|
||||
namespace Helper {
|
||||
void apply(Void::Build::Target t);
|
||||
}
|
||||
)cpp");
|
||||
write_text_file(proj / "build-support" / "Flags.cpp", R"cpp(#include "Flags.hpp"
|
||||
namespace Helper {
|
||||
void apply(Void::Build::Target t) {
|
||||
t.compile_option("-Wall");
|
||||
}
|
||||
}
|
||||
)cpp");
|
||||
write_text_file(proj / "build.profiles.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void profiles(Void::Build::Profiles &p) {
|
||||
p = Void::Build::default_profiles();
|
||||
p.inherit("fast", "release", {"-DFAST_MODE=1"});
|
||||
}
|
||||
)cpp");
|
||||
write_text_file(proj / "build.cpp", R"cpp(#include "build-support/Flags.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
// Deliberate stdout noise to verify result channel isolation!
|
||||
std::cout << "noisy user diagnostic that must not break JSON protocol\n";
|
||||
|
||||
auto gen = project.custom_action("gen_header");
|
||||
gen.command({"/bin/sh", "-c", "mkdir -p \"$1\" && printf '#pragma once\\ninline int gen_val(){return 40;}\\n' > \"$1/generated.hpp\"",
|
||||
"sh", "$GEN_DIR"})
|
||||
.outputs({"generated.hpp"});
|
||||
|
||||
auto priv_lib = project.static_library("priv_math");
|
||||
priv_lib.sources(project.glob("src/math/*.cpp"))
|
||||
.include_directory("include", Void::Build::Visibility::Public);
|
||||
|
||||
auto mid_lib = project.static_library("mid");
|
||||
mid_lib.sources({"src/mid.cpp"})
|
||||
.include_directory("include", Void::Build::Visibility::Public)
|
||||
.link(priv_lib, Void::Build::Visibility::Private); // Private static dep must propagate to app link!
|
||||
|
||||
auto app = project.executable("demo");
|
||||
app.sources({"src/main.cpp"})
|
||||
.link(mid_lib)
|
||||
.include_directory("include", Void::Build::Visibility::Private)
|
||||
.include_directory("$GEN/", Void::Build::Visibility::Private)
|
||||
.depends_on(gen);
|
||||
Helper::apply(app);
|
||||
|
||||
auto extra = project.executable("unused_tool");
|
||||
extra.sources({"src/tool.cpp"});
|
||||
}
|
||||
)cpp");
|
||||
|
||||
write_text_file(proj / "include" / "math.hpp", "int add_two();\nint mid_compute();\n");
|
||||
write_text_file(proj / "src" / "math" / "a.cpp", "int add_two() { return 2; }\n");
|
||||
write_text_file(proj / "src" / "math" / "removable.cpp",
|
||||
"extern \"C\" int vbs_removable_symbol() { return 777; }\n");
|
||||
write_text_file(proj / "src" / "mid.cpp",
|
||||
"#include \"math.hpp\"\nint mid_compute() { return add_two(); }\n");
|
||||
write_text_file(proj / "src" / "main.cpp", R"cpp(#include "math.hpp"
|
||||
#include "generated.hpp"
|
||||
#include <iostream>
|
||||
int main() {
|
||||
std::cout << (gen_val() + mid_compute()) << "|" << __FILE__ << "|" << __DATE__ << "|" << __TIME__ << "\n";
|
||||
return 0;
|
||||
}
|
||||
)cpp");
|
||||
write_text_file(proj / "src" / "tool.cpp", "int main() { return 0; }\n");
|
||||
|
||||
// 1. Compile configuration descriptor out-of-process.
|
||||
Config::FrontendOptions fopts;
|
||||
fopts.project_root = proj;
|
||||
fopts.build_root = build_dir;
|
||||
fopts.sdk_include_dir = std::filesystem::path{Bootstrap::sdk_include_dir};
|
||||
fopts.sdk_source_dir = std::filesystem::path{Bootstrap::sdk_source_dir};
|
||||
|
||||
auto compiled1 = Config::compile_descriptor(fopts);
|
||||
Void::Testing::expect(compiled1.has_value());
|
||||
if (!compiled1) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect(compiled1->recompiled);
|
||||
|
||||
// Second compile without edits MUST reuse cached executable!
|
||||
auto compiled2 = Config::compile_descriptor(fopts);
|
||||
Void::Testing::expect(compiled2.has_value());
|
||||
if (compiled2) {
|
||||
Void::Testing::expect(!compiled2->recompiled);
|
||||
}
|
||||
|
||||
// Editing included helper header MUST trigger recompilation!
|
||||
write_text_file(proj / "build-support" / "Flags.hpp", R"cpp(#pragma once
|
||||
#include <Void/Build.hpp>
|
||||
namespace Helper {
|
||||
// edited comment to verify header depfile invalidation
|
||||
void apply(Void::Build::Target t);
|
||||
}
|
||||
)cpp");
|
||||
auto compiled3 = Config::compile_descriptor(fopts);
|
||||
Void::Testing::expect(compiled3.has_value());
|
||||
if (compiled3) {
|
||||
Void::Testing::expect(compiled3->recompiled);
|
||||
}
|
||||
|
||||
// 2. Discover custom inherited profiles and evaluate for "fast" profile.
|
||||
auto discovered_profiles = Config::discover_profiles(*compiled3, fopts);
|
||||
Void::Testing::expect(discovered_profiles.has_value());
|
||||
if (!discovered_profiles) {
|
||||
return;
|
||||
}
|
||||
auto ctx = discovered_profiles->resolve("fast", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, build_dir / ".vbs" / "probes");
|
||||
Void::Testing::expect(tc.has_value());
|
||||
if (!tc) {
|
||||
return;
|
||||
}
|
||||
auto desc = Config::evaluate_project(*compiled3, ctx, fopts);
|
||||
Void::Testing::expect(desc.has_value());
|
||||
if (!desc) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace $GEN_DIR placeholder in custom_action command with profile gen dir for test.
|
||||
const auto gen_dir = build_dir / "profiles" / "fast" / "gen";
|
||||
for (auto &t : desc->targets) {
|
||||
for (auto &arg : t.command_argv) {
|
||||
if (arg == "$GEN_DIR") {
|
||||
arg = gen_dir.string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Capture immutable snapshot + lower graph + execute ONLY target "demo"!
|
||||
Snapshot::SnapshotOptions sopts;
|
||||
sopts.project_root = proj;
|
||||
sopts.snapshot_store_dir = build_dir / ".vbs" / "snapshots";
|
||||
sopts.reproducibility_epoch = 0;
|
||||
auto snap = Snapshot::capture_snapshot(sopts, {}, {proj / "src", proj / "include"});
|
||||
Void::Testing::expect(snap.has_value());
|
||||
if (!snap) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graph::GraphLowerOptions gopts;
|
||||
gopts.project_root = proj;
|
||||
gopts.build_root = build_dir;
|
||||
gopts.snapshot = &(*snap);
|
||||
auto graph = Graph::lower_project_graph(*desc, *tc, gopts);
|
||||
Void::Testing::expect(graph.has_value());
|
||||
if (!graph) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Graph contains ALL configured targets (including unused_tool for compdb!),
|
||||
// while executing selected target "demo" skips unused_tool!
|
||||
Void::Testing::expect_eq(graph->targets.size(), std::size_t{5});
|
||||
|
||||
auto state = State::StateStore::open(build_dir / ".vbs");
|
||||
Void::Testing::expect(state.has_value());
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
||||
Execution::ExecutionOptions eopts;
|
||||
eopts.jobs = 2;
|
||||
eopts.selected_targets = {"demo"};
|
||||
auto rep1 = Execution::execute_graph(*graph, *state, eopts);
|
||||
Void::Testing::expect(rep1.has_value() && rep1->succeeded);
|
||||
if (!rep1) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect(rep1->executed_count > 0);
|
||||
Void::Testing::expect(
|
||||
!std::filesystem::exists(build_dir / "profiles" / "fast" / "out" / "bin" / "unused_tool"));
|
||||
|
||||
// Run built demo executable and verify deterministic output & mapped __FILE__ path!
|
||||
const auto demo_bin = build_dir / "profiles" / "fast" / "out" / "bin" / "demo";
|
||||
Platform::ProcessRequest run_demo;
|
||||
run_demo.executable = demo_bin;
|
||||
auto demo_out = Platform::run_supervised(run_demo);
|
||||
Void::Testing::expect(demo_out.has_value() && demo_out->succeeded());
|
||||
if (demo_out) {
|
||||
Void::Testing::expect(demo_out->stdout_data.starts_with("42|"));
|
||||
// __FILE__ was remapped from snapshot path back to logical project path!
|
||||
Void::Testing::expect(demo_out->stdout_data.find(proj.string()) != std::string::npos);
|
||||
Void::Testing::expect(demo_out->stdout_data.find("snapshots/trees") == std::string::npos);
|
||||
// SOURCE_DATE_EPOCH=0 produces deterministic Jan 1 1970|00:00:00!
|
||||
Void::Testing::expect(demo_out->stdout_data.find("1970|00:00:00") != std::string::npos);
|
||||
}
|
||||
|
||||
// 4. Warm no-op rebuild must execute ZERO actions and hit cache for all!
|
||||
auto rep2 = Execution::execute_graph(*graph, *state, eopts);
|
||||
Void::Testing::expect(rep2.has_value() && rep2->succeeded);
|
||||
if (rep2) {
|
||||
Void::Testing::expect_eq(rep2->executed_count, std::size_t{0});
|
||||
Void::Testing::expect_eq(rep2->cached_count, rep2->total_selected);
|
||||
}
|
||||
|
||||
// 5. Delete src/math/removable.cpp and rebuild: verify symbol disappears from libpriv_math.a!
|
||||
std::filesystem::remove(proj / "src" / "math" / "removable.cpp");
|
||||
auto snap2 = Snapshot::capture_snapshot(sopts, {}, {proj / "src", proj / "include"});
|
||||
Void::Testing::expect(snap2.has_value());
|
||||
gopts.snapshot = &(*snap2);
|
||||
auto graph2 = Graph::lower_project_graph(*desc, *tc, gopts);
|
||||
Void::Testing::expect(graph2.has_value());
|
||||
auto rep3 = Execution::execute_graph(*graph2, *state, eopts);
|
||||
Void::Testing::expect(rep3.has_value() && rep3->succeeded);
|
||||
|
||||
const auto archive_path = build_dir / "profiles" / "fast" / "out" / "libpriv_math.a";
|
||||
Platform::ProcessRequest nm_req;
|
||||
nm_req.executable = "nm";
|
||||
nm_req.arguments = {archive_path.string()};
|
||||
auto nm_out = Platform::run_supervised(nm_req);
|
||||
Void::Testing::expect(nm_out.has_value() && nm_out->succeeded());
|
||||
if (nm_out) {
|
||||
Void::Testing::expect(nm_out->stdout_data.find("vbs_removable_symbol") ==
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
@@ -30,14 +30,14 @@ foreach(profile IN ITEMS debug release)
|
||||
expect_json(-O3 profile compile_options 0)
|
||||
expect_json(-DNDEBUG profile compile_options 1)
|
||||
endif()
|
||||
expect_json(vbs_sdk targets 0 name)
|
||||
expect_json(VoidBuildSdk targets 0 name)
|
||||
expect_json(static_library targets 0 kind)
|
||||
expect_json(file targets 0 sources 0 kind)
|
||||
expect_json(src/build.cpp targets 0 sources 0 path)
|
||||
expect_json(src/Build.cpp targets 0 sources 0 path)
|
||||
expect_json(public targets 0 include_directories 0 visibility)
|
||||
expect_json(vbs targets 1 name)
|
||||
expect_json(executable targets 1 kind)
|
||||
expect_json(vbs_sdk targets 1 links 0 target)
|
||||
expect_json(VoidBuildSdk targets 1 links 0 target)
|
||||
expect_json(private targets 1 links 0 visibility)
|
||||
expect_json(VoidLibrary targets 1 links 1 dependency)
|
||||
expect_json(Void::Configuration targets 1 links 1 target)
|
||||
|
||||
+17
-13
@@ -1,14 +1,16 @@
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <vbs/build.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
Void::Testing::Test example_uses_runtime_compiler() {
|
||||
vbs::Profiles definitions;
|
||||
Void::Build::Profiles definitions;
|
||||
profiles(definitions);
|
||||
vbs::Project gcc{definitions.resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
vbs::Project clang{definitions.resolve("debug", vbs::CompilerFamily::clang, "linux", "x86_64")};
|
||||
Void::Build::Project gcc{
|
||||
definitions.resolve("debug", Void::Build::CompilerFamily::Gcc, "linux", "x86_64")};
|
||||
Void::Build::Project clang{
|
||||
definitions.resolve("debug", Void::Build::CompilerFamily::Clang, "linux", "x86_64")};
|
||||
build(gcc);
|
||||
build(clang);
|
||||
for (std::size_t index = 0; index < gcc.targets().size(); ++index) {
|
||||
@@ -24,11 +26,12 @@ Void::Testing::Test example_uses_runtime_compiler() {
|
||||
}
|
||||
|
||||
Void::Testing::Test example_profile_options_are_separate() {
|
||||
vbs::Profiles definitions;
|
||||
Void::Build::Profiles definitions;
|
||||
profiles(definitions);
|
||||
vbs::Project debug{definitions.resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
vbs::Project release{
|
||||
definitions.resolve("release", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
Void::Build::Project debug{
|
||||
definitions.resolve("debug", Void::Build::CompilerFamily::Gcc, "linux", "x86_64")};
|
||||
Void::Build::Project release{
|
||||
definitions.resolve("release", Void::Build::CompilerFamily::Gcc, "linux", "x86_64")};
|
||||
build(debug);
|
||||
build(release);
|
||||
Void::Testing::expect(
|
||||
@@ -41,14 +44,15 @@ Void::Testing::Test example_profile_options_are_separate() {
|
||||
}
|
||||
|
||||
Void::Testing::Test example_records_sources_links_and_pin() {
|
||||
vbs::Project project{
|
||||
vbs::default_profiles().resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
Void::Build::Project project{Void::Build::default_profiles().resolve(
|
||||
"debug", Void::Build::CompilerFamily::Gcc, "linux", "x86_64")};
|
||||
build(project);
|
||||
Void::Testing::expect_eq(project.targets().size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(project.targets().at(0).name, std::string{"vbs_sdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(0).name, std::string{"VoidBuildSdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(0).sources.at(0).path,
|
||||
std::string{"src/build.cpp"});
|
||||
Void::Testing::expect_eq(project.targets().at(1).links.at(0).target, std::string{"vbs_sdk"});
|
||||
std::string{"src/Build.cpp"});
|
||||
Void::Testing::expect_eq(project.targets().at(1).links.at(0).target,
|
||||
std::string{"VoidBuildSdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(1).links.at(1).target,
|
||||
std::string{"Void::Configuration"});
|
||||
Void::Testing::expect_eq(project.dependencies().at(0).revision,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,318 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Registry/HttpServer.hpp>
|
||||
#include <Void/Build/Registry/RegistryService.hpp>
|
||||
#include <Void/Build/Util/Sha256.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 <fstream>
|
||||
|
||||
using namespace Void::Build;
|
||||
using namespace Void::Build::Registry;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string extract_session_cookie(const std::vector<std::string> &set_cookies) {
|
||||
for (const auto &sc : set_cookies) {
|
||||
if (sc.starts_with("vbs_session=")) {
|
||||
const auto semi = sc.find(';');
|
||||
return sc.substr(0, semi);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string extract_json_str(std::string_view json, const std::string &key) {
|
||||
auto parsed = Void::Json::Strict::parse(json);
|
||||
if (!parsed)
|
||||
return {};
|
||||
const auto *obj = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
||||
if (!obj)
|
||||
return {};
|
||||
const auto it = obj->find(key);
|
||||
if (it == obj->end())
|
||||
return {};
|
||||
const auto *s = std::get_if<std::string>(&it->second.value);
|
||||
return s ? *s : std::string{};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test registry_rbac_immutability_csrf_xss_web_and_backup_restore() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_reg_"};
|
||||
RegistryConfig cfg;
|
||||
cfg.data_dir = tmp / "data";
|
||||
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
||||
cfg.bind_address = "127.0.0.1";
|
||||
cfg.port = 0; // Ephemeral port!
|
||||
cfg.bootstrap_admin_user = "admin";
|
||||
cfg.bootstrap_admin_password = "admin_secret_password";
|
||||
|
||||
auto svc = RegistryService::open(cfg);
|
||||
Void::Testing::expect(svc.has_value());
|
||||
if (!svc)
|
||||
return;
|
||||
|
||||
Void::Testing::expect(
|
||||
(*svc)->create_user("pub_alice", "alice_pass", Role::Publisher).has_value());
|
||||
Void::Testing::expect((*svc)->create_user("read_bob", "bob_pass", Role::Reader).has_value());
|
||||
auto alice_tok = (*svc)->create_token("pub_alice", "ci", {"read", "publish"});
|
||||
auto bob_tok = (*svc)->create_token("read_bob", "ro", {"read"});
|
||||
Void::Testing::expect(alice_tok.has_value() && bob_tok.has_value());
|
||||
if (!alice_tok || !bob_tok)
|
||||
return;
|
||||
|
||||
Void::Testing::expect((*svc)->start_http().has_value());
|
||||
const auto port = (*svc)->bound_port();
|
||||
Void::Testing::expect(port > 0);
|
||||
|
||||
// 1. Static web UI assets served with security headers; path traversal blocked!
|
||||
auto idx = send_loopback_http(port, "GET", "/");
|
||||
Void::Testing::expect(idx.has_value() && idx->status == 200);
|
||||
if (idx) {
|
||||
Void::Testing::expect(idx->headers.contains("content-security-policy"));
|
||||
Void::Testing::expect_eq(idx->headers.at("x-frame-options"), std::string{"DENY"});
|
||||
Void::Testing::expect(idx->body.find("VoidBuildSystem Registry") != std::string::npos);
|
||||
}
|
||||
auto trav = send_loopback_http(port, "GET", "/../CMakeLists.txt");
|
||||
Void::Testing::expect(trav.has_value() && trav->status == 403);
|
||||
|
||||
// 2. Build a valid deterministic package tar and publish as Publisher Alice.
|
||||
const auto pkg_src = tmp / "pkg_src";
|
||||
(void)Platform::atomic_write_file(pkg_src / "build.cpp",
|
||||
"void build(Void::Build::Project&){}\n", false);
|
||||
const auto tar1 = tmp / "p1.tar";
|
||||
auto sha1 = Package::create_source_package(pkg_src, tar1, 0);
|
||||
Void::Testing::expect(sha1.has_value());
|
||||
auto bytes1 = Void::FileSystem::read_file(tar1);
|
||||
Void::Testing::expect(bytes1.has_value());
|
||||
if (!sha1 || !bytes1)
|
||||
return;
|
||||
|
||||
// Reader Bob CANNOT publish (403)!
|
||||
auto bob_pub = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *bob_tok}, {"X-Content-SHA256", *sha1}}, *bytes1);
|
||||
Void::Testing::expect(bob_pub.has_value() && bob_pub->status == 403);
|
||||
|
||||
// Wrong SHA-256 rejected (400)!
|
||||
auto bad_sha = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", std::string(64, '0')}},
|
||||
*bytes1);
|
||||
Void::Testing::expect(bad_sha.has_value() && bad_sha->status == 400);
|
||||
|
||||
// Malicious non-tar / traversal upload rejected (422)!
|
||||
auto bad_tar =
|
||||
send_loopback_http(port, "PUT", "/api/v1/packages/demo-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok}}, "not a valid tar archive");
|
||||
Void::Testing::expect(bad_tar.has_value() && bad_tar->status == 422);
|
||||
|
||||
// Valid private package publish by Alice -> 201 Created!
|
||||
auto pub_ok = send_loopback_http(port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok},
|
||||
{"X-Content-SHA256", *sha1},
|
||||
{"X-Package-Private", "true"},
|
||||
{"X-Package-Description", "<script>alert('xss')</script>"}},
|
||||
*bytes1);
|
||||
Void::Testing::expect(pub_ok.has_value() && pub_ok->status == 201);
|
||||
|
||||
// Unauthenticated access to private package MUST fail (401)!
|
||||
auto anon_priv = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg");
|
||||
Void::Testing::expect(anon_priv.has_value() && anon_priv->status == 401);
|
||||
auto anon_dl = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg/1.0.0/download");
|
||||
Void::Testing::expect(anon_dl.has_value() && anon_dl->status == 401);
|
||||
|
||||
// Idempotent same-bytes republish -> 200 OK!
|
||||
auto idemp = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", *sha1}}, *bytes1);
|
||||
Void::Testing::expect(idemp.has_value() && idemp->status == 200);
|
||||
|
||||
// Different bytes for SAME immutable release -> 409 Conflict!
|
||||
(void)Platform::atomic_write_file(pkg_src / "extra.txt", "changed", false);
|
||||
const auto tar2 = tmp / "p2.tar";
|
||||
auto sha2 = Package::create_source_package(pkg_src, tar2, 0);
|
||||
auto bytes2 = Void::FileSystem::read_file(tar2);
|
||||
auto conflict = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/secret-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok}, {"X-Content-SHA256", *sha2}}, *bytes2);
|
||||
Void::Testing::expect(conflict.has_value() && conflict->status == 409);
|
||||
|
||||
// 3. Browser session login (HttpOnly cookie) + CSRF rejection without header + valid CSRF yank!
|
||||
auto login = send_loopback_http(
|
||||
port, "POST", "/api/v1/auth/login", {{"Content-Type", "application/json"}},
|
||||
"{\"username\":\"admin\",\"password\":\"admin_secret_password\"}");
|
||||
Void::Testing::expect(login.has_value() && login->status == 200);
|
||||
if (!login)
|
||||
return;
|
||||
const auto cookie = extract_session_cookie(login->set_cookies);
|
||||
const auto csrf = extract_json_str(login->body, "csrf_token");
|
||||
Void::Testing::expect(!cookie.empty() && !csrf.empty());
|
||||
Void::Testing::expect(login->set_cookies[0].find("HttpOnly") != std::string::npos);
|
||||
Void::Testing::expect(login->set_cookies[0].find("SameSite=Strict") != std::string::npos);
|
||||
|
||||
// Mutation with session cookie WITHOUT X-CSRF-Token -> 403 CSRF rejected!
|
||||
auto no_csrf = send_loopback_http(port, "POST", "/api/v1/packages/secret-pkg/1.0.0/yank",
|
||||
{{"Cookie", cookie}}, "{\"yanked\":true}");
|
||||
Void::Testing::expect(no_csrf.has_value() && no_csrf->status == 403);
|
||||
|
||||
// Mutation WITH valid X-CSRF-Token -> 200 OK!
|
||||
auto with_csrf =
|
||||
send_loopback_http(port, "POST", "/api/v1/packages/secret-pkg/1.0.0/yank",
|
||||
{{"Cookie", cookie}, {"X-CSRF-Token", csrf}}, "{\"yanked\":true}");
|
||||
Void::Testing::expect(with_csrf.has_value() && with_csrf->status == 200);
|
||||
|
||||
// Audit log contains zero secrets (no passwords or bearer tokens)!
|
||||
auto audit = send_loopback_http(port, "GET", "/api/v1/audit", {{"Cookie", cookie}});
|
||||
Void::Testing::expect(audit.has_value() && audit->status == 200);
|
||||
if (audit) {
|
||||
Void::Testing::expect(audit->body.find("admin_secret_password") == std::string::npos);
|
||||
Void::Testing::expect(audit->body.find(*alice_tok) == std::string::npos);
|
||||
}
|
||||
|
||||
// 4. Consistent backup & restore into a brand-new registry instance preserves releases &
|
||||
// download!
|
||||
const auto backup_dir = tmp / "backup";
|
||||
Void::Testing::expect((*svc)->backup_to(backup_dir).has_value());
|
||||
(*svc)->stop_http();
|
||||
|
||||
RegistryConfig cfg2 = cfg;
|
||||
cfg2.data_dir = tmp / "restored_data";
|
||||
cfg2.bootstrap_admin_password.clear();
|
||||
auto svc2 = RegistryService::open(cfg2);
|
||||
Void::Testing::expect(svc2.has_value());
|
||||
if (svc2) {
|
||||
Void::Testing::expect((*svc2)->restore_from(backup_dir).has_value());
|
||||
Void::Testing::expect((*svc2)->start_http().has_value());
|
||||
auto dl = send_loopback_http((*svc2)->bound_port(), "GET",
|
||||
"/api/v1/packages/secret-pkg/1.0.0/download",
|
||||
{{"Authorization", "Bearer " + *alice_tok}});
|
||||
Void::Testing::expect(dl.has_value() && dl->status == 200 && dl->body == *bytes1);
|
||||
(*svc2)->stop_http();
|
||||
}
|
||||
}
|
||||
|
||||
// End-to-end live client <-> server test: `vbs publish` -> `vbs deps resolve` -> `vbs build
|
||||
// --locked`!
|
||||
Void::Testing::Test cli_publish_deps_resolve_and_locked_build_against_live_registry() {
|
||||
const auto vbs_bin = std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs";
|
||||
Void::Testing::expect(std::filesystem::exists(vbs_bin));
|
||||
if (!std::filesystem::exists(vbs_bin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_reg_e2e_"};
|
||||
RegistryConfig cfg;
|
||||
cfg.data_dir = tmp / "reg_data";
|
||||
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
||||
cfg.bind_address = "127.0.0.1";
|
||||
cfg.port = 0;
|
||||
cfg.bootstrap_admin_user = "admin";
|
||||
cfg.bootstrap_admin_password = "admin_e2e_password";
|
||||
|
||||
auto svc = RegistryService::open(cfg);
|
||||
Void::Testing::expect(svc.has_value());
|
||||
if (!svc)
|
||||
return;
|
||||
Void::Testing::expect((*svc)->create_user("ci_pub", "ci_pass", Role::Publisher).has_value());
|
||||
auto tok = (*svc)->create_token("ci_pub", "publish", {"read", "publish"});
|
||||
Void::Testing::expect(tok.has_value());
|
||||
if (!tok)
|
||||
return;
|
||||
Void::Testing::expect((*svc)->start_http().has_value());
|
||||
const std::string reg_url = "http://127.0.0.1:" + std::to_string((*svc)->bound_port());
|
||||
|
||||
// 1. Create a real CMake library package and publish 1.0.0 and 1.1.0 via `vbs publish` CLI!
|
||||
const auto pkg_dir = tmp / "hello_pkg";
|
||||
(void)Platform::atomic_write_file(pkg_dir / "CMakeLists.txt", R"cmake(
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(hello_pkg LANGUAGES CXX)
|
||||
add_library(hello_pkg STATIC src/hello.cpp)
|
||||
target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
)cmake",
|
||||
false);
|
||||
(void)Platform::atomic_write_file(pkg_dir / "include" / "hello_pkg.hpp",
|
||||
"#pragma once\nint hello_pkg_value();\n", false);
|
||||
(void)Platform::atomic_write_file(
|
||||
pkg_dir / "src" / "hello.cpp",
|
||||
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 10; }\n", false);
|
||||
|
||||
Platform::ProcessRequest pub1;
|
||||
pub1.executable = vbs_bin;
|
||||
pub1.arguments = {"publish", "--project", pkg_dir.string(), "--registry",
|
||||
reg_url, "--name", "hello-pkg", "--version",
|
||||
"1.0.0", "--description", "Live E2E package"};
|
||||
pub1.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
||||
auto r1 = Platform::run_supervised(pub1);
|
||||
Void::Testing::expect(r1.has_value() && r1->succeeded());
|
||||
|
||||
// Publish 1.1.0 returning 42 so solver (^1.0) selects 1.1.0!
|
||||
(void)Platform::atomic_write_file(
|
||||
pkg_dir / "src" / "hello.cpp",
|
||||
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 42; }\n", false);
|
||||
Platform::ProcessRequest pub2 = pub1;
|
||||
pub2.arguments[8] = "1.1.0";
|
||||
auto r2 = Platform::run_supervised(pub2);
|
||||
Void::Testing::expect(r2.has_value() && r2->succeeded());
|
||||
|
||||
// 2. Create a consumer project declaring `.package("hello-pkg", "^1.0").registry(reg_url)`.
|
||||
const auto cons_dir = tmp / "consumer";
|
||||
const auto cons_build = tmp / "consumer_build";
|
||||
(void)Platform::atomic_write_file(cons_dir / "build.cpp",
|
||||
"#include <Void/Build.hpp>\n"
|
||||
"void build(Void::Build::Project &p) {\n"
|
||||
" auto dep = p.dependency(\"hello\")\n"
|
||||
" .package(\"hello-pkg\", \"^1.0\")\n"
|
||||
" .registry(\"" +
|
||||
reg_url +
|
||||
"\");\n"
|
||||
" p.executable(\"reg_consumer\")\n"
|
||||
" .sources({\"src/main.cpp\"})\n"
|
||||
" .link(dep.target(\"hello_pkg\"));\n"
|
||||
"}\n",
|
||||
false);
|
||||
(void)Platform::atomic_write_file(
|
||||
cons_dir / "src" / "main.cpp",
|
||||
"#include \"hello_pkg.hpp\"\nint main() { return hello_pkg_value() == 42 ? 0 : 1; }\n",
|
||||
false);
|
||||
|
||||
// 3. Resolve dependencies into vbs.lock against the live registry!
|
||||
Platform::ProcessRequest deps_req;
|
||||
deps_req.executable = vbs_bin;
|
||||
deps_req.arguments = {"deps", "resolve", "--project", cons_dir.string(),
|
||||
"--build-dir", cons_build.string()};
|
||||
deps_req.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
||||
auto deps_res = Platform::run_supervised(deps_req);
|
||||
Void::Testing::expect(deps_res.has_value() && deps_res->succeeded());
|
||||
|
||||
auto lock_text = Void::FileSystem::read_file(cons_dir / "vbs.lock");
|
||||
Void::Testing::expect(lock_text.has_value());
|
||||
if (lock_text) {
|
||||
Void::Testing::expect(lock_text->find("\"version\":\"1.1.0\"") != std::string::npos);
|
||||
Void::Testing::expect(lock_text->find("\"source_kind\":\"package\"") != std::string::npos);
|
||||
Void::Testing::expect(lock_text->find(*tok) == std::string::npos); // Zero token leaks!
|
||||
}
|
||||
|
||||
// 4. Build in --locked mode and execute the consumer binary!
|
||||
Platform::ProcessRequest bld_req;
|
||||
bld_req.executable = vbs_bin;
|
||||
bld_req.arguments = {"build", "--project", cons_dir.string(),
|
||||
"--build-dir", cons_build.string(), "--locked"};
|
||||
auto bld_res = Platform::run_supervised(bld_req);
|
||||
Void::Testing::expect(bld_res.has_value() && bld_res->succeeded());
|
||||
|
||||
Platform::ProcessRequest run_req;
|
||||
run_req.executable = cons_build / "profiles" / "debug" / "out" / "bin" / "reg_consumer";
|
||||
auto run_res = Platform::run_supervised(run_req);
|
||||
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
|
||||
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
+74
-61
@@ -1,15 +1,16 @@
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <vbs/build.hpp>
|
||||
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace {
|
||||
vbs::ProfileContext context() {
|
||||
return vbs::default_profiles().resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64");
|
||||
Void::Build::ProfileContext context() {
|
||||
return Void::Build::default_profiles().resolve("debug", Void::Build::CompilerFamily::Gcc,
|
||||
"linux", "x86_64");
|
||||
}
|
||||
constexpr auto revision = "9931c5ffc4844a5e09e1b1db35b3d29c5097c3a5";
|
||||
using Json = Void::Json::Strict::Value;
|
||||
@@ -23,59 +24,64 @@ std::string text(const Json &value) { return std::get<std::string>(value.value);
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test default_profiles_and_overrides() {
|
||||
const auto profiles = vbs::default_profiles();
|
||||
const auto debug = profiles.resolve("debug", vbs::CompilerFamily::clang, "linux", "aarch64");
|
||||
const auto release = profiles.resolve("release", vbs::CompilerFamily::gcc, "linux", "x86_64");
|
||||
const auto profiles = Void::Build::default_profiles();
|
||||
const auto debug =
|
||||
profiles.resolve("debug", Void::Build::CompilerFamily::Clang, "linux", "aarch64");
|
||||
const auto release =
|
||||
profiles.resolve("release", Void::Build::CompilerFamily::Gcc, "linux", "x86_64");
|
||||
Void::Testing::expect_eq(profiles.records().size(), std::size_t{2});
|
||||
Void::Testing::expect(debug.compiler == vbs::CompilerFamily::clang);
|
||||
Void::Testing::expect(debug.compiler == Void::Build::CompilerFamily::Clang);
|
||||
Void::Testing::expect_eq(debug.architecture, std::string{"aarch64"});
|
||||
Void::Testing::expect_eq(debug.compile_options.at(0), std::string{"-O0"});
|
||||
Void::Testing::expect_eq(release.compile_options.at(0), std::string{"-O3"});
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_invalid_profiles() {
|
||||
auto profiles = vbs::default_profiles();
|
||||
auto profiles = Void::Build::default_profiles();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add("debug"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add("bad", {""}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] {
|
||||
(void)profiles.resolve("unknown", Void::Build::CompilerFamily::Gcc, "linux", "x86_64");
|
||||
});
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)profiles.resolve("unknown", vbs::CompilerFamily::gcc, "linux", "x86_64"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([] { (void)vbs::parse_compiler("msvc"); });
|
||||
[] { (void)Void::Build::parse_compiler("msvc"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)profiles.resolve("debug", vbs::CompilerFamily::gcc, "", "x86_64"); });
|
||||
[&] { (void)profiles.resolve("debug", Void::Build::CompilerFamily::Gcc, "", "x86_64"); });
|
||||
}
|
||||
|
||||
Void::Testing::Test declaration_records_and_visibility() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto library = project.static_library("library");
|
||||
library.sources({"one.cpp", "two.cpp"})
|
||||
.include_directory("include", vbs::Visibility::public_)
|
||||
.include_directory("include", Void::Build::Visibility::Public)
|
||||
.compile_option("-Wall");
|
||||
auto executable = project.executable("app");
|
||||
executable.link(library).link(library, vbs::Visibility::interface_);
|
||||
Void::Testing::expect(library.record().kind == vbs::TargetKind::static_library);
|
||||
executable.link(library).link(library, Void::Build::Visibility::Interface);
|
||||
Void::Testing::expect(library.record().kind == Void::Build::TargetKind::StaticLibrary);
|
||||
Void::Testing::expect_eq(library.record().sources.size(), std::size_t{2});
|
||||
Void::Testing::expect(library.record().include_directories.at(0).visibility ==
|
||||
vbs::Visibility::public_);
|
||||
Void::Testing::expect(executable.record().links.at(0).visibility == vbs::Visibility::private_);
|
||||
Void::Build::Visibility::Public);
|
||||
Void::Testing::expect(executable.record().links.at(0).visibility ==
|
||||
Void::Build::Visibility::Private);
|
||||
Void::Testing::expect(executable.record().links.at(1).visibility ==
|
||||
vbs::Visibility::interface_);
|
||||
Void::Build::Visibility::Interface);
|
||||
}
|
||||
|
||||
Void::Testing::Test sources_are_symbolic() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto target = project.executable("symbolic");
|
||||
target.sources({"missing/../literal.cpp"}).sources(project.glob("nonexistent/**/*.cpp"));
|
||||
Void::Testing::expect_eq(target.record().sources.at(0).path,
|
||||
std::string{"missing/../literal.cpp"});
|
||||
Void::Testing::expect(target.record().sources.at(0).kind == vbs::SourceKind::file);
|
||||
Void::Testing::expect(target.record().sources.at(1).kind == vbs::SourceKind::glob);
|
||||
Void::Testing::expect(target.record().sources.at(0).kind == Void::Build::SourceKind::File);
|
||||
Void::Testing::expect(target.record().sources.at(1).kind == Void::Build::SourceKind::Glob);
|
||||
Void::Testing::expect_eq(target.record().sources.at(1).path,
|
||||
std::string{"nonexistent/**/*.cpp"});
|
||||
}
|
||||
|
||||
Void::Testing::Test handles_survive_record_growth() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto library = project.static_library("first");
|
||||
auto dependency = project.dependency("original");
|
||||
const auto imported = dependency.target("Original::Library");
|
||||
@@ -83,7 +89,7 @@ Void::Testing::Test handles_survive_record_growth() {
|
||||
(void)project.executable("target" + std::to_string(i));
|
||||
(void)project.dependency("dependency" + std::to_string(i));
|
||||
}
|
||||
dependency.git("https://example.invalid/library.git", vbs::Commit{revision}).cmake();
|
||||
dependency.git("https://example.invalid/library.git", Void::Build::Commit{revision}).cmake();
|
||||
library.compile_option("-Wextra");
|
||||
auto app = project.executable("last");
|
||||
app.link(library).link(imported);
|
||||
@@ -95,8 +101,8 @@ Void::Testing::Test handles_survive_record_growth() {
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_cross_project_links() {
|
||||
vbs::Project first{context()};
|
||||
vbs::Project second{context()};
|
||||
Void::Build::Project first{context()};
|
||||
Void::Build::Project second{context()};
|
||||
auto app = first.executable("app");
|
||||
auto other = second.static_library("other");
|
||||
auto imported = second.dependency("remote").target("Remote::Library");
|
||||
@@ -106,18 +112,18 @@ Void::Testing::Test rejects_cross_project_links() {
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_expired_handles_and_owner_moves() {
|
||||
static_assert(!std::is_move_constructible_v<vbs::Project>);
|
||||
static_assert(!std::is_copy_constructible_v<vbs::Project>);
|
||||
std::optional<vbs::Target> target;
|
||||
std::optional<vbs::Dependency> dependency;
|
||||
std::optional<vbs::ImportedTarget> imported;
|
||||
static_assert(!std::is_move_constructible_v<Void::Build::Project>);
|
||||
static_assert(!std::is_copy_constructible_v<Void::Build::Project>);
|
||||
std::optional<Void::Build::Target> target;
|
||||
std::optional<Void::Build::Dependency> dependency;
|
||||
std::optional<Void::Build::ImportedTarget> imported;
|
||||
{
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
target = project.executable("expired");
|
||||
dependency = project.dependency("expired");
|
||||
imported = dependency->target("Expired::Target");
|
||||
}
|
||||
vbs::Project replacement{context()};
|
||||
Void::Build::Project replacement{context()};
|
||||
auto app = replacement.executable("new");
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { target->compile_option("-g"); });
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { dependency->cmake(); });
|
||||
@@ -127,7 +133,7 @@ Void::Testing::Test rejects_expired_handles_and_owner_moves() {
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_empty_and_duplicate_identifiers() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto app = project.executable("app");
|
||||
auto dep = project.dependency("dep");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
@@ -138,50 +144,51 @@ Void::Testing::Test rejects_empty_and_duplicate_identifiers() {
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)dep.target(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.include_directory(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.compile_option(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([] { (void)vbs::SourceSet::file(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[] { (void)Void::Build::SourceSet::file(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.glob(""); });
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_contradictory_providers() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto git = project.dependency("git");
|
||||
git.git("https://example.invalid/repo", vbs::Commit{revision}).cmake();
|
||||
git.git("https://example.invalid/repo", Void::Build::Commit{revision}).cmake();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { git.package("pkg", "^1"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { git.git("url", vbs::Commit{revision}); });
|
||||
[&] { git.git("url", Void::Build::Commit{revision}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { git.cmake(); });
|
||||
auto package = project.dependency("package");
|
||||
package.package("pkg", "^1");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { package.git("url", vbs::Commit{revision}); });
|
||||
[&] { package.git("url", Void::Build::Commit{revision}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { package.cmake(); });
|
||||
auto builder = project.dependency("builder");
|
||||
builder.cmake();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { builder.package("pkg", "^1"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { builder.git("url", vbs::Commit{"main"}); });
|
||||
[&] { builder.git("url", Void::Build::Commit{"main"}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.to_json(); });
|
||||
}
|
||||
|
||||
Void::Testing::Test json_schema_types_and_escaping() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
std::string escaped = "quote\" slash\\ newline\n\r\t";
|
||||
for (char c = 0; c < 32; ++c)
|
||||
escaped += c;
|
||||
auto dep = project.dependency("dependency");
|
||||
dep.git("https://example.invalid/\"repo", vbs::Commit{revision})
|
||||
dep.git("https://example.invalid/\"repo", Void::Build::Commit{revision})
|
||||
.cmake({{"string", escaped},
|
||||
{"literal", "text"},
|
||||
{"bool", false},
|
||||
{"integer", -42},
|
||||
{"maximum", std::numeric_limits<std::int64_t>::max()}});
|
||||
auto library = project.static_library("library");
|
||||
library.sources(vbs::SourceSet::file(escaped))
|
||||
library.sources(Void::Build::SourceSet::file(escaped))
|
||||
.sources(project.glob("src/**/*.cpp"))
|
||||
.include_directory("include", vbs::Visibility::public_)
|
||||
.include_directory("include", Void::Build::Visibility::Public)
|
||||
.link(dep.target("Remote::Library"));
|
||||
auto app = project.executable("app");
|
||||
app.link(library, vbs::Visibility::public_).compile_option(escaped);
|
||||
app.link(library, Void::Build::Visibility::Public).compile_option(escaped);
|
||||
project.dependency("package").package("org/pkg", ">=1.2 <2");
|
||||
const auto json = project.to_json();
|
||||
Void::Testing::expect_eq(json, project.to_json());
|
||||
@@ -215,9 +222,11 @@ Void::Testing::Test json_preserves_valid_utf8() {
|
||||
// Boundary scalar values for every UTF-8 width, including either side of surrogates.
|
||||
const std::string unicode = "ASCII \xc2\x80\xdf\xbf\xe0\xa0\x80\xed\x9f\xbf"
|
||||
"\xee\x80\x80\xef\xbf\xbf\xf0\x90\x80\x80\xf4\x8f\xbf\xbf";
|
||||
vbs::Project project{context()};
|
||||
project.executable(unicode).sources(vbs::SourceSet::file(unicode));
|
||||
project.dependency("unicode").git("url", vbs::Commit{revision}).cmake({{unicode, unicode}});
|
||||
Void::Build::Project project{context()};
|
||||
project.executable(unicode).sources(Void::Build::SourceSet::file(unicode));
|
||||
project.dependency("unicode")
|
||||
.git("url", Void::Build::Commit{revision})
|
||||
.cmake({{unicode, unicode}});
|
||||
const auto json = project.to_json();
|
||||
Void::Testing::expect(json.find(unicode) != std::string::npos);
|
||||
const auto parsed = Void::Json::Strict::parse(json);
|
||||
@@ -240,35 +249,39 @@ Void::Testing::Test json_rejects_malformed_utf8() {
|
||||
"\xff"};
|
||||
for (const auto &bytes : invalid) {
|
||||
const auto malformed = "prefix" + bytes + "suffix";
|
||||
vbs::Project named{context()};
|
||||
Void::Build::Project named{context()};
|
||||
(void)named.executable(bytes);
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)named.to_json(); });
|
||||
|
||||
vbs::Project sourced{context()};
|
||||
sourced.executable("source").sources(vbs::SourceSet::file(malformed));
|
||||
Void::Build::Project sourced{context()};
|
||||
sourced.executable("source").sources(Void::Build::SourceSet::file(malformed));
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)sourced.to_json(); });
|
||||
|
||||
vbs::Project keyed{context()};
|
||||
keyed.dependency("key").git("url", vbs::Commit{revision}).cmake({{malformed, true}});
|
||||
Void::Build::Project keyed{context()};
|
||||
keyed.dependency("key")
|
||||
.git("url", Void::Build::Commit{revision})
|
||||
.cmake({{malformed, true}});
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)keyed.to_json(); });
|
||||
|
||||
vbs::Project valued{context()};
|
||||
valued.dependency("value").git("url", vbs::Commit{revision}).cmake({{"option", malformed}});
|
||||
Void::Build::Project valued{context()};
|
||||
valued.dependency("value")
|
||||
.git("url", Void::Build::Commit{revision})
|
||||
.cmake({{"option", malformed}});
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)valued.to_json(); });
|
||||
|
||||
auto profile = context();
|
||||
profile.compile_options.push_back(malformed);
|
||||
vbs::Project configured{profile};
|
||||
Void::Build::Project configured{profile};
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)configured.to_json(); });
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test independent_projects_and_contexts() {
|
||||
auto initial = context();
|
||||
vbs::Project first{initial};
|
||||
Void::Build::Project first{initial};
|
||||
initial.name = "mutated";
|
||||
vbs::Project second{
|
||||
vbs::default_profiles().resolve("release", vbs::CompilerFamily::clang, "linux", "aarch64")};
|
||||
Void::Build::Project second{Void::Build::default_profiles().resolve(
|
||||
"release", Void::Build::CompilerFamily::Clang, "linux", "aarch64")};
|
||||
first.executable("first").compile_option("-g");
|
||||
Void::Testing::expect_eq(first.context().name, std::string{"debug"});
|
||||
Void::Testing::expect_eq(second.context().name, std::string{"release"});
|
||||
@@ -277,12 +290,12 @@ Void::Testing::Test independent_projects_and_contexts() {
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_option_errors_without_mutation() {
|
||||
vbs::Project project{context()};
|
||||
Void::Build::Project project{context()};
|
||||
auto dep = project.dependency("library");
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { dep.cmake({{"", true}}); });
|
||||
Void::Testing::expect(dep.record().builder.empty());
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[] { (void)vbs::OptionValue{std::numeric_limits<std::uint64_t>::max()}; });
|
||||
dep.cmake({{"enabled", true}}).git("url", vbs::Commit{revision});
|
||||
[] { (void)Void::Build::OptionValue{std::numeric_limits<std::uint64_t>::max()}; });
|
||||
dep.cmake({{"enabled", true}}).git("url", Void::Build::Commit{revision});
|
||||
Void::Testing::expect_eq(dep.record().options.size(), std::size_t{1});
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
#include <SelfHost/VbsSelfHostRecipe.hpp>
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
#include <Void/Build/Install/Installer.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <VoidLibrary/VoidLibraryRecipe.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <sys/stat.h>
|
||||
|
||||
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());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Plan 18: Native non-CMake Void::Testing scanner avoids equal-basename collisions!
|
||||
Void::Testing::Test native_test_registration_generator_avoids_basename_collisions() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_testgen_"};
|
||||
const auto f1 = tmp / "dir_a" / "SameStem.cpp";
|
||||
const auto f2 = tmp / "dir_b" / "SameStem.cpp";
|
||||
write_file(f1, "#include <Void/Testing/Test.hpp>\nVoid::Testing::Test case_alpha() {}\n");
|
||||
write_file(f2, "#include <Void/Testing/Test.hpp>\nVoid::Testing::Test case_beta() {}\n");
|
||||
|
||||
const auto out_dir = tmp / "gen";
|
||||
auto r1 = SelfHost::generate_test_registration_unit(f1, out_dir);
|
||||
auto r2 = SelfHost::generate_test_registration_unit(f2, out_dir);
|
||||
Void::Testing::expect(r1.has_value() && r2.has_value());
|
||||
if (r1 && r2) {
|
||||
Void::Testing::expect(r1->generated_cpp != r2->generated_cpp);
|
||||
Void::Testing::expect_eq(r1->cases.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(r2->cases.size(), std::size_t{1});
|
||||
Void::Testing::expect_eq(r1->cases[0].function_name, std::string{"case_alpha"});
|
||||
Void::Testing::expect_eq(r2->cases[0].function_name, std::string{"case_beta"});
|
||||
}
|
||||
}
|
||||
|
||||
// Plan 18: Strict native VoidLibrary closure + native VBS SDK + native test runner built
|
||||
// completely WITHOUT CMake (trapped cmake shim ahead of PATH!) in a clean stage directory!
|
||||
Void::Testing::Test strict_native_selfhost_voidlibrary_and_sdk_without_cmake() {
|
||||
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
|
||||
Void::Testing::expect(std::filesystem::is_directory(void_src));
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_selfhost_"};
|
||||
const auto stage1_dir = tmp / "stage1";
|
||||
const auto trap_bin = tmp / "trap_bin";
|
||||
|
||||
// Plant a failing trap `cmake` ahead of PATH to prove zero CMake invocation occurs!
|
||||
write_file(
|
||||
trap_bin / "cmake",
|
||||
"#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN STRICT NATIVE STAGE' >&2\nexit 99\n");
|
||||
(void)::chmod((trap_bin / "cmake").c_str(), 0755);
|
||||
|
||||
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, stage1_dir / ".vbs" / "probes");
|
||||
Void::Testing::expect(tc.has_value());
|
||||
if (!tc)
|
||||
return;
|
||||
|
||||
// Declare native VoidLibrary module closure + VoidBuildSdk + native-registered Void::Testing
|
||||
// suite!
|
||||
Project proj{ctx};
|
||||
auto void_libs =
|
||||
Recipes::add_void_library_native(proj, void_src, {"Configuration", "Text", "Testing"});
|
||||
|
||||
const std::filesystem::path vbs_root{Bootstrap::source_dir};
|
||||
auto sdk = proj.static_library("VoidBuildSdk");
|
||||
sdk.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources(SourceSet::file((vbs_root / "src" / "Build.cpp").string()))
|
||||
.sources(SourceSet::file((vbs_root / "src" / "Util" / "Json.cpp").string()))
|
||||
.include_directory((vbs_root / "include").string(), Visibility::Public)
|
||||
.compile_option("-freflection", Visibility::Public);
|
||||
|
||||
// Generate native C++ test registrations for SdkDeclarations.cpp (NO CMake scanner!).
|
||||
const auto test_src = vbs_root / "tests" / "SdkDeclarations.cpp";
|
||||
auto reg = SelfHost::generate_test_registration_unit(test_src, stage1_dir / "gen_tests");
|
||||
Void::Testing::expect(reg.has_value() && reg->cases.size() >= 14);
|
||||
if (!reg)
|
||||
return;
|
||||
|
||||
auto native_tests = proj.executable("stage1_sdk_tests");
|
||||
native_tests.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources(SourceSet::file(test_src.string()))
|
||||
.sources(SourceSet::file(reg->generated_cpp.string()))
|
||||
.link(sdk)
|
||||
.link(void_libs.modules.at("Testing"))
|
||||
.link(void_libs.modules.at("Data"));
|
||||
|
||||
auto desc = Graph::ProjectDescription::from_json(proj.to_json());
|
||||
Void::Testing::expect(desc.has_value());
|
||||
if (!desc)
|
||||
return;
|
||||
|
||||
auto graph = Graph::lower_project_graph(*desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768});
|
||||
Void::Testing::expect(graph.has_value());
|
||||
if (!graph)
|
||||
return;
|
||||
|
||||
auto state = State::StateStore::open(stage1_dir / ".vbs");
|
||||
Void::Testing::expect(state.has_value());
|
||||
if (!state)
|
||||
return;
|
||||
|
||||
auto exec =
|
||||
Execution::execute_graph(*graph, *state, {4, true, true, {"stage1_sdk_tests"}, {}, {}});
|
||||
Void::Testing::expect(exec.has_value() && exec->succeeded);
|
||||
if (!exec || !exec->succeeded)
|
||||
return;
|
||||
|
||||
// Execute the strictly natively-built Void::Testing suite and verify all 14+ cases pass!
|
||||
const auto exe_path = stage1_dir / "profiles" / "debug" / "out" / "bin" / "stage1_sdk_tests";
|
||||
Platform::ProcessRequest run_req;
|
||||
run_req.executable = exe_path;
|
||||
run_req.arguments = {"--no-color"};
|
||||
// Prepend trap_bin to PATH as an extra assertion.
|
||||
if (const char *old_path = std::getenv("PATH")) {
|
||||
run_req.environment.set_vars["PATH"] = trap_bin.string() + ":" + old_path;
|
||||
}
|
||||
auto res = Platform::run_supervised(run_req);
|
||||
Void::Testing::expect(res.has_value() && res->succeeded());
|
||||
if (res) {
|
||||
Void::Testing::expect(res->stdout_data.find("14 tests:") != std::string::npos);
|
||||
}
|
||||
|
||||
// Plan 18 Stage 1 -> Stage 2 isolation: install Stage 1 VoidBuildSdk to a clean prefix,
|
||||
// then in an isolated stage2 directory (with trapped cmake!) compile & run a fresh
|
||||
// stage2 consumer linked ONLY against the installed Stage 1 SDK artifacts!
|
||||
const auto stage1_prefix = tmp / "stage1_prefix";
|
||||
const auto stage2_dir = tmp / "stage2";
|
||||
const auto stage2_src = tmp / "stage2_src";
|
||||
|
||||
// Re-describe installable VoidBuildSdk + public headers matching stage1 output layout.
|
||||
Project stage1_pkg_proj{ctx};
|
||||
auto s1_sdk = stage1_pkg_proj.static_library("VoidBuildSdk");
|
||||
s1_sdk.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources(SourceSet::file((vbs_root / "src" / "Build.cpp").string()))
|
||||
.sources(SourceSet::file((vbs_root / "src" / "Util" / "Json.cpp").string()))
|
||||
.include_directory((vbs_root / "include").string(), Visibility::Public)
|
||||
.compile_option("-freflection", Visibility::Public)
|
||||
.install("lib");
|
||||
stage1_pkg_proj.install_directory((vbs_root / "include").string(), "include");
|
||||
auto s1_pkg_desc = Graph::ProjectDescription::from_json(stage1_pkg_proj.to_json());
|
||||
Void::Testing::expect(s1_pkg_desc.has_value());
|
||||
if (!s1_pkg_desc)
|
||||
return;
|
||||
|
||||
auto s1_pkg_graph =
|
||||
Graph::lower_project_graph(*s1_pkg_desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768});
|
||||
Void::Testing::expect(s1_pkg_graph.has_value());
|
||||
if (!s1_pkg_graph)
|
||||
return;
|
||||
|
||||
// Install the already-built stage1 VoidBuildSdk (at stage1_dir/profiles/debug/out/lib/...)!
|
||||
auto inst_s1 = Install::install_project(
|
||||
*s1_pkg_desc, *s1_pkg_graph,
|
||||
{"VoidBuildSdk", "0.1.0", stage1_prefix, std::nullopt, true, true});
|
||||
Void::Testing::expect(inst_s1.has_value());
|
||||
if (!inst_s1)
|
||||
return;
|
||||
|
||||
// Build stage2 consumer using ONLY stage1_prefix/include + stage1_prefix/lib/libVoidBuildSdk.a!
|
||||
write_file(stage2_src / "stage2_check.cpp", R"cpp(
|
||||
#include <Void/Build.hpp>
|
||||
int main() {
|
||||
auto ctx = Void::Build::default_profiles().resolve(
|
||||
"debug", Void::Build::CompilerFamily::Gcc, "Linux", "x86_64");
|
||||
Void::Build::Project p{ctx};
|
||||
p.executable("hello").sources({"hello.cpp"});
|
||||
const auto json = p.to_json();
|
||||
return json.find("\"hello\"") != std::string::npos ? 0 : 1;
|
||||
}
|
||||
)cpp");
|
||||
|
||||
Project stage2_proj{ctx};
|
||||
Graph::ImportedTargetInterface s1_imported;
|
||||
s1_imported.dependency_name = "stage1_sdk";
|
||||
s1_imported.target_name = "VoidBuildSdk";
|
||||
s1_imported.include_dirs.emplace_back(stage1_prefix / "include", false);
|
||||
s1_imported.compile_options.push_back("-freflection");
|
||||
s1_imported.static_libraries.push_back(stage1_prefix / "lib" / "libVoidBuildSdk.a");
|
||||
|
||||
auto s2_dep = stage2_proj.dependency("stage1_sdk").path(stage1_prefix.string());
|
||||
auto s2_app = stage2_proj.executable("stage2_consumer");
|
||||
s2_app.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources(SourceSet::file((stage2_src / "stage2_check.cpp").string()))
|
||||
.link(s2_dep.target("VoidBuildSdk"));
|
||||
|
||||
auto s2_desc = Graph::ProjectDescription::from_json(stage2_proj.to_json());
|
||||
Void::Testing::expect(s2_desc.has_value());
|
||||
if (!s2_desc)
|
||||
return;
|
||||
auto s2_graph = Graph::lower_project_graph(
|
||||
*s2_desc, *tc,
|
||||
{stage2_src, stage2_dir, nullptr, {{"stage1_sdk::VoidBuildSdk", s1_imported}}, 32768});
|
||||
Void::Testing::expect(s2_graph.has_value());
|
||||
if (!s2_graph)
|
||||
return;
|
||||
auto s2_state = State::StateStore::open(stage2_dir / ".vbs");
|
||||
Void::Testing::expect(s2_state.has_value());
|
||||
if (!s2_state)
|
||||
return;
|
||||
|
||||
auto s2_exec = Execution::execute_graph(*s2_graph, *s2_state);
|
||||
Void::Testing::expect(s2_exec.has_value() && s2_exec->succeeded);
|
||||
|
||||
Platform::ProcessRequest s2_run;
|
||||
s2_run.executable = stage2_dir / "profiles" / "debug" / "out" / "bin" / "stage2_consumer";
|
||||
if (const char *old_path = std::getenv("PATH")) {
|
||||
s2_run.environment.set_vars["PATH"] = trap_bin.string() + ":" + old_path;
|
||||
}
|
||||
auto s2_res = Platform::run_supervised(s2_run);
|
||||
Void::Testing::expect(s2_res.has_value() && s2_res->succeeded());
|
||||
}
|
||||
|
||||
// Plan 18 True Self-Hosting: Stage 0 builds the FULL native `vbs` CLI binary (VoidLibrary closure +
|
||||
// VoidBuildSdk + VoidBuildCore + stage-isolated BootstrapConfig.hpp, ZERO CMake!) into stage1_dir,
|
||||
// then executes that freshly self-hosted `stage1/bin/vbs` binary WITH TRAPPED `cmake` ON PATH to
|
||||
// build and test a real Stage 2 C++ project!
|
||||
Void::Testing::Test strict_native_full_vbs_stage1_to_stage2_without_cmake() {
|
||||
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
|
||||
const std::filesystem::path vbs_root{Bootstrap::source_dir};
|
||||
Void::Testing::expect(std::filesystem::is_directory(void_src));
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_full_selfhost_"};
|
||||
const auto stage1_dir = tmp / "stage1";
|
||||
const auto trap_bin = tmp / "trap_bin";
|
||||
|
||||
write_file(
|
||||
trap_bin / "cmake",
|
||||
"#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN STRICT SELF-HOST STAGE' >&2\nexit 99\n");
|
||||
(void)::chmod((trap_bin / "cmake").c_str(), 0755);
|
||||
|
||||
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, stage1_dir / ".vbs" / "probes");
|
||||
Void::Testing::expect(tc.has_value());
|
||||
if (!tc)
|
||||
return;
|
||||
|
||||
// 1. Declare the COMPLETE native VoidBuildSystem graph via VbsSelfHostRecipe (no CMake!).
|
||||
Project stage1_proj{ctx};
|
||||
Recipes::VbsSelfHostConfig sh_cfg;
|
||||
sh_cfg.vbs_source_dir = vbs_root;
|
||||
sh_cfg.void_source_dir = void_src;
|
||||
sh_cfg.stage_build_dir = stage1_dir;
|
||||
sh_cfg.version = "0.1.0-selfhost";
|
||||
sh_cfg.include_registry = false;
|
||||
sh_cfg.include_tests = false;
|
||||
auto added = Recipes::add_vbs_selfhost_native(stage1_proj, sh_cfg);
|
||||
Void::Testing::expect(added.has_value());
|
||||
if (!added)
|
||||
return;
|
||||
|
||||
auto s1_desc = Graph::ProjectDescription::from_json(stage1_proj.to_json());
|
||||
Void::Testing::expect(s1_desc.has_value());
|
||||
if (!s1_desc)
|
||||
return;
|
||||
|
||||
auto s1_graph =
|
||||
Graph::lower_project_graph(*s1_desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768});
|
||||
Void::Testing::expect(s1_graph.has_value());
|
||||
auto s1_state = State::StateStore::open(stage1_dir / ".vbs");
|
||||
Void::Testing::expect(s1_state.has_value());
|
||||
if (!s1_graph || !s1_state)
|
||||
return;
|
||||
|
||||
auto s1_exec = Execution::execute_graph(*s1_graph, *s1_state, {4, true, true, {"vbs"}, {}, {}});
|
||||
Void::Testing::expect(s1_exec.has_value() && s1_exec->succeeded);
|
||||
if (!s1_exec || !s1_exec->succeeded)
|
||||
return;
|
||||
|
||||
const auto stage1_vbs = stage1_dir / "profiles" / "debug" / "out" / "bin" / "vbs";
|
||||
Void::Testing::expect(std::filesystem::exists(stage1_vbs));
|
||||
|
||||
// 2. Verify self-hosted Stage 1 `vbs` CLI metadata with trapped `cmake` ahead of PATH!
|
||||
std::string trapped_path = trap_bin.string();
|
||||
if (const char *old_path = std::getenv("PATH")) {
|
||||
trapped_path += ":";
|
||||
trapped_path += old_path;
|
||||
}
|
||||
|
||||
{
|
||||
Platform::ProcessRequest ver_req;
|
||||
ver_req.executable = stage1_vbs;
|
||||
ver_req.arguments = {"--version"};
|
||||
ver_req.environment.set_vars["PATH"] = trapped_path;
|
||||
auto ver_res = Platform::run_supervised(ver_req);
|
||||
Void::Testing::expect(ver_res.has_value() && ver_res->succeeded());
|
||||
if (ver_res) {
|
||||
Void::Testing::expect(ver_res->stdout_data.find("vbs 0.1.0-selfhost") !=
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Stage 2: Execute the freshly self-hosted `stage1_vbs test` on a real C++ project
|
||||
// completely without CMake!
|
||||
const auto s2_proj = tmp / "stage2_proj";
|
||||
const auto s2_build = tmp / "stage2_build";
|
||||
write_file(s2_proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
auto lib = p.static_library("s2math")
|
||||
.sources({"src/math.cpp"})
|
||||
.include_directory("include", Void::Build::Visibility::Public);
|
||||
p.test("s2math_test")
|
||||
.sources({"tests/test_math.cpp"})
|
||||
.link(lib);
|
||||
}
|
||||
)cpp");
|
||||
write_file(s2_proj / "include" / "s2math.hpp", "#pragma once\nint s2_answer();\n");
|
||||
write_file(s2_proj / "src" / "math.cpp",
|
||||
"#include \"s2math.hpp\"\nint s2_answer() { return 42; }\n");
|
||||
write_file(s2_proj / "tests" / "test_math.cpp",
|
||||
"#include \"s2math.hpp\"\nint main() { return s2_answer() == 42 ? 0 : 1; }\n");
|
||||
|
||||
Platform::ProcessRequest s2_test_req;
|
||||
s2_test_req.executable = stage1_vbs;
|
||||
s2_test_req.arguments = {"test", "--project", s2_proj.string(), "--build-dir",
|
||||
s2_build.string()};
|
||||
s2_test_req.environment.set_vars["PATH"] = trapped_path;
|
||||
s2_test_req.timeout = std::chrono::seconds{120};
|
||||
auto s2_test_res = Platform::run_supervised(s2_test_req);
|
||||
Void::Testing::expect(s2_test_res.has_value() && s2_test_res->succeeded());
|
||||
if (s2_test_res) {
|
||||
Void::Testing::expect(s2_test_res->stdout_data.find("vbs test: PASSED 's2math_test'") !=
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user