Skip to content

feat(runner): configure emails client before running flows#1382

Draft
Chase J (chajac) wants to merge 4 commits into
mainfrom
chajac/cli-emails-wiring
Draft

feat(runner): configure emails client before running flows#1382
Chase J (chajac) wants to merge 4 commits into
mainfrom
chajac/cli-emails-wiring

Conversation

@chajac

@chajac Chase J (chajac) commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Resolves: WIZ-10915

Overview of Changes

Wires the @qawolf/emails client into the flow run path so email-dependent flows (e.g. magic-link / OTP login) work locally. Previously configureEmails existed but was never called, so any flow calling mail.inbox() failed with "… requires a client. Call configureEmailsClient(...) …".

  • configureEmails rewritten to configure the client against the authenticated API (base URL + API key + team id), replacing the unused stub.
  • configureEmailsForRun helper resolves the API key + team id and configures the client once per flow executing process. It is total/graceful: if auth, identity, or the client can't be resolved it returns a skipped-* outcome and the run proceeds.
  • Wired into both run paths: the in process run (--workers 1) and the worker subprocess (--workers >1).
  • resolveApiBaseUrl extracted to a shared helper so the worker (which has no CommandContext) resolves the same base URL as the command context.

Testing

  • Unit tests for resolveApiBaseUrl, configureEmails, and
    configureEmailsForRun.
  • Verified end to end with the node built CLI against a real environment: the
    client configures and the OTP email is retrieved successfully for the login
    flow.
bun run typecheck
bun run lint
bun run format:check
bun run knip
bun run test
bun run build

Checklist

  • Changes follow the code style of this project
  • Self-review completed
  • Tests added/updated (or not applicable)
  • No breaking changes (or described below)

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

A new resolveApiBaseUrl utility is extracted to src/shell/resolveApiBaseUrl.ts, replacing inline QAWOLF_API_URL resolution in buildBaseContext. The configureEmails function is refactored to accept a single params object adding apiKey and teamId, switching the client URL to ${apiBaseUrl}/api and raising default timeouts to 300s/15s. A new configureEmailsForRun module introduces a ConfigureEmailsOutcome discriminated union and an orchestrator that resolves API credentials, fetches team identity, and configures the emails client with graceful degradation. A convenience wrapper configureEmailsForInProcessRun gates execution to single-worker runs. Both the in-process run paths (runDefaults, hybridRunDefaults) and the worker subprocess (runWorker.register) are updated to call these functions during startup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, imperative, and accurately describes wiring the emails client into flow execution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description matches the required structure and includes overview, testing, and checklist details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/flows/configureEmailsForRun.ts`:
- Around line 44-56: The configureEmailsForRun helper only handles the undefined
and !ok paths, so exceptions from resolveApiKey() or getIdentity() can still
abort the run instead of producing a skipped-* result. Update the main flow in
configureEmailsForRun to catch errors around both dependency calls, log a
concise skip message, and return the appropriate skipped outcome (for auth/read
failures and identity/dependency failures) so startup continues gracefully. Use
the existing resolveApiKey and getIdentity symbols to wrap the error-prone calls
without changing the successful path behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2cae0c84-4c21-4b15-8344-1c2d9c3db709

📥 Commits

Reviewing files that changed from the base of the PR and between 989579d and 77824a9.

📒 Files selected for processing (10)
  • src/commands/context.ts
  • src/commands/flows/configureEmailsForRun.test.ts
  • src/commands/flows/configureEmailsForRun.ts
  • src/commands/flows/hybridRunDefaults.ts
  • src/commands/flows/runDefaults.ts
  • src/commands/flows/runWorker.register.ts
  • src/domains/emails/configureEmails.test.ts
  • src/domains/emails/configureEmails.ts
  • src/shell/resolveApiBaseUrl.test.ts
  • src/shell/resolveApiBaseUrl.ts

Comment thread src/commands/flows/configureEmailsForRun.ts
@chajac Chase J (chajac) marked this pull request as draft June 24, 2026 11:19
@chajac Chase J (chajac) marked this pull request as ready for review June 24, 2026 14:45
@chajac Chase J (chajac) marked this pull request as draft June 25, 2026 10:58
@qa-wolf

qa-wolf Bot commented Jun 26, 2026

Copy link
Copy Markdown

E2E tests

  • Last commit: 989579d
  • Last tested commit: None

Steps:

  1. When you're ready for a review, click the button to run E2E tests.
  2. If you pushed commits after tests finished, re-run them before merging.

🐺 If tests fail, you can relax and do nothing: your wolf pack will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant