Skip to content

fix switch bug(oss host), and optimise branch create flow.#112

Merged
jwfing merged 6 commits intomainfrom
feat/branching
May 8, 2026
Merged

fix switch bug(oss host), and optimise branch create flow.#112
jwfing merged 6 commits intomainfrom
feat/branching

Conversation

@jwfing
Copy link
Copy Markdown
Member

@jwfing jwfing commented May 8, 2026


Summary by cubic

Fixes branch switch writing a bare oss_host and auto-heals existing configs. Improves branch create with a single @clack/prompts spinner covering create, provisioning, and the auto-switch, with clear switch‑failure messaging; JSON mode unchanged.

  • Bug Fixes

    • Switch saves oss_host via buildOssHost() (https); getProjectConfig() normalizes legacy bare-host values on read.
    • After a successful create, a switch error is reported as “switching context failed” with a retry hint, not “creation failed”.
  • New Features

    • One spinner spans create → provisioning → switch, stays active through switch, and failures render in the same frame; runBranchSwitch now runs with silent: true.
    • JSON mode still outputs only the final { branch } payload.

Written for commit 34f5383. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Spinner feedback now spans branch creation, provisioning, and optional auto-switch for clearer CLI progress.
  • Bug Fixes

    • Legacy OSS host values are normalized to a valid HTTPS URL; OSS host construction centralized to ensure consistent URLs.
  • Chores

    • Bumped package version to 0.1.70.
  • Tests

    • Added tests for spinner lifecycle and OSS host construction; updated branch-switch tests to reflect URL behavior.

jwfing and others added 4 commits May 7, 2026 20:24
branch switch wrote oss_host as a bare hostname, so every later ossFetch
threw "Failed to parse URL". Extract the buildOssHost helper that
create/link already use into src/lib/config.ts and use it from switch
too, so all three sites share one canonical URL builder.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The POST /branches request can hang for ~2 minutes before returning,
during which the CLI printed nothing — easy to mistake for a hang.
Wrap createBranchApi and pollUntilReady in a single clack.spinner()
that animates through the slow POST and updates its message in place
on each provisioning state change. JSON mode is unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2a4bb30-0e41-4952-8ff0-d4ee6ebcb28c

📥 Commits

Reviewing files that changed from the base of the PR and between ec96748 and 34f5383.

📒 Files selected for processing (2)
  • src/commands/branch/create.test.ts
  • src/commands/branch/create.ts

Walkthrough

This PR centralizes OSS host URL construction into a shared utility, refactors commands to use it, normalizes legacy config, integrates a spinner into branch creation/polling/switch flows, updates tests, and bumps the package version to 0.1.70.

Changes

OSS Host Utility Extraction

Layer / File(s) Summary
Utility Definition
src/lib/config.ts
New buildOssHost(appkey, region) export and getProjectConfig() normalization; ensures oss_host is an HTTPS URL.
Command Migration
src/commands/create.ts, src/commands/projects/link.ts, src/commands/branch/switch.ts
Commands remove local helpers and import buildOssHost from the shared config module; runBranchSwitch uses the shared helper.
Tests and Version
src/lib/config.test.ts, src/commands/branch/switch.test.ts, package.json
Added tests for buildOssHost, updated switch test expectations to HTTPS oss_host, and bumped version to 0.1.70.

Branch Create Spinner Integration

Layer / File(s) Summary
Spinner Dependency
src/commands/branch/create.ts
Imports @clack/prompts spinner and removes outputSuccess import.
Spinner-Driven Flow
src/commands/branch/create.ts
Single spinner spans create POST, polling, and optional auto-switch in non-JSON mode; JSON mode disables spinner and emits only JSON output.
Polling Helper Signature
src/commands/branch/create.ts
pollUntilReady now accepts a nullable spinner parameter and updates spinner messages on branch-state changes instead of conditional progress printing.
Spinner Tests
src/commands/branch/create.test.ts
Mocks @clack/prompts spinner, resets spinner mock state in beforeEach, and adds tests asserting spinner start/stop messages and silent switch invocation, plus failure messaging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Fermionic-Lyu

Poem

🐇 A tiny spinner hops in place,
While hosts find their HTTPS grace,
Shared helper stitched, the branches sing,
Tests check the tune, the version's spring,
Rabbits clap — the CLI's in pace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main changes: fixing the OSS host bug in branch switch and optimizing the branch create flow with a spinner for better UX.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/branching

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Microsoft Presidio Analyzer (2.2.362)
src/commands/branch/create.test.ts

Microsoft Presidio Analyzer failed to scan this file


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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/commands/branch/create.ts (1)

56-71: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Delay the success spinner until after auto-switch completes.

In the default --switch path, Lines 57-60 mark the flow as successful before runBranchSwitch(...) runs. If the switch step fails, the terminal still shows a success spinner entry even though the overall command errors. Keep the spinner active through the switch, or change it to a neutral “Switching context...” message first.

🤖 Prompt for 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.

In `@src/commands/branch/create.ts` around lines 56 - 71, The success spinner is
stopped before the optional auto-switch runs, which can show a success even if
runBranchSwitch fails; modify the flow around spinner, runBranchSwitch, and
outputJson so the spinner remains active through the switch: if opts.switch and
ready.branch_state === 'ready' either change spinner text to a neutral message
like "Switching context..." (using the existing spinner instance) while awaiting
runBranchSwitch({ name, apiUrl, json, silent: json }), or defer calling
spinner?.stop(...) until after runBranchSwitch completes successfully; ensure
spinner is stopped with the appropriate success or error message and only then
call outputJson({ branch: ready }).
🤖 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.

Outside diff comments:
In `@src/commands/branch/create.ts`:
- Around line 56-71: The success spinner is stopped before the optional
auto-switch runs, which can show a success even if runBranchSwitch fails; modify
the flow around spinner, runBranchSwitch, and outputJson so the spinner remains
active through the switch: if opts.switch and ready.branch_state === 'ready'
either change spinner text to a neutral message like "Switching context..."
(using the existing spinner instance) while awaiting runBranchSwitch({ name,
apiUrl, json, silent: json }), or defer calling spinner?.stop(...) until after
runBranchSwitch completes successfully; ensure spinner is stopped with the
appropriate success or error message and only then call outputJson({ branch:
ready }).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3987b47e-087c-4c64-ab7f-3a85e95931c4

📥 Commits

Reviewing files that changed from the base of the PR and between d4285ef and 294c90d.

📒 Files selected for processing (7)
  • package.json
  • src/commands/branch/create.ts
  • src/commands/branch/switch.test.ts
  • src/commands/branch/switch.ts
  • src/commands/create.ts
  • src/commands/projects/link.ts
  • src/lib/config.ts

Comment thread src/lib/config.ts
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Copy link
Copy Markdown
Member Author

@jwfing jwfing left a comment

Choose a reason for hiding this comment

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

Code Review — #112

Summary: Solid bug fix and UX improvement. The https:// scheme fix in switch.ts is correct and the extraction of buildOssHost into config.ts properly eliminates three independent copies of the same string-building logic. The clack spinner in branch create is a clear UX win over the previous silent hang.


Requirements context

No /docs/superpowers/ directory exists in this repo. Review assessed against the PR description and code intent directly.


Findings

Critical

(none)


Suggestion

[Software Engineering] buildOssHost has no direct unit testsrc/lib/config.ts:110

The bug being fixed (missing https:// scheme) was caused by an unchecked string expression. buildOssHost is now the canonical implementation used by four call sites, but it has no unit test of its own. The switch test (switch.test.ts:11) exercises the behavior end-to-end, but it does so via a mock that independently hard-codes the expected format — it doesn't call the real function. A trivial test in a config.test.ts would give early warning if the function's output ever drifts:

it('buildOssHost always returns an https URL', () => {
  expect(buildOssHost('p1ky-x9p', 'us-east')).toBe('https://p1ky-x9p.us-east.insforge.app');
});

[Software Engineering] No test covers the interactive (non-JSON) spinner pathsrc/commands/branch/create.ts:38-64

All three tests in create.test.ts invoke the command with --json, which sets spinner = null and skips every clack call. The spinner refactoring — spinner.start, spinner.message inside pollUntilReady, spinner.stop on success and error — is exercised zero times by the test suite. If @clack/prompts is not mocked and a future test removes --json, the spinner will hit a real TTY and may hang or throw. Consider adding one non-JSON happy-path test with @clack/prompts mocked (the mock used in link.test.ts can serve as a template):

vi.mock('@clack/prompts', () => ({
  spinner: () => ({ start: vi.fn(), message: vi.fn(), stop: vi.fn() }),
}));

Information

  • No security-relevant changes. All external inputs (branch name, mode) were already validated upstream; no new user input reaches SQL, shell, or HTTP without validation. @clack/prompts is an existing dependency (not newly introduced).

  • No performance concerns. POLL_INTERVAL_MS and POLL_TIMEOUT_MS are unchanged; the spinner merely replaces outputInfo calls inside the polling loop.

  • src/lib/config.ts:103-111 JSDoc is well-written. The comment explains why the scheme is required (fetch() rejects bare hostnames), which is exactly the right level of documentation for a bug-prevention helper.

  • Version bump (0.1.69 → 0.1.70) in package.json. Consistent with what appears to be the project's release-in-PR pattern; nothing wrong here, just noting it is included.


Verdict

approved (informational — explicit GitHub approval is a separate human action)

No Critical findings. The two Suggestions (direct unit test for buildOssHost, non-JSON test for the spinner path) are worth addressing in a follow-up but are not blocking.

Address PR #112 review:

- `getProjectConfig()` now repairs bare-hostname `oss_host` values written
  by the buggy `branch switch` (pre-0.1.70). Without this, users who
  already switched on the broken build stay broken until they re-switch.
- `branch create` keeps the spinner active through `runBranchSwitch`
  (silent: true always now), so a switch failure renders as a red error
  frame instead of the misleading "✓ Branch is ready" line followed by
  an error.
- Add direct unit test for `buildOssHost` and a non-JSON spinner-path
  test for `branch create` (mocks `@clack/prompts`), closing two gaps
  flagged in review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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/branch/create.ts`:
- Around line 71-73: The catch currently always reports "Branch '<name>'
creation failed" even if the error came from runBranchSwitch(); change the
control flow so errors from branch creation and errors from switching are
handled separately: move the runBranchSwitch() call into its own try/catch (or
detect and rethrow with a different error type/message) and call spinner?.stop
with "Branch '<name>' creation failed" only for creation errors, and with a
distinct message like "Switching to branch '<name>' failed" for
runBranchSwitch() failures; update the throw to rethrow the original error after
the appropriate spinner?.stop call.
🪄 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: CHILL

Plan: Pro

Run ID: a3d11b11-aeb9-4435-a46c-a089ac73a7e6

📥 Commits

Reviewing files that changed from the base of the PR and between 294c90d and ec96748.

📒 Files selected for processing (4)
  • src/commands/branch/create.test.ts
  • src/commands/branch/create.ts
  • src/lib/config.test.ts
  • src/lib/config.ts
✅ Files skipped from review due to trivial changes (1)
  • src/lib/config.test.ts

Comment thread src/commands/branch/create.ts
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/commands/branch/create.ts">

<violation number="1" location="src/commands/branch/create.ts:64">
P2: If `runBranchSwitch` throws, the catch block reports "creation failed" even though the branch was successfully created and provisioned. This misleads users into thinking the branch doesn't exist. Consider distinguishing switch failures from creation failures in the spinner stop message.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src/commands/branch/create.ts
If runBranchSwitch threw after the branch was successfully created and
provisioned, the catch reported "Branch X creation failed" — but the
branch was alive in the cloud, so users would either re-create it (name
collision) or assume nothing happened.

Track a `provisioned` flag and pick the right copy in catch: switch
failures now say "Branch X is ready, but switching context failed —
run \`insforge branch switch X\` to retry". Only true creation/poll
failures keep the original message.

Add a regression test mocking runBranchSwitch to throw and asserting
the spinner does not say "creation failed".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jwfing jwfing merged commit c893d93 into main May 8, 2026
3 of 4 checks passed
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