Skip to content

Commit 2088314

Browse files
committed
Merge branch 'GoogleCloudPlatform:main' into online_evals
2 parents 9a9cd1e + 7403c01 commit 2088314

87 files changed

Lines changed: 5750 additions & 838 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/TGC_WORKFLOWS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# TGC Resource Main Loop
2+
3+
This document serves as the entry point for TGC (Terraform Google Conversion) development workflows.
4+
5+
Depending on your specific task, please refer to and strictly follow the appropriate workflow file:
6+
7+
- **For Adding a New Resource**: Follow the workflow defined in [tgc_add.md](tgc_add.md).
8+
- **For Fixing a Resource or Test Failure**: Follow the workflow defined in [tgc_fix.md](tgc_fix.md).
9+
10+
Please ensure you follow the sequence of phases and mandatory skill checks specified in those files.
11+
12+
## Error Reporting Template
13+
14+
If a failure is detected or provided, you **MUST** report it using the following template before proceeding.
15+
16+
```markdown
17+
# Error Report
18+
19+
## Failed Command
20+
`[Paste the exact command that failed here]`
21+
22+
## Detailed Logs
23+
```
24+
[Paste relevant log snippets or error messages here]
25+
```
26+
27+
## Analysis
28+
[Provide a detailed analysis of the failure. Explain what happened, which stage of the workflow failed, and why.]
29+
30+
## Tracing Evidence (Required for Integration Test failures only)
31+
[Cite specific lines or file contents from `Test_export.tf`, `Test_roundtrip.json`, or `Test_roundtrip.tf` to prove at which stage the data was lost.]
32+
33+
## Proposed Solution
34+
[Describe the proposed solution to fix the failure. Include file paths and code changes if known.]
35+
36+
> [!IMPORTANT]
37+
> I have stopped execution and am waiting for your approval to proceed with this solution.
38+
```
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
trigger: always_on
3+
description: Always-on system prompt for TGC development
4+
---
5+
6+
---
7+
trigger: always_on
8+
description: Enforce TGC development Rules
9+
---
10+
11+
# Environment Setup Rule
12+
Before proceeding to Phase 2 (Implementation) or running any tests, the agent MUST execute a command to verify that `TGC_DIR` is set to the active downstream TGC directory and print its value in the chat. Failure to do so is a violation of process.
13+
14+
The agent MUST run the `tgc-sync-provider` skill during Phase 1 (Session Setup) before Phase 2, to ensure the downstream repository is aligned with Magic Modules.
15+
16+
# TGC development Rules
17+
18+
As an AI agent operating in this repository, you must **ALWAYS** follow these steps before attempting to add a new resource/field to TGC:
19+
20+
1. **[MANDATORY WORKFLOW ENTRYPOINT]**: At the very start of any session (Phase 1: Session Setup), the agent MUST execute the `view_file` tool on `.agents/TGC_WORKFLOWS.md`, and either `.agents/tgc_add.md` or `.agents/tgc_fix.md` depending on the task. The agent MUST print a summary of these entrypoints in their first response and list them as checked items in `task.md`. Failure to call `view_file` on these files in Phase 1 is a fatal process violation.
21+
22+
2. In the magic-modules repository, don't run command `go test` or `go mod tidy`.
23+
24+
3. In the downstream TGC repository, don't run command `go test`.
25+
26+
27+
4. To fix the failed TGC integration tests
28+
- **don't** modify the templates in `mmv1/templates/terraform`. It is allowed to modify the templates in `mmv1/templates/tgc_next`.
29+
- **don't** add ignore_read_extra to example in Resource.yaml
30+
- **don't** add new fields to mmv1/api/resource/custom_code.go unless it is guided by the user
31+
- **don't** remove any existing custom_code, including any constants
32+
- **don't** change the schema of a resource (e.g., making a Required field Optional or a Set) to fix conversion failures, unless explicitly guided by the user.
33+
- **don't** remove `exclude_test: true` from examples in resource YAML files to force test generation for TGC, as this may break tests in the standard Terraform provider.
34+
35+
36+
5. Only commit files under the `mmv1` folder in the branch, and exclude scratch files like `.txt`, `.py`, and `.sh` from commits.
37+
38+
6. DO NOT make changes directly in the downstream repository (`terraform-google-conversion`). All changes must be driven through Magic Modules (`mmv1/`).
39+
40+
7. You must strictly follow the sequence of phases defined in `.agents/tgc_add.md` or `.agents/tgc_fix.md` depending on whether you are adding a resource or fixing a failure (Session Setup -> Implementation -> Unit Testing -> Integration Testing). Code generation (Phase 2) MUST be performed before unit tests (Phase 3), and unit tests MUST be performed before integration tests (Phase 5). Structure your `task.md` to reflect these phases.
41+
42+
8. For any failure (build, unit test, integration test, or verification), stop execution immediately after reporting the error using the template in .agents/TGC_WORKFLOWS.md. Do not proceed with applying any fixes or running subsequent steps until the user has explicitly approved the proposed solution in the chat.
43+
44+
9. **Prioritize process reporting**: If the user's request involves a test failure (input or discovered), you must follow the reporting template specified in `.agents/TGC_WORKFLOWS.md` before proceeding with planning or execution.
45+
46+
10. **Integration Test Subtests**: When running integration tests using `run_integration_test.sh`, if the test name contains an underscore (e.g., `TestAccContainerCluster_withAutopilotClusterPolicy`), it is likely a subtest. You MUST verify if it expects the format `ParentTest/SubTest` (e.g., `TestAccContainerCluster/TestAccContainerCluster_withAutopilotClusterPolicy`) and pass it accordingly as documented in `.agents/TGC_WORKFLOWS.md`. For new resources, you MUST run the top-level test (e.g., `TestAccGKEHub2Feature`) instead of a specific subtest, as the top-level test will cover all of the subtests.
47+
48+
11. **Mandatory Skill Reading for Specialized Tasks**: Before proposing an implementation plan or making code changes for a resource identified as handwritten or generated, you MUST:
49+
- Identify the resource type.
50+
- Add a specific task item to `task.md` to read the corresponding skill (e.g., `tgc-fix-handwritten-resources-tests-skill`).
51+
- Execute the `view_file` tool on that skill and mark the task as completed in `task.md`. **Note: Notwithstanding general Planning Mode instructions, you are authorized and required to create `task.md` during Phase 1 (Session Setup) to track these mandatory steps.**
52+
Failure to perform the reading step strictly before planning is a violation of process.
53+
54+
12. **Skill Reading Before Proposing Solutions**: The agent MUST NOT propose a solution in the error report or create an implementation plan until it has executed the `view_file` tool on the mandatory skill corresponding to the resource type (either `tgc-fix-handwritten-resources-tests-skill` or `tgc-fix-integration-tests-skill`).
55+
56+
13. **Field Ordering in YAML Files**: When adding or modifying fields in Magic Modules YAML files (e.g., `include_in_tgc_next`, `tgc_decoder`), you MUST ensure they follow the order of fields defined in the `Resource` struct in `mmv1/api/resource.go`.
57+
58+
14. **Tracing Evidence for Integration Tests**: For **integration test failures**, the agent MUST NOT propose a solution or apply a fix until it has explicitly cited evidence from the intermediate files (`Test_export.tf`, `Test_roundtrip.json`, etc.) in the chat to demonstrate tracing.
59+
60+
15. **Mandatory Tracing Checklist**: When fixing integration test failures, the agent MUST include explicit sub-items in `task.md` to track the verification of `Test_roundtrip.tf`, `Test_roundtrip.json`, and `Test_export.tf`.
61+
62+
16. **Run All Failed Tests Before Analysis**: When fixing integration test failures, the agent MUST run all failed integration tests for the affected resource before analyzing the failure or proposing a solution.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import os
4+
import re
5+
6+
def extract_field_value(yaml_file_path, field_name):
7+
"""Extracts the string value of a top-level field in a YAML file using regex."""
8+
# Matches field_name followed by optional quotes, capturing value
9+
pattern = re.compile(r'^' + re.escape(field_name) + r'\s*:\s*[\'"]?([^\'"]+)[\'"]?')
10+
with open(yaml_file_path, "r") as f:
11+
for line in f:
12+
match = pattern.match(line.strip())
13+
if match:
14+
return match.group(1).strip()
15+
return None
16+
17+
def main():
18+
if len(sys.argv) < 2:
19+
print("Usage: check_redundant_cai_overrides.py <resource-yaml-file>", file=sys.stderr)
20+
sys.exit(1)
21+
22+
resource_yaml = sys.argv[1]
23+
if not os.path.exists(resource_yaml):
24+
print(f"Error: Resource YAML file not found at {resource_yaml}", file=sys.stderr)
25+
sys.exit(1)
26+
27+
cai_override = extract_field_value(resource_yaml, "cai_asset_name_format")
28+
if not cai_override:
29+
# No override specified, so it's perfectly clean!
30+
print(f"✅ No cai_asset_name_format override specified in {os.path.basename(resource_yaml)} (Clean).")
31+
sys.exit(0)
32+
33+
id_format = extract_field_value(resource_yaml, "id_format")
34+
if not id_format:
35+
print(f"Warning: id_format not found in {resource_yaml}. Skipping redundancy check.", file=sys.stderr)
36+
sys.exit(0)
37+
38+
# Standardize by stripping any leading/trailing slashes and standard prefixes
39+
def normalize(val):
40+
val = val.strip().strip("/")
41+
# Remove potential leading domain/service name if full URL was passed
42+
val = re.sub(r'^(https?://)?([a-zA-Z0-9.-]+\.googleapis\.com/)?', '', val)
43+
return val
44+
45+
norm_cai_override = normalize(cai_override)
46+
norm_id_format = normalize(id_format)
47+
48+
if norm_cai_override == norm_id_format:
49+
print(f"❌ REDUNDANT CAI OVERRIDE DETECTED in {resource_yaml}:", file=sys.stderr)
50+
print(f" cai_asset_name_format: '{cai_override}'", file=sys.stderr)
51+
print(f" id_format: '{id_format}'", file=sys.stderr)
52+
print("\nThis override is identical to the default computed format and can be safely removed.", file=sys.stderr)
53+
sys.exit(1)
54+
55+
print(f"✅ Verification passed: cai_asset_name_format override is custom and non-redundant.")
56+
sys.exit(0)
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
 (0)