-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathworkunit_publish_gate.rs
More file actions
164 lines (151 loc) · 5.52 KB
/
workunit_publish_gate.rs
File metadata and controls
164 lines (151 loc) · 5.52 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
use decapod::core::capsule_policy::CapsulePolicyBinding;
use decapod::core::context_capsule::{
ContextCapsuleSnippet, ContextCapsuleSource, DeterministicContextCapsule, write_context_capsule,
};
use decapod::core::{workspace, workunit};
use tempfile::tempdir;
fn write_manifest(
root: &std::path::Path,
task_id: &str,
status: workunit::WorkUnitStatus,
state_refs: Vec<&str>,
proof_plan: Vec<&str>,
proof_results: Vec<(&str, &str)>,
) {
let manifest = workunit::WorkUnitManifest {
task_id: task_id.to_string(),
intent_ref: "intent://demo".to_string(),
spec_refs: vec![],
state_refs: state_refs.into_iter().map(|s| s.to_string()).collect(),
proof_plan: proof_plan.into_iter().map(|s| s.to_string()).collect(),
proof_results: proof_results
.into_iter()
.map(|(gate, status)| workunit::WorkUnitProofResult {
gate: gate.to_string(),
status: status.to_string(),
artifact_ref: None,
})
.collect(),
status,
};
workunit::write_workunit(root, &manifest).expect("write workunit manifest");
}
fn write_capsule(root: &std::path::Path, task_id: &str) {
let capsule = DeterministicContextCapsule {
schema_version: "1.1.0".to_string(),
topic: "publish".to_string(),
scope: "interfaces".to_string(),
task_id: Some(task_id.to_string()),
workunit_id: None,
sources: vec![ContextCapsuleSource {
path: "interfaces/PLAN_GOVERNED_EXECUTION.md".to_string(),
section: "Contract".to_string(),
}],
snippets: vec![ContextCapsuleSnippet {
source_path: "interfaces/PLAN_GOVERNED_EXECUTION.md".to_string(),
text: "promotion path is proof-gated".to_string(),
}],
policy: CapsulePolicyBinding {
risk_tier: "medium".to_string(),
policy_hash: "abc123".to_string(),
policy_version: "jit-capsule-policy-v1".to_string(),
policy_path: ".decapod/generated/policy/context_capsule_policy.json".to_string(),
repo_revision: "UNBORN:master".to_string(),
},
capsule_hash: String::new(),
};
write_context_capsule(root, &capsule).expect("write capsule");
}
#[test]
fn publish_gate_skips_when_branch_has_no_task_ids() {
let dir = tempdir().expect("tempdir");
let result = workspace::verify_workunit_gate_for_publish(dir.path(), "feature/no-task-id");
assert!(result.is_ok(), "expected no-op pass for non-task branch");
}
#[test]
fn publish_gate_fails_when_branch_task_manifest_missing() {
let dir = tempdir().expect("tempdir");
let err = workspace::verify_workunit_gate_for_publish(dir.path(), "agent/unknown/r_01ABCXYZ")
.expect_err("expected missing workunit manifest failure");
let msg = err.to_string();
assert!(
msg.contains("missing required workunit manifest"),
"unexpected error message: {msg}"
);
}
#[test]
fn publish_gate_fails_when_branch_task_not_verified() {
let dir = tempdir().expect("tempdir");
write_manifest(
dir.path(),
"test_01",
workunit::WorkUnitStatus::Claimed,
vec![],
vec!["validate_passes"],
vec![("validate_passes", "pass")],
);
let err = workspace::verify_workunit_gate_for_publish(dir.path(), "agent/codex/test_01")
.expect_err("expected status gate failure");
let msg = err.to_string();
assert!(
msg.contains("is not VERIFIED"),
"unexpected error message: {msg}"
);
}
#[test]
fn publish_gate_passes_when_branch_task_verified() {
let dir = tempdir().expect("tempdir");
write_capsule(dir.path(), "test_02");
write_manifest(
dir.path(),
"test_02",
workunit::WorkUnitStatus::Verified,
vec![".decapod/generated/context/test_02.json"],
vec!["validate_passes", "test:cargo test --all"],
vec![
("validate_passes", "pass"),
("test:cargo test --all", "pass"),
],
);
let result = workspace::verify_workunit_gate_for_publish(dir.path(), "agent/codex/test_02");
assert!(result.is_ok(), "expected verified branch task to pass");
}
#[test]
fn publish_gate_fails_when_verified_task_missing_capsule_lineage() {
let dir = tempdir().expect("tempdir");
write_manifest(
dir.path(),
"test_03",
workunit::WorkUnitStatus::Verified,
vec![".decapod/generated/context/test_03.json"],
vec!["validate_passes"],
vec![("validate_passes", "pass")],
);
let err = workspace::verify_workunit_gate_for_publish(dir.path(), "agent/codex/test_03")
.expect_err("expected missing capsule lineage failure");
let msg = err.to_string();
assert!(
msg.contains("WORKUNIT_CAPSULE_POLICY_LINEAGE_MISSING"),
"unexpected error message: {msg}"
);
}
#[test]
fn publish_gate_fails_when_verified_task_capsule_state_ref_missing() {
let dir = tempdir().expect("tempdir");
write_capsule(dir.path(), "test_04");
write_manifest(
dir.path(),
"test_04",
workunit::WorkUnitStatus::Verified,
vec![],
vec!["validate_passes"],
vec![("validate_passes", "pass")],
);
let err = workspace::verify_workunit_gate_for_publish(dir.path(), "agent/codex/test_04")
.expect_err("expected missing capsule state_ref failure");
let msg = err.to_string();
assert!(
msg.contains("WORKUNIT_CAPSULE_POLICY_LINEAGE_STATE_REF_MISSING"),
"unexpected error message: {msg}"
);
}