-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathartifact_governance_final_signoff_contract.rs
More file actions
330 lines (299 loc) · 11.2 KB
/
Copy pathartifact_governance_final_signoff_contract.rs
File metadata and controls
330 lines (299 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#![allow(missing_docs)]
use serde_json::Value;
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
const SIGNOFF_PATH: &str = "artifacts/artifact_governance_final_signoff_v1.json";
const RUNBOOK_PATH: &str = "docs/proof/artifact_governance_final_signoff.md";
const LEDGER_PATH: &str = "artifacts/artifact_governance_ledger_v1.json";
const HARNESS_PATH: &str = "artifacts/artifact_governance_validation_harness_v1.json";
const MANIFEST_PATH: &str = "artifacts/proof_lane_manifest_v1.json";
const STATUS_PATH: &str = "artifacts/proof_status_snapshot_v1.json";
const BEAD_ID: &str = "asupersync-artifact-governance-awdiwy.6";
const LANE_ID: &str = "artifact-governance-final-signoff";
const GUARANTEE_ID: &str = "artifact-governance-final-signoff";
const CLAIM_ID: &str = "artifact-governance-final-signoff";
fn repo_path(relative: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join(relative)
}
fn read_repo_file(relative: &str) -> String {
std::fs::read_to_string(repo_path(relative))
.unwrap_or_else(|error| panic!("read {relative}: {error}"))
}
fn repo_json(relative: &str) -> Value {
serde_json::from_str(&read_repo_file(relative))
.unwrap_or_else(|error| panic!("parse {relative}: {error}"))
}
fn array<'a>(value: &'a Value, key: &str) -> &'a [Value] {
value
.get(key)
.and_then(Value::as_array)
.map_or_else(|| panic!("{key} must be an array"), Vec::as_slice)
}
fn object<'a>(value: &'a Value, key: &str) -> &'a serde_json::Map<String, Value> {
value
.get(key)
.and_then(Value::as_object)
.unwrap_or_else(|| panic!("{key} must be an object"))
}
fn string<'a>(value: &'a Value, key: &str) -> &'a str {
let text = value
.get(key)
.and_then(Value::as_str)
.unwrap_or_else(|| panic!("{key} must be a string"));
assert!(!text.trim().is_empty(), "{key} must be nonempty");
text
}
fn optional_string<'a>(value: &'a Value, key: &str) -> Option<&'a str> {
match value.get(key) {
Some(Value::Null) | None => None,
Some(Value::String(text)) => {
assert!(!text.trim().is_empty(), "{key} must be nonempty when set");
Some(text)
}
Some(_) => panic!("{key} must be null or string"),
}
}
fn bool_field(value: &Value, key: &str) -> bool {
value
.get(key)
.and_then(Value::as_bool)
.unwrap_or_else(|| panic!("{key} must be a bool"))
}
fn string_set(value: &Value, key: &str) -> BTreeSet<String> {
array(value, key)
.iter()
.map(|entry| {
entry
.as_str()
.filter(|text| !text.trim().is_empty())
.unwrap_or_else(|| panic!("{key} entries must be nonempty strings"))
.to_owned()
})
.collect()
}
fn assert_repo_file_exists(path: &str) {
assert!(repo_path(path).is_file(), "repo file must exist: {path}");
}
fn rows_by_id() -> BTreeMap<String, Value> {
let ledger = repo_json(LEDGER_PATH);
let mut rows = BTreeMap::new();
for row in array(&ledger, "rows") {
let artifact_id = string(row, "artifact_id").to_owned();
assert!(
rows.insert(artifact_id.clone(), row.clone()).is_none(),
"duplicate ledger row {artifact_id}"
);
}
rows
}
fn lanes_by_id() -> BTreeMap<String, Value> {
let manifest = repo_json(MANIFEST_PATH);
array(&manifest, "lanes")
.iter()
.map(|lane| (string(lane, "lane_id").to_owned(), lane.clone()))
.collect()
}
fn guarantees_by_id() -> BTreeMap<String, Value> {
let manifest = repo_json(MANIFEST_PATH);
array(&manifest, "guarantees")
.iter()
.map(|guarantee| {
(
string(guarantee, "guarantee_id").to_owned(),
guarantee.clone(),
)
})
.collect()
}
fn status_rows_by_claim() -> BTreeMap<String, Value> {
let status = repo_json(STATUS_PATH);
array(&status, "claim_categories")
.iter()
.map(|row| (string(row, "claim_id").to_owned(), row.clone()))
.collect()
}
#[test]
fn final_signoff_schema_sources_and_policy_are_bounded() {
let signoff = repo_json(SIGNOFF_PATH);
assert_eq!(
signoff.get("schema_version").and_then(Value::as_str),
Some("artifact-governance-final-signoff-v1")
);
assert_eq!(
signoff.get("bead_id").and_then(Value::as_str),
Some(BEAD_ID)
);
for path in object(&signoff, "source_of_truth")
.values()
.map(|value| value.as_str().expect("source path string"))
{
assert_repo_file_exists(path);
}
let policy = object(&signoff, "signoff_policy");
let policy_value = Value::Object(policy.clone());
assert!(!bool_field(&policy_value, "full_corpus_claim"));
assert!(bool_field(
&policy_value,
"requires_remote_required_validation"
));
assert!(bool_field(&policy_value, "no_local_fallback"));
let non_destructive = string(&policy_value, "non_destructive_policy");
for required in [
"does not delete",
"branches",
"worktrees",
"local Cargo fallback",
] {
assert!(
non_destructive.contains(required),
"non_destructive_policy missing {required}"
);
}
assert!(string(&policy_value, "tracker_policy").contains(".beads/issues.jsonl"));
for boundary in string_set(&signoff, "no_claim_boundaries") {
assert!(
boundary.starts_with("does_not_"),
"boundary must be a does_not token: {boundary}"
);
}
}
#[test]
fn child_deliverables_match_existing_artifacts_contracts_and_ledger_rows() {
let signoff = repo_json(SIGNOFF_PATH);
let rows = rows_by_id();
let children = array(&signoff, "child_deliverables");
let child_ids = children
.iter()
.map(|child| string(child, "child_id").to_owned())
.collect::<BTreeSet<_>>();
assert_eq!(
child_ids,
BTreeSet::from([
"A1".to_owned(),
"A2".to_owned(),
"A3".to_owned(),
"A4".to_owned(),
"A5".to_owned(),
"A7".to_owned(),
"A8".to_owned(),
])
);
for child in children {
assert_eq!(string(child, "status"), "landed");
assert_repo_file_exists(string(child, "primary_artifact"));
for test_path in array(child, "contract_tests") {
assert_repo_file_exists(test_path.as_str().expect("contract test path"));
}
let no_claims = string_set(child, "no_claim_boundaries");
assert!(no_claims.len() >= 3);
assert!(no_claims.iter().all(|claim| claim.starts_with("does_not_")));
if let Some(row_id) = optional_string(child, "ledger_row") {
let row = rows
.get(row_id)
.unwrap_or_else(|| panic!("missing ledger row {row_id}"));
assert_eq!(string(row, "path"), string(child, "primary_artifact"));
}
}
}
#[test]
fn manifest_and_status_rows_point_to_the_same_remote_required_lane() {
let signoff = repo_json(SIGNOFF_PATH);
let proof_lane = object(&signoff, "proof_lane");
let proof_lane_value = Value::Object(proof_lane.clone());
let command = string(&proof_lane_value, "command");
assert_eq!(string(&proof_lane_value, "lane_id"), LANE_ID);
assert_eq!(string(&proof_lane_value, "guarantee_id"), GUARANTEE_ID);
assert_eq!(string(&proof_lane_value, "status_claim_id"), CLAIM_ID);
assert!(command.starts_with("RCH_REQUIRE_REMOTE=1 rch exec -- "));
assert!(command.contains("artifact_governance_final_signoff_contract"));
assert!(command.contains("proof_lane_manifest_contract"));
assert!(command.contains("proof_status_snapshot_contract"));
let lanes = lanes_by_id();
let lane = lanes.get(LANE_ID).expect("manifest lane");
assert_eq!(string(lane, "command"), command);
assert_eq!(string(lane, "kind"), "artifact_contract");
assert_eq!(
string(lane, "resource_envelope_class"),
"artifact-contract-medium"
);
assert_eq!(
string_set(lane, "guarantee_ids"),
BTreeSet::from([GUARANTEE_ID.to_owned()])
);
assert!(string(lane, "explicit_not_covered").contains("release readiness"));
assert!(string(lane, "explicit_not_covered").contains("workspace health"));
assert!(
string_set(&lane["proof_reuse_policy"], "non_citeable_claim_scopes")
.contains("release-readiness")
);
let guarantees = guarantees_by_id();
let guarantee = guarantees.get(GUARANTEE_ID).expect("manifest guarantee");
assert_eq!(
string_set(guarantee, "lane_ids"),
BTreeSet::from([LANE_ID.to_owned()])
);
let status_rows = status_rows_by_claim();
let status = status_rows.get(CLAIM_ID).expect("status claim row");
assert_eq!(string(status, "status"), "yellow_scoped");
assert_eq!(string(status, "proof_evidence_status"), "rerun-required");
assert_eq!(
string_set(status, "manifest_lane_ids"),
BTreeSet::from([LANE_ID.to_owned()])
);
assert_eq!(
string_set(status, "manifest_guarantee_ids"),
BTreeSet::from([GUARANTEE_ID.to_owned()])
);
assert_eq!(
string_set(status, "proof_commands"),
BTreeSet::from([command.to_owned()])
);
assert!(string(status, "notes").contains("scoped"));
assert!(string(status, "notes").contains("does not prove release readiness"));
}
#[test]
fn ledger_and_validation_harness_include_final_signoff_without_overclaiming() {
let rows = rows_by_id();
let row = rows
.get("artifact-governance-final-signoff")
.expect("final signoff ledger row");
assert_eq!(string(row, "path"), SIGNOFF_PATH);
assert_eq!(string(row, "owning_bead"), BEAD_ID);
assert_eq!(string(row, "artifact_family"), "artifact_governance");
assert_eq!(string(row, "citeability_class"), "proof-bearing");
assert!(
string_set(row, "no_claim_boundaries").contains("does_not_authorize_local_cargo_fallback")
);
assert!(string_set(row, "no_claim_boundaries").contains("does_not_prove_release_readiness"));
let harness = repo_json(HARNESS_PATH);
let class_counts = object(&harness["e2e_flow_log"], "artifact_counts_by_class");
let actual_proof_bearing = rows
.values()
.filter(|row| string(row, "citeability_class") == "proof-bearing")
.count() as u64;
assert_eq!(
class_counts["proof-bearing"].as_u64(),
Some(actual_proof_bearing)
);
}
#[test]
fn runbook_and_docs_markers_preserve_no_local_fallback_boundary() {
let runbook = read_repo_file(RUNBOOK_PATH);
for required in [
SIGNOFF_PATH,
"artifact_governance_final_signoff_contract",
"RCH_REQUIRE_REMOTE=1 rch exec --",
"do not cite the lane as fresh proof",
"does_not_authorize_local_cargo_fallback",
"does_not_prove_release_readiness",
"close A4, A7, A8, and A6",
] {
assert!(runbook.contains(required), "runbook missing {required}");
}
let readme = read_repo_file("README.md");
let agents = read_repo_file("AGENTS.md");
for marker in [SIGNOFF_PATH, RUNBOOK_PATH] {
assert!(readme.contains(marker), "README missing marker {marker}");
assert!(agents.contains(marker), "AGENTS missing marker {marker}");
}
}