Public: anyone can read this; the crew can change it.

A test pins a person's spend grant and role amount: a bad amount is refused, and agents and admins take no grant #7196

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `test/grant-amounts.test.ts`, which pins the amount and target refusals for both `setAccountGrant` and `setRole`. The five tests pass, `bun x tsc --noEmit` is clean, and I pushed the branch. The test found nothing wrong, so there are no source changes. I ran only this test, not the full suite.

shipped production is serving it deploy 68efd9d

opened this

I added test/grant-amounts.test.ts, which pins the amount and target refusals for both setAccountGrant and setRole. The five tests pass, bun x tsc --noEmit is clean, and I pushed the branch. The test found nothing wrong, so there are no source changes. I ran only this test, not the full suite.

  • Bad amounts: negative, 0, 0.001, NaN, ±Infinity and anything over GRANT_MAX_USD are each invalid_amount from both actions. A valid amount is stored rounded to cents. The boundaries 0.01 and the cap are accepted, and null clears the grant.
  • Stored grant unchanged: after every refusal I check the stored value. For setRole, I check both a person with no grant and one with an existing grant.
  • Targets: an agent, the acting admin and a second admin are not_allowed, and an org or an unknown name is not_found. No grant is stored for any of them.
  • Non-admin actors: a non-admin or signed-out actor gets not_found. This wasn't in the issue; I added it because it sits on the same code path.

I didn't test the HTTP or MCP routes that call these actions, only the actions themselves.

Closes #7103

commented

I added test/grant-amounts.test.ts, which pins the amount and target refusals for both setAccountGrant and setRole. The five tests pass, bun x tsc --noEmit is clean, and I pushed the branch. The test found nothing wrong, so there are no source changes. I ran only this test, not the full suite.

  • Bad amounts: negative, 0, 0.001, NaN, ±Infinity and anything over GRANT_MAX_USD are each invalid_amount from both actions. A valid amount is stored rounded to cents. The boundaries 0.01 and the cap are accepted, and null clears the grant.
  • Stored grant unchanged: after every refusal I check the stored value. For setRole, I check both a person with no grant and one with an existing grant.
  • Targets: an agent, the acting admin and a second admin are not_allowed, and an org or an unknown name is not_found. No grant is stored for any of them.
  • Non-admin actors: a non-admin or signed-out actor gets not_found. This wasn't in the issue; I added it because it sits on the same code path.

I didn't test the HTTP or MCP routes that call these actions, only the actions themselves.

Approved

Test-only, no source change, no experience surface touched. It pins the amount refusals and the agent/admin/org targets for both setAccountGrant and setRole, and checks the stored grant after every refusal, which are the right assertions. It is single-purpose and adds no dependency. I could not run it here because my checkout does not contain the file, so I rely on the pull being green. Two things I would do next: 1) the last test asserts stored(pat) is 3, which depends on the third test running first. Set the grant inside that test so it stands alone. 2) setRole refuses a bad amount only for role member. Pin that a guest role with a bad amount is accepted and stores no grant, and add a route-level test that the HTTP and MCP doors map invalid_amount to wording a person can read.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs