Skip to content

Comments

Add comprehensive unit tests and improve error handling#6

Merged
GsCommand merged 1 commit intomainfrom
claude/review-production-readiness-c01t9
Feb 15, 2026
Merged

Add comprehensive unit tests and improve error handling#6
GsCommand merged 1 commit intomainfrom
claude/review-production-readiness-c01t9

Conversation

@GsCommand
Copy link
Contributor

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

  • New unit test suite (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.
  • Improved CLI argument parsing: Added parseIntSafe() helper to safely parse numeric CLI arguments with fallback defaults, replacing unsafe Number() conversions.
  • Enhanced error handling in client.call():
    • Added verb validation to reject unsupported verbs with a clear error message
    • Improved JSON parsing error handling to distinguish between non-JSON responses and HTTP errors
  • Updated test scripts: Added test:unit and test npm scripts to run unit tests and smoke tests.

Python SDK

  • Type safety improvements in verify.py:
    • Added explicit type annotations for pubkey, pubkey_source, ens_error, and ens_txt_key variables
    • Fixed ENS module null-check to prevent AttributeError when ENS is unavailable
    • Improved type narrowing for mypy compatibility
  • Context manager support in client.py: Added __enter__ and __exit__ methods to CommandLayerClient for use with with statements.
  • Type ignore comment: Added # type: ignore[no-any-return] to suppress mypy warning in call() return statement.

CI/CD

  • New Python SDK test workflow (.github/workflows/python-sdk-tests.yml): Runs linting (ruff), type checking (mypy), and pytest across Python 3.10, 3.11, and 3.12.
  • Updated TypeScript SDK workflow: Added unit test step before CLI smoke tests.

Notable Implementation Details

  • Unit tests are self-contained and use tweetnacl directly for cryptographic operations, avoiding external test framework dependencies.
  • Error handling improvements provide better diagnostics for both CLI users and programmatic API consumers.
  • Type annotations in Python SDK improve IDE support and catch potential runtime errors earlier.

https://claude.ai/code/session_018eVmxc7pcom9N88xbcZvaZ

- 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
@GsCommand GsCommand merged commit d910454 into main Feb 15, 2026
8 checks passed
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@GsCommand GsCommand deleted the claude/review-production-readiness-c01t9 branch February 15, 2026 23:52
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.

2 participants