1package snapshotcodec
2
3import (
4 "errors"
5 "testing"
6
7 renderer "github.com/bnema/vev-vt"
8 "github.com/bnema/vev/internal/domain/layout"
9)
10
11func TestPreflightRejectsDanglingTreeAndFocusReferencesBeforeDecode(t *testing.T) {
12 sealed, tail := historyBlobs(t, nil)
13 transcript := transcriptBlob(t, [][]renderer.Cell{{{Rune: 'v'}}})
14 for _, tt := range []struct {
15 name string
16 tab Tab
17 }{
18 {
19 name: "tree leaf",
20 tab: Tab{
21 Focus: "pane",
22 Tree: layout.NewTree("missing"),
23 Panes: []Pane{{ID: "pane", SealedChunks: sealed, Tail: tail, Transcript: transcript}},
24 },
25 },
26 {
27 name: "tab focus",
28 tab: Tab{
29 Focus: "missing",
30 Tree: layout.NewTree("pane"),
31 Panes: []Pane{{ID: "pane", SealedChunks: sealed, Tail: tail, Transcript: transcript}},
32 },
33 },
34 } {
35 t.Run(tt.name, func(t *testing.T) {
36 encoded, err := marshalTest(Session{Name: "hostile", Tabs: []Tab{tt.tab}})
37 if err != nil {
38 t.Fatalf("Marshal: %v", err)
39 }
40 if err := preflightSession(encoded[16:]); !errors.Is(err, ErrUnknownPane) {
41 t.Fatalf("preflightSession() error = %v, want %v", err, ErrUnknownPane)
42 }
43 })
44 }
45}