Skip to content

test(tariff): Hypothesis fuzz the five tariff_engine invariants (Phase 11 PR-18)#102

Merged
Artic0din merged 1 commit into
feat/hassfest-hacs-cifrom
feat/tariff-engine-hypothesis
May 22, 2026
Merged

test(tariff): Hypothesis fuzz the five tariff_engine invariants (Phase 11 PR-18)#102
Artic0din merged 1 commit into
feat/hassfest-hacs-cifrom
feat/tariff-engine-hypothesis

Conversation

@Artic0din

Copy link
Copy Markdown
Owner

Final v2.0 GA plank. 5 invariants from v2 research § 7.3 covered by Hypothesis property-based tests. 9 new test classes; 1054 total. Stacked on PR #101.

…e 11 PR-18)

PR-18 — Final v2.0 GA plank. Property-based tests cover the five
invariants from v2 research § 7.3 for tariff_engine pure functions
(calc_stepped_cost, get_stepped_import_rate, get_current_tou_period).

- 1. Monotonic stepped cost: cost(k1) <= cost(k2) for k1 <= k2.
- 2. Threshold equality: cost(threshold) == threshold * step1_rate.
- 3. Step composition above threshold: cost = step1_cost +
     (k - threshold) * step2_rate.
- 4. Stepped rate dichotomy: returned rate is exactly step1 or step2.
- 5. TOU period closure: returned period name is in the supplied
     dict OR "unknown"; rate matches the period when found; full-day
     coverage produces no "unknown".

≥ 200 fuzzed examples per invariant via hypothesis. 9 test classes.
1054 total pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Artic0din added a commit that referenced this pull request May 22, 2026
Narrow scope: only edits dual-loop-review.yml (the Claude AI review
workflow). PRs targeting dev now trigger Claude review, which is the
core need for the stacked v3.0 PR series.

The other 5 workflows (python-ci, pr-checks, lint, docs-check,
security-scan) also have the same `[main, develop]` gate but expose
pre-existing failures when extended to dev:
- python-ci.yml mypy: 27 baseline type errors in tests
- pr-checks.yml: CodeRabbit gate still checks for CR approval despite
  CLAUDE.md saying CR is not used
- security-scan.yml gitleaks: flags string-literal test secrets in
  tests/test_reauth.py + others; needs allowlist for test fixtures
- dual-loop-review run for THIS PR hit an upstream tsconfig
  directory-mismatch bug in the anthropics/claude-code-action@v1
  action; transient

Each is a separate cleanup PR. Landing this narrow change unblocks
the Claude AI review path for the 17 stacked PRs without sweeping
unrelated debt under the rug.

After merge: the 17 stacked PRs (#87..#102) trigger dual-loop-review
on next synchronize (push, rebase, or empty commit).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Artic0din added a commit that referenced this pull request May 22, 2026
Narrow scope: only edits dual-loop-review.yml (the Claude AI review
workflow). PRs targeting dev now trigger Claude review, which is the
core need for the stacked v3.0 PR series.

The other 5 workflows (python-ci, pr-checks, lint, docs-check,
security-scan) also have the same `[main, develop]` gate but expose
pre-existing failures when extended to dev:
- python-ci.yml mypy: 27 baseline type errors in tests
- pr-checks.yml: CodeRabbit gate still checks for CR approval despite
  CLAUDE.md saying CR is not used
- security-scan.yml gitleaks: flags string-literal test secrets in
  tests/test_reauth.py + others; needs allowlist for test fixtures
- dual-loop-review run for THIS PR hit an upstream tsconfig
  directory-mismatch bug in the anthropics/claude-code-action@v1
  action; transient

Each is a separate cleanup PR. Landing this narrow change unblocks
the Claude AI review path for the 17 stacked PRs without sweeping
unrelated debt under the rug.

After merge: the 17 stacked PRs (#87..#102) trigger dual-loop-review
on next synchronize (push, rebase, or empty commit).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Artic0din Artic0din merged commit 65a6889 into feat/hassfest-hacs-ci May 22, 2026
4 checks passed
@Artic0din Artic0din deleted the feat/tariff-engine-hypothesis branch May 22, 2026 04:50
Artic0din added a commit that referenced this pull request May 23, 2026
…CI (#143)

Four findings from a 2026-05-23 @claude retro-review of merged PRs.

- providers/openelectricity.py: ``_is_auth_error`` no longer matches the
  bare word ``forbidden`` in exception messages — TLS/corporate-proxy
  errors with that word were mis-classified as ``ConfigEntryAuthFailed``,
  prompting users to re-enter their API key when the real problem is
  connectivity. Auth detection now keys on auth-specific message tokens
  (401, unauthorized, invalid api key); the class-name check still
  catches genuine ``*Forbidden*`` exception types. New regression test
  test_tls_error_with_forbidden_word_is_not_auth_failure. (Retro #86)

- tests/test_tariff_engine_hypothesis.py: three property tests used
  ``if k <= threshold: return`` to early-exit out-of-range draws,
  which Hypothesis treats as PASSED rather than discarded. With
  max_examples=200 and ~75% of draws hitting the early return, the
  effective constrained-region coverage was ~50 examples per invariant
  instead of 200. Switched to ``assume(k > threshold)`` / ``assume(k <
  threshold)`` / ``assume(k >= threshold)`` so Hypothesis discards and
  regenerates until 200 valid examples are spent in the interesting
  region. Tolerance also aligned to 1e-9 across invariants 2 + 3
  (single bounded-float multiplications have round-trip error <
  ~4e-12, so the tight value is safe). (Retro #102)

- .github/workflows/dual-loop-review.yml: dropped ``develop`` from the
  pull_request branches filter — ``gh api repos/.../branches`` confirms
  no ``develop`` branch exists; it was a stale alias from the template
  that silently never matched. Filter now ``[main, dev]``. (Retro #103)

PR #84 review noted no issues (after_dependencies fix verified correct);
no change here for that PR.

Full test suite: 1119 passing locally.
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