Skip to content

Refactor tests to pure functions and improve error handling#218

Merged
GsCommand merged 1 commit into
mainfrom
claude/audit-commandlayer-protocol-O05aO
May 14, 2026
Merged

Refactor tests to pure functions and improve error handling#218
GsCommand merged 1 commit into
mainfrom
claude/audit-commandlayer-protocol-O05aO

Conversation

@GsCommand
Copy link
Copy Markdown
Contributor

Summary

This PR refactors the test suite to focus on pure verification functions, improves error handling across multiple modules, and enhances documentation formatting.

Key Changes

Test Suite Refactoring (tests/commons-flow.test.js)

  • Converted from browser-based DOM tests to Node.js unit tests using node:test and node:assert
  • Extracted pure helper functions (canonicalize, canonicalReceiptPayload, sha256HexSync) that work without DOM
  • Added comprehensive test coverage for:
    • Canonicalization of primitives, objects, and arrays
    • Key sorting in nested objects
    • Receipt payload extraction
    • SHA-256 hash computation against known sample values
    • Tampering detection via hash changes
    • HTML escaping utility
  • Removed browser-specific code (DOM element resolution, event listeners, ENS record mocking)

Error Handling Improvements

  • public/js/verify-url.js: Enhanced error messages with HTTP status codes and exception details
  • examples/webhook-auto-verify/server.js:
    • Added HTTP status validation before parsing response
    • Improved error logging with specific error messages
    • Changed console output to use process.stdout.write for consistency
  • api/verify-receipt.js: Removed verbose console logging that exposed internal request/response details
  • public/js/verify.js: Removed unnecessary error logging

Documentation Improvements (docs/wrap-your-agent.md)

  • Fixed code block syntax highlighting (added language identifiers)
  • Improved formatting and indentation of code examples
  • Reorganized section headers for better hierarchy
  • Enhanced JSON example readability
  • Clarified prose and removed redundant text

Configuration

  • .env.example: Added descriptive comments explaining RUNTIME_BASE_URL purpose and format

Implementation Details

  • The refactored tests use synchronous SHA-256 hashing via Node.js crypto module instead of Web Crypto API
  • Pure functions are duplicated in test file to avoid DOM dependencies while maintaining test isolation
  • Error handling now provides actionable feedback with specific failure reasons rather than generic messages
  • Removed sensitive internal logging that could expose implementation details in production

https://claude.ai/code/session_01GQcff5HnFcrTbyuwuvsNEv

… improve error handling, update .env.example, fix doc code fences
@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
commandlayer-commandlayer-org Ready Ready Preview, Comment May 14, 2026 1:50am
commandlayer-org Ready Ready Preview, Comment May 14, 2026 1:50am
commandlayer-org111 Ready Ready Preview, Comment May 14, 2026 1:50am

Request Review

@GsCommand GsCommand merged commit 5aee47e into main May 14, 2026
6 checks passed
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.

1 participant