Files
Ydisks-Xianyu-Helper/internal/server/platform_runtime_boundary_test.go
T
Christ 375e84d663 重构:统一应用服务与基础设施适配边界
将账号、认证、管理员、分析、自动化、卡券、聊天、商品、关键词、设置和订单能力迁移到 application 与 adapter,删除 Server 内对应的旧仓储和业务服务实现,并收紧架构检查。

完善批量发布与订单刷新生命周期、凭证写回、账号任务补偿、订单 reconciliation、通知和敏感数据边界;补充正常、失败、取消、并发、越权及多方言回归测试,并修正 MySQL 延迟任务表的 InnoDB 配置。

修复空卡密响应为 null 时前端加载失败的问题,重建嵌入式前端资产;重写重构总计划,清除历史流水并明确阶段 1 至 10 各对应一次完整迭代和一个 PR。

验证:make check;make test-server-race;npm test/typecheck/comments:check/build;Docker SQLite/MySQL 8.4/PostgreSQL 17 TestMultiDB_*。
2026-08-16 23:51:06 +08:00

37 lines
1.9 KiB
Go

package server
import (
"context"
"testing"
"xianyu-go/internal/adapter"
accountapp "xianyu-go/internal/application/account"
)
// TestLoadCookiePlatformDetailRequiresCredentialPort 验证平台运行时读取不会在缺少应用 Port 时直接访问 Store。
func TestLoadCookiePlatformDetailRequiresCredentialPort(t *testing.T) {
// srv 是仅装配空账号登录服务的测试 Server,模拟凭证适配器缺失场景。
srv := &Server{applications: &applicationServices{accountLogin: &accountLoginService{}}}
// loadErr 保存缺少凭证 Port 时的平台视图读取错误。
_, loadErr := srv.loadCookiePlatformDetail(context.Background(), "cid")
if loadErr == nil {
t.Fatal("缺少凭证 Port 时不应继续读取平台运行视图")
}
}
// TestPersistMTopCookieSessionRequiresCredentialPort 验证 MTOP Cookie 会话写回通过凭证 Port 而非直接访问 Store。
func TestPersistMTopCookieSessionRequiresCredentialPort(t *testing.T) {
// srv 是仅装配空账号登录服务的测试 Server,模拟写回适配器缺失场景。
srv := &Server{applications: &applicationServices{accountLogin: &accountLoginService{}}}
// detail 是不含登录密码的兼容平台凭证模型。
detail := &accountapp.CredentialDetail{ID: "cid", Value: "sid=old", MetadataJSON: "{}"}
// ctx、session 保存发生权威 Cookie 变化的 MTOP 会话。
ctx, session := adapter.WithFlatCookieSession(context.Background(), detail.Value)
session.ReplaceSnapshot([]adapter.BrowserCookie{{Name: "sid", Value: "new", Domain: ".goofish.com", Path: "/"}})
// value、changed、handled、persistErr 保存会话写回结果及其错误阶段。
_, changed, handled, persistErr := srv.persistMTopCookieSessionLocked(ctx, detail, session)
if !changed || !handled || persistErr == nil {
t.Fatalf("缺少凭证 Port 时应报告写回错误: changed=%v handled=%v err=%v", changed, handled, persistErr)
}
}