Skip to content

ponymail-mcp: add unit tests and CI#5

Merged
rbowen merged 1 commit intoapache:rbowen-ponymail-mcpfrom
potiuk:add-tests-and-ci
Apr 27, 2026
Merged

ponymail-mcp: add unit tests and CI#5
rbowen merged 1 commit intoapache:rbowen-ponymail-mcpfrom
potiuk:add-tests-and-ci

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented Apr 25, 2026

Summary

Targets PR #2's branch (apache:rbowen-ponymail-mcp). The package shipped without tests or CI — this adds both, using only built-in Node tooling so the dependency tree stays unchanged.

  • mcp/ponymail-mcp/restrictions.test.js — 15 unit tests covering pattern grammar (prefix@, @domain, prefix@domain), env-var parsing edge cases (none, "", mixed case, whitespace), case-insensitive input matching, every public export (restrictionFor / restrictionForAddress / isRestricted / restrictionError / listRestrictions), and falsy-input tolerance.
  • mcp/ponymail-mcp/auth.test.js — 8 unit tests for the session-persistence helpers (loadSession, clearSession). Each test runs in a child process with HOME pointed at a temp directory so the on-disk session.json is fully isolated. Covers: missing file, fresh cookie, expired cookie, missing-timestamp behaviour, malformed JSON, missing cookie field, and clearSession idempotency. The interactive performLogin() flow is out of scope for unit tests (browser, local HTTP server, network validation).
  • mcp/ponymail-mcp/package.json — adds npm test script using node:test with the spec reporter, and declares engines.node: >=20.
  • .github/workflows/ponymail-mcp-tests.yml — runs the suite on push/PR (path-filtered to mcp/ponymail-mcp/**) on Node 20 and 22.

Workflow hardening

  • Top-level permissions: {} (deny-all) with per-job contents: read.
  • Third-party actions pinned to commit SHAs with version comments.
  • actions/checkout sets persist-credentials: false.
  • 10-minute job timeout.

Why a child-process per test

restrictions.js captures PONYMAIL_RESTRICTED_LISTS at module load, and auth.js computes SESSION_FILE from os.homedir() at module load. Tests need different env per case, so each spawns a fresh node process. Slow (~24ms per test) but unambiguous.

Notes for downstream PRs

PR #3 (built on top of this branch) already adds tests for the allowlist mechanism it introduces; if this lands first, PR #3 will need a one-line rebase to merge the package.json test script. Happy to handle that rebase.

Test plan

  • cd mcp/ponymail-mcp && npm install && npm test passes locally (23/23)
  • CI workflow turns green on Node 20 and 22 once the PR is opened

🤖 Generated with Claude Code

@potiuk potiuk mentioned this pull request Apr 25, 2026
The mcp/ponymail-mcp package shipped without tests or CI. This adds
both, using only built-in Node tooling so the dependency tree stays
unchanged.

- restrictions.test.js: 15 unit tests covering pattern grammar
  (prefix@, @Domain, prefix@domain), env-var parsing edge cases
  (none, empty, mixed case, whitespace), case-insensitive input
  matching, restrictionFor/restrictionForAddress/isRestricted/
  restrictionError/listRestrictions, and falsy-input tolerance.
  Each test that exercises a different env spawns a child node
  process and re-imports restrictions.js, since RESTRICTED is
  captured at module load.
- auth.test.js: 8 unit tests for the session-persistence helpers
  (loadSession, clearSession). Each test runs in a child process
  with HOME pointed at a temporary directory so the on-disk
  session.json is fully isolated. Covers: missing file, fresh
  cookie, expired cookie, missing-timestamp behaviour, malformed
  JSON, missing cookie field, and clearSession idempotency. The
  interactive performLogin() flow (browser, local HTTP server,
  network validation) is out of scope for unit tests.
- package.json: adds `npm test` script using node:test with the
  spec reporter, and declares engines.node: >=20 (uses node:test
  built-in runner; no new deps).
- .github/workflows/ponymail-mcp-tests.yml: runs the suite on
  push/PR (path-filtered to mcp/ponymail-mcp/) on Node 20 and 22.
  Hardened: top-level `permissions: {}` (deny-all) with per-job
  contents: read, third-party actions pinned to commit SHAs with
  version comments, actions/checkout sets persist-credentials:
  false, 10-minute job timeout.

Generated-by: Claude Code (Claude Opus 4.7)
@potiuk potiuk force-pushed the add-tests-and-ci branch from a514ccb to face465 Compare April 26, 2026 20:22
@rbowen rbowen merged commit 3c04b57 into apache:rbowen-ponymail-mcp Apr 27, 2026
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