Skip to content

Commit cd8209d

Browse files
authored
Merge pull request #27 from akihikokuroda/clitests
2 parents fab0fa4 + 46f48a0 commit cd8209d

File tree

12 files changed

+1514
-24
lines changed

12 files changed

+1514
-24
lines changed

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zI
7070
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
7171
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
7272
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
73+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
74+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
7375
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
7476
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
7577
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=

lint.sh

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-License-Identifier: MIT
4+
# Copyright (c) 2025 IBM
5+
6+
set -e
7+
8+
# Parse command line arguments
9+
SKIP_SECURITY=false
10+
for arg in "$@"; do
11+
case $arg in
12+
--skip-security)
13+
SKIP_SECURITY=true
14+
shift
15+
;;
16+
--help|-h)
17+
echo "Usage: $0 [--skip-security]"
18+
echo " --skip-security Skip security checks (govulncheck, gosec)"
19+
exit 0
20+
;;
21+
esac
22+
done
23+
24+
echo "🔍 Running linter on Maestro MCP Server project..."
25+
26+
# Colors for output
27+
RED='\033[0;31m'
28+
GREEN='\033[0;32m'
29+
YELLOW='\033[1;33m'
30+
BLUE='\033[0;34m'
31+
NC='\033[0m' # No Color
32+
33+
print_status() {
34+
echo -e "${GREEN}[INFO]${NC} $1"
35+
}
36+
37+
print_warning() {
38+
echo -e "${YELLOW}[WARNING]${NC} $1"
39+
}
40+
41+
print_error() {
42+
echo -e "${RED}[ERROR]${NC} $1"
43+
}
44+
45+
print_header() {
46+
echo -e "${BLUE}[LINT]${NC} $1"
47+
}
48+
49+
print_success() {
50+
echo -e "${GREEN}[SUCCESS]${NC} $1"
51+
}
52+
53+
# Function to check if command exists
54+
command_exists() {
55+
command -v "$1" >/dev/null 2>&1
56+
}
57+
58+
# Go linting
59+
echo "📁 Checking Go files..."
60+
if command_exists go; then
61+
print_header "Running Go linter..."
62+
63+
# Install golangci-lint if not present
64+
if ! command_exists golangci-lint; then
65+
print_status "Installing golangci-lint..."
66+
if command_exists curl; then
67+
# Use go install to build with current Go version for compatibility
68+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
69+
else
70+
print_warning "curl not found, please install golangci-lint manually"
71+
print_status "Visit: https://golangci-lint.run/usage/install/"
72+
fi
73+
fi
74+
75+
# Run golangci-lint if available
76+
if command_exists golangci-lint; then
77+
print_status "Running golangci-lint..."
78+
if golangci-lint run --timeout 5m ./src/...; then
79+
print_success "Go linting passed!"
80+
else
81+
print_error "Go linting failed!"
82+
exit 1
83+
fi
84+
else
85+
# Fallback to go vet and go fmt
86+
print_status "Running go vet..."
87+
if go vet ./src/...; then
88+
print_success "go vet passed!"
89+
else
90+
print_error "go vet failed!"
91+
exit 1
92+
fi
93+
94+
print_status "Checking go fmt..."
95+
if [ "$(gofmt -s -l src/)" ]; then
96+
print_warning "Code is not formatted with go fmt!"
97+
print_status "Auto-fixing formatting..."
98+
gofmt -s -w src/
99+
print_success "Code formatting fixed!"
100+
else
101+
print_success "go fmt check passed!"
102+
fi
103+
fi
104+
105+
# Check for common Go issues
106+
print_status "Checking for common Go issues..."
107+
108+
# Check for unused imports
109+
if command_exists goimports; then
110+
print_status "Checking imports..."
111+
if [ "$(goimports -l src/)" ]; then
112+
print_warning "Unused imports found. Run 'goimports -w src/' to fix"
113+
else
114+
print_success "Import check passed!"
115+
fi
116+
fi
117+
118+
# Check for race conditions
119+
print_status "Checking for race conditions..."
120+
if go test -race ./src/... >/dev/null 2>&1; then
121+
print_success "Race condition check passed!"
122+
else
123+
print_warning "Race condition check failed or tests not available"
124+
fi
125+
126+
print_success "Go linting checks passed!"
127+
else
128+
print_error "Go is not installed, skipping Go linting"
129+
exit 1
130+
fi
131+
132+
# JSON linting
133+
echo "📄 Checking JSON files..."
134+
if find . -name "*.json" -not -path "./src/vendor/*" -not -path "./node_modules/*" | grep -q .; then
135+
find . -name "*.json" -not -path "./src/vendor/*" -not -path "./node_modules/*" -print0 | while IFS= read -r -d '' json_file; do
136+
if ! python3 -m json.tool "$json_file" >/dev/null 2>&1; then
137+
print_error "Invalid JSON found in $json_file"
138+
exit 1
139+
fi
140+
done
141+
print_success "JSON files are valid!"
142+
else
143+
echo "ℹ️ No JSON files found to validate"
144+
fi
145+
146+
# YAML linting (excluding GitHub Actions workflows with false positives)
147+
echo "📋 Checking YAML files..."
148+
if find . -name "*.yml" -o -name "*.yaml" | grep -q .; then
149+
if command_exists yamllint; then
150+
# Use .yamllint config file to exclude GitHub Actions workflows with false positives
151+
if yamllint .; then
152+
print_success "YAML linting passed!"
153+
else
154+
print_warning "YAML linting issues found"
155+
fi
156+
else
157+
print_warning "yamllint not found, skipping YAML linting"
158+
print_status "Install yamllint: pip install yamllint"
159+
fi
160+
else
161+
echo "ℹ️ No YAML files found to lint"
162+
fi
163+
164+
# Markdown linting (excluding docs directory with extended formats)
165+
echo "📝 Checking Markdown files..."
166+
if find . -name "*.md" -not -path "./src/vendor/*" -not -path "./node_modules/*" -not -path "./docs/*" | grep -q .; then
167+
if command_exists markdownlint; then
168+
if npx markdownlint "**/*.md" --ignore node_modules --ignore src/vendor --ignore docs; then
169+
print_success "Markdown linting passed!"
170+
else
171+
print_warning "Markdown linting issues found"
172+
fi
173+
else
174+
print_warning "markdownlint not found, skipping Markdown linting"
175+
print_status "Install markdownlint: npm install -g markdownlint-cli"
176+
fi
177+
else
178+
echo "ℹ️ No Markdown files found to lint (excluding docs directory with extended formats)"
179+
fi
180+
181+
# Shell script linting
182+
echo "🐚 Checking shell scripts..."
183+
if find . -name "*.sh" | grep -q .; then
184+
if command_exists shellcheck; then
185+
find . -name "*.sh" -print0 | while IFS= read -r -d '' sh_file; do
186+
if shellcheck "$sh_file"; then
187+
print_success "Shell script $sh_file passed!"
188+
else
189+
print_error "Shell script $sh_file has issues"
190+
exit 1
191+
fi
192+
done
193+
else
194+
print_warning "shellcheck not found, skipping shell script linting"
195+
print_status "Install shellcheck: brew install shellcheck (macOS) or apt-get install shellcheck (Ubuntu)"
196+
fi
197+
else
198+
echo "ℹ️ No shell scripts found to lint"
199+
fi
200+
201+
# Security checks (optional)
202+
if [ "$SKIP_SECURITY" = true ]; then
203+
echo "🔒 Skipping security checks (--skip-security flag used)"
204+
else
205+
echo "🔒 Running security checks..."
206+
if command_exists govulncheck; then
207+
print_status "Running govulncheck vulnerability scanner..."
208+
if govulncheck ./src/...; then
209+
print_success "Vulnerability scan passed!"
210+
else
211+
print_warning "Vulnerabilities found"
212+
fi
213+
else
214+
print_status "govulncheck not available - using go mod audit as alternative"
215+
if go list -json -m all | grep -q '"Indirect":true'; then
216+
print_status "Checking for known vulnerabilities in dependencies..."
217+
if go mod audit; then
218+
print_success "Dependency audit passed!"
219+
else
220+
print_warning "Potential dependency issues found"
221+
fi
222+
else
223+
print_status "No indirect dependencies to audit"
224+
fi
225+
fi
226+
227+
# Additional security checks with gosec if available
228+
if command_exists gosec; then
229+
print_status "Running gosec security scanner..."
230+
if gosec ./src/...; then
231+
print_success "Security scan passed!"
232+
else
233+
print_warning "Security issues found"
234+
fi
235+
else
236+
print_status "gosec not available - using go vet as security alternative"
237+
print_status "Running go vet for basic security checks..."
238+
if go vet -unsafeptr=false ./src/...; then
239+
print_success "Basic security checks passed!"
240+
else
241+
print_warning "Basic security checks found issues"
242+
fi
243+
fi
244+
fi
245+
246+
# Dependency checks
247+
echo "📦 Checking dependencies..."
248+
if command_exists go; then
249+
print_status "Checking for outdated dependencies..."
250+
if command_exists go-mod-outdated; then
251+
if go-mod-outdated -update -direct; then
252+
print_success "Dependencies are up to date!"
253+
else
254+
print_warning "Some dependencies may be outdated"
255+
fi
256+
else
257+
print_status "Checking go.mod..."
258+
if go mod verify; then
259+
print_success "Dependencies verified!"
260+
else
261+
print_error "Dependency verification failed!"
262+
exit 1
263+
fi
264+
fi
265+
fi
266+
267+
print_success "All code quality checks completed successfully!"
268+
echo "🎯 Linting completed successfully!"

src/commands.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7-
"maestro/internal/common"
87
"maestro/internal/commands"
8+
"maestro/internal/common"
99
)
1010

1111
// VDB Commands
@@ -402,13 +402,13 @@ var deprecatedCreateCmd = &cobra.Command{
402402
Short: "*** Deprecated *** Create",
403403
Long: `*** Deprecated *** Create: Use agent or tool create.`,
404404
Aliases: []string{"create"},
405-
Args: cobra.ExactArgs(1),
405+
Args: cobra.ExactArgs(1),
406406
Example: ` maestro agent/tool create yaml_file.`,
407407
RunE: func(cmd *cobra.Command, args []string) error {
408408
fmt.Println("***Deprecated Create: Use agent or tool create.***")
409409
defs, _ := common.ParseYAML(args[0])
410410
fmt.Println(defs[0]["kind"])
411-
if defs[0]["kind"] == "Agent" || defs[0]["kind"] == "MCPTool"{
411+
if defs[0]["kind"] == "Agent" || defs[0]["kind"] == "MCPTool" {
412412
options := commands.NewCommandOptions(cmd)
413413
return commands.DeprecatedCreateCommand(args[0], options)
414414
}
@@ -422,7 +422,7 @@ var deprecatedCreateCrCmd = &cobra.Command{
422422
Short: "*** Deprecated *** Create-cr",
423423
Long: `*** Deprecated *** Create-cr: Use curomresource create yaml_file.`,
424424
Aliases: []string{"create"},
425-
Args: cobra.ExactArgs(1),
425+
Args: cobra.ExactArgs(1),
426426
Example: ` maestro agent/tool create-cr yaml_file.`,
427427
RunE: func(cmd *cobra.Command, args []string) error {
428428
fmt.Println("***Deprecated Create: Use agent or tool create.***")
@@ -451,7 +451,7 @@ var deprecatedDeployCmd = &cobra.Command{
451451
Short: "*** Deprecated *** Deploy",
452452
Long: `*** Deprecated *** Deploy: Use workflow deploy.`,
453453
Aliases: []string{"deploy"},
454-
Args: cobra.MinimumNArgs(2),
454+
Args: cobra.MinimumNArgs(2),
455455
Example: ` maestro deploy agentyaml_file workflowyaml_file.`,
456456
RunE: func(cmd *cobra.Command, args []string) error {
457457
fmt.Println("***Deprecated Deploy: Use workflow deploy.***")
@@ -466,7 +466,7 @@ var deprecatedServeCmd = &cobra.Command{
466466
Short: "*** Deprecated *** Serve",
467467
Long: `*** Deprecated *** : Use workflow/agent serve.`,
468468
Aliases: []string{"serve"},
469-
Args: cobra.ExactArgs(1),
469+
Args: cobra.ExactArgs(1),
470470
Example: ` maestro serve agentyaml_file.`,
471471
RunE: func(cmd *cobra.Command, args []string) error {
472472
fmt.Println("***Deprecated Serve: Use workflow serve.***")

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ if [ "$RUN_UNIT_TESTS" = true ]; then
117117
# Run specific test files if they exist
118118
if [ -f "tests/main_test.go" ]; then
119119
print_status "Running main tests..."
120-
go test -v tests/main_test.go tests/validate_test.go tests/create_test.go tests/delete_test.go tests/list_test.go
120+
go test -v tests/main_test.go tests/test_utils.go tests/validate_test.go tests/create_test.go tests/delete_test.go tests/list_test.go
121121
fi
122122

123123
print_status "✓ Unit tests completed successfully!"

0 commit comments

Comments
 (0)