Skip to content

test(contract): prove the 402 envelope's current field against an over-cap account - #982

Open
AmirF194 wants to merge 2 commits into
tokencanopy:mainfrom
AmirF194:fix/828-account-limits-current-field
Open

test(contract): prove the 402 envelope's current field against an over-cap account#982
AmirF194 wants to merge 2 commits into
tokencanopy:mainfrom
AmirF194:fix/828-account-limits-current-field

Conversation

@AmirF194

@AmirF194 AmirF194 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

account_limits_enforced asserts error.details.current in the 402 envelope, but at the moment of refusal current == limit by construction of the count >= lim.MaxAgents / count >= lim.MaxDomains checks in internal/limits/enforcer.go. A server that hardcoded Current to the cap instead of the real resource count would pass every assertion in that scenario.

This adds a third seeded contract account (OverCapAPIKey) whose domains and agents are created before a lower cap is applied, so it starts already over both caps. A further create attempt is then refused with current strictly greater than limit, the only value a server actually reading the resource count can produce.

Verified by mutation: I temporarily hardcoded Current: lim.MaxAgents / Current: lim.MaxDomains in enforcer.go. account_limits_enforced stayed green; the new account_limits_current_field_proven scenario failed (error.details.current = 1, want 2), confirming it closes the gap.

No production code changes: CheckAgentCreate/CheckDomainCreate already report the real count today, this only proves it and guards against a future regression.

Client surface checklist

Test-only change, no API or client surface touched.

Operational risk

None. Test infrastructure only; no production code path changes.

Test plan

  • go test -tags integration -run TestScenarios ./tests/contract/...: new scenario passes; existing account_limits_enforced still passes.
  • TestOverCapScenarioShape (new, mirrors TestLimitsScenarioShape) pins the assertion shape.
  • Mutation check: hardcoding Current to the cap in enforcer.go makes the new scenario fail while account_limits_enforced stays green (reverted before pushing).
  • make fmt-check, go vet -tags integration ./internal/testutil/... ./tests/contract/..., go build ./... all clean.
  • Not run: the full make cover-check coverage-floor gate (needs the whole suite; my diff touches no package with a configured floor) and the TS/Python contract runners, which do not yet consume scenarios.yaml (per this file's own header comment).

Fixes #828

…r-cap account

account_limits_enforced asserts error.details.current, but at the moment
of refusal current == limit by construction of the count >= cap checks in
CheckAgentCreate/CheckDomainCreate, so a server that hardcoded Current to
the cap would pass every existing assertion.

Add a third seeded contract account (OverCapAPIKey) whose domains and
agents are created before a lower cap is applied, so it starts already
over both caps. A further create attempt is refused with current strictly
greater than limit, which only a server reading the real resource count
can produce. Verified by mutation: hardcoding Current to lim.MaxAgents /
lim.MaxDomains fails the new scenario while account_limits_enforced stays
green.

Fixes tokencanopy#828

Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
@AmirF194
AmirF194 requested a review from jiashuoz as a code owner September 1, 2026 12:51
…unners

The standalone contract-server helper (cmd/e2a-contract-server) wrote
E2A_TEST_BASE_URL, E2A_TEST_API_KEY and E2A_TEST_CAPPED_API_KEY to its
env file, but never E2A_TEST_OVERCAP_API_KEY, even though
testutil.ContractServer already exposes OverCapAPIKey. The Go
integration suite runs the contract server in process and reads
cs.OverCapAPIKey directly, so it never depended on that env var and
kept passing.

The TS and Python contract runners never read an
E2A_TEST_OVERCAP_API_KEY env var and never wired an overcap_api_key
template variable, so the new account_limits_current_field_proven
scenario's auth_override reached the wire as the literal string
"Bearer {overcap_api_key}". The server rejected that as an invalid
key with 401 before ever reaching the over-cap check, which is the
failure both jobs reported.

This adds E2A_TEST_OVERCAP_API_KEY to the env file the helper writes,
and wires it into both runners the same way E2A_TEST_CAPPED_API_KEY
already is, including a skip gate for a deployed target that has no
over-cap account to offer.

Verified in a clean Docker container against current HEAD: the Go
integration suite (go test -tags integration ./tests/contract/...)
passes all 33 scenarios including account_limits_current_field_proven,
the TypeScript contract suite passes 50 tests with 0 failures, and the
Python contract suite passes 48 tests with 0 failures.

Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
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.

tests/contract: the 402 envelope current field is not independently proven (needs an over-cap account)

1 participant