重构:统一应用服务与基础设施适配边界
将账号、认证、管理员、分析、自动化、卡券、聊天、商品、关键词、设置和订单能力迁移到 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_*。
This commit is contained in:
1 parent
19a7d5f924
commit
375e84d663
239 files changed
+23870
-7871
No files matched your search
@@ -210,6 +210,14 @@ func (s *ChannelService) DeleteChannel(ctx context.Context, userID, channelID in
|
||||
return s.repository.DeleteChannel(ctx, channelID, userID)
|
||||
}
|
||||
|
||||
// OwnsChannel 查询渠道是否属于指定用户;只返回归属结论,不读取渠道配置。
|
||||
func (s *ChannelService) OwnsChannel(ctx context.Context, userID, channelID int64) (bool, error) {
|
||||
if s == nil || s.repository == nil || userID <= 0 || channelID <= 0 {
|
||||
return false, ErrChannelInvalidInput
|
||||
}
|
||||
return s.repository.OwnsChannel(ctx, channelID, userID)
|
||||
}
|
||||
|
||||
// TestChannel 校验渠道归属并发送固定格式测试通知;body 不包含渠道配置或凭证。
|
||||
func (s *ChannelService) TestChannel(ctx context.Context, userID, channelID int64, now time.Time) error {
|
||||
if s == nil || s.repository == nil || userID <= 0 || channelID <= 0 {
|
||||
|
||||
@@ -167,6 +167,43 @@ func TestChannelServiceRejectsOwnershipAndStorageFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestChannelServiceOwnsChannelKeepsRepositoryBoundary 验证渠道归属查询只透传非敏感结论和存储错误。
|
||||
func TestChannelServiceOwnsChannelKeepsRepositoryBoundary(t *testing.T) {
|
||||
// cases 描述成功、越权、存储失败和非法输入四类归属结果。
|
||||
cases := []struct {
|
||||
name string
|
||||
repository *channelRepositoryStub
|
||||
userID int64
|
||||
channelID int64
|
||||
want bool
|
||||
wantErr error
|
||||
}{
|
||||
{name: "owned", repository: &channelRepositoryStub{ownedChannel: true}, userID: 7, channelID: 1, want: true},
|
||||
{name: "not owned", repository: &channelRepositoryStub{ownedChannel: false}, userID: 7, channelID: 1},
|
||||
{name: "storage error", repository: &channelRepositoryStub{err: errors.New("storage failed")}, userID: 7, channelID: 1, wantErr: errors.New("storage failed")},
|
||||
{name: "invalid user", repository: &channelRepositoryStub{ownedChannel: true}, userID: 0, channelID: 1, wantErr: ErrChannelInvalidInput},
|
||||
}
|
||||
// testCase 表示当前验证的渠道归属边界场景。
|
||||
for _, testCase := range cases {
|
||||
// service 是使用当前场景持久化替身的通知渠道服务。
|
||||
service := NewChannelService(testCase.repository, nil)
|
||||
// exists、ownershipErr 保存应用层归属结果。
|
||||
exists, ownershipErr := service.OwnsChannel(context.Background(), testCase.userID, testCase.channelID)
|
||||
if exists != testCase.want {
|
||||
t.Fatalf("%s: 归属结果=%v,期望=%v", testCase.name, exists, testCase.want)
|
||||
}
|
||||
if testCase.wantErr != nil {
|
||||
if ownershipErr == nil || ownershipErr.Error() != testCase.wantErr.Error() {
|
||||
t.Fatalf("%s: 错误=%v,期望=%v", testCase.name, ownershipErr, testCase.wantErr)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ownershipErr != nil {
|
||||
t.Fatalf("%s: 意外错误=%v", testCase.name, ownershipErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestChannelServiceTestSendUsesSafeBody 验证测试发送只生成固定正文,不携带渠道配置。
|
||||
func TestChannelServiceTestSendUsesSafeBody(t *testing.T) {
|
||||
// repository 是允许渠道归属且不返回敏感配置的端口替身。
|
||||
|
||||
Reference in new issue
Block a user