Skip to content

Commit 1c308a5

Browse files
omerdemirokactions-user
authored andcommitted
add scripts for creating linear tickets for gcp dynamic adapters (#2662)
Add some tools for better AI integration for GCP adapter development. GitOrigin-RevId: 297e1a351ab3c82801d180788dcbf547ac748a4d
1 parent 50dc11c commit 1c308a5

File tree

8 files changed

+762
-110
lines changed

8 files changed

+762
-110
lines changed

sources/gcp/dynamic/adapters/.cursor/rules/dynamic-adapter-creation.md renamed to sources/gcp/dynamic/adapters/.cursor/rules/dynamic-adapter-creation.mdc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
description: "GCP Dynamic Adapter development patterns and standards"
3+
globs: **/*.go
4+
alwaysApply: false
5+
---
6+
17
# Dynamic Adapter Creation Rules
28

39
## Overview

sources/gcp/dynamic/adapters/.cursor/rules/dynamic-adapter-testing.md renamed to sources/gcp/dynamic/adapters/.cursor/rules/dynamic-adapter-testing.mdc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
description: "GCP Dynamic Adapter unit testing patterns and standards"
3+
globs: **/*_test.go
4+
---
5+
16
# Dynamic Adapter Unit Testing Rules
27
## Overview
38

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# Dynamic Adapter AI Tools
2+
3+
This directory contains tools for generating prompts and tickets for dynamic adapter development and testing.
4+
5+
## Files
6+
7+
- `generate-test-ticket-cmd/` - Go implementation for generating Linear ticket content for dynamic adapter unit tests
8+
- `generate-adapter-ticket-cmd/` - Go implementation for generating Linear ticket content for creating new dynamic adapters
9+
- `build.sh` - Build script for both tools
10+
- `README.md` - This documentation
11+
12+
## Related Files
13+
14+
- `../adapters/.cursor/rules/dynamic-adapter-testing.md` - Cursor agent rules for writing adapter tests
15+
- `../adapters/.cursor/rules/dynamic-adapter-creation.md` - Cursor agent rules for creating new adapters
16+
- `../adapters/` - Directory containing dynamic adapter implementations
17+
18+
## generate-adapter-ticket
19+
20+
### Purpose
21+
Generates complete Linear ticket content for creating new dynamic adapters. This tool helps create comprehensive tickets for implementing new GCP resource adapters with proper context and requirements.
22+
23+
### Usage
24+
```bash
25+
# Run directly with go run
26+
go run generate-adapter-ticket-cmd/main.go -name <adapter-name> -api-ref <api-reference-url> [-type-ref <type-reference-url>] [--verbose]
27+
28+
# Or build and run
29+
./build.sh
30+
./generate-adapter-ticket -name <adapter-name> -api-ref <api-reference-url> [-type-ref <type-reference-url>] [--verbose]
31+
32+
# Build for specific platform
33+
./build.sh linux/amd64
34+
./build.sh darwin/arm64
35+
```
36+
37+
### Examples
38+
```bash
39+
# Generate ticket for monitoring alert policy adapter
40+
go run generate-adapter-ticket-cmd/main.go -name monitoring-alert-policy -api-ref "https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.alertPolicies"
41+
42+
# Generate ticket with type reference
43+
go run generate-adapter-ticket-cmd/main.go -name compute-instance-template -api-ref "https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates" -type-ref "https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates#InstanceTemplate"
44+
45+
# Generate with verbose output
46+
go run generate-adapter-ticket-cmd/main.go --verbose -name storage-bucket -api-ref "https://cloud.google.com/storage/docs/json_api/v1/buckets"
47+
```
48+
49+
### What it does
50+
1. **Create Linear ticket** for new adapter implementation
51+
2. **Generate comprehensive context** with API references
52+
3. **Include implementation checklist** following dynamic adapter patterns
53+
4. **Reference Cursor rules** for consistent implementation
54+
5. **Copy description to clipboard** and optionally print it
55+
56+
### Output
57+
The tool generates a Linear URL with pre-filled fields and copies the description to clipboard. The description includes:
58+
- Task overview
59+
- API references
60+
- Files to create
61+
- Implementation instructions referencing Cursor rules
62+
63+
## generate-test-ticket
64+
65+
### Purpose
66+
Generates complete Linear ticket content for creating unit tests for dynamic adapters. The Go implementation provides better maintainability, type safety, and cross-platform compatibility.
67+
68+
### Usage
69+
```bash
70+
# Run directly with go run
71+
go run generate-test-ticket-cmd/main.go [--verbose|-v] <adapter-name>
72+
73+
# Or build and run
74+
./build.sh
75+
./generate-test-ticket [--verbose|-v] <adapter-name>
76+
77+
# Build for specific platform
78+
./build.sh linux/amd64
79+
./build.sh darwin/arm64
80+
81+
# Build specific tool only
82+
./build.sh "" generate-test-ticket
83+
./build.sh linux/amd64 generate-test-ticket
84+
```
85+
86+
### Examples
87+
```bash
88+
# Generate ticket for compute global forwarding rule (quiet mode)
89+
go run generate-test-ticket-cmd/main.go compute-global-forwarding-rule
90+
91+
# Generate ticket with verbose output (shows description)
92+
go run generate-test-ticket-cmd/main.go --verbose compute-global-forwarding-rule
93+
94+
# Short form of verbose flag
95+
go run generate-test-ticket-cmd/main.go -v compute-global-address
96+
```
97+
98+
### What it does
99+
1. **Extract adapter information** from the adapter file in `../adapters/`
100+
2. **Determine protobuf types** based on adapter name patterns
101+
3. **Extract blast propagation** configuration from the adapter
102+
4. **Generate a Linear URL** with basic fields pre-filled:
103+
- Title: "Write unit test for {adapter-name} dynamic adapter"
104+
- Assignee: Cursor Agent
105+
- Project: GCP Source Improvements
106+
- Cycle: This
107+
- Size: Small (2 points)
108+
- Status: Todo
109+
- Milestone: Quality Improvements
110+
5. **Copy description to clipboard** and optionally print it
111+
112+
### Output
113+
The tool generates a Linear URL with basic fields and copies the description to clipboard. In verbose mode (`--verbose` or `-v`), it also prints the complete description for review.
114+
115+
### Requirements
116+
- Must be run from the `prompter` directory
117+
- Adapter file must exist in `../adapters/`
118+
- Adapter file must contain valid SDP item type and blast propagation configuration
119+
- Go 1.19+ required
120+
121+
## Integration with Cursor Agents
122+
123+
The generated tickets work seamlessly with:
124+
- **Cursor rules** in `../adapters/.cursor/rules/dynamic-adapter-testing.md`
125+
- **Existing test patterns** from `../adapters/compute-global-address_test.go`
126+
- **Comprehensive testing requirements** for Get, List, and Search functionality
127+
128+
## Workflow
129+
130+
### Creating New Adapters
131+
132+
#### Quick Mode (default)
133+
1. **Generate Linear URL** using `generate-adapter-ticket`
134+
2. **Click the URL** to create a new Linear issue with basic fields pre-filled
135+
3. **Paste the description** (already copied to clipboard) into the issue
136+
4. **Save the issue** - it's ready for implementation
137+
138+
#### Review Mode (verbose)
139+
1. **Generate Linear URL** using `generate-adapter-ticket --verbose`
140+
2. **Review the description** printed in the output
141+
3. **Click the URL** to create a new Linear issue with basic fields pre-filled
142+
4. **Paste the description** (already copied to clipboard) into the issue
143+
5. **Save the issue** - it's ready for implementation
144+
145+
### Creating Tests for Existing Adapters
146+
147+
#### Quick Mode (default)
148+
1. **Generate Linear URL** using `generate-test-ticket`
149+
2. **Click the URL** to create a new Linear issue with basic fields pre-filled
150+
3. **Paste the description** (already copied to clipboard) into the issue
151+
4. **Save the issue** - it's already assigned to Cursor Agent
152+
153+
#### Review Mode (verbose)
154+
1. **Generate Linear URL** using `generate-test-ticket --verbose` or `-v` flag
155+
2. **Review the description** printed in the output
156+
3. **Click the URL** to create a new Linear issue with basic fields pre-filled
157+
4. **Paste the description** (already copied to clipboard) into the issue
158+
5. **Save the issue** - it's already assigned to Cursor Agent
159+
160+
### Cursor Agent Execution
161+
When a Cursor agent picks up the ticket:
162+
1. It will automatically apply the rules from `../adapters/.cursor/rules/dynamic-adapter-testing.md`
163+
2. Follow the comprehensive testing patterns
164+
3. Create the test file with proper structure
165+
4. Include all required test cases (Get, List, Search if supported)
166+
5. Add proper blast propagation tests
167+
168+
## Example Ticket Content
169+
170+
For `compute-global-forwarding-rule`:
171+
172+
**Title**: `Write unit test for compute-global-forwarding-rule dynamic adapter`
173+
174+
**Key Details**:
175+
- **SDP Item Type**: `gcpshared.ComputeGlobalForwardingRule`
176+
- **Protobuf Types**: `computepb.ForwardingRule` and `computepb.ForwardingRuleList`
177+
- **API Endpoints**:
178+
- GET: `https://compute.googleapis.com/compute/v1/projects/{project}/global/forwardingRules/{forwardingRule}`
179+
- LIST: `https://compute.googleapis.com/compute/v1/projects/{project}/global/forwardingRules`
180+
- **Blast Propagation**: network (InOnly), subnetwork (InOnly), IPAddress (BothWays), backendService (BothWays)
181+
182+
## Benefits
183+
184+
1. **Consistency**: All tests follow the same patterns and structure
185+
2. **Completeness**: Comprehensive coverage of Get, List, and Search functionality
186+
3. **Automation**: Cursor agents can automatically generate high-quality tests
187+
4. **Documentation**: Clear requirements and acceptance criteria
188+
5. **Maintainability**: Standardized approach makes tests easier to maintain
189+
190+
## Adding New Adapters
191+
192+
### Complete Workflow for New Adapters
193+
194+
#### Step 1: Create Implementation Ticket
195+
1. Run `go run generate-adapter-ticket-cmd/main.go -name my-new-adapter -api-ref "https://api-reference-url"`
196+
2. Click the generated URL to create Linear issue with pre-filled fields
197+
3. Paste the description (copied to clipboard) into the issue
198+
4. Save the issue - it's ready for implementation
199+
200+
#### Step 2: Implement the Adapter
201+
The Cursor agent (or developer) will:
202+
1. Follow the rules in `../adapters/.cursor/rules/dynamic-adapter-creation.md`
203+
2. Create the adapter file (e.g., `my-new-adapter.go`)
204+
3. Add any necessary SDP item types to `../shared/item-types.go` and `../shared/models.go`
205+
206+
#### Step 3: Create Test Ticket
207+
1. Run `go run generate-test-ticket-cmd/main.go my-new-adapter` to generate test ticket content
208+
2. Click the generated URL to create Linear issue with pre-filled fields
209+
3. Paste the description (copied to clipboard) into the issue
210+
4. Save the issue - it's already assigned to Cursor Agent
211+
212+
### Quick Testing for Existing Adapters
213+
214+
When you just need tests for an existing adapter:
215+
1. Run `go run generate-test-ticket-cmd/main.go existing-adapter-name`
216+
2. Click the generated URL to create Linear issue with pre-filled fields
217+
3. Paste the description (copied to clipboard) into the issue
218+
4. Save the issue - it's already assigned to Cursor Agent
219+
220+
## Rules Application
221+
222+
### For Adapter Creation
223+
The `../adapters/.cursor/rules/dynamic-adapter-creation.md` file ensures that:
224+
- Proper adapter structure and patterns are followed
225+
- Correct SDP item types and metadata are defined
226+
- Appropriate blast propagation is configured
227+
- Terraform mappings are included when applicable
228+
- IAM permissions are properly defined
229+
230+
### For Test Creation
231+
The `../adapters/.cursor/rules/dynamic-adapter-testing.md` file ensures that:
232+
- All tests use the correct package (`adapters_test`)
233+
- Proper imports are included
234+
- Correct protobuf types are used
235+
- Comprehensive test coverage is provided
236+
- Static tests with blast propagation are included
237+
- Common mistakes are avoided
238+
239+
This ensures consistent, high-quality implementations and unit tests for all dynamic adapters.
240+
241+
## Quick Reference
242+
243+
### Building Tools
244+
```bash
245+
# Build both tools for current platform
246+
./build.sh
247+
248+
# Build for specific platform
249+
./build.sh linux/amd64
250+
251+
# Build specific tool only
252+
./build.sh "" generate-adapter-ticket
253+
./build.sh "" generate-test-ticket
254+
```
255+
256+
### Creating New Adapter
257+
```bash
258+
# Generate implementation ticket
259+
go run generate-adapter-ticket-cmd/main.go -name my-adapter -api-ref "https://api-url"
260+
261+
# After implementation, generate test ticket
262+
go run generate-test-ticket-cmd/main.go my-adapter
263+
```
264+
265+
### Testing Existing Adapter
266+
```bash
267+
# Generate test ticket
268+
go run generate-test-ticket-cmd/main.go existing-adapter-name
269+
```
270+
271+
Both tools support `--verbose` flag to preview the description before creating tickets.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# Build script for prompter tools
4+
# Usage: ./build.sh [platform] [tool]
5+
# Examples:
6+
# ./build.sh # Build both tools for current platform
7+
# ./build.sh linux/amd64 # Build both tools for Linux AMD64
8+
# ./build.sh darwin/arm64 # Build both tools for macOS ARM64
9+
# ./build.sh "" generate-test-ticket # Build only generate-test-ticket for current platform
10+
# ./build.sh linux/amd64 generate-adapter-ticket # Build only generate-adapter-ticket for Linux AMD64
11+
12+
set -e
13+
14+
# Check if Go is installed
15+
if ! command -v go &> /dev/null; then
16+
echo "Error: Go is not installed or not in PATH"
17+
exit 1
18+
fi
19+
20+
PLATFORM="${1:-}"
21+
TOOL="${2:-}"
22+
23+
# Define available tools
24+
TOOLS=("generate-test-ticket" "generate-adapter-ticket")
25+
26+
# If specific tool requested, validate it
27+
if [ -n "$TOOL" ]; then
28+
if [[ ! " ${TOOLS[@]} " =~ " ${TOOL} " ]]; then
29+
echo "Error: Unknown tool '$TOOL'. Available tools: ${TOOLS[*]}"
30+
exit 1
31+
fi
32+
TOOLS=("$TOOL")
33+
fi
34+
35+
# Build function
36+
build_tool() {
37+
local tool="$1"
38+
local platform="$2"
39+
local source_dir="${tool}-cmd"
40+
local binary_name="$tool"
41+
42+
if [ ! -d "$source_dir" ]; then
43+
echo "Error: Source directory '$source_dir' not found"
44+
return 1
45+
fi
46+
47+
if [ -z "$platform" ]; then
48+
echo "Building $binary_name for current platform..."
49+
go build -o "$binary_name" "./$source_dir"
50+
echo "✅ Built successfully: $binary_name"
51+
else
52+
echo "Building $binary_name for $platform..."
53+
54+
# Split platform into GOOS and GOARCH
55+
IFS='/' read -r GOOS GOARCH <<< "$platform"
56+
57+
if [ -z "$GOOS" ] || [ -z "$GOARCH" ]; then
58+
echo "Error: Invalid platform format. Use: os/arch (e.g., linux/amd64)"
59+
return 1
60+
fi
61+
62+
OUTPUT_NAME="${binary_name}-${GOOS}-${GOARCH}"
63+
if [ "$GOOS" = "windows" ]; then
64+
OUTPUT_NAME="${OUTPUT_NAME}.exe"
65+
fi
66+
67+
GOOS="$GOOS" GOARCH="$GOARCH" go build -o "$OUTPUT_NAME" "./$source_dir"
68+
echo "✅ Built successfully: $OUTPUT_NAME"
69+
fi
70+
}
71+
72+
# Build all requested tools
73+
for tool in "${TOOLS[@]}"; do
74+
build_tool "$tool" "$PLATFORM"
75+
done
76+
77+
echo ""
78+
echo "Built tools:"
79+
for tool in "${TOOLS[@]}"; do
80+
echo " $tool"
81+
done
82+
83+
echo ""
84+
echo "Usage examples:"
85+
echo " ./generate-test-ticket [--verbose|-v] <adapter-name>"
86+
echo " ./generate-adapter-ticket -name monitoring-alert-policy -api-ref https://..."
87+
echo ""
88+
echo "For more information, see README.md"

0 commit comments

Comments
 (0)