Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions engines/evidence-ledger/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,12 @@ func openMigrated() (*sql.DB, Paths, error) {
func cmdInit(args []string, out, errw io.Writer) int {
_ = args
paths := ResolvePaths()
if err := security.EnsurePrivateParent(paths.ConfigPath); err != nil {
return fatalf(errw, "init: %s", err)
}
if err := security.EnsurePrivateDir(paths.DataDir); err != nil {
return fatalf(errw, "init: %s", err)
}
if err := security.EnsurePrivateDir(paths.CacheDir); err != nil {
return fatalf(errw, "init: %s", err)
}
if _, err := os.Stat(paths.ConfigPath); errors.Is(err, os.ErrNotExist) {
body := fmt.Sprintf("db_path = %q\ncache_dir = %q\n", paths.DBPath, paths.CacheDir)
if err := security.WritePrivateFileAtomic(paths.ConfigPath, []byte(body)); err != nil {
return fatalf(errw, "init: %s", err)
}
}
db, err := archive.Open(paths.DBPath)
if err != nil {
return fatalf(errw, "init: %s", err)
Expand Down
22 changes: 21 additions & 1 deletion engines/evidence-ledger/internal/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ func TestInitCreatesPrivateDirsAndDoctorJSON(t *testing.T) {
t.Fatalf("init failed: code=%d err=%s", code, errb.String())
}
paths := ResolvePaths()
assertPrivate(t, filepath.Dir(paths.ConfigPath))
if _, err := os.Stat(paths.ConfigPath); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("init created config.toml at %s: %v", paths.ConfigPath, err)
}
assertPrivate(t, paths.DataDir)
assertPrivate(t, paths.CacheDir)
assertPrivate(t, paths.DBPath)

out.Reset()
errb.Reset()
Expand All @@ -46,6 +49,23 @@ func TestInitCreatesPrivateDirsAndDoctorJSON(t *testing.T) {
}
}

func TestInitLeavesExistingConfigUntouched(t *testing.T) {
withTempHome(t)
paths := ResolvePaths()
custom := "db_path = \"/custom/fork.db\"\ncache_dir = \"/custom/cache\"\n"
mustWrite(t, paths.ConfigPath, custom)

runOK(t, "init")

got, err := os.ReadFile(paths.ConfigPath)
if err != nil {
t.Fatalf("read config: %v", err)
}
if string(got) != custom {
t.Fatalf("init rewrote config.toml:\n got %q\nwant %q", got, custom)
}
}

func TestDoctorMCPJSON(t *testing.T) {
withTempHome(t)
runOK(t, "init")
Expand Down
Loading