feat(registry): add the remote worker lease and result protocol
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 5s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 52s

This commit is contained in:
faumaray committed 2026-12-05 11:08:23 +03:00
1 parent c2b80416a5
commit 1ae72e4d07
7 files changed
+336 -1

No files matched your search

+99
View File
@@ -1942,3 +1942,102 @@ VOID_TEST(RegistryTests, options_preflight_metadata_and_download_endpoints) {
(*svc)->stop_http();
}
// Remote execution worker protocol: registration, heartbeat, action lease, and result upload
// on top of the shared HTTP CAS.
VOID_TEST(RegistryTests, remote_worker_registration_lease_and_result_upload) {
Void::FileSystem::TempDir tmp{"vbs_worker_"};
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_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::expect(
(*svc)->create_user("exec_user", "exec_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("exec_user", "exec", {"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::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
// Input blob and the initial action record live in the CAS.
const std::string input = "WORKER_INPUT_BYTES";
const std::string input_sha = Util::sha256_hex(input);
auto blob_put = send_loopback_http(port, "PUT", "/api/v1/cas/blobs/" + input_sha, auth, input);
Void::Testing::expect(blob_put.has_value() && blob_put->status == 201);
const std::string action_key = Util::sha256_hex("worker-action-key");
const std::string initial_record =
"{\"schema_version\":1,\"action_key\":\"" + action_key + "\",\"outputs\":{}}";
auto record_put =
send_loopback_http(port, "PUT", "/api/v1/cas/actions/" + action_key, auth, initial_record);
Void::Testing::expect(record_put.has_value() && record_put->status == 201);
// Worker registration + heartbeat.
auto registered = send_loopback_http(port, "POST", "/api/v1/workers", auth,
"{\"platform\":\"linux-x86_64\"}");
Void::Testing::expect(registered.has_value() && registered->status == 201);
if (!registered) {
return;
}
const std::string worker_id = extract_json_str(registered->body, "worker_id");
Void::Testing::expect(!worker_id.empty());
auto heartbeat =
send_loopback_http(port, "POST", "/api/v1/workers/" + worker_id + "/heartbeat", auth, "");
Void::Testing::expect(heartbeat.has_value() && heartbeat->status == 200);
auto workers = send_loopback_http(port, "GET", "/api/v1/workers", auth);
Void::Testing::expect(workers.has_value() && workers->status == 200);
if (workers) {
Void::Testing::expect(workers->body.find(worker_id) != std::string::npos);
}
// Lease the action once; a concurrent lease conflicts.
const std::string lease_body = "{\"action_key\":\"" + action_key + "\",\"worker_id\":\"" +
worker_id + "\",\"lease_seconds\":60}";
auto lease = send_loopback_http(port, "POST", "/api/v1/actions/lease", auth, lease_body);
Void::Testing::expect(lease.has_value() && lease->status == 200);
if (!lease) {
return;
}
const std::string lease_token = extract_json_str(lease->body, "lease_token");
Void::Testing::expect(!lease_token.empty());
Void::Testing::expect(lease->body.find("\"record\":") != std::string::npos);
auto conflict = send_loopback_http(port, "POST", "/api/v1/actions/lease", auth, lease_body);
Void::Testing::expect(conflict.has_value() && conflict->status == 409);
// Result upload: wrong token is rejected, the leased token is accepted.
const std::string result_record = "{\"schema_version\":1,\"action_key\":\"" + action_key +
"\",\"outputs\":{\"out.o\":{\"sha256\":\"" + input_sha +
"\",\"size\":17,\"mode\":420}}}";
auto bad_result =
send_loopback_http(port, "POST", "/api/v1/actions/" + action_key + "/result", auth,
"{\"lease_token\":\"deadbeef\",\"record\":" + result_record + "}");
Void::Testing::expect(bad_result.has_value() && bad_result->status == 403);
auto good_result = send_loopback_http(
port, "POST", "/api/v1/actions/" + action_key + "/result", auth,
"{\"lease_token\":\"" + lease_token + "\",\"record\":" + result_record + "}");
Void::Testing::expect(good_result.has_value() && good_result->status == 200);
auto fetched = send_loopback_http(port, "GET", "/api/v1/cas/actions/" + action_key, auth);
Void::Testing::expect(fetched.has_value() && fetched->status == 200);
if (fetched) {
Void::Testing::expect(fetched->body.find("out.o") != std::string::npos);
}
// Leasing an unknown action is a 404.
auto unknown = send_loopback_http(port, "POST", "/api/v1/actions/lease", auth,
"{\"action_key\":\"" + std::string(64, 'a') +
"\",\"worker_id\":\"" + worker_id + "\"}");
Void::Testing::expect(unknown.has_value() && unknown->status == 404);
(*svc)->stop_http();
}