feat: teai role
This commit is contained in:
@@ -25,7 +25,7 @@ func loginTestEnv(t *testing.T, configContent string) (args []string, configPath
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Setenv("TEA_CONFIG", configPath)
|
||||
t.Setenv("TEAI_CONFIG", configPath)
|
||||
return []string{"--config", configPath}, configPath
|
||||
}
|
||||
|
||||
@@ -117,6 +117,13 @@ func TestLoginAddVerifiesThenWrites(t *testing.T) {
|
||||
if info.Mode().Perm() != 0o600 {
|
||||
t.Fatalf("perm = %v", info.Mode().Perm())
|
||||
}
|
||||
// 新項目只寫 teai 欄位,不含 tea 的 ssh_*/preferences。
|
||||
s := string(data)
|
||||
for _, ban := range []string{"ssh_", "insecure:", "version_check:", "preferences:"} {
|
||||
if strings.Contains(s, ban) {
|
||||
t.Fatalf("tea field leaked %q:\n%s", ban, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginAddTokenFromStdin(t *testing.T) {
|
||||
@@ -187,6 +194,7 @@ preferences:
|
||||
if strings.Contains(s, "old-tok") || !strings.Contains(s, "token: new-tok") {
|
||||
t.Fatalf("token not replaced:\n%s", s)
|
||||
}
|
||||
// 未知欄位與其他區段逐字保留(行級編輯,不整檔覆寫)。
|
||||
if !strings.Contains(s, `ssh_key: "keep-me"`) || !strings.Contains(s, "editor: false") {
|
||||
t.Fatalf("unrelated content lost:\n%s", s)
|
||||
}
|
||||
@@ -290,3 +298,26 @@ func TestLoginRegisteredInUsage(t *testing.T) {
|
||||
t.Fatalf("usage should list login: %s", stdout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginConfigPathIndependentOfTea(t *testing.T) {
|
||||
t.Setenv("TEA_CONFIG", "/from-tea.yml")
|
||||
t.Setenv("TEAI_CONFIG", "")
|
||||
g := defaultGlobals()
|
||||
got := loginConfigPath(g)
|
||||
if got == "/from-tea.yml" {
|
||||
t.Fatal("TEA_CONFIG must not be used")
|
||||
}
|
||||
if !strings.HasSuffix(filepath.ToSlash(got), ".config/teai/config.yml") {
|
||||
t.Fatalf("default path want ~/.config/teai/config.yml, got %q", got)
|
||||
}
|
||||
|
||||
t.Setenv("TEAI_CONFIG", "/from-teai.yml")
|
||||
if got := loginConfigPath(g); got != "/from-teai.yml" {
|
||||
t.Fatalf("TEAI_CONFIG: got %q", got)
|
||||
}
|
||||
|
||||
g.ConfigPath = "/explicit.yml"
|
||||
if got := loginConfigPath(g); got != "/explicit.yml" {
|
||||
t.Fatalf("--config: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user