Skip to content

Add deterministic cooldown decisions - #11

Merged
andrew merged 2 commits into
mainfrom
issue-10-deterministic-decisions
Aug 16, 2026
Merged

Add deterministic cooldown decisions#11
andrew merged 2 commits into
mainfrom
issue-10-deterministic-decisions

Conversation

@andrew

@andrew andrew commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Adds deterministic cooldown evaluation with the selected duration, availability time, and typed reason. Keeps the existing boolean API as a current-time wrapper.

Fixes #10

Copilot AI 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

Adds a deterministic cooldown evaluation API so callers can reproduce decisions at a supplied evaluation time and understand why a version is allowed/blocked (including selected cooldown, availability timestamp, and a typed reason), while keeping IsAllowed as a current-time wrapper for backwards compatibility.

Changes:

  • Introduces Decision/Reason types and a new Config.Evaluate(..., evaluatedAt) method returning structured cooldown decisions.
  • Refactors Config.IsAllowed to delegate to Evaluate using time.Now().
  • Updates README usage/docs and adds unit tests covering the new decision behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
README.md Documents Config.Evaluate and adds an example showing decision/availability output.
cooldown.go Adds Reason/Decision and implements deterministic evaluation via Config.Evaluate.
cooldown_test.go Adds TestConfigEvaluate to validate decision outputs for disabled/elapsed/waiting/unknown cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cooldown.go Outdated
Comment on lines 113 to 117
if cooldown == 0 {
decision.Allowed = true
decision.Reason = ReasonDisabled
return decision
}
Comment thread cooldown_test.go
Comment on lines +127 to +145
{
name: "disabled",
packagePURL: "pkg:npm/lodash",
publishedAt: evaluatedAt.Add(-time.Minute),
want: Decision{
Allowed: true,
AvailableAt: evaluatedAt.Add(-time.Minute),
Reason: ReasonDisabled,
},
},
{
name: "unknown publication time",
packagePURL: "pkg:npm/express",
want: Decision{
Allowed: true,
Cooldown: 3 * 24 * time.Hour,
Reason: ReasonUnknownPublicationTime,
},
},
@andrew
andrew merged commit f6aeee7 into main Aug 16, 2026
2 checks passed
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.

Add deterministic cooldown decisions with reasons

2 participants