|
| 1 | +//go:build e2e && vm |
| 2 | + |
| 3 | +package e2e |
| 4 | + |
| 5 | +import ( |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/openbootdotdev/openboot/testutil" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +// TestE2E_Sync_Shell_CaptureShell verifies that CaptureShell works correctly |
| 15 | +// in a real macOS environment: detects Oh-My-Zsh and reads theme/plugins from .zshrc. |
| 16 | +func TestE2E_Sync_Shell_CaptureShell(t *testing.T) { |
| 17 | + if testing.Short() { |
| 18 | + t.Skip("skipping VM test in short mode") |
| 19 | + } |
| 20 | + |
| 21 | + vm := testutil.NewTartVM(t) |
| 22 | + installOhMyZsh(t, vm) |
| 23 | + bin := vmCopyDevBinary(t, vm) |
| 24 | + |
| 25 | + // Set a known theme and plugins so we can assert on them |
| 26 | + _, err := vm.Run(`sed -i '' 's/ZSH_THEME="[^"]*"/ZSH_THEME="agnoster"/' ~/.zshrc`) |
| 27 | + require.NoError(t, err) |
| 28 | + _, err = vm.Run(`sed -i '' 's/plugins=(git)/plugins=(git docker)/' ~/.zshrc`) |
| 29 | + require.NoError(t, err) |
| 30 | + |
| 31 | + zshrc, err := vm.Run("cat ~/.zshrc") |
| 32 | + require.NoError(t, err) |
| 33 | + assert.Contains(t, zshrc, `ZSH_THEME="agnoster"`, ".zshrc should have agnoster theme") |
| 34 | + assert.Contains(t, zshrc, "docker", ".zshrc should have docker plugin") |
| 35 | + |
| 36 | + // Run snapshot --json to exercise the full capture path (including CaptureShell indirectly) |
| 37 | + snapshotOut, err := vmRunDevBinary(t, vm, bin, "snapshot --json") |
| 38 | + require.NoError(t, err, "snapshot should succeed, output: %s", snapshotOut) |
| 39 | + assert.NotEmpty(t, snapshotOut) |
| 40 | + |
| 41 | + _, err = vm.Run("test -d ~/.oh-my-zsh") |
| 42 | + assert.NoError(t, err, "~/.oh-my-zsh should exist after install") |
| 43 | +} |
| 44 | + |
| 45 | +// TestE2E_Sync_Shell_NoPanic verifies that the binary handles a remote config |
| 46 | +// with shell settings without panicking. |
| 47 | +func TestE2E_Sync_Shell_NoPanic(t *testing.T) { |
| 48 | + if testing.Short() { |
| 49 | + t.Skip("skipping VM test in short mode") |
| 50 | + } |
| 51 | + |
| 52 | + vm := testutil.NewTartVM(t) |
| 53 | + installOhMyZsh(t, vm) |
| 54 | + bin := vmCopyDevBinary(t, vm) |
| 55 | + |
| 56 | + cfg := `{"username":"testuser","slug":"default","packages":[],"casks":[],"taps":[],"npm":[],"shell":{"oh_my_zsh":true,"theme":"agnoster","plugins":["git","docker"]}}` |
| 57 | + escaped := strings.ReplaceAll(cfg, "'", "'\\''") |
| 58 | + _, err := vm.Run("printf '%s' '" + escaped + "' > /tmp/shell-config.json") |
| 59 | + require.NoError(t, err) |
| 60 | + |
| 61 | + out, _ := vmRunDevBinaryWithGit(t, vm, bin, "--from /tmp/shell-config.json --silent --dry-run") |
| 62 | + t.Logf("dry-run output:\n%s", out) |
| 63 | + assert.NotContains(t, out, "panic", "binary should not panic with shell config") |
| 64 | +} |
0 commit comments