Skip to content

Make functions:test-function block-and-show-sends; surface watch/wait in help text#83

Merged
etbyrd merged 4 commits into
mainfrom
discover-emails-watch-wait
May 12, 2026
Merged

Make functions:test-function block-and-show-sends; surface watch/wait in help text#83
etbyrd merged 4 commits into
mainfrom
discover-emails-watch-wait

Conversation

@etbyrd
Copy link
Copy Markdown
Member

@etbyrd etbyrd commented May 12, 2026

Summary

Closes two AGX-discoverability gaps in one PR. Targets a 0.26.1 patch release (0.26.0 already published from #82).

functions:test-function --wait --show-sends

Hand-rolled override that wraps the auto-generated POST /functions/{id}/test with the wait-and-show-sends flow AGX walkthroughs flagged as the single biggest verification time-sink. Today an agent has to triple-thread the queued send id, emails:wait, getEmail, and sending:list-sent-emails to verify a function ran and see what it emitted. Now:

  • `primitive functions:test-function --id ` continues to fire-and-forget, same shape as the auto-generated version it replaces.
  • `--wait` blocks until the test inbound has landed AND the function's webhook has reached a terminal status (`fired` or `exhausted`). Exits non-zero on timeout (exit 2) or on exhausted retries (exit 1) so CI can gate on the exit code.
  • `--show-sends` (implies `--wait`) additionally prints the inbound's `replies` array (id, status, to, subject, queue_id for each outbound the function emitted while processing the test inbound).
  • `--timeout` (default 60s; 0 waits forever) and `--poll-interval` (default 2s) bound the wait.

Implementation polls two existing endpoints: `searchEmails({to, since})` to find the test inbound row, then `getEmail({id})` until `webhook_status` is terminal. The `replies` field on EmailDetail already carries the outbound correlation so no new server surface is needed.

The auto-generated functions:test-function entry is filtered out of `generatedCommands` so the hand-rolled command owns the id without a name collision.

Surface emails:wait and emails:watch in emails topic help text

The `emails` oclif topic description previously only mentioned `emails:latest`. `emails:wait` and `emails:watch` have been shipped since #56 but weren't discoverable via `primitive --help` or `primitive emails --help`. Description rewritten to also call out wait (block-until-arrives, bounded by --timeout/--number) and watch (stream forever).

The description is duplicated in both `cli-node/package.json` (canonical `@primitivedotdev/cli`) and `sdk-node/package.json` (deprecated alias that still ships the CLI). Both are updated so users on either package see the new copy.

Version bumps

  • `@primitivedotdev/cli` 0.26.0 -> 0.26.1
  • `@primitivedotdev/sdk` 0.26.0 -> 0.26.1

Patch level rather than minor because pre-1.0 caret matching (`^0.26.0`) already gives existing consumers automatic uptake of the new flag, no need to inflate the minor for a targeted CLI add-on. `CLI_VERSION_RANGE` in the functions:init scaffolder stays at `^0.26.0` since it still satisfies the bumped CLI version.

`sdk-python` and `sdk-go` are untouched in this PR; their 0.26.0 releases stand.

Test plan

  • `pnpm exec biome check src tests` (no warnings)
  • `pnpm typecheck`
  • `pnpm exec vitest run tests/oclif/functions-test-function.test.ts` (6 passed)
  • `pnpm exec vitest run tests/oclif/functions-init.test.ts` (lockstep test, 27 passed)
  • Smoke against a real function on staging: trigger with --wait --show-sends, verify the JSON outcome includes replies for handlers that send mail.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR closes two discoverability gaps: it introduces a hand-rolled functions:test-function command with --wait / --show-sends / --timeout flags that block until a test inbound lands and the function's webhook reaches a terminal state, and it rewrites the emails topic description in both package files to surface emails:wait and emails:watch. The previous review finding — that only sdk-node/package.json had been updated — is fully resolved here; cli-node/package.json now carries the same updated copy.

  • functions:test-function command (cli-node/src/oclif/commands/functions-test-function.ts): two-phase polling loop — first finds the test inbound via searchEmails, then polls getEmail until webhook_status is fired or exhausted; exits 0 on success, 1 on exhausted, and 2 on timeout. Uses OVERRIDDEN_OPERATION_IDS in index.ts to suppress the auto-generated duplicate.
  • emails topic description (cli-node/package.json, sdk-node/package.json): updated text now mentions emails:wait (bounded blocking) and emails:watch (indefinite stream), matching the PR's discoverability goal.
  • Version bump: both packages advance from 0.26.0 to 0.26.1; CLI_VERSION_RANGE in functions-init.ts remains ^0.26.0, which covers 0.26.1 via semver range and requires no update.

Confidence Score: 5/5

Safe to merge; the new command adds polling on top of existing API endpoints with correct timeout/exit-code handling, and all package description updates are consistent across both packages.

The hand-rolled command follows the established pattern for other CLI shortcuts, the two-phase polling correctly uses poll_since to anchor the search window, terminal webhook states are well-defined, and the OVERRIDDEN_OPERATION_IDS filter cleanly prevents the auto-generated duplicate from being registered. The previous finding about cli-node/package.json carrying stale help text is now fully addressed.

No files require special attention.

Important Files Changed

Filename Overview
cli-node/src/oclif/commands/functions-test-function.ts New hand-rolled command implementing fire-and-forget, --wait, and --show-sends flows with correct polling, timeout, and exit-code logic
cli-node/src/oclif/index.ts Adds OVERRIDDEN_OPERATION_IDS filter to prevent auto-generated functions:test-function from colliding with the new hand-rolled command; correctly splices it into COMMANDS before generatedCommands
cli-node/tests/oclif/functions-test-function.test.ts Smoke tests verify command registration, flag presence/descriptions, and static examples; consistent with the pattern used for other hand-rolled commands
cli-node/package.json Version bumped to 0.26.1; emails topic description updated to surface emails:wait and emails:watch — addresses the previous review finding that only sdk-node had been updated
sdk-node/package.json Version bump to 0.26.1 and matching emails topic description update for the deprecated CLI alias package

Reviews (5): Last reviewed commit: "Bump cli-node and sdk-node to 0.26.1 for..." | Re-trigger Greptile

@etbyrd etbyrd changed the title Surface emails:wait and emails:watch in emails topic help text Make functions:test-function block-and-show-sends; surface watch/wait in help text May 12, 2026
@etbyrd etbyrd force-pushed the discover-emails-watch-wait branch from d5dcd31 to 54aa5c1 Compare May 12, 2026 18:40
@etbyrd etbyrd merged commit fd2b8ea into main May 12, 2026
10 checks passed
@etbyrd etbyrd deleted the discover-emails-watch-wait branch May 12, 2026 18:51
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