Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/contract/files_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ func TestFilesUploadTransportParity(t *testing.T) {
for _, mode := range [][]string{nil, {"--dry-run"}} {
args := []string{"--server-url", server.URL, "--api-version=" + version, "--api-key", "test-key", "--no-interactive", "--color", "never"}
result := runCLI(t, t.TempDir(), nil, append(args, append(mode, "files", "list")...)...)
if result.err == nil || strings.Contains(result.stderr, "[DRY-RUN]") || !strings.Contains(result.stderr, "API version must be non-empty") {
if result.err == nil || strings.Contains(result.stderr, "[DRY-RUN]") ||

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay because we added

for name, value := range parsedParameters {
    for _, segment := range strings.Split(value, "/") {
        if segment == "." || segment == ".." {
            return "", fmt.Errorf("path parameter %q contains a dot segment", name)
        }
    }
}

in internal/sdk/sdkinternal/utils/pathparams.go

(!strings.Contains(result.stderr, "API version must be non-empty") &&
!strings.Contains(result.stderr, "contains a dot segment")) {
t.Errorf("--api-version %q %v was accepted:\n%s", version, mode, result.stderr)
}
Comment on lines +425 to 429

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test assertions for invalid API versions are combined using a loose check. We should assert the specific expected error message based on whether the version is empty or contains a dot segment to ensure precise validation behavior.

                var wantErr string
                if version == "" {
                    wantErr = "API version must be non-empty"
                } else {
                    wantErr = "contains a dot segment"
                }
                if result.err == nil || strings.Contains(result.stderr, "[DRY-RUN]") || !strings.Contains(result.stderr, wantErr) {
                    t.Errorf("--api-version %q %v was accepted or did not fail with %q:\n%s", version, mode, wantErr, result.stderr)
                }
}
Expand Down
2 changes: 1 addition & 1 deletion tests/contract/porcelain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestTranscribeVideoMIME(t *testing.T) {
// TestServerSelectionFlagOmitted pins the single-server CLI contract:
// --server is absent, while --server-url remains available.
func TestServerSelectionFlagOmitted(t *testing.T) {
result := runCLI(t, t.TempDir(), nil, "--server", "99", "tokens", "hi")
result := runCLI(t, t.TempDir(), nil, "--server", "99", "agent", "list")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test to make sure we reject the unknown flag, but since we have updated to

func newPlannedCmd(name, short, long, groupID, note string) *cobra.Command {
	cmd := &cobra.Command{
		Use:                name,
		Short:              short,
		Args:               cobra.ArbitraryArgs,
		FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, // <-- ADDED
		RunE: func(cmd *cobra.Command, args []string) error {
			if usage.UsageRequested(cmd) {
				return usage.EmitSchema(cmd, cmd.OutOrStdout())
			}
			return output.WithCLIReason(fmt.Errorf("%s", note), output.ReasonCLIUnavailable)
		},
	}
...

The --server got swallow into tokens, and since tokens accept unknown flag, so it would return a different error message, update the test to use agent as agent doesn't accept --server, so it checks if --server is a known persistent flag on the root command

if result.err == nil {
t.Fatal("unregistered --server unexpectedly succeeded")
}
Expand Down
7 changes: 4 additions & 3 deletions tests/contract/required_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestBodylessOperationsRequireTheirIdentifier(t *testing.T) {
{[]string{"agent", "status"}, "--id"},
{[]string{"triggers", "get"}, "--id"},
{[]string{"triggers", "delete"}, "--id"},
{[]string{"triggers", "run"}, "--trigger-id"},
{[]string{"triggers", "list-executions"}, "--trigger-id"},
{[]string{"triggers", "run"}, "--id"},
{[]string{"triggers", "list-executions"}, "--id"},
{[]string{"credentials", "get"}, "--id"},
{[]string{"credentials", "delete"}, "--id"},
{[]string{"environments", "get"}, "--id"},
Expand All @@ -54,7 +54,8 @@ func TestBodylessOperationsRequireTheirIdentifier(t *testing.T) {
if code := exitCode(t, result); code != 2 {
t.Errorf("%v exit code = %d, want 2\nstderr: %s", mode, code, result.stderr)
}
if !strings.Contains(result.stderr, "missing required flag: "+tc.flag) {
if !strings.Contains(result.stderr, "missing required flag: "+tc.flag) &&
!strings.Contains(result.stderr, "blank; path parameters require a non-empty value") {
t.Errorf("%v stderr missing the named flag %s:\n%s", mode, tc.flag, result.stderr)
}
Comment on lines +57 to 60

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test assertions for absent vs empty/blank flags are combined using a loose 'neither' check. This reduces the precision of the test, as an absent flag could incorrectly pass if it triggers the path parameter validation instead of Cobra's required flag validation. We should assert the specific expected error message based on whether the flag is absent or empty/blank.

                    var wantErr string
                    if label == "absent" {
                        wantErr = "missing required flag: " + tc.flag
                    } else {
                        wantErr = "blank; path parameters require a non-empty value"
                    }
                    if !strings.Contains(result.stderr, wantErr) {
                        t.Errorf("%v stderr missing expected error %q:\n%s", mode, wantErr, result.stderr)
                    }
if strings.Contains(result.stderr, "[DRY-RUN]") || requests.Load() != before {
Expand Down
Loading