Files
Reims-Go/window_launch_test.go
T
千川白浪andClaude Opus 5.5 2f1e0bb0e4 feat(cli): fold the command line into reims-go.exe
Only reims-go.exe ships now; reims-go-cli.exe is gone. Without
arguments it opens the window, with a command it runs command-line mode
(cmd/reims-go moved to internal/cli). Missing standard handles are
attached to the parent console; handles the caller passes in (pipes,
files) are kept, so scripts and agents get output and exit codes.

`vm start` hands the VM to the window process so it gets Guest Tools
and the Win10 cold-reboot watcher, which a command that exits could not
run:
- a running window gets the request through Wails' single-instance
  protocol and stays hidden;
- otherwise the command launches the window tray-only (--background),
  detached from the caller's console and handles;
- the window writes the outcome, with the VM's last log lines on
  failure, to <DataRoot>\tmp\cli-start-*.json (it accepts no other
  path) and the command reports it.
With --data-root the VM still starts in the command itself.

The window now takes a single-instance lock: a second double-click
brings the running window forward. `wails dev` builds use their own
lock name.

Tested on Win10 19045 with macos-tahoe: start from the command line
with no window running (4 s, exit 0) and with one running (3 s, exit 0,
same process); the cold-reboot monitor was held by the window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 22:52:07 -07:00

49 lines
1.3 KiB
Go

package main
import (
"fmt"
"path/filepath"
"testing"
"github.com/Nwflower/reims-go/internal/config"
)
func TestLogCaptureKeepsLastLinesOfItsSource(t *testing.T) {
a := &App{cfg: config.Default()}
c := a.captureLogs("m0")
for i := 0; i < logCaptureMax+3; i++ {
a.emitLog("m0", fmt.Sprintf("line %d", i))
}
a.emitLog("other", "not mine")
lines := a.releaseLogs("m0", c)
if len(lines) != logCaptureMax || lines[0] != "line 3" || lines[len(lines)-1] != fmt.Sprintf("line %d", logCaptureMax+2) {
t.Fatalf("captured %q", lines)
}
a.emitLog("m0", "after release")
if len(c.lines) != logCaptureMax || len(a.logCaptures) != 0 {
t.Fatal("a released capture must stop collecting")
}
}
func TestStartResultPathStaysInTempDir(t *testing.T) {
cfg := config.Default()
cfg.DataRoot = `D:\Data\reims-go`
a := &App{cfg: cfg}
tmp := cfg.TempDir()
good := filepath.Join(tmp, "cli-start-123.json")
if got := a.startResultPath(good); got != good {
t.Fatalf("own result file rejected: %q", got)
}
for _, bad := range []string{
filepath.Join(tmp, "..", "reims-go.json"),
filepath.Join(tmp, "sub", "cli-start-1.json"),
filepath.Join(tmp, "notes.json"),
`C:\Windows\cli-start-1.json`,
} {
if got := a.startResultPath(bad); got != "" {
t.Errorf("startResultPath(%q) = %q, want rejected", bad, got)
}
}
}