GeezerVison is showing github.com — perf(providers): parallelize isolated provider unit tests and shrink … · Twigpine/zero@d6b25fc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: internal/config/unknownfields.go +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -131,7 +131,7 @@ type knownField struct { | 131 | 131 | } | 132 | 132 |
| 133 | 133 | func derefType(t reflect.Type) reflect.Type { | 134 | | - for t != nil && t.Kind() == reflect.Ptr { | | 134 | + for t != nil && t.Kind() == reflect.Pointer { | 135 | 135 | t = t.Elem() | 136 | 136 | } | 137 | 137 | return t | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/cache_breakpoints_test.go +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import ( | 16 | 16 | // unmarked (Anthropic caps breakpoints at 4 per request: system, tools, and | 17 | 17 | // these two). | 18 | 18 | func TestAnthropicRequestMarksLastTwoMessagesForCaching(t *testing.T) { | | 19 | + t.Parallel() | 19 | 20 | var gotBody map[string]any | 20 | 21 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 21 | 22 | if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil { | @@ -73,6 +74,7 @@ func TestAnthropicRequestMarksLastTwoMessagesForCaching(t *testing.T) { | 73 | 74 | // the breakpoint, and thinking blocks must never carry cache_control (the API | 74 | 75 | // rejects them) — the marker goes on the last cacheable block instead. | 75 | 76 | func TestApplyMessageCacheBreakpointsSkipsThinkingBlocks(t *testing.T) { | | 77 | + t.Parallel() | 76 | 78 | messages := []anthropicMessage{ | 77 | 79 | {Role: "user", Content: "plain string"}, | 78 | 80 | {Role: "assistant", Content: []map[string]any{ | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/dropped_test.go +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import ( | 13 | 13 | // can ask the model to retry, mirroring the OpenAI provider's behavior, instead | 14 | 14 | // of silently dropping it. | 15 | 15 | func TestStreamCompletionEmitsDroppedOnNamelessToolUseBlock(t *testing.T) { | | 16 | + t.Parallel() | 16 | 17 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 17 | 18 | writeSSEEvent(w, "content_block_start", `{"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"","name":""}}`) | 18 | 19 | writeSSEEvent(w, "content_block_stop", `{"type":"content_block_stop","index":0}`) | @@ -45,6 +46,7 @@ func TestStreamCompletionEmitsDroppedOnNamelessToolUseBlock(t *testing.T) { | 45 | 46 |
| 46 | 47 | // A well-formed tool_use block must NOT emit a dropped signal. | 47 | 48 | func TestStreamCompletionDoesNotDropValidToolUseBlock(t *testing.T) { | | 49 | + t.Parallel() | 48 | 50 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 49 | 51 | writeSSEEvent(w, "content_block_start", `{"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_1","name":"read_file"}}`) | 50 | 52 | writeSSEEvent(w, "content_block_stop", `{"type":"content_block_stop","index":0}`) | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/finish_reason_test.go +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ import ( | 11 | 11 | // truncated at the output cap. The provider must surface it on the done event so | 12 | 12 | // the agent does not treat a clipped answer as complete. | 13 | 13 | func TestStreamCompletionSurfacesMaxTokensStopReason(t *testing.T) { | | 14 | + t.Parallel() | 14 | 15 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 15 | 16 | writeSSEEvent(w, "message_start", `{"type":"message_start","message":{"usage":{"input_tokens":5,"output_tokens":0}}}`) | 16 | 17 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"cut"}}`) | @@ -37,6 +38,7 @@ func TestStreamCompletionSurfacesMaxTokensStopReason(t *testing.T) { | 37 | 38 |
| 38 | 39 | // A normal end_turn stop_reason must leave the done event's FinishReason empty. | 39 | 40 | func TestStreamCompletionNormalStopReasonHasNoFinishReason(t *testing.T) { | | 41 | + t.Parallel() | 40 | 42 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 41 | 43 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"ok"}}`) | 42 | 44 | writeSSEEvent(w, "message_delta", `{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":2}}`) | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/idle_test.go +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ import ( | 15 | 15 | // message_stop or closing) must abort on the idle timeout instead of blocking | 16 | 16 | // the agent forever. | 17 | 17 | func TestStreamCompletionIdleTimeoutAbortsStalledStream(t *testing.T) { | | 18 | + t.Parallel() | 18 | 19 | released := make(chan struct{}) | 19 | 20 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 20 | 21 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"hi"}}`) | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/image_test.go +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,6 +60,7 @@ func firstUserContentBlocks(t *testing.T, body map[string]any) []any { | 60 | 60 | // TestUserTextOnlyTurnUnchanged pins the text-only wire shape: a single | 61 | 61 | // user message whose content is a one-element text-block array. | 62 | 62 | func TestUserTextOnlyTurnUnchanged(t *testing.T) { | | 63 | + t.Parallel() | 63 | 64 | body := captureRequestBody(t, zeroruntime.CompletionRequest{ | 64 | 65 | Messages: []zeroruntime.Message{ | 65 | 66 | {Role: zeroruntime.MessageRoleUser, Content: "Describe this."}, | @@ -78,6 +79,7 @@ func TestUserTextOnlyTurnUnchanged(t *testing.T) { | 78 | 79 | // TestUserImagePlusTextTurn asserts a text block followed by one image | 79 | 80 | // source block carrying base64 of the RAW bytes. | 80 | 81 | func TestUserImagePlusTextTurn(t *testing.T) { | | 82 | + t.Parallel() | 81 | 83 | raw := []byte{0x89, 0x50, 0x4e, 0x47, 0x01, 0x02} | 82 | 84 | body := captureRequestBody(t, zeroruntime.CompletionRequest{ | 83 | 85 | Messages: []zeroruntime.Message{ | @@ -112,6 +114,7 @@ func TestUserImagePlusTextTurn(t *testing.T) { | 112 | 114 | // TestUserImageOnlyTurnEmits asserts an image-only user turn (empty Content) | 113 | 115 | // still produces a user message with a single image block. | 114 | 116 | func TestUserImageOnlyTurnEmits(t *testing.T) { | | 117 | + t.Parallel() | 115 | 118 | raw := []byte{0xff, 0xd8, 0xff, 0xe0} | 116 | 119 | body := captureRequestBody(t, zeroruntime.CompletionRequest{ | 117 | 120 | Messages: []zeroruntime.Message{ | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/provider_test.go +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,10 +9,16 @@ import ( | 9 | 9 | "strings" | 10 | 10 | "testing" | 11 | 11 |
| | 12 | + "github.com/Gitlawb/zero/internal/providers/providerio" | 12 | 13 | "github.com/Gitlawb/zero/internal/zeroruntime" | 13 | 14 | ) | 14 | 15 |
| | 16 | +func init() { | | 17 | + providerio.ShrinkBackoffForTest() | | 18 | +} | | 19 | + | 15 | 20 | func TestStreamCompletionPostsMessagesRequest(t *testing.T) { | | 21 | + t.Parallel() | 16 | 22 | var gotPath string | 17 | 23 | var gotAPIKey string | 18 | 24 | var gotVersion string | @@ -123,6 +129,7 @@ func TestStreamCompletionPostsMessagesRequest(t *testing.T) { | 123 | 129 | } | 124 | 130 |
| 125 | 131 | func TestStreamCompletionAppliesCustomAuthAndHeaders(t *testing.T) { | | 132 | + t.Parallel() | 126 | 133 | var gotDefaultAuth string | 127 | 134 | var gotCustomAuth string | 128 | 135 | var gotTenant string | @@ -165,6 +172,7 @@ func TestStreamCompletionAppliesCustomAuthAndHeaders(t *testing.T) { | 165 | 172 | } | 166 | 173 |
| 167 | 174 | func TestStreamCompletionEmitsTextUsageAndDone(t *testing.T) { | | 175 | + t.Parallel() | 168 | 176 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 169 | 177 | writeSSEEvent(w, "message_start", `{"type":"message_start","message":{"usage":{"input_tokens":25}}}`) | 170 | 178 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}`) | @@ -186,6 +194,7 @@ func TestStreamCompletionEmitsTextUsageAndDone(t *testing.T) { | 186 | 194 | } | 187 | 195 |
| 188 | 196 | func TestStreamCompletionReportsCacheTokens(t *testing.T) { | | 197 | + t.Parallel() | 189 | 198 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 190 | 199 | writeSSEEvent(w, "message_start", `{"type":"message_start","message":{"usage":{"input_tokens":10,"cache_read_input_tokens":200,"cache_creation_input_tokens":40}}}`) | 191 | 200 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"hi"}}`) | @@ -217,6 +226,7 @@ func TestStreamCompletionReportsCacheTokens(t *testing.T) { | 217 | 226 | } | 218 | 227 |
| 219 | 228 | func TestStreamCompletionEnablesThinkingWhenEffortRequested(t *testing.T) { | | 229 | + t.Parallel() | 220 | 230 | var gotBody map[string]any | 221 | 231 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 222 | 232 | if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil { | @@ -257,6 +267,7 @@ func TestStreamCompletionEnablesThinkingWhenEffortRequested(t *testing.T) { | 257 | 267 | } | 258 | 268 |
| 259 | 269 | func TestStreamCompletionOmitsThinkingWithoutEffort(t *testing.T) { | | 270 | + t.Parallel() | 260 | 271 | var gotBody map[string]any | 261 | 272 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 262 | 273 | if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil { | @@ -287,6 +298,7 @@ func TestStreamCompletionOmitsThinkingWithoutEffort(t *testing.T) { | 287 | 298 | } | 288 | 299 |
| 289 | 300 | func TestStreamCompletionCapturesThinkingBlocksForReplay(t *testing.T) { | | 301 | + t.Parallel() | 290 | 302 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 291 | 303 | writeSSEEvent(w, "content_block_start", `{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":""}}`) | 292 | 304 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"Let me think"}}`) | @@ -312,6 +324,7 @@ func TestStreamCompletionCapturesThinkingBlocksForReplay(t *testing.T) { | 312 | 324 | } | 313 | 325 |
| 314 | 326 | func TestStreamCompletionPreservesUnclosedThinkingBlockAtStreamEnd(t *testing.T) { | | 327 | + t.Parallel() | 315 | 328 | // The SSE ends after thinking_delta/signature_delta but BEFORE the thinking | 316 | 329 | // block's content_block_stop. The open buffer must still be finalized into the | 317 | 330 | // done event's ReasoningBlocks (via closeOpen), or the next Anthropic replay | @@ -339,6 +352,7 @@ func TestStreamCompletionPreservesUnclosedThinkingBlockAtStreamEnd(t *testing.T) | 339 | 352 | } | 340 | 353 |
| 341 | 354 | func TestAnthropicRequestReplaysThinkingBlocksFirst(t *testing.T) { | | 355 | + t.Parallel() | 342 | 356 | var gotBody map[string]any | 343 | 357 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 344 | 358 | if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil { | @@ -392,6 +406,7 @@ func TestAnthropicRequestReplaysThinkingBlocksFirst(t *testing.T) { | 392 | 406 | } | 393 | 407 |
| 394 | 408 | func TestStreamCompletionEmitsToolUseBlocks(t *testing.T) { | | 409 | + t.Parallel() | 395 | 410 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 396 | 411 | writeSSEEvent(w, "content_block_start", `{"type":"content_block_start","index":1,"content_block":{"type":"tool_use","id":"toolu_1","name":"read_file","input":{}}}`) | 397 | 412 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"{\"path\":"}}`) | @@ -414,6 +429,7 @@ func TestStreamCompletionEmitsToolUseBlocks(t *testing.T) { | 414 | 429 | } | 415 | 430 |
| 416 | 431 | func TestStreamCompletionClosesOpenToolCallOnEOF(t *testing.T) { | | 432 | + t.Parallel() | 417 | 433 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 418 | 434 | writeSSEEvent(w, "content_block_start", `{"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_1","name":"grep","input":{}}}`) | 419 | 435 | writeSSEEvent(w, "content_block_delta", `{"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"{\"pattern\":\"Zero\"}"}}`) | @@ -429,6 +445,7 @@ func TestStreamCompletionClosesOpenToolCallOnEOF(t *testing.T) { | 429 | 445 | } | 430 | 446 |
| 431 | 447 | func TestStreamCompletionClassifiesHTTPErrorsAndRedactsToken(t *testing.T) { | | 448 | + t.Parallel() | 432 | 449 | cases := []struct { | 433 | 450 | name string | 434 | 451 | status int | @@ -464,6 +481,7 @@ func TestStreamCompletionClassifiesHTTPErrorsAndRedactsToken(t *testing.T) { | 464 | 481 | } | 465 | 482 |
| 466 | 483 | func TestStreamCompletionEmitsStreamErrorObject(t *testing.T) { | | 484 | + t.Parallel() | 467 | 485 | provider := newTestProviderWithKey(t, "sk-ant", func(w http.ResponseWriter, r *http.Request) { | 468 | 486 | writeSSEEvent(w, "error", `{"type":"error","error":{"message":"stream failed sk-ant","type":"overloaded_error"}}`) | 469 | 487 | }) | @@ -481,6 +499,7 @@ func TestStreamCompletionEmitsStreamErrorObject(t *testing.T) { | 481 | 499 | } | 482 | 500 |
| 483 | 501 | func TestStreamCompletionRejectsMalformedHistoryBeforeDispatch(t *testing.T) { | | 502 | + t.Parallel() | 484 | 503 | provider := newTestProvider(t, func(w http.ResponseWriter, r *http.Request) { | 485 | 504 | t.Fatal("provider should not dispatch malformed history") | 486 | 505 | }) | @@ -507,6 +526,7 @@ func TestStreamCompletionRejectsMalformedHistoryBeforeDispatch(t *testing.T) { | 507 | 526 | } | 508 | 527 |
| 509 | 528 | func TestNewRequiresModelAndPositiveMaxTokens(t *testing.T) { | | 529 | + t.Parallel() | 510 | 530 | if _, err := New(Options{}); err == nil { | 511 | 531 | t.Fatal("New without model returned nil error") | 512 | 532 | } | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/anthropic/stop_reason_test.go +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | ) | 8 | 8 |
| 9 | 9 | func TestMapStopReasonRefusal(t *testing.T) { | | 10 | + t.Parallel() | 10 | 11 | if got := mapStopReason("refusal"); got != zeroruntime.FinishReasonContentFilter { | 11 | 12 | t.Errorf("refusal → %q, want content_filter (M4)", got) | 12 | 13 | } | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/factory_turn_session_test.go +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import ( | 14 | 14 | // wraps into the default TurnSessionProvider: construction succeeds, a session | 15 | 15 | // opens, and Compact reports unsupported (the default adapter contract). | 16 | 16 | func TestNewTurnSessionProviderForEveryKind(t *testing.T) { | | 17 | + t.Parallel() | 17 | 18 | kinds := []config.ProviderKind{ | 18 | 19 | config.ProviderKindOpenAI, | 19 | 20 | config.ProviderKindOpenAICompatible, | @@ -65,6 +66,7 @@ func TestNewTurnSessionProviderForEveryKind(t *testing.T) { | 65 | 66 | // projects the model-registry entry (context limits, capability flags, | 66 | 67 | // reasoning efforts) into the flat ProviderCapabilities. | 67 | 68 | func TestNewTurnSessionProviderProjectsRegistryCapabilities(t *testing.T) { | | 69 | + t.Parallel() | 68 | 70 | registry, err := modelregistry.NewRegistry([]modelregistry.ModelEntry{{ | 69 | 71 | ID: "pr7-caps-model", | 70 | 72 | DisplayName: "PR7 Capability Probe", | @@ -137,6 +139,7 @@ func TestNewTurnSessionProviderProjectsRegistryCapabilities(t *testing.T) { | 137 | 139 | // entry that enumerates no efforts of its own still reports the name-inferred | 138 | 140 | // effective tiers the /effort picker and run-time resolver advertise. | 139 | 141 | func TestNewTurnSessionProviderUsesEffectiveReasoningEfforts(t *testing.T) { | | 142 | + t.Parallel() | 140 | 143 | registry, err := modelregistry.NewRegistry([]modelregistry.ModelEntry{{ | 141 | 144 | // A gpt-5-family id with NO ReasoningEfforts listed: the effective | 142 | 145 | // efforts come from name inference, differing from the raw entry. | |
Collapse file Copy file name to clipboardExpand all lines: internal/providers/gemini/done_test.go +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import ( | 10 | 10 | // emitDone must mark the shared state done so callers observe it through the | 11 | 11 | // pointer (a by-value receiver would make state.done a dead store). | 12 | 12 | func TestEmitDoneMarksStateDoneThroughPointer(t *testing.T) { | | 13 | + t.Parallel() | 13 | 14 | provider, err := New(Options{Model: "gemini-test"}) | 14 | 15 | if err != nil { | 15 | 16 | t.Fatalf("New returned error: %v", err) | |
|