Skip to content

test(pricing): cover 30 untested money-path cases (#50) - #51

Merged
ualtinok merged 1 commit into
cortexkit:masterfrom
iceteaSA:test/issue-50-pricing-gaps
Dec 4, 2026
Merged

ualtinok merged 1 commit into
cortexkit:masterfrom
iceteaSA:test/issue-50-pricing-gaps

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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-core for price arithmetic and list valuation. It changes only test code. One BROCA test helper in pricing.rs gets 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_unvalued and pricing_mutation_list_value_does_not_treat_euros_as_dollars.

What proves it

  • Test: the 22 tests named pricing_mutation_* and pricing_batch2_mutation_* in pricing.rs, pricing_unit_billing_tests.rs, multiplier/shared_valuer_tests.rs and report/hourly/valuation/tests.rs.
  • Failed without the fix: this PR has no production change. For each of the 30 cases in Price arithmetic: 30 code changes that no test detects (tests attached) #50, I applied that one code change and ran its test. Each test stopped on an equality assertion (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.
  • At this branch on Linux, these commands are satisfactory: scripts/fmt-check.sh, cargo clippy --workspace --all-targets --locked -- -D warnings and cargo 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-core that 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.

  • The BROCA helper in pricing.rs now takes its measurements and rates as parameters, with the same values as before.
  • Includes three tests beyond the issue patch: pricing_batch2_mutation_token_selector_cannot_claim_cache_lifetime, pricing_mutation_list_value_keeps_conflicting_mode_aliases_unvalued, and pricing_mutation_list_value_does_not_treat_euros_as_dollars.
  • Verified with scripts/fmt-check.sh, cargo clippy --workspace --all-targets --locked -- -D warnings, and cargo test --workspace --all-targets --locked (2,335 passing, 0 failing, 38 ignored).

Written for commit fa9caef. Summary will update on new commits.

View guided diff

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
"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(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

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.

Price arithmetic: 30 code changes that no test detects (tests attached)

2 participants