-
Notifications
You must be signed in to change notification settings - Fork 340
Preserve script order in generated README #2875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikeland73
wants to merge
4
commits into
main
Choose a base branch
from
claude/focused-goldberg-txihvu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5b0d0f
Preserve script order in generated README (#1991)
claude c0a718f
Address review: clarify map-order comment, dedupe order by last occur…
claude 15b1dcb
ci: re-trigger checks (flaky add_platforms_flakeref network test)
claude a70478f
ci: re-trigger checks (flaky integration testscripts)
claude 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package configfile | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // scriptNames returns just the names of the ordered scripts, for convenient | ||
| // assertions. | ||
| func scriptNames(scripts []ScriptWithName) []string { | ||
| names := make([]string, 0, len(scripts)) | ||
| for _, s := range scripts { | ||
| names = append(names, s.Name) | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| func TestScriptsInOrderPreservesSourceOrder(t *testing.T) { | ||
| config := []byte(`{ | ||
| "shell": { | ||
| "scripts": { | ||
| "step-one": "echo one", | ||
| "step-two": "echo two", | ||
| "step-three": "echo three", | ||
| "step-four": "echo four" | ||
| } | ||
| } | ||
| }`) | ||
|
|
||
| cfg, err := LoadBytes(config) | ||
| require.NoError(t, err) | ||
|
|
||
| ordered := cfg.Scripts().InOrder(cfg.ScriptOrder()) | ||
| assert.Equal(t, | ||
| []string{"step-one", "step-two", "step-three", "step-four"}, | ||
| scriptNames(ordered), | ||
| ) | ||
| } | ||
|
|
||
| func TestScriptsInOrderFallsBackToAlphabetical(t *testing.T) { | ||
| // When no order is provided (e.g. the config wasn't parsed from a file), | ||
| // the result should be deterministic (alphabetical) rather than random | ||
| // map order. | ||
| scripts := Scripts{ | ||
| "build": &script{}, | ||
| "test": &script{}, | ||
| "clean": &script{}, | ||
| } | ||
|
|
||
| ordered := scripts.InOrder(nil) | ||
| assert.Equal(t, []string{"build", "clean", "test"}, scriptNames(ordered)) | ||
| } | ||
|
|
||
| func TestScriptsInOrderAppendsUnknownScripts(t *testing.T) { | ||
| // Scripts present in the map but missing from the order slice should be | ||
| // appended in alphabetical order, with no duplicates. | ||
| scripts := Scripts{ | ||
| "first": &script{}, | ||
| "second": &script{}, | ||
| "zeta": &script{}, | ||
| "alpha": &script{}, | ||
| } | ||
|
|
||
| ordered := scripts.InOrder([]string{"first", "second"}) | ||
| assert.Equal(t, | ||
| []string{"first", "second", "alpha", "zeta"}, | ||
| scriptNames(ordered), | ||
| ) | ||
| } | ||
|
|
||
| func TestScriptsInOrderDedupesKeepingLastOccurrence(t *testing.T) { | ||
| // When a script name appears more than once in order (e.g. defined in | ||
| // both an included config and the root config), it should appear once, at | ||
| // the position of its last occurrence — matching the merge precedence | ||
| // where the later (root) definition wins. | ||
| scripts := Scripts{ | ||
| "shared": &script{}, | ||
| "plugin-only": &script{}, | ||
| "root-only": &script{}, | ||
| } | ||
|
|
||
| // Simulates: included config order ["shared", "plugin-only"] followed by | ||
| // root config order ["root-only", "shared"]. "shared" is overridden by | ||
| // root, so it should follow root-only rather than lead. | ||
| order := []string{"shared", "plugin-only", "root-only", "shared"} | ||
|
|
||
| ordered := scripts.InOrder(order) | ||
| assert.Equal(t, | ||
| []string{"plugin-only", "root-only", "shared"}, | ||
| scriptNames(ordered), | ||
| ) | ||
| } | ||
|
|
||
| func TestScriptsInOrderCarriesCommands(t *testing.T) { | ||
| config := []byte(`{ | ||
| "shell": { | ||
| "scripts": { | ||
| "greet": ["echo hello", "echo world"] | ||
| } | ||
| } | ||
| }`) | ||
|
|
||
| cfg, err := LoadBytes(config) | ||
| require.NoError(t, err) | ||
|
|
||
| ordered := cfg.Scripts().InOrder(cfg.ScriptOrder()) | ||
| require.Len(t, ordered, 1) | ||
| assert.Equal(t, "greet", ordered[0].Name) | ||
| require.NotNil(t, ordered[0].Commands) | ||
| assert.Equal(t, "echo hello\necho world", ordered[0].Commands.String()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.