Wrap chain composes outermost-first (registration order). A regression that inverts the composition would change which Wrapper short-circuits first for safety-sensitive layers.
(t *testing.T)
| 84 | // that inverts the composition would change which Wrapper short-circuits |
| 85 | // first for safety-sensitive layers. |
| 86 | func TestInstall_wrapperChainOrder(t *testing.T) { |
| 87 | root := &cobra.Command{Use: "lark-cli"} |
| 88 | var order []string |
| 89 | leaf := &cobra.Command{Use: "+x", RunE: func(*cobra.Command, []string) error { |
| 90 | order = append(order, "RunE") |
| 91 | return nil |
| 92 | }} |
| 93 | root.AddCommand(leaf) |
| 94 | |
| 95 | reg := hook.NewRegistry() |
| 96 | reg.AddWrapper(hook.WrapperEntry{ |
| 97 | Name: "outer", Selector: platform.All(), |
| 98 | Fn: func(next platform.Handler) platform.Handler { |
| 99 | return func(ctx context.Context, inv platform.Invocation) error { |
| 100 | order = append(order, "outer-before") |
| 101 | err := next(ctx, inv) |
| 102 | order = append(order, "outer-after") |
| 103 | return err |
| 104 | } |
| 105 | }, |
| 106 | }) |
| 107 | reg.AddWrapper(hook.WrapperEntry{ |
| 108 | Name: "inner", Selector: platform.All(), |
| 109 | Fn: func(next platform.Handler) platform.Handler { |
| 110 | return func(ctx context.Context, inv platform.Invocation) error { |
| 111 | order = append(order, "inner-before") |
| 112 | err := next(ctx, inv) |
| 113 | order = append(order, "inner-after") |
| 114 | return err |
| 115 | } |
| 116 | }, |
| 117 | }) |
| 118 | |
| 119 | hook.Install(root, reg, fakeViewSource{view: fakeView{path: "+x"}}) |
| 120 | if err := leaf.RunE(leaf, nil); err != nil { |
| 121 | t.Fatalf("RunE: %v", err) |
| 122 | } |
| 123 | want := []string{"outer-before", "inner-before", "RunE", "inner-after", "outer-after"} |
| 124 | if !equalStrings(order, want) { |
| 125 | t.Fatalf("Wrapper order = %v, want %v", order, want) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Denial guard physical isolation: the most safety-critical invariant. |
| 130 | // A denied command must NEVER reach a Wrap chain. We register a Wrap |
nothing calls this directly
no test coverage detected