File size: 4,577 Bytes
52a9af3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use super::*;
use codex_plugin::PluginId;
use pretty_assertions::assert_eq;

#[test]
fn recognizes_supported_artifact_markers() {
    for skill in ARTIFACT_SKILLS {
        for operation_kind in ["create", "edit"] {
            let attribution = attribution(skill.plugin_name, skill.script_path);
            assert_eq!(
                recognize_artifact_operation(
                    Some(&attribution),
                    &marker_command(
                        skill.script_path,
                        operation_kind,
                        "2",
                        skill.output_formats[0],
                    ),
                ),
                Some(ArtifactOperation {
                    plugin_name: skill.plugin_name,
                    script_path: skill.script_path,
                    artifact_type: skill.artifact_type,
                    operation_kind,
                    expected_output_count: 2,
                    output_format: skill.output_formats[0],
                })
            );
        }
    }
}

#[test]
fn rejects_untrusted_mismatched_or_invalid_markers() {
    let presentation = &ARTIFACT_SKILLS[0];
    let cases = [
        (
            None,
            marker_command(presentation.script_path, "create", "1", "pptx"),
        ),
        (
            Some(PluginCommandAttribution {
                plugin_id: PluginId::parse("documents@openai-primary-runtime").expect("plugin id"),
                normalized_relative_path: presentation.script_path.to_string(),
            }),
            marker_command(presentation.script_path, "create", "1", "pptx"),
        ),
        (
            Some(attribution(
                "presentations",
                "skills/presentations/container_tools/render_slides.mjs",
            )),
            marker_command(presentation.script_path, "create", "1", "pptx"),
        ),
        (
            Some(attribution(
                presentation.plugin_name,
                presentation.script_path,
            )),
            command_with_arguments(presentation.script_path, Vec::new()),
        ),
        (
            Some(attribution(
                presentation.plugin_name,
                presentation.script_path,
            )),
            command_with_arguments(
                presentation.script_path,
                marker_arguments("read", "1", "pptx"),
            ),
        ),
        (
            Some(attribution(
                presentation.plugin_name,
                presentation.script_path,
            )),
            command_with_arguments(
                presentation.script_path,
                marker_arguments("create", "0", "pptx"),
            ),
        ),
        (
            Some(attribution(
                presentation.plugin_name,
                presentation.script_path,
            )),
            command_with_arguments(
                presentation.script_path,
                marker_arguments("create", "101", "pptx"),
            ),
        ),
        (
            Some(attribution(
                presentation.plugin_name,
                presentation.script_path,
            )),
            command_with_arguments(
                presentation.script_path,
                marker_arguments("create", "1", "html"),
            ),
        ),
    ];

    for (attribution, command) in cases {
        assert_eq!(
            recognize_artifact_operation(attribution.as_ref(), &command),
            None
        );
    }
}

fn attribution(plugin_name: &str, script_path: &str) -> PluginCommandAttribution {
    PluginCommandAttribution {
        plugin_id: PluginId::parse(&format!("{plugin_name}@openai-primary-runtime"))
            .expect("plugin id"),
        normalized_relative_path: script_path.to_string(),
    }
}

fn marker_command(
    script_path: &str,
    operation_kind: &str,
    expected_output_count: &str,
    output_format: &str,
) -> Vec<String> {
    command_with_arguments(
        script_path,
        marker_arguments(operation_kind, expected_output_count, output_format),
    )
}

fn command_with_arguments(script_path: &str, arguments: Vec<String>) -> Vec<String> {
    [vec!["node".to_string(), script_path.to_string()], arguments].concat()
}

fn marker_arguments(
    operation_kind: &str,
    expected_output_count: &str,
    output_format: &str,
) -> Vec<String> {
    [
        "--operation-kind",
        operation_kind,
        "--expected-output-count",
        expected_output_count,
        "--output-format",
        output_format,
    ]
    .map(str::to_string)
    .to_vec()
}