跳到主要内容

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

浏览文件

shell.bats

78 行 · 3.1 KB历史下载
1# SPDX-FileCopyrightText: Copyright The Lima Authors
2# SPDX-License-Identifier: Apache-2.0
3
4load "../helpers/load"
5
6INSTANCE=bats-dummy
7
8@test 'lima stopped lima instance' {
9 # check that the "tty" flag is used, also for stdin
10 run_e -1 limactl shell --tty=false "$INSTANCE" true </dev/null
11 assert_stderr --partial "instance \`$INSTANCE\` is stopped"
12}
13
14@test 'yes | stopped lima instance' {
15 # check that stdin is verified and not just crashing
16 run_e -1 bash -c "yes | limactl shell --tty=true $INSTANCE true"
17 assert_stderr --partial "instance \`$INSTANCE\` is stopped"
18}
19
20@test 'limactl shell without --instance requires instance name as first argument' {
21 run_e -1 limactl shell --tty=false
22 assert_stderr --partial "requires instance name as first argument"
23}
24
25@test 'limactl shell nonexistent instance' {
26 run_e -1 limactl shell --tty=false nonexistent
27 assert_stderr --partial 'does not exist'
28}
29
30@test 'limactl shell --instance nonexistent instance' {
31 run_e -1 limactl shell --tty=false --instance nonexistent
32 assert_stderr --partial 'does not exist'
33}
34
35@test 'limactl shell --instance resolves instance name' {
36 # --instance should resolve the instance name the same way as the positional arg.
37 # Normalize the logrus timestamp because the two invocations may land in different seconds.
38 run_e -1 limactl shell --tty=false --instance nonexistent
39 inst_output=$(sed 's/^time="[^"]*"/time="TIMESTAMP"/' <<<"$stderr")
40
41 run_e -1 limactl shell --tty=false nonexistent
42 pos_output=$(sed 's/^time="[^"]*"/time="TIMESTAMP"/' <<<"$stderr")
43
44 assert_equal "$pos_output" "$inst_output"
45}
46
47@test 'limactl shell --instance with unknown flag errors' {
48 # Without --, an unknown flag after --instance should be rejected by cobra
49 run_e -1 limactl shell --tty=false --instance "$INSTANCE" --nonexistent-flag
50 assert_stderr --partial "unknown flag"
51}
52
53@test 'limactl shell --instance with double dash stops flag parsing' {
54 # With --, "--nonexistent-flag" must be treated as a command, not a flag.
55 # The key assertion is that we do NOT get "unknown flag" (contrast with the test above).
56 run_e limactl shell --tty=false --instance "$INSTANCE" -- --nonexistent-flag </dev/null
57 refute_stderr --partial "unknown flag"
58}
59
60@test 'limactl shell positional instance with double dash' {
61 # Same double-dash behavior with positional instance name
62 run_e limactl shell --tty=false "$INSTANCE" -- --nonexistent-flag </dev/null
63 refute_stderr --partial "unknown flag"
64}
65
66@test 'lima wrapper forwards unknown limactl shell flags' {
67 # The lima wrapper should forward flags to limactl shell.
68 # --start=false is a valid limactl shell flag; if the wrapper didn't forward it,
69 # it would be treated as a command name and fail with "unknown flag".
70 run_e env LIMA_INSTANCE="$INSTANCE" lima --tty=false --start=false </dev/null
71 refute_stderr --partial "unknown flag"
72}
73
74@test 'lima wrapper rejects unknown flags' {
75 # Flags not recognized by limactl shell should cause an error
76 run_e -1 env LIMA_INSTANCE="$INSTANCE" lima --tty=false --nonexistent-flag
77 assert_stderr --partial "unknown flag"
78}