feat(twitter): add switch-account command with --list and @handle modes#1858
Open
Semonxue wants to merge 8 commits into
Open
feat(twitter): add switch-account command with --list and @handle modes#1858Semonxue wants to merge 8 commits into
Semonxue wants to merge 8 commits into
Conversation
- openAccountMenu: click side-nav trigger, poll for UserCell - readAccountMenu: exported for unit tests, parses all UserCell rows - --list: open menu → read accounts → close menu → return table - @handle: click aria-label button, poll for trigger update - best-effort menu close (AppTabBar_Profile_Link click) - graceful error messages with available-account list on switch miss - 14 unit tests covering routing, readAccountMenu, --list, and switch modes
…ests - Use LI-based current account detection (no Switch button) instead of relying on trigger avatar, which caches the previous active account - Improve avatar container scoping to [data-testid=UserCell] to avoid counting page-level avatars - Add list mode: --list to enumerate accounts without switching - Rewrite tests to match new evaluate block structure with real error paths (AUTH_REQUIRED, ARGUMENT, NOT_FOUND, already_current, switched)
…for reliable switching
The current account renders as <li> in the switcher menu (no 'Switch to' button), so switching to it via @handle previously threw NOT_FOUND. Detect via the isCurrent flag on the parsed accounts list and return already_current. Also drops the debug suffix from the already_current message.
6657691 to
d166e7a
Compare
…p lint
- readAccountMenu: rename displayName/isCurrent → display_name/is_current
- page.evaluate: return accounts array directly (list mode) to avoid
returning a { mode, currentHandle, accounts } wrapper with non-column keys
- already_current / switched wrappers: mode → status, drop currentHandle
- NOT_FOUND: drop available field; bake the list into the message
- defensive: only unwrap a 1-element array (was always splitting list output)
- tests: update mocks to match new return shapes; assert on err.hint not err.message
…rror when handle is missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
opencli twitter switch-accountfor the X account-switcher menu:opencli twitter switch-account --listenumerates every account in the switcher, marking the active one.opencli twitter switch-account @handleswitches into the named account by clicking the matchingaria-label="Switch to @handle"button. Ifhandlealready matches the active account, returnsstatus: already_current.isCurrentis detected from the menu's DOM: the current account renders as<li data-testid="UserCell">(no "Switch to" button), while the other accounts are<button data-testid="UserCell" aria-label="Switch to @xxx">. The trigger avatar was unreliable for this because X caches the previous active account there until a full page reload.After clicking the switch button, the page is reloaded so the Playwright session syncs to the new account before the next call.
Tests
npx vitest run --project adapter clis/twitter/switch-account.test.js— 15 / 15 passnpm run test:adapter— 382 files / 3780 tests passnpm run typecheck— cleannpm run build— clean,cli-manifest.jsonregeneratesLive verify
Files
clis/twitter/switch-account.js— newclis/twitter/switch-account.test.js— new, 15 unit tests covering argument routing,readAccountMenu, registration,--listmode, and switch-mode error paths (auth required, malformed handle, target not in menu, already current, switched)CHANGELOG.md—## UnreleasedFeatures entry