f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func readConfigFile(t *testing.T, dir string) Config {
|
|
t.Helper()
|
|
var fileCfg Config
|
|
_, err := toml.DecodeFile(
|
|
filepath.Join(dir, configFileName), &fileCfg,
|
|
)
|
|
require.NoError(t, err, "parsing config file")
|
|
return fileCfg
|
|
}
|
|
|
|
func TestCursorSecret_GeneratedAndPersisted(t *testing.T) {
|
|
dir := setupTestEnv(t)
|
|
|
|
// First load: should generate a secret
|
|
cfg1, err := LoadMinimal()
|
|
require.NoError(t, err, "first load failed")
|
|
require.NotEmpty(t, cfg1.CursorSecret, "cursor secret was not generated")
|
|
require.Equal(t, dir, cfg1.DataDir)
|
|
|
|
// Verify file existence and content
|
|
fileCfg := readConfigFile(t, dir)
|
|
|
|
assert.Equal(t, cfg1.CursorSecret, fileCfg.CursorSecret)
|
|
|
|
// Second load: should read the same secret
|
|
cfg2, err := LoadMinimal()
|
|
require.NoError(t, err, "second load failed")
|
|
assert.Equal(t, cfg1.CursorSecret, cfg2.CursorSecret)
|
|
}
|
|
|
|
func TestCursorSecret_RegeneratedIfMissing(t *testing.T) {
|
|
dir := setupTestEnv(t)
|
|
|
|
initialContent := "cursor_secret = \"\"\n"
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, configFileName), []byte(initialContent), 0o600))
|
|
|
|
cfg, err := LoadMinimal()
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, cfg.CursorSecret, "cursor secret should have been regenerated")
|
|
|
|
// Verify it was updated in the file
|
|
fileCfg := readConfigFile(t, dir)
|
|
assert.NotEmpty(t, fileCfg.CursorSecret, "cursor secret was not updated in the file")
|
|
}
|
|
|
|
func TestCursorSecret_LoadErrorOnInvalidConfig(t *testing.T) {
|
|
dir := setupTestEnv(t)
|
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, configFileName), []byte("[invalid toml = ="), 0o600))
|
|
|
|
_, err := LoadMinimal()
|
|
require.Error(t, err, "expected error loading invalid config")
|
|
}
|
|
|
|
func TestCursorSecret_PreservesOtherFields(t *testing.T) {
|
|
dir := setupTestEnv(t)
|
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, configFileName), []byte("github_token = \"my-token\"\n"), 0o600))
|
|
|
|
cfg, err := LoadMinimal()
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, cfg.CursorSecret, "cursor secret not generated")
|
|
assert.Equal(t, "my-token", cfg.GithubToken)
|
|
|
|
// Verify file content has both
|
|
fileCfg := readConfigFile(t, dir)
|
|
|
|
assert.NotEmpty(t, fileCfg.CursorSecret, "cursor_secret missing in file")
|
|
assert.Equal(t, "my-token", fileCfg.GithubToken, "github_token lost/changed in file")
|
|
}
|