|
31 | 31 | import setup_environment |
32 | 32 |
|
33 | 33 |
|
| 34 | +class TestConvertToRawUrl: |
| 35 | + """Test URL transformation for skills - converting tree/blob URLs to raw URLs.""" |
| 36 | + |
| 37 | + def test_github_tree_url(self) -> None: |
| 38 | + """Test converting GitHub tree URL to raw URL.""" |
| 39 | + url = 'https://github.com/owner/repo/tree/main/skills/my-skill' |
| 40 | + expected = 'https://raw.githubusercontent.com/owner/repo/main/skills/my-skill' |
| 41 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 42 | + |
| 43 | + def test_github_blob_url(self) -> None: |
| 44 | + """Test converting GitHub blob URL to raw URL.""" |
| 45 | + url = 'https://github.com/owner/repo/blob/main/skills/my-skill' |
| 46 | + expected = 'https://raw.githubusercontent.com/owner/repo/main/skills/my-skill' |
| 47 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 48 | + |
| 49 | + def test_github_raw_url_unchanged(self) -> None: |
| 50 | + """Test that raw.githubusercontent.com URLs are returned unchanged.""" |
| 51 | + url = 'https://raw.githubusercontent.com/owner/repo/main/skills/my-skill' |
| 52 | + assert setup_environment.convert_to_raw_url(url) == url |
| 53 | + |
| 54 | + def test_gitlab_tree_url(self) -> None: |
| 55 | + """Test converting GitLab tree URL to raw URL.""" |
| 56 | + url = 'https://gitlab.com/ns/proj/-/tree/main/skills/my-skill' |
| 57 | + expected = 'https://gitlab.com/ns/proj/-/raw/main/skills/my-skill' |
| 58 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 59 | + |
| 60 | + def test_gitlab_blob_url(self) -> None: |
| 61 | + """Test converting GitLab blob URL to raw URL.""" |
| 62 | + url = 'https://gitlab.com/ns/proj/-/blob/main/skills/my-skill' |
| 63 | + expected = 'https://gitlab.com/ns/proj/-/raw/main/skills/my-skill' |
| 64 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 65 | + |
| 66 | + def test_gitlab_self_hosted_tree_url(self) -> None: |
| 67 | + """Test converting self-hosted GitLab tree URL to raw URL.""" |
| 68 | + url = 'https://gitlab.company.com/group/project/-/tree/develop/path/to/skill' |
| 69 | + expected = 'https://gitlab.company.com/group/project/-/raw/develop/path/to/skill' |
| 70 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 71 | + |
| 72 | + def test_local_path_unchanged(self) -> None: |
| 73 | + """Test that local paths are returned unchanged.""" |
| 74 | + path = './skills/local-skill' |
| 75 | + assert setup_environment.convert_to_raw_url(path) == path |
| 76 | + |
| 77 | + def test_absolute_local_path_unchanged(self) -> None: |
| 78 | + """Test that absolute local paths are returned unchanged.""" |
| 79 | + path = '/home/user/skills/local-skill' |
| 80 | + assert setup_environment.convert_to_raw_url(path) == path |
| 81 | + |
| 82 | + def test_windows_path_unchanged(self) -> None: |
| 83 | + """Test that Windows paths are returned unchanged.""" |
| 84 | + path = 'C:\\Users\\user\\skills\\local-skill' |
| 85 | + assert setup_environment.convert_to_raw_url(path) == path |
| 86 | + |
| 87 | + def test_github_refs_heads_prefix(self) -> None: |
| 88 | + """Test handling of refs/heads/ prefix in GitHub URLs.""" |
| 89 | + url = 'https://github.com/owner/repo/tree/refs/heads/main/skills/my-skill' |
| 90 | + expected = 'https://raw.githubusercontent.com/owner/repo/main/skills/my-skill' |
| 91 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 92 | + |
| 93 | + def test_github_url_with_trailing_slash(self) -> None: |
| 94 | + """Test GitHub URL with trailing slash is handled correctly.""" |
| 95 | + url = 'https://github.com/owner/repo/tree/main/skills/my-skill/' |
| 96 | + expected = 'https://raw.githubusercontent.com/owner/repo/main/skills/my-skill' |
| 97 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 98 | + |
| 99 | + def test_github_url_deep_path(self) -> None: |
| 100 | + """Test GitHub URL with deep nested path.""" |
| 101 | + url = 'https://github.com/org/repo/tree/main/skills/library/context-retrieval-protocol' |
| 102 | + expected = ( |
| 103 | + 'https://raw.githubusercontent.com/org/repo/main/' |
| 104 | + 'skills/library/context-retrieval-protocol' |
| 105 | + ) |
| 106 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 107 | + |
| 108 | + def test_github_url_feature_branch(self) -> None: |
| 109 | + """Test GitHub URL with feature branch name containing slashes.""" |
| 110 | + url = 'https://github.com/owner/repo/tree/feature/new-skill/skills/my-skill' |
| 111 | + expected = ( |
| 112 | + 'https://raw.githubusercontent.com/owner/repo/' |
| 113 | + 'feature/new-skill/skills/my-skill' |
| 114 | + ) |
| 115 | + assert setup_environment.convert_to_raw_url(url) == expected |
| 116 | + |
| 117 | + def test_gitlab_raw_url_unchanged(self) -> None: |
| 118 | + """Test that GitLab raw URLs are returned unchanged.""" |
| 119 | + url = 'https://gitlab.com/ns/proj/-/raw/main/skills/my-skill' |
| 120 | + assert setup_environment.convert_to_raw_url(url) == url |
| 121 | + |
| 122 | + def test_other_url_unchanged(self) -> None: |
| 123 | + """Test that other URLs (not GitHub/GitLab tree/blob) are returned unchanged.""" |
| 124 | + url = 'https://example.com/skills/my-skill' |
| 125 | + assert setup_environment.convert_to_raw_url(url) == url |
| 126 | + |
| 127 | + def test_http_url_github(self) -> None: |
| 128 | + """Test HTTP (non-HTTPS) GitHub tree URL.""" |
| 129 | + # GitHub tree URLs should be converted even with HTTP |
| 130 | + url = 'http://github.com/owner/repo/tree/main/skills' |
| 131 | + # This won't match the pattern because it starts with http:// |
| 132 | + # The regex specifically checks for https:// |
| 133 | + # So this is expected behavior - http URLs are returned unchanged |
| 134 | + assert setup_environment.convert_to_raw_url(url) == url |
| 135 | + |
| 136 | + |
34 | 137 | class TestValidateSkillFiles: |
35 | 138 | """Test skill file validation.""" |
36 | 139 |
|
|
0 commit comments