| 1 | package cage |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | func TestSafetyRejectionExplainsFailedCheck(t *testing.T) { |
| 10 | report := SafetyReport{Policy: SafetyPolicyVersion, ID: "test", RunID: "run", CheckID: "check", Configuration: "config", CreatedAt: time.Now()} |
| 11 | for _, id := range requiredSafetyChecks { |
| 12 | report.Checks = append(report.Checks, SafetyCheck{ID: id, Critical: true, State: CheckPassed, Evidence: "verified", CheckedAt: report.CreatedAt}) |
| 13 | } |
| 14 | report.Checks[4].State = CheckFailed |
| 15 | report.Checks[4].Title = "浏览器时区与语言" |
| 16 | report.Checks[4].Evidence = "浏览器语言与设置不一致" |
| 17 | report.Checks[4].Remedy = "更新环境组件,再重新检测" |
| 18 | err := report.Authorizes(report.RunID, report.Configuration, time.Now()) |
| 19 | for _, part := range []string{"浏览器时区与语言", "浏览器语言与设置不一致", "更新环境组件", "外网保持关闭"} { |
| 20 | if err == nil || !strings.Contains(err.Error(), part) { |
| 21 | t.Fatalf("missing actionable failure %q: %v", part, err) |
| 22 | } |
| 23 | } |
| 24 | report.Checks[4].State = CheckUnknown |
| 25 | report.Checks[4].Evidence = "未能读取浏览器设置" |
| 26 | err = report.Authorizes(report.RunID, report.Configuration, time.Now()) |
| 27 | if err == nil || !strings.Contains(err.Error(), "未能确认") { |
| 28 | t.Fatalf("unknown was presented as a confirmed mismatch: %v", err) |
| 29 | } |
| 30 | } |