devrites 5.12.0 → 5.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +5 -3
  3. package/docs/architecture.md +2 -2
  4. package/docs/command-map.md +3 -1
  5. package/docs/engine/commands.md +21 -0
  6. package/docs/flow.md +2 -1
  7. package/docs/skills.md +13 -4
  8. package/engine/help.go +4 -1
  9. package/engine/help_test.go +2 -0
  10. package/engine/internal/overhaul/admit/admit_test.go +170 -0
  11. package/engine/internal/overhaul/admit/run.go +416 -0
  12. package/engine/internal/overhaul/bench/run.go +248 -0
  13. package/engine/internal/overhaul/bench/run_test.go +139 -0
  14. package/engine/internal/overhaul/overhaul.go +64 -0
  15. package/engine/internal/overhaul/ovio/ovio.go +158 -0
  16. package/engine/internal/overhaul/records/check.go +834 -0
  17. package/engine/internal/overhaul/records/records_test.go +577 -0
  18. package/engine/internal/overhaul/records/run.go +392 -0
  19. package/engine/internal/overhaul/render/run.go +776 -0
  20. package/engine/internal/overhaul/render/run_test.go +293 -0
  21. package/engine/internal/overhaul/score/run.go +600 -0
  22. package/engine/internal/overhaul/score/run_test.go +405 -0
  23. package/engine/internal/overhaul/snapshot/run.go +563 -0
  24. package/engine/internal/overhaul/snapshot/run_test.go +360 -0
  25. package/engine/main.go +4 -0
  26. package/engine/root_routing_test.go +2 -1
  27. package/pack/.claude/skills/overhaul/SKILL.md +201 -0
  28. package/pack/.claude/skills/overhaul/references/audit-domains.md +263 -0
  29. package/pack/.claude/skills/overhaul/references/lifecycle.md +308 -0
  30. package/pack/.claude/skills/overhaul/references/orchestration.md +264 -0
  31. package/pack/.claude/skills/overhaul/references/records.md +137 -0
  32. package/pack/.claude/skills/overhaul/references/repair-and-measurement.md +207 -0
  33. package/pack/.claude/skills/overhaul/references/review-and-report.md +137 -0
  34. package/pack/.claude/skills/overhaul/references/scope-and-safety.md +191 -0
  35. package/pack/.claude/skills/overhaul/references/scoring.md +222 -0
  36. package/pack/.claude/skills/overhaul/references/stack-profiles.md +264 -0
  37. package/pack/.claude/skills/overhaul/roles/backend-engineer.md +61 -0
  38. package/pack/.claude/skills/overhaul/roles/boundary.md +56 -0
  39. package/pack/.claude/skills/overhaul/roles/craft.md +77 -0
  40. package/pack/.claude/skills/overhaul/roles/frontend-engineer.md +63 -0
  41. package/pack/.claude/skills/overhaul/roles/implementer.md +59 -0
  42. package/pack/.claude/skills/overhaul/roles/recon.md +60 -0
  43. package/pack/.claude/skills/overhaul/roles/specialist.md +56 -0
  44. package/pack/.claude/skills/overhaul/roles/verifier.md +60 -0
  45. package/pack/generated/claude/skills/overhaul/SKILL.md +201 -0
  46. package/pack/generated/claude/skills/overhaul/references/audit-domains.md +263 -0
  47. package/pack/generated/claude/skills/overhaul/references/lifecycle.md +308 -0
  48. package/pack/generated/claude/skills/overhaul/references/orchestration.md +264 -0
  49. package/pack/generated/claude/skills/overhaul/references/records.md +137 -0
  50. package/pack/generated/claude/skills/overhaul/references/repair-and-measurement.md +207 -0
  51. package/pack/generated/claude/skills/overhaul/references/review-and-report.md +137 -0
  52. package/pack/generated/claude/skills/overhaul/references/scope-and-safety.md +191 -0
  53. package/pack/generated/claude/skills/overhaul/references/scoring.md +222 -0
  54. package/pack/generated/claude/skills/overhaul/references/stack-profiles.md +264 -0
  55. package/pack/generated/claude/skills/overhaul/roles/backend-engineer.md +61 -0
  56. package/pack/generated/claude/skills/overhaul/roles/boundary.md +56 -0
  57. package/pack/generated/claude/skills/overhaul/roles/craft.md +77 -0
  58. package/pack/generated/claude/skills/overhaul/roles/frontend-engineer.md +63 -0
  59. package/pack/generated/claude/skills/overhaul/roles/implementer.md +59 -0
  60. package/pack/generated/claude/skills/overhaul/roles/recon.md +60 -0
  61. package/pack/generated/claude/skills/overhaul/roles/specialist.md +56 -0
  62. package/pack/generated/claude/skills/overhaul/roles/verifier.md +60 -0
  63. package/pack/generated/codex/skills/overhaul/SKILL.md +201 -0
  64. package/pack/generated/codex/skills/overhaul/agents/openai.yaml +2 -0
  65. package/pack/generated/codex/skills/overhaul/references/audit-domains.md +263 -0
  66. package/pack/generated/codex/skills/overhaul/references/lifecycle.md +308 -0
  67. package/pack/generated/codex/skills/overhaul/references/orchestration.md +264 -0
  68. package/pack/generated/codex/skills/overhaul/references/records.md +137 -0
  69. package/pack/generated/codex/skills/overhaul/references/repair-and-measurement.md +207 -0
  70. package/pack/generated/codex/skills/overhaul/references/review-and-report.md +137 -0
  71. package/pack/generated/codex/skills/overhaul/references/scope-and-safety.md +191 -0
  72. package/pack/generated/codex/skills/overhaul/references/scoring.md +222 -0
  73. package/pack/generated/codex/skills/overhaul/references/stack-profiles.md +264 -0
  74. package/pack/generated/codex/skills/overhaul/roles/backend-engineer.md +61 -0
  75. package/pack/generated/codex/skills/overhaul/roles/boundary.md +56 -0
  76. package/pack/generated/codex/skills/overhaul/roles/craft.md +77 -0
  77. package/pack/generated/codex/skills/overhaul/roles/frontend-engineer.md +63 -0
  78. package/pack/generated/codex/skills/overhaul/roles/implementer.md +59 -0
  79. package/pack/generated/codex/skills/overhaul/roles/recon.md +60 -0
  80. package/pack/generated/codex/skills/overhaul/roles/specialist.md +56 -0
  81. package/pack/generated/codex/skills/overhaul/roles/verifier.md +60 -0
  82. package/pack/generated/devin/skills/overhaul/SKILL.md +201 -0
  83. package/pack/generated/devin/skills/overhaul/references/audit-domains.md +263 -0
  84. package/pack/generated/devin/skills/overhaul/references/lifecycle.md +308 -0
  85. package/pack/generated/devin/skills/overhaul/references/orchestration.md +264 -0
  86. package/pack/generated/devin/skills/overhaul/references/records.md +137 -0
  87. package/pack/generated/devin/skills/overhaul/references/repair-and-measurement.md +207 -0
  88. package/pack/generated/devin/skills/overhaul/references/review-and-report.md +137 -0
  89. package/pack/generated/devin/skills/overhaul/references/scope-and-safety.md +191 -0
  90. package/pack/generated/devin/skills/overhaul/references/scoring.md +222 -0
  91. package/pack/generated/devin/skills/overhaul/references/stack-profiles.md +264 -0
  92. package/pack/generated/devin/skills/overhaul/roles/backend-engineer.md +61 -0
  93. package/pack/generated/devin/skills/overhaul/roles/boundary.md +56 -0
  94. package/pack/generated/devin/skills/overhaul/roles/craft.md +77 -0
  95. package/pack/generated/devin/skills/overhaul/roles/frontend-engineer.md +63 -0
  96. package/pack/generated/devin/skills/overhaul/roles/implementer.md +59 -0
  97. package/pack/generated/devin/skills/overhaul/roles/recon.md +60 -0
  98. package/pack/generated/devin/skills/overhaul/roles/specialist.md +56 -0
  99. package/pack/generated/devin/skills/overhaul/roles/verifier.md +60 -0
  100. package/pack/generated/omp/skills/overhaul/SKILL.md +201 -0
  101. package/pack/generated/omp/skills/overhaul/references/audit-domains.md +263 -0
  102. package/pack/generated/omp/skills/overhaul/references/lifecycle.md +308 -0
  103. package/pack/generated/omp/skills/overhaul/references/orchestration.md +264 -0
  104. package/pack/generated/omp/skills/overhaul/references/records.md +137 -0
  105. package/pack/generated/omp/skills/overhaul/references/repair-and-measurement.md +207 -0
  106. package/pack/generated/omp/skills/overhaul/references/review-and-report.md +137 -0
  107. package/pack/generated/omp/skills/overhaul/references/scope-and-safety.md +191 -0
  108. package/pack/generated/omp/skills/overhaul/references/scoring.md +222 -0
  109. package/pack/generated/omp/skills/overhaul/references/stack-profiles.md +264 -0
  110. package/pack/generated/omp/skills/overhaul/roles/backend-engineer.md +61 -0
  111. package/pack/generated/omp/skills/overhaul/roles/boundary.md +56 -0
  112. package/pack/generated/omp/skills/overhaul/roles/craft.md +77 -0
  113. package/pack/generated/omp/skills/overhaul/roles/frontend-engineer.md +63 -0
  114. package/pack/generated/omp/skills/overhaul/roles/implementer.md +59 -0
  115. package/pack/generated/omp/skills/overhaul/roles/recon.md +60 -0
  116. package/pack/generated/omp/skills/overhaul/roles/specialist.md +56 -0
  117. package/pack/generated/omp/skills/overhaul/roles/verifier.md +60 -0
  118. package/pack/generated/pi/skills/overhaul/SKILL.md +201 -0
  119. package/pack/generated/pi/skills/overhaul/references/audit-domains.md +263 -0
  120. package/pack/generated/pi/skills/overhaul/references/lifecycle.md +308 -0
  121. package/pack/generated/pi/skills/overhaul/references/orchestration.md +264 -0
  122. package/pack/generated/pi/skills/overhaul/references/records.md +137 -0
  123. package/pack/generated/pi/skills/overhaul/references/repair-and-measurement.md +207 -0
  124. package/pack/generated/pi/skills/overhaul/references/review-and-report.md +137 -0
  125. package/pack/generated/pi/skills/overhaul/references/scope-and-safety.md +191 -0
  126. package/pack/generated/pi/skills/overhaul/references/scoring.md +222 -0
  127. package/pack/generated/pi/skills/overhaul/references/stack-profiles.md +264 -0
  128. package/pack/generated/pi/skills/overhaul/roles/backend-engineer.md +61 -0
  129. package/pack/generated/pi/skills/overhaul/roles/boundary.md +56 -0
  130. package/pack/generated/pi/skills/overhaul/roles/craft.md +77 -0
  131. package/pack/generated/pi/skills/overhaul/roles/frontend-engineer.md +63 -0
  132. package/pack/generated/pi/skills/overhaul/roles/implementer.md +59 -0
  133. package/pack/generated/pi/skills/overhaul/roles/recon.md +60 -0
  134. package/pack/generated/pi/skills/overhaul/roles/specialist.md +56 -0
  135. package/pack/generated/pi/skills/overhaul/roles/verifier.md +60 -0
  136. package/package.json +1 -1
@@ -0,0 +1,405 @@
1
+ package score
2
+
3
+ import (
4
+ "bytes"
5
+ "encoding/json"
6
+ "fmt"
7
+ "maps"
8
+ "math/big"
9
+ "os"
10
+ "path/filepath"
11
+ "strings"
12
+ "testing"
13
+
14
+ "github.com/devrites/devrites/internal/overhaul/ovio"
15
+ )
16
+
17
+ var doms = []string{"correctness", "security", "reliability", "performance", "tests", "architecture", "ux", "operations"}
18
+
19
+ func ctl(i int, d string, w any, lanes ...string) map[string]any {
20
+ if len(lanes) == 0 {
21
+ lanes = []string{"backend"}
22
+ }
23
+ return map[string]any{"id": fmt.Sprintf("C-%03d", i), "domain": d, "lanes": lanes, "weight": w, "hard_gate": false}
24
+ }
25
+
26
+ func rubricOf(controls []map[string]any) map[string]any {
27
+ return map[string]any{"schema": "overhaul.rubric/1", "rev": 1, "lanes": []string{"frontend", "backend"},
28
+ "controls": controls, "domains": map[string]any{"correctness": 20, "security": 20, "reliability": 15,
29
+ "performance": 15, "tests": 10, "architecture": 10, "ux": 5, "operations": 5}}
30
+ }
31
+
32
+ func resOf(status map[string]string) map[string]any {
33
+ r := map[string]any{}
34
+ for k, v := range status {
35
+ r[k] = map[string]any{"status": v, "evidence": []string{"EV-1"}}
36
+ }
37
+ return map[string]any{"schema": "overhaul.results/1", "subject": "candidate", "results": r}
38
+ }
39
+
40
+ func passing() map[string]any {
41
+ g := map[string]any{}
42
+ for _, id := range auditGates {
43
+ g[id] = map[string]any{"status": "PASS", "evidence": []string{"EV-g"}}
44
+ }
45
+ return map[string]any{"mode": "audit", "gates": g}
46
+ }
47
+
48
+ func allPass(cs []map[string]any) map[string]string {
49
+ st := map[string]string{}
50
+ for _, c := range cs {
51
+ st[c["id"].(string)] = "PASS"
52
+ }
53
+ return st
54
+ }
55
+
56
+ // norm round-trips v through JSON with UseNumber, exactly as file input arrives.
57
+ func norm(t *testing.T, v any) map[string]any {
58
+ t.Helper()
59
+ b, err := json.Marshal(v)
60
+ if err != nil {
61
+ t.Fatal(err)
62
+ }
63
+ dec := json.NewDecoder(bytes.NewReader(b))
64
+ dec.UseNumber()
65
+ var m map[string]any
66
+ if err := dec.Decode(&m); err != nil {
67
+ t.Fatal(err)
68
+ }
69
+ return m
70
+ }
71
+
72
+ func tryScore(t *testing.T, r, s, g any) (map[string]any, error) {
73
+ t.Helper()
74
+ out, err := score(norm(t, r), norm(t, s), norm(t, g))
75
+ if err != nil {
76
+ return nil, err
77
+ }
78
+ return norm(t, out), nil
79
+ }
80
+
81
+ func mustScore(t *testing.T, r, s, g any) map[string]any {
82
+ t.Helper()
83
+ out, err := tryScore(t, r, s, g)
84
+ if err != nil {
85
+ t.Fatalf("score: %v", err)
86
+ }
87
+ return out
88
+ }
89
+
90
+ func get(v any, path string) string { return fmt.Sprint(ovio.Get(v, path)) }
91
+
92
+ func exact(t *testing.T, v any, path string) *big.Rat {
93
+ t.Helper()
94
+ r, ok := new(big.Rat).SetString(get(v, path))
95
+ if !ok {
96
+ t.Fatalf("%s is not exact: %v", path, ovio.Get(v, path))
97
+ }
98
+ return r
99
+ }
100
+
101
+ func base() []map[string]any {
102
+ var b []map[string]any
103
+ for i, d := range doms {
104
+ b = append(b, ctl(i, d, 5, "frontend", "backend"))
105
+ }
106
+ return b
107
+ }
108
+
109
+ func workedExample() ([]map[string]any, map[string]string) {
110
+ ex := append(base(), ctl(10, "correctness", 5), ctl(11, "correctness", 5), ctl(12, "correctness", 3), ctl(13, "correctness", 1))
111
+ st := allPass(ex)
112
+ st["C-013"] = "FAIL"
113
+ return ex, st
114
+ }
115
+
116
+ func laneMasking() []map[string]any {
117
+ l := base()
118
+ for k := range 10 {
119
+ l = append(l, ctl(30+k, "correctness", 5, "backend"))
120
+ }
121
+ return append(l, ctl(40, "correctness", 5, "frontend"))
122
+ }
123
+
124
+ // 1. Worked example: correctness 5,5,5,3 PASS + 1 FAIL -> D=180/19, Q=18800/1900.
125
+ func TestWorkedExample(t *testing.T) {
126
+ ex, st := workedExample()
127
+ out := mustScore(t, rubricOf(ex), resOf(st), passing())
128
+ if got := get(out, "global.domains.correctness.exact"); got != "180/19" {
129
+ t.Fatalf("correctness = %s", got)
130
+ }
131
+ if got := get(out, "global.Q.exact"); got != "188/19" {
132
+ t.Fatalf("Q = %s", got)
133
+ }
134
+ if got := get(out, "global.Q.decimal"); got != "9.894736842105" {
135
+ t.Fatalf("decimal = %s", got)
136
+ }
137
+ if v := get(out, "readiness_verdict"); v != "MEETS_TARGETS" {
138
+ t.Fatalf("verdict = %s", v)
139
+ }
140
+ }
141
+
142
+ // 2. Same numbers, failing control is a hard gate -> NOT_READY despite Q 9.89.
143
+ func TestHardGateBlocks(t *testing.T) {
144
+ ex, st := workedExample()
145
+ ex[len(ex)-1]["hard_gate"] = true
146
+ out := mustScore(t, rubricOf(ex), resOf(st), passing())
147
+ if get(out, "readiness_verdict") != "NOT_READY" || get(out, "gates.G-MANDATORY") != "FAIL" {
148
+ t.Fatalf("verdict %s, G-MANDATORY %s", get(out, "readiness_verdict"), get(out, "gates.G-MANDATORY"))
149
+ }
150
+ if got := get(out, "global.Q.exact"); got != "188/19" {
151
+ t.Fatalf("Q = %s", got)
152
+ }
153
+ }
154
+
155
+ // 3. Q exactly 9.696 fails 9.7 at full precision.
156
+ func TestFullPrecisionThreshold(t *testing.T) {
157
+ var cs []map[string]any
158
+ st := map[string]string{}
159
+ i := 100
160
+ for _, d := range doms {
161
+ n := 1
162
+ if d == "correctness" || d == "security" {
163
+ n = 250
164
+ }
165
+ for k := range n {
166
+ cs = append(cs, ctl(i, d, 1, "frontend", "backend"))
167
+ st[fmt.Sprintf("C-%03d", i)] = "PASS"
168
+ if n == 250 && k < 19 {
169
+ st[fmt.Sprintf("C-%03d", i)] = "FAIL"
170
+ }
171
+ i++
172
+ }
173
+ }
174
+ out := mustScore(t, rubricOf(cs), resOf(st), passing())
175
+ if got := get(out, "global.Q.exact"); got != "1212/125" {
176
+ t.Fatalf("Q = %s", got)
177
+ }
178
+ row := ovio.List(out["thresholds"])[0]
179
+ if get(row, "scope") != "global" || get(row, "result") != "FAIL" || get(out, "readiness_verdict") != "NOT_READY" {
180
+ t.Fatalf("row %v verdict %s", row, get(out, "readiness_verdict"))
181
+ }
182
+ }
183
+
184
+ // 4. Zero denominator: an applicable domain whose only control is N/A -> NOT_ASSESSABLE, never 10.
185
+ func TestZeroDenominatorNotAssessable(t *testing.T) {
186
+ b := base()
187
+ z := make([]map[string]any, len(b))
188
+ for i, c := range b {
189
+ z[i] = maps.Clone(c)
190
+ }
191
+ z[6]["na"] = map[string]any{"reason": "no UI", "evidence": []string{"EV-2"}, "approved": true}
192
+ out := mustScore(t, rubricOf(z), resOf(allPass(b)), passing())
193
+ if ovio.Get(out, "global.Q") != nil || get(out, "readiness_verdict") != "NOT_ASSESSABLE" {
194
+ t.Fatalf("Q %v verdict %s", ovio.Get(out, "global.Q"), get(out, "readiness_verdict"))
195
+ }
196
+ }
197
+
198
+ // 5. Global 59/6 and backend 10 cannot mask frontend 9.0; shared controls count once globally.
199
+ func TestLaneMasking(t *testing.T) {
200
+ l := laneMasking()
201
+ st := allPass(l)
202
+ st["C-040"] = "FAIL"
203
+ out := mustScore(t, rubricOf(l), resOf(st), passing())
204
+ if row := ovio.List(out["thresholds"])[0]; get(row, "result") != "PASS" || get(out, "global.Q.exact") != "59/6" {
205
+ t.Fatalf("global row %v Q %s", row, get(out, "global.Q.exact"))
206
+ }
207
+ if get(out, "lanes.frontend.Q.exact") != "9/1" || get(out, "lanes.backend.Q.exact") != "10/1" {
208
+ t.Fatalf("lanes %v", out["lanes"])
209
+ }
210
+ laneRow := "missing"
211
+ for _, row := range ovio.List(out["thresholds"]) {
212
+ if get(row, "scope") == "lane frontend" {
213
+ laneRow = get(row, "result")
214
+ }
215
+ }
216
+ if laneRow != "FAIL" {
217
+ t.Fatalf("lane frontend threshold row = %s", laneRow)
218
+ }
219
+ if get(out, "readiness_verdict") != "NOT_READY" {
220
+ t.Fatalf("verdict %s", get(out, "readiness_verdict"))
221
+ }
222
+ if get(out, "counts.controls") != "19" || get(out, "counts.lane_appearances") != "27" {
223
+ t.Fatalf("counts %v", out["counts"])
224
+ }
225
+ }
226
+
227
+ // 6. PASS without evidence counts as UNKNOWN; UNKNOWN earns zero, not N/A.
228
+ func TestPassWithoutEvidenceIsUnknown(t *testing.T) {
229
+ b := base()
230
+ r := resOf(allPass(b))
231
+ r["results"].(map[string]any)["C-000"].(map[string]any)["evidence"] = []string{}
232
+ out := mustScore(t, rubricOf(b), r, passing())
233
+ if get(out, "status_by_control.C-000") != "UNKNOWN" || get(out, "global.domains.correctness.exact") != "0/1" {
234
+ t.Fatalf("status %s correctness %s", get(out, "status_by_control.C-000"), get(out, "global.domains.correctness.exact"))
235
+ }
236
+ if len(ovio.List(out["downgrades"])) != 1 {
237
+ t.Fatalf("downgrades %v", out["downgrades"])
238
+ }
239
+ }
240
+
241
+ // 7. Fixed-catalog monotonicity: turning any PASS into FAIL never raises any score.
242
+ func TestMonotonicity(t *testing.T) {
243
+ l := laneMasking()
244
+ full := allPass(l)
245
+ top := mustScore(t, rubricOf(l), resOf(full), passing())
246
+ for id := range full {
247
+ worse := maps.Clone(full)
248
+ worse[id] = "FAIL"
249
+ low := mustScore(t, rubricOf(l), resOf(worse), passing())
250
+ for _, p := range []string{"global.Q.exact", "lanes.frontend.Q.exact", "lanes.backend.Q.exact"} {
251
+ if exact(t, low, p).Cmp(exact(t, top, p)) > 0 {
252
+ t.Fatalf("failing %s raised %s", id, p)
253
+ }
254
+ }
255
+ if exact(t, low, "global.Q.exact").Cmp(exact(t, top, "global.Q.exact")) >= 0 {
256
+ t.Fatalf("failing %s did not lower global Q", id)
257
+ }
258
+ }
259
+ }
260
+
261
+ // 8. Duplicate control ids and zero weights are invalid input.
262
+ func TestInvalidCatalog(t *testing.T) {
263
+ zero := base()
264
+ zero[0] = maps.Clone(zero[0])
265
+ zero[0]["weight"] = 0
266
+ for _, tc := range []struct {
267
+ cs []map[string]any
268
+ want string
269
+ }{{append(base(), base()[0]), "duplicate control id"}, {zero, "must be > 0"}} {
270
+ if _, err := tryScore(t, rubricOf(tc.cs), resOf(nil), passing()); err == nil || !strings.Contains(err.Error(), tc.want) {
271
+ t.Fatalf("want %q, got %v", tc.want, err)
272
+ }
273
+ }
274
+ }
275
+
276
+ // 9. Approved sequential degradation is the only open gate -> qualified outcome.
277
+ func TestApprovedDegradation(t *testing.T) {
278
+ b := base()
279
+ g := passing()
280
+ g["gates"].(map[string]any)["G-CONCURRENCY"] = map[string]any{"status": "WAIVED_OPERATIONAL", "approval": "AP-2"}
281
+ out := mustScore(t, rubricOf(b), resOf(allPass(b)), g)
282
+ if v := get(out, "readiness_verdict"); v != "MEETS_TARGETS_WITH_APPROVED_DEGRADATION" {
283
+ t.Fatalf("verdict %s", v)
284
+ }
285
+ }
286
+
287
+ // 10. Missing gate evidence -> UNKNOWN -> NOT_READY.
288
+ func TestGatePassWithoutEvidence(t *testing.T) {
289
+ b := base()
290
+ g := passing()
291
+ g["gates"].(map[string]any)["G-COVERAGE"] = map[string]any{"status": "PASS"}
292
+ out := mustScore(t, rubricOf(b), resOf(allPass(b)), g)
293
+ if get(out, "gates.G-COVERAGE") != "UNKNOWN" || get(out, "readiness_verdict") != "NOT_READY" {
294
+ t.Fatalf("gate %s verdict %s", get(out, "gates.G-COVERAGE"), get(out, "readiness_verdict"))
295
+ }
296
+ }
297
+
298
+ // 11. A rubric cannot lower the policy thresholds or drop a domain without a recorded exclusion.
299
+ func TestWeakenedRubric(t *testing.T) {
300
+ b := base()
301
+ low := rubricOf(b)
302
+ low["policy"] = map[string]any{"global_min": "0"}
303
+ var four []map[string]any
304
+ for i, d := range []string{"tests", "architecture", "ux", "operations"} {
305
+ four = append(four, ctl(i+1, d, 5))
306
+ }
307
+ partial := rubricOf(four)
308
+ partial["domains"] = map[string]any{"tests": 10, "architecture": 10, "ux": 5, "operations": 5}
309
+ for _, tc := range []struct {
310
+ r map[string]any
311
+ st map[string]string
312
+ want string
313
+ }{{low, allPass(b), "policy may only raise"}, {partial, allPass(four), "needs a weight or a recorded exclusion"}} {
314
+ if _, err := tryScore(t, tc.r, resOf(tc.st), passing()); err == nil || !strings.Contains(err.Error(), tc.want) {
315
+ t.Fatalf("want %q, got %v", tc.want, err)
316
+ }
317
+ }
318
+ }
319
+
320
+ func writeJSON(t *testing.T, dir, name string, v any) string {
321
+ t.Helper()
322
+ b, err := json.Marshal(v)
323
+ if err != nil {
324
+ t.Fatal(err)
325
+ }
326
+ p := filepath.Join(dir, name)
327
+ if err := os.WriteFile(p, b, 0o644); err != nil {
328
+ t.Fatal(err)
329
+ }
330
+ return p
331
+ }
332
+
333
+ func runCLI(args ...string) (int, string, string) {
334
+ var o, e bytes.Buffer
335
+ code := Run(args, &o, &e)
336
+ return code, o.String(), e.String()
337
+ }
338
+
339
+ func TestCompare(t *testing.T) {
340
+ var excl []any
341
+ for _, d := range doms[2:] {
342
+ excl = append(excl, map[string]any{"domain": d, "reason": "out of scope", "evidence": []string{"EV-x"}})
343
+ }
344
+ r := map[string]any{"schema": "overhaul.rubric/1", "rev": 1, "lanes": []string{"backend"},
345
+ "domains": map[string]any{"correctness": 50, "security": 50}, "domain_exclusions": excl,
346
+ "controls": []map[string]any{ctl(1, "correctness", 5), ctl(2, "correctness", 5), ctl(3, "security", 5)}}
347
+ dir := t.TempDir()
348
+ code, stdout, stderr := runCLI("compare", "--rubric", writeJSON(t, dir, "r.json", r),
349
+ "--baseline", writeJSON(t, dir, "a.json", resOf(map[string]string{"C-001": "PASS", "C-002": "UNKNOWN", "C-003": "PASS"})),
350
+ "--candidate", writeJSON(t, dir, "b.json", resOf(map[string]string{"C-001": "FAIL", "C-002": "PASS", "C-003": "PASS"})))
351
+ if code != 0 {
352
+ t.Fatalf("exit %d: %s", code, stderr)
353
+ }
354
+ out := norm(t, json.RawMessage(stdout))
355
+ if get(out, "baseline_Q.exact") != "15/2" || get(out, "candidate_Q.exact") != "15/2" {
356
+ t.Fatalf("Q %v / %v", out["baseline_Q"], out["candidate_Q"])
357
+ }
358
+ rows := ovio.List(out["transitions"])
359
+ if len(rows) != 2 ||
360
+ get(rows[0], "control") != "C-001" || get(rows[0], "kind") != "regression-or-new-failure" ||
361
+ get(rows[1], "control") != "C-002" || get(rows[1], "kind") != "evidence-only" {
362
+ t.Fatalf("transitions %v", rows)
363
+ }
364
+ }
365
+
366
+ func TestCLIOutWritesScorecard(t *testing.T) {
367
+ dir := t.TempDir()
368
+ b := base()
369
+ outPath := filepath.Join(dir, "scorecard.json")
370
+ code, stdout, stderr := runCLI("--rubric", writeJSON(t, dir, "r.json", rubricOf(b)),
371
+ "--results", writeJSON(t, dir, "s.json", resOf(allPass(b))),
372
+ "--gates", writeJSON(t, dir, "g.json", passing()), "--out", outPath)
373
+ if code != 0 || stdout != "MEETS_TARGETS -> "+outPath+"\n" {
374
+ t.Fatalf("exit %d stdout %q stderr %q", code, stdout, stderr)
375
+ }
376
+ card, err := ovio.LoadObject(outPath)
377
+ if err != nil {
378
+ t.Fatal(err)
379
+ }
380
+ if get(card, "schema") != "overhaul.scorecard/1" || get(card, "readiness_verdict") != "MEETS_TARGETS" ||
381
+ len(get(card, "inputs.rubric_sha256")) != 64 {
382
+ t.Fatalf("scorecard %v", card)
383
+ }
384
+ }
385
+
386
+ func TestCLIInvalidInputExits2(t *testing.T) {
387
+ dir := t.TempDir()
388
+ b := base()
389
+ bad := rubricOf(b)
390
+ bad["schema"] = "overhaul.rubric/0"
391
+ rubric := writeJSON(t, dir, "r.json", rubricOf(b))
392
+ stale := resOf(allPass(b))
393
+ stale["rubric_digest"] = strings.Repeat("0", 64)
394
+ for name, args := range map[string][]string{
395
+ "bad rubric": {"--rubric", writeJSON(t, dir, "bad.json", bad), "--results", writeJSON(t, dir, "s.json", resOf(allPass(b))),
396
+ "--gates", writeJSON(t, dir, "g.json", passing())},
397
+ "stale digest": {"--rubric", rubric, "--results", writeJSON(t, dir, "stale.json", stale),
398
+ "--gates", filepath.Join(dir, "g.json")},
399
+ } {
400
+ code, stdout, stderr := runCLI(args...)
401
+ if code != 2 || stdout != "" || !strings.HasPrefix(stderr, "ERROR: ") {
402
+ t.Fatalf("%s: exit %d stdout %q stderr %q", name, code, stdout, stderr)
403
+ }
404
+ }
405
+ }