返回 CodeWhale
builtin_tests.rs
根目录 / crates / plugins / src / builtin_tests.rs
1 use super::*;
2 use std::fs;
3
4 #[test]
5 fn exclusive_publication_preserves_even_an_empty_destination() {
6 let temp = tempfile::tempdir().unwrap();
7 let stage = temp.path().join("stage");
8 let destination = temp.path().join("destination");
9 fs::create_dir(&stage).unwrap();
10 fs::write(stage.join("complete"), b"complete").unwrap();
11 fs::create_dir(&destination).unwrap();
12 assert_eq!(
13 publish_snapshot(&stage, &destination).unwrap_err().kind(),
14 io::ErrorKind::AlreadyExists
15 );
16 assert_eq!(fs::read_dir(destination).unwrap().count(), 0);
17 assert!(stage.join("complete").is_file());
18 }
19
20 #[test]
21 fn bundled_agent_teams_materializes_trusted_and_enabled_by_default_with_off_switch() {
22 let temp = tempfile::tempdir().unwrap();
23 let home = temp.path().join("home");
24 let workspace = temp.path().join("workspace");
25 fs::create_dir_all(&home).unwrap();
26 fs::create_dir_all(&workspace).unwrap();
27
28 let snapshot = materialize_at_home(&home)
29 .unwrap()
30 .expect("bundled agent-teams snapshot");
31 let bundle_root = snapshot.join(AGENT_TEAMS_BUNDLE_NAME);
32 let license = fs::read_to_string(bundle_root.join("LICENSE")).unwrap();
33 assert!(license.contains("MIT License"));
34 assert!(license.contains("程序员阿江"));
35 assert!(bundle_root.join("plugin.json").is_file());
36 assert!(bundle_root.join("lib/index.js").is_file());
37
38 let discovery = crate::discovery::DiscoveryConfig {
39 workspace: workspace.clone(),
40 user_plugins_dir: home.join("plugins"),
41 workspace_plugins_dir: workspace.join(".codewhale/plugins"),
42 builtin_plugin_dirs: vec![snapshot],
43 state_path: home.join("plugins/state.json"),
44 };
45 let mut registry = crate::discovery::discover_with_config(&discovery);
46 let plugin = registry.get(AGENT_TEAMS_BUNDLE_NAME).expect("agent-teams");
47 assert_eq!(plugin.scope, PluginScope::Builtin);
48 assert_eq!(
49 plugin.trust_status,
50 crate::types::PluginTrustStatus::Trusted
51 );
52 assert!(plugin.enabled);
53 assert!(plugin.staged_root.is_some());
54 assert!(plugin.inventory.native > 0);
55
56 registry.disable(AGENT_TEAMS_BUNDLE_NAME).unwrap();
57 let disabled = registry.get(AGENT_TEAMS_BUNDLE_NAME).expect("agent-teams");
58 assert!(!disabled.enabled);
59 assert_eq!(
60 disabled.trust_status,
61 crate::types::PluginTrustStatus::Trusted
62 );
63
64 let reloaded = crate::discovery::discover_with_config(&discovery);
65 let reloaded_plugin = reloaded.get(AGENT_TEAMS_BUNDLE_NAME).expect("agent-teams");
66 assert!(!reloaded_plugin.enabled);
67 assert_eq!(
68 reloaded_plugin.trust_status,
69 crate::types::PluginTrustStatus::Trusted
70 );
71 }
72
72 lines RUST