Skip to content

feat(schema): from_resolved_toml + validate#4

Merged
UnbreakableMJ merged 1 commit into
mainfrom
feat/schema-parse-validate
Apr 27, 2026
Merged

feat(schema): from_resolved_toml + validate#4
UnbreakableMJ merged 1 commit into
mainfrom
feat/schema-parse-validate

Conversation

@UnbreakableMJ

Copy link
Copy Markdown
Contributor

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

pub fn from_resolved_toml(s: &str) -> Result<DeclaredState, SchemaError>
pub fn validate(d: &DeclaredState) -> Result<(), Vec<ContractViolation>>

from_resolved_toml is a single-shot toml::from_str — the value here is in the fixtures and error-path tests. validate runs three contract checks and collects every violation rather than returning the first.

Contracts

ID Check
DUPLICATE_PACKAGES Every package name appears in at most one list across PackageSet + the two RemovePolicy lists.
KERNEL_MODULES_NOT_UNIQUE kernel.modules and kernel.blacklist each unique, and disjoint.
ARCH_LEVEL_MISMATCH arch_level = "v3" forbids non-empty packages.cachyos-v4, and symmetrically. (Inferred from PRD §6.2's schema.)

Fixtures

fixtures/schema/:

  • host_minimal.toml — meta + kernel.package only.
  • host_full.toml — every section populated.
  • host_invalid_arch.toml — bogus arch_level = "v5".
  • host_malformed_mode.toml — mode as a string instead of an integer.

Tests

12 total, all passing:

  • 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.

Out of scope

  • Property tests with proptest (chunk M1-W1-C).
  • 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

🤖 Generated with Claude Code

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>
@UnbreakableMJ
UnbreakableMJ merged commit 9b9c8e0 into main Apr 27, 2026
3 checks passed
@UnbreakableMJ
UnbreakableMJ deleted the feat/schema-parse-validate branch April 27, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant