fix(app-iced, presenter): M114 r4 —— 登录面板 Close 不再是死按钮 + 面板态删掉原文字段(把「画原文」变成编译错)

复审 r2 P2-1:`Account::Close` 只在 `phase.busy()` 时派 `CancelDeviceLogin`,而
`Page::build` 只要非 Idle 就强制回 Microsoft ⇒ Failed/Succeeded 下 Close 点了没反应。
- 判据改成「两条轨任一非 Idle 就取消」;host 侧 `CancelDeviceLogin` 本来就把两条轨收成 Idle
- mock 补 `AppCommand::CancelDeviceLogin` 分支(按真 host 契约发 Idle),否则 mock 下不可验
- 新增 headless 回归闸:失败/成功/第三方轨三种态 → Close → `panel == None`
  (变异实证:判据退回 `busy()` ⇒ 该用例红,打印 left: Microsoft / right: None)

复审 r2 P2-2:`DevicePanel`/`AuthlibPanel` 删掉 `message`/`detail` 字段。
视图没有材料可画,「把后端原文画上屏」从测试问题变成**类型错误**;
`tests_text.rs` 的 docstring 改成真实边界(只覆盖模型 + i18n 查表,视图靠类型 + 出图)。

顺带(塔看图标出):alert 的 `Code: …` 与标题同排,省一整行高度,
避免 1180×760 把 All accounts 第三行挤到折线下;新增 `closed` 取证场景出「关掉之后」的对照图。
This commit is contained in:
AskaEth committed 2026-11-05 05:10:47 +08:00
1 parent bc71834bc3
commit f3e20b670e
9 files changed
+188 -81

No files matched your search

+106 -4
View File
@@ -14,7 +14,7 @@
//! `Task` 是惰性 stream,丢掉返回值等于永不执行(日志页的 Copy summary 就是正确写法)。
use iced::Task;
use unlucky_presenter::dto::{AccountKind, AppCommand, AuthlibRequest};
use unlucky_presenter::dto::{AccountKind, AppCommand, AuthlibRequest, DeviceLoginPhase};
use crate::app::Message;
use crate::pages::account::{Hint, Message as Account, Panel, Track};
@@ -43,8 +43,13 @@ impl App {
}
Account::Close => {
self.account_form.close();
// 关面板同时收掉登录任务(避免关掉面板后后台还在轮询、也不会凭空多一个账户)
if self.state.device_login.phase.busy() || self.state.authlib_login.phase.busy() {
// 关面板必须把**两条轨**的登录态都收回 Idle(复审 r2 P2-1:只看 `busy()` 时,
// `Failed`/`Succeeded` 不在 busy ⇒ 状态仍是非 Idle ⇒ `Page::build` 又把面板
// 强制回 Microsoft,按钮成了死按钮)。`CancelDeviceLogin` 在 host 侧本来就
// 同时收两条轨并发 Idle,所以判据用「非 Idle」而不是「busy」。
if self.state.device_login.phase != DeviceLoginPhase::Idle
|| self.state.authlib_login.phase != DeviceLoginPhase::Idle
{
self.dispatch(AppCommand::CancelDeviceLogin);
}
self.view_dirty = true;
@@ -188,6 +193,11 @@ pub(super) fn force_account_state(app: &mut App) {
app.account_form.login = "steve@example.com".to_string();
app.account_form.password = "not-a-real-password".to_string();
}
// 「关掉之后」:mock 给的是 failed 种子,这里按一次 Close(走真实的
// `on_account` → `CancelDeviceLogin` 通道),出「面板真的关了」的对照图。
"closed" => {
let _ = app.on_account(crate::pages::account::Message::Close);
}
// 有账号时「Add an account」展开态(P2-4 的收敛后形态)
"add" => {
app.account_form.section_open = true;
@@ -198,7 +208,99 @@ pub(super) fn force_account_state(app: &mut App) {
#[cfg(test)]
mod tests {
use crate::pages::account::{Form, Panel, Track};
use unlucky_design::color::SchemeFlavor;
use unlucky_presenter::dto::{
AppEvent, AuthlibLoginView, CoreEvent, DeviceLoginPhase, DeviceLoginView, LoginFailure,
};
use unlucky_presenter::mock::MockBackend;
use unlucky_presenter::settings_bridge::SettingsBridge;
use crate::pages::account::{Form, Message as Account, Panel, Track};
use crate::theme::Families;
use super::App;
/// 不碰磁盘的 App(mock 后端 + 内存设置桥),与 `app/tests.rs` 的 `headless` 同源。
fn headless() -> App {
App::with_presenter(
crate::cli::Options::default(),
Families {
text: "Segoe UI",
display: "Segoe UI",
mono: "Consolas",
},
SchemeFlavor::Light,
Box::new(MockBackend::new()),
SettingsBridge::memory_only(),
)
}
fn seed(app: &mut App, event: CoreEvent) {
app.state.apply(AppEvent::Core(event));
app.refresh_view();
}
/// **复审 r2 P2-1 的回归闸**:登录失败/成功态下按 `Close`,面板必须真的关掉。
///
/// 为什么这条以前是死按钮:`Page::build` 只要 `device_login.phase != Idle` 就把面板强制
/// 回 Microsoft,而 `Close` 只在 `busy()`(Requesting/Waiting)时才派 `CancelDeviceLogin`
/// ⇒ Failed/Succeeded 下点了没反应。现在判据改成「非 Idle」,两条轨都覆盖。
///
/// 抓得住:判据退回 `busy()`;`Close` 忘了 dispatch;`CancelDeviceLogin` 没有把状态收回 Idle。
/// 抓不住:`CancelDeviceLogin` 在**真 host** 上的副作用(这里跑的是 mock,但 mock 已按
/// 真 host 的契约发 Idle,见 `presenter/src/mock.rs`)。
#[test]
fn close_really_closes_the_login_panel_on_both_tracks() {
// ① 微软轨:失败态
let mut app = headless();
seed(
&mut app,
CoreEvent::DeviceLoginChanged(DeviceLoginView {
phase: DeviceLoginPhase::Failed,
message: "微软拒绝了这次登录:AADSTS7000218(HTTP 403)".to_string(),
failure: Some(LoginFailure::NotWhitelisted),
..DeviceLoginView::new()
}),
);
assert_eq!(app.account.panel, Panel::Microsoft, "失败态面板要显示");
let _ = app.on_account(Account::Close);
assert_eq!(app.account.panel, Panel::None, "Close 之后面板必须关掉");
assert_eq!(app.state.device_login.phase, DeviceLoginPhase::Idle);
// ② 微软轨:成功态(同样不在 busy 里)
let mut app = headless();
seed(
&mut app,
CoreEvent::DeviceLoginChanged(DeviceLoginView::succeeded("Steve")),
);
assert_eq!(app.account.panel, Panel::Microsoft);
let _ = app.on_account(Account::Close);
assert_eq!(app.account.panel, Panel::None, "成功提示也要能关掉");
// ③ 第三方轨:失败态
let mut app = headless();
seed(
&mut app,
CoreEvent::AuthlibLoginChanged(AuthlibLoginView {
phase: DeviceLoginPhase::Failed,
server: "https://example.invalid/api/yggdrasil/".to_string(),
server_name: String::new(),
message: "服务器返回 HTTP 404".to_string(),
failure: Some(LoginFailure::NotAuthlibServer),
account_name: String::new(),
}),
);
app.account_form.open(Track::Authlib);
app.refresh_view();
assert_eq!(
app.account.panel,
Panel::Authlib,
"第三方轨失败态面板要显示"
);
let _ = app.on_account(Account::Close);
assert_eq!(app.account.panel, Panel::None, "第三方轨也要能关掉");
assert_eq!(app.state.authlib_login.phase, DeviceLoginPhase::Idle);
}
/// 表单态是纯 UI 状态:打开/关闭面板不派命令,但会把面板切对。
///