@@ -8,6 +8,67 @@ import (
88 "github.com/stretchr/testify/require"
99)
1010
11+ // TestUpCommandContextSizeFlagBehavior verifies that the --context-size flag on
12+ // the compose up command is not "changed" by default (i.e. nil ContextSize
13+ // should be sent when the flag is absent) and is marked as changed after an
14+ // explicit value is provided.
15+ func TestUpCommandContextSizeFlagBehavior (t * testing.T ) {
16+ t .Run ("context-size flag not changed by default" , func (t * testing.T ) {
17+ cmd := newUpCommand ()
18+ // Parse with just the required --model flag — no --context-size.
19+ err := cmd .ParseFlags ([]string {"--model" , "mymodel" })
20+ require .NoError (t , err )
21+ // The flag must NOT be marked as changed so that ContextSize is omitted
22+ // from the configure request (i.e. remains nil).
23+ assert .False (t , cmd .Flags ().Changed ("context-size" ),
24+ "context-size must not be Changed when the flag is absent" )
25+ })
26+
27+ t .Run ("context-size flag changed after explicit value" , func (t * testing.T ) {
28+ cmd := newUpCommand ()
29+ err := cmd .ParseFlags ([]string {"--model" , "mymodel" , "--context-size" , "4096" })
30+ require .NoError (t , err )
31+ assert .True (t , cmd .Flags ().Changed ("context-size" ),
32+ "context-size must be Changed when explicitly provided" )
33+ })
34+
35+ t .Run ("context-size flag changed with unlimited value -1" , func (t * testing.T ) {
36+ cmd := newUpCommand ()
37+ err := cmd .ParseFlags ([]string {"--model" , "mymodel" , "--context-size" , "-1" })
38+ require .NoError (t , err )
39+ assert .True (t , cmd .Flags ().Changed ("context-size" ),
40+ "context-size must be Changed when explicitly set to -1 (unlimited)" )
41+ })
42+
43+ t .Run ("ContextSize is nil in BackendConfiguration when flag not set" , func (t * testing.T ) {
44+ cmd := newUpCommand ()
45+ require .NoError (t , cmd .ParseFlags ([]string {"--model" , "mymodel" }))
46+ // Simulate the logic in compose.go RunE: only add ContextSize when Changed.
47+ backendConfig := inference.BackendConfiguration {}
48+ if cmd .Flags ().Changed ("context-size" ) {
49+ size := int32 (- 1 ) // default value
50+ backendConfig .ContextSize = & size
51+ }
52+ assert .Nil (t , backendConfig .ContextSize ,
53+ "ContextSize must be nil in BackendConfiguration when --context-size is not provided" )
54+ })
55+
56+ t .Run ("ContextSize is non-nil in BackendConfiguration when flag is set" , func (t * testing.T ) {
57+ cmd := newUpCommand ()
58+ require .NoError (t , cmd .ParseFlags ([]string {"--model" , "mymodel" , "--context-size" , "64000" }))
59+ ctxSize , err := cmd .Flags ().GetInt64 ("context-size" )
60+ require .NoError (t , err )
61+ backendConfig := inference.BackendConfiguration {}
62+ if cmd .Flags ().Changed ("context-size" ) {
63+ size := int32 (ctxSize )
64+ backendConfig .ContextSize = & size
65+ }
66+ require .NotNil (t , backendConfig .ContextSize ,
67+ "ContextSize must be non-nil when --context-size is provided" )
68+ assert .Equal (t , int32 (64000 ), * backendConfig .ContextSize )
69+ })
70+ }
71+
1172func TestParseBackendMode (t * testing.T ) {
1273 tests := []struct {
1374 name string
0 commit comments