package pipeline

import (
	"context"
	"testing"
)

func TestRunnerUsesProvidedSessionWithoutSourceFallback(t *testing.T) {
	for _, test := range []struct {
		name    string
		session string
		wantSet bool
		want    string
	}{
		{name: "provided", session: " supplied-session ", wantSet: true, want: "supplied-session"},
		{name: "empty", wantSet: false},
	} {
		t.Run(test.name, func(t *testing.T) {
			prepared, _ := preparedTerminalDebugPipeline(t)
			output, err := New().Run(context.Background(), RunInput{
				Prepared:  prepared,
				RawInput:  []byte("input"),
				SessionID: test.session,
			})
			if err != nil {
				t.Fatal(err)
			}
			value, found := output.Manifest.Metadata["session_id"]
			if found != test.wantSet {
				t.Fatalf("manifest session presence = %t, want %t; metadata = %#v", found, test.wantSet, output.Manifest.Metadata)
			}
			if found && value != test.want {
				t.Fatalf("manifest session = %#v, want %q", value, test.want)
			}
		})
	}
}
