修改配置编辑不了的问题

This commit is contained in:
andy committed 2026-08-18 12:41:39 +08:00
1 parent 22b504e53e
commit 2a2f78c81e
42 files changed
+1082 -178

No files matched your search

+74 -5
View File
@@ -65,12 +65,61 @@ func TestServiceSavePreservesSecretsAndUnrelatedEnvLines(t *testing.T) {
if !reflect.DeepEqual(applied, map[string]string{"ZHINIAN_BILLING_CONTACT": "", "EVOLINK_BASE_URL": "https://new.example/v1"}) {
t.Fatalf("applied = %#v", applied)
}
if payload := value.(Payload); !payload.RestartRequired {
t.Fatal("provider setting update must declare restartRequired")
if payload := value.(Payload); payload.RestartRequired {
t.Fatal("provider setting update must be applied without restart")
}
assertSecretProjection(t, value, "ZHINIAN_AUTH_SESSION_SECRET", true)
}
func TestRuntimeRepositoryOverridesEnvironmentAndProjectsSecrets(t *testing.T) {
repository := &runtimeSettingsRepositoryStub{values: map[string]string{
"EVOLINK_API_KEY": "database-secret",
"EVOLINK_BASE_URL": "https://database.example",
"IMAGE_GENERATE_ENGINE": "evolink",
}}
service := NewWithRuntimeRepository(
filepath.Join(t.TempDir(), ".env.local"),
map[string]string{"EVOLINK_API_KEY": "environment-secret", "EVOLINK_BASE_URL": "https://environment.example"},
repository,
nil,
)
value, err := service.Get(context.Background())
if err != nil {
t.Fatal(err)
}
if got := fieldValue(t, value, "EVOLINK_BASE_URL"); got != "https://database.example" {
t.Fatalf("base URL = %q", got)
}
assertSecretProjection(t, value, "EVOLINK_API_KEY", true)
runtime, err := service.RuntimeValues(context.Background())
if err != nil || runtime["EVOLINK_API_KEY"] != "database-secret" {
t.Fatalf("runtime=%#v err=%v", runtime, err)
}
}
func TestRuntimeRepositorySaveIsPartialImmediateAndDoesNotCreateSettingsFile(t *testing.T) {
path := filepath.Join(t.TempDir(), "nested", ".env.local")
repository := &runtimeSettingsRepositoryStub{values: map[string]string{"EVOLINK_API_KEY": "keep-secret"}}
service := NewWithRuntimeRepository(path, nil, repository, nil)
value, err := service.Save(context.Background(), map[string]any{
"EVOLINK_API_KEY": " ",
"EVOLINK_BASE_URL": " https://saved.example ",
})
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(repository.saved, map[string]string{"EVOLINK_BASE_URL": "https://saved.example"}) {
t.Fatalf("saved=%#v", repository.saved)
}
if _, err := os.Stat(path); !os.IsNotExist(err) {
t.Fatalf("provider save unexpectedly created local settings file: %v", err)
}
if value.(Payload).RestartRequired {
t.Fatal("provider database update should apply immediately")
}
assertSecretProjection(t, value, "EVOLINK_API_KEY", true)
}
func TestServiceGetUsesInjectedEnvironmentWithoutMutatingProcess(t *testing.T) {
path := filepath.Join(t.TempDir(), ".env.local")
if err := os.WriteFile(path, []byte("EVOLINK_BASE_URL=file-value\nSEEDANCE_API_KEY=file-secret\n"), 0o600); err != nil {
@@ -100,7 +149,7 @@ func TestServiceGetUsesInjectedEnvironmentWithoutMutatingProcess(t *testing.T) {
assertSecretProjection(t, value, "SEEDANCE_API_KEY", true)
}
func TestLoadEnvironmentAllowsBootstrapRuntimeFlagButIgnoresUnknownKeys(t *testing.T) {
func TestLoadEnvironmentIgnoresUnknownRuntimeFlags(t *testing.T) {
path := filepath.Join(t.TempDir(), ".env.local")
if err := os.WriteFile(path, []byte("ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS=true\nUNKNOWN_RUNTIME_FLAG=true\n"), 0o600); err != nil {
t.Fatal(err)
@@ -109,8 +158,8 @@ func TestLoadEnvironmentAllowsBootstrapRuntimeFlagButIgnoresUnknownKeys(t *testi
if err != nil {
t.Fatal(err)
}
if values["ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS"] != "true" {
t.Fatalf("bootstrap flag = %q", values["ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS"])
if _, exists := values["ZHINIAN_ALLOW_UNCONFIGURED_PROVIDERS"]; exists {
t.Fatal("obsolete provider bootstrap flag was loaded")
}
if _, exists := values["UNKNOWN_RUNTIME_FLAG"]; exists {
t.Fatal("unknown runtime flag was loaded")
@@ -160,6 +209,26 @@ func (writer *billingWriterStub) SaveBillingAccount(_ context.Context, value Bil
return nil
}
type runtimeSettingsRepositoryStub struct {
values map[string]string
saved map[string]string
}
func (repository *runtimeSettingsRepositoryStub) LoadRuntimeSettings(_ context.Context, _ []string) (map[string]string, error) {
return clone(repository.values), nil
}
func (repository *runtimeSettingsRepositoryStub) SaveRuntimeSettings(_ context.Context, values map[string]string) error {
repository.saved = clone(values)
if repository.values == nil {
repository.values = map[string]string{}
}
for key, value := range values {
repository.values[key] = value
}
return nil
}
func fieldValue(t *testing.T, value any, key string) string {
t.Helper()
payload := value.(Payload)