Skip to content

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

Merged
wyattjoh merged 3 commits into
mainfrom
wyattjoh/use-capture-log
May 21, 2026
Merged

refactor(test): standardize log capture on useCaptureLog#287
wyattjoh merged 3 commits 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: 25cef18

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: 995f18d5-b478-4749-b708-10c8d064474a

📥 Commits

Reviewing files that changed from the base of the PR and between cb9b976 and 25cef18.

📒 Files selected for processing (2)
  • packages/cli-core/src/lib/log.ts
  • packages/cli-core/src/test/integration/lib/harness.test.ts
💤 Files with no reviewable changes (1)
  • packages/cli-core/src/lib/log.ts

📝 Walkthrough

Walkthrough

This PR replaces the CLI's AsyncLocalStorage-based log capture with a module-level activeCapture and exported accessors, introduces log.ui() for pre-formatted stderr UI output, routes commander output through log.data/log.ui, reroutes spinner output to log.ui(), replaces captureLog() with a useCaptureLog() test hook, updates the integration harness to use setActiveCapture(), and migrates 40+ tests to the new capture pattern (removing captured.run wrappers and per-test teardown).

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 20.45% 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 'refactor(test): standardize log capture on useCaptureLog' accurately summarizes the primary change in this PR.
Description check ✅ Passed The description clearly explains the motivation, changes, and test plan for standardizing log capture, making it fully related to the changeset.
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.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

# Conflicts:
#	packages/cli-core/src/commands/whoami/index.test.ts
#	packages/cli-core/src/lib/bapi-command.test.ts
Comment thread packages/cli-core/src/lib/log.ts Outdated
- remove unused log capture accessor
- enforce integration harness import invariant with AST check
@wyattjoh wyattjoh requested a review from rafa-thayto May 21, 2026 20:35
@wyattjoh wyattjoh merged commit 6a47f50 into main May 21, 2026
10 checks passed
@wyattjoh wyattjoh deleted the wyattjoh/use-capture-log branch May 21, 2026 20:35
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