-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add two-way manifest sync between project and app settings #543
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
58e107c
feat: add two-way manifest sync between project and app settings
mwbrooks cd86717
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks 38f720f
fix: refuse manifest sync when project source is remote
mwbrooks 6f49023
fix: gate manifest sync command behind experiment
mwbrooks f531346
fix: return error on path collisions when unflattening manifests
mwbrooks 52a2fbf
fix: write manifest.json atomically via temp file rename
mwbrooks be92c96
fix: refresh cached manifest hash after sync pushes to app settings
mwbrooks 4dc53cc
fix: honor --force flag in non-TTY manifest sync
mwbrooks faf52bc
fix: surface marshal errors in writeback instead of dropping them
mwbrooks c911ada
fix: surface a warning when manifest.json key order is rewritten
mwbrooks 68ff27e
fix: propagate marshal errors from valuesEqual instead of declaring i…
mwbrooks 49f12f3
fix: escape dots in flattened path segments to preserve dotted keys
mwbrooks c2b199c
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks d57b965
chore: add Apache 2.0 license headers to new manifest files
mwbrooks 22e3a29
refactor: move manifest package out of internal/pkg
mwbrooks f4c93e5
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks 0da44a8
Merge branch 'main' into mwbrooks-2-way-manifest-sync
srtaalej 0b98837
test: add coverage for manifest sync and display
srtaalej be0f881
test: remove redundant formatValue truncation case
srtaalej 879f3a6
Merge branch 'main' into mwbrooks-2-way-manifest-sync
srtaalej f2fc5be
chore: retrigger e2e tests
srtaalej 0c1eae1
fix: resolve merge conflicts with main after PR #591
srtaalej d329dd9
Merge branch 'main' into mwbrooks-2-way-manifest-sync
srtaalej 515d959
docs: add manifest-sync experiment
zimeg 5797458
style: command format for aliased processes
zimeg 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright 2022-2026 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package manifest | ||
|
|
||
| import ( | ||
| "github.com/opentracing/opentracing-go" | ||
| "github.com/slackapi/slack-cli/internal/app" | ||
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/manifest" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/slackerror" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var manifestSyncFunc = manifest.Sync | ||
|
|
||
| func NewSyncCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "sync", | ||
| Short: "Sync the app manifest between project and app settings", | ||
| Long: "Compare the local project manifest with app settings, resolve differences, and sync both to the same state.", | ||
| Hidden: true, | ||
| Example: style.ExampleCommandsf([]style.ExampleCommand{ | ||
| {Command: "manifest sync", Meaning: "Sync project manifest with app settings"}, | ||
| }), | ||
| Args: cobra.NoArgs, | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| if !clients.Config.WithExperimentOn(experiment.ManifestSync) { | ||
| return slackerror.New(slackerror.ErrExperimentRequired). | ||
| WithRemediation("Enable the %s experiment with %s", | ||
| style.Highlight(string(experiment.ManifestSync)), | ||
| style.CommandText("--experiment manifest-sync"), | ||
| ) | ||
| } | ||
| return cmdutil.IsValidProjectDirectory(clients) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
| span, ctx := opentracing.StartSpanFromContext(ctx, "cmd.manifest.sync") | ||
| defer span.Finish() | ||
|
|
||
| selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| clients.Config.ManifestEnv = app.SetManifestEnvTeamVars(clients.Config.ManifestEnv, selection.App.TeamDomain, selection.App.IsDev) | ||
|
|
||
| _, err = manifestSyncFunc(ctx, clients, selection.App, selection.Auth) | ||
| return err | ||
| }, | ||
| } | ||
| return cmd | ||
| } |
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,51 @@ | ||
| // Copyright 2022-2026 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package manifest | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/slackerror" | ||
| "github.com/slackapi/slack-cli/test/testutil" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func TestSyncCommand(t *testing.T) { | ||
| testutil.TableTestCommand(t, testutil.CommandTests{ | ||
| "errors when the manifest-sync experiment is off": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AddDefaultMocks() | ||
| cf.Config.LoadExperiments(ctx, cf.IO.PrintDebug) | ||
| }, | ||
| ExpectedError: slackerror.New(slackerror.ErrExperimentRequired), | ||
| }, | ||
| "passes the experiment gate when manifest-sync is enabled via flag": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AddDefaultMocks() | ||
| cf.Config.ExperimentsFlag = []string{string(experiment.ManifestSync)} | ||
| cf.Config.LoadExperiments(ctx, cf.IO.PrintDebug) | ||
| }, | ||
| // We expect the command to fail downstream of the gate (no app | ||
| // selected, no SDK config), but NOT with ErrCommandUnavailable — | ||
| // the gate itself should pass. | ||
| ExpectedErrorStrings: []string{}, | ||
| }, | ||
| }, func(clients *shared.ClientFactory) *cobra.Command { | ||
| return NewSyncCommand(clients) | ||
| }) | ||
| } |
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,169 @@ | ||
| // Copyright 2022-2026 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package manifest | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "sort" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| ) | ||
|
|
||
| // DisplayDiffs prints the differences to the terminal. | ||
| func DisplayDiffs(ctx context.Context, io iostreams.IOStreamer, diffs *DiffResult) { | ||
| if !diffs.HasDifferences() { | ||
| return | ||
| } | ||
|
|
||
| sorted := make([]FieldDiff, len(diffs.Diffs)) | ||
| copy(sorted, diffs.Diffs) | ||
| sort.Slice(sorted, func(i, j int) bool { | ||
| return sorted[i].Path < sorted[j].Path | ||
| }) | ||
|
|
||
| io.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "books", | ||
| Text: "App Manifest", | ||
| Secondary: []string{ | ||
| fmt.Sprintf("Found %d difference(s) between project and app settings", len(sorted)), | ||
| }, | ||
| })) | ||
|
|
||
| for _, d := range sorted { | ||
| io.PrintInfo(ctx, false, "") | ||
| switch d.Type { | ||
| case DiffModified: | ||
| io.PrintInfo(ctx, false, " %s", style.Bold(d.Path)) | ||
| io.PrintInfo(ctx, false, " Project: %s", formatValue(d.LocalValue)) | ||
| io.PrintInfo(ctx, false, " App settings: %s", formatValue(d.RemoteValue)) | ||
| case DiffLocalOnly: | ||
| io.PrintInfo(ctx, false, " %s %s", style.Bold(d.Path), "(only in project)") | ||
| io.PrintInfo(ctx, false, " Value: %s", formatValue(d.LocalValue)) | ||
| case DiffRemoteOnly: | ||
| io.PrintInfo(ctx, false, " %s %s", style.Bold(d.Path), "(only in app settings)") | ||
| io.PrintInfo(ctx, false, " Value: %s", formatValue(d.RemoteValue)) | ||
| } | ||
| } | ||
| io.PrintInfo(ctx, false, "") | ||
| } | ||
|
|
||
| // PromptResolutionStrategy asks the user how they want to resolve differences. | ||
| func PromptResolutionStrategy(ctx context.Context, io iostreams.IOStreamer) (MergeStrategy, error) { | ||
| options := []string{ | ||
| "Use all project values", | ||
| "Use all app settings values", | ||
| "Choose for each difference", | ||
| } | ||
| resp, err := io.SelectPrompt(ctx, "How would you like to resolve these differences?", options, iostreams.SelectPromptConfig{ | ||
| Required: true, | ||
| }) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| switch resp.Index { | ||
| case 0: | ||
| return MergeAllLocal, nil | ||
| case 1: | ||
| return MergeAllRemote, nil | ||
| default: | ||
| return MergePerField, nil | ||
| } | ||
| } | ||
|
|
||
| // PromptFieldResolutions asks the user to resolve each difference individually. | ||
| func PromptFieldResolutions(ctx context.Context, io iostreams.IOStreamer, diffs *DiffResult) ([]FieldResolution, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📣 thought: IMHO prompts and outputs are better to include with |
||
| sorted := make([]FieldDiff, len(diffs.Diffs)) | ||
| copy(sorted, diffs.Diffs) | ||
| sort.Slice(sorted, func(i, j int) bool { | ||
| return sorted[i].Path < sorted[j].Path | ||
| }) | ||
|
|
||
| resolutions := make([]FieldResolution, 0, len(sorted)) | ||
| for _, d := range sorted { | ||
| var options []string | ||
| switch d.Type { | ||
| case DiffModified: | ||
| options = []string{ | ||
| fmt.Sprintf("Use project: %s", formatValue(d.LocalValue)), | ||
| fmt.Sprintf("Use app settings: %s", formatValue(d.RemoteValue)), | ||
| } | ||
| case DiffLocalOnly: | ||
| options = []string{ | ||
| "Keep (include in merged manifest)", | ||
| "Remove (exclude from merged manifest)", | ||
| } | ||
| case DiffRemoteOnly: | ||
| options = []string{ | ||
| "Remove (exclude from merged manifest)", | ||
| "Keep (include in merged manifest)", | ||
| } | ||
| } | ||
|
|
||
| resp, err := io.SelectPrompt(ctx, d.Path, options, iostreams.SelectPromptConfig{ | ||
| Required: true, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var resolution Resolution | ||
| switch d.Type { | ||
| case DiffModified: | ||
| if resp.Index == 0 { | ||
| resolution = ResolveLocal | ||
| } else { | ||
| resolution = ResolveRemote | ||
| } | ||
| case DiffLocalOnly: | ||
| if resp.Index == 0 { | ||
| resolution = ResolveLocal | ||
| } else { | ||
| resolution = ResolveRemote | ||
| } | ||
| case DiffRemoteOnly: | ||
| if resp.Index == 0 { | ||
| resolution = ResolveLocal | ||
| } else { | ||
| resolution = ResolveRemote | ||
| } | ||
| } | ||
|
|
||
| resolutions = append(resolutions, FieldResolution{Path: d.Path, Resolution: resolution}) | ||
| } | ||
| return resolutions, nil | ||
| } | ||
|
|
||
| func formatValue(v any) string { | ||
| if v == nil { | ||
| return "(not present)" | ||
| } | ||
| switch val := v.(type) { | ||
| case string: | ||
| return fmt.Sprintf("%q", val) | ||
| default: | ||
| data, err := json.Marshal(val) | ||
| if err != nil { | ||
| return fmt.Sprintf("%v", val) | ||
| } | ||
| s := string(data) | ||
| if len(s) > 80 { | ||
| return s[:77] + "..." | ||
| } | ||
| return s | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📣 suggestion: We should reuse the formatting of the
manifest diffcommand here!