MCPcopy Create free account
hub / github.com/Facets-cloud/flow / TestSpawnTabScriptShape

Function TestSpawnTabScriptShape

internal/ghostty/ghostty_test.go:13–54  ·  view source on GitHub ↗

TestSpawnTabScriptShape verifies the AppleScript emitted to osascript targets Ghostty, embeds env-var assignments before the command, sets the tab title via an OSC 2 escape sequence (Ghostty's `name` property is read-only), and uses `new tab in front window` when a window already exists. The osascri

(t *testing.T)

Source from the content-addressed store, hash-verified

11// property is read-only), and uses `new tab in front window` when a
12// window already exists. The osascript binary is mocked via Runner.
13func TestSpawnTabScriptShape(t *testing.T) {
14 var captured string
15 old := Runner
16 Runner = func(args []string) error {
17 if len(args) >= 2 {
18 captured = args[1]
19 }
20 return nil
21 }
22 t.Cleanup(func() { Runner = old })
23
24 envVars := map[string]string{
25 "FLOW_TASK": "my-task",
26 "FLOW_PROJECT": "flow",
27 }
28 if err := SpawnTab("flow/my-task", "/Users/me/repo", "claude --resume abc", envVars); err != nil {
29 t.Fatalf("SpawnTab: %v", err)
30 }
31
32 mustContain := []string{
33 `tell application "Ghostty"`,
34 `activate`,
35 `if (count of windows) is 0 then`,
36 `set newWin to (new window)`,
37 `set targetTerm to focused terminal of (first tab of newWin)`,
38 `set newTab to (new tab in front window)`,
39 `input text "`,
40 ` & return to targetTerm`,
41 // OSC 2 title set inline via printf — Ghostty's name property is read-only.
42 `printf '\\033]2;%s\\007' 'flow/my-task' ;`,
43 // env vars assigned alphabetically, before the command, all on one line:
44 `FLOW_PROJECT='flow' FLOW_TASK='my-task' claude --resume abc`,
45 // cd is the first thing in the typed line, single-leading-space
46 // for histignorespace:
47 ` cd '/Users/me/repo' && `,
48 }
49 for _, s := range mustContain {
50 if !strings.Contains(captured, s) {
51 t.Errorf("script missing %q\n--- script ---\n%s", s, captured)
52 }
53 }
54}
55
56// TestSpawnTabNoEnvVars covers the env-prefix branch when envVars is
57// nil — the line should still cd and run the command, just with no

Callers

nothing calls this directly

Calls 1

SpawnTabFunction · 0.70

Tested by

no test coverage detected