Skip to content

factory: connect the first run's GitHub in the browser (device flow) - #2494

Merged
santoshkumarradha merged 3 commits into
factory/general-intakefrom
factory/gh-signin
Nov 7, 2026
Merged

santoshkumarradha merged 3 commits into
factory/general-intakefrom
factory/gh-signin

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

The app's first run can now connect GitHub in the browser with GitHub's OAuth device flow. The person sees a one-time code, approves on github.com/login/device, and setup moves on by itself. Owner's rule (2026-11-07): WorkAF users never think about code. Desk half: Agent-Field/codeaf-desk#281.

Wire

  • factory.setup_github_start {caller} → FactorySignIn, the shape factory.sign_in_start answers. GitHub's device code stays in the engine.
  • factory.setup_github_poll {flow, caller} → {state: pending|signed_in|expired|denied, interval?, message?, github_token?, view?}.
    • A poll that comes too soon is answered without asking GitHub, and slow_down raises the interval.
    • On approval the token goes through the pasted token's own connect (FactorySetupAct connect, source token), so there is no second credential store.
    • The signed_in answer then carries github_token once, for the app's Keychain, which is where a pasted token is kept. It is the only setup answer that carries a secret.
  • factory.setup_github_cancel {flow, caller}.
  • Hello feature factory.setup_github, announced only when the build names an OAuth app. Absent, not broken: without one the methods are unknown_method.

Client ID and scope

  • Client ID: stamped at build time (make build|app-sidecar CODEAF_GITHUB_CLIENT_ID=Ov23…; release.yml reads the repository variable vars.CODEAF_GITHUB_CLIENT_ID), or set at run time from CODEAF_GITHUB_CLIENT_ID. Verified with -ldflags -X.
  • Scope: repo only. It is the one classic scope that reads issues, comments, pushes a branch and opens a PR on a private repository; classic OAuth has nothing narrower for private repos. GET /user needs no scope.
  • Not requested: workflow. A job whose change edits .github/workflows/* will be refused on push.
  • Test-only base URL: CODEAF_GITHUB_LOGIN_URL points the device calls at a stand-in, and must be https or loopback http.

Also in this PR

  • PROTOCOL.md rows and a prose paragraph.
  • A manual section: "connect GitHub in the app — sign in with GitHub in the browser, the one-time code, gh already signed in, paste a token instead", plus 3 probes.
  • Change entry docs/changes/unreleased/2494-factory-github-browser-sign-in.md.

Proof

  • Unit: TestSetupGitHub* (3), the real wire on a fake GitHub:
    • pending → slow_down → grant, with the pace held;
    • another window's flow is not_found;
    • the view after the connect, with the token in app credentials;
    • the device code never on the wire and the token said once;
    • denied, expired, a second start that replaces the first, and cancel;
    • absent with no client ID.
  • Device client: TestDevice*: the loopback/https rule, the client ID run-time-over-build-time order, and every GitHub answer.
  • make test-touched BASE=origin/factory/general-intake: exit 0.
    • cmd/codeaf, 8 shards: TestFactoryRetryActionsDoNotReportStopped/try_again failed once and passed on rerun, so it is reported flaky. This change does not touch it.
    • appwire, factory/github and manual: ok.
  • make test-quick: ok.
  • test-tooling (pulled in by the Makefile edit): scripts/one-suite_test.sh hangs on this laptop because bwrap cannot map user namespaces here. My Makefile change only adds the -X stamp.
  • Live leg (-tags e2e, TestLiveBrowserSignInConnectsTheRealAccount, opt-in):
    • The real wire and the real device client run against a loopback stand-in for github.com/login's two endpoints. The stand-in grants a real token from a mode-600 file, which was deleted after the run.
    • The connect that follows then talks to real GitHub: @santoshkumarradha connected, 225 repos visible, 8 reads, 0 writes.
    • The token crossed the wire once and was written to no file.
  • Live against github.com itself: waits on the owner's OAuth client ID.

🤖 Generated with Claude Code

…e flow

factory.setup_github_{start,poll,cancel} run GitHub's OAuth device flow for
the factory on this machine. The granted token takes the pasted token's own
connect and is handed back once as github_token for the app's Keychain.
The OAuth client ID is stamped at build time (CODEAF_GITHUB_CLIENT_ID) or set
at run time; a build without one leaves the verb off the wire.
Opt-in (CODEAF_LIVE_GITHUB_SIGNIN=1, a mode-600 token file): the real wire and
device client against a loopback stand-in for github.com/login, then the real
GitHub for the connect. Asserts the account, zero writes, the token said once
on the wire and written to no file.
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 7, 2026 11:46
@santoshkumarradha
santoshkumarradha merged commit 7d4f0de into factory/general-intake Nov 7, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the factory/gh-signin branch November 7, 2026 11:46
santoshkumarradha added a commit that referenced this pull request Nov 7, 2026
…2501)

* config: list the GitHub sign-in's two variables as operator plumbing

TestRegistryCoversEveryUserFacingEnvironmentPin failed on factory/general-intake
since the browser sign-in landed (#2494): CODEAF_GITHUB_CLIENT_ID and
CODEAF_GITHUB_LOGIN_URL are read in internal/factory/github but were neither a
settings row nor on the operator allowlist. Both are build or test plumbing,
not preferences, so they join OperatorEnvPins.

* changes: entry for #2501
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