engine_policy_test.go RawHistoryFolder

1package daemonmux
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/require"
7
8	"github.com/bnema/vev/internal/ports"
9)
10
11// TestStreamEngineRestrictAdmissions proves the accepted physical policy seam:
12// it is configured once before any admission, refuses a mismatched fresh Open
13// before that Open records anything, leaves a replayed identity classified as a
14// duplicate rather than a policy refusal, and admits a matching Open.
15func TestStreamEngineRestrictAdmissions(t *testing.T) {
16	engine := NewStreamEngine()
17	require.NoError(t, engine.RestrictAdmissions(testPolicy()))
18	require.ErrorIs(t, engine.RestrictAdmissions(testPolicy()), ErrStreamState, "the policy is fixed once")
19
20	mismatched := openFor(1)
21	mismatched.Policy = alternatePolicy(testPolicy())
22	require.ErrorIs(t, engine.Open(mismatched), ErrOpenPolicyRefused)
23	_, tracked := engine.Status(1)
24	require.False(t, tracked, "a policy refusal records no stream")
25	require.Zero(t, engine.Live())
26
27	matching := openFor(1)
28	matching.Policy = testPolicy()
29	require.NoError(t, engine.Open(matching))
30	require.Equal(t, 1, engine.Live())
31
32	// A duplicate identity is still fenced by reference/identity first, so a
33	// mismatched replay never disturbs the live stream it names.
34	replay := openFor(1)
35	replay.Policy = alternatePolicy(testPolicy())
36	require.ErrorIs(t, engine.Open(replay), ErrStreamIDReused)
37	require.Equal(t, 1, engine.Live())
38}
39
40// TestStreamEngineRestrictAdmissionsGuards proves the seam refuses an invalid
41// policy, a terminal engine, and a nil receiver, and that a policy gate is
42// optional: an unrestricted engine admits any validly encoded Open.
43func TestStreamEngineRestrictAdmissionsGuards(t *testing.T) {
44	var nilEngine *StreamEngine
45	require.ErrorIs(t, nilEngine.RestrictAdmissions(testPolicy()), ErrPhysicalClosed)
46
47	engine := NewStreamEngine()
48	require.Error(t, engine.RestrictAdmissions(ports.BrokerPolicy{}), "an invalid policy is refused")
49
50	unrestricted := NewStreamEngine()
51	require.NoError(t, unrestricted.Open(openFor(1)))
52
53	terminated := NewStreamEngine()
54	terminated.Terminate()
55	require.ErrorIs(t, terminated.RestrictAdmissions(testPolicy()), ErrPhysicalClosed)
56}

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 12

Tags 11

↑↓ moveenter openesc close