File size: 3,347 Bytes
17f328f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use std::collections::BTreeMap;

use codex_config::AppRequirementToml;
use codex_config::AppsRequirementsToml;
use codex_config::ConfigLayerStack;
use codex_config::ConfigRequirements;
use codex_config::ConfigRequirementsToml;
use pretty_assertions::assert_eq;

use super::*;

#[test]
fn projection_deduplicates_apps_and_ignores_non_runtime_tools() {
    let config = ConfigLayerStack::new(
        Vec::new(),
        ConfigRequirements::default(),
        ConfigRequirementsToml::default(),
    )
    .expect("config layer stack");
    let apps = installed_connector_runtime(
        &config,
        [
            tool(Some(" drive "), /*connector_name*/ None, "files/list"),
            tool(Some("drive"), Some(" Drive "), "files/get"),
            ConnectorRuntimeTool {
                synthetic: true,
                ..tool(Some("synthetic"), Some("Synthetic"), "link")
            },
            tool(Some(" "), Some("Empty"), "empty"),
            tool(/*connector_id*/ None, Some("Missing"), "missing"),
        ],
    );

    assert_eq!(
        apps,
        vec![InstalledConnectorRuntime {
            id: "drive".to_string(),
            runtime_name: Some("Drive".to_string()),
            enabled: true,
            callable: true,
        }]
    );
}

#[test]
fn projection_applies_managed_app_policy_and_model_visibility() {
    let requirements = ConfigRequirementsToml {
        apps: Some(AppsRequirementsToml {
            apps: BTreeMap::from([(
                "disabled".to_string(),
                AppRequirementToml {
                    enabled: Some(false),
                    tools: None,
                },
            )]),
        }),
        ..Default::default()
    };
    let config = ConfigLayerStack::new(Vec::new(), ConfigRequirements::default(), requirements)
        .expect("config layer stack");
    let apps = installed_connector_runtime(
        &config,
        [
            tool(Some("disabled"), Some("Disabled"), "disabled/tool"),
            ConnectorRuntimeTool {
                model_visible: false,
                ..tool(Some("hidden"), Some("Hidden"), "hidden/tool")
            },
            tool(Some("callable"), Some("Callable"), "callable/tool"),
        ],
    );

    assert_eq!(
        apps,
        vec![
            InstalledConnectorRuntime {
                id: "callable".to_string(),
                runtime_name: Some("Callable".to_string()),
                enabled: true,
                callable: true,
            },
            InstalledConnectorRuntime {
                id: "disabled".to_string(),
                runtime_name: Some("Disabled".to_string()),
                enabled: false,
                callable: false,
            },
            InstalledConnectorRuntime {
                id: "hidden".to_string(),
                runtime_name: Some("Hidden".to_string()),
                enabled: true,
                callable: false,
            },
        ]
    );
}

fn tool<'a>(
    connector_id: Option<&'a str>,
    connector_name: Option<&'a str>,
    tool_name: &'a str,
) -> ConnectorRuntimeTool<'a> {
    ConnectorRuntimeTool {
        connector_id,
        connector_name,
        tool_name,
        tool_title: None,
        destructive_hint: None,
        open_world_hint: None,
        synthetic: false,
        model_visible: true,
    }
}