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