Update: align component feed identities
CI / GCC 16 / C++26 / werror (push) Failing after 1m57s
CI / GCC 16 / C++26 / default (push) Failing after 2m36s
CI / GCC 16 / C++26 / sanitizers (push) Failing after 2m39s

This commit is contained in:
faumaray committed 2026-07-29 00:41:57 +03:00
1 parent 05815c4668
commit 7edce967f2
3 files changed
+100 -11

No files matched your search

+6 -1
View File
@@ -100,6 +100,7 @@ namespace Void::Update
std::string kind; std::string kind;
Semver::Version componentVersion; Semver::Version componentVersion;
std::string activation; std::string activation;
std::map<std::string, std::string> dependencyConstraints;
std::map<std::string, Semver::VersionRange> dependencies; std::map<std::string, Semver::VersionRange> dependencies;
std::uint64_t sequence{0}; std::uint64_t sequence{0};
std::string latestUrl; std::string latestUrl;
@@ -129,9 +130,13 @@ namespace Void::Update
Semver::Version componentVersion; Semver::Version componentVersion;
std::string sourceSha; std::string sourceSha;
std::string sourceTreeHash; std::string sourceTreeHash;
std::string abiHash; std::optional<std::string> abiHash;
std::string artifactIdentity; std::string artifactIdentity;
std::string activation; std::string activation;
std::string platform;
std::string architecture;
std::string toolchainContract;
std::map<std::string, std::string> dependencyConstraints;
std::map<std::string, Semver::VersionRange> dependencies; std::map<std::string, Semver::VersionRange> dependencies;
ComponentArtifact artifact; ComponentArtifact artifact;
}; };
+74 -7
View File
@@ -101,6 +101,21 @@ namespace Void::Update
}); });
} }
[[nodiscard]] bool
valid_prefixed_hash(std::string_view value, std::string_view prefix,
std::size_t hexadecimalSize) noexcept
{
if (!value.starts_with(prefix)) {
return false;
}
const auto hexadecimal = value.substr(prefix.size());
return hexadecimal.size() == hexadecimalSize &&
std::ranges::all_of(hexadecimal, [](const char character) {
return (character >= '0' && character <= '9') ||
(character >= 'a' && character <= 'f');
});
}
[[nodiscard]] bool valid_hex(std::string_view value, [[nodiscard]] bool valid_hex(std::string_view value,
std::size_t size) noexcept std::size_t size) noexcept
{ {
@@ -395,6 +410,20 @@ namespace Void::Update
return std::optional<std::string>{value->as_string()}; return std::optional<std::string>{value->as_string()};
} }
[[nodiscard]] Void::Result::Result<std::optional<std::string>>
optional_string(const Json::Value& object, std::string_view name)
{
const auto* value = object.find(name);
if (value == nullptr || value->is_null()) {
return std::optional<std::string>{};
}
if (!value->is_string()) {
return Void::Result::fail(std::format(
"Component feed: {} must be null or a string", name));
}
return std::optional<std::string>{value->as_string()};
}
[[nodiscard]] Void::Result::Result< [[nodiscard]] Void::Result::Result<
std::map<std::string, Semver::VersionRange>> std::map<std::string, Semver::VersionRange>>
parse_dependencies(const Json::Value& object) parse_dependencies(const Json::Value& object)
@@ -421,6 +450,27 @@ namespace Void::Update
return result; return result;
} }
[[nodiscard]] Void::Result::Result<std::map<std::string, std::string>>
parse_dependency_constraints(const Json::Value& object)
{
const auto* dependencies = object.find("dependencies");
if (dependencies == nullptr || !dependencies->is_object()) {
return Void::Result::fail(
"Component feed: dependencies must be an object");
}
std::map<std::string, std::string> result;
for (const auto& [component, value] : dependencies->as_object()) {
if (!valid_token(component, 256) || !value.is_string() ||
value.as_string().empty() ||
value.as_string().size() > 512) {
return Void::Result::fail(
"Component feed: dependency contains an unsafe field");
}
result.emplace(component, value.as_string());
}
return result;
}
[[nodiscard]] Void::Result::Result<ComponentDocumentHeader> [[nodiscard]] Void::Result::Result<ComponentDocumentHeader>
parse_component_header(const Json::Value& document, parse_component_header(const Json::Value& document,
std::string_view expectedDocument, std::string_view expectedDocument,
@@ -490,12 +540,14 @@ namespace Void::Update
auto sequence = unsigned_number<std::uint64_t>(value, "sequence"); auto sequence = unsigned_number<std::uint64_t>(value, "sequence");
auto latestUrl = string_member(value, "latestUrl"); auto latestUrl = string_member(value, "latestUrl");
auto artifactSha = string_member(value, "artifactSha256"); auto artifactSha = string_member(value, "artifactSha256");
auto dependencyConstraints = parse_dependency_constraints(value);
auto dependencies = parse_dependencies(value); auto dependencies = parse_dependencies(value);
if (!componentId || !pluginId || !kind || !versionText || if (!componentId || !pluginId || !kind || !versionText ||
!activation || !sequence || !latestUrl || !artifactSha || !activation || !sequence || !latestUrl || !artifactSha ||
!dependencies || !valid_token(*componentId, 256) || !dependencyConstraints || !dependencies ||
!valid_token(*kind, 128) || !valid_token(*activation, 128) || !valid_token(*componentId, 256) || !valid_token(*kind, 128) ||
!bounded_url(*latestUrl) || !valid_sha256(*artifactSha)) { !valid_token(*activation, 128) || !bounded_url(*latestUrl) ||
!valid_sha256(*artifactSha)) {
return Void::Result::fail( return Void::Result::fail(
"Component feed: catalog entry contains an unsafe field"); "Component feed: catalog entry contains an unsafe field");
} }
@@ -510,6 +562,7 @@ namespace Void::Update
.kind = std::move(*kind), .kind = std::move(*kind),
.componentVersion = std::move(*version), .componentVersion = std::move(*version),
.activation = std::move(*activation), .activation = std::move(*activation),
.dependencyConstraints = std::move(*dependencyConstraints),
.dependencies = std::move(*dependencies), .dependencies = std::move(*dependencies),
.sequence = *sequence, .sequence = *sequence,
.latestUrl = std::move(*latestUrl), .latestUrl = std::move(*latestUrl),
@@ -690,19 +743,28 @@ namespace Void::Update
auto componentVersion = string_member(*document, "componentVersion"); auto componentVersion = string_member(*document, "componentVersion");
auto sourceSha = string_member(*document, "sourceSha"); auto sourceSha = string_member(*document, "sourceSha");
auto sourceTreeHash = string_member(*document, "sourceTreeHash"); auto sourceTreeHash = string_member(*document, "sourceTreeHash");
auto abiHash = string_member(*document, "abiHash"); auto abiHash = optional_string(*document, "abiHash");
auto artifactIdentity = string_member(*document, "artifactIdentity"); auto artifactIdentity = string_member(*document, "artifactIdentity");
auto activation = string_member(*document, "activation"); auto activation = string_member(*document, "activation");
auto platform = string_member(*document, "platform");
auto architecture = string_member(*document, "architecture");
auto toolchainContract = string_member(*document, "toolchainContract");
auto dependencyConstraints = parse_dependency_constraints(*document);
auto dependencies = parse_dependencies(*document); auto dependencies = parse_dependencies(*document);
const auto* artifactValue = document->find("artifact"); const auto* artifactValue = document->find("artifact");
if (!header || !componentId || !pluginId || !kind || if (!header || !componentId || !pluginId || !kind ||
!componentVersion || !sourceSha || !sourceTreeHash || !abiHash || !componentVersion || !sourceSha || !sourceTreeHash || !abiHash ||
!artifactIdentity || !activation || !dependencies || !artifactIdentity || !activation || !platform || !architecture ||
!toolchainContract || !dependencyConstraints || !dependencies ||
artifactValue == nullptr || !artifactValue->is_object() || artifactValue == nullptr || !artifactValue->is_object() ||
!valid_token(*componentId, 256) || !valid_token(*kind, 128) || !valid_token(*componentId, 256) || !valid_token(*kind, 128) ||
!valid_token(*artifactIdentity, 256) || !valid_token(*artifactIdentity, 256) ||
!valid_token(*activation, 128) || !valid_hex(*sourceSha, 40) || !valid_token(*activation, 128) || !valid_token(*platform, 64) ||
!valid_sha256(*sourceTreeHash) || !valid_sha256(*abiHash)) { !valid_token(*architecture, 64) ||
!valid_token(*toolchainContract, 256) ||
!valid_hex(*sourceSha, 40) ||
!valid_prefixed_hash(*sourceTreeHash, "git-sha1:", 40) ||
(*abiHash && !valid_prefixed_hash(**abiHash, "sha256:", 64))) {
return Void::Result::fail( return Void::Result::fail(
"Component feed: release contains an unsafe field"); "Component feed: release contains an unsafe field");
} }
@@ -737,6 +799,10 @@ namespace Void::Update
.abiHash = std::move(*abiHash), .abiHash = std::move(*abiHash),
.artifactIdentity = std::move(*artifactIdentity), .artifactIdentity = std::move(*artifactIdentity),
.activation = std::move(*activation), .activation = std::move(*activation),
.platform = std::move(*platform),
.architecture = std::move(*architecture),
.toolchainContract = std::move(*toolchainContract),
.dependencyConstraints = std::move(*dependencyConstraints),
.dependencies = std::move(*dependencies), .dependencies = std::move(*dependencies),
.artifact = {.name = std::move(*artifactName), .artifact = {.name = std::move(*artifactName),
.url = std::move(*artifactUrl), .url = std::move(*artifactUrl),
@@ -769,6 +835,7 @@ namespace Void::Update
value.artifact.sha256 != entry.artifactSha256 || value.artifact.sha256 != entry.artifactSha256 ||
value.activation != entry.activation || value.activation != entry.activation ||
value.pluginId != entry.pluginId || value.kind != entry.kind || value.pluginId != entry.pluginId || value.kind != entry.kind ||
value.dependencyConstraints != entry.dependencyConstraints ||
value.dependencies.size() != entry.dependencies.size()) { value.dependencies.size() != entry.dependencies.size()) {
return Void::Result::fail(std::format( return Void::Result::fail(std::format(
"Component set: release {} does not match the catalog", "Component set: release {} does not match the catalog",
+20 -3
View File
@@ -151,10 +151,13 @@ namespace
"kind": "{}", "kind": "{}",
"componentVersion": "{}", "componentVersion": "{}",
"sourceSha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "sourceSha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"sourceTreeHash": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "sourceTreeHash": "git-sha1:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"abiHash": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "abiHash": {},
"artifactIdentity": "{}-{}-linux-x86_64", "artifactIdentity": "{}-{}-linux-x86_64",
"activation": "restart-required", "activation": "restart-required",
"platform": "linux",
"architecture": "x86_64",
"toolchainContract": "linux-x86_64-glibc-2.35-cxx26",
"dependencies": {}, "dependencies": {},
"artifact": {{ "artifact": {{
"name": "{}-{}.tar.zst", "name": "{}-{}.tar.zst",
@@ -166,7 +169,11 @@ namespace
}} }}
}})json", }})json",
componentId, componentId == "Api" ? "sdk" : "runtime-module", componentId, componentId == "Api" ? "sdk" : "runtime-module",
version, componentId, version, dependencies, componentId, version, version,
componentId == "Api"
? "null"
: R"("sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")",
componentId, version, dependencies, componentId, version,
componentId, version, artifactHash); componentId, version, artifactHash);
} }
} // namespace } // namespace
@@ -242,6 +249,16 @@ Void::Testing::Test component_feed_verifies_and_resolves_complete_set()
"{}")); "{}"));
Void::Testing::require(host.has_value()); Void::Testing::require(host.has_value());
Void::Testing::require(api.has_value()); Void::Testing::require(api.has_value());
Void::Testing::expect(!api->abiHash.has_value());
Void::Testing::require(host->abiHash.has_value());
Void::Testing::expect_eq(*host->abiHash,
std::string{"sha256:"
"ccccccccccccccccccccccccccccccccccccc"
"ccccccccccccccccccccccccccc"});
Void::Testing::expect_eq(
host->sourceTreeHash,
std::string{"git-sha1:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"});
Void::Testing::expect_eq(host->platform, std::string{"linux"});
std::map<std::string, Void::Update::ComponentRelease> releases; std::map<std::string, Void::Update::ComponentRelease> releases;
releases.emplace("Api", *api); releases.emplace("Api", *api);
releases.emplace("Host", *host); releases.emplace("Host", *host);