Skip to content

refactor(test): standardize log capture on useCaptureLog#287

Open
wyattjoh wants to merge 1 commit into
mainfrom
wyattjoh/use-capture-log
Open

refactor(test): standardize log capture on useCaptureLog#287
wyattjoh wants to merge 1 commit into
mainfrom
wyattjoh/use-capture-log

Conversation

@wyattjoh
Copy link
Copy Markdown
Contributor

@wyattjoh wyattjoh commented May 13, 2026

Summary

Standardize unit-test log capture on a single helper, and stabilize the integration harness.

Unit-test log capture is rebuilt on top of a useCaptureLog() lifecycle helper that installs a fresh buffer per test via beforeEach/afterEach, replacing the prior AsyncLocalStorage-backed captureLog().run(...) wrapper. With the slot installed automatically, test bodies no longer wrap their emitting calls. As part of this, log.ui() stops appending its own trailing newline so spinner cursor-control writes survive, the cli-program writeErr newline-stripping workaround that compensated for the old behavior is removed, and a latent double-newline bug in the spinner output is fixed by moving the trailing \n onto each emitting call site.

The integration harness's config load moves out of a top-level await so each test gets a fresh instance, and a new harness test covers the new shape.

Test plan

  • bun run format:check
  • bun run lint
  • bun run typecheck
  • bun run test

@wyattjoh
Copy link
Copy Markdown
Contributor Author

wyattjoh commented May 13, 2026

Stack: wyattjoh/nextjs-pinned-range

Part of a stacked-prs chain. Do not merge manually.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2026

⚠️ No Changeset found

Latest commit: 05e1716

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@wyattjoh wyattjoh changed the title refactor(test): standardize log capture on useCaptureLog and stabilize integration harness refactor(test): standardize log capture on useCaptureLog May 13, 2026
@wyattjoh wyattjoh force-pushed the wyattjoh/use-capture-log branch from 88c14ab to 8cc424a Compare May 13, 2026 20:03
@wyattjoh wyattjoh force-pushed the wyattjoh/nextjs-pinned-range branch 2 times, most recently from 5e0198f to 7750d4a Compare May 14, 2026 18:13
@wyattjoh wyattjoh force-pushed the wyattjoh/use-capture-log branch 3 times, most recently from 950205c to 6f9372a Compare May 14, 2026 18:53
@wyattjoh wyattjoh force-pushed the wyattjoh/nextjs-pinned-range branch from 710f7b0 to 8881d1d Compare May 14, 2026 18:53
@wyattjoh wyattjoh force-pushed the wyattjoh/use-capture-log branch 2 times, most recently from 4183e10 to b1d6e71 Compare May 14, 2026 19:52
Base automatically changed from wyattjoh/nextjs-pinned-range to main May 14, 2026 21:17
…e integration harness

Replace ad-hoc log spy patterns across every command and lib test with the
useCaptureLog helper. Refactor log.ts and spinner.ts so the helper can hook
in cleanly, drop unused test-helper imports as a side effect.

Add a harness test covering the lazy config-module loader so each test gets
a fresh instance.
@wyattjoh wyattjoh force-pushed the wyattjoh/use-capture-log branch from b1d6e71 to 05e1716 Compare May 14, 2026 21:19
@wyattjoh wyattjoh marked this pull request as ready for review May 14, 2026 21:19
@wyattjoh wyattjoh requested a review from rafa-thayto May 14, 2026 21:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21c460fa-6406-44f2-aa8f-97ff0af31ad5

📥 Commits

Reviewing files that changed from the base of the PR and between 6ac3fa7 and 05e1716.

📒 Files selected for processing (41)
  • .claude/rules/logging.md
  • packages/cli-core/src/cli-program.ts
  • packages/cli-core/src/commands/api/catalog.test.ts
  • packages/cli-core/src/commands/api/index.test.ts
  • packages/cli-core/src/commands/api/interactive.test.ts
  • packages/cli-core/src/commands/api/ls.test.ts
  • packages/cli-core/src/commands/apps/create.test.ts
  • packages/cli-core/src/commands/apps/list.test.ts
  • packages/cli-core/src/commands/auth/login.test.ts
  • packages/cli-core/src/commands/auth/logout.test.ts
  • packages/cli-core/src/commands/billing/index.test.ts
  • packages/cli-core/src/commands/config/pull.test.ts
  • packages/cli-core/src/commands/config/push.test.ts
  • packages/cli-core/src/commands/config/schema.test.ts
  • packages/cli-core/src/commands/deploy/index.test.ts
  • packages/cli-core/src/commands/doctor/context.test.ts
  • packages/cli-core/src/commands/env/pull.test.ts
  • packages/cli-core/src/commands/init/index.test.ts
  • packages/cli-core/src/commands/init/scan.test.ts
  • packages/cli-core/src/commands/link/index.test.ts
  • packages/cli-core/src/commands/open/index.test.ts
  • packages/cli-core/src/commands/orgs/index.test.ts
  • packages/cli-core/src/commands/switch-env/index.test.ts
  • packages/cli-core/src/commands/unlink/index.test.ts
  • packages/cli-core/src/commands/users/create.test.ts
  • packages/cli-core/src/commands/users/list.test.ts
  • packages/cli-core/src/commands/users/menu.test.ts
  • packages/cli-core/src/commands/users/open.test.ts
  • packages/cli-core/src/commands/whoami/index.test.ts
  • packages/cli-core/src/lib/auth-server.test.ts
  • packages/cli-core/src/lib/autoclaim.test.ts
  • packages/cli-core/src/lib/autolink.test.ts
  • packages/cli-core/src/lib/bapi-command.test.ts
  • packages/cli-core/src/lib/first-application.test.ts
  • packages/cli-core/src/lib/keyless.test.ts
  • packages/cli-core/src/lib/log.test.ts
  • packages/cli-core/src/lib/log.ts
  • packages/cli-core/src/lib/spinner.ts
  • packages/cli-core/src/test/integration/lib/harness.test.ts
  • packages/cli-core/src/test/integration/lib/harness.ts
  • packages/cli-core/src/test/lib/stubs.ts

📝 Walkthrough

Walkthrough

This PR replaces the CLI's AsyncLocalStorage-based log capture mechanism with a module-level activeCapture variable and a new useCaptureLog() hook-based test pattern. Core changes include: adding getActiveCapture()/setActiveCapture() accessors to log.ts; introducing log.ui() for pre-formatted UI output; rerouting spinner output through log.ui(); refactoring test stubs from captureLog() to useCaptureLog(); updating the integration harness to use setActiveCapture(); configuring commander output routing in cli-program.ts; and migrating 40+ test files to remove captured.run() wrappers and explicit teardown calls.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • clerk/cli#280: Both PRs refactor the same logging and test capture infrastructure, replacing AsyncLocalStorage-based captureLog/withCapturedLogs with the new activeCapture/useCaptureLog pattern.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: standardizing log capture on the useCaptureLog helper across tests.
Description check ✅ Passed The description provides relevant context about the log capture refactoring, the introduction of useCaptureLog, and related changes to log.ui() and the integration harness.
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.

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


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

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