- 1
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 2
- 3
use vak_tools::ResourceClaims; - 4
- 5
fn claims(paths: &[&str]) -> ResourceClaims { - 6
ResourceClaims { - 7
exclusive: false, - 8
read_only: false, - 9
paths: paths.iter().map(|s| s.to_string()).collect(), - 10
} - 11
} - 12
- 13
#[test] - 14
fn unclaimed_never_conflicts() { - 15
let a = ResourceClaims::default(); - 16
let b = claims(&["src/**"]); - 17
assert!(!a.conflicts(&b)); - 18
assert!(!b.conflicts(&a)); - 19
} - 20
- 21
#[test] - 22
fn read_only_never_conflicts() { - 23
let a = ResourceClaims { - 24
exclusive: false, - 25
read_only: true, - 26
paths: Vec::new(), - 27
}; - 28
let b = claims(&["src/**"]); - 29
assert!(!a.conflicts(&b)); - 30
assert!(!b.conflicts(&a)); - 31
} - 32
- 33
#[test] - 34
fn exclusive_conflicts_with_any_claimed() { - 35
let a = ResourceClaims { - 36
exclusive: true, - 37
read_only: false, - 38
paths: Vec::new(), - 39
}; - 40
let b = claims(&["docs/**"]); - 41
assert!(a.conflicts(&b)); - 42
assert!(b.conflicts(&a)); - 43
} - 44
- 45
#[test] - 46
fn overlapping_prefixes_conflict() { - 47
assert!(claims(&["src/**"]).conflicts(&claims(&["src/auth/**"]))); - 48
assert!(claims(&["src/auth/**"]).conflicts(&claims(&["src/**"]))); - 49
assert!(claims(&["src/auth/**"]).conflicts(&claims(&["src/auth/**"]))); - 50
} - 51
- 52
#[test] - 53
fn sibling_scopes_are_disjoint() { - 54
assert!(!claims(&["src/auth/**"]).conflicts(&claims(&["src/billing/**"]))); - 55
assert!(!claims(&["src/auth/**"]).conflicts(&claims(&["docs/**"]))); - 56
} - 57
- 58
#[test] - 59
fn normalization_handles_globs_and_slashes() { - 60
// "src/" vs "src/**" must be seen as the same scope - 61
assert!(claims(&["src/"]).conflicts(&claims(&["src/**"]))); - 62
assert!(claims(["src"].as_slice()).conflicts(&claims(&["src/*"]))); - 63
} - 64
- 65
#[test] - 66
fn builtin_tools_declare_claims() { - 67
use serde_json::json; - 68
use vak_tools::{ - 69
Tool, bash::BashTool, edit::EditTool, glob::GlobTool, grep::GrepTool, read::ReadTool, - 70
write::WriteTool, - 71
}; - 72
- 73
let path_args = json!({"path": "src/a.rs"}); - 74
let w = WriteTool.claims(&path_args); - 75
assert!(!w.is_unclaimed() && !w.read_only && w.paths == vec!["src/a.rs".to_string()]); - 76
let e = EditTool.claims(&path_args); - 77
assert!(!e.is_unclaimed() && !e.read_only); - 78
- 79
let b = BashTool.claims(&json!({"command": "ls"})); - 80
assert!(b.exclusive, "bash must serialize against everything"); - 81
- 82
for t in [&ReadTool as &dyn Tool, &GlobTool, &GrepTool] { - 83
let c = t.claims(&path_args); - 84
assert!(c.read_only, "{} must be read-only", t.name()); - 85
} - 86
- 87
// Two edits to the same file conflict; different files don't. - 88
assert!(w.conflicts(&e)); - 89
let other = WriteTool.claims(&json!({"path": "src/b.rs"})); - 90
assert!(!w.conflicts(&other)); - 91
} - 92
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.