Add link requirement and unknown category isolation

MR adds two new validation checks to the features.yml file:

  1. Unknown category isolation: ensure that the unknown category is not used with other categories.
  2. Require a link for all features unless category is unknown. Also fixes 19 violations.

Related to Product#14293 (closed)

Duo summary

Features Checker (lib/features/features_yml_checker.rb)

New Functionality Added:

  1. Unknown Category Isolation Validation

    • Added check_unknown_category_isolation method
    • Prevents mixing "unknown" with other categories
    • Error message: "category 'unknown' cannot be combined with other categories: [list]"
  2. Stricter Link Requirement Logic

    • Updated category_is_unknown? method to only return true when category is exactly ['unknown']
    • Previously: returned true if "unknown" was anywhere in the categories array
    • Now: returns true only if the entire categories array is ['unknown']

Performance Optimizations:

  1. Single Category Extraction

    • Added extract_categories method using Ruby's Array() pattern (consistent with existing codebase)
    • Categories now extracted once per feature instead of 3 times
    • All validation methods updated to accept categories as parameter
  2. Method Signature Updates:

    • check_category_validity - now takes categories parameter
    • check_link_requirement - now takes categories parameter
    • check_unknown_category_isolation - now takes categories parameter
    • category_is_unknown? - now takes categories parameter instead of feature_data

Integration:

  1. Updated Validation Pipeline
    • Added check_unknown_category_isolation to the validation sequence
    • All methods now receive pre-extracted categories

Test File (spec/features/features_yml_checker_spec.rb)

Test Coverage Improvements:

  1. Removed Redundant Tests (earlier in conversation):

    • Removed duplicate positive validation tests
    • Removed redundant link validation tests
    • Streamlined from ~15 tests to 11 focused tests
  2. Added New Test Cases:

    • 'fails when unknown is mixed with valid categories' - expects 2 errors (isolation + link requirement)
    • 'fails when unknown is mixed with invalid categories' - expects 3 errors (invalid category + isolation + link requirement)
    • 'passes when multiple valid categories are used' - validates array categories work correctly
    • Kept existing 'passes when link is missing but category is unknown' test

Test Expectations Updated:

  1. Accurate Error Counts
    • Tests now expect correct number of validation errors
    • Account for cascading effects of stricter category_is_unknown? logic

Real Data Impact (data/features.yml)

Validation Results:

  • Before changes: 19 validation errors (missing link fields)
  • After changes: 0 validation errors
  • Errors fixed: 19 errors resolved

The real data/features.yml file now passes validation completely, indicating:

  1. No features currently mix "unknown" with other categories
  2. All features that were missing links have been fixed
  3. The new validation rules don't break existing valid data

Overall Impact:

  • Functionality: Enhanced validation with semantic correctness for "unknown" categories
  • Performance: ~67% reduction in category extraction operations
  • Quality: Comprehensive test coverage with no redundancy
  • Compatibility: All existing valid data continues to pass validation
  • Standards: Code follows project conventions and passes rubocop

The implementation successfully adds new validation rules while maintaining backward compatibility and improving performance.

Edited by Cynthia "Arty" Ng

Merge request reports

Loading