Skip to content

fix: explicit probability 0 means never (unset stays always) - #1

Merged
achoimet merged 1 commit into
mainfrom
fix/probability-zero-means-never
Aug 27, 2026
Merged

achoimet merged 1 commit into
mainfrom
fix/probability-zero-means-never

Conversation

@achoimet

Copy link
Copy Markdown
Member

Problem

fault.Match clamped probability <= 0 up to 1.0, so a rule explicitly configured to fault 0% of connections faulted 100% instead. The float zero-value could not express "never" — it was indistinguishable from "unset".

Fix

Rule.Probability becomes *float64:

  • nil (unset) → always (1.0) — preserves the standalone convenience of omitting probability
  • explicit value, including 0 → honored (0 = never)

The CLI flag --fault-probability now defaults to 1 (always), and the JSON RuleDTO defaults nil to always. So "omit = always" is unchanged, while an explicit 0 now correctly means never.

This pairs with the extension change (percentageToProbability clamps to [0,1]), so a 0% Percentage in the UI now means "never fault" as expected.

Tests

  • TestMatch_UnsetProbabilityMeansAlways (nil → always)
  • TestMatch_ExplicitZeroProbabilityMeansNever (0 → never)
  • config: unset defaults to always, explicit 0 accepted. All unit tests pass.

Match clamped probability <= 0 up to 1.0, so a rule that explicitly asked
to fault 0% of connections faulted 100% instead. The zero value could not
express 'never'.

Make Rule.Probability a *float64: nil (unset) defaults to always, an
explicit value — including 0 (never) — is honored. The CLI flag defaults to
1 (always) and the JSON DTO defaults nil to always, so 'omit = always' is
preserved while 0 now correctly means never.
@achoimet
achoimet merged commit 2147abd into main Aug 27, 2026
3 checks passed
@achoimet
achoimet deleted the fix/probability-zero-means-never branch August 27, 2026 12:29
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