Skip to content

feat(backend,ai,onchain): resolve #249 shared error-code taxonomy and #233 cap allowed_tokens#418

Open
precy41 wants to merge 1 commit into
ChainForgee:mainfrom
precy41:fix/precy41-issues-249-233
Open

feat(backend,ai,onchain): resolve #249 shared error-code taxonomy and #233 cap allowed_tokens#418
precy41 wants to merge 1 commit into
ChainForgee:mainfrom
precy41:fix/precy41-issues-249-233

Conversation

@precy41

@precy41 precy41 commented Jul 26, 2026

Copy link
Copy Markdown

Resolves both issues assigned to precy41 in a single PR:

#249 — Shared error-code taxonomy

  • docs/errors.yaml: single source of truth for every error code emitted across backend and AI service.
  • app/backend/src/common/errors/codes.ts + app/backend/src/common/errors/codes.spec.ts: TypeScript enum + parity test that walks docs/errors.yaml and asserts the TS binding matches every entry.
  • app/ai-service/schemas/codes.py + app/ai-service/tests/test_codes.py: Python enum + parity test mirroring the TS side; both YAML parsers are byte-for-byte equivalent in shape.
  • app/ai-service/main.py: HTTPException, validation, body-size, and fallback exception handlers now route through ErrorCode.<X>.value / code_for_http_status(...) instead of ad-hoc literal strings.
  • Backend wire format (code: number) is intentionally preserved; only the semantic mapping to the shared taxonomy is enforced.

#233 — Cap allowed_tokens list length

  • app/onchain/contracts/aid_escrow/src/lib.rs:
    • new pub const MAX_ALLOWED_TOKENS: u32 = 32;
    • new Error::TooManyAllowedTokens = 23 variant.
    • set_config rejects oversized allowlists with Error::TooManyAllowedTokens BEFORE the per-token validate_token loop, so a malicious admin can neither bloat wasm storage nor burn host cost.
  • app/onchain/contracts/aid_escrow/tests/aid_escrow_tests.rs:
    • set_config_rejects_too_many_allowed_tokens (vec of length MAX + 1, asserts TooManyAllowedTokens).
    • set_config_passes_cap_check_at_max_boundary (vec of length MAX, asserts InvalidToken rather than TooManyAllowedTokens to prove the cap is exclusive).
    • Both reference aid_escrow::MAX_ALLOWED_TOKENS directly.

Both contracts public wire formats are unchanged.

Closes #249
Closes #233

…in one PR

ChainForgee#249 — Shared error-code taxonomy
  * docs/errors.yaml: single source of truth for every error code we
    emit across backend and AI service.
  * app/backend/src/common/errors/codes.ts: TypeScript enum + meta
    table + codeForHttpStatus/httpStatusForCode helpers.
  * app/backend/src/common/errors/codes.spec.ts: parity test that
    walks docs/errors.yaml and asserts the TS binding matches every
    entry, plus a first-declared-wins lookup lock.
  * app/ai-service/schemas/codes.py: Python mirror of the TS binding
    (enum + dataclass meta + identical reverse-lookup semantics).
  * app/ai-service/tests/test_codes.py: parity test mirroring
    codes.spec.ts.  Both YAML parsers are byte-for-byte equivalent in
    shape and produce the same set of entries for docs/errors.yaml.
  * app/ai-service/main.py: HTTPException, validation, body-size, and
    fallback exception handlers now route through
    ErrorCode.<X>.value / code_for_http_status(...) instead of ad-hoc
    literal strings.
  * app/backend/src/common/filters/http-exception.filter.ts: doc
    comment pinning the wire-format contract (code: number, the existing
    public envelope shape) so a future PR cannot accidentally break it.

ChainForgee#233 — Cap allowed_tokens at MAX_ALLOWED_TOKENS
  * app/onchain/contracts/aid_escrow/src/lib.rs:
      - new pub const MAX_ALLOWED_TOKENS: u32 = 32 (re-exported for tests).
      - new Error::TooManyAllowedTokens = 23 variant.
      - set_config rejects oversized allowlists with
        Error::TooManyAllowedTokens BEFORE the per-token validate_token
        loop, so a malicious admin can neither bloat wasm storage
        nor burn host cost.
  * app/onchain/contracts/aid_escrow/tests/aid_escrow_tests.rs:
      - set_config_rejects_too_many_allowed_tokens (vec of length
        MAX + 1, asserts TooManyAllowedTokens)
      - set_config_passes_cap_check_at_max_boundary (vec of length
        MAX made of dummy AidEscrow writes to lmts, asserts InvalidToken
        rather than TooManyAllowedTokens to prove the cap is exclusive).
    Both tests reference aid_escrow::MAX_ALLOWED_TOKENS directly so
    future tweaks to the cap cannot silently drift out of spec.

Both contracts public wire formats are unchanged.

Closes ChainForgee#249
Closes ChainForgee#233
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.

Shared error-code taxonomy module Cap allowed_tokens list length

1 participant