Skip to content

chore: split credentials.tsx pure logic into credentials/ modules with tests - #612

Merged
Colin Francis (colifran) merged 7 commits into
mainfrom
colifran/reorg-creds
Aug 8, 2026
Merged

chore: split credentials.tsx pure logic into credentials/ modules with tests#612
Colin Francis (colifran) merged 7 commits into
mainfrom
colifran/reorg-creds

Conversation

@colifran

@colifran Colin Francis (colifran) commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Refactor phase 3, following #611: this breaks the ~5,700-line credentials.tsx file into focused, individually testable modules under src/setup/credentials/, adds coverage for the extracted units, and fixes one setup-flow bug the new tests surfaced.

credentials.tsx is now a thin composition root (30 lines): the setup wizard's state machine lives in a useInitSetup hook, its rendering in an InitSetupView, and its pure logic (routing, formatting, env persistence) in sibling modules with their own test files. The extraction is mechanical and behavior-neutral, with one intentional exception called out under Behavior change below, so reviews get smaller and regressions in the first-run setup surface get caught.

Structure

credentials.tsx went from ~5,744 lines to 30 (a composition root + public re-export shim). Its contents were extracted into:

src/setup/credentials/
  use-init-setup.ts   Ink useInput state machine (the controller)
  view.tsx            presentational InitSetupView
  components.tsx      leaf components + the Prompt step router
  steps.ts            pure step routing / spine / status logic
  format.ts           credential display formatting + masking
  persistence.ts      pure buildCredentialEnvUpdates (env-write derivation)
  constants.ts        types.ts

test/setup/credentials/ mirrors this layout, so every extracted pure module has a sibling test. The use-init-setup.ts controller is coverage-excluded (documented in vitest.config.ts): it is a keyboard-driven useInput flow that unit tests cannot drive cleanly, and its extractable logic already lives in the tested modules above.

Coverage

Both columns measured under the repo's all: true vitest config.

Metric Before (main) After
Statements 70.97% 87.74%
Branches 64.61% 82.45%
Functions 78.43% 92.62%
Lines 71.00% 87.74%
Test files / tests 131 / 1751 137 / 2035

Behavior change

The optional LangSmith setup step no longer re-prompts after it has been declined. needsCredentialSetup already gated the step on the two-signal needsLangSmithStep() (a recorded LANGCHAIN_TRACING_V2 decision counts as answered), but the two entry-point routers — getInitialStep and getNextStepAfterRegion — still used a naive !process.env.LANGSMITH_API_KEY check, so a user who declined LangSmith got sent back into the step whenever setup reopened for another reason. Both routers now use needsLangSmithStep(), with a decision-table regression test covering both routers across all four env states.

Testing

New unit tests for every extracted pure module plus the onboarding.ts gaps above. All tests pass (2035/2035). Typecheck, lint, and build are clean.

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7345805

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openwiki Patch

Not sure what this means? Click here to learn what changesets are.

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

@colifran
Colin Francis (colifran) merged commit 3d51348 into main Aug 8, 2026
14 checks passed
@colifran
Colin Francis (colifran) deleted the colifran/reorg-creds branch August 8, 2026 03:40
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