Repository navigation
test(pricing): cover 30 untested money-path cases (#50) - #51
Conversation
Add 22 exact-value tests for price arithmetic and list valuation in astrocyte-core. Each test passes on the current code and fails on an equality assertion when its case is changed. Test code only; one BROCA test helper takes its measurements and rates as parameters, with the same values.
There was a problem hiding this comment.
3 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/astrocyte-core/src/pricing.rs">
<violation number="1" location="crates/astrocyte-core/src/pricing.rs:4935">
P3: This test can pass even if the resolver prices `output`/`request` with either request-rate key, because the fake catalog contains neither key. Add both `rate.output.per_request` and `rate.request.per_request` and keep the expected output row unpriced, so an invalid role mapping cannot pass unnoticed.</violation>
<violation number="2" location="crates/astrocyte-core/src/pricing.rs:5028">
P3: The zero charge masks the selected rate, so this test can pass with the tiered catalog entry. Assert the stored catalog entry's `fact_key` is `rate.input` (not `rate.input.above_context.272000`) in addition to the zero charge.</violation>
<violation number="3" location="crates/astrocyte-core/src/pricing.rs:5051">
P3: The fake catalog lacks the base cache-write rate, so this assertion still passes if a token measurement incorrectly ignores its `ttl` selector and attempts the base rate. Add both the base and TTL facts; the token row must remain `no_rate` and must not be priced by either key.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| .into_iter() | ||
| .map(|(reason, _, _, _, charge)| (reason, charge)) | ||
| .collect(); | ||
| assert_eq!(actual, [(None, Some(0))]); |
There was a problem hiding this comment.
P3: The zero charge masks the selected rate, so this test can pass with the tiered catalog entry. Assert the stored catalog entry's fact_key is rate.input (not rate.input.above_context.272000) in addition to the zero charge.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/astrocyte-core/src/pricing.rs, line 5028:
<comment>The zero charge masks the selected rate, so this test can pass with the tiered catalog entry. Assert the stored catalog entry's `fact_key` is `rate.input` (not `rate.input.above_context.272000`) in addition to the zero charge.</comment>
<file context>
@@ -4897,6 +4897,369 @@ mod tests {
+ .into_iter()
+ .map(|(reason, _, _, _, charge)| (reason, charge))
+ .collect();
+ assert_eq!(actual, [(None, Some(0))]);
+ }
+
</file context>
| assert_eq!(actual, [(None, Some(0))]); | |
| assert_eq!(actual, [(None, Some(0))]); | |
| let entry: Value = conn | |
| .query_row( | |
| "SELECT catalog_entry FROM priced_charge WHERE event_key=(SELECT event_key FROM usage_event WHERE event_id=?1)", | |
| [&event], | |
| |row| row.get::<_, String>(0), | |
| ) | |
| .map(|raw| serde_json::from_str(&raw).unwrap()) | |
| .unwrap(); | |
| assert_eq!(entry["fact_key"], "rate.input"); |
| .event_id; | ||
| tx.commit().unwrap(); | ||
| let catalog = client(FakeCatalog::new(BTreeMap::from([( | ||
| "rate.cache_write.ttl.1h".into(), |
There was a problem hiding this comment.
P3: The fake catalog lacks the base cache-write rate, so this assertion still passes if a token measurement incorrectly ignores its ttl selector and attempts the base rate. Add both the base and TTL facts; the token row must remain no_rate and must not be priced by either key.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/astrocyte-core/src/pricing.rs, line 5051:
<comment>The fake catalog lacks the base cache-write rate, so this assertion still passes if a token measurement incorrectly ignores its `ttl` selector and attempts the base rate. Add both the base and TTL facts; the token row must remain `no_rate` and must not be priced by either key.</comment>
<file context>
@@ -4897,6 +4897,369 @@ mod tests {
+ .event_id;
+ tx.commit().unwrap();
+ let catalog = client(FakeCatalog::new(BTreeMap::from([(
+ "rate.cache_write.ttl.1h".into(),
+ rate(3_000_000),
+ )])));
</file context>
| "rate.cache_write.ttl.1h".into(), | |
| "rate.cache_write".into(), | |
| rate(3_000_000), | |
| "rate.cache_write.ttl.1h".into(), |
| vec![measurement("input", Some(1_000_000))], | ||
| ); | ||
| let catalog = client(FakeCatalog::new(BTreeMap::from([( | ||
| "rate.input".into(), |
There was a problem hiding this comment.
P3: This test can pass even if the resolver prices output/request with either request-rate key, because the fake catalog contains neither key. Add both rate.output.per_request and rate.request.per_request and keep the expected output row unpriced, so an invalid role mapping cannot pass unnoticed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At crates/astrocyte-core/src/pricing.rs, line 4935:
<comment>This test can pass even if the resolver prices `output`/`request` with either request-rate key, because the fake catalog contains neither key. Add both `rate.output.per_request` and `rate.request.per_request` and keep the expected output row unpriced, so an invalid role mapping cannot pass unnoticed.</comment>
<file context>
@@ -4897,6 +4897,369 @@ mod tests {
+ vec![measurement("input", Some(1_000_000))],
+ );
+ let catalog = client(FakeCatalog::new(BTreeMap::from([(
+ "rate.input".into(),
+ unit_billing_rate(
+ None,
</file context>
Which issue gave this a go?
#50, the go of 2026-12-03 19:18Z.
Closes #50
What changed
This PR adds 22 tests in
astrocyte-corefor price arithmetic and list valuation. It changes only test code. One BROCA test helper inpricing.rsgets its measurements and rates as parameters, with the same values. This PR also has the three tests that the issue patch did not have:pricing_batch2_mutation_token_selector_cannot_claim_cache_lifetime,pricing_mutation_list_value_keeps_conflicting_mode_aliases_unvaluedandpricing_mutation_list_value_does_not_treat_euros_as_dollars.What proves it
pricing_mutation_*andpricing_batch2_mutation_*inpricing.rs,pricing_unit_billing_tests.rs,multiplier/shared_valuer_tests.rsandreport/hourly/valuation/tests.rs.assertion left == right failed). The same test is satisfactory on the unchanged code. No test can be satisfactory without its case: each test compares the accurate charge, quantity, rate key or outcome.scripts/fmt-check.sh,cargo clippy --workspace --all-targets --locked -- -D warningsandcargo test --workspace --all-targets --locked(2,335 satisfactory, 0 unsatisfactory, 38 ignored).AI helped write this draft.
Summary by cubic
Adds 22 tests in
astrocyte-corethat cover the 30 untested money-path cases in #50, closing it. This PR changes test code only; each test asserts exact charge, quantity, rate key, or outcome values, so it passes on unchanged code and fails on an equality assertion when its case behavior is altered.pricing.rsnow takes its measurements and rates as parameters, with the same values as before.pricing_batch2_mutation_token_selector_cannot_claim_cache_lifetime,pricing_mutation_list_value_keeps_conflicting_mode_aliases_unvalued, andpricing_mutation_list_value_does_not_treat_euros_as_dollars.scripts/fmt-check.sh,cargo clippy --workspace --all-targets --locked -- -D warnings, andcargo test --workspace --all-targets --locked(2,335 passing, 0 failing, 38 ignored).Written for commit fa9caef. Summary will update on new commits.