Skip to content

Add unit tests for safeStringify circular, BigInt, and truncation handling #146

Description

@mikewheeleer

Test the safeStringify serialiser and safeFormatTimestamp fallbacks

Description

src/lib/format.ts exposes safeStringify (used by the event log to render arbitrary payloads without throwing — handling circular refs as [Circular], BigInt as a marker, functions/symbols/undefined, and truncating past EVENT_PAYLOAD_MAX_CHARS) and safeFormatTimestamp (which coerces malformed timestamps to a placeholder). The formatStroops/formatRequests paths have tests, but these two render-safety helpers do not. This issue covers them.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-frontend only.
  • For safeStringify: assert circular objects produce [Circular], BigInt produces [BigInt:…], top-level undefined/function/symbol return the typeof sentinel, and an over-long string is truncated with EVENT_PAYLOAD_TRUNCATED_MARKER.
  • Assert a custom maxChars is respected and small payloads are returned untruncated.
  • For safeFormatTimestamp: assert valid numeric/string timestamps return ISO, and null/undefined/non-finite/NaN inputs return the fallback dash.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/testing-safestringify-timestamp
  • Implement changes
    • Write comprehensive tests in: extend src/lib/__tests__/format.test.ts.
    • Write code in: no source change expected (file a follow-up if a bug is found).
    • Add documentation: none beyond test descriptions.
    • Validate the function never throws for any input shape.
  • Test and commit

Test and commit

  • Run npm run lint, npm run typecheck, and npm test.
  • Cover edge cases: nested circular, a payload exactly at the limit, BigInt inside an array, and a "not-a-date" timestamp string.
  • Include the npm test output and coverage for format.ts.

Example commit message

test(lib): cover safeStringify circular/BigInt/truncation and safeFormatTimestamp

Guidelines

  • Minimum 95 percent test coverage for the impacted functions.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions