Skip to main content

kcode_k1_daemon_lib_testkit/
lib.rs

1#![forbid(unsafe_code)]
2
3const REQUIRED_LINES: &[&str] = &[
4    "kcode-k1-access = \"0.6.1\"",
5    "kcode-k1-access-full-audio = \"0.9.1\"",
6    "kcode-k1-access-launch-nodes = \"0.2.0\"",
7    "kcode-k1-access-persons = \"0.3.0\"",
8    "kcode-k1-access-profiles = \"0.6.2\"",
9    "kcode-k1-audio-classification = \"0.5.9\"",
10    "kcode-k1-authority-filters = \"0.2.0\"",
11    "kcode-k1-chat-service = \"0.8.0\"",
12    "kcode-k1-daemon-provider-config = \"0.1.5\"",
13    "kcode-k1-full-audio = \"0.3.7\"",
14    "kcode-k1-http-access-context = \"0.2.0\"",
15    "kcode-k1-http-access-profile-presentation = \"0.1.0\"",
16    "kcode-k1-http-audio = \"0.3.0\"",
17    "kcode-k1-http-audio-artifacts = \"0.4.0\"",
18    "kcode-k1-http-chat = \"0.6.0\"",
19    "kcode-k1-http-launch-nodes = \"0.3.0\"",
20    "kcode-k1-http-people = \"0.9.0\"",
21    "kcode-k1-http-persons = \"0.3.0\"",
22    "kcode-k1-launch-nodes = \"0.3.0\"",
23    "kcode-k1-peering = \"0.3.1\"",
24    "kcode-k1-txn-ordering = \"0.5.1\"",
25];
26
27const OBSOLETE_LINES: &[&str] = &[
28    "kcode-k1-chat-service = \"0.3.0\"",
29    "kcode-k1-chat-service = \"0.6.0\"",
30    "kcode-k1-chat-service = \"0.7.0\"",
31    "kcode-k1-chat-service = \"0.9.0\"",
32    "kcode-k1-daemon-provider-config = \"0.1.4\"",
33    "kcode-k1-http-chat = \"0.2.0\"",
34    "kcode-k1-http-chat = \"0.5.0\"",
35    "kcode-k1-http-launch-nodes = \"0.2.0\"",
36    "kcode-k1-http-audio-artifacts = \"0.3.0\"",
37];
38
39pub fn verify_manifest(manifest: &str) {
40    for required in REQUIRED_LINES {
41        assert!(
42            manifest.lines().any(|line| line == *required),
43            "missing required manifest line: {required}"
44        );
45    }
46    for obsolete in OBSOLETE_LINES {
47        assert!(
48            !manifest.lines().any(|line| line == *obsolete),
49            "obsolete manifest line: {obsolete}"
50        );
51    }
52    assert!(
53        !manifest.lines().any(|line| line.contains(" = \"=")),
54        "manifest contains an exact internal pin"
55    );
56}
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    fn good_manifest() -> String {
63        REQUIRED_LINES.join("\n")
64    }
65
66    #[test]
67    fn accepts_current_manifest() {
68        verify_manifest(&good_manifest());
69    }
70
71    #[test]
72    #[should_panic(expected = "missing required manifest line")]
73    fn rejects_missing_required_line() {
74        verify_manifest(&good_manifest().replacen(
75            "kcode-k1-http-audio-artifacts = \"0.4.0\"\n",
76            "",
77            1,
78        ));
79    }
80
81    #[test]
82    #[should_panic(expected = "obsolete manifest line")]
83    fn rejects_obsolete_line() {
84        verify_manifest(&format!(
85            "{}\nkcode-k1-http-chat = \"0.5.0\"",
86            good_manifest()
87        ));
88    }
89
90    #[test]
91    #[should_panic(expected = "exact internal pin")]
92    fn rejects_exact_internal_pin() {
93        verify_manifest(&format!(
94            "{}\nkcode-k1-peering = \"=0.3.1\"",
95            good_manifest()
96        ));
97    }
98}