Skip to content

Commit 60d0663

Browse files
wesmclaude
andcommitted
fix: remove legacy migration from .agent-session-viewer
Delete MigrateFromLegacy and all associated tests/helpers. The legacy directory is no longer supported. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a034ca4 commit 60d0663

File tree

5 files changed

+1
-315
lines changed

5 files changed

+1
-315
lines changed

cmd/agentsview/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ func mustLoadConfig(args []string) config.Config {
154154
log.Fatalf("parsing flags: %v", err)
155155
}
156156

157-
dataDir, err := config.ResolveDataDir()
158-
if err != nil {
159-
log.Fatalf("resolving data dir: %v", err)
160-
}
161-
config.MigrateFromLegacy(dataDir)
162-
163157
cfg, err := config.Load(fs)
164158
if err != nil {
165159
log.Fatalf("loading config: %v", err)

cmd/agentsview/prune.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ func runPrune(args []string) {
236236
os.Exit(1)
237237
}
238238

239-
dataDir, err := config.ResolveDataDir()
240-
if err != nil {
241-
log.Fatalf("resolving data dir: %v", err)
242-
}
243-
config.MigrateFromLegacy(dataDir)
244-
245239
appCfg, err := config.LoadMinimal()
246240
if err != nil {
247241
log.Fatalf("loading config: %v", err)

internal/config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func Load(fs *flag.FlagSet) (Config, error) {
6262

6363
// LoadMinimal builds a Config from defaults, env, and config file,
6464
// without parsing CLI flags. Use this for subcommands that manage
65-
// their own flag sets. Call MigrateFromLegacy before this if
66-
// legacy data migration is needed.
65+
// their own flag sets.
6766
func LoadMinimal() (Config, error) {
6867
cfg, err := Default()
6968
if err != nil {

internal/config/config_test.go

Lines changed: 0 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,6 @@ func skipIfNotUnix(t *testing.T) {
2424
}
2525
}
2626

27-
const (
28-
legacyDirName = ".agent-session-viewer"
29-
newDirName = ".agentsview"
30-
)
31-
32-
// setupLegacyEnv creates a temp directory with a populated legacy
33-
// data dir and returns (tmp, newDir). Files are written into the
34-
// legacy directory with config.json getting 0o600 permissions and
35-
// all other files getting 0o644.
36-
func setupLegacyEnv(
37-
t *testing.T, files map[string]string,
38-
) (string, string) {
39-
t.Helper()
40-
tmp := t.TempDir()
41-
legacyDir := filepath.Join(tmp, legacyDirName)
42-
newDir := filepath.Join(tmp, newDirName)
43-
44-
if err := os.MkdirAll(legacyDir, 0o755); err != nil {
45-
t.Fatalf("create legacy dir: %v", err)
46-
}
47-
48-
for name, content := range files {
49-
perm := os.FileMode(0o644)
50-
if name == "config.json" {
51-
perm = 0o600
52-
}
53-
path := filepath.Join(legacyDir, name)
54-
if err := os.WriteFile(
55-
path, []byte(content), perm,
56-
); err != nil {
57-
t.Fatalf("write %s: %v", name, err)
58-
}
59-
}
60-
return tmp, newDir
61-
}
62-
63-
func assertFileContent(
64-
t *testing.T, path, expected string,
65-
) {
66-
t.Helper()
67-
data, err := os.ReadFile(path)
68-
if err != nil {
69-
t.Fatalf("read %s: %v", filepath.Base(path), err)
70-
}
71-
if string(data) != expected {
72-
t.Errorf(
73-
"%s content = %q, want %q",
74-
filepath.Base(path), data, expected,
75-
)
76-
}
77-
}
78-
7927
func writeConfig(t *testing.T, dir string, data any) {
8028
t.Helper()
8129
b, err := json.Marshal(data)
@@ -135,25 +83,6 @@ func configWithTmpDir(t *testing.T) (Config, string) {
13583
return Config{DataDir: dir}, dir
13684
}
13785

138-
// assertFilePerm checks that the file at path has permission bits
139-
// matching the given mask and expected value.
140-
func assertFilePerm(
141-
t *testing.T, path string,
142-
mask, want os.FileMode,
143-
) {
144-
t.Helper()
145-
info, err := os.Stat(path)
146-
if err != nil {
147-
t.Fatalf("stat %s: %v", filepath.Base(path), err)
148-
}
149-
if got := info.Mode().Perm() & mask; got != want {
150-
t.Errorf(
151-
"%s perm & %o = %o, want %o",
152-
filepath.Base(path), mask, got, want,
153-
)
154-
}
155-
}
156-
15786
func loadConfigFromFlags(t *testing.T, args ...string) (Config, error) {
15887
t.Helper()
15988
fs := flag.NewFlagSet("test", flag.ContinueOnError)
@@ -164,123 +93,6 @@ func loadConfigFromFlags(t *testing.T, args ...string) (Config, error) {
16493
return Load(fs)
16594
}
16695

167-
func TestMigrateFromLegacy(t *testing.T) {
168-
tests := []struct {
169-
name string
170-
legacyFiles map[string]string
171-
preCreateNew bool
172-
wantFiles map[string]string // Content to assert in new dir
173-
wantMissing []string // Files that should NOT exist
174-
}{
175-
{
176-
name: "CopiesGoDBAndConfig",
177-
legacyFiles: map[string]string{
178-
"sessions-go.db": "go-db-content",
179-
"config.json": `{"github_token": "secret"}`,
180-
},
181-
wantFiles: map[string]string{
182-
"sessions.db": "go-db-content",
183-
"config.json": `{"github_token": "secret"}`,
184-
},
185-
},
186-
{
187-
name: "CopiesGoDBOnly",
188-
legacyFiles: map[string]string{
189-
"sessions-go.db": "just-db",
190-
},
191-
wantFiles: map[string]string{
192-
"sessions.db": "just-db",
193-
},
194-
wantMissing: []string{"config.json"},
195-
},
196-
{
197-
name: "IgnoresPythonDB",
198-
legacyFiles: map[string]string{
199-
"sessions.db": "python-db",
200-
"config.json": `{"github_token":"tok"}`,
201-
},
202-
wantFiles: map[string]string{
203-
"config.json": `{"github_token":"tok"}`,
204-
},
205-
wantMissing: []string{"sessions.db"},
206-
},
207-
{
208-
name: "SkipsIfNewDirExists",
209-
legacyFiles: map[string]string{
210-
"sessions.db": "db",
211-
},
212-
preCreateNew: true,
213-
wantMissing: []string{"sessions.db"},
214-
},
215-
{
216-
name: "SkipsIfNoLegacyDir",
217-
legacyFiles: nil,
218-
wantMissing: []string{"."},
219-
},
220-
}
221-
222-
for _, tt := range tests {
223-
t.Run(tt.name, func(t *testing.T) {
224-
var tmp, newDir string
225-
if tt.legacyFiles != nil {
226-
tmp, newDir = setupLegacyEnv(t, tt.legacyFiles)
227-
} else {
228-
tmp = t.TempDir()
229-
newDir = filepath.Join(tmp, newDirName)
230-
}
231-
232-
if tt.preCreateNew {
233-
if err := os.MkdirAll(newDir, 0o700); err != nil {
234-
t.Fatal(err)
235-
}
236-
}
237-
238-
t.Setenv("HOME", tmp)
239-
MigrateFromLegacy(newDir)
240-
241-
if tt.legacyFiles == nil {
242-
if _, err := os.Stat(newDir); err == nil {
243-
t.Error("new dir should not be created without legacy dir")
244-
}
245-
return
246-
}
247-
248-
for path, content := range tt.wantFiles {
249-
assertFileContent(t, filepath.Join(newDir, path), content)
250-
}
251-
252-
for _, path := range tt.wantMissing {
253-
if _, err := os.Stat(filepath.Join(newDir, path)); err == nil {
254-
t.Errorf("file %s should not exist", path)
255-
}
256-
}
257-
})
258-
}
259-
}
260-
261-
func TestMigrateFromLegacy_FilePermissions(t *testing.T) {
262-
if runtime.GOOS == "windows" {
263-
t.Skip("file permission checks not reliable on Windows")
264-
}
265-
266-
tmp, newDir := setupLegacyEnv(t, map[string]string{
267-
"sessions-go.db": "db",
268-
"config.json": `{"github_token":"x"}`,
269-
})
270-
271-
t.Setenv("HOME", tmp)
272-
MigrateFromLegacy(newDir)
273-
274-
// Data dir must not be group/other accessible
275-
assertFilePerm(t, newDir, 0o077, 0)
276-
277-
// config.json must not be group/other readable
278-
assertFilePerm(t, filepath.Join(newDir, "config.json"), 0o077, 0)
279-
280-
// sessions.db should be owner-accessible
281-
assertFilePerm(t, filepath.Join(newDir, "sessions.db"), 0o400, 0o400)
282-
}
283-
28496
func TestLoadEnv_OverridesDataDir(t *testing.T) {
28597
custom, _ := setupConfigDir(t)
28698

@@ -434,37 +246,3 @@ func TestResolveDataDir_DefaultAndEnvOverride(t *testing.T) {
434246
}
435247
}
436248

437-
// TestMigrateThenLoad_GithubTokenAvailable verifies that the
438-
// startup sequence (resolve data dir, migrate, load) makes
439-
// legacy github_token immediately available without a second
440-
// load.
441-
func TestMigrateThenLoad_GithubTokenAvailable(t *testing.T) {
442-
cfgJSON, _ := json.Marshal(map[string]string{
443-
"github_token": "legacy-secret",
444-
})
445-
tmp, newDir := setupLegacyEnv(t, map[string]string{
446-
"config.json": string(cfgJSON),
447-
})
448-
449-
t.Setenv("HOME", tmp)
450-
t.Setenv("AGENT_VIEWER_DATA_DIR", newDir)
451-
452-
// Simulate startup: resolve, migrate, then load
453-
dataDir, err := ResolveDataDir()
454-
if err != nil {
455-
t.Fatal(err)
456-
}
457-
MigrateFromLegacy(dataDir)
458-
459-
cfg, err := LoadMinimal()
460-
if err != nil {
461-
t.Fatal(err)
462-
}
463-
464-
if cfg.GithubToken != "legacy-secret" {
465-
t.Errorf(
466-
"GithubToken = %q, want %q",
467-
cfg.GithubToken, "legacy-secret",
468-
)
469-
}
470-
}

internal/config/migration.go

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)