Skip to content

Commit ddbba69

Browse files
committed
fix(documents): default file picker to cwd, not ~/Downloads
The document file picker defaulted to the system Downloads folder via `xdg.UserDirs.Download`. That's non-deterministic — demos, tapes, and tutorials would pick up whatever happens to sit at the top of the recorder's real Downloads, producing non-reproducible captures and risking PII leaks in committed demo videos. Default to the current working directory instead. Explicit `documents.file_picker_dir` / `MICASA_DOCUMENTS_FILE_PICKER_DIR` still wins. Users who want Downloads as the starting location set it explicitly.
1 parent c7c7a55 commit ddbba69

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

internal/config/config.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,19 @@ type Documents struct {
256256
CacheTTL *Duration `toml:"cache_ttl,omitempty" deprecated:"cache_ttl_days" deprecated_transform:"days_to_duration" validate:"omitempty,nonneg_duration"`
257257

258258
// FilePickerDir is the starting directory for the document file picker.
259-
// Default: the system Downloads folder (e.g. ~/Downloads).
259+
// Default: the current working directory.
260260
FilePickerDir string `toml:"file_picker_dir"`
261261
}
262262

263263
// ResolvedFilePickerDir returns the starting directory for the file picker.
264264
// Uses the configured value if set and the directory exists, otherwise falls
265-
// back to the system Downloads folder, then the current working directory.
265+
// back to the current working directory.
266266
func (d Documents) ResolvedFilePickerDir() string {
267267
if d.FilePickerDir != "" {
268268
if info, err := os.Stat(d.FilePickerDir); err == nil && info.IsDir() {
269269
return d.FilePickerDir
270270
}
271271
}
272-
if dir := xdg.UserDirs.Download; dir != "" {
273-
if info, err := os.Stat(dir); err == nil && info.IsDir() {
274-
return dir
275-
}
276-
}
277272
if dir, err := os.Getwd(); err == nil {
278273
return dir
279274
}
@@ -829,8 +824,8 @@ model = "` + DefaultModel + `"
829824
# cache_ttl = "30d"
830825
831826
# Starting directory for the document file picker.
832-
# Default: system Downloads folder (~/Downloads on most systems).
833-
# file_picker_dir = "/home/user/Documents"
827+
# Default: the current working directory.
828+
# file_picker_dir = "/home/user/Downloads"
834829
835830
[locale]
836831
# ISO 4217 currency code. Stored in the database on first run; after that the

internal/config/config_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,24 @@ func TestResolvedFilePickerDir_ConfiguredDirMissing(t *testing.T) {
10641064
assert.NotEmpty(t, result)
10651065
}
10661066

1067-
func TestResolvedFilePickerDir_EmptyFallsBackToDownloadsOrCwd(t *testing.T) {
1068-
t.Parallel()
1067+
func TestResolvedFilePickerDir_EmptyFallsBackToCwd(t *testing.T) {
1068+
// Not parallel: we mutate cwd.
1069+
cwd := t.TempDir()
1070+
t.Chdir(cwd)
1071+
10691072
d := Documents{}
10701073
result := d.ResolvedFilePickerDir()
1071-
assert.NotEmpty(t, result)
1074+
1075+
// Resolve symlinks on both sides: macOS returns /private/var/... for
1076+
// temp dirs via Getwd while t.TempDir reports /var/...
1077+
wantResolved, err := filepath.EvalSymlinks(cwd)
1078+
require.NoError(t, err)
1079+
gotResolved, err := filepath.EvalSymlinks(result)
1080+
require.NoError(t, err)
1081+
assert.Equal(t, wantResolved, gotResolved,
1082+
"with no config, the picker should default to cwd — not the "+
1083+
"user's Downloads folder, which varies per machine and "+
1084+
"leaks into demo recordings")
10721085
}
10731086

10741087
func TestFilePickerDir_FromTOML(t *testing.T) {

0 commit comments

Comments
 (0)