跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

url-github.bats

177 行 · 6.7 KB历史下载
1# SPDX-FileCopyrightText: Copyright The Lima Authors
2# SPDX-License-Identifier: Apache-2.0
3
4load "../helpers/load"
5
6# The jandubois/jandubois GitHub repo has been especially constructed to test
7# various features of the github URL scheme:
8#
9# * repo defaults to org when not specified
10# * filename defaults to .lima.yaml when only a path is specified
11# * .yaml default extension
12# * .lima.yaml files may be treated as symlinks
13# * default branch lookup when not specified
14# * github:ORG// repos can redirect to another github:ORG URL in the same ORG
15#
16# The jandubois/jandubois repo files are:
17#
18# ├── .lima.yaml -> templates/demo.yaml
19# ├── back
20# │ └── .lima.yaml -> github:jandubois//loop/
21# ├── docs
22# │ └── .lima.yaml -> ../templates/demo.yaml
23# ├── example.yaml -> templates/demo.yaml
24# ├── invalid
25# │ ├── org
26# │ │ └── .lima.yaml -> github:lima-vm
27# │ └── tag
28# │ └── .lima.yaml -> github:jandubois//@v0.0.0
29# ├── loop
30# │ └── .lima.yaml -> github:jandubois//back/
31# ├── redirect
32# │ └── .lima.yaml -> github:jandubois/lima/templates/default
33# ├── templates
34# │ └── demo.yaml "base: template:default"
35# └── yaml
36# └── .lima.yaml "{}"
37#
38# Both the `main` branch and the `v0.0.0` tag have this layout.
39#
40# All these URLs should redirect to the same template URL (either on "main" or at "v0.0.0"):
41# "https://raw.githubusercontent.com/jandubois/jandubois/${tag}/templates/demo.yaml"
42#
43# Additional tests rely on jandubois/lima existing and containing the v1.2.1 tag.
44
45URLS=(
46 github:jandubois/jandubois/templates/demo.yaml@main
47 github:jandubois/jandubois/templates/demo.yaml
48 github:jandubois/jandubois/templates/demo
49 github:jandubois/jandubois/.lima.yaml
50 github:jandubois/jandubois/@v0.0.0
51 github:jandubois/jandubois
52 github:jandubois//templates/demo.yaml@main
53 github:jandubois//templates/demo.yaml
54 github:jandubois//templates/demo
55 github:jandubois//.lima.yaml
56 github:jandubois//@v0.0.0
57 github:jandubois//
58 github:jandubois/
59 github:[email protected]
60 github:jandubois
61 github:jandubois/jandubois/example.yaml
62 github:jandubois/jandubois/example@main
63 github:jandubois//[email protected]
64 github:jandubois//example
65 github:jandubois/jandubois/docs/.lima.yaml@main
66 github:jandubois/jandubois/docs/.lima.yaml
67 github:jandubois/jandubois/docs/.lima
68 github:jandubois/jandubois/docs/
69 github:jandubois//docs/[email protected]
70 github:jandubois//docs/.lima.yaml
71 github:jandubois//docs/.lima
72 github:jandubois//docs/@v0.0.0
73 github:jandubois//docs/
74)
75
76url() {
77 run_e "$1" limactl --debug template url "$2"
78}
79
80test_jandubois_url() {
81 local url=$1
82 local tag="main"
83 if [[ $url == *v0.0.0* ]]; then
84 tag="v0.0.0"
85 fi
86
87 url -0 "$url"
88 assert_output "https://raw.githubusercontent.com/jandubois/jandubois/${tag}/templates/demo.yaml"
89}
90
91# Dynamically register a @test for each URL in the list
92for url in "${URLS[@]}"; do
93 bats_test_function --description "$url" -- test_jandubois_url "$url"
94done
95
96@test '.lima.yaml is retained when it exits and is not a symlink' {
97 url -0 'github:jandubois//yaml/'
98 assert_output 'https://raw.githubusercontent.com/jandubois/jandubois/main/yaml/.lima.yaml'
99}
100
101@test 'non-existing .lima.yaml returns an error' {
102 url -1 'github:jandubois//missing/'
103 assert_fatal 'file `https://raw.githubusercontent.com/jandubois/jandubois/main/missing/.lima.yaml` not found or inaccessible: status 404'
104}
105
106@test 'hidden files without an extension get a .yaml extension' {
107 url -1 'github:jandubois//test/.hidden'
108 assert_fatal 'file `https://raw.githubusercontent.com/jandubois/jandubois/main/test/.hidden.yaml` not found or inaccessible: status 404'
109}
110
111@test 'files that have an extension do not get a .yaml extension' {
112 # This command doesn't fail because only *.yaml files are checked for redirects/symlinks, and therefore fail right away if they don't exist.
113 url -0 'github:jandubois//test/.script.sh'
114 assert_output 'https://raw.githubusercontent.com/jandubois/jandubois/main/test/.script.sh'
115}
116
117@test 'github: URLs are EXPERIMENTAL' {
118 url -0 'github:jandubois'
119 assert_warning "The github: scheme is still EXPERIMENTAL"
120}
121
122# Invalid URLs
123@test 'empty github: url returns an error' {
124 url -1 'github:'
125 assert_fatal 'github: URL must contain at least an ORG, got ``'
126}
127
128@test 'missing org returns an error' {
129 url -1 'github:/jandubois'
130 assert_fatal 'github: URL must contain at least an ORG, got ``'
131}
132
133# github: redirects in github:ORG// repos
134@test 'org redirects can point to different repo and may switch the branch name' {
135 url -0 'github:jandubois//redirect/'
136 # Note that the default branch in jandubois/jandubois is main, but in jandubois/lima it is master
137 assert_debug 'Locator `github:jandubois//redirect/` replaced with `github:jandubois/lima/templates/default`'
138 assert_debug 'Locator `github:jandubois/lima/templates/default` replaced with `https://raw.githubusercontent.com/jandubois/lima/master/templates/default.yaml`'
139 assert_output 'https://raw.githubusercontent.com/jandubois/lima/master/templates/default.yaml'
140}
141
142@test 'org redirects propagate an explicit branch/tag to the other repo' {
143 url -0 'github:jandubois//redirect/@v1.2.1'
144 assert_debug 'Locator `github:jandubois//redirect/@v1.2.1` replaced with `github:jandubois/lima/templates/[email protected]`'
145 assert_debug 'Locator `github:jandubois/lima/templates/[email protected]` replaced with `https://raw.githubusercontent.com/jandubois/lima/v1.2.1/templates/default.yaml`'
146 assert_output 'https://raw.githubusercontent.com/jandubois/lima/v1.2.1/templates/default.yaml'
147}
148
149@test 'org redirects cannot point to another org' {
150 url -1 'github:jandubois//invalid/org/'
151 assert_fatal 'redirect `github:lima-vm` is not a `github:jandubois` URL…'
152}
153
154@test 'org redirects with branch cannot point to another org' {
155 url -1 'github:jandubois//invalid/org/@main'
156 assert_fatal 'redirect `github:lima-vm` is not a `github:jandubois` URL…'
157}
158
159@test 'org redirects cannot include a branch or tag' {
160 url -1 'github:jandubois//invalid/tag/'
161 assert_fatal 'redirect `github:jandubois//@v0.0.0` must not include a branch/tag/sha…'
162}
163
164@test 'org redirects with tag cannot include a branch or tag' {
165 url -1 'github:jandubois//invalid/tag/@v0.0.0'
166 assert_fatal 'redirect `github:jandubois//@v0.0.0` must not include a branch/tag/sha…'
167}
168
169@test 'org redirects must not create circular redirects' {
170 url -1 'github:jandubois//loop/'
171 assert_fatal 'custom locator `github:jandubois//loop/` has a redirect loop'
172}
173
174@test 'org redirects with branch must not create circular redirects' {
175 url -1 'github:jandubois//back/@main'
176 assert_fatal 'custom locator `github:jandubois//back/@main` has a redirect loop'
177}