feat: 同步失败台账双向可重试 + 拧紧枪按工位配置 + 虚拟工位体系 + 去Redis与文档口径对齐
- 同步失败台账:MES/WMS 双端新增台账与页面,跨系统通知失败落台账、人工重试或标记已处理,不自动重传;重试前先判对端终态;叫料、配送、出库回写失败提示指向台账;补幂等建表脚本与菜单权限。 - 拧紧枪:新增按工位配置页,展示控制器地址与三把枪通道号(仅供查看,不参与采集校验);「允许手填」由全局开关改为每工位开关,关闭时校验该工位已配控制器;终端启动/登录上报配置并按本工位拉取,扭矩手填框按本工位置灰;补全局值迁移到各工位的脚本。 - 工位体系:终端未配置工位号时登录页可选(含虚拟工位),固定工位模式保留;虚拟/线下位不叫料、不退料、不作转产目标,未采集绑定放行并说明原因;叫料期望接驳台改为选填。 - AGV与出库:补「出库单已送达」回写;空车回充、接驳台传感器失联、配送状态更新失败均落预警或留痕并提示人工核对;人工出库不引入送达状态;出库单支持目标工位/接驳台并扩展导出列。 - 基础设施:看板缓存由Redis改为MES进程内实现,文档与启动脚本同步去Redis;扫码监听支持多地址、端口被占自动降级;PLC对账与工位报警在MES不可达时降级放行并留日志。 - 文档与帮助:案例与部署手册按实测订正(工位绑定、菜单名称、补料由班组长代提、菜单覆盖对照、虚拟工位);迁移脚本改为本地即时执行并登记7个已执行脚本;三端页面帮助改为「业务/操作/影响范围/后果」四要素。 - 测试:新增独立Go模块,按三个业务场景做真实HTTP与真实写库的流水测试,含运行报告。
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
// Package assert 四层断言 + 每步六字段报告。
|
||||
package assert
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"bj_power_test/internal/client"
|
||||
"bj_power_test/internal/db"
|
||||
"bj_power_test/internal/fixture"
|
||||
)
|
||||
|
||||
// Layer 断言分层。
|
||||
type Layer string
|
||||
|
||||
const (
|
||||
L1 Layer = "L1 接口响应"
|
||||
L2 Layer = "L2 数据库落库"
|
||||
L3 Layer = "L3 状态流转"
|
||||
L4 Layer = "L4 交付物"
|
||||
)
|
||||
|
||||
// Result 每步报告:步骤ID + 案例.md行号 + 期望 + 实际 + 通过/失败 + 失败原因。
|
||||
type Result struct {
|
||||
StepID string `json:"stepId"`
|
||||
CaseLine string `json:"caseLine"`
|
||||
Layer Layer `json:"layer"`
|
||||
Expect string `json:"expect"`
|
||||
Actual string `json:"actual"`
|
||||
Pass bool `json:"pass"`
|
||||
FailReason string `json:"failReason"`
|
||||
Status string `json:"status"` // 通过 / 失败 / 阻断
|
||||
}
|
||||
|
||||
// Ctx 用例执行上下文。
|
||||
type Ctx struct {
|
||||
C context.Context
|
||||
Run *fixture.Run
|
||||
Client *client.Set
|
||||
DB *db.DB
|
||||
Results []Result
|
||||
Blocked bool
|
||||
}
|
||||
|
||||
func NewCtx(c context.Context, run *fixture.Run, cl *client.Set, d *db.DB) *Ctx {
|
||||
return &Ctx{C: c, Run: run, Client: cl, DB: d}
|
||||
}
|
||||
|
||||
func (c *Ctx) add(r Result) {
|
||||
if r.Status == "" {
|
||||
if r.Pass {
|
||||
r.Status = "通过"
|
||||
} else {
|
||||
r.Status = "失败"
|
||||
}
|
||||
}
|
||||
c.Results = append(c.Results, r)
|
||||
}
|
||||
|
||||
// Block 标记阻断:服务/库不可用时不编造数据,明确写「阻断」。
|
||||
func (c *Ctx) Block(stepID, caseLine, expect, reason string) {
|
||||
c.Blocked = true
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L1, Expect: expect,
|
||||
Actual: "未执行(前置条件不满足)", FailReason: reason, Status: "阻断"})
|
||||
}
|
||||
|
||||
// L1 接口响应:HTTP 状态码、业务码、提示文案(三者都判)。
|
||||
func (c *Ctx) L1(stepID, caseLine, expect string, resp *client.Response, callErr error, wantHTTP, wantCode int, wantMsg string) {
|
||||
if callErr != nil {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L1, Expect: expect,
|
||||
Actual: "调用异常:" + callErr.Error(), FailReason: "HTTP 请求未送达(服务未启动或网络不通)", Status: "阻断"})
|
||||
c.Blocked = true
|
||||
return
|
||||
}
|
||||
var reasons []string
|
||||
if resp.HTTPStatus != wantHTTP {
|
||||
reasons = append(reasons, fmt.Sprintf("HTTP 状态码期望 %d 实际 %d", wantHTTP, resp.HTTPStatus))
|
||||
}
|
||||
if resp.Code != wantCode {
|
||||
reasons = append(reasons, fmt.Sprintf("业务码期望 %d 实际 %d", wantCode, resp.Code))
|
||||
}
|
||||
if wantMsg != "" && !strings.Contains(resp.Message+resp.Raw, wantMsg) {
|
||||
reasons = append(reasons, fmt.Sprintf("提示文案未包含 %q", wantMsg))
|
||||
}
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L1, Expect: expect,
|
||||
Actual: resp.Brief(), Pass: len(reasons) == 0, FailReason: strings.Join(reasons, ";")})
|
||||
}
|
||||
|
||||
// L2 数据库落库:直连库执行 SQL,比对期望值。
|
||||
func (c *Ctx) L2(stepID, caseLine, expect string, target db.Target, query string, args []any, want string) {
|
||||
if !c.DB.Ready(target) {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L2, Expect: expect,
|
||||
Actual: "库未连接", FailReason: string(target) + " 库不可用", Status: "阻断"})
|
||||
return
|
||||
}
|
||||
got, err := c.DB.Scalar(c.C, target, query, args...)
|
||||
actual := fmt.Sprintf("%s = %q", query, got)
|
||||
if err != nil {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L2, Expect: expect,
|
||||
Actual: "SQL 执行失败:" + err.Error(), FailReason: err.Error()})
|
||||
return
|
||||
}
|
||||
pass := got == want
|
||||
reason := ""
|
||||
if !pass {
|
||||
reason = fmt.Sprintf("期望 %q,实际 %q", want, got)
|
||||
}
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L2, Expect: expect, Actual: actual,
|
||||
Pass: pass, FailReason: reason})
|
||||
}
|
||||
|
||||
// L3 状态流转:查单据当前状态是否与状态机期望一致。
|
||||
func (c *Ctx) L3(stepID, caseLine, expect string, target db.Target, query string, args []any, allow []string) {
|
||||
if !c.DB.Ready(target) {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L3, Expect: expect,
|
||||
Actual: "库未连接", FailReason: string(target) + " 库不可用", Status: "阻断"})
|
||||
return
|
||||
}
|
||||
got, err := c.DB.Scalar(c.C, target, query, args...)
|
||||
if err != nil {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L3, Expect: expect,
|
||||
Actual: "SQL 执行失败:" + err.Error(), FailReason: err.Error()})
|
||||
return
|
||||
}
|
||||
pass := false
|
||||
for _, a := range allow {
|
||||
if got == a {
|
||||
pass = true
|
||||
break
|
||||
}
|
||||
}
|
||||
reason := ""
|
||||
if !pass {
|
||||
reason = fmt.Sprintf("状态期望属于 %v,实际 %q", allow, got)
|
||||
}
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L3, Expect: expect,
|
||||
Actual: fmt.Sprintf("当前状态 = %q", got), Pass: pass, FailReason: reason})
|
||||
}
|
||||
|
||||
// L4 交付物:接口返回或聚合查询是否产出交付物数据。
|
||||
func (c *Ctx) L4(stepID, caseLine, expect, actual string, pass bool, reason string) {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L4, Expect: expect,
|
||||
Actual: actual, Pass: pass, FailReason: reason})
|
||||
}
|
||||
|
||||
// Note 记录一条不带断言的事实(例如前一步真实单号),便于报告串起流水。
|
||||
func (c *Ctx) Note(stepID, caseLine, fact string) {
|
||||
c.add(Result{StepID: stepID, CaseLine: caseLine, Layer: L1, Expect: "记录本步真实产出供下一步使用",
|
||||
Actual: fact, Pass: true, Status: "通过"})
|
||||
}
|
||||
Reference in New Issue
Block a user