Sheets native: Fable's review of ded0f68
1 (MED) The route alone decides the suspension: .onChange(of: route) calls SheetsOficinaSession.routeChanged(to:), which suspends straight in on the server route and resumes it on Oficina ID, so a route that flips by itself (the last server account signed out) no longer leaves Welcome with straight in suspended. 3 (LOW) "Use another Oficina ID" is offered only while signed in (SheetsOficinaSession.useAnother refuses otherwise, and the menu item is hidden), so it is never left asking over an outage with no dialog. 4 (LOW) As Docs does, the open-document guard is checked again when the question is asked, and an ask over an outage is cancelled. 5 (LOW) Kept Docs' behaviour (a failed switch to another team unmounts to the kit's "Can't reach Oficina ID"); the banner comment now says so. 6 (LOW) The fixtures fail rather than skip when the fake sign-in fails, so the launch suite can never be skipped silently. New tests: the route alone decides the suspension (and suspending while signed in changes nothing); sign-out and Use another refused with an open document, Use another refused over an outage; open documents block only their own identity. swift test passes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+133
−14
native/apple/Sources/SheetsApp/SheetsAccountWindow.swift+29 −12native/apple/Sources/SheetsKit/SheetsOficinaID.swift+32 −0native/apple/Tests/SheetsKitTests/OficinaIDAdoptionTests.swift+54 −1native/apple/Tests/SheetsWindowTests/SignedInLaunchTests.swift+5 −1native/apple/Tests/SheetsWindowTests/WindowRoutingTests.swift+13 −0
CI passed — run details
CI log
amadan: .amadan/timeout: this job's budget is 15m0s (this runner allows up to 30m0s) === vet === CGO_ENABLED=0 go vet ./... CGO_ENABLED=0 go vet -tags browser ./internal/sheets/ === fmt === === build === CGO_ENABLED=0 go build ./... === migrations === go tool rastrillo migration check rastrillo migration check: models and migrations agree === go-test === CGO_ENABLED=0 go test -count=1 ./... ? amadan.net/oficina/sheets/cmd/sheets [no test files] ? amadan.net/oficina/sheets/cmd/sheets-contract [no test files] ok amadan.net/oficina/sheets/internal/guardstest 0.169s ok amadan.net/oficina/sheets/internal/sheets 15.686s ok amadan.net/oficina/sheets/internal/sheets/calc 0.015s ok amadan.net/oficina/sheets/internal/sheets/format 0.003s ? amadan.net/oficina/sheets/internal/sheets/keymailtest [no test files] ok amadan.net/oficina/sheets/internal/sheets/live 0.055s ok amadan.net/oficina/sheets/internal/sheets/seal 0.003s ok amadan.net/oficina/sheets/internal/sheets/sealtest 0.003s ok amadan.net/oficina/sheets/internal/sheets/store 6.309s ok amadan.net/oficina/sheets/internal/sheets/teamstate 0.121s ok amadan.net/oficina/sheets/internal/sheets/xlsx 4.837s ? amadan.net/oficina/sheets/tools/gencorpus [no test files] === race === go test -race -count=1 ./internal/sheets/store/... ./internal/sheets/live/... ok amadan.net/oficina/sheets/internal/sheets/store 74.102s ok amadan.net/oficina/sheets/internal/sheets/live 1.066s
diff --git a/native/apple/Sources/SheetsApp/SheetsAccountWindow.swift b/native/apple/Sources/SheetsApp/SheetsAccountWindow.swift| index 7233ff3..cc3f17b 100644 |
| --- a/native/apple/Sources/SheetsApp/SheetsAccountWindow.swift |
| +++ b/native/apple/Sources/SheetsApp/SheetsAccountWindow.swift |
| @@ -56,10 +56,7 @@ struct SheetsAccountWindow: View { |
| case .server: |
| if let client = connection.client { serverWorkspace(client) } |
| else { |
| - SheetsOtherWaysView(connection: connection) { |
| - storedRoute = SheetsSignInRoute.oficinaID.rawValue |
| - Task { await model.resumeStraightIn() } |
| - } |
| + SheetsOtherWaysView(connection: connection) { storedRoute = SheetsSignInRoute.oficinaID.rawValue } |
| } |
| } |
| } |
| @@ -68,6 +65,18 @@ struct SheetsAccountWindow: View { |
| // A sign-in made here chooses Oficina ID for good (Appendix C); a launch |
| // going straight in leaves the route someone chose alone. |
| .onChange(of: oficina.signIns) { _, _ in storedRoute = SheetsSignInRoute.oficinaID.rawValue } |
| + // Straight in is suspended exactly while the app's own sign-in is the |
| + // route, however the route changes: chosen, or flipped by the last |
| + // server account signing out (rule 0). |
| + .onChange(of: route) { _, value in Task { await oficina.routeChanged(to: value) } } |
| + // "Use another" re-checks the document guard when it asks, as signing |
| + // out does, and is never left asking over an outage. |
| + .onChange(of: model.confirmingReplace) { _, confirming in |
| + guard confirming else { return } |
| + let signedIn: Bool |
| + if case .signedIn = model.step { signedIn = true } else { signedIn = false } |
| + if oficina.mounted != nil, !signedIn || openDocuments(of: model.identity?.id ?? "") { model.cancelReplace() } |
| + } |
| .onChange(of: scenePhase) { _, phase in |
| if phase == .active { Task { await oficina.renewIfNeeded() } } |
| } |
| @@ -113,14 +122,14 @@ struct SheetsAccountWindow: View { |
| }, updateRecents: { documents in |
| guard currentAccount == account else { return } |
| windows.updateRecents(documents, account: account, client: client) |
| - }, useAnother: { useAnother(state) }, accountsLabel: sheetsMacString("Teams"), |
| + }, useAnother: canUseAnother ? { useAnother(state) } : nil, accountsLabel: sheetsMacString("Teams"), |
| signOutLabel: OficinaIDText.text("signOut", state.identity.label)) |
| .id(account) |
| .safeAreaInset(edge: .bottom, spacing: 0) { passkeyNudge } |
| .sheet(isPresented: $pickingTeam) { teamPicker(state, canLeave: canLeave) } |
| #else |
| SheetsWorkspace(client: client, accounts: { pickingTeam = true }, signOut: { signOutOficinaID(state) }, |
| - useAnother: { useAnother(state) }, accountsLabel: sheetsMacString("Teams"), |
| + useAnother: canUseAnother ? { useAnother(state) } : nil, accountsLabel: sheetsMacString("Teams"), |
| signOutLabel: OficinaIDText.text("signOut", state.identity.label)) |
| .id(account) |
| .safeAreaInset(edge: .bottom, spacing: 0) { passkeyNudge } |
| @@ -132,8 +141,11 @@ struct SheetsAccountWindow: View { |
| if model.offerPasskey { OficinaPasskeyNudge(model: model).padding(12) } |
| } |
| - /// Over a mounted workspace: Oficina ID can't mint this team a session |
| - /// right now (§11), or a team switch failed. Nothing is unmounted. |
| + /// Over the mounted workspace: Oficina ID can't mint this team a new |
| + /// session right now (§11), so the open team stays, with Try again. A |
| + /// switch to another team that fails the same way unmounts this one and |
| + /// shows the kit's "Can't reach Oficina ID" (Try again, Other ways), as |
| + /// Docs does. |
| @ViewBuilder private var oficinaBanner: some View { |
| if case .unavailable = model.step { |
| HStack(spacing: 12) { |
| @@ -166,12 +178,18 @@ struct SheetsAccountWindow: View { |
| #endif |
| } |
| + /// "Use another Oficina ID" is offered only while signed in: over an |
| + /// outage there is no dialog to ask with. |
| + private var canUseAnother: Bool { |
| + if case .signedIn = model.step { return true } |
| + return false |
| + } |
| + |
| /// "Use another Oficina ID" from the account menu: slice A replaces the |
| /// identity, so the kit asks first (`oficinaReplaceConfirmation` above), |
| /// and the same guard as signing out applies. |
| private func useAnother(_ state: OficinaSignedIn) { |
| - guard model.identity?.id == state.identity.id, !openDocuments(of: state.identity.id) else { return } |
| - model.useAnother() |
| + oficina.useAnother(identity: state.identity.id, canLeave: !openDocuments(of: state.identity.id)) |
| } |
| /// "Sign out of <label>": every team of the identity, on every Oficina app |
| @@ -179,11 +197,10 @@ struct SheetsAccountWindow: View { |
| /// is open (the menu disables it then too). |
| private func signOutOficinaID(_ state: OficinaSignedIn) { |
| let identity = state.identity.id |
| - guard model.identity?.id == identity, !openDocuments(of: identity) else { return } |
| + guard oficina.signOut(identity: identity, canLeave: !openDocuments(of: identity)) else { return } |
| #if os(macOS) |
| windows.entries.removeAll { SheetsOficinaSession.account($0.account, belongsTo: identity) } |
| #endif |
| - model.signOut() |
| } |
| // MARK: Other ways (server address) |
diff --git a/native/apple/Sources/SheetsKit/SheetsOficinaID.swift b/native/apple/Sources/SheetsKit/SheetsOficinaID.swift| index 5e93d86..fffa972 100644 |
| --- a/native/apple/Sources/SheetsKit/SheetsOficinaID.swift |
| +++ b/native/apple/Sources/SheetsKit/SheetsOficinaID.swift |
| @@ -92,6 +92,38 @@ public enum SheetsSignInRoute: String, Sendable { |
| await model.refreshTeams() |
| } |
| + /// The route changed, by the person or by itself (the last server account |
| + /// signed out, say): straight in is suspended exactly while the app's |
| + /// own sign-in is the route, and resumes when it stops being (spec §9, |
| + /// rule 0). Without this a route that flips on its own would leave |
| + /// Welcome with straight in still suspended (Fable, sheets ded0f68). |
| + public func routeChanged(to route: SheetsSignInRoute) async { |
| + switch route { |
| + case .server: model.suspendStraightIn() |
| + case .oficinaID: await model.resumeStraightIn() |
| + } |
| + } |
| + |
| + /// "Use another Oficina ID" from the account menu: only while signed in |
| + /// (over an outage there is no dialog to ask with), and only when |
| + /// `canLeave` (no document window of the identity open). Returns whether |
| + /// it asked. |
| + @discardableResult |
| + public func useAnother(identity: String, canLeave: Bool) -> Bool { |
| + guard case .signedIn(let state) = model.step, state.identity.id == identity, canLeave else { return false } |
| + model.useAnother() |
| + return true |
| + } |
| + |
| + /// "Sign out of <label>", refused while a document window of the |
| + /// identity is open. Returns whether it signed out. |
| + @discardableResult |
| + public func signOut(identity: String, canLeave: Bool) -> Bool { |
| + guard model.identity?.id == identity, canLeave else { return false } |
| + model.signOut() |
| + return true |
| + } |
| + |
| /// The team picker opened: refresh if the list is five minutes old. |
| public func pickerOpened() async { await model.refreshTeams() } |
diff --git a/native/apple/Tests/SheetsKitTests/OficinaIDAdoptionTests.swift b/native/apple/Tests/SheetsKitTests/OficinaIDAdoptionTests.swift| index 9718567..9dc56d5 100644 |
| --- a/native/apple/Tests/SheetsKitTests/OficinaIDAdoptionTests.swift |
| +++ b/native/apple/Tests/SheetsKitTests/OficinaIDAdoptionTests.swift |
| @@ -62,7 +62,12 @@ import XCTest |
| await docs.submitEmail() |
| docs.code = FakeOficinaIDService.goodCode |
| await docs.submitCode() |
| - guard case .signedIn = docs.step else { throw XCTSkip("Docs did not sign in: \(docs.step)") } |
| + // A fixture that cannot sign in fails the test: skipping would hide the |
| + // launch suite behind it. |
| + guard case .signedIn = docs.step else { |
| + XCTFail("Docs did not sign in: \(docs.step)") |
| + throw CancellationError() |
| + } |
| return paulca |
| } |
| @@ -99,6 +104,54 @@ import XCTest |
| XCTAssertEqual(sheets.mounted?.origin, Self.sheetsOrigin) |
| } |
| + /// The route flipping to Oficina ID on its own (the last server account |
| + /// signed out) resumes straight in; flipping back to the app's own |
| + /// sign-in while signed in disturbs nothing (Fable, sheets ded0f68). |
| + func testTheRouteAloneDecidesTheSuspension() async throws { |
| + try await savedIdentity() |
| + let sheets = SheetsOficinaSession(model: model("sheets", "Sheets")) |
| + await sheets.start(serverRoute: true) |
| + XCTAssertTrue(sheets.model.straightInSuspended) |
| + XCTAssertNil(sheets.mounted) |
| + await sheets.routeChanged(to: .oficinaID) |
| + XCTAssertFalse(sheets.model.straightInSuspended) |
| + let mounted = try XCTUnwrap(sheets.mounted, "straight in once the route is Oficina ID") |
| + await sheets.routeChanged(to: .server) |
| + XCTAssertTrue(sheets.model.straightInSuspended) |
| + XCTAssertEqual(sheets.mounted, mounted, "signed in, suspending changes nothing") |
| + } |
| + |
| + /// Sign-out and "Use another" are refused while a document window of the |
| + /// identity is open, and "Use another" while the team is unreachable. |
| + func testLeavingIsRefusedWithAnOpenDocumentOrOverAnOutage() async throws { |
| + let paulca = try await savedIdentity() |
| + let sheets = SheetsOficinaSession(model: model("sheets", "Sheets")) |
| + await sheets.start() |
| + let state = try XCTUnwrap(sheets.mounted) |
| + XCTAssertFalse(sheets.useAnother(identity: state.identity.id, canLeave: false)) |
| + XCTAssertFalse(sheets.model.confirmingReplace) |
| + XCTAssertFalse(sheets.signOut(identity: state.identity.id, canLeave: false)) |
| + XCTAssertEqual(sheets.mounted, state) |
| + XCTAssertEqual(try sheets.model.store.identities().map(\.id), ["id-1"]) |
| + |
| + // Over an outage the team stays mounted, but there is no dialog to ask |
| + // "Use another" with. |
| + service.expire(session: state.session) |
| + service.failNext("exchange", at: Self.sheetsOrigin.absoluteString, with: .offline) |
| + await sheets.rejected(SheetsOficinaSession.accountID(state)) |
| + XCTAssertEqual(sheets.model.step, .unavailable(paulca)) |
| + XCTAssertNotNil(sheets.mounted) |
| + XCTAssertFalse(sheets.useAnother(identity: state.identity.id, canLeave: true)) |
| + XCTAssertFalse(sheets.model.confirmingReplace) |
| + |
| + await sheets.model.retry() |
| + XCTAssertTrue(sheets.useAnother(identity: state.identity.id, canLeave: true)) |
| + XCTAssertTrue(sheets.model.confirmingReplace) |
| + sheets.model.cancelReplace() |
| + XCTAssertTrue(sheets.signOut(identity: state.identity.id, canLeave: true)) |
| + XCTAssertNil(sheets.mounted) |
| + } |
| + |
| // MARK: Transport |
| /// The workspace's transport reads the latest session: a 401 re-mints |
diff --git a/native/apple/Tests/SheetsWindowTests/SignedInLaunchTests.swift b/native/apple/Tests/SheetsWindowTests/SignedInLaunchTests.swift| index f8d58ec..521b5de 100644 |
| --- a/native/apple/Tests/SheetsWindowTests/SignedInLaunchTests.swift |
| +++ b/native/apple/Tests/SheetsWindowTests/SignedInLaunchTests.swift |
| @@ -49,7 +49,11 @@ import SheetsKit |
| await docs.submitCode() |
| let sheets = SheetsOficinaSession(model: model("sheets", "Sheets")) |
| await sheets.start() |
| - guard sheets.mounted != nil else { throw XCTSkip("Sheets did not go straight in: \(sheets.model.step)") } |
| + // Failing, not skipping: a skip here would hide the whole launch suite. |
| + guard sheets.mounted != nil else { |
| + XCTFail("Sheets did not go straight in: \(sheets.model.step)") |
| + throw CancellationError() |
| + } |
| return sheets |
| } |
diff --git a/native/apple/Tests/SheetsWindowTests/WindowRoutingTests.swift b/native/apple/Tests/SheetsWindowTests/WindowRoutingTests.swift| index 648936e..3f5b1f7 100644 |
| --- a/native/apple/Tests/SheetsWindowTests/WindowRoutingTests.swift |
| +++ b/native/apple/Tests/SheetsWindowTests/WindowRoutingTests.swift |
| @@ -24,4 +24,17 @@ import RastrilloApple |
| #expect(windows.entries.first(where: { $0.id == id })?.title == "Current title") |
| #expect(windows.entries.first(where: { $0.id == id })?.isOpen == false) |
| } |
| + |
| +/// Signing out of an Oficina ID ends all its teams, so any of its teams' |
| +/// open document windows blocks it; another identity's never does. |
| +@MainActor @Test func openDocumentsBlockLeavingTheirIdentityOnly() { |
| + let windows = SheetsWindows() |
| + let client = NativeHTTP(origin: URL(string: "https://team.invalid")!) |
| + let account = "oficina-id.id-1.t2" |
| + let id = windows.reserve(account: account, document: 1, title: "Plan", client: client) |
| + #expect(windows.hasOpenDocuments(identity: "id-1")) |
| + #expect(!windows.hasOpenDocuments(identity: "id-10")) |
| + windows.setOpen(id, false) |
| + #expect(!windows.hasOpenDocuments(identity: "id-1")) |
| +} |
| #endif |