feat(backend,ai,onchain): resolve #249 shared error-code taxonomy and #233 cap allowed_tokens#418
Open
precy41 wants to merge 1 commit into
Open
feat(backend,ai,onchain): resolve #249 shared error-code taxonomy and #233 cap allowed_tokens#418precy41 wants to merge 1 commit into
precy41 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 throughErrorCode.<X>.value/code_for_http_status(...)instead of ad-hoc literal strings.#233 — Cap
allowed_tokenslist lengthapp/onchain/contracts/aid_escrow/src/lib.rs:pub const MAX_ALLOWED_TOKENS: u32 = 32;Error::TooManyAllowedTokens = 23variant.set_configrejects oversized allowlists withError::TooManyAllowedTokensBEFORE the per-tokenvalidate_tokenloop, 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).aid_escrow::MAX_ALLOWED_TOKENSdirectly.Both contracts public wire formats are unchanged.
Closes #249
Closes #233