跳到主要内容

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

浏览文件

fuzz_test.go

36 行 · 1.2 KB历史下载
1package vmname
2
3import (
4 "regexp"
5 "strings"
6 "testing"
7)
8
9// Lima's identifiers (pkg/identifiers): letters and digits, groups joined by
10// one of . _ -, 76 characters at most.
11var limaID = regexp.MustCompile(`^[A-Za-z0-9]+([._-][A-Za-z0-9]+)*$`)
12
13// Any folder: a name Lima takes (Name's length aside: a long one is refused
14// with the advice to rename the folder), never the base template's, and a
15// scratch name that IsScratch knows and Name never gives.
16func FuzzName(f *testing.F) {
17 for _, s := range []string{"/home/u/proj", "/", "/home/u/__", "/home/u/-x-", "/home/u/café", "/home/u/base", "/home/u/x-scratch", "/a\nb", "/home/u/" + strings.Repeat("y", 90)} {
18 f.Add(s)
19 }
20 f.Fuzz(func(t *testing.T, dir string) {
21 n := Name(dir)
22 if !limaID.MatchString(n) || n == Template {
23 t.Fatalf("Name(%q) = %q", dir, n)
24 }
25 if IsScratch(n) && !strings.HasSuffix(strings.TrimSuffix(dir, "/"), "-scratch") && !strings.HasSuffix(strings.TrimSuffix(dir, "/"), "scratch") {
26 t.Fatalf("Name(%q) = %q looks like a scratch VM", dir, n)
27 }
28 s, err := Scratch(dir)
29 if err != nil {
30 t.Fatal(err)
31 }
32 if !limaID.MatchString(s) || len(s) > 76 || !IsScratch(s) {
33 t.Fatalf("Scratch(%q) = %q", dir, s)
34 }
35 })
36}