feat(schema): from_resolved_toml + validate#4
Merged
Conversation
Chunk M1-W1-B of M1 plan. Lands the two pure functions Plan §6.1 calls out, plus four canonical fixtures and 12 unit tests. pub fn from_resolved_toml(s: &str) -> Result<DeclaredState, SchemaError>: - Single-shot toml::from_str into DeclaredState. The existing SchemaError::InvalidToml variant wraps toml::de::Error via #[from], so the implementation is a one-liner; the value is in fixtures + error-path tests. pub fn validate(d: &DeclaredState) -> Result<(), Vec<ContractViolation>>: - DUPLICATE_PACKAGES — every package name appears in at most one list across PackageSet and the two RemovePolicy lists. Violations name every list the duplicate appeared in. - KERNEL_MODULES_NOT_UNIQUE — kernel.modules and kernel.blacklist each contain unique entries, and the two are disjoint. - ARCH_LEVEL_MISMATCH — meta.arch_level = "v3" forbids a non-empty packages.cachyos-v4, and symmetrically. (PRD §6.2 makes this relationship explicit; Plan §6.1 listed only the first two contracts but this is in the same spirit.) validate() collects every violation rather than returning the first. Fixtures (fixtures/schema/): - host_minimal.toml — meta + kernel.package only. - host_full.toml — every section populated, two users (one with HM, one without), two config entries, custom snapshots.keep. - host_invalid_arch.toml — bogus arch_level = "v5". - host_malformed_mode.toml — mode as a string instead of an integer. Tests: - parse: parse_minimal_succeeds, parse_full_succeeds, reject_invalid_arch_level, reject_malformed_mode. - validate: validate_clean_minimal, validate_clean_full_fixture, validate_duplicate_packages, validate_kernel_modules_overlap, validate_kernel_modules_duplicate_within_list, validate_arch_level_v3_with_v4_packages, validate_arch_level_v4_with_v3_packages, validate_collects_multiple_violations. What's NOT in this chunk: - Property tests (chunk M1-W1-C with proptest). - JsonSchema Draft-2020-12 fixture (chunk M1-W1-C). Verification: - cargo test -p pearlite-schema (12 passed; 0 failed) - cargo clippy --workspace --all-targets -- -D warnings (zero warnings) - cargo fmt --all --check - scripts/ci/check-spdx.sh - pearlite-audit check . (1 check, 0 violations) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chunk M1-W1-B of M1 plan. Lands the two pure functions Plan §6.1 calls out, plus four canonical fixtures and 12 unit tests.
API
from_resolved_tomlis a single-shottoml::from_str— the value here is in the fixtures and error-path tests.validateruns three contract checks and collects every violation rather than returning the first.Contracts
DUPLICATE_PACKAGESPackageSet+ the twoRemovePolicylists.KERNEL_MODULES_NOT_UNIQUEkernel.modulesandkernel.blacklisteach unique, and disjoint.ARCH_LEVEL_MISMATCHarch_level = "v3"forbids non-emptypackages.cachyos-v4, and symmetrically. (Inferred from PRD §6.2's schema.)Fixtures
fixtures/schema/:host_minimal.toml— meta +kernel.packageonly.host_full.toml— every section populated.host_invalid_arch.toml— bogusarch_level = "v5".host_malformed_mode.toml— mode as a string instead of an integer.Tests
12 total, all passing:
parse_minimal_succeeds,parse_full_succeeds,reject_invalid_arch_level,reject_malformed_mode.validate_clean_minimal,validate_clean_full_fixture,validate_duplicate_packages,validate_kernel_modules_overlap,validate_kernel_modules_duplicate_within_list,validate_arch_level_v3_with_v4_packages,validate_arch_level_v4_with_v3_packages,validate_collects_multiple_violations.Out of scope
proptest(chunk M1-W1-C).JsonSchemaDraft-2020-12 fixture (chunk M1-W1-C).Verification
cargo test -p pearlite-schema— 12 passed; 0 failedcargo clippy --workspace --all-targets -- -D warnings— zero warningscargo fmt --all --checkscripts/ci/check-spdx.shpearlite-audit check .— 1 check, 0 violations🤖 Generated with Claude Code