[M5+] add resolver::nixpkgs_probe (nix eval wrapper)

This commit is contained in:
2026-05-10 09:52:06 +00:00
parent f3d18b7939
commit 1c7ff39f64
7 changed files with 239 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#include <catch2/catch_test_macros.hpp>
import cargoxx.resolver;
import cargoxx.util;
import std;
using cargoxx::resolver::parse_nix_eval_json;
using cargoxx::util::ErrorCode;
TEST_CASE("parse_nix_eval_json extracts version and outPath", "[resolver][nixpkgs]") {
constexpr std::string_view input = R"({
"version": "3.7.0",
"path": "/nix/store/abc-simdjson-3.7.0"
})";
auto r = parse_nix_eval_json("simdjson", input);
REQUIRE(r.has_value());
REQUIRE(r->attr == "simdjson");
REQUIRE(r->version == "3.7.0");
REQUIRE(r->out_path == "/nix/store/abc-simdjson-3.7.0");
}
TEST_CASE("parse_nix_eval_json accepts an empty version field",
"[resolver][nixpkgs]") {
constexpr std::string_view input = R"({
"version": "",
"path": "/nix/store/xyz-foo"
})";
auto r = parse_nix_eval_json("foo", input);
REQUIRE(r.has_value());
REQUIRE(r->version.empty());
REQUIRE(r->out_path == "/nix/store/xyz-foo");
}
TEST_CASE("parse_nix_eval_json fails when outPath is missing",
"[resolver][nixpkgs]") {
constexpr std::string_view input = R"({"version": "1.0"})";
auto r = parse_nix_eval_json("foo", input);
REQUIRE_FALSE(r.has_value());
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
}
TEST_CASE("parse_nix_eval_json fails on garbage input", "[resolver][nixpkgs]") {
auto r = parse_nix_eval_json("foo", "not-json-at-all");
REQUIRE_FALSE(r.has_value());
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
}
TEST_CASE("parse_nix_eval_json fails on a non-object root",
"[resolver][nixpkgs]") {
auto r = parse_nix_eval_json("foo", "[]");
REQUIRE_FALSE(r.has_value());
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
}