Bring the interactive site selector to pull-reprint - #3729
Conversation
…interactive-site-selector-to-pull-reprint # Conflicts: # apps/cli/commands/tests/pull-reprint.test.ts
…ring-the-interactive-site-selector-to-pull-reprint
📊 Performance Test ResultsComparing d43d5bd vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
…interactive-site-selector-to-pull-reprint
…or-to-pull-reprint
fredrikekelund
left a comment
There was a problem hiding this comment.
The control works well, but we need to look into the site list fetching. Right now, non-Atomic sites are displayed in the list, but selecting them leads to an error like this for me:
✖ Invalid API response format: Zod validation failed: [
{
"expected": "string",
"code": "invalid_type",
"path": [
"body",
"data",
"secret"
],
"message": "Invalid input: expected string, received undefined"
}
]. Raw response: {"code":404,"headers":[{"name":"Content-Type","value":"application/json"}],"body":{"error":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}}
| /** | ||
| * Interactive, searchable WordPress.com site picker. | ||
| * | ||
| * A trimmed clone of `pickSyncSite` (`apps/cli/lib/sync-site-picker.ts`) | ||
| * for the `pull-reprint` source-selection flow. It keeps the | ||
| * `[staging]` badge but, because `WpComSiteInfo` has no `syncSupport`, | ||
| * drops the disabled-entry and sync-support logic — every site is | ||
| * selectable. | ||
| * | ||
| * Type-to-filter matches on the site name and normalized hostname. Esc | ||
| * cancels the prompt (TTY only, via an `AbortController` wired to the | ||
| * raw escape byte) and resolves to `undefined`, as does Ctrl-C — so the | ||
| * caller can treat a cancellation as a clean no-op rather than an error. | ||
| */ |
There was a problem hiding this comment.
In my testing, it doesn't appear that Reprint can sync non-Atomic sites. I would think this should be theoretically possible with how the Reprint exporter is deployed through wpcomsh, but I'm not familiar enough with wpcomsh to say for sure.
In any case, we need to adjust this implementation:
- We should only display syncable sites in the list. The simple solution to this problem is to change the site fetching to use the same implementation as
apps/cli/commands/pull.ts - If we do this, then there's not really a need for separate implementations between the
pullandpull-reprintcommands, as I understand it. Yes, the Jetpack-poweredpullcommand is going away soon enough, so this isn't very important, but it'd be a nice touch. - We should talk to Adam about whether Reprint is intended to work for simple sites, too, and what adjustments we might need to make that work.
There was a problem hiding this comment.
separate implementations
I guess I explicitly said not to worry about this in the Linear issue 😅 Let's ignore this unless the implementation end up 1:1
There was a problem hiding this comment.
Well spotted! I didn't have any simple sites so when comparing with the pull command I was obtaining the same results, I will work on that.
| // In a real terminal, let the user pick interactively. Outside a | ||
| // TTY (CI, Desktop driving the command), keep the original | ||
| // print-list-and-abort behavior so scripted callers are | ||
| // unaffected. | ||
| if ( ! process.stdin.isTTY ) { | ||
| console.log( __( 'Connected WordPress.com sites:' ) ); | ||
| console.log( formatWpComSitesList( sites ) ); | ||
| console.log( '' ); | ||
| throw new LoggerError( | ||
| __( 'Multiple WordPress.com sites are available. Re-run with `--url <site-url>`.' ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
If no --url option was provided and this isn't a TTY, I think it's fine to just exit with an error. Realistically, the main case in which this command would be triggered in a non-TTY context is when it is spawned as a child command of Studio.
If we follow this suggestion, then let's also remove the formatWpComSitesList function.
I could also see us moving the if ( ! process.stdin.isTTY ) into the pickWpComSite implementation, but I'll leave that to you, @epeicher
There was a problem hiding this comment.
Addressed as part of fc3d1fa, with regards to moving the condition, I prefer the TTY gate at the call site: "are we allowed to prompt, and what do we do if not?" and keep the picker focused on "given a list, return a choice or a cancel."
…site-selector-to-pull-reprint' into studio-10-bring-the-interactive-site-selector-to-pull-reprint
…or-to-pull-reprint
…site-selector-to-pull-reprint' into studio-10-bring-the-interactive-site-selector-to-pull-reprint
|
Hi @fredrikekelund, after our conversation, I have checked the conditions to pull sites and I've decided to unify them so The logic is greatly simplified, can you have a look at it and let me know any issues? |
…or-to-pull-reprint
fredrikekelund
left a comment
There was a problem hiding this comment.
Looks good! 👍 There's more we can do to streamline and simplify site fetching and preflight logic, but we can do that in follow-up PRs
Related issues
Selector compared with previous one
How AI was used in this PR
Claude Code adapted the existing
pullsite selector (pickSyncSite) into a trimmedpull-reprintvariant per the issue's guidance to copy rather than abstract (sincepullis being deprecated), added unit tests for both the picker and the source-resolution flow, and verified the change —cli:build,typecheck, and the new test suites all pass. I reviewed the diff against the reference implementation and confirmed there are no behavior changes on the non-interactive paths.Proposed Changes
When you run
pull-reprintwithout--urland have more than one connected WordPress.com site, the command previously printed the list and aborted, forcing you to re-run with an explicit--url. Now, in an interactive terminal, it opens a searchable site picker (type to filter by name or hostname, arrow keys to navigate, Enter to select) — the same friendly selection experience already offered bypull. Cancelling with Esc or Ctrl-C is treated as a clean no-op: nothing is downloaded and no local state is created.Existing behavior is preserved everywhere else: a single connected site is still auto-selected, the zero-site and
--url/--secretpaths are unchanged, and non-interactive callers (CI, the Desktop app driving the CLI) keep the original print-list-and-abort behavior so scripted usage is unaffected.Testing Instructions
studio auth login).npm run cli:buildfirst)~/Studio/and no state under~/.studio/pulls/.... pull-reprint | cat) should fall back to printing the list and aborting.Pre-merge Checklist