Skip to main content

concinnity_dev/command/
check.rs

1// src/cli/check.rs: discovery wrapper around crate::check_at_path
2//
3// `cn test` accepts an optional --file path. When the path is missing or
4// doesn't exist on disk, fall back to discovery via find_world_jsonl.
5
6use crate::check_at_path;
7use concinnity_cook::authoring::world::find_world_jsonl;
8
9/// Validate a world and report its errors without building blobs.
10///
11/// `json_path` is used when it names an existing file; otherwise the world is
12/// discovered.
13pub fn check(json_path: &str) -> std::io::Result<()> {
14    let resolved;
15    let json_path = if !std::path::Path::new(json_path).exists() {
16        resolved = find_world_jsonl(None)?;
17        resolved.as_str()
18    } else {
19        json_path
20    };
21    check_at_path(json_path)
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    // An explicit, existing path is validated in place -- the discovery branch
29    // (and its process-global path anchors) is never touched.
30    #[test]
31    fn check_validates_an_explicit_existing_world() {
32        let dir = tempfile::tempdir().unwrap();
33        let path = dir.path().join("world.jsonl");
34        std::fs::write(
35            &path,
36            "{\"name\":\"phys\",\"type\":\"PhysicsConfig\",\"args\":{}}\n",
37        )
38        .unwrap();
39        check(path.to_str().unwrap()).unwrap();
40    }
41
42    #[test]
43    fn check_reports_an_invalid_explicit_world() {
44        let dir = tempfile::tempdir().unwrap();
45        let path = dir.path().join("world.jsonl");
46        std::fs::write(
47            &path,
48            "{\"name\":\"x\",\"type\":\"NotARealAssetType\",\"args\":{}}\n",
49        )
50        .unwrap();
51        assert!(check(path.to_str().unwrap()).is_err());
52    }
53}