Skip to content

fix(instances): Preserve env variables values verbatim#395

Open
nurof3n wants to merge 2 commits into
prod-stagingfrom
nurof3n/fix/instances-env-sep
Open

fix(instances): Preserve env variables values verbatim#395
nurof3n wants to merge 2 commits into
prod-stagingfrom
nurof3n/fix/instances-env-sep

Conversation

@nurof3n

@nurof3n nurof3n commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Closes TOOL-1125

@nurof3n nurof3n requested a review from jedevc July 3, 2026 12:54
@nurof3n nurof3n force-pushed the nurof3n/fix/instances-env-sep branch from 2e442b8 to 89f1bc0 Compare July 6, 2026 13:05
@craciunoiuc craciunoiuc requested a review from Copilot July 6, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates instance-related commands to correctly accept environment variables in KEY=VALUE form even when values contain commas, by preventing Kong’s default comma-splitting and handling parsing explicitly before shortcut-flag processing.

Changes:

  • Set sep:"none" for -e/--env on instance create/edit to avoid Kong splitting values on commas.
  • Pre-process Env into --set runtime.env=... entries before applying generic shortcut flags (create/edit/run).
  • Add helpers to split and encode env assignments as JSON map fragments for consistent patch parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/cmd/run.go Pre-processes --env into --set entries before generic shortcut handling to support KEY=VALUE parsing.
internal/cmd/instances.go Disables Kong comma-splitting for --env, adds env parsing helpers, and applies the same pre-processing for create/edit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cmd/instances.go Outdated

@craciunoiuc craciunoiuc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comments my side 🥺

Comment thread internal/cmd/instances.go
Comment thread internal/cmd/instances.go Outdated
Comment thread internal/cmd/instances.go Outdated
Comment thread internal/cmd/instances.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread internal/cmd/instances.go Outdated
Comment thread internal/resource/value/parse_test.go Outdated
Comment thread internal/resource/value/parse.go Outdated
@nurof3n nurof3n force-pushed the nurof3n/fix/instances-env-sep branch from 5311264 to a8d856f Compare July 7, 2026 13:00
@nurof3n nurof3n requested a review from Copilot July 7, 2026 13:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread internal/resource/value/parse.go
Comment thread internal/resource/value/parse_test.go Outdated
Comment thread internal/cmd/instances.go
@craciunoiuc

Copy link
Copy Markdown
Contributor

@nurof3n tests failing 😳

Also please close copilot comments which no longer apply

Looks much leaner now 🫦

@nurof3n nurof3n changed the title fix(instances): Handle env variables with key=value, syntax fix(instances): Preserve env variables verbatim Jul 7, 2026
@nurof3n nurof3n changed the title fix(instances): Preserve env variables verbatim fix(instances): Preserve env variables values verbatim Jul 7, 2026
@nurof3n nurof3n force-pushed the nurof3n/fix/instances-env-sep branch from a8d856f to 937a9a1 Compare July 7, 2026 13:26
@nurof3n nurof3n requested a review from Copilot July 7, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread internal/resource/value/parse.go Outdated
Comment thread internal/resource/value/parse.go Outdated
Comment thread internal/resource/value/parse_test.go Outdated
Comment thread internal/resource/value/parse.go Outdated
Comment on lines +178 to +190
// Each input string is a single key=value entry. Split on the
// first "=" only; the value is then parsed by parseReflect
// according to the map's element type. For string element types
// (e.g. map[string]string) the value is taken verbatim, so it may
// contain commas, "=", or any other characters. For non-string
// element types (e.g. slices, structs), parseReflect may still
// interpret commas per the element type's own parsing rules.
// Multiple entries are supplied via repeated --set flags (multiple
// input strings), not via commas within a single string.
//
// Skip empty/whitespace-only inputs so a bare "--set field=" can
// be used without creating a spurious empty-key entry, and trim
// the key only (values are kept verbatim).

@jedevc jedevc Jul 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

YESSSS, this is what I meant! Perfect 🎉 Incredible find 🎉

I will say though... this might have an impact on other things. Take a quick look and see where else it impacts. Also, note there's above logic for structs where we have similar logic actually!

We could also make the previous range behavior optional, similar to kong, and obey a sep tag on things. If it's none then we skip it, otherwise we split on the value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to do that, let me know if it's too complicated again :x

@nurof3n nurof3n requested review from craciunoiuc and jedevc July 8, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread internal/resource/value/parse.go
@nurof3n nurof3n force-pushed the nurof3n/fix/instances-env-sep branch from 469fb03 to 4dc1888 Compare July 8, 2026 11:25
@nurof3n nurof3n requested a review from Copilot July 8, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +292 to +296
candidate := strings.TrimSpace(input[i+1:])
if candidate == "" || strings.HasPrefix(candidate, ",") || looksLikeStructField(candidate, s) {
items = append(items, strings.TrimSpace(input[start:i]))
start = i + 1
}
Comment on lines +222 to 226
t.Run("struct", func(t *testing.T) {
got, err := Parse[testStruct]([]string{"name=hello,value=42"})
require.NoError(t, err)
assert.Equal(t, map[string]string{"a": "1", "b": "2"}, got)
assert.Equal(t, testStruct{Name: "hello", Value: 42}, got)
})
}
mapp.SetMapIndex(key, val)

// Each input string is a single key=value entry. Split on the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this section also use sep? Right now, it's only being used for slices+structs, not maps.

return strings.Split(input, sep)
}

func splitStructValues(input string, s reflect.Value, sep string) []string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤔 Hm, wait why aren't we just using splitStructValues here?

Also, again, I don't love methods like looksLikeStructField - this means it's going to magically try and work out how to parse something, which is unexpected and will make the user sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants