MCPcopy Index your code
hub / github.com/github/copilot-sdk / TestSession_HookForwardCompatibility

Function TestSession_HookForwardCompatibility

go/session_test.go:1096–1133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1094}
1095
1096func TestSession_HookForwardCompatibility(t *testing.T) {
1097 t.Run("unknown hook type returns nil without error when known hooks are registered", func(t *testing.T) {
1098 session, cleanup := newTestSession()
1099 defer cleanup()
1100
1101 // Register known hook handlers to simulate a real session configuration.
1102 // The handler itself does nothing; it only exists to confirm that even
1103 // when other hooks are active, an unknown hook type is still ignored.
1104 session.registerHooks(&SessionHooks{
1105 OnPostToolUse: func(input PostToolUseHookInput, invocation HookInvocation) (*PostToolUseHookOutput, error) {
1106 return nil, nil
1107 },
1108 })
1109
1110 // "futureUnknownHookType" stands in for a hook type introduced by a
1111 // newer CLI version that the SDK does not yet know about.
1112 output, err := session.handleHooksInvoke("futureUnknownHookType", json.RawMessage(`{}`))
1113 if err != nil {
1114 t.Errorf("Expected no error for unknown hook type, got: %v", err)
1115 }
1116 if output != nil {
1117 t.Errorf("Expected nil output for unknown hook type, got: %v", output)
1118 }
1119 })
1120
1121 t.Run("unknown hook type with no hooks registered returns nil without error", func(t *testing.T) {
1122 session, cleanup := newTestSession()
1123 defer cleanup()
1124
1125 output, err := session.handleHooksInvoke("futureHookType", json.RawMessage(`{"someField":"value"}`))
1126 if err != nil {
1127 t.Errorf("Expected no error for unknown hook type with no hooks, got: %v", err)
1128 }
1129 if output != nil {
1130 t.Errorf("Expected nil output for unknown hook type with no hooks, got: %v", output)
1131 }
1132 })
1133}
1134
1135func TestSession_ElicitationRequestSchema(t *testing.T) {
1136 t.Run("nil content values are allowed", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

newTestSessionFunction · 0.85
registerHooksMethod · 0.45
handleHooksInvokeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…