Skip to content

feat(tree): validate YANG unique list constraints#448

Open
steiler wants to merge 1 commit into
mainfrom
feat/yang-unique-constraint
Open

feat(tree): validate YANG unique list constraints#448
steiler wants to merge 1 commit into
mainfrom
feat/yang-unique-constraint

Conversation

@steiler

@steiler steiler commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add validation_entry_unique.go: walks list children, collects leaf values per unique statement, reports violations
  • Wire into validation_dispatch.go and ValidationStats
  • Add test YANG schema (sdcio_model_list_unique.yang) covering single-leaf, multi-leaf composite, and descendant-path unique statements
  • Regenerate tests/sdcioygot/sdcio_schema.go with updated schema

Closes #445

Related

Implement unique constraint validation in the tree validation pipeline.
Reads UniqueConstraint entries from ContainerSchema, collects leaf
values across all list entries, and reports violations via
ValidationStats. Covers single-leaf, multi-leaf composite, and
descendant-path unique statements.

Co-authored-by: Cursor <cursoragent@cursor.com>
@steiler steiler force-pushed the feat/yang-unique-constraint branch from db96bc0 to 0b9a3ec Compare June 5, 2026 13:12
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.20792% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/tree/ops/validation/validation_entry_unique.go 82.10% 10 Missing and 7 partials ⚠️
pkg/config/validation.go 0.00% 2 Missing ⚠️
pkg/tree/types/validation_stats.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 10 to +11
unique "ip port";
unique "description";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should these not be in one unique entry?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

According to the YANG 1.1 Specification (RFC 7950, Section 7.8.3), the unique statement can be used multiple times within a single list definition.

Because each unique statement enforces a distinct constraint on a different set of leafes, our validation logic must iterate through all instances of the statement rather than assuming a single occurrence per list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so there is no difference between

unique "ip port xyz"

and

unique "ip port"
unique "xyz"

?

I couldn't get this from the RFC

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

so there is no difference between

unique "ip port xyz"

and

unique "ip port"
unique "xyz"

?

I couldn't get this from the RFC

No — they are not the same. Each unique statement is one constraint; multiple unique statements mean multiple independent constraints.

unique "ip port xyz" (one constraint)

This enforces uniqueness of the composite (ip, port, xyz) across list entries (with the usual RFC rules for missing/empty values). Two entries may share the same ip and port if xyz differs, because it is the full triple that must not repeat.

unique "ip port" plus unique "xyz" (two constraints)

  1. unique "ip port" — the pair (ip, port) must not repeat. Same ip+port on two rows is invalid even if xyz differs.
  2. unique "xyz"xyz must not repeat by itself, even if ip/port differ.

So the second form is not equivalent: it adds a separate uniqueness requirement on (ip, port) and another on xyz alone.

Tiny example

Assume all three leaves are set:

Scenario Row A Row B unique "ip port xyz" unique "ip port" + unique "xyz"
Same ip,port; different xyz 1,1,a 1,1,b OK Fails unique "ip port"
Different ip,port; same xyz 1,1,x 2,2,x OK Fails unique "xyz"

RFC reference: RFC 7950 §7.8.3 (unique statement).

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.

Implement YANG unique list constraint at instance validation

2 participants