Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
58e107c
feat: add two-way manifest sync between project and app settings
mwbrooks May 13, 2026
cd86717
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks Jun 11, 2026
38f720f
fix: refuse manifest sync when project source is remote
mwbrooks Jun 11, 2026
6f49023
fix: gate manifest sync command behind experiment
mwbrooks Jun 12, 2026
f531346
fix: return error on path collisions when unflattening manifests
mwbrooks Jun 12, 2026
52a2fbf
fix: write manifest.json atomically via temp file rename
mwbrooks Jun 12, 2026
be92c96
fix: refresh cached manifest hash after sync pushes to app settings
mwbrooks Jun 12, 2026
4dc53cc
fix: honor --force flag in non-TTY manifest sync
mwbrooks Jun 12, 2026
faf52bc
fix: surface marshal errors in writeback instead of dropping them
mwbrooks Jun 12, 2026
c911ada
fix: surface a warning when manifest.json key order is rewritten
mwbrooks Jun 12, 2026
68ff27e
fix: propagate marshal errors from valuesEqual instead of declaring i…
mwbrooks Jun 12, 2026
49f12f3
fix: escape dots in flattened path segments to preserve dotted keys
mwbrooks Jun 12, 2026
c2b199c
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks Jun 12, 2026
d57b965
chore: add Apache 2.0 license headers to new manifest files
mwbrooks Jun 12, 2026
22e3a29
refactor: move manifest package out of internal/pkg
mwbrooks Jun 12, 2026
f4c93e5
Merge remote-tracking branch 'origin/main' into mwbrooks-2-way-manife…
mwbrooks Jun 13, 2026
0da44a8
Merge branch 'main' into mwbrooks-2-way-manifest-sync
srtaalej Jul 15, 2026
0b98837
test: add coverage for manifest sync and display
srtaalej Jul 15, 2026
be0f881
test: remove redundant formatValue truncation case
srtaalej Jul 15, 2026
879f3a6
Merge branch 'main' into mwbrooks-2-way-manifest-sync
srtaalej Jul 21, 2026
f2fc5be
chore: retrigger e2e tests
srtaalej Jul 27, 2026
0c1eae1
fix: resolve merge conflicts with main after PR #591
srtaalej Jul 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
// Add child commands
cmd.AddCommand(NewDiffCommand(clients))
cmd.AddCommand(NewInfoCommand(clients))
cmd.AddCommand(NewSyncCommand(clients))
cmd.AddCommand(NewValidateCommand(clients))

cmd.Flags().StringVar(
Expand Down
69 changes: 69 additions & 0 deletions cmd/manifest/sync.go
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
}
51 changes: 51 additions & 0 deletions cmd/manifest/sync_test.go
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)
})
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var AliasMap = map[string]*AliasInfo{
"logout": {CommandFactory: auth.NewLogoutCommand, CanonicalName: "auth logout", ParentName: "auth"},
"run": {CommandFactory: platform.NewRunCommand, CanonicalName: "platform run", ParentName: "platform"},
"samples": {CommandFactory: project.NewSamplesCommand, CanonicalName: "project samples", ParentName: "project"},
"sync": {CommandFactory: manifest.NewSyncCommand, CanonicalName: "manifest sync", ParentName: "manifest"},
"uninstall": {CommandFactory: app.NewUninstallCommand, CanonicalName: "app uninstall", ParentName: "app"},
}
var processName = cmdutil.GetProcessName()
Expand Down
4 changes: 4 additions & 0 deletions internal/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
// Lipgloss experiment shows pretty styles.
Lipgloss Experiment = "lipgloss"

// ManifestSync experiment enables two-way manifest sync between local and remote.
ManifestSync Experiment = "manifest-sync"

// Placeholder experiment is a placeholder for testing and does nothing... or does it?
Placeholder Experiment = "placeholder"

Expand All @@ -44,6 +47,7 @@ const (
// Please also add here 👇
var AllExperiments = []Experiment{
Lipgloss,
ManifestSync,
Placeholder,
SetIcon,
}
Expand Down
169 changes: 169 additions & 0 deletions internal/manifest/display.go
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) {
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
}
}
Loading
Loading