-
Notifications
You must be signed in to change notification settings - Fork 58
Add required-test-attestations rule data #1788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
joejstuart
wants to merge
2
commits into
conforma:main
Choose a base branch
from
joejstuart:EC-1951
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Time-Gated Rule Data | ||
|
|
||
| Rule data entries with `effective_on` dates allow gradual rollout of policy requirements. The `ectime` library resolves which entry applies now (`most_current`) and which is newest regardless of date (`newest`). Several packages use this pattern: `required_tasks`, `test_attestation`, and their release-side counterparts. | ||
|
|
||
| ## How do `most_current` and `newest` differ in failure behavior? | ||
|
|
||
|
joejstuart marked this conversation as resolved.
|
||
| `newest` sorts entries by `effective_on` as a string and picks the last one. It almost always succeeds for non-empty input — it doesn't parse or validate dates. `most_current` parses each `effective_on` with `time.parse_rfc3339_ns`, filters to entries not in the future, then calls `newest` on that filtered set. It is undefined when all entries are in the future. | ||
|
|
||
| This asymmetry matters: checking `not ectime.newest(data)` is almost never true when data exists, so it's not a useful guard on its own. The meaningful existence check is whether the resolution path produces an entry with the expected fields (e.g., `.tests` or `.tasks`). | ||
|
|
||
| ## Why do consumer helpers need `default` values? | ||
|
|
||
| Rego's `not X in Y` requires `Y` to be defined. If `Y` is undefined, Rego tries to bind `Y` before evaluating the `in` expression, and the undefined binding causes the entire rule body to fail — `not` does not rescue it. This means helpers consumed by rules that use `in` or `some ... in` must always be defined. | ||
|
|
||
| Use `default _helper := []` (not `else := []`) to provide the fallback. `default` is the canonical Rego mechanism for ensuring a rule always has a value. `else := []` works but conflates "couldn't resolve" with "resolved to empty," making existence checks on the same helper unreliable. | ||
|
|
||
| ## What is the pattern for adding new time-gated rule data? | ||
|
|
||
| Follow the separation used by `required_tasks` and `test_attestation`: | ||
|
|
||
| 1. **Consumer helpers** — always defined via `default`, safe for `in` expressions: | ||
| ```rego | ||
| default _current_required_items := [] | ||
| _current_required_items := entry.items if { | ||
| entry := ectime.most_current(_rule_data) | ||
| } | ||
| ``` | ||
|
|
||
| 2. **Existence checks** — undefined-based boolean helpers (no default/else) for deny/warn guards: | ||
| ```rego | ||
| _resolved_required_items if { | ||
| ectime.most_current(_rule_data).items | ||
| } | ||
| _resolved_required_items if { | ||
| ectime.newest(_rule_data).items | ||
| } | ||
| ``` | ||
|
|
||
| 3. **Deny rule** — checks data exists but resolution fails: | ||
| ```rego | ||
| deny contains result if { | ||
| count(_rule_data) > 0 | ||
| not _resolved_required_items | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| The boolean helper uses two rule bodies (OR): it's true if either current or newest resolves to an entry with the expected field. The deny fires only when data was provided but neither path produces a usable entry. | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.