Skip to content

test: cover finding rules, model predicates, cost buckets, and region logic - #85

Merged
Bccorb merged 1 commit into
mainfrom
test/core-logic-coverage
Jul 20, 2026
Merged

test: cover finding rules, model predicates, cost buckets, and region logic#85
Bccorb merged 1 commit into
mainfrom
test/core-logic-coverage

Conversation

@Bccorb

@Bccorb Bccorb commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Closes #38.

A bug the tests found

Cost data failed to load on the first of every month.

month_to_date_from returned (first_of_month, today). On the 1st those are the same date, and Cost Explorer rejects that interval:

Start date (and hour) should be before end date (and hour)

I confirmed it against the live API rather than inferring it: the empty interval is rejected, a normal one is accepted. So on the 1st of each month every cost view reported Cost Explorer as unavailable, which would have looked like an intermittent permissions or outage problem.

Fixed by widening the window to cover the current day when it would otherwise collapse, verified against the live API for the 1st of a month, the 1st of January, and a mid-month control. All three now return real cost data.

Coverage

140 to 205 tests, across the four areas the issue names.

Finding rules: 11 of 25 exercised, now 25 of 25. The additions focus on the pairs that must not double-report, since that is where a rule change quietly breaks another: production versus general secret rotation, stopped instances that look important versus merely unused, idle load balancers versus failing ones, and zero-healthy versus partially-unhealthy target groups.

Model predicates: EC2, RDS, ELB, target groups, and SQS gained tests. These pin the boundaries the findings depend on:

  • backlog thresholds are inclusive, the low-CPU threshold is exclusive
  • unreadable tags never count as a coverage gap, so a failed lookup cannot be reported as an untagged resource
  • healthy_targets saturates, so a service reporting more unhealthy than registered targets cannot underflow into a huge count
  • a dead-letter queue is identified by another queue redriving to it, not by its name

Cost buckets: had no tests at all. Covering them meant making the window helpers take the date instead of reading the clock, which is also what makes the December rollover and year-boundary cases testable. There is a test asserting the six-month labels and the requested window agree, since a mismatch there silently offsets the chart axis from its data.

Region logic: the synthetic global slot (one past the real regions, and not selectable when none were discovered), exact case-sensitive region matching, and the index clamp that keeps a stale index from reading past a shorter region list.

Verification

  • cargo test: 205 passed, 0 failed
  • cargo clippy --all-targets -- -D warnings: clean
  • cargo fmt --check: clean
  • The cost bug and its fix were both verified against the live Cost Explorer API, not just asserted in unit tests.

Note

Every test here passed on first run except one, which was my own invalid fixture date (29 February 2026, which does not exist; 2026 is not a leap year). So apart from the interval bug above, these tests confirm existing behavior rather than having uncovered further defects.

… logic

Coverage went from 140 to 205 tests across the four areas the issue names.

All 25 finding rules are now exercised, up from 11. The added ones cover the
pairs that must not double-report: production versus general secret rotation,
stopped instances that look important versus merely unused, and idle load
balancers versus failing ones.

Model predicates gained tests on EC2, RDS, ELB, target groups, and SQS. These
are the thresholds and boundaries the findings are built on: inclusive backlog
thresholds, a low-CPU threshold that is exclusive at the boundary, unreadable
tags never counting as a coverage gap, and saturating arithmetic that cannot
underflow when a service reports more unhealthy targets than registered ones.

Cost time-bucket logic had no tests at all. Covering it required making the
window helpers take the date rather than reading the clock, which is also what
let the December and year-boundary cases be tested at all.

That surfaced a real bug, fixed here. Cost Explorer rejects a time period whose
start and end are the same day, and the month-to-date window collapsed to
exactly that on the first of every month, so all cost views reported the
service unavailable that day. The window now covers the current day.

Region selection gained tests for the synthetic global slot, exact and
case-sensitive region matching, and the index clamp that keeps a stale index
from reading past a shorter region list.
@Bccorb
Bccorb merged commit 59d3b1c into main Jul 20, 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.

test: add coverage for finding rules, model predicates, cost parsing, and region/profile logic

1 participant