File size: 4,222 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
use super::*;
use pretty_assertions::assert_eq;
use std::fs;
use std::path::Path;

const TEST_REWRITE_PROFILE: RewriteProfile = RewriteProfile::new(
    "CLAUDE.md",
    &[
        "claude code",
        "claude-code",
        "claude_code",
        "claudecode",
        "claude",
    ],
);

#[test]
fn command_skill_names_must_fit_codex_skill_loader_limit() {
    let source_name = "this-is-a-deeply-nested-command-with-a-very-long-name";
    let file = Path::new("commands/this/is/a/deeply/nested/command/with/a/very/long/name.md");
    let document = parse_command_content("---\ndescription: Review PR\n---\nReview\n");

    assert!(
        command_skill_name_if_supported(
            source_name,
            file,
            &document,
            CommandDescriptionMode::RequireFrontmatter,
        )
        .is_none()
    );
}

#[test]
fn commands_with_overlong_descriptions_are_preserved() {
    let description = "x".repeat(1025);
    let document =
        parse_command_content(&format!("---\ndescription: {description}\n---\nReview\n"));

    assert_eq!(
        command_skill_name_if_supported(
            "review",
            Path::new("commands/review.md"),
            &document,
            CommandDescriptionMode::RequireFrontmatter,
        ),
        Some("source-command-review".to_string())
    );

    let rendered = render_command_skill(
        &document.body,
        "source-command-review",
        &description,
        "review",
        TEST_REWRITE_PROFILE,
    );
    assert_eq!(
        parse_command_content(&rendered).description.as_deref(),
        Some(description.as_str())
    );
}

#[test]
fn commands_with_provider_runtime_expansion_are_skipped() {
    let document = parse_command_content(
        "---\ndescription: Deploy\n---\nDeploy $ARGUMENTS from @release.yaml\n",
    );

    assert!(
        command_skill_name_if_supported(
            "deploy",
            Path::new("commands/deploy.md"),
            &document,
            CommandDescriptionMode::RequireFrontmatter,
        )
        .is_none()
    );
}

#[test]
fn commands_without_description_are_skipped() {
    let document = parse_command_content("Review the current change.\n");

    assert!(
        command_skill_name_if_supported(
            "review",
            Path::new("commands/review.md"),
            &document,
            CommandDescriptionMode::RequireFrontmatter,
        )
        .is_none()
    );
}

#[test]
fn commands_can_derive_descriptions_from_source_names() {
    let root = tempfile::TempDir::new().expect("tempdir");
    let commands = root.path().join("commands");
    let target_skills = root.path().join("skills");
    fs::create_dir_all(&commands).expect("create commands");
    fs::write(
        commands.join("review-code.md"),
        "Review the current change.\n",
    )
    .expect("write command");
    let profile = CommandMigrationProfile::new(
        TEST_REWRITE_PROFILE,
        CommandDescriptionMode::UseSourceNameFallback,
    );

    assert_eq!(
        import_commands_with_profile(&commands, &target_skills, profile).unwrap(),
        vec!["source-command-review-code".to_string()]
    );
    let rendered = fs::read_to_string(
        target_skills
            .join("source-command-review-code")
            .join("SKILL.md"),
    )
    .expect("read migrated command");
    assert!(rendered.contains("description: \"Migrated source command `review-code`\""));
    assert!(rendered.contains("Review the current change."));
}

#[test]
fn command_slug_collisions_are_skipped() {
    let root = tempfile::TempDir::new().expect("tempdir");
    let commands = root.path().join("commands");
    fs::create_dir_all(&commands).expect("create commands");
    fs::write(
        commands.join("foo-bar.md"),
        "---\ndescription: First\n---\nRun the first command.\n",
    )
    .expect("write first command");
    fs::write(
        commands.join("foo_bar.md"),
        "---\ndescription: Second\n---\nRun the second command.\n",
    )
    .expect("write second command");

    assert_eq!(
        unique_supported_command_sources(&commands, CommandDescriptionMode::RequireFrontmatter,)
            .unwrap(),
        Vec::<CommandSource>::new()
    );
}