Skip to content

Commit 105eeba

Browse files
authored
feat: add ci job for verifying mocks (#514)
* stick to format and add job * cleaner
1 parent 4db785d commit 105eeba

5 files changed

Lines changed: 68 additions & 21 deletions

File tree

.github/workflows/ci-presubmit.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ jobs:
8989
./dev/ci/presubmits/verify-gomod.sh
9090
9191
92+
verify-mocks:
93+
runs-on: ubuntu-latest
94+
timeout-minutes: 60
95+
steps:
96+
- uses: actions/checkout@v4
97+
- uses: actions/setup-go@v5
98+
with:
99+
go-version-file: 'go.mod'
100+
- name: "Run dev/ci/presubmits/verify-mocks.sh"
101+
run: |
102+
./dev/ci/presubmits/verify-mocks.sh
103+
104+
92105
concurrency:
93106
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
94107
cancel-in-progress: true

dev/ci/presubmits/verify-mocks.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT="$(git rev-parse --show-toplevel)"
21+
cd ${REPO_ROOT}
22+
23+
if ! command -v mockgen &> /dev/null; then
24+
echo "mockgen not found, installing..."
25+
go install go.uber.org/mock/mockgen@latest
26+
fi
27+
28+
# We run generate to see if it creates any diffs.
29+
go generate ./internal/mocks
30+
31+
if ! git diff --quiet --exit-code -- internal/mocks; then
32+
echo "Mocks are stale. Commit the changes to the generated files."
33+
exit 1
34+
fi
35+
36+
echo "Mocks are up to date."

gollm/bedrock.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
349349
if partial, exists := partialTools[idx]; exists {
350350
// Parse the JSON to extract arguments for function call
351351
inputJSON := partial.input.String()
352-
352+
353353
var args map[string]any
354354
if inputJSON != "" {
355355
if err := json.Unmarshal([]byte(inputJSON), &args); err != nil {
@@ -358,7 +358,7 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
358358
} else {
359359
args = make(map[string]any)
360360
}
361-
361+
362362
// Create ToolUseBlock for conversation history
363363
// Use the accumulated JSON string to create proper Input document
364364
toolUse := types.ToolUseBlock{
@@ -367,7 +367,7 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
367367
Input: document.NewLazyDocument(args),
368368
}
369369
completedTools = append(completedTools, toolUse)
370-
370+
371371
// Yield tool immediately with parsed arguments
372372
response := &bedrockStreamResponse{
373373
content: "",
@@ -379,7 +379,7 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
379379
if !yield(response, nil) {
380380
return
381381
}
382-
382+
383383
delete(partialTools, idx)
384384
}
385385

@@ -402,13 +402,13 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
402402
assistantMessage.Content = append(assistantMessage.Content,
403403
&types.ContentBlockMemberText{Value: fullContent.String()})
404404
}
405-
405+
406406
// Include completed tools in conversation history
407407
for _, tool := range completedTools {
408408
assistantMessage.Content = append(assistantMessage.Content,
409409
&types.ContentBlockMemberToolUse{Value: tool})
410410
}
411-
411+
412412
// Only add to history if there's content or tools
413413
if len(assistantMessage.Content) > 0 {
414414
c.messages = append(c.messages, assistantMessage)
@@ -425,7 +425,7 @@ func (c *bedrockChat) SendStreaming(ctx context.Context, contents ...any) (ChatR
425425
// following AWS Bedrock Converse API patterns
426426
func (c *bedrockChat) addContentsToHistory(contents []any) error {
427427
var contentBlocks []types.ContentBlock
428-
428+
429429
for _, content := range contents {
430430
switch c := content.(type) {
431431
case string:
@@ -443,13 +443,13 @@ func (c *bedrockChat) addContentsToHistory(contents []any) error {
443443
}
444444
// Check for status field
445445
if statusVal, hasStatus := c.Result["status"]; hasStatus {
446-
if statusStr, isString := statusVal.(string); isString &&
447-
(statusStr == "failed" || statusStr == "error") {
446+
if statusStr, isString := statusVal.(string); isString &&
447+
(statusStr == "failed" || statusStr == "error") {
448448
status = types.ToolResultStatusError
449449
}
450450
}
451451
}
452-
452+
453453
// Convert to AWS Bedrock ToolResultBlock format per official docs
454454
toolResult := types.ToolResultBlock{
455455
ToolUseId: aws.String(c.ID),
@@ -465,15 +465,15 @@ func (c *bedrockChat) addContentsToHistory(contents []any) error {
465465
return fmt.Errorf("unhandled content type: %T", content)
466466
}
467467
}
468-
468+
469469
if len(contentBlocks) > 0 {
470470
// Add user message with all content blocks to conversation history
471471
c.messages = append(c.messages, types.Message{
472472
Role: types.ConversationRoleUser,
473473
Content: contentBlocks,
474474
})
475475
}
476-
476+
477477
return nil
478478
}
479479

@@ -643,12 +643,12 @@ func (c *bedrockStreamCandidate) String() string {
643643
// Parts returns the parts of the streaming candidate
644644
func (c *bedrockStreamCandidate) Parts() []Part {
645645
var parts []Part
646-
646+
647647
// Handle text content
648648
if c.content != "" {
649649
parts = append(parts, &bedrockTextPart{text: c.content})
650650
}
651-
651+
652652
// Handle tool calls with streaming args
653653
for i, toolUse := range c.toolUses {
654654
var args map[string]any
@@ -660,7 +660,7 @@ func (c *bedrockStreamCandidate) Parts() []Part {
660660
args: args,
661661
})
662662
}
663-
663+
664664
return parts
665665
}
666666

makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ generate:
9292
go generate ./internal/mocks
9393

9494
verify-mocks:
95-
# Re-generate and fail if it produces diffs
96-
go generate ./internal/mocks
97-
git diff --quiet --exit-code -- internal/mocks || \
98-
(echo "Mocks are stale. Run 'make generate' and commit changes." && exit 1)
95+
@echo "λ Verifying mocks..."
96+
./dev/ci/presubmits/verify-mocks.sh
9997
# --- Generation Tasks ---
10098
generate-actions: ## Generate GitHub Actions workflows
10199
@echo "λ Generating GitHub Actions workflows..."

pkg/mcp/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func processToolResponse(result any) (string, error) {
393393
if isError {
394394
// Extract error message
395395
errorMsg := fmt.Sprintf("%+v", result)
396-
396+
397397
// Try to get message from Content field
398398
contentField := rv.FieldByName("Content")
399399
if contentField.IsValid() && contentField.Len() > 0 {
@@ -403,7 +403,7 @@ func processToolResponse(result any) (string, error) {
403403
}
404404
}
405405
}
406-
406+
407407
// Return JSON error data instead of Go error
408408
return fmt.Sprintf(`{"error": true, "message": %q, "status": "failed"}`, errorMsg), nil
409409
}

0 commit comments

Comments
 (0)