- 1
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 2
- 3
use vak_flow::{ParseError, parse_flow}; - 4
- 5
#[test] - 6
fn valid_flow_parses_with_layers() { - 7
let toml = r#" - 8
[flow] - 9
name = "demo" - 10
- 11
[[nodes]] - 12
id = "a" - 13
type = "bash" - 14
command = "echo a" - 15
- 16
[[nodes]] - 17
id = "b" - 18
type = "agent" - 19
prompt = "use {{a}}" - 20
- 21
[[nodes]] - 22
id = "c" - 23
type = "merge" - 24
deps = ["b"] - 25
"#; - 26
let flow = parse_flow(toml).unwrap(); - 27
assert_eq!(flow.nodes.len(), 3); - 28
let layers = vak_flow::parse::layers(&flow).unwrap(); - 29
assert_eq!(layers.len(), 3); - 30
assert_eq!(layers[0], vec!["a"]); - 31
assert_eq!(layers[1], vec!["b"]); - 32
assert_eq!(layers[2], vec!["c"]); - 33
} - 34
- 35
#[test] - 36
fn independent_nodes_share_a_layer() { - 37
let toml = r#" - 38
[flow] - 39
name = "fan" - 40
- 41
[[nodes]] - 42
id = "x" - 43
type = "bash" - 44
command = "echo x" - 45
- 46
[[nodes]] - 47
id = "y" - 48
type = "bash" - 49
command = "echo y" - 50
- 51
[[nodes]] - 52
id = "z" - 53
type = "merge" - 54
deps = ["x", "y"] - 55
"#; - 56
let layers = vak_flow::parse::layers(&parse_flow(toml).unwrap()).unwrap(); - 57
assert_eq!(layers.len(), 2); - 58
assert!(layers[0].contains(&"x".to_string())); - 59
assert!(layers[0].contains(&"y".to_string())); - 60
} - 61
- 62
#[test] - 63
fn cycle_is_rejected() { - 64
let toml = r#" - 65
[flow] - 66
name = "cycle" - 67
- 68
[[nodes]] - 69
id = "a" - 70
type = "bash" - 71
command = "echo a" - 72
deps = ["b"] - 73
- 74
[[nodes]] - 75
id = "b" - 76
type = "bash" - 77
command = "echo b" - 78
deps = ["a"] - 79
"#; - 80
match parse_flow(toml) { - 81
Err(ParseError::Cycle(stuck)) => assert!(stuck.contains("a") && stuck.contains("b")), - 82
other => panic!("expected cycle, got {other:?}"), - 83
} - 84
} - 85
- 86
#[test] - 87
fn unknown_dep_and_self_dep_rejected() { - 88
let toml = r#" - 89
[flow] - 90
name = "bad" - 91
- 92
[[nodes]] - 93
id = "a" - 94
type = "bash" - 95
command = "echo a" - 96
deps = ["ghost"] - 97
"#; - 98
assert!(matches!( - 99
parse_flow(toml), - 100
Err(ParseError::UnknownDep(node, dep)) if node == "a" && dep == "ghost" - 101
)); - 102
- 103
let toml = r#" - 104
[flow] - 105
name = "bad" - 106
- 107
[[nodes]] - 108
id = "a" - 109
type = "bash" - 110
command = "echo a" - 111
deps = ["a"] - 112
"#; - 113
assert!(matches!(parse_flow(toml), Err(ParseError::SelfDep(_)))); - 114
} - 115
- 116
#[test] - 117
fn unknown_type_and_missing_fields_rejected() { - 118
let toml = r#" - 119
[flow] - 120
name = "bad" - 121
- 122
[[nodes]] - 123
id = "a" - 124
type = "quantum" - 125
command = "echo a" - 126
"#; - 127
assert!(matches!( - 128
parse_flow(toml), - 129
Err(ParseError::UnknownType(_, t)) if t == "quantum" - 130
)); - 131
- 132
let toml = r#" - 133
[flow] - 134
name = "bad" - 135
- 136
[[nodes]] - 137
id = "a" - 138
type = "agent" - 139
"#; - 140
assert!(matches!( - 141
parse_flow(toml), - 142
Err(ParseError::MissingField(id, _, field)) if id == "a" && field == "prompt" - 143
)); - 144
} - 145
- 146
#[test] - 147
fn duplicate_ids_rejected() { - 148
let toml = r#" - 149
[flow] - 150
name = "dup" - 151
- 152
[[nodes]] - 153
id = "a" - 154
type = "bash" - 155
command = "echo 1" - 156
- 157
[[nodes]] - 158
id = "a" - 159
type = "bash" - 160
command = "echo 2" - 161
"#; - 162
assert!(matches!(parse_flow(toml), Err(ParseError::Duplicate(d)) if d == "a")); - 163
} - 164
- 165
#[test] - 166
fn accept_done_contract_parses_and_survives_validation() { - 167
let toml = r#" - 168
[flow] - 169
name = "accept-flow" - 170
- 171
[[nodes]] - 172
id = "build" - 173
type = "bash" - 174
command = "cargo build" - 175
accept = ["verify: test -f target", "exit 0"] - 176
- 177
[[nodes]] - 178
id = "report" - 179
type = "merge" - 180
deps = ["build"] - 181
"#; - 182
let flow = vak_flow::parse_flow(toml).expect("parse"); - 183
let node = flow.nodes.iter().find(|n| n.id == "build").unwrap(); - 184
assert_eq!(node.accept.len(), 2); - 185
assert_eq!(node.accept[0], "verify: test -f target"); - 186
} - 187
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.