feat(cache): add shared HTTP action cache and parallel snapshot hashing
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s

- D1: RemoteCasClient + registry /api/v1/cas endpoints with bearer auth and digest verification, StateStore remote action/blob APIs, build-path-independent action keys, --remote-cache CLI
- D2: parallel snapshot revalidation hashing via Void::Concurrency::ThreadPool
- Verified in Docker GCC 16: 8/8 CTest suites, cross-build-dir 100% cache hit, 5001-file warm no-op 374 ms
- Fix self-host recipe source list for RemoteCache.cpp and accept GCC 16 -lgcc_s_asneeded
This commit is contained in:
faumaray committed 2026-12-03 12:36:21 +03:00
1 parent 6c225c2dff
commit 09c0a91d1d
19 files changed
+1213 -18

No files matched your search

+142
View File
@@ -4,6 +4,7 @@
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Registry/HttpServer.hpp>
#include <Void/Build/Registry/RegistryService.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/Data/StrictJson.hpp>
#include <Void/System/Path.hpp>
@@ -215,6 +216,147 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
}
}
// Track D1: shared HTTP content-addressed action cache blob/record round-trip across stores.
VOID_TEST(RegistryTests, shared_remote_action_cache_blob_and_record_roundtrip) {
Void::FileSystem::TempDir tmp{"vbs_remote_cas_"};
RegistryConfig cfg;
cfg.data_dir = tmp / "reg_data";
cfg.bind_address = "127.0.0.1";
cfg.port = 0;
cfg.bootstrap_admin_user = "admin";
cfg.bootstrap_admin_password = "admin_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::expect((*svc)->create_user("ci_cache", "ci_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("ci_cache", "cas", {"read", "publish"});
Void::Testing::expect(tok.has_value());
if (!tok) {
return;
}
Void::Testing::expect((*svc)->start_http().has_value());
const auto port = (*svc)->bound_port();
State::RemoteCacheConfig remote;
remote.url = "http://127.0.0.1:" + std::to_string(port);
remote.bearer_token = *tok;
Void::FileSystem::TempDir store_tmp{"vbs_remote_store_"};
auto store = State::StateStore::open(store_tmp / ".vbs");
Void::Testing::expect(store.has_value());
if (!store) {
return;
}
store->configure_remote_cache(remote);
const auto artifact = tmp / "remote_obj.o";
(void)Platform::atomic_write_file(artifact, "REMOTE_CACHE_OBJECT_BYTES", false);
auto blob = store->store_blob_from_file(artifact);
Void::Testing::expect(blob.has_value());
if (!blob) {
return;
}
Void::Testing::expect(store->publish_remote_blob(blob->sha256).has_value());
// A fresh, empty store downloads and SHA-256 verifies the blob from the shared cache.
Void::FileSystem::TempDir store2_tmp{"vbs_remote_store2_"};
auto store2 = State::StateStore::open(store2_tmp / ".vbs");
Void::Testing::expect(store2.has_value());
if (!store2) {
return;
}
store2->configure_remote_cache(remote);
Void::Testing::expect(!store2->verify_blob(blob->sha256).value_or(true));
auto ensured = store2->ensure_remote_blob(blob->sha256);
Void::Testing::expect(ensured.has_value() && *ensured);
Void::Testing::expect(store2->verify_blob(blob->sha256).value_or(false));
// Action record round-trip by portable key.
const std::string key = Util::sha256_hex("portable-action-key");
const std::string record = "{\"schema_version\":1,\"action_key\":\"" + key + "\"}";
Void::Testing::expect(store->publish_remote_action(key, record).has_value());
auto fetched = store2->fetch_remote_action(key);
Void::Testing::expect(fetched.has_value() && fetched->has_value() && **fetched == record);
// Unauthenticated CAS reads are rejected.
auto anon = send_loopback_http(port, "GET", "/api/v1/cas/blobs/" + blob->sha256);
Void::Testing::expect(anon.has_value() && anon->status == 401);
(*svc)->stop_http();
}
// Track D1 acceptance: a cold build populates the shared CAS, then a second clean build
// directory is a 100% verified cache hit and its binary runs.
VOID_TEST(RegistryTests, shared_remote_cache_cold_populates_then_clean_build_all_hits) {
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_remote_accept_"};
RegistryConfig cfg;
cfg.data_dir = tmp / "reg_data";
cfg.bind_address = "127.0.0.1";
cfg.port = 0;
cfg.bootstrap_admin_user = "admin";
cfg.bootstrap_admin_password = "admin_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::expect((*svc)->create_user("ci_cache", "ci_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("ci_cache", "accept", {"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());
const auto proj = tmp / "proj";
(void)Platform::atomic_write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.executable("cache_app").sources({"src/main.cpp"});
}
)cpp",
false);
(void)Platform::atomic_write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n",
false);
auto run_build = [&](const std::filesystem::path &build_dir) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"build", "--project", proj.string(),
"--build-dir", build_dir.string(), "--remote-cache",
reg_url, "--jobs", "4"};
req.environment.set_vars["VBS_REMOTE_CACHE_TOKEN"] = *tok;
return Platform::run_supervised(req);
};
auto first = run_build(tmp / "build_a");
Void::Testing::expect(first.has_value() && first->succeeded());
if (first) {
Void::Testing::expect(first->stdout_data.find("built (0 executed") == std::string::npos);
}
auto second = run_build(tmp / "build_b");
Void::Testing::expect(second.has_value() && second->succeeded());
if (second) {
Void::Testing::expect(second->stdout_data.find("built (0 executed") != std::string::npos);
}
Platform::ProcessRequest run_req;
run_req.executable = tmp / "build_b" / "profiles" / "debug" / "out" / "bin" / "cache_app";
auto run_res = Platform::run_supervised(run_req);
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
(*svc)->stop_http();
}
// End-to-end live client <-> server test: `vbs publish` -> `vbs deps resolve` -> `vbs build
// --locked`!
VOID_TEST(RegistryTests, cli_publish_deps_resolve_and_locked_build_against_live_registry) {