v0.5.1 31f302d

wire_test.go RawHistoryFolder

1package visualproc
2
3import (
4	"bytes"
5	"encoding/binary"
6	"reflect"
7	"strings"
8	"testing"
9	"time"
10
11	"github.com/bnema/neferafk/internal/ports"
12)
13
14func TestCommandRoundTrip(t *testing.T) {
15	var b bytes.Buffer
16	lock := ports.VisualLock{Generation: 4, Auth: ports.AuthBootstrap{Generation: 4, PINSource: ports.PINSourceEnv, PINReference: "r", EnvPIN: []byte("123456")}, Output: "DP-2"}
17	for _, c := range []ports.VisualCommand{ports.VisualFade{Black: true, Duration: 2 * time.Second}, ports.VisualFade{}, lock} {
18		if err := WriteCommand(&b, c); err != nil {
19			t.Fatal(err)
20		}
21	}
22	if c, err := ReadCommand(&b); err != nil || !reflect.DeepEqual(c, ports.VisualFade{Black: true, Duration: 2 * time.Second}) {
23		t.Fatalf("%#v %v", c, err)
24	}
25	if c, err := ReadCommand(&b); err != nil || !reflect.DeepEqual(c, ports.VisualFade{}) {
26		t.Fatalf("%#v %v", c, err)
27	}
28	c, err := ReadCommand(&b)
29	got, ok := c.(ports.VisualLock)
30	if err != nil || !ok || got.Generation != 4 || got.Auth.Generation != 4 || got.Auth.PINSource != ports.PINSourceEnv || got.Auth.PINReference != "r" || string(got.Auth.EnvPIN) != "123456" || got.Output != "DP-2" {
31		t.Fatalf("%#v %v", c, err)
32	}
33}
34
35func TestCommandRejectsMismatchedGenerationAndGarbage(t *testing.T) {
36	var b bytes.Buffer
37	if err := WriteCommand(&b, ports.VisualLock{Generation: 1, Auth: ports.AuthBootstrap{Generation: 2}}); err == nil {
38		t.Fatal("mismatched generations encoded")
39	}
40	if err := WriteCommand(&b, ports.VisualLock{}); err == nil {
41		t.Fatal("zero generation encoded")
42	}
43	if err := WriteCommand(&b, ports.VisualLock{Generation: 1, Auth: ports.AuthBootstrap{Generation: 1}, Output: strings.Repeat("x", ports.MaxOutputName+1)}); err == nil {
44		t.Fatal("oversized output name encoded")
45	}
46	for _, in := range []string{"", "NAV2", "XXXX\x01\x00\x00\x00\x00", "NAV1\x01\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00", "NAV2\x09\x00\x00\x00\x00", "NAV2\x01\xff\xff\xff\xff", "NAV2\x01\x00\x00\x00\x02ab"} {
47		if _, err := ReadCommand(bytes.NewReader([]byte(in))); err == nil {
48			t.Fatalf("%q accepted", in)
49		}
50		if _, err := ReadEvent(bytes.NewReader([]byte(in))); err == nil {
51			t.Fatalf("%q accepted as event", in)
52		}
53	}
54}
55
56func TestEventRoundTripAndNoUnlockRequestExists(t *testing.T) {
57	var b bytes.Buffer
58	for _, e := range []ports.VisualEvent{ports.LockConfirmed{Generation: 2}, ports.LockReleased{Generation: 2}} {
59		if err := WriteEvent(&b, e); err != nil {
60			t.Fatal(err)
61		}
62	}
63	if e, err := ReadEvent(&b); err != nil || e != (ports.LockConfirmed{Generation: 2}) {
64		t.Fatalf("%#v %v", e, err)
65	}
66	if e, err := ReadEvent(&b); err != nil || e != (ports.LockReleased{Generation: 2}) {
67		t.Fatalf("%#v %v", e, err)
68	}
69	if err := WriteEvent(&b, ports.VisualExited{}); err == nil {
70		t.Fatal("process exit must not be a wire event")
71	}
72	// A daemon->visual frame kind is not accepted in the event direction, and
73	// there is no command kind other than fade and lock.
74	var c bytes.Buffer
75	WriteCommand(&c, ports.VisualFade{})
76	if _, err := ReadEvent(&c); err == nil {
77		t.Fatal("command parsed as event")
78	}
79	if _, err := ReadCommand(bytes.NewReader([]byte("NAV2\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01"))); err == nil {
80		t.Fatal("event parsed as command")
81	}
82}
83
84func TestReadCommandBoundsLockFields(t *testing.T) {
85	// Hand-build lock frames the writer refuses: an oversize PINSource or
86	// Output, and the older three-field layout.
87	long := func(n int) []byte { return bytes.Repeat([]byte("x"), n) }
88	for name, fields := range map[string][][]byte{
89		"oversize PINSource": {long(17), nil, nil, nil},
90		"oversize Output":    {nil, nil, nil, long(ports.MaxOutputName + 1)},
91		"three fields":       {nil, nil, nil},
92	} {
93		p := binary.BigEndian.AppendUint64(nil, 1)
94		for _, f := range fields {
95			p = binary.BigEndian.AppendUint32(p, uint32(len(f)))
96			p = append(p, f...)
97		}
98		var b bytes.Buffer
99		if err := writeFrame(&b, kindLock, p); err != nil {
100			t.Fatal(err)
101		}
102		if _, err := ReadCommand(&b); err == nil {
103			t.Fatalf("%s accepted", name)
104		}
105	}
106}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 9

↑↓ moveenter openesc close