Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit f7ae224

Browse files
committed
chore(clover): add smoke test instructions for robots to test gcp
1 parent 50d07b5 commit f7ae224

9 files changed

Lines changed: 500 additions & 18 deletions

File tree

‎bin/clover/AGENTS.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,30 @@ buck2 run //bin/si:si schema upload --from-file [filepath]
3636
```
3737

3838
This will upload the spec files to make them available as schemas in System Initiative. Schemas that match components that already exist will upload as Working Copies. Existing components will need to be upgraded to take on any changes.
39+
40+
## Testing and Debugging
41+
42+
### Debugging Failed Actions
43+
44+
When an action fails (Create, Update, Delete, Discover, Import, etc.), **always check the func run logs** to understand the actual error:
45+
46+
1. Use `action-list` to find the failed action and its `funcRunId`
47+
2. Use `func-run-get` with `logs: true` and optionally `result: true` to see:
48+
- The actual error message from the cloud provider
49+
- The function execution logs showing what happened
50+
- The result/output of the function
51+
52+
Example:
53+
```
54+
# List actions to find the funcRunId
55+
action-list --changeSetId <id>
56+
57+
# Get the func run details with logs
58+
func-run-get --funcRunId <id> --logs true --result true
59+
```
60+
61+
**Important:** MCP tool errors (like schema validation errors) may hide the actual cloud provider error. Always dig into the func run logs to find the root cause.
62+
63+
### Tests to Run
64+
65+
Look in each pipeline for a smoke.md file that describes which tests to run for that provider.

‎bin/clover/src/pipelines/gcp/funcs/actions/create.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ ${errorText}`
9393
// - Compute Engine uses "kind" containing "operation"
9494
// - GKE/Container API uses "operationType" field
9595
// - Other APIs (API Keys, etc.) use "name" starting with "operations/"
96+
// - Cloud Run v2 uses "name" containing "/operations/" and has "metadata" with resource details
9697
const isLRO = (responseJson.kind && responseJson.kind.includes("operation")) ||
9798
responseJson.operationType ||
98-
(responseJson.name && responseJson.name.startsWith("operations/"));
99+
(responseJson.name && responseJson.name.startsWith("operations/")) ||
100+
(responseJson.name && responseJson.name.includes("/operations/") && responseJson.metadata);
99101
if (isLRO) {
100102
console.log(`[CREATE] LRO detected, polling for completion...`);
101103

‎bin/clover/src/pipelines/gcp/funcs/actions/refresh.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ async function refreshViaList(
6060
let listUrl = buildUrlWithParams(baseUrl, listApiPath, component, projectId, { forList: true });
6161

6262
// Handle parent as query parameter for some APIs
63+
// Only add parent if it's declared as a valid query parameter in the API
6364
if (!listUrl.includes("parent=") && !listApiPath.path.includes("{parent}") && !listApiPath.path.includes("{+parent}")) {
64-
const parentValue = resolveParamValue(component, "parent", projectId, true);
65-
if (parentValue) {
66-
listUrl += (listUrl.includes("?") ? "&" : "?") + `parent=${encodeURIComponent(parentValue)}`;
65+
const validQueryParams = listApiPath.queryParams || [];
66+
if (validQueryParams.includes("parent")) {
67+
const parentValue = resolveParamValue(component, "parent", projectId, true);
68+
if (parentValue) {
69+
listUrl += (listUrl.includes("?") ? "&" : "?") + `parent=${encodeURIComponent(parentValue)}`;
70+
}
6771
}
6872
}
6973

@@ -95,7 +99,7 @@ async function refreshViaList(
9599
for (const resource of items || []) {
96100
const resourceName = resource.name || resource.id;
97101
if (resourceName === resourceId || resourceName === domainName ||
98-
resourceName?.endsWith(`/${resourceId}`) || resourceId.endsWith(`/${resourceName}`)) {
102+
resourceName?.endsWith(`/${resourceId}`) || resourceId.endsWith(`/${resourceName}`)) {
99103
return { payload: normalizeGcpResourceValues(resource), status: "ok" };
100104
}
101105
}

‎bin/clover/src/pipelines/gcp/funcs/actions/update.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ async function main(component: Input): Promise<Output> {
3434
if (currentResource.fingerprint) {
3535
updatePayload.fingerprint = currentResource.fingerprint;
3636
}
37+
38+
// Some assets requires 'name' in the request body even for updates
39+
// Always include it from the current resource if available
40+
if (currentResource.name && !updatePayload.name) {
41+
updatePayload.name = currentResource.name;
42+
}
3743
}
3844

3945
// Try to get update API path first, fall back to patch
@@ -83,12 +89,23 @@ async function main(component: Input): Promise<Output> {
8389

8490
// Many GCP APIs require or benefit from an updateMask query parameter
8591
// that specifies which fields are being updated
86-
const updateFields = Object.keys(updatePayload).filter(k => k !== 'fingerprint');
92+
// Exclude 'fingerprint' (used for concurrency) and 'name' (required in body but immutable)
93+
const updateFields = Object.keys(updatePayload).filter(k => k !== 'fingerprint' && k !== 'name');
8794
if (updateFields.length > 0) {
8895
const updateMask = updateFields.join(',');
8996
url += (url.includes('?') ? '&' : '?') + `updateMask=${encodeURIComponent(updateMask)}`;
9097
}
9198

99+
// Some GCP APIs (like Pub/Sub) use a wrapper request type (e.g., UpdateTopicRequest)
100+
// where the payload needs to be wrapped under a specific field (e.g., "topic")
101+
// If requestWrapperField is set, wrap the payload accordingly
102+
let requestBody = updatePayload;
103+
if (updateApiPath.requestWrapperField) {
104+
requestBody = {
105+
[updateApiPath.requestWrapperField]: updatePayload,
106+
};
107+
}
108+
92109
// Make the API request with retry logic
93110
const response = await siExec.withRetry(async () => {
94111
const resp = await fetch(url, {
@@ -97,7 +114,7 @@ async function main(component: Input): Promise<Output> {
97114
"Authorization": `Bearer ${token}`,
98115
"Content-Type": "application/json",
99116
},
100-
body: JSON.stringify(updatePayload),
117+
body: JSON.stringify(requestBody),
101118
});
102119

103120
if (!resp.ok) {

‎bin/clover/src/pipelines/gcp/funcs/management/discover.ts‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ async function main({ thisComponent }: Input): Promise<Output> {
7070

7171
// Handle parent as query parameter for APIs like Resource Manager Folders
7272
// that don't use parent in the path but require it as a query parameter
73+
// Only add parent if it's declared as a valid query parameter in the API
7374
if (!listUrl.includes("parent=") && !listApiPath.path.includes("{parent}") && !listApiPath.path.includes("{+parent}")) {
74-
const parentValue = resolveParamValue(component, "parent", projectId, true);
75-
if (parentValue) {
76-
listUrl += (listUrl.includes("?") ? "&" : "?") + `parent=${encodeURIComponent(parentValue)}`;
75+
const validQueryParams = listApiPath.queryParams || [];
76+
if (validQueryParams.includes("parent")) {
77+
const parentValue = resolveParamValue(component, "parent", projectId, true);
78+
if (parentValue) {
79+
listUrl += (listUrl.includes("?") ? "&" : "?") + `parent=${encodeURIComponent(parentValue)}`;
80+
}
7781
}
7882
}
7983

@@ -148,7 +152,13 @@ async function main({ thisComponent }: Input): Promise<Output> {
148152
} else {
149153
// Try to get from discovered resource first, then fall back to domain
150154
paramValue = _.get(resource, [paramName]) ||
151-
_.get(component.properties, ["domain", paramName]);
155+
_.get(component.properties, ["domain", paramName]);
156+
157+
// GCP often returns full URLs for reference fields - extract just the resource name
158+
if (paramValue && typeof paramValue === "string" && paramValue.startsWith("https://")) {
159+
const urlParts = paramValue.split("/");
160+
paramValue = urlParts[urlParts.length - 1];
161+
}
152162
}
153163

154164
if (paramValue) {
@@ -174,15 +184,18 @@ async function main({ thisComponent }: Input): Promise<Output> {
174184

175185
const fullResource = await resourceResponse.json();
176186

187+
// Normalize the resource to convert full GCP URLs to simple values
188+
const normalizedResource = normalizeGcpResourceValues(fullResource);
189+
177190
const properties = {
178191
si: {
179192
resourceId,
180193
},
181194
domain: {
182195
...component.properties?.domain || {},
183-
...fullResource,
196+
...normalizedResource,
184197
},
185-
resource: fullResource,
198+
resource: normalizedResource,
186199
};
187200

188201
// Apply refinement filter

‎bin/clover/src/pipelines/gcp/funcs/shared/utils.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function isFullResourcePath(resourceId: string, pathTemplate: string): boolean {
157157

158158
function buildUrlWithParams(
159159
baseUrl: string,
160-
apiPath: { path: string; parameterOrder?: string[] },
160+
apiPath: { path: string; parameterOrder?: string[]; queryParams?: string[] },
161161
component: Input,
162162
projectId: string | undefined,
163163
options: { resourceId?: string; forList?: boolean } = {}
@@ -187,6 +187,10 @@ function buildUrlWithParams(
187187
if (paramValue) {
188188
// Handle {+param} (reserved expansion - don't encode, allows slashes)
189189
if (url.includes(`{+${paramName}}`)) {
190+
// For {+project}, if paramValue doesn't start with "projects/", prepend it
191+
if ((paramName === "project" || paramName === "projectId") && !paramValue.startsWith("projects/")) {
192+
paramValue = `projects/${paramValue}`;
193+
}
190194
url = url.replace(`{+${paramName}}`, paramValue);
191195
} else if (url.includes(`{${paramName}}`)) {
192196
// Handle {param} (simple expansion - encode)
@@ -197,13 +201,24 @@ function buildUrlWithParams(
197201
}
198202
}
199203
}
204+
}
200205

201-
// Add query parameters if any
202-
if (queryParams.length > 0) {
203-
url += `?${queryParams.join("&")}`;
206+
// Handle additional query parameters (e.g., serviceId for Cloud Run)
207+
// These are parameters defined with location: "query" in the API spec
208+
if (apiPath.queryParams) {
209+
for (const paramName of apiPath.queryParams) {
210+
const paramValue = resolveParamValue(component, paramName, projectId, options.forList);
211+
if (paramValue) {
212+
queryParams.push(`${paramName}=${encodeURIComponent(paramValue)}`);
213+
}
204214
}
205215
}
206216

217+
// Add query parameters if any
218+
if (queryParams.length > 0) {
219+
url += `?${queryParams.join("&")}`;
220+
}
221+
207222
// Fail fast if URL still contains unresolved placeholders
208223
// This catches cases where required parameters (like location in parent) are missing
209224
const unresolvedMatches = [...url.matchAll(/\{[+]?([^}]+)\}/g)];

‎bin/clover/src/pipelines/gcp/pipeline-steps/addDefaultProps.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,27 @@ export function addDefaultProps(specs: ExpandedPkgSpec[]): ExpandedPkgSpec[] {
7676
false,
7777
);
7878
insertProp.data.hidden = true;
79+
80+
// Collect query parameters for the insert method
81+
// These are parameters with location: "query" that need to be added to the URL
82+
const queryParams: string[] = [];
83+
if (gcpSchema.methods.insert.parameters) {
84+
for (
85+
const [paramName, paramDef] of Object.entries(
86+
gcpSchema.methods.insert.parameters,
87+
)
88+
) {
89+
if (paramDef.location === "query") {
90+
queryParams.push(paramName);
91+
}
92+
}
93+
}
94+
7995
insertProp.data.defaultValue = JSON.stringify({
8096
path: gcpSchema.methods.insert.path,
8197
httpMethod: gcpSchema.methods.insert.httpMethod,
8298
parameterOrder: gcpSchema.methods.insert.parameterOrder,
99+
...(queryParams.length > 0 ? { queryParams } : {}),
83100
});
84101
extraProp.entries.push(insertProp);
85102
}
@@ -108,10 +125,25 @@ export function addDefaultProps(specs: ExpandedPkgSpec[]): ExpandedPkgSpec[] {
108125
false,
109126
);
110127
patchProp.data.hidden = true;
128+
129+
// Detect if the patch request uses a wrapper type (e.g., UpdateTopicRequest)
130+
// Wrapper types have a field that contains the resource (e.g., "topic") and an "updateMask" field
131+
// If detected, store the wrapper field name so the update action can wrap the payload
132+
let requestWrapperField: string | undefined;
133+
const patchRequest = gcpSchema.methods.patch.request;
134+
if (patchRequest?.properties) {
135+
const props = Object.keys(patchRequest.properties);
136+
// A wrapper type has exactly 2 properties: the resource wrapper field and updateMask
137+
if (props.length === 2 && props.includes("updateMask")) {
138+
requestWrapperField = props.find((p) => p !== "updateMask");
139+
}
140+
}
141+
111142
patchProp.data.defaultValue = JSON.stringify({
112143
path: gcpSchema.methods.patch.path,
113144
httpMethod: gcpSchema.methods.patch.httpMethod,
114145
parameterOrder: gcpSchema.methods.patch.parameterOrder,
146+
...(requestWrapperField ? { requestWrapperField } : {}),
115147
});
116148
extraProp.entries.push(patchProp);
117149
}
@@ -134,6 +166,20 @@ export function addDefaultProps(specs: ExpandedPkgSpec[]): ExpandedPkgSpec[] {
134166
}
135167

136168
if (gcpSchema.methods.list) {
169+
// Extract query parameters from the list method
170+
const queryParams: string[] = [];
171+
if (gcpSchema.methods.list.parameters) {
172+
for (
173+
const [paramName, paramDef] of Object.entries(
174+
gcpSchema.methods.list.parameters,
175+
)
176+
) {
177+
if (paramDef.location === "query") {
178+
queryParams.push(paramName);
179+
}
180+
}
181+
}
182+
137183
const listProp = createScalarProp(
138184
"listApiPath",
139185
"string",
@@ -144,6 +190,7 @@ export function addDefaultProps(specs: ExpandedPkgSpec[]): ExpandedPkgSpec[] {
144190
listProp.data.defaultValue = JSON.stringify({
145191
path: gcpSchema.methods.list.path,
146192
parameterOrder: gcpSchema.methods.list.parameterOrder,
193+
queryParams: queryParams, // Store valid query parameters
147194
});
148195
extraProp.entries.push(listProp);
149196
}
@@ -237,6 +284,21 @@ export function addDefaultProps(specs: ExpandedPkgSpec[]): ExpandedPkgSpec[] {
237284
pathParamsSet.add("location");
238285
}
239286

287+
// Add query parameters from insert method to pathParameters
288+
// These are URL params that should NOT be included in the request body
289+
// (e.g., serviceId for Cloud Run services)
290+
if (gcpSchema.methods.insert?.parameters) {
291+
for (
292+
const [paramName, param] of Object.entries(
293+
gcpSchema.methods.insert.parameters,
294+
)
295+
) {
296+
if (param.location === "query") {
297+
pathParamsSet.add(paramName);
298+
}
299+
}
300+
}
301+
240302
const propUsageMap: PropUsageMap = {
241303
createOnly: [],
242304
updatable: [],

0 commit comments

Comments
 (0)