Repository navigation
Conversation
#HTTPDo only allowed GET, POST, PUT and DELETE, so a PATCH, HEAD or OPTIONS request failed CUE validation although the provider passes the method straight to the Go client. The method field of the http provider, the legacy op.#HTTPDo provider and the request step definition now accepts GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE and PATCH, still defaulting to GET. #HTTPPatch, #HTTPHead and #HTTPOptions join the existing method definitions in both providers. No Go change is needed. The method tests now record the method the server receives, since a HEAD response has no body, and cover the new definitions for both providers. Fixes kubevela#295 Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Now that the request step accepts HEAD, a successful HEAD response would fail in json.Unmarshal because it has no body. The same applies to 204 and other empty responses. Only decode a non-empty body, and cover empty and JSON responses with tests. Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #340 +/- ##
===========================================
+ Coverage 62.49% 80.64% +18.15%
===========================================
Files 62 88 +26
Lines 4415 7053 +2638
===========================================
+ Hits 2759 5688 +2929
- Misses 1324 1365 +41
+ Partials 332 0 -332
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
3 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/providers/http/method_cue_test.go">
<violation number="1" location="pkg/providers/http/method_cue_test.go:59">
P3: This change removes the only assertion of `$returns.body` propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.</violation>
</file>
<file name="pkg/providers/http/request_definition_test.go">
<violation number="1" location="pkg/providers/http/request_definition_test.go:57">
P2: The request-step method matrix omits `CONNECT`, `TRACE`, and `PATCH`, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.</violation>
<violation number="2" location="pkg/providers/http/request_definition_test.go:81">
P2: This test never verifies the waiting contract: a broken `wait.continue` value would still pass because it checks only `response` absence. Assert that `wait.continue` evaluates to false.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.
View guided diff | Re-trigger cubic
| status int | ||
| wantResponse bool | ||
| }{ | ||
| "HEAD has no body": {method: "HEAD", status: 200}, |
There was a problem hiding this comment.
P2: The request-step method matrix omits CONNECT, TRACE, and PATCH, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/request_definition_test.go, line 57:
<comment>The request-step method matrix omits `CONNECT`, `TRACE`, and `PATCH`, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.</comment>
<file context>
@@ -0,0 +1,82 @@
+ status int
+ wantResponse bool
+ }{
+ "HEAD has no body": {method: "HEAD", status: 200},
+ "204 has no body": {method: "DELETE", status: 204},
+ "empty 200": {method: "OPTIONS", status: 200},
</file context>
| func TestRequestStepBeforeResponse(t *testing.T) { | ||
| v := cuecontext.New().CompileString(requestStepTemplate(t) + "\nparameter: {url: \"http://x\", method: \"HEAD\"}\n") | ||
| require.NoError(t, v.Err()) | ||
| require.False(t, v.LookupPath(cue.ParsePath("response")).Exists()) |
There was a problem hiding this comment.
P2: This test never verifies the waiting contract: a broken wait.continue value would still pass because it checks only response absence. Assert that wait.continue evaluates to false.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/request_definition_test.go, line 81:
<comment>This test never verifies the waiting contract: a broken `wait.continue` value would still pass because it checks only `response` absence. Assert that `wait.continue` evaluates to false.</comment>
<file context>
@@ -0,0 +1,82 @@
+func TestRequestStepBeforeResponse(t *testing.T) {
+ v := cuecontext.New().CompileString(requestStepTemplate(t) + "\nparameter: {url: \"http://x\", method: \"HEAD\"}\n")
+ require.NoError(t, v.Err())
+ require.False(t, v.LookupPath(cue.ParsePath("response")).Exists())
+}
</file context>
| require.NoError(t, v.Err()) | ||
| out, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call"))) | ||
| got = "" | ||
| _, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call"))) |
There was a problem hiding this comment.
P3: This change removes the only assertion of $returns.body propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/method_cue_test.go, line 59:
<comment>This change removes the only assertion of `$returns.body` propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.</comment>
<file context>
@@ -34,27 +34,31 @@ import (
require.NoError(t, v.Err())
- out, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))
+ got = ""
+ _, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))
require.NoError(t, err)
- body, err := out.LookupPath(cue.ParsePath("$returns.body")).String()
</file context>
Description of your changes
#HTTPDoonly allowed GET/POST/PUT/DELETE, so PATCH, HEAD and OPTIONS requests failed CUE validation even though the provider passes the method straight through to the Go client. This widensmethodto GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE and PATCH (default still GET) in the http provider, the legacyop.#HTTPDoprovider and therequeststep definition in the chart, and adds#HTTPPatch,#HTTPHeadand#HTTPOptionsto both providers. No Go changes were needed outside tests.The
requeststep always ranjson.Unmarshalon the response body, so a successful HEAD request (or any empty response, such as a 204) would fail the step. It now decodes only a non-empty body, andresponseis left unset otherwise.Fixes #295
I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
The method tests for both providers send each method definition's request to an
httptest.Serverand check the method the server received. They now cover PATCH, HEAD and OPTIONS, and the server recordsr.Methodinstead of echoing it in the body, since a HEAD response has no body.TestRequestStepResponseBodyevaluates the chart'srequesttemplate with stubbed vela imports for HEAD, 204, an empty 200 and a JSON body. The empty-body cases fail without the guard and pass with it.go test ./pkg/providers/http/... ./pkg/providers/legacy/http/...,go veton those packages and gofmt pass. I did not runmake reviewableor the envtest-based kube suites, which need etcd locally.Special notes for your reviewer
The legacy test reads the method from each CUE definition and sends it with
Do(), because calling the legacy provider directly from an uncompiled template trips over the emptyresponsefield.🤖 Generated with Claude Code
Summary by cubic
The HTTP providers and
requeststep now accept all standard HTTP methods, so PATCH, HEAD, OPTIONS, CONNECT, and TRACE requests no longer fail CUE validation. Adds#HTTPPatch,#HTTPHead, and#HTTPOptionsdefinitions to both the http and legacy providers;methoddefaults to GET as before. Fixes #295.The
requeststep no longer decodes an empty response body, so HEAD requests and empty responses such as 204 no longer fail the step.responseis left unset when there is no body to decode.Written for commit 90691de. Summary will update on new commits.