From 2237fd2d899a9ccc95a9faaca36d65ad59e4f7e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Aug 2026 13:46:44 +0000 Subject: [PATCH 1/3] Initial plan From 763c06efc7c6cba2a587fd437a4db97b57d192ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Aug 2026 13:52:53 +0000 Subject: [PATCH 2/3] Add spec_test.go for ctxutil package Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/ctxutil/spec_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pkg/ctxutil/spec_test.go diff --git a/pkg/ctxutil/spec_test.go b/pkg/ctxutil/spec_test.go new file mode 100644 index 00000000000..290c3dc5e2d --- /dev/null +++ b/pkg/ctxutil/spec_test.go @@ -0,0 +1,45 @@ +//go:build !integration + +package ctxutil_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/github/gh-aw/pkg/ctxutil" +) + +// TestSpec_PublicAPI_OrBackground validates the documented behavior of +// OrBackground as described in the ctxutil README.md specification. +func TestSpec_PublicAPI_OrBackground(t *testing.T) { + type key string + const testKey key = "spec-key" + + t.Run("returns context.Background() when ctx is nil", func(t *testing.T) { + var nilCtx context.Context + + got := ctxutil.OrBackground(nilCtx) + assert.NotNil(t, got, "OrBackground should never return a nil context") + assert.Equal(t, context.Background(), got, "OrBackground should fall back to context.Background() for a nil input") + }) + + t.Run("returns the context unchanged when ctx is non-nil", func(t *testing.T) { + ctx := context.WithValue(context.Background(), testKey, "value") + + got := ctxutil.OrBackground(ctx) + + assert.Equal(t, ctx, got, "OrBackground should return a non-nil context unchanged") + assert.Equal(t, "value", got.Value(testKey), "OrBackground should preserve values carried by the input context") + }) + + t.Run("preserves cancellation of the input context", func(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + + got := ctxutil.OrBackground(ctx) + cancel() + + assert.ErrorIs(t, got.Err(), context.Canceled, "OrBackground should not detach the input context from its cancellation") + }) +} From b880992d2e55dd8f76435a172ae906d78b1f4ba0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Aug 2026 04:48:06 +0000 Subject: [PATCH 3/3] Use assert.Same for context identity in ctxutil spec test Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/ctxutil/spec_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ctxutil/spec_test.go b/pkg/ctxutil/spec_test.go index 290c3dc5e2d..34fcc8cc476 100644 --- a/pkg/ctxutil/spec_test.go +++ b/pkg/ctxutil/spec_test.go @@ -30,7 +30,7 @@ func TestSpec_PublicAPI_OrBackground(t *testing.T) { got := ctxutil.OrBackground(ctx) - assert.Equal(t, ctx, got, "OrBackground should return a non-nil context unchanged") + assert.Same(t, ctx, got, "OrBackground should return the exact same non-nil context instance") assert.Equal(t, "value", got.Value(testKey), "OrBackground should preserve values carried by the input context") })