vyre-self-substrate 0.6.1

Vyre self-substrate: vyre using its own primitives on its own scheduler problems. The recursion-thesis layer between vyre-primitives and vyre-driver.
Documentation
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//! Final release launch sequence validation.

/// One final launch step.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseLaunchStep<'a> {
    /// Stable launch step id.
    pub id: &'a str,
    /// Exact command or externally verified action.
    pub command: &'a str,
    /// Whether the step is green.
    pub green: bool,
}

/// Validated release launch sequence.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseLaunchSequenceProof {
    /// Step count.
    pub step_count: usize,
}

/// Validated release tag-plan artifact.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseTagPlanProof {
    /// Number of ordered release tags.
    pub tag_count: usize,
}

/// Validated final launch receipt artifact.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseLaunchReceiptProof {
    /// Required executed receipt count.
    pub receipt_count: usize,
}

/// Release launch sequence validation errors.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReleaseLaunchSequenceError {
    /// Required step is missing or out of order.
    MissingOrOutOfOrder {
        /// Expected step id.
        expected: &'static str,
        /// Expected index.
        index: usize,
    },
    /// Step metadata is empty.
    EmptyMetadata {
        /// Step id.
        id: String,
        /// Field.
        field: &'static str,
    },
    /// Step is not green.
    StepNotGreen {
        /// Step id.
        id: String,
    },
    /// Required command pattern is absent.
    InvalidCommand {
        /// Step id.
        id: String,
        /// Command.
        command: String,
        /// Required command fragment.
        required_fragment: &'static str,
    },
    /// Release tag-plan artifact is missing required launch evidence.
    TagPlanMissingEvidence {
        /// Missing evidence.
        evidence: &'static str,
    },
    /// Final launch receipt artifact is missing required execution evidence.
    ReceiptMissingEvidence {
        /// Missing evidence.
        evidence: &'static str,
    },
}

impl std::fmt::Display for ReleaseLaunchSequenceError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::MissingOrOutOfOrder { expected, index } => write!(
                f,
                "release launch sequence missing `{expected}` at index {index}. Fix: run release gates before publish, then cargo publish, then public repo switch, then git push and tags."
            ),
            Self::EmptyMetadata { id, field } => write!(
                f,
                "release launch step `{id}` has empty {field}. Fix: record exact command/action evidence."
            ),
            Self::StepNotGreen { id } => write!(
                f,
                "release launch step `{id}` is not green. Fix: do not publish or push until every required launch step is green."
            ),
            Self::InvalidCommand {
                id,
                command,
                required_fragment,
            } => write!(
                f,
                "release launch step `{id}` command `{command}` lacks `{required_fragment}`. Fix: record the exact required launch command/action."
            ),
            Self::TagPlanMissingEvidence { evidence } => write!(
                f,
                "release tag plan is missing {evidence}. Fix: regenerate tag-plan evidence before publishing or pushing tags."
            ),
            Self::ReceiptMissingEvidence { evidence } => write!(
                f,
                "release launch receipt is missing {evidence}. Fix: record executed cargo publish, public repository switch, release branch push, and tag push receipts after they actually complete."
            ),
        }
    }
}

impl std::error::Error for ReleaseLaunchSequenceError {}

const REQUIRED_STEPS: &[(&str, &str)] = &[
    ("release-checklist-green", "./cargo_full"),
    ("cargo-publish", "cargo publish"),
    ("repos-public", "public"),
    ("git-push-release", "git push"),
    ("git-push-tags", "git push --tags"),
];

/// Validate the final launch sequence order and command evidence.
pub fn validate_release_launch_sequence(
    steps: &[ReleaseLaunchStep<'_>],
) -> Result<ReleaseLaunchSequenceProof, ReleaseLaunchSequenceError> {
    if steps.len() < REQUIRED_STEPS.len() {
        return Err(ReleaseLaunchSequenceError::MissingOrOutOfOrder {
            expected: REQUIRED_STEPS[steps.len()].0,
            index: steps.len(),
        });
    }

    for (index, (expected_id, required_fragment)) in REQUIRED_STEPS.iter().copied().enumerate() {
        let step = steps
            .get(index)
            .ok_or(ReleaseLaunchSequenceError::MissingOrOutOfOrder {
                expected: expected_id,
                index,
            })?;
        if step.id != expected_id {
            return Err(ReleaseLaunchSequenceError::MissingOrOutOfOrder {
                expected: expected_id,
                index,
            });
        }
        for (field, value) in [("id", step.id), ("command", step.command)] {
            if value.trim().is_empty() {
                return Err(ReleaseLaunchSequenceError::EmptyMetadata {
                    id: step.id.to_owned(),
                    field,
                });
            }
        }
        if !step.green {
            return Err(ReleaseLaunchSequenceError::StepNotGreen {
                id: step.id.to_owned(),
            });
        }
        if !step.command.contains(required_fragment) {
            return Err(ReleaseLaunchSequenceError::InvalidCommand {
                id: step.id.to_owned(),
                command: step.command.to_owned(),
                required_fragment,
            });
        }
    }

    Ok(ReleaseLaunchSequenceProof {
        step_count: REQUIRED_STEPS.len(),
    })
}

/// Validate committed release tag-plan evidence for final launch.
pub fn validate_release_tag_plan_artifact(
    artifact: &str,
) -> Result<ReleaseTagPlanProof, ReleaseLaunchSequenceError> {
    for (evidence, needle) in [
        ("Vyre RC tag", "\"vyre_rc_tag\""),
        ("dataflow consumer RC tag", "\"dataflow_consumer_rc_tag\""),
        ("combined RC tag", "\"combined_release_train_rc_tag\""),
        ("Vyre release tag", "\"vyre_tag\""),
        ("dataflow consumer release tag", "\"dataflow_consumer_tag\""),
        ("combined release tag", "\"combined_release_train_tag\""),
        ("tag creation order", "\"tag_creation_order\""),
        ("completion audit gate", "release-completion-audit"),
        ("release gate command", "\"release_gate_command\""),
        ("branch protection gate", "apply-branch-protection.sh"),
        ("final launch order", "\"final_launch_order\""),
        ("Vyre cargo publish", "cargo publish -p vyre"),
        (
            "dataflow consumer cargo publish",
            "\"dataflow_consumer_publish_command\"",
        ),
        (
            "public repository action",
            "\"repository_visibility_action\": \"public\"",
        ),
        ("release branch push", "git push origin release"),
        ("release tag push", "git push --tags"),
        (
            "zero version blockers",
            "\"version_matrix_blocker_count\": 0",
        ),
    ] {
        if !artifact.contains(needle) {
            return Err(ReleaseLaunchSequenceError::TagPlanMissingEvidence { evidence });
        }
    }
    require_artifact_contains_any(
        artifact,
        "empty blocker list",
        &["\"blockers\": []", "\"blockers\":[]"],
    )?;

    Ok(ReleaseTagPlanProof { tag_count: 6 })
}

/// Validate the final launch receipt artifact after publish/public/push execution.
pub fn validate_release_launch_receipts(
    artifact: &str,
) -> Result<ReleaseLaunchReceiptProof, ReleaseLaunchSequenceError> {
    for (evidence, needle) in [
        ("receipt schema", "\"schema_version\": 1"),
        (
            "active plan path",
            "\"plan_path\": \"release/plans/paradigm-shift-100-concrete.md\"",
        ),
        ("launch receipts object", "\"launch_receipts\""),
        ("cargo publish receipts", "\"cargo_publish_receipts\""),
        ("Vyre publish receipt", "\"crate\": \"vyre\""),
        (
            "dataflow consumer publish receipt",
            "\"crate_role\": \"dataflow-consumer\"",
        ),
        (
            "repository visibility receipt",
            "\"repository_visibility_receipt\"",
        ),
        ("public repository state", "\"visibility\": \"public\""),
        (
            "release branch push receipt",
            "\"release_branch_push_receipt\"",
        ),
        ("release branch push command", "git push origin release"),
        ("tag push receipt", "\"tag_push_receipt\""),
        ("tag push command", "git push --tags"),
        ("executed receipt status", "\"status\": \"executed\""),
        ("zero receipt blockers", "\"blockers\": []"),
    ] {
        if !artifact.contains(needle) {
            return Err(ReleaseLaunchSequenceError::ReceiptMissingEvidence { evidence });
        }
    }

    Ok(ReleaseLaunchReceiptProof { receipt_count: 5 })
}

fn require_artifact_contains_any(
    artifact: &str,
    evidence: &'static str,
    needles: &[&str],
) -> Result<(), ReleaseLaunchSequenceError> {
    if needles.iter().any(|needle| artifact.contains(needle)) {
        Ok(())
    } else {
        Err(ReleaseLaunchSequenceError::TagPlanMissingEvidence { evidence })
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn launch_sequence_accepts_required_order() {
        let proof = validate_release_launch_sequence(&steps())
            .expect("Fix: valid launch sequence should pass");

        assert_eq!(proof.step_count, 5);
    }

    #[test]
    fn launch_sequence_rejects_out_of_order_publish() {
        let mut steps = steps();
        steps.swap(0, 1);

        assert_eq!(
            validate_release_launch_sequence(&steps).expect_err("out-of-order launch should fail"),
            ReleaseLaunchSequenceError::MissingOrOutOfOrder {
                expected: "release-checklist-green",
                index: 0,
            }
        );
    }

    #[test]
    fn launch_sequence_rejects_unverified_or_wrong_commands() {
        let mut not_green = steps();
        not_green[1].green = false;
        assert_eq!(
            validate_release_launch_sequence(&not_green)
                .expect_err("not-green publish should fail"),
            ReleaseLaunchSequenceError::StepNotGreen {
                id: "cargo-publish".to_owned(),
            }
        );

        let mut wrong = steps();
        wrong[1].command = "cargo package";
        assert_eq!(
            validate_release_launch_sequence(&wrong)
                .expect_err("wrong publish command should fail"),
            ReleaseLaunchSequenceError::InvalidCommand {
                id: "cargo-publish".to_owned(),
                command: "cargo package".to_owned(),
                required_fragment: "cargo publish",
            }
        );
    }

    #[test]
    fn launch_sequence_accepts_committed_release_tag_plan() {
        let proof = validate_release_tag_plan_artifact(include_str!(
            "../../../../release/evidence/version/release-tag-plan.json"
        ))
        .expect("Fix: committed release tag plan should contain required launch gates");

        assert_eq!(proof.tag_count, 6);
    }

    #[test]
    fn launch_sequence_rejects_tag_plan_without_release_gate() {
        let err = validate_release_tag_plan_artifact(
            r#"{"vyre_rc_tag":"vyre-v0.4.1-rc.1","dataflow_consumer_rc_tag":"dataflow-consumer-v0.1.0-rc.1","combined_release_train_rc_tag":"x","vyre_tag":"vyre-v0.4.1","dataflow_consumer_tag":"dataflow-consumer-v0.1.0","combined_release_train_tag":"x","tag_creation_order":[],"dataflow_consumer_publish_command":"cargo publish -p dataflow-consumer","final_launch_order":["cargo publish -p vyre"],"repository_visibility_action":"public","required_gate_before_tag":"release-completion-audit && apply-branch-protection.sh","version_matrix_blocker_count":0,"blockers":[]}"#,
        )
        .expect_err("tag plan without release gate should fail");

        assert_eq!(
            err,
            ReleaseLaunchSequenceError::TagPlanMissingEvidence {
                evidence: "release gate command",
            }
        );
    }

    #[test]
    fn launch_receipts_accept_executed_final_launch_artifact() {
        let proof = validate_release_launch_receipts(
            r#"{
              "schema_version": 1,
              "plan_path": "release/plans/paradigm-shift-100-concrete.md",
              "launch_receipts": {
                "cargo_publish_receipts": [
                  {"crate": "vyre", "command": "cargo publish -p vyre", "status": "executed"},
                  {"crate": "dataflow-consumer", "crate_role": "dataflow-consumer", "command": "cargo publish -p dataflow-consumer", "status": "executed"}
                ],
                "repository_visibility_receipt": {"visibility": "public", "status": "executed"},
                "release_branch_push_receipt": {"command": "git push origin release", "status": "executed"},
                "tag_push_receipt": {"command": "git push --tags", "status": "executed"}
              },
              "blockers": []
            }"#,
        )
        .expect("Fix: executed launch receipts should pass");

        assert_eq!(proof.receipt_count, 5);
    }

    #[test]
    fn launch_receipts_reject_planned_launch_without_execution() {
        let err = validate_release_launch_receipts(
            r#"{
              "schema_version": 1,
              "plan_path": "release/plans/paradigm-shift-100-concrete.md",
              "final_launch_order": ["cargo publish -p vyre", "cargo publish -p dataflow-consumer", "git push origin release", "git push --tags"],
              "blockers": []
            }"#,
        )
        .expect_err("planned final launch order is not an execution receipt");

        assert_eq!(
            err,
            ReleaseLaunchSequenceError::ReceiptMissingEvidence {
                evidence: "launch receipts object",
            }
        );
    }

    fn steps() -> Vec<ReleaseLaunchStep<'static>> {
        vec![
            ReleaseLaunchStep {
                id: "release-checklist-green",
                command: "./cargo_full test -j1 --workspace",
                green: true,
            },
            ReleaseLaunchStep {
                id: "cargo-publish",
                command: "cargo publish -p vyre",
                green: true,
            },
            ReleaseLaunchStep {
                id: "repos-public",
                command: "set GitHub repositories public",
                green: true,
            },
            ReleaseLaunchStep {
                id: "git-push-release",
                command: "git push origin release",
                green: true,
            },
            ReleaseLaunchStep {
                id: "git-push-tags",
                command: "git push --tags",
                green: true,
            },
        ]
    }
}