feat(worker): add the vbs remote-execution worker client
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 9s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 11:18:22 +03:00
1 parent 1ae72e4d07
commit 0674b7f9fe
10 files changed
+423 -1

No files matched your search

+87
View File
@@ -2041,3 +2041,90 @@ VOID_TEST(RegistryTests, remote_worker_registration_lease_and_result_upload) {
(*svc)->stop_http();
}
// `vbs worker` CLI: leases an action, publishes its blobs/record to the registry CAS, and
// reports the result back through the lease token.
VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) {
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_worker_cli_"};
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("wrk_pub", "wrk_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("wrk_pub", "wrk", {"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();
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
const std::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
const std::string action_key = Util::sha256_hex("worker-cli-action");
auto state = State::StateStore::open(tmp / "build" / ".vbs");
Void::Testing::require(state.has_value());
const auto artifact = tmp / "worker_out.o";
(void)Platform::atomic_write_file(artifact, "WORKER_OUTPUT", false);
auto blob = state->store_blob_from_file(artifact);
Void::Testing::require(blob.has_value());
State::ActionSuccessRecord record;
record.action_key = action_key;
record.profile_identity = "prof";
record.target_name = "winapp";
record.outputs[artifact.string()] = *blob;
Void::Testing::require(state->record_action_success(record).has_value());
auto seeded = send_loopback_http(port, "PUT", "/api/v1/cas/actions/" + action_key, auth,
"{\"schema_version\":1,\"action_key\":\"" + action_key +
"\",\"outputs\":{}}");
Void::Testing::expect(seeded.has_value() && seeded->status == 201);
const auto record_file = tmp / "record.json";
(void)Platform::atomic_write_file(record_file,
"{\"schema_version\":1,\"action_key\":\"" + action_key +
"\",\"target_name\":\"winapp\",\"outputs\":{\"" +
artifact.string() + "\":{\"sha256\":\"" + blob->sha256 +
"\",\"size\":" + std::to_string(blob->size) +
",\"mode\":420}}}",
false);
Platform::ProcessRequest worker;
worker.executable = vbs_bin;
worker.arguments = {
"worker", "--registry", reg_url, "--action-key", action_key,
"--record", record_file.string(), "--build-dir", (tmp / "build").string()};
worker.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
worker.timeout = std::chrono::seconds{120};
auto worker_res = Platform::run_supervised(worker);
Void::Testing::expect_eq(
worker_res ? (worker_res->succeeded() ? std::string{}
: (worker_res->stdout_data + worker_res->stderr_data))
: worker_res.error().message(),
std::string{});
auto cas_record = send_loopback_http(port, "GET", "/api/v1/cas/actions/" + action_key, auth);
Void::Testing::expect(cas_record.has_value() && cas_record->status == 200);
if (cas_record) {
Void::Testing::expect(cas_record->body.find("winapp") != std::string::npos);
}
auto cas_blob = send_loopback_http(port, "GET", "/api/v1/cas/blobs/" + blob->sha256, auth);
Void::Testing::expect(cas_blob.has_value() && cas_blob->status == 200);
if (cas_blob) {
Void::Testing::expect(cas_blob->body == "WORKER_OUTPUT");
}
(*svc)->stop_http();
}