With -config or $VCOM_CONFIG naming a missing file, main now passes that path to the UI and paths.DefaultConfigFile returns $VCOM_CONFIG, so SetKey creates the file every later start reads instead of writing ~/.config/vcom/vcom.toml. A broken-config notice now starts with "Config error:" so the status line shows it as an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
339 lines
12 KiB
Go
339 lines
12 KiB
Go
package ui
|
|
|
|
// QA (v0.2.8 RC2): re-check of the QA fixes from the user's side and of the
|
|
// stage-2C changes the old UI now uses (config/SetKey, session, trash).
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"vcom/internal/config"
|
|
vfs "vcom/internal/fs"
|
|
"vcom/internal/testutil/teadriver"
|
|
)
|
|
|
|
// newModelLikeMain mirrors cmd/vcom/main.go: Load, pass info.Path only if
|
|
// the file was found and parsed, set the notice.
|
|
func newModelLikeMain(t *testing.T, left, right string) (*teadriver.Driver, config.LoadInfo) {
|
|
t.Helper()
|
|
cfg, info, err := config.Load("")
|
|
resolved := ""
|
|
if info.Found && err == nil {
|
|
resolved = info.Path
|
|
}
|
|
cfg.UI.IconMode = "ascii"
|
|
cfg.Startup.LeftPath, cfg.Startup.RightPath = left, right
|
|
m, merr := NewModel(cfg, resolved)
|
|
if merr != nil {
|
|
t.Fatalf("NewModel: %v", merr)
|
|
}
|
|
if err != nil {
|
|
m = m.WithStatus(err.Error())
|
|
}
|
|
t.Cleanup(func() { m.cleanupArchiveMounts(); m.cleanupRemoteImageTemp() })
|
|
d := teadriver.New(t, m, 160, 40, teadriver.WithLongCmd(300*time.Millisecond))
|
|
d.Settle(settle)
|
|
return d, info
|
|
}
|
|
|
|
func userConfig(t *testing.T) string {
|
|
return filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "vcom", "vcom.toml")
|
|
}
|
|
|
|
// Unknown theme name: vcom starts with the default theme and says why;
|
|
// choosing a theme then fixes the file, keeping the rest of it.
|
|
func TestQAUnknownThemeStartsAndIsFixable(t *testing.T) {
|
|
isolateEnv(t)
|
|
dir := t.TempDir()
|
|
p := userConfig(t)
|
|
writeFile(t, p, "# keep me\n[ui]\ntheme = \"no-such-theme\"\nicon_mode = \"ascii\"\n")
|
|
d, _ := newModelLikeMain(t, dir, dir)
|
|
if !d.ScreenContains("no-such-theme") {
|
|
t.Fatalf("unknown theme not explained on screen:\n%s", d.Screen())
|
|
}
|
|
d.Press("t", "j", "enter")
|
|
d.Settle(settle)
|
|
b, _ := os.ReadFile(p)
|
|
if strings.Contains(string(b), "no-such-theme") || !strings.Contains(string(b), "# keep me") || !strings.Contains(string(b), "icon_mode") {
|
|
t.Fatalf("config after theme choice: %q (status %q)", b, cur(t, d).status)
|
|
}
|
|
}
|
|
|
|
// Broken config: vcom starts with defaults, shows the error; choosing a
|
|
// theme must not overwrite (or "repair") the user's broken file.
|
|
func TestQABrokenConfigNotOverwrittenByTheme(t *testing.T) {
|
|
isolateEnv(t)
|
|
dir := t.TempDir()
|
|
p := userConfig(t)
|
|
broken := "[ui]\ntheme = \"catppuccin-mocha\"\nicon_mode = \n# half-edited\n"
|
|
writeFile(t, p, broken)
|
|
d, _ := newModelLikeMain(t, dir, dir)
|
|
if !d.ScreenContains("incomplete number") { // shown, though not highlighted as an error (see report)
|
|
t.Fatalf("broken config not reported: %q", cur(t, d).status)
|
|
}
|
|
d.Press("t", "j", "enter")
|
|
d.Settle(settle)
|
|
if b, _ := os.ReadFile(p); string(b) != broken {
|
|
t.Fatalf("broken config was rewritten: %q", b)
|
|
}
|
|
}
|
|
|
|
// $VCOM_CONFIG (or -config) names a file that does not exist yet: the
|
|
// theme must be saved there, so the next start (which reads $VCOM_CONFIG)
|
|
// sees it. main passes "" for a missing file and SetKey("") writes the
|
|
// default ~/.config/vcom/vcom.toml instead.
|
|
func TestQAThemeSavedToExplicitMissingConfig(t *testing.T) {
|
|
home := isolateEnv(t)
|
|
explicit := filepath.Join(home, "custom", "vcom.toml")
|
|
t.Setenv("VCOM_CONFIG", explicit)
|
|
dir := t.TempDir()
|
|
d, info := newModelLikeMain(t, dir, dir)
|
|
if info.Path != explicit {
|
|
t.Fatalf("Load info.Path=%q", info.Path)
|
|
}
|
|
d.Press("t", "j", "enter")
|
|
d.Settle(settle)
|
|
if _, err := os.Stat(explicit); err != nil {
|
|
t.Fatalf("theme not saved to $VCOM_CONFIG (%v); default exists: %v", err, exists(userConfig(t)))
|
|
}
|
|
}
|
|
|
|
// A broken session.toml: start at the startup paths, quit writes a valid one.
|
|
func TestQABrokenSessionRecovers(t *testing.T) {
|
|
isolateEnv(t)
|
|
dir := t.TempDir()
|
|
sp := filepath.Join(os.Getenv("XDG_STATE_HOME"), "vcom", "session.toml")
|
|
writeFile(t, sp, "active_pane = 'right'\n[left\n")
|
|
d := teadriver.New(t, newTestModelKeepEnv(t, dir, dir), 160, 40, teadriver.WithLongCmd(300*time.Millisecond))
|
|
d.Settle(settle)
|
|
if p := activeOf(t, d).Path; p != dir {
|
|
t.Fatalf("pane at %q, want startup %q", p, dir)
|
|
}
|
|
d.Press("q")
|
|
d.Settle(settle)
|
|
s, err := config.LoadSession()
|
|
if err != nil || s.Left.Path != dir {
|
|
t.Fatalf("session after quit: %+v %v", s, err)
|
|
}
|
|
}
|
|
|
|
// Old session location: restored once, then moved to the state dir.
|
|
func TestQAOldSessionMigratedThroughUI(t *testing.T) {
|
|
isolateEnv(t)
|
|
start, saved := t.TempDir(), t.TempDir()
|
|
old := filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "vcom", "session.toml")
|
|
writeFile(t, old, "active_pane = 'left'\n[left]\npath = '"+saved+"'\n[right]\npath = '"+saved+"'\n")
|
|
m := newTestModelKeepEnv(t, start, start)
|
|
if m.left.Path != saved {
|
|
t.Fatalf("old session not restored: left=%q", m.left.Path)
|
|
}
|
|
if exists(old) {
|
|
t.Fatal("old session not removed after migration")
|
|
}
|
|
if !exists(filepath.Join(os.Getenv("XDG_STATE_HOME"), "vcom", "session.toml")) {
|
|
t.Fatal("session not written to the state dir")
|
|
}
|
|
}
|
|
|
|
// State dir not writable (e.g. XDG_STATE_HOME on a read-only mount): the
|
|
// old session is read but not applied, because applySession drops the
|
|
// session whenever Load returns an error.
|
|
func TestQAOldSessionRestoredWhenStateDirReadOnly(t *testing.T) {
|
|
t.Skip("BUG QA-16 (P2): if migrating the session to an unwritable state dir fails, state.Load returns the old session with an error and ui.applySession (model.go:5453-5457) discards it: panes are not restored")
|
|
if os.Geteuid() == 0 {
|
|
t.Skip("root ignores permissions")
|
|
}
|
|
home := isolateEnv(t)
|
|
start, saved := t.TempDir(), t.TempDir()
|
|
old := filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "vcom", "session.toml")
|
|
writeFile(t, old, "active_pane = 'left'\n[left]\npath = '"+saved+"'\n")
|
|
ro := filepath.Join(home, "ro")
|
|
if err := os.MkdirAll(ro, 0o500); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.Chmod(ro, 0o700) })
|
|
t.Setenv("XDG_STATE_HOME", filepath.Join(ro, "state"))
|
|
m := newTestModelKeepEnv(t, start, start)
|
|
if m.left.Path != saved {
|
|
t.Fatalf("session not restored: left=%q", m.left.Path)
|
|
}
|
|
}
|
|
|
|
// newTestModelKeepEnv is newTestModel without re-isolating the environment
|
|
// (the test prepared files in it).
|
|
func newTestModelKeepEnv(t *testing.T, left, right string) Model {
|
|
t.Helper()
|
|
cfg := config.Default()
|
|
cfg.UI.IconMode = "ascii"
|
|
cfg.Startup.LeftPath, cfg.Startup.RightPath = left, right
|
|
m, err := NewModel(cfg, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { m.cleanupArchiveMounts(); m.cleanupRemoteImageTemp() })
|
|
return m
|
|
}
|
|
|
|
// QA-1 bypass: one item the trash refuses (name too long for its
|
|
// .trashinfo) in a multi-selection with an ordinary file. Only the refused
|
|
// item may be offered for permanent deletion; the ordinary file belongs in
|
|
// the trash.
|
|
func TestQATrashOfferOnlyForRefusedItems(t *testing.T) {
|
|
t.Skip("BUG QA-17 (P2): when the trash refuses one item, the permanent-delete offer covers it AND every later selected item, which the trash would have accepted (model.go:5314: trashFailed = sources[i:]); confirming deletes them irrecoverably")
|
|
dir := t.TempDir()
|
|
long := strings.Repeat("a", 250) // + ".trashinfo" > NAME_MAX
|
|
writeFile(t, filepath.Join(dir, long), "x")
|
|
writeFile(t, filepath.Join(dir, "b.txt"), "ordinary")
|
|
d := newDriver(t, dir, t.TempDir())
|
|
m := cur(t, d)
|
|
for _, e := range m.activePane().Entries {
|
|
if !e.IsParent {
|
|
m.activePane().EnsureMarked(e.Path)
|
|
}
|
|
}
|
|
d = teadriver.New(t, m, 160, 40, teadriver.WithoutInit(), teadriver.WithLongCmd(300*time.Millisecond))
|
|
d.Press("f8", "enter")
|
|
d.Settle(settle)
|
|
if exists(filepath.Join(dir, "b.txt")) {
|
|
if d.ScreenContains("Not in trash: 2") {
|
|
t.Fatalf("b.txt (trashable) offered for permanent deletion:\n%s", d.Screen())
|
|
}
|
|
}
|
|
if !exists(filepath.Join(trashFiles(t), "b.txt")) {
|
|
t.Fatal("b.txt should be in the trash")
|
|
}
|
|
}
|
|
|
|
// Long names: does the trash accept a 250-byte name at all? (Recorded in
|
|
// the report; the offer flow covers it.)
|
|
func TestQATrashLongNameOffered(t *testing.T) {
|
|
dir := t.TempDir()
|
|
long := strings.Repeat("л", 125) // 250 bytes
|
|
writeFile(t, filepath.Join(dir, long), "x")
|
|
d := newDriver(t, dir, t.TempDir())
|
|
selectName(t, d, long)
|
|
d.Press("f8", "enter")
|
|
d.Settle(settle)
|
|
if exists(filepath.Join(dir, long)) {
|
|
if !d.ScreenContains("Delete permanently?") {
|
|
t.Fatalf("long name neither trashed nor offered:\n%s\nstatus %q", d.Screen(), cur(t, d).status)
|
|
}
|
|
d.Press("esc")
|
|
d.Settle(settle)
|
|
if !exists(filepath.Join(dir, long)) {
|
|
t.Fatal("esc deleted the file")
|
|
}
|
|
}
|
|
}
|
|
|
|
// QA-2 neighbour: mirror from a local pane INTO a pane that is inside an
|
|
// archive. The passive pane keeps its archive mount while showing a real
|
|
// directory: it stays "read-only" on the real filesystem, can never leave
|
|
// the archive (root is the temp dir) and the temp dir lingers.
|
|
func TestQAMirrorIntoArchivePane(t *testing.T) {
|
|
t.Skip("BUG QA-18 (P2, since v0.2.7): mirror (p) into a pane that is inside an archive sets its path to a real directory but keeps the archive mount: the pane treats the real filesystem as a read-only archive and Backspace never closes the archive (model.go:2667-2669, handleMirrorPane local branch only clears remote mounts)")
|
|
dir := t.TempDir()
|
|
writeFile(t, filepath.Join(dir, "inner.txt"), "in")
|
|
if err := vfs.CreateArchive(context.Background(), []string{filepath.Join(dir, "inner.txt")}, filepath.Join(dir, "box.zip"), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
work := t.TempDir()
|
|
writeFile(t, filepath.Join(work, "w.txt"), "w")
|
|
d := newDriver(t, dir, work)
|
|
selectName(t, d, "box.zip")
|
|
d.Press("enter") // left into the archive
|
|
d.Settle(settle)
|
|
d.Press("tab", "p") // right (local) mirrors into left
|
|
d.Settle(settle)
|
|
m := cur(t, d)
|
|
if m.passivePane().Path == work && m.passivePane().InArchive() {
|
|
t.Fatalf("passive pane shows %s but is still in the archive", work)
|
|
}
|
|
}
|
|
|
|
// QA-3 re-check: shifted letters, digits, space and Cyrillic are text in
|
|
// the filter; arrows still navigate.
|
|
func TestQAFilterAllPrintable(t *testing.T) {
|
|
dir := t.TempDir()
|
|
writeFile(t, filepath.Join(dir, "My Kj 2 файл.txt"), "x")
|
|
writeFile(t, filepath.Join(dir, "other"), "x")
|
|
d := newDriver(t, dir, t.TempDir())
|
|
d.Press("/")
|
|
d.Type("My Kj 2 фа")
|
|
if q := cur(t, d).filterQuery; q != "My Kj 2 фа" {
|
|
t.Fatalf("filter query %q", q)
|
|
}
|
|
d.Press("enter")
|
|
if d.ScreenContains("other") {
|
|
t.Fatalf("filter did not narrow:\n%s", d.Screen())
|
|
}
|
|
}
|
|
|
|
// QA-4 re-check: '?' typed into every SSH form field; F1 toggles help.
|
|
func TestQASSHFormQuestionMarkEveryField(t *testing.T) {
|
|
d := newDriver(t, t.TempDir(), t.TempDir())
|
|
openSSHAddForm(t, d)
|
|
for i := 0; i < 5; i++ {
|
|
d.Type("a?b")
|
|
if got := cur(t, d).ssh.inputs[i].Value(); got != "a?b" {
|
|
t.Fatalf("field %d = %q", i, got)
|
|
}
|
|
d.Press("tab")
|
|
}
|
|
d.Press("f1")
|
|
if !cur(t, d).ssh.showHelp {
|
|
t.Fatal("F1 did not open help")
|
|
}
|
|
d.Press("f1")
|
|
if cur(t, d).ssh.showHelp || cur(t, d).modal.kind != modalSSHConnect {
|
|
t.Fatal("F1 did not close help")
|
|
}
|
|
}
|
|
|
|
// QA-10 re-check: F7 in an SSH pane: existing name → error, new nested
|
|
// name works, existing *file* name → error.
|
|
func TestQARemoteMkdirVariants(t *testing.T) {
|
|
rdir := t.TempDir()
|
|
writeFile(t, filepath.Join(rdir, "file"), "x")
|
|
d := newRemoteDriver(t, rdir, t.TempDir())
|
|
for _, tc := range []struct {
|
|
name string
|
|
ok bool
|
|
}{{"file", false}, {"new/sub", true}, {"new/sub", false}, {"папка", true}} {
|
|
d.Press("f7")
|
|
d.Type(tc.name)
|
|
d.Press("enter")
|
|
d.Settle(settle)
|
|
isErr := classifyStatus(cur(t, d).status) == statusError
|
|
if cur(t, d).modal.kind != modalNone {
|
|
d.Press("esc") // the dialog stays open after an error
|
|
}
|
|
if isErr == tc.ok {
|
|
t.Fatalf("mkdir %q: status %q", tc.name, cur(t, d).status)
|
|
}
|
|
}
|
|
if !exists(filepath.Join(rdir, "new", "sub")) || !exists(filepath.Join(rdir, "папка")) {
|
|
t.Fatal("remote dirs not created")
|
|
}
|
|
}
|
|
|
|
// When saving the chosen theme fails (broken config, forms SetKey cannot
|
|
// edit), the user must see it. finalizeTheme sets "Theme: X (save failed:
|
|
// ...)", but the theme selector overwrites the status with "Theme: X" right
|
|
// after, so a theme that was not persisted looks saved.
|
|
func TestQAThemeSaveFailureVisible(t *testing.T) {
|
|
t.Skip("BUG QA-19 (P2): theme selector overwrites finalizeTheme's \"save failed\" status with \"Theme: X\" (model.go:1645-1648): a theme that was not saved looks saved")
|
|
isolateEnv(t)
|
|
dir := t.TempDir()
|
|
writeFile(t, userConfig(t), "[ui]\nicon_mode = \n")
|
|
d, _ := newModelLikeMain(t, dir, dir)
|
|
d.Press("t", "j", "enter")
|
|
d.Settle(settle)
|
|
if !strings.Contains(cur(t, d).status, "save failed") {
|
|
t.Fatalf("theme save failure not reported: %q", cur(t, d).status)
|
|
}
|
|
}
|