Skip to content

Sign a Simulator into WordPress.com from a launch-argument token - #25801

Open
jkmassel wants to merge 2 commits into
trunkfrom
jkmassel/sim-wpcom-token-signin
Open

jkmassel wants to merge 2 commits into
trunkfrom
jkmassel/sim-wpcom-token-signin

Conversation

@jkmassel

@jkmassel jkmassel commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Lets a Simulator sign in to WordPress.com from a launch-argument token with no taps, using the same code path as tapping "Continue with WordPress.com".

Summary

  • The login screen runs the "Continue with WordPress.com" button action itself when it first appears and a token was passed. Sign-in, the account sync and the screens that follow are the same as a manual sign-in.
  • The launch argument is now -wpcom-token. The older -ui-test-wpcom-token still works.
  • Removes the unused autoSignInUITestSite helper. Nothing passes the -ui-test-select-wpcom-site argument it reads.
  • docs/simulator-sign-in.md: the command reads the token from a file inside the command, so the token never appears in shell history or an agent's transcript.

Why only once per launch

The token stays in the process's launch arguments after sign-in. Signing out shows a new login screen, and without a guard it would sign straight back in. A static flag on LoginPrologueViewController limits the automatic sign-in to the first time the screen appears in each launch.

What isn't covered

The token still shows in ps while simctl launch runs, as any launch argument does.

Test plan

On a new iPhone 18 Pro simulator (iOS 27.2), with a Jetpack Debug build of this branch. The token was read from a file in every launch command:

  • Launch with -wpcom-token "$(cat <token-file>)" → the app signed in with no tap and showed "Enable Notifications", the same screen a manual sign-in shows on a fresh install.
  • Log out from the Me tab → the app stayed on the login screen and didn't start signing in again.
  • Relaunch with the older -ui-test-wpcom-token → the app signed in and opened My Site.
  • SwiftLint and swift format lint pass on the changed files.

Related

@wpmobilebot

wpmobilebot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number33358
VersionPR #25801
Bundle IDorg.wordpress.alpha
Commit6a719d5
Installation URL10nmn546bf0r8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number33358
VersionPR #25801
Bundle IDcom.jetpack.alpha
Commit6a719d5
Installation URL2t4ba39snumv0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@jkmassel
jkmassel force-pushed the jkmassel/sim-wpcom-token-signin branch from 5b8b264 to 976ef69 Compare July 22, 2026 19:11
@jkmassel
jkmassel requested a review from crazytonyli July 22, 2026 21:29
@jkmassel jkmassel added [Type] Tooling Testing Unit and UI Tests and Tooling labels Jul 22, 2026
@jkmassel jkmassel added this to the 27.2 milestone Jul 22, 2026
@jkmassel
jkmassel marked this pull request as ready for review July 22, 2026 21:31
// login screen. Swap the window root to the signed-in app (no epilogue, so no taps).
windowManager.showUI()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I intentionally kept the sign in flow manual, mainly because I want to avoid introducing another code path to the sign in flow, like this function here. The current auto-sign flow only changes where to get the token/credentials (web or env var).

If we want to fully automated sign in, do you think we can move the logic to the view controller that shows the buttons? Something like:

func viewDidAppear() {
  if autoSignWPCom {
    continueWithWPComButtonAction()
  }
}

For self-hosted site auto-sign in, we can do similar, something like

.onAppear {
  self.siteAddress = siteUrlEnvVar()
  continueButtonAction()
}

With this direction, the sign in code path stays the same, manually or fully automated.


BTW, the autoSignInUITestSite is a left-over dead code and should be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From Claude:

Good call. The separate sign-in path is gone. The login screen now calls the "Continue with WordPress.com" button action itself when it first appears with a token, so automatic and manual sign-in go through the same code. It only does this once per launch, so logging out stays on the login screen. I also deleted autoSignInUITestSite.

Comment thread AGENTS.md Outdated
- Add every unit test target to `WordPressUnitTests.xctestplan`.
- Run the full suite with `xcodebuild -workspace WordPress.xcworkspace -scheme WordPress -testPlan WordPressUnitTests test`. Do not use `swift test`.
- To verify changes end-to-end on an iOS simulator, follow @docs/simulator-sign-in.md to sign in to the app.
- To sign a Simulator into WordPress.com, run `make sim-login` (it targets the running simulator; the WordPress.com token comes from `~/.wpcom-token` or `WPCOM_TOKEN`, and it prompts if none is set). See @docs/simulator-sign-in.md for options and self-hosted sign-in.

@crazytonyli crazytonyli Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it targets the running simulator

There may be multiple running simulators. Or, maybe I want a new one.

the WordPress.com token comes from ~/.wpcom-token or WPCOM_TOKEN

I feel like this belongs to personal configuration. What do you think?


Overall, I feel like the new script adds too many restrictions to what the agent can do intuitively. Currently, I can say "Create a new simulator, sign in to the test account (WP.com or a self-hosted site), perform this end-to-end verification on the Jetpack app", and the agent has enough info (from the AGENTS.md and the sign in doc) to help with that. With this new change, the agent can't get how to do that from the prompts themselves. I have not tried the new script, but I suspect the agent would read the makefile and the new script to understand what it does and then perform the actions.

The new script wraps an oneline simctl command, which AI agents should be able to see in the docs/simulator-sign-in.md. Maybe it solves other problems that I don't see?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From Claude:

Agreed. I dropped the script, the make sim-login target and the AGENTS.md change. Where the token lives is personal setup, so it doesn't belong in the repo. One part of the script was worth keeping: the agent never saw the token. Pasting the token into a raw simctl command puts it in the agent's transcript. So the doc's command now reads the token from a file inside the command, -wpcom-token "$(cat <token-file>)", and tells agents not to print the file.

@wpmobilebot wpmobilebot modified the milestones: 27.2, 27.3 Aug 19, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.2 has now entered code-freeze, so the milestone of this PR has been updated to 27.3.

@wpmobilebot wpmobilebot modified the milestones: 27.3, 27.4 Sep 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.3 has now entered code-freeze, so the milestone of this PR has been updated to 27.4.

jkmassel added a commit to Automattic/wordpress-rs that referenced this pull request Sep 29, 2026
Adds `make example-app-login` (wrapping `scripts/example-app-signin.sh`), which launches the Swift example app on an iOS Simulator with `-wpcom-token`, or the Android example app on an emulator with a `wpcom-token` intent extra. The app stores the token as its WordPress.com account at launch, so no OAuth app credentials or taps are needed.

The token is read from `WPCOM_TOKEN` or `~/.wpcom-token` (or a hidden prompt), never the command line. Modelled on wordpress-mobile/WordPress-iOS#25801.

Co-Authored-By: Claude <noreply@anthropic.com>
jkmassel added a commit to Automattic/wordpress-rs that referenced this pull request Sep 29, 2026
…#1652)

* fix: show the Swift example app's WP.com Sign Out button on iPhone

The `.toolbar` was attached to the `NavigationView`, which drops toolbar items once it collapses to a single column on iPhone, so there was no way to sign out. Attach it to the sidebar column instead.

Co-Authored-By: Claude <noreply@anthropic.com>

* Sign the example apps into WordPress.com from a launch-argument token

Adds `make example-app-login` (wrapping `scripts/example-app-signin.sh`), which launches the Swift example app on an iOS Simulator with `-wpcom-token`, or the Android example app on an emulator with a `wpcom-token` intent extra. The app stores the token as its WordPress.com account at launch, so no OAuth app credentials or taps are needed.

The token is read from `WPCOM_TOKEN` or `~/.wpcom-token` (or a hidden prompt), never the command line. Modelled on wordpress-mobile/WordPress-iOS#25801.

Co-Authored-By: Claude <noreply@anthropic.com>

* Read the example-app sign-in token from wp_com_test_credentials.json

Resolve the token from `WPCOM_TOKEN`, then the repo's `wp_com_test_credentials.json` `bearer_token` (the one the WordPress.com integration tests use), then `~/.wpcom-token`, and fail with a pointer to the credentials file otherwise. This replaces the hidden paste-and-save prompt, which assumed a developer had a token to hand but nowhere to keep it.

Co-Authored-By: Claude <noreply@anthropic.com>

* Say which source the example-app sign-in token came from

Prints `Using the WordPress.com token from <source>` (never the token itself), so it's clear whether `WPCOM_TOKEN`, `wp_com_test_credentials.json`, or `~/.wpcom-token` won.

Co-Authored-By: Claude <noreply@anthropic.com>

* Add a changelog entry for the example-app WordPress.com sign-in

Co-Authored-By: Claude <noreply@anthropic.com>

* Treat placeholder OAuth credentials as unset in the Android example app

`generateWpComCredentials` emitted `client_id: 0` / `client_secret: ""` from `wp_com_test_credentials.json-example` as real credentials, enabling a WordPress.com OAuth button that can't work. The placeholders are required for a bearer-token-only file to satisfy `integration_test_credentials`, so require both values to be non-zero/non-empty or generate both as `null`, matching the Swift example app.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
@wpmobilebot wpmobilebot modified the milestones: 27.4, 27.5 Oct 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.4 has now entered code-freeze, so the milestone of this PR has been updated to 27.5.

@wpmobilebot wpmobilebot modified the milestones: 27.5, 27.6 Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

@jkmassel
jkmassel marked this pull request as draft November 24, 2026 00:57
Nothing passes the `-ui-test-select-wpcom-site` launch argument it
reads, so the helper never runs.
Signing a Simulator in with a launch-argument token still needed a tap
on "Continue with WordPress.com". The login screen now runs that same
button action itself when it first appears with a token, so automatic
and manual sign-in share one code path.

It runs once per launch, so signing out stays on the login screen. The
argument is now `-wpcom-token`; `-ui-test-wpcom-token` still works.

The doc reads the token from a file inside the command, which keeps it
out of shell history and agent transcripts.
@jkmassel
jkmassel force-pushed the jkmassel/sim-wpcom-token-signin branch from 6a719d5 to 23f2db2 Compare November 26, 2026 21:27
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@jkmassel
jkmassel marked this pull request as ready for review November 26, 2026 21:33
jkmassel added a commit that referenced this pull request Nov 26, 2026
docs/ui-tests.md said running the JetpackUITests plan in Xcode skips
the suites that run against the fixtures. It runs them, and each of
their tests fails at launch, because an Xcode build can't include the
fixtures. Also drop references to Scripts/sim-signin.sh, which #25801
no longer adds.
jkmassel added a commit that referenced this pull request Nov 26, 2026
#25801 signs in from the -wpcom-token launch argument through the
login screen, the same way a manual sign-in does. A fresh sign-in
then ends on the "Enable Notifications?" screen instead of My Site,
and every test that resets the app timed out waiting for My Site.

@crazytonyli crazytonyli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A small issue: When the app is already logged in and the launch argument is passed to the app, logging out would auto sign in again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing Unit and UI Tests and Tooling [Type] Tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants