Add comprehensive unit tests and improve error handling#6
Conversation
- Fix 5 mypy type errors in Python SDK (union-attr, typeddict-item, arg-type, no-any-return) - Fix silent JSON parse failure in TS client that swallowed server errors as empty objects - Add runtime verb validation in TS client.call() to match Python SDK behavior - Add NaN-safe numeric parsing for CLI --timeout-ms and --max-tokens options - Add context manager (__enter__/__exit__) to Python client to prevent resource leaks - Add Python CI workflow (ruff + mypy + pytest across Python 3.10-3.12) - Add TS unit tests for canonicalization, hashing, Ed25519, and receipt verification (30 tests) - Update TS CI workflow to run unit tests alongside smoke tests https://claude.ai/code/session_018eVmxc7pcom9N88xbcZvaZ
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ccb45b1cf7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "test:cli-smoke": "node scripts/cli-smoke.mjs" | ||
| "test:cli-smoke": "node scripts/cli-smoke.mjs", | ||
| "test:unit": "node scripts/unit-tests.mjs", | ||
| "test": "npm run test:unit && npm run test:cli-smoke" |
There was a problem hiding this comment.
Build artifacts before running npm test
The new test script invokes test:unit immediately, but scripts/unit-tests.mjs loads ../dist/index.cjs; on a clean checkout where dist/ has not been built yet, npm test now fails with MODULE_NOT_FOUND. This makes the default test entrypoint unusable for local runs and CI jobs that call npm test without a prior explicit build step.
Useful? React with 👍 / 👎.
Summary
This PR adds comprehensive unit tests for the TypeScript SDK and improves error handling across both SDKs. It also adds CI/CD workflows for automated testing.
Key Changes
TypeScript SDK
scripts/unit-tests.mjs): Tests core SDK logic including canonicalization, SHA-256 hashing, Ed25519 key parsing, signature verification, and receipt verification. Uses tweetnacl for key generation without requiring external test frameworks.parseIntSafe()helper to safely parse numeric CLI arguments with fallback defaults, replacing unsafeNumber()conversions.client.call():test:unitandtestnpm scripts to run unit tests and smoke tests.Python SDK
verify.py:pubkey,pubkey_source,ens_error, andens_txt_keyvariablesclient.py: Added__enter__and__exit__methods toCommandLayerClientfor use withwithstatements.# type: ignore[no-any-return]to suppress mypy warning incall()return statement.CI/CD
.github/workflows/python-sdk-tests.yml): Runs linting (ruff), type checking (mypy), and pytest across Python 3.10, 3.11, and 3.12.Notable Implementation Details
https://claude.ai/code/session_018eVmxc7pcom9N88xbcZvaZ