Skip to content

fix(domain): align product categories with schema enums - #58

Merged
LKSNDRTMLKV merged 1 commit into
mainfrom
fix/sli-vocabulary
Jul 25, 2026
Merged

fix(domain): align product categories with schema enums#58
LKSNDRTMLKV merged 1 commit into
mainfrom
fix/sli-vocabulary

Conversation

@LKSNDRTMLKV

Copy link
Copy Markdown
Member

One concept, two spellings — in two sectors. Flagged by Codacy on #56.

The drift

Sector Catalog said Schema enum says Property
battery sli starting-lighting-ignition batteryType
unsold-goods clothing_accessories accessories productCategory

Codacy found the first. The drift guard added here found the second.

Both catalogs now use the schema spelling, on the rule that the schema is what real data validates against — and for battery it also has a typed home, BatteryType::Sli already carrying #[serde(rename = "starting-lighting-ignition")].

Why nothing was broken

SectorDescriptor::product_categories has no reader anywhere in Rust. (verify.rs:156 reads credential.credential_subject.product_categories — the credential's own scope, a different field.) So today it is declared data with no consumer, which is why the mismatch was invisible. It becomes load-bearing the moment a first reader appears, which is the worst moment to discover the spellings disagree.

The actual fix

product_categories_are_legal_values_of_their_schema_enum in catalog/tests.rs. The rename alone just resets the clock; this is what stops it recurring.

The correspondence is not derivable — categories live under productCategory, productType, batteryType, productFamily, productionRoute or tyreClass depending on sector — so it is declared in a 9-row table rather than inferred by convention. A sector absent from the table is skipped; textile is the real case, declaring categories with no schema enum to check against. If a schema property is renamed the row panics loudly rather than silently skipping.

Verified non-vacuous by reintroducing sli and confirming the failure names both the offending value and the legal set:

sector 'battery' lists product category 'sli', which is not a legal value of
schema property 'batteryType' (["portable", "industrial", "ev", "lmt", "starting-lighting-ignition"])

Found, not fixed

textile declares home_textile in snake_case while comparable sectors use kebab-case, and the unsold-goods schema spells the same concept home-textile. It has no schema enum, so the guard cannot reach it. That is a naming-convention decision across the whole catalog rather than a correctness fix.

Verification

just check green: 814 tests, plugin suites included. just build-plugins green.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR successfully aligns the battery and unsold-goods sectors with schema enums and implements a drift-guard test to prevent future regressions. Codacy quality results are up to standards. The review identified two primary improvements for the new test logic in crates/dpp-domain/src/catalog/tests.rs: the test currently assumes a flat JSON schema structure which may break if schemas evolve to use $ref or allOf, and it relies on a manual mapping table that could allow new sectors to bypass validation if omitted. Overall, the logic is sound and meets the primary acceptance criteria.

About this PR

  • The new drift-guard test is a positive step for data integrity. To ensure its long-term effectiveness, consider the risk that new sectors added to the catalog might be silently ignored if the mapping table is not updated. Ensuring a default-fail or explicit-exemption policy for all sectors would make this check more robust.

Test suggestions

  • Verify battery sector categories match the 'batteryType' schema enum
  • Verify unsold-goods sector categories match the 'productCategory' schema enum
  • Ensure drift guard fails when a catalog category is missing from the schema enum
  • Ensure drift guard correctly maps sectors to their specific schema property names (e.g., tyreClass, productionRoute)

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

/// `SectorDescriptor::product_categories` has no reader in Rust today; both
/// would have become load-bearing the moment one appeared.
#[test]
fn product_categories_are_legal_values_of_their_schema_enum() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Suggestion: This drift-guard test ensures consistency between the catalog and schemas. To prevent new sectors from silently bypassing this check, consider adding a secondary check that verifies every sector in the catalog with categories is either present in CATEGORY_ENUM_PROPERTY or explicitly exempted.

Try running the following prompt in your IDE agent:

Update the test product_categories_are_legal_values_of_their_schema_enum in crates/dpp-domain/src/catalog/tests.rs to include a validation step that ensures all sectors in the catalog which define product_categories are either included in the CATEGORY_ENUM_PROPERTY table or are explicitly marked as exempt (e.g., 'textile'). This will ensure that future additions to the domain model are automatically validated against their respective schemas.

let schema: serde_json::Value =
serde_json::from_str(schema_json).expect("schema is valid JSON");

let allowed: Vec<&str> = schema["properties"][property]["enum"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Nitpick: The direct lookup of the enum property assumes a flat schema structure. If schemas are updated to use $ref or allOf to define these properties, the test will fail to find the valid values. Consider adding a comment about this structural dependency or confirming that the registry provides dereferenced schemas.

Try running the following prompt in your coding agent:

In crates/dpp-domain/src/catalog/tests.rs, enhance the product_categories_are_legal_values_of_their_schema_enum test to handle cases where the enum might be nested within a $ref or an allOf block, or verify if the VersionedSchemaRegistry provides dereferenced JSON.

@LKSNDRTMLKV
LKSNDRTMLKV merged commit c7066b2 into main Jul 25, 2026
11 checks passed
@LKSNDRTMLKV
LKSNDRTMLKV deleted the fix/sli-vocabulary branch July 25, 2026 14:24
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