Task 8: fluxer-core store skeleton and session domain (#8) #39
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "task/8-core-store-session"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What this builds
The
fluxer-corestore skeleton and the session domain (Foundation plan Task 8, spec §4).App/CoreConfig/App::apply(CoreEvent) -> Vec<Effect>; the other domains (Guilds,Channels,Messages,PresenceState,ReadStates,UiState) are empty structs until Tasks 9-11.CoreEvent,ApiResult,UserAction,SettingsTab,PersistResult,GatewayState(event.rs);Effect,ApiRequest,PersistOp,Notification(effect.rs);EffectId,TimerId(ids.rs);CoreError,AuthError(error.rs).Session/Authreducer:SubmitLogin->Discover(skipped once endpoints are known) ->Login->Persist(SaveToken)+ConnectGateway; MFA ->AwaitingTotp->LoginTotp; a 401 on any call while logged in, orGatewayState::AuthFailed, ->LoggedOut { SessionExpired }+DisconnectGateway+Persist(ClearToken);Logout;READY/USER_UPDATE/USER_SETTINGS_UPDATE/Merefresh the user and settings.UserAction::OpenUrlemitsEffect::OpenUrlforhttp/httpslinks only.How it was tested
crates/fluxer-core/tests/session.rs(16 tests, written first and committed failing): the five the plan names plus second-login-skips-discovery,SetInstance, wrong TOTP code, failure-to-AuthErrormapping, discovery failure, unusable gateway URL from the instance, gatewayAuthFailed, non-401 failures while logged in, logout,READYreplacing the user, stale login answer after cancel. Two unit tests for theOpenUrlscheme filter.cargo xtask ciis green locally (Linux).Deviations from the plan
CoreErrorinstead ofApiError. The plan mapsAuthError"fromApiError", butfluxer-coremay not depend onfluxer-api(reqwest).CoreErrormirrorsfluxer_api::ApiErrorvariant for variant (Transport->Network(String),Decode(String), plusOther(String)); the runtime (Task 14) converts. The same applies toGatewayState, redefined here with the variants offluxer_gateway::GatewayState.ApiResult::Sent { message: Box<Message> }andApiResult::Edited(Box<Message>)are boxed (clippylarge_enum_variant), as the mergedGatewayEventvariants are.Auth::LoggedInkeeps the plan's unboxed fields with an#[expect]and a reason.PersistOphas onlySaveToken/ClearToken,PersistResultonlyOk,Notificationis a minimal struct,EditMessage/DeleteMessagefields are my reading of the plan's{..}- Tasks 10, 12 and 23 extend them.Sessioncarriesinstance,endpoints,gateway,user_settings,totp_errorandrequest_in_flight(); right after loginAuth::LoggedIn.useris built from the login answer's partial user (no e-mail) untilREADYreplaces it; wrong credentials are recognised as 401 or HTTP 400 on the login calls.ApiResult), so they are matched by state; an answer arriving after the user cancelled is dropped.READYtest parsed the fixture as a bare payload; the fixture is a full frame, so the implementation commit fixes the test to read itsd.Closes #8
🤖 Generated with Claude Code
Independent review — Task 8 (core store skeleton + session), head
cacedcbReviewed
git diff 2750bbb..origin/task/8-core-store-sessioncold (11 files, onlycrates/fluxer-core+Cargo.lock).1. Tests named by the plan — all five exist in
crates/fluxer-core/tests/session.rsand assert what the plan says:login_happy_path_emits_discover_login_persist_connect:Api Discover→Api Login→[Persist(SaveToken), ConnectGateway], fixture token,wss://fluxer.forked.io/gateway, endsLoggedIn.login_mfa_moves_to_awaiting_totp_then_connects:AwaitingTotp { ticket }with the fixture ticket,LoginTotp { ticket, code }, then save + connect.captcha_error_shows_message_and_stays_logged_out:LoggedOut { error: Some(CaptchaRequired) }, no effects.unauthorized_while_logged_in_logs_out_and_disconnects:[DisconnectGateway, Persist(ClearToken)]+SessionExpired;GatewayState::AuthFailedhas its own test with the same assertions.effects_get_unique_ids: 5 Api effects, 5 distinct ids.2. Interfaces —
App(fields, privatenext_effect_id),App::new(CoreConfig),apply,CoreEvent,Effect,AuthError,ApiRequest,ApiResult,UserAction(all 20 variants),Authmatch the plan. Deviations, none blocking:ApiResult::Sent.messageandApiResult::EditedareBox<Message>(clippylarge_enum_variant); Task 10 builds against merged code.GatewayStateandCoreErrorare defined influxer-core, because the crate cannot depend onfluxer-gateway/fluxer-api. Variants equal the Task 7 list. Task 14 has to convert both; the README says so.PersistOp/PersistResult/Notificationare the subset this task needs; Tasks 12 and 23 extend them as the plan already states.3. Invariants —
fluxer-coredeps:fluxer-proto,secrecy,thiserror,tracing,url(all existing workspace deps); no banned crates, no I/O, nounwrap/expect/panic!/indexing outside tests. An unparsable or non-ws gateway URL from discovery ends inAuthError::Other, tested. Tokens and passwords areSecretString; the only token literal is the scrubbed fixture value. Commits carryRefs #8and the co-author line; README updated.4. Review Focus — none of the five items is assigned to Task 8 (captcha is Tasks 6/17); the core half of it is covered by the captcha test above.
5.
cargo xtask ciin the review worktree: green (fmt, clippy, deny, tests; 16 session tests + 2 unit tests pass; screenshot step skipped becauseFLUXER_SCREENSHOT_TESTSis not 1). Remote runners not checked.Findings
crates/fluxer-core/src/session.rs(on_failed,on_api): answers and 401s are not tied to a login attempt or session.EffectFailed { Unauthorized }whose id is not the in-flight one expires the current session. A late 401 from a request sent with the previous session's token (after Logout + quick re-login), or from a cancelled login attempt, logs the new session out and clears its token.SetInstancein between, the old instance's discovery document is stored for the new instance.ApiResult(an interface change, so a follow-up issue rather than this PR).crates/fluxer-core/src/error.rs(from_login_failure): every 400 on Login/LoginTotp becomesInvalidCredentials, including validation errors that are not about credentials (e.g. a malformed e-mail).CoreError::Http.codeis available to narrow it.crates/fluxer-core/src/effect.rs,session.rs: the MFAticketand TOTPcodeare plainStrings in types that deriveDebug(ApiRequest::LoginTotp,Auth::AwaitingTotp); nothing logs them today, but a runtime that debug-logs effects would. Short-lived values, the plan leaves the types open.Verdict: APPROVE — 0 blocking, 3 minor; local ci green.