feat(worker): add the vbs remote-execution worker client
This commit is contained in:
1 parent
1ae72e4d07
commit
0674b7f9fe
10 files changed
+423
-1
No files matched your search
@@ -338,6 +338,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
|||||||
|
|
||||||
- **Wave 122 (Remote Execution Worker Protocol)**: `vbs-registry` now exposes an in-memory worker/lease protocol on the existing CAS - `POST /api/v1/workers` (registration), `/workers/<id>/heartbeat`, `GET /workers`, `POST /api/v1/actions/lease` (exclusive lease with TTL and token) and `POST /api/v1/actions/<key>/result` (token-checked result upload that requires every referenced output blob to exist). `RegistryTests.remote_worker_registration_lease_and_result_upload` covers registration, heartbeat, lease/conflict, wrong-token rejection, result publication and the unknown-action 404.
|
- **Wave 122 (Remote Execution Worker Protocol)**: `vbs-registry` now exposes an in-memory worker/lease protocol on the existing CAS - `POST /api/v1/workers` (registration), `/workers/<id>/heartbeat`, `GET /workers`, `POST /api/v1/actions/lease` (exclusive lease with TTL and token) and `POST /api/v1/actions/<key>/result` (token-checked result upload that requires every referenced output blob to exist). `RegistryTests.remote_worker_registration_lease_and_result_upload` covers registration, heartbeat, lease/conflict, wrong-token rejection, result publication and the unknown-action 404.
|
||||||
|
|
||||||
|
- **Wave 123 (`vbs worker` Client)**: added `vbs worker --registry --action-key --record FILE [--build-dir] [--token-env] [--lease-seconds]`, which registers a worker, leases the action, publishes each referenced output blob and the action record to the registry CAS (via the StateStore remote cache), and submits the result with the lease token. Supporting APIs: `StateStore::export_action_record_json`, `Package::register_worker`/`lease_action`/`submit_action_result`. `RegistryTests.worker_cli_leases_publishes_and_reports_result` verifies the CAS record and blob after a worker run.
|
||||||
|
|
||||||
## Remaining future scope
|
## Remaining future scope
|
||||||
|
|
||||||
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
||||||
|
|||||||
@@ -125,4 +125,5 @@ Base HEAD: `fe0d1a6`
|
|||||||
| Wave 120 (WiX/MSI-style packaging + VoidLibrary CI) | `--archive-format wix` WiX v3 source generator; `.gitea/workflows/vbs.yml` template on the branch | COMPLETE & VERIFIED for the generator (XML parsed, install test passes, full CTest 8/8); CI template unexecuted | `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, [Void/Library build-vbs](https://git.faumaray.com/Void/Library/src/branch/build-vbs), docs |
|
| Wave 120 (WiX/MSI-style packaging + VoidLibrary CI) | `--archive-format wix` WiX v3 source generator; `.gitea/workflows/vbs.yml` template on the branch | COMPLETE & VERIFIED for the generator (XML parsed, install test passes, full CTest 8/8); CI template unexecuted | `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, [Void/Library build-vbs](https://git.faumaray.com/Void/Library/src/branch/build-vbs), docs |
|
||||||
| Wave 121 (libFuzzer fuzzing) | `fuzz/fuzz_parsers.cpp` + `fuzz/run.sh` for JSON and SemVer with Clang/libFuzzer | COMPLETE & VERIFIED (1,541,020 runs, 0 findings) | `fuzz/`, docs |
|
| Wave 121 (libFuzzer fuzzing) | `fuzz/fuzz_parsers.cpp` + `fuzz/run.sh` for JSON and SemVer with Clang/libFuzzer | COMPLETE & VERIFIED (1,541,020 runs, 0 findings) | `fuzz/`, docs |
|
||||||
| Wave 122 (Remote worker protocol) | Registry worker registration/heartbeat, exclusive action leases with TTL/tokens, token-checked result upload with blob verification | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; new registry E2E passes, full CTest 8/8) | `registry/include/Void/Build/Registry/RegistryService.hpp`, `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs |
|
| Wave 122 (Remote worker protocol) | Registry worker registration/heartbeat, exclusive action leases with TTL/tokens, token-checked result upload with blob verification | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; new registry E2E passes, full CTest 8/8) | `registry/include/Void/Build/Registry/RegistryService.hpp`, `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs |
|
||||||
|
| Wave 123 (`vbs worker` client) | Worker CLI: register, lease, publish blobs/record, submit result; StateStore export; client APIs | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; worker CLI E2E passes, full CTest 8/8) | `src/Main.cpp`, `src/Package/RegistryClient.cpp`, `src/State/StateStore.cpp`, `tests/RegistryTests.cpp`, docs |
|
||||||
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
||||||
@@ -1687,6 +1687,15 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30
|
|||||||
the result (visible through the CAS GET), and leasing an unknown action returns 404.
|
the result (visible through the CAS GET), and leasing an unknown action returns 404.
|
||||||
- Full CTest: **8 / 8 passed** in 280.81 s.
|
- Full CTest: **8 / 8 passed** in 280.81 s.
|
||||||
|
|
||||||
|
## `vbs worker` Client (GCC 16.2, pin `0002e74`)
|
||||||
|
|
||||||
|
- `RegistryTests.worker_cli_leases_publishes_and_reports_result` **passed** (417 ms): with a
|
||||||
|
local StateStore holding an output blob and an action record, the worker CLI registers,
|
||||||
|
leases the action, publishes the blob and record into the registry CAS, submits the result
|
||||||
|
with the lease token, and the registry afterwards serves the record (`winapp`) and the exact
|
||||||
|
blob bytes (`WORKER_OUTPUT`).
|
||||||
|
- Full CTest: **8 / 8 passed** in 281.23 s.
|
||||||
|
|
||||||
## Limits and Unrun Checks
|
## Limits and Unrun Checks
|
||||||
|
|
||||||
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
|
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ Concrete work this implies:
|
|||||||
6. Test-runner parity.
|
6. Test-runner parity.
|
||||||
7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling).
|
7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling).
|
||||||
8. CI on real runners, sanitizer jobs (**sanitizer build run done**), parser fuzzing (**deterministic mutation harness and a Clang/libFuzzer target done**).
|
8. CI on real runners, sanitizer jobs (**sanitizer build run done**), parser fuzzing (**deterministic mutation harness and a Clang/libFuzzer target done**).
|
||||||
9. Remote execution workers (**registry-side worker/lease/result protocol done**; a `vbs worker` client remains).
|
9. Remote execution workers (**registry-side worker/lease/result protocol and the `vbs worker` client done**; distributed scheduling remains).
|
||||||
|
|
||||||
## 6. Observed baseline (2026-12-05, x86_64, GCC 16.2, Debug, `benchmarks/compare.sh 20`)
|
## 6. Observed baseline (2026-12-05, x86_64, GCC 16.2, Debug, `benchmarks/compare.sh 20`)
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,33 @@ struct TokenInfo {
|
|||||||
[[nodiscard]] Void::Result::Result<std::vector<TokenInfo>, Void::Result::Error>
|
[[nodiscard]] Void::Result::Result<std::vector<TokenInfo>, Void::Result::Error>
|
||||||
fetch_tokens(std::string_view registry_url, const RegistryAuth &auth = {});
|
fetch_tokens(std::string_view registry_url, const RegistryAuth &auth = {});
|
||||||
|
|
||||||
|
// Remote execution worker protocol (registry-side lease/result endpoints).
|
||||||
|
struct WorkerRegistration {
|
||||||
|
std::string worker_id;
|
||||||
|
std::int64_t registered_epoch{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LeasedAction {
|
||||||
|
std::string action_key;
|
||||||
|
std::string worker_id;
|
||||||
|
std::string lease_token;
|
||||||
|
std::int64_t expires_epoch{0};
|
||||||
|
std::string record_json;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] Void::Result::Result<WorkerRegistration, Void::Result::Error>
|
||||||
|
register_worker(std::string_view registry_url, std::string_view platform,
|
||||||
|
const RegistryAuth &auth = {});
|
||||||
|
|
||||||
|
[[nodiscard]] Void::Result::Result<LeasedAction, Void::Result::Error>
|
||||||
|
lease_action(std::string_view registry_url, std::string_view action_key, std::string_view worker_id,
|
||||||
|
std::int64_t lease_seconds, const RegistryAuth &auth = {});
|
||||||
|
|
||||||
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
||||||
|
submit_action_result(std::string_view registry_url, std::string_view action_key,
|
||||||
|
std::string_view lease_token, std::string_view record_json,
|
||||||
|
const RegistryAuth &auth = {});
|
||||||
|
|
||||||
// Marks a release yanked or unyanked via POST .../<version>/yank (bearer tokens are exempt
|
// Marks a release yanked or unyanked via POST .../<version>/yank (bearer tokens are exempt
|
||||||
// from CSRF; owner or admin authority required). Returns the resulting yank state.
|
// from CSRF; owner or admin authority required). Returns the resulting yank state.
|
||||||
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
|
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ class StateStore {
|
|||||||
|
|
||||||
[[nodiscard]] std::size_t recorded_action_count() const;
|
[[nodiscard]] std::size_t recorded_action_count() const;
|
||||||
|
|
||||||
|
// Serialized registry-form action record for `action_key` (for worker/result upload).
|
||||||
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
||||||
|
export_action_record_json(std::string_view action_key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DatabaseSnapshot {
|
struct DatabaseSnapshot {
|
||||||
int schema_version{kStateSchemaVersion};
|
int schema_version{kStateSchemaVersion};
|
||||||
|
|||||||
+131
@@ -1449,6 +1449,117 @@ int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct WorkerCmdOptions {
|
||||||
|
std::optional<std::string> registry_arg;
|
||||||
|
std::optional<std::string> action_key_arg;
|
||||||
|
std::optional<std::string> record_arg;
|
||||||
|
std::string project_arg;
|
||||||
|
std::optional<std::string> build_arg;
|
||||||
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||||
|
std::string lease_seconds_arg{"60"};
|
||||||
|
};
|
||||||
|
|
||||||
|
int execute_worker_command(const WorkerCmdOptions &opts) {
|
||||||
|
if (!opts.registry_arg || !opts.action_key_arg || !opts.record_arg) {
|
||||||
|
std::cerr << "vbs worker: --registry, --action-key, and --record are required\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
int lease_seconds = 60;
|
||||||
|
if (!Void::Str::to_int(opts.lease_seconds_arg, lease_seconds) || lease_seconds <= 0 ||
|
||||||
|
lease_seconds > 3600) {
|
||||||
|
std::cerr << "vbs worker: invalid --lease-seconds value '" << opts.lease_seconds_arg
|
||||||
|
<< "'\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
const std::string registry = *opts.registry_arg;
|
||||||
|
const std::string action_key = *opts.action_key_arg;
|
||||||
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||||
|
|
||||||
|
auto record_text = Void::FileSystem::read_file(*opts.record_arg);
|
||||||
|
if (!record_text) {
|
||||||
|
std::cerr << "vbs worker: " << record_text.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
auto record_json = Void::Json::Strict::parse(*record_text);
|
||||||
|
const auto *record_object =
|
||||||
|
record_json ? std::get_if<Void::Json::Strict::Value::Object>(&record_json->value) : nullptr;
|
||||||
|
if (record_object == nullptr) {
|
||||||
|
std::cerr << "vbs worker: --record must contain a JSON object\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::filesystem::path project_root{opts.project_arg};
|
||||||
|
const std::filesystem::path build_root =
|
||||||
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
||||||
|
auto state = State::StateStore::open(build_root / ".vbs");
|
||||||
|
if (!state) {
|
||||||
|
std::cerr << "vbs worker: " << state.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string platform =
|
||||||
|
Toolchain::host_os_name() + "-" + Toolchain::host_architecture_name();
|
||||||
|
auto registration = Package::register_worker(registry, platform, auth);
|
||||||
|
if (!registration) {
|
||||||
|
std::cerr << "vbs worker: " << registration.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Void::Log::info("Worker", "Registered as {}", registration->worker_id);
|
||||||
|
|
||||||
|
auto leased =
|
||||||
|
Package::lease_action(registry, action_key, registration->worker_id, lease_seconds, auth);
|
||||||
|
if (!leased) {
|
||||||
|
std::cerr << "vbs worker: " << leased.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased->expires_epoch);
|
||||||
|
|
||||||
|
State::RemoteCacheConfig remote;
|
||||||
|
remote.url = registry;
|
||||||
|
remote.bearer_token = auth.bearer_token;
|
||||||
|
state->configure_remote_cache(remote);
|
||||||
|
|
||||||
|
// Publish every referenced output blob, then the action record itself.
|
||||||
|
if (const auto outputs_it = record_object->find("outputs");
|
||||||
|
outputs_it != record_object->end()) {
|
||||||
|
if (const auto *outputs =
|
||||||
|
std::get_if<Void::Json::Strict::Value::Object>(&outputs_it->second.value)) {
|
||||||
|
for (const auto &[path, ref] : *outputs) {
|
||||||
|
const auto *ref_object = std::get_if<Void::Json::Strict::Value::Object>(&ref.value);
|
||||||
|
if (ref_object == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto sha_it = ref_object->find("sha256");
|
||||||
|
if (sha_it == ref_object->end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto *sha = std::get_if<std::string>(&sha_it->second.value);
|
||||||
|
if (sha == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto published = state->publish_remote_blob(*sha); !published) {
|
||||||
|
std::cerr << "vbs worker: publishing blob " << *sha << ": "
|
||||||
|
<< published.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (auto published = state->publish_remote_action(action_key, *record_text); !published) {
|
||||||
|
std::cerr << "vbs worker: publishing action record: " << published.error().message()
|
||||||
|
<< '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (auto submitted = Package::submit_action_result(registry, action_key, leased->lease_token,
|
||||||
|
*record_text, auth);
|
||||||
|
!submitted) {
|
||||||
|
std::cerr << "vbs worker: " << submitted.error().message() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "worker " << registration->worker_id << " completed action " << action_key << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct MigrateCmdOptions {
|
struct MigrateCmdOptions {
|
||||||
std::string input_arg{"CMakeLists.txt"};
|
std::string input_arg{"CMakeLists.txt"};
|
||||||
std::string output_arg{"build.cpp"};
|
std::string output_arg{"build.cpp"};
|
||||||
@@ -2950,6 +3061,8 @@ int main(int argc, char **argv) {
|
|||||||
VerifyCmdOptions verify_opts;
|
VerifyCmdOptions verify_opts;
|
||||||
PresetsCmdOptions presets_opts;
|
PresetsCmdOptions presets_opts;
|
||||||
MigrateCmdOptions migrate_opts;
|
MigrateCmdOptions migrate_opts;
|
||||||
|
WorkerCmdOptions worker_opts;
|
||||||
|
worker_opts.project_arg = cwd;
|
||||||
CompdbEntriesCmdOptions compdb_entries_opts;
|
CompdbEntriesCmdOptions compdb_entries_opts;
|
||||||
publish_opts.project_arg = cwd;
|
publish_opts.project_arg = cwd;
|
||||||
BridgeCmdOptions bridge_opts;
|
BridgeCmdOptions bridge_opts;
|
||||||
@@ -3163,6 +3276,21 @@ int main(int argc, char **argv) {
|
|||||||
verify_opts.trusted_key_files);
|
verify_opts.trusted_key_files);
|
||||||
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
|
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
|
||||||
|
|
||||||
|
auto &worker_cmd = root.subcommand(
|
||||||
|
"worker", "Run one remote-execution worker step (lease, publish, result upload)");
|
||||||
|
worker_cmd
|
||||||
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||||
|
worker_opts.registry_arg)
|
||||||
|
.option("--action-key", "", "Action key to lease and publish", worker_opts.action_key_arg)
|
||||||
|
.option("--record", "", "Action record JSON file to publish", worker_opts.record_arg)
|
||||||
|
.option_default("--project", "-C", "Project directory", worker_opts.project_arg, cwd)
|
||||||
|
.option("--build-dir", "-B", "Build directory", worker_opts.build_arg)
|
||||||
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||||
|
worker_opts.token_env, "VBS_REGISTRY_TOKEN")
|
||||||
|
.option_default("--lease-seconds", "", "Lease TTL in seconds (1..3600)",
|
||||||
|
worker_opts.lease_seconds_arg, "60");
|
||||||
|
add_log_flags(worker_cmd);
|
||||||
|
|
||||||
auto &migrate_cmd = root.subcommand(
|
auto &migrate_cmd = root.subcommand(
|
||||||
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
|
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
|
||||||
migrate_cmd
|
migrate_cmd
|
||||||
@@ -3666,6 +3794,9 @@ int main(int argc, char **argv) {
|
|||||||
if (cmd == "migrate") {
|
if (cmd == "migrate") {
|
||||||
return execute_migrate_command(migrate_opts);
|
return execute_migrate_command(migrate_opts);
|
||||||
}
|
}
|
||||||
|
if (cmd == "worker") {
|
||||||
|
return execute_worker_command(worker_opts);
|
||||||
|
}
|
||||||
if (cmd == "compdb-entries") {
|
if (cmd == "compdb-entries") {
|
||||||
return execute_compdb_entries_command(compdb_entries_opts);
|
return execute_compdb_entries_command(compdb_entries_opts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -797,6 +797,148 @@ fetch_tokens(std::string_view registry_url, const RegistryAuth &auth) {
|
|||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string json_quote_of(std::string_view text) {
|
||||||
|
std::string out{"\""};
|
||||||
|
for (const char c : text) {
|
||||||
|
if (c == '"' || c == '\\') {
|
||||||
|
out.push_back('\\');
|
||||||
|
out.push_back(c);
|
||||||
|
} else if (c == '\n') {
|
||||||
|
out += "\\n";
|
||||||
|
} else {
|
||||||
|
out.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.push_back('"');
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string, std::less<>> bearer_headers(const RegistryAuth &auth) {
|
||||||
|
std::map<std::string, std::string, std::less<>> headers;
|
||||||
|
headers["Content-Type"] = "application/json";
|
||||||
|
if (!auth.bearer_token.empty()) {
|
||||||
|
headers["Authorization"] = "Bearer " + auth.bearer_token;
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Void::Result::Result<WorkerRegistration, Void::Result::Error>
|
||||||
|
register_worker(std::string_view registry_url, std::string_view platform,
|
||||||
|
const RegistryAuth &auth) {
|
||||||
|
auto parsed_url = parse_registry_url(registry_url);
|
||||||
|
if (!parsed_url) {
|
||||||
|
return std::unexpected{parsed_url.error()};
|
||||||
|
}
|
||||||
|
const std::string body = std::format("{{\"platform\":{}}}", json_quote_of(platform));
|
||||||
|
auto reply =
|
||||||
|
send_http_request(*parsed_url, "POST", "/api/v1/workers", bearer_headers(auth), body);
|
||||||
|
if (!reply) {
|
||||||
|
return std::unexpected{reply.error()};
|
||||||
|
}
|
||||||
|
if (reply->status != 201) {
|
||||||
|
return std::unexpected{
|
||||||
|
make_error(reply->status == 401 || reply->status == 403
|
||||||
|
? Void::System::SystemErrorCode::permission_denied
|
||||||
|
: Void::System::SystemErrorCode::io_error,
|
||||||
|
std::format("worker registration failed with HTTP {}", reply->status))};
|
||||||
|
}
|
||||||
|
auto json = Void::Json::Strict::parse(reply->body);
|
||||||
|
const auto *object = json ? std::get_if<JsonVal::Object>(&json->value) : nullptr;
|
||||||
|
if (!object) {
|
||||||
|
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||||
|
"invalid worker registration response")};
|
||||||
|
}
|
||||||
|
WorkerRegistration registration;
|
||||||
|
registration.worker_id = get_str(*object, "worker_id");
|
||||||
|
registration.registered_epoch = get_i64(*object, "registered_epoch", 0);
|
||||||
|
if (registration.worker_id.empty()) {
|
||||||
|
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||||
|
"worker registration response has no worker_id")};
|
||||||
|
}
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Result::Result<LeasedAction, Void::Result::Error>
|
||||||
|
lease_action(std::string_view registry_url, std::string_view action_key, std::string_view worker_id,
|
||||||
|
std::int64_t lease_seconds, const RegistryAuth &auth) {
|
||||||
|
auto parsed_url = parse_registry_url(registry_url);
|
||||||
|
if (!parsed_url) {
|
||||||
|
return std::unexpected{parsed_url.error()};
|
||||||
|
}
|
||||||
|
const std::string body =
|
||||||
|
std::format("{{\"action_key\":{},\"worker_id\":{},\"lease_seconds\":{}}}",
|
||||||
|
json_quote_of(action_key), json_quote_of(worker_id), lease_seconds);
|
||||||
|
auto reply =
|
||||||
|
send_http_request(*parsed_url, "POST", "/api/v1/actions/lease", bearer_headers(auth), body);
|
||||||
|
if (!reply) {
|
||||||
|
return std::unexpected{reply.error()};
|
||||||
|
}
|
||||||
|
if (reply->status != 200) {
|
||||||
|
return std::unexpected{make_error(
|
||||||
|
reply->status == 404 ? Void::System::SystemErrorCode::not_found
|
||||||
|
: reply->status == 409 ? Void::System::SystemErrorCode::busy
|
||||||
|
: reply->status == 401 || reply->status == 403
|
||||||
|
? Void::System::SystemErrorCode::permission_denied
|
||||||
|
: Void::System::SystemErrorCode::io_error,
|
||||||
|
std::format("action lease failed with HTTP {}: {}", reply->status, reply->body))};
|
||||||
|
}
|
||||||
|
auto json = Void::Json::Strict::parse(reply->body);
|
||||||
|
const auto *object = json ? std::get_if<JsonVal::Object>(&json->value) : nullptr;
|
||||||
|
if (!object) {
|
||||||
|
return std::unexpected{
|
||||||
|
make_error(Void::System::SystemErrorCode::io_error, "invalid action lease response")};
|
||||||
|
}
|
||||||
|
LeasedAction leased;
|
||||||
|
leased.action_key = get_str(*object, "action_key");
|
||||||
|
leased.worker_id = get_str(*object, "worker_id");
|
||||||
|
leased.lease_token = get_str(*object, "lease_token");
|
||||||
|
leased.expires_epoch = get_i64(*object, "expires_epoch", 0);
|
||||||
|
if (const auto it = object->find("record"); it != object->end()) {
|
||||||
|
auto serialized = Void::Json::Strict::serialize(it->second);
|
||||||
|
if (!serialized) {
|
||||||
|
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||||
|
"cannot serialize leased record")};
|
||||||
|
}
|
||||||
|
leased.record_json = *serialized;
|
||||||
|
}
|
||||||
|
if (leased.lease_token.empty()) {
|
||||||
|
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||||
|
"action lease response has no lease_token")};
|
||||||
|
}
|
||||||
|
return leased;
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Result::Result<void, Void::Result::Error> submit_action_result(std::string_view registry_url,
|
||||||
|
std::string_view action_key,
|
||||||
|
std::string_view lease_token,
|
||||||
|
std::string_view record_json,
|
||||||
|
const RegistryAuth &auth) {
|
||||||
|
auto parsed_url = parse_registry_url(registry_url);
|
||||||
|
if (!parsed_url) {
|
||||||
|
return std::unexpected{parsed_url.error()};
|
||||||
|
}
|
||||||
|
const std::string path =
|
||||||
|
"/api/v1/actions/" + Void::Encoding::Url::encode(action_key) + "/result";
|
||||||
|
const std::string body = std::format("{{\"lease_token\":{},\"record\":{}}}",
|
||||||
|
json_quote_of(lease_token), record_json);
|
||||||
|
auto reply = send_http_request(*parsed_url, "POST", path, bearer_headers(auth), body);
|
||||||
|
if (!reply) {
|
||||||
|
return std::unexpected{reply.error()};
|
||||||
|
}
|
||||||
|
if (reply->status != 200) {
|
||||||
|
return std::unexpected{
|
||||||
|
make_error(reply->status == 409 ? Void::System::SystemErrorCode::busy
|
||||||
|
: reply->status == 403 ? Void::System::SystemErrorCode::permission_denied
|
||||||
|
: reply->status == 400 ? Void::System::SystemErrorCode::invalid_argument
|
||||||
|
: Void::System::SystemErrorCode::io_error,
|
||||||
|
std::format("action result upload failed with HTTP {}: {}", reply->status,
|
||||||
|
reply->body))};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
Void::Result::Result<bool, Void::Result::Error>
|
Void::Result::Result<bool, Void::Result::Error>
|
||||||
set_release_yanked(std::string_view registry_url, std::string_view package_name,
|
set_release_yanked(std::string_view registry_url, std::string_view package_name,
|
||||||
std::string_view version, bool yanked, const RegistryAuth &auth) {
|
std::string_view version, bool yanked, const RegistryAuth &auth) {
|
||||||
|
|||||||
@@ -1174,4 +1174,23 @@ std::size_t StateStore::recorded_action_count() const {
|
|||||||
return db ? db->actions.size() : 0;
|
return db ? db->actions.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Result::Result<std::string, Void::Result::Error>
|
||||||
|
StateStore::export_action_record_json(std::string_view action_key) const {
|
||||||
|
auto lock = Platform::FileLock::acquire(lock_file_, Platform::LockMode::Shared);
|
||||||
|
if (!lock) {
|
||||||
|
return std::unexpected{lock.error()};
|
||||||
|
}
|
||||||
|
auto db = load_db_locked();
|
||||||
|
if (!db) {
|
||||||
|
return std::unexpected{db.error()};
|
||||||
|
}
|
||||||
|
const auto it = db->actions.find(std::string{action_key});
|
||||||
|
if (it == db->actions.end()) {
|
||||||
|
return std::unexpected{
|
||||||
|
make_error(Void::System::SystemErrorCode::not_found,
|
||||||
|
std::format("no local action record for '{}'", action_key))};
|
||||||
|
}
|
||||||
|
return serialize_action(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Void::Build::State
|
} // namespace Void::Build::State
|
||||||
@@ -2041,3 +2041,90 @@ VOID_TEST(RegistryTests, remote_worker_registration_lease_and_result_upload) {
|
|||||||
|
|
||||||
(*svc)->stop_http();
|
(*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();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user