# Test: `only_valid::` Parameter
Edge case coverage for the `only_valid::` parameter on `.usage`. See [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md) for specification.
### Test Case Index
| EC-1 | `only_valid::1` hides 🔴 rows; shows 🟢 and 🟡 | Behavioral Divergence |
| EC-2 | `only_valid::0` (default) shows all rows | Behavioral Divergence |
| EC-3 | `only_valid::bad` exits 1 naming valid values | Invalid Value |
| EC-4 | `only_valid::1` with all 🔴 accounts shows 0 rows | Empty Result |
| EC-5 | `only_valid::true` accepted (alias for 1) | Alias Acceptance |
| EC-6 | `only_valid::false` accepted (alias for 0) | Alias Acceptance |
| EC-7 | Cancelled account (`billing_type="none"`, `result=Ok`) excluded by `only_valid::1` | Cancelled Subscription |
---
### EC-1: `only_valid::1` hides 🔴 rows
- **Given:** Three accounts: one 🟢, one 🟡, one 🔴.
- **When:** `clp .usage only_valid::1`
- **Then:** Exits 0. 🟢 and 🟡 rows shown; 🔴 row hidden.
- **Exit:** 0
- **Source fn:** `it228_lim_it_only_valid_1_shows_green_hides_red` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-2: `only_valid::0` shows all rows
- **Given:** Three accounts: one 🟢, one 🟡, one 🔴.
- **When:** `clp .usage only_valid::0`
- **Then:** Exits 0. All rows shown.
- **Exit:** 0
- **Source fn:** `it169_only_valid_0_shows_all_rows` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-3: `only_valid::bad` exits 1 naming valid values
- **Given:** Any environment.
- **When:** `clp .usage only_valid::bad`
- **Then:** Exits 1. Stderr names valid values: `0`, `1`, `false`, `true`.
- **Exit:** 1
- **Source fn:** `it170_only_valid_bad_exits_1` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-4: `only_valid::1` with all 🔴 accounts shows 0 rows
- **Given:** Two accounts; both are 🔴 (expired token or network error).
- **When:** `clp .usage only_valid::1`
- **Then:** Exits 0. Table has 0 data rows (all filtered). No error.
- **Exit:** 0
- **Source fn:** `it171_only_valid_1_all_red_shows_empty` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-5: `only_valid::true` accepted as alias for 1
- **Given:** Three accounts: one 🟢, one 🟡, one 🔴.
- **When:** `clp .usage only_valid::true`
- **Then:** Exits 0. 🟢 and 🟡 rows shown — same result as `only_valid::1`.
- **Exit:** 0
- **Source fn:** `it172_only_valid_true_accepted` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-6: `only_valid::false` accepted as alias for 0
- **Given:** Three accounts: one 🟢, one 🟡, one 🔴.
- **When:** `clp .usage only_valid::false`
- **Then:** Exits 0. All rows shown — same result as `only_valid::0`.
- **Exit:** 0
- **Source fn:** `it173_only_valid_false_shows_all_rows` (in `tests/cli/usage_test.rs`)
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)
---
### EC-7: Cancelled account (`billing_type="none"`, `result=Ok`) excluded by `only_valid::1`
- **Given (unit test):** One `AccountQuota` with `result = Ok(OauthUsageData)` (quota fetch succeeded) and `account = Some(OauthAccountData { billing_type: "none", ... })` — subscription cancelled. This is the critical case: `result.is_ok()` is `true`, so the first predicate passes, but `billing_type="none"` triggers the second predicate.
- **When:** `only_valid::1` filter applied (via `accounts.retain(...)` in `api.rs`).
- **Then:** The account is excluded from the result set. Without Fix(BUG-317), this account would pass `only_valid::1` because only `result.is_ok()` was checked.
- **Exit:** n/a (unit test — retain predicate)
- **Source fn:** `mre_bug317_cancelled_excluded_by_only_valid` (in `src/usage/api_tests.rs`)
- **Note:** Fix(BUG-317): predicate is now `result.is_ok() && !account.as_ref().is_some_and(|a| a.billing_type == "none")`. Both conditions must pass independently.
- **Source:** [param/043_only_valid.md](../../../../docs/cli/param/043_only_valid.md)