fix(server,host): emit the opening auth state and forward session activation - #393
fix(server,host): emit the opening auth state and forward session activation#393filvecchiato wants to merge 7 commits into
Conversation
…ivation The core reports the outcome of the host's first session reconciliation even when it is the default Disconnected, and the worker runtime exposes activateStoredSession, activateExternalSession and resetSessionState.
…om:paritytech/truapi into fix/initial-auth-state-and-session-restore
…e-and-session-restore # Conflicts: # js/packages/truapi-host/src/worker-runtime.ts
| /// future resolves. | ||
| /// future resolves. Reports the resulting auth state to the host, including | ||
| /// when there was no session to restore. | ||
| pub(crate) async fn activate_stored_session(&self) -> Result<(), String> { |
There was a problem hiding this comment.
Both activation entry points announce now, which is right. reset_session_state, further down at
line 780, does not, and it is the third call the worker exposes through the same
sessionActivationResponse reply. Tested: with a session active, reset emits Disconnected because
the state really changed; with nothing active it emits nothing at all. That silent case is the
"already signed out" one, where a host that waits for an auth state before routing cannot tell the
answer from no answer, which is the problem this PR closes everywhere else. Adding the same one-line
self.auth_state.announce_current(); at the end of reset_session_state would make all three calls
report.
| * once product frames may use it, so a host can await this at boot before | ||
| * routing. Rejects when the runtime has been disposed or the worker faulted, | ||
| * so a host never routes on an activation that did not run. | ||
| */ |
There was a problem hiding this comment.
It would be nice to document these three methods in js/packages/truapi-host/README.md as well.
activateStoredSession, activateExternalSession and resetSessionState are the answer to "how
does a browser host restore a session across a reload", and the README's worker example currently
stops at createProvider, so a host author has to read these types to find them. A few lines
showing the boot order, create the runtime, await activateStoredSession(), then open providers,
would make the fix discoverable. CLAUDE.md asks for README updates after any code change. The same subsection could also cover disconnectSession and notifySessionStoreChanged, which are
undocumented there too.
Closes #389.
AuthStateMachine::transitionalso emits on the first attempt, so a signed-out boot reportsDisconnectedinstead of silence. Two tests that asserted the silence now assert the emission.WorkerPairingHostRuntimeexposesactivateStoredSession,activateExternalSessionandresetSessionState, sharing onesessionActivationResponsereply and pending map; in-flight calls reject on worker teardown.Verified:
cargo test --workspace --all-features,cargo +nightly fmt --check,npm run build/npm test --prefix js/packages/truapi-host(44 pass, 3 new).