vyre-self-substrate 0.6.3

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
420
421
//! Release gap-finding validation.

use std::collections::BTreeSet;

/// Status of an intentional release gap finding.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReleaseGapStatus {
    /// Gap is known and intentionally visible in beta/release evidence.
    Open,
    /// Gap is actively being fixed.
    InProgress,
    /// Gap is fixed and retained as regression evidence.
    Fixed,
}

/// One tracked release gap.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseGapFinding<'a> {
    /// Stable gap id.
    pub id: &'a str,
    /// Owning subsystem.
    pub owner: &'a str,
    /// Feature or invariant covered by the gap.
    pub feature: &'a str,
    /// Exact reproduction command.
    pub reproduction_command: &'a str,
    /// Test or artifact path that exposes the gap.
    pub evidence_path: &'a str,
    /// Current status.
    pub status: ReleaseGapStatus,
}

/// Gap-finding validation proof.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseGapFindingProof {
    /// Number of tracked gaps.
    pub gap_count: usize,
    /// Number of open gaps.
    pub open_count: usize,
    /// Number of fixed regression gaps.
    pub fixed_count: usize,
}

/// Committed gap-suite artifact proof.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReleaseGapSuiteArtifactProof {
    /// Total gap-suite file count.
    pub file_count: u64,
    /// Vyre gap-suite file count.
    pub vyre_file_count: u64,
    /// Dataflow consumer gap-suite file count.
    pub dataflow_consumer_file_count: u64,
    /// Vyrec gap-suite file count.
    pub vyrec_file_count: u64,
}

/// Gap-finding validation errors.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReleaseGapFindingError {
    /// No gap findings were supplied.
    EmptyFindings,
    /// Gap id is duplicated.
    DuplicateId {
        /// Duplicate id.
        id: String,
    },
    /// Required metadata is empty.
    EmptyMetadata {
        /// Gap id.
        id: String,
        /// Field name.
        field: &'static str,
    },
    /// Reproduction command does not use cargo_full.
    ReproductionDoesNotUseCargoFull {
        /// Gap id.
        id: String,
        /// Reproduction command.
        command: String,
    },
    /// Gap evidence does not include an open or in-progress finding.
    NoActiveGap,
    /// Committed gap-suite artifact is missing required evidence.
    ArtifactMissingEvidence {
        /// Missing evidence field.
        evidence: &'static str,
    },
    /// Committed gap-suite artifact has a missing or malformed numeric field.
    ArtifactMissingNumber {
        /// Missing numeric field.
        field: &'static str,
    },
    /// Committed gap-suite artifact does not meet a release threshold.
    ArtifactThresholdMiss {
        /// Field name.
        field: &'static str,
        /// Observed value.
        observed: u64,
        /// Required value.
        required: u64,
    },
}

impl std::fmt::Display for ReleaseGapFindingError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::EmptyFindings => write!(
                f,
                "release gap findings are empty. Fix: track every missing clang/dataflow parity item as an explicit gap finding."
            ),
            Self::DuplicateId { id } => write!(
                f,
                "release gap finding `{id}` is duplicated. Fix: keep one tracked owner per gap."
            ),
            Self::EmptyMetadata { id, field } => write!(
                f,
                "release gap finding `{id}` has empty {field}. Fix: every gap needs owner, feature, reproduction command, evidence path, and status."
            ),
            Self::ReproductionDoesNotUseCargoFull { id, command } => write!(
                f,
                "release gap finding `{id}` uses reproduction command `{command}` instead of ./cargo_full. Fix: make the gap reproducible through the release test harness."
            ),
            Self::NoActiveGap => write!(
                f,
                "release gap findings contain no open or in-progress gaps. Fix: if parity is complete, convert this gate into fixed regression evidence after completion audit."
            ),
            Self::ArtifactMissingEvidence { evidence } => write!(
                f,
                "release gap suite artifact is missing {evidence}. Fix: commit reproducible gap-suite evidence rather than synthetic gap inventory."
            ),
            Self::ArtifactMissingNumber { field } => write!(
                f,
                "release gap suite artifact has no numeric {field}. Fix: record the exact gap-suite counter."
            ),
            Self::ArtifactThresholdMiss {
                field,
                observed,
                required,
            } => write!(
                f,
                "release gap suite artifact {field}={observed} missed required {required}. Fix: add real gap tests across Vyre, dataflow consumers, and Vyrec or close the approved beta gap explicitly."
            ),
        }
    }
}

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

/// Validate release gap findings.
pub fn validate_release_gap_findings(
    findings: &[ReleaseGapFinding<'_>],
) -> Result<ReleaseGapFindingProof, ReleaseGapFindingError> {
    if findings.is_empty() {
        return Err(ReleaseGapFindingError::EmptyFindings);
    }

    let mut ids = BTreeSet::new();
    let mut open_count = 0_usize;
    let mut fixed_count = 0_usize;
    for finding in findings {
        validate_metadata(finding)?;
        if !ids.insert(finding.id) {
            return Err(ReleaseGapFindingError::DuplicateId {
                id: finding.id.to_owned(),
            });
        }
        if !finding
            .reproduction_command
            .trim_start()
            .starts_with("./cargo_full ")
        {
            return Err(ReleaseGapFindingError::ReproductionDoesNotUseCargoFull {
                id: finding.id.to_owned(),
                command: finding.reproduction_command.to_owned(),
            });
        }
        match finding.status {
            ReleaseGapStatus::Open | ReleaseGapStatus::InProgress => open_count += 1,
            ReleaseGapStatus::Fixed => fixed_count += 1,
        }
    }
    if open_count == 0 {
        return Err(ReleaseGapFindingError::NoActiveGap);
    }

    Ok(ReleaseGapFindingProof {
        gap_count: findings.len(),
        open_count,
        fixed_count,
    })
}

/// Validate the committed release gap-suite artifact.
pub fn validate_release_gap_suite_artifact(
    artifact: &str,
) -> Result<ReleaseGapSuiteArtifactProof, ReleaseGapFindingError> {
    artifact_contains(artifact, "gap suite marker", "\"suite\": \"gap\"")?;
    artifact_contains(artifact, "zero blockers", "\"blockers\": []")?;
    artifact_contains(artifact, "gap layer", "\"gap\"")?;
    artifact_contains(artifact, "Vyre test paths", "/matching/vyre/")?;
    if artifact.contains("\"oversized\": true") {
        return Err(ReleaseGapFindingError::ArtifactMissingEvidence {
            evidence: "no oversized gap tests",
        });
    }
    if artifact.contains("\"god_test_candidate\": true") {
        return Err(ReleaseGapFindingError::ArtifactMissingEvidence {
            evidence: "no god-test gap candidates",
        });
    }

    let file_count = artifact_number_field(artifact, "file_count")?;
    let vyre_file_count = artifact_number_field(artifact, "vyre_file_count")?;
    let dataflow_consumer_file_count =
        artifact_number_field(artifact, "dataflow_consumer_file_count")?;
    let vyrec_file_count = artifact_number_field(artifact, "vyrec_file_count")?;
    let test_entrypoints = artifact.matches("\"has_test_entrypoint\": true").count() as u64;
    let gap_layer_mentions = artifact.matches("\"gap\"").count() as u64;

    artifact_at_least("file_count", file_count, 20)?;
    artifact_at_least("vyre_file_count", vyre_file_count, 20)?;
    artifact_at_least(
        "dataflow_consumer_file_count",
        dataflow_consumer_file_count,
        1,
    )?;
    artifact_at_least("vyrec_file_count", vyrec_file_count, 1)?;
    artifact_at_least("has_test_entrypoint=true", test_entrypoints, 10)?;
    artifact_at_least("gap layer mentions", gap_layer_mentions, file_count)?;

    Ok(ReleaseGapSuiteArtifactProof {
        file_count,
        vyre_file_count,
        dataflow_consumer_file_count,
        vyrec_file_count,
    })
}

fn validate_metadata(finding: &ReleaseGapFinding<'_>) -> Result<(), ReleaseGapFindingError> {
    for (field, value) in [
        ("id", finding.id),
        ("owner", finding.owner),
        ("feature", finding.feature),
        ("reproduction_command", finding.reproduction_command),
        ("evidence_path", finding.evidence_path),
    ] {
        if value.trim().is_empty() {
            return Err(ReleaseGapFindingError::EmptyMetadata {
                id: finding.id.to_owned(),
                field,
            });
        }
    }
    Ok(())
}

fn artifact_contains(
    artifact: &str,
    evidence: &'static str,
    needle: &str,
) -> Result<(), ReleaseGapFindingError> {
    if artifact.contains(needle) {
        Ok(())
    } else {
        Err(ReleaseGapFindingError::ArtifactMissingEvidence { evidence })
    }
}

fn artifact_at_least(
    field: &'static str,
    observed: u64,
    required: u64,
) -> Result<(), ReleaseGapFindingError> {
    if observed >= required {
        Ok(())
    } else {
        Err(ReleaseGapFindingError::ArtifactThresholdMiss {
            field,
            observed,
            required,
        })
    }
}

fn artifact_number_field(
    artifact: &str,
    field: &'static str,
) -> Result<u64, ReleaseGapFindingError> {
    let key = format!("\"{field}\"");
    let start = artifact
        .find(&key)
        .ok_or(ReleaseGapFindingError::ArtifactMissingNumber { field })?;
    let after_key = &artifact[start + key.len()..];
    let colon = after_key
        .find(':')
        .ok_or(ReleaseGapFindingError::ArtifactMissingNumber { field })?;
    let after_colon = after_key[colon + 1..].trim_start();
    let digits = after_colon
        .chars()
        .take_while(|ch| ch.is_ascii_digit())
        .collect::<String>();
    if digits.is_empty() {
        return Err(ReleaseGapFindingError::ArtifactMissingNumber { field });
    }
    digits
        .parse::<u64>()
        .map_err(|_| ReleaseGapFindingError::ArtifactMissingNumber { field })
}

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

    #[test]
    fn gap_findings_accept_active_cargo_full_reproductions() {
        let proof = validate_release_gap_findings(&[
            finding("vyrec-semantic-gap", ReleaseGapStatus::Open),
            finding("vyrec-parser-regression", ReleaseGapStatus::Fixed),
        ])
        .expect("Fix: valid gap findings should pass");

        assert_eq!(proof.gap_count, 2);
        assert_eq!(proof.open_count, 1);
        assert_eq!(proof.fixed_count, 1);
    }

    #[test]
    fn gap_findings_reject_raw_cargo_reproduction() {
        let mut bad = finding("bad", ReleaseGapStatus::Open);
        bad.reproduction_command = "cargo test";

        assert_eq!(
            validate_release_gap_findings(&[bad]).expect_err("raw cargo should fail"),
            ReleaseGapFindingError::ReproductionDoesNotUseCargoFull {
                id: "bad".to_owned(),
                command: "cargo test".to_owned(),
            }
        );
    }

    #[test]
    fn gap_findings_require_active_gap_until_completion_audit() {
        assert_eq!(
            validate_release_gap_findings(&[finding("fixed", ReleaseGapStatus::Fixed)])
                .expect_err("no active gap should fail until completion audit"),
            ReleaseGapFindingError::NoActiveGap
        );
    }

    #[test]
    fn gap_findings_accept_committed_gap_suite_artifact() {
        let proof = validate_release_gap_suite_artifact(include_str!(
            "../../../../release/evidence/tests/gap-suite-platform.json"
        ))
        .expect("Fix: committed gap suite artifact should pass");

        assert!(proof.file_count >= 20);
        assert!(proof.vyre_file_count >= 20);
        assert!(proof.dataflow_consumer_file_count >= 1);
        assert!(proof.vyrec_file_count >= 1);
    }

    #[test]
    fn gap_findings_reject_unowned_or_blocked_gap_suite_artifact() {
        let artifact = r#"{
          "schema_version": 1,
          "suite": "gap",
          "file_count": 20,
          "vyre_file_count": 20,
          "dataflow_consumer_file_count": 0,
          "vyrec_file_count": 1,
          "blockers": ["missing-dataflow-consumer-gap"],
          "files": []
        }"#;

        assert_eq!(
            validate_release_gap_suite_artifact(artifact)
                .expect_err("blocked gap suite should fail"),
            ReleaseGapFindingError::ArtifactMissingEvidence {
                evidence: "zero blockers",
            }
        );
    }

    #[test]
    fn gap_findings_reject_oversized_gap_suite_artifact() {
        let artifact = r#"{
          "schema_version": 1,
          "suite": "gap",
          "file_count": 20,
          "vyre_file_count": 20,
          "dataflow_consumer_file_count": 1,
          "vyrec_file_count": 1,
          "blockers": [],
          "path": "/matching/vyre/test.rs",
          "layers": ["gap"],
          "has_test_entrypoint": true,
          "oversized": true,
          "god_test_candidate": false
        }"#;

        assert_eq!(
            validate_release_gap_suite_artifact(artifact)
                .expect_err("oversized gap suite should fail"),
            ReleaseGapFindingError::ArtifactMissingEvidence {
                evidence: "no oversized gap tests",
            }
        );
    }

    fn finding(id: &'static str, status: ReleaseGapStatus) -> ReleaseGapFinding<'static> {
        ReleaseGapFinding {
            id,
            owner: "vyrec",
            feature: "clang semantic parity",
            reproduction_command: "./cargo_full test -j1 -p vyrec",
            evidence_path: "release/gaps/vyrec-clang-parity.md",
            status,
        }
    }
}