diff --git a/docs/user/reference/cli/azldev_component.md b/docs/user/reference/cli/azldev_component.md index d12ebbeb6..f36a6f06e 100644 --- a/docs/user/reference/cli/azldev_component.md +++ b/docs/user/reference/cli/azldev_component.md @@ -17,7 +17,7 @@ components defined in the project configuration. ``` -h, --help[=true|false] help for component - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) ``` ### Options inherited from parent commands diff --git a/docs/user/reference/cli/azldev_component_add.md b/docs/user/reference/cli/azldev_component_add.md index 2e09c577f..c2d39949a 100644 --- a/docs/user/reference/cli/azldev_component_add.md +++ b/docs/user/reference/cli/azldev_component_add.md @@ -46,7 +46,7 @@ azldev component add [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_build.md b/docs/user/reference/cli/azldev_component_build.md index 58ed53177..c1f7ac75c 100644 --- a/docs/user/reference/cli/azldev_component_build.md +++ b/docs/user/reference/cli/azldev_component_build.md @@ -78,7 +78,7 @@ azldev component build [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_changed.md b/docs/user/reference/cli/azldev_component_changed.md index 466f85135..94023d3d0 100644 --- a/docs/user/reference/cli/azldev_component_changed.md +++ b/docs/user/reference/cli/azldev_component_changed.md @@ -68,7 +68,7 @@ azldev component changed [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_diff-sources.md b/docs/user/reference/cli/azldev_component_diff-sources.md index a86246e8d..ab9954584 100644 --- a/docs/user/reference/cli/azldev_component_diff-sources.md +++ b/docs/user/reference/cli/azldev_component_diff-sources.md @@ -40,7 +40,7 @@ azldev component diff-sources [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_history.md b/docs/user/reference/cli/azldev_component_history.md index 519b3a079..a1ac8a4cf 100644 --- a/docs/user/reference/cli/azldev_component_history.md +++ b/docs/user/reference/cli/azldev_component_history.md @@ -66,7 +66,7 @@ azldev component history [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_list.md b/docs/user/reference/cli/azldev_component_list.md index 60bf2651d..8da42e9dc 100644 --- a/docs/user/reference/cli/azldev_component_list.md +++ b/docs/user/reference/cli/azldev_component_list.md @@ -55,7 +55,7 @@ azldev component list [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_metadata.md b/docs/user/reference/cli/azldev_component_metadata.md index e8ef62231..bec7c153e 100644 --- a/docs/user/reference/cli/azldev_component_metadata.md +++ b/docs/user/reference/cli/azldev_component_metadata.md @@ -81,7 +81,7 @@ azldev component metadata [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_prepare-sources.md b/docs/user/reference/cli/azldev_component_prepare-sources.md index 9741a6f4c..e7ff1ad6f 100644 --- a/docs/user/reference/cli/azldev_component_prepare-sources.md +++ b/docs/user/reference/cli/azldev_component_prepare-sources.md @@ -61,7 +61,7 @@ azldev component prepare-sources [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_query.md b/docs/user/reference/cli/azldev_component_query.md index d277c29d7..3be445bbd 100644 --- a/docs/user/reference/cli/azldev_component_query.md +++ b/docs/user/reference/cli/azldev_component_query.md @@ -58,7 +58,7 @@ azldev component query [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_render.md b/docs/user/reference/cli/azldev_component_render.md index c7beff797..bd6c50e58 100644 --- a/docs/user/reference/cli/azldev_component_render.md +++ b/docs/user/reference/cli/azldev_component_render.md @@ -81,7 +81,7 @@ azldev component render [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_test.md b/docs/user/reference/cli/azldev_component_test.md index 57251bfe3..305e69d97 100644 --- a/docs/user/reference/cli/azldev_component_test.md +++ b/docs/user/reference/cli/azldev_component_test.md @@ -107,7 +107,7 @@ azldev component test COMPONENT [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/cli/azldev_component_update.md b/docs/user/reference/cli/azldev_component_update.md index 427b48927..4b9aeac7a 100644 --- a/docs/user/reference/cli/azldev_component_update.md +++ b/docs/user/reference/cli/azldev_component_update.md @@ -82,7 +82,7 @@ azldev component update [flags] --permissive-config[=true|false] do not fail on unknown fields in TOML config files -C, --project string path to Azure Linux project -q, --quiet[=true|false] only enable minimal output - --spec-editor editor Select the RPM spec editor (legacy or experimental) (default legacy) + --spec-editor editor Select the RPM spec editor ('structural' or deprecated 'legacy') (default structural) --unique-mockroot[=true|false] use unique mock roots labeled with the action, components, and a random suffix (at most 24 characters); allows 'component build' to build multiple components concurrently -v, --verbose[=true|false] enable verbose output --without-lockfile[=true|false] preview: track resolved upstream commits in generated config instead of lock files diff --git a/docs/user/reference/config/overlays.md b/docs/user/reference/config/overlays.md index f252e9d91..5910f5aec 100644 --- a/docs/user/reference/config/overlays.md +++ b/docs/user/reference/config/overlays.md @@ -10,7 +10,9 @@ Overlays are defined within a component's configuration in your TOML config file ### Spec Overlays -These overlays modify `.spec` files using the component command's `--spec-editor` option. The default `legacy` editor is line-oriented; `--spec-editor experimental` selects the structural editor, which preserves conditional and section structure. +These overlays modify `.spec` files using the component command's `--spec-editor` option. The default `structural` editor preserves conditional and section structure; `--spec-editor legacy` selects the line-oriented legacy editor. + +The `legacy` editor is deprecated and will be removed in a future release. Explicit use emits a warning; migrate existing invocations to `structural` or omit `--spec-editor`. #### Known Limitations diff --git a/internal/app/azldev/agentskill/agentskill_test.go b/internal/app/azldev/agentskill/agentskill_test.go index e53c985a8..acf1b4cfd 100644 --- a/internal/app/azldev/agentskill/agentskill_test.go +++ b/internal/app/azldev/agentskill/agentskill_test.go @@ -185,6 +185,14 @@ func TestComponentTomlSkillDocumentsRPMDevBumpspecPreview(t *testing.T) { assert.Contains(t, doc, "no bumpspec runtime discovery occurs") } +func TestOverlaysSkillDocumentsSpecEditorDeprecation(t *testing.T) { + doc, err := agentskill.SkillDocument("azldev-overlays", testParams()) + require.NoError(t, err) + assert.Contains(t, doc, "The structural editor is the default") + assert.Contains(t, doc, "The `legacy` editor is deprecated") + assert.Contains(t, doc, "The former `experimental` value is no longer accepted") +} + func TestImageSkillDocumentsSKUGroupGuidance(t *testing.T) { doc, err := agentskill.SkillDocument("azldev-image", testParams()) require.NoError(t, err) diff --git a/internal/app/azldev/agentskill/content/overlays.md.tmpl b/internal/app/azldev/agentskill/content/overlays.md.tmpl index 23b8b1121..80c633bf6 100644 --- a/internal/app/azldev/agentskill/content/overlays.md.tmpl +++ b/internal/app/azldev/agentskill/content/overlays.md.tmpl @@ -33,6 +33,13 @@ overlays before it stay applied. Config errors reference the offending overlay by its `description`, so give every overlay a short, specific `description`. +## Spec editor selection + +The structural editor is the default. It preserves conditional and section structure +more reliably than the line-oriented editor. The `legacy` editor is deprecated and +emits a warning when selected with `--spec-editor legacy`; it will be removed in a +future release. The former `experimental` value is no longer accepted. + ## Diagnose common failures Start with `azldev comp diff-sources -p ` to see the exact overlay effect. diff --git a/internal/app/azldev/cmds/component/speceditor.go b/internal/app/azldev/cmds/component/speceditor.go index 6c4467c09..7ed4dfac8 100644 --- a/internal/app/azldev/cmds/component/speceditor.go +++ b/internal/app/azldev/cmds/component/speceditor.go @@ -5,6 +5,7 @@ package component import ( "fmt" + "log/slog" "github.com/microsoft/azure-linux-dev-tools/internal/rpm/spec" "github.com/spf13/cobra" @@ -12,8 +13,10 @@ import ( ) const ( - specEditorLegacy = "legacy" - specEditorExperimental = "experimental" + // specEditorLegacy remains supported temporarily for backward compatibility. + // It is deprecated and will be removed in a future release. + specEditorLegacy = "legacy" + specEditorStructural = "structural" ) // componentCommandOptions are shared by component subcommands that edit specs. @@ -23,7 +26,7 @@ type componentCommandOptions struct { func (o componentCommandOptions) specEditorMode() spec.EditorMode { if o.SpecEditor == "" { - return spec.EditorLegacy + return spec.EditorStructural } return o.SpecEditor @@ -36,12 +39,12 @@ type specEditorFlagValue struct { var _ pflag.Value = (*specEditorFlagValue)(nil) func newSpecEditorFlagValue() *specEditorFlagValue { - return &specEditorFlagValue{mode: spec.EditorLegacy} + return &specEditorFlagValue{mode: spec.EditorStructural} } func (v *specEditorFlagValue) String() string { if v.mode == spec.EditorStructural { - return specEditorExperimental + return specEditorStructural } return specEditorLegacy @@ -51,12 +54,15 @@ func (v *specEditorFlagValue) Set(value string) error { switch value { case specEditorLegacy: v.mode = spec.EditorLegacy - case specEditorExperimental: + + slog.Warn("The RPM spec 'legacy' editor is deprecated and will be removed in a future release; " + + "use 'structural' instead") + case specEditorStructural: v.mode = spec.EditorStructural default: return fmt.Errorf( "unsupported RPM spec editor %#q; expected %#q or %#q", - value, specEditorLegacy, specEditorExperimental, + value, specEditorLegacy, specEditorStructural, ) } @@ -71,19 +77,19 @@ func addSpecEditorOption(cmd *cobra.Command) { cmd.PersistentFlags().Var( newSpecEditorFlagValue(), "spec-editor", - "Select the RPM spec editor (legacy or experimental)", + "Select the RPM spec editor ('structural' or deprecated 'legacy')", ) } func specEditorFromCommand(cmd *cobra.Command) spec.EditorMode { flag := cmd.Flags().Lookup("spec-editor") if flag == nil { - return spec.EditorLegacy + return spec.EditorStructural } value, ok := flag.Value.(*specEditorFlagValue) if !ok { - return spec.EditorLegacy + return spec.EditorStructural } return value.mode diff --git a/internal/app/azldev/cmds/component/speceditor_internal_test.go b/internal/app/azldev/cmds/component/speceditor_internal_test.go index 95c918587..43d9f5f52 100644 --- a/internal/app/azldev/cmds/component/speceditor_internal_test.go +++ b/internal/app/azldev/cmds/component/speceditor_internal_test.go @@ -5,8 +5,10 @@ package component import ( + "bytes" "context" "errors" + "log/slog" "path/filepath" "strings" "testing" @@ -26,15 +28,15 @@ import ( "github.com/stretchr/testify/require" ) -func TestComponentCommandOptionsDefaultsToLegacy(t *testing.T) { - assert.Equal(t, spec.EditorLegacy, componentCommandOptions{}.specEditorMode()) +func TestComponentCommandOptionsDefaultsToStructural(t *testing.T) { + assert.Equal(t, spec.EditorStructural, componentCommandOptions{}.specEditorMode()) } -func TestSpecEditorOptionDefaultsToLegacy(t *testing.T) { +func TestSpecEditorOptionDefaultsToStructural(t *testing.T) { editor, err := executeSpecEditorProductionCommand(t, "render") require.NoError(t, err) - assert.Equal(t, spec.EditorLegacy, editor) + assert.Equal(t, spec.EditorStructural, editor) } func TestSpecEditorOptionParsesLegacy(t *testing.T) { @@ -44,32 +46,76 @@ func TestSpecEditorOptionParsesLegacy(t *testing.T) { assert.Equal(t, spec.EditorLegacy, editor) } -func TestSpecEditorOptionParsesExperimental(t *testing.T) { - editor, err := executeSpecEditorProductionCommand(t, "render", "--spec-editor", specEditorExperimental) +func TestSpecEditorOptionWarnsOnlyForLegacy(t *testing.T) { + var logs bytes.Buffer + + originalLogger := slog.Default() + slog.SetDefault(slog.New(slog.NewTextHandler(&logs, nil))) + t.Cleanup(func() { + slog.SetDefault(originalLogger) + }) + + for _, testCase := range []struct { + name string + value string + warning bool + }{ + {name: "legacy", value: specEditorLegacy, warning: true}, + {name: "structural", value: specEditorStructural}, + } { + t.Run(testCase.name, func(t *testing.T) { + logs.Reset() + + value := newSpecEditorFlagValue() + + require.NoError(t, value.Set(testCase.value)) + + if testCase.warning { + assert.Contains(t, logs.String(), "deprecated") + assert.Contains(t, logs.String(), "removed in a future release") + assert.Contains(t, logs.String(), "'structural'") + } else { + assert.Empty(t, logs.String()) + } + }) + } +} + +func TestSpecEditorOptionHelpMarksLegacyDeprecated(t *testing.T) { + cmd := newComponentCmd(&azldev.App{}) + flag := cmd.PersistentFlags().Lookup("spec-editor") + + require.NotNil(t, flag) + assert.Contains(t, flag.Usage, "deprecated") + assert.Contains(t, flag.Usage, "structural") +} + +func TestSpecEditorOptionParsesStructural(t *testing.T) { + editor, err := executeSpecEditorProductionCommand(t, "render", "--spec-editor", specEditorStructural) require.NoError(t, err) assert.Equal(t, spec.EditorStructural, editor) } func TestSpecEditorOptionDoesNotLeakBetweenCommands(t *testing.T) { - experimental, err := executeSpecEditorProductionCommand(t, "render", "--spec-editor", specEditorExperimental) + legacy, err := executeSpecEditorProductionCommand(t, "render", "--spec-editor", specEditorLegacy) require.NoError(t, err) - assert.Equal(t, spec.EditorStructural, experimental) + assert.Equal(t, spec.EditorLegacy, legacy) - legacy, err := executeSpecEditorProductionCommand(t, "render") + structural, err := executeSpecEditorProductionCommand(t, "render") require.NoError(t, err) - assert.Equal(t, spec.EditorLegacy, legacy) + assert.Equal(t, spec.EditorStructural, structural) } func TestSpecEditorOptionIsInheritedByNonConsumingCommands(t *testing.T) { testEnv := testutils.NewTestEnv(t) cmd := newComponentCmd(&azldev.App{}) - cmd.SetArgs([]string{"list", "--spec-editor", specEditorExperimental}) + cmd.SetArgs([]string{"list", "--spec-editor", specEditorStructural}) require.NoError(t, cmd.ExecuteContext(testEnv.Env)) } -func TestSpecEditorOptionRejectsUnsupportedValuesWithoutFallback(t *testing.T) { +func TestSpecEditorOptionRejectsExperimentalWithoutFallback(t *testing.T) { executed := false originalNewSourcePreparer := newSourcePreparer newSourcePreparer = func( @@ -89,12 +135,12 @@ func TestSpecEditorOptionRejectsUnsupportedValuesWithoutFallback(t *testing.T) { }) cmd := newComponentCmd(&azldev.App{}) - cmd.SetArgs([]string{"render", "--spec-editor", "structural"}) + cmd.SetArgs([]string{"render", "--spec-editor", "experimental"}) err := cmd.Execute() require.Error(t, err) - require.ErrorContains(t, err, "unsupported RPM spec editor `structural`; expected `legacy` or `experimental`") + require.ErrorContains(t, err, "unsupported RPM spec editor `experimental`; expected `legacy` or `structural`") assert.False(t, executed) } @@ -105,8 +151,8 @@ func TestSpecEditorOptionRoutesToRelevantComponentCommands(t *testing.T) { expected spec.EditorMode }{ { - name: "omitted flag uses legacy", - expected: spec.EditorLegacy, + name: "omitted flag uses structural", + expected: spec.EditorStructural, }, { name: "explicit legacy uses legacy", @@ -114,8 +160,8 @@ func TestSpecEditorOptionRoutesToRelevantComponentCommands(t *testing.T) { expected: spec.EditorLegacy, }, { - name: "experimental uses structural", - args: []string{"--spec-editor", specEditorExperimental}, + name: "structural uses structural", + args: []string{"--spec-editor", specEditorStructural}, expected: spec.EditorStructural, }, } { diff --git a/internal/app/azldev/core/sources/sourceprep.go b/internal/app/azldev/core/sources/sourceprep.go index 4edeb30b6..b0922ced5 100644 --- a/internal/app/azldev/core/sources/sourceprep.go +++ b/internal/app/azldev/core/sources/sourceprep.go @@ -123,6 +123,7 @@ func WithoutLockfileHistory() PreparerOption { } // WithSpecEditor selects the [spec.EditorMode] used for source preparation. +// [spec.EditorLegacy] is deprecated and will be removed in a future release. func WithSpecEditor(mode spec.EditorMode) PreparerOption { return func(p *sourcePreparerImpl) { p.specEditor = mode } } @@ -268,7 +269,7 @@ func NewPreparer( impl := &sourcePreparerImpl{ sourceManager: sourceManager, - specEditor: spec.EditorLegacy, + specEditor: spec.EditorStructural, fs: fs, eventListener: eventListener, dryRunnable: dryRunnable, diff --git a/internal/rpm/spec/edit_test.go b/internal/rpm/spec/edit_test.go index 5fff1d154..ec5cc0040 100644 --- a/internal/rpm/spec/edit_test.go +++ b/internal/rpm/spec/edit_test.go @@ -37,7 +37,12 @@ Patch2: other.patch expectedTags []string }{ { - name: "default legacy editor", + name: "default structural editor", + expectedTags: []string{"Name", "Version", "Patch0", "Summary", "Patch1", "Summary", "Patch2"}, + }, + { + name: "legacy editor", + options: []spec.OpenOption{spec.WithEditor(spec.EditorLegacy)}, expectedTags: []string{"Name", "Version", "Patch0", "Summary", "Patch1", "Summary", "Patch2"}, }, { @@ -115,24 +120,36 @@ Patch1: devel.patch ` tests := []struct { - name string - packageName string - options []spec.OpenOption - expectedTags []string + name string + packageName string + options []spec.OpenOption + expectedTags []string + mutate bool + expectMutation bool }{ { - name: "default legacy editor filters package", - packageName: "devel", - expectedTags: []string{"Summary", "Patch1"}, + name: "default structural editor filters package", + packageName: "devel", + expectedTags: []string{"Summary", "Patch1"}, + mutate: true, + expectMutation: true, }, { - name: "structural editor filters package and mutates it", + name: "legacy editor filters package", packageName: "devel", - options: []spec.OpenOption{spec.WithEditor(spec.EditorStructural)}, + options: []spec.OpenOption{spec.WithEditor(spec.EditorLegacy)}, expectedTags: []string{"Summary", "Patch1"}, }, { - name: "default legacy editor ignores unknown package", + name: "structural editor filters package and mutates it", + packageName: "devel", + options: []spec.OpenOption{spec.WithEditor(spec.EditorStructural)}, + expectedTags: []string{"Summary", "Patch1"}, + mutate: true, + expectMutation: true, + }, + { + name: "unknown package", packageName: "missing", }, } @@ -147,7 +164,7 @@ Patch1: devel.patch require.NoError(t, specFile.VisitTagsPackage( testCase.packageName, func(tagLine *spec.TagLine, ctx *spec.Context) error { tags = append(tags, tagLine.Tag) - if testCase.name == "structural editor filters package and mutates it" && tagLine.Tag == "Summary" { + if testCase.mutate && tagLine.Tag == "Summary" { ctx.ReplaceLine("Summary: Structural mutation") } @@ -155,7 +172,7 @@ Patch1: devel.patch })) assert.Equal(t, testCase.expectedTags, tags) - if testCase.options != nil { + if testCase.expectMutation { var actual bytes.Buffer require.NoError(t, specFile.Serialize(&actual)) assert.Contains(t, actual.String(), "Summary: Structural mutation") @@ -325,7 +342,10 @@ func TestVisitPreservesMutationsBeforeVisitorError(t *testing.T) { name string options []spec.OpenOption }{ - {name: "legacy editor"}, + { + name: "legacy editor", + options: []spec.OpenOption{spec.WithEditor(spec.EditorLegacy)}, + }, { name: "structural editor", options: []spec.OpenOption{spec.WithEditor(spec.EditorStructural)}, diff --git a/internal/rpm/spec/editor.go b/internal/rpm/spec/editor.go index 78967de13..1c45c268b 100644 --- a/internal/rpm/spec/editor.go +++ b/internal/rpm/spec/editor.go @@ -16,6 +16,8 @@ const ( elseDirective = "%else" // EditorLegacy uses the established line-oriented editor. + // Deprecated: EditorLegacy is deprecated and will be removed in a future + // release. Use EditorStructural unless legacy behavior is explicitly required. EditorLegacy EditorMode = "legacy" // EditorStructural uses the lossless structural editor. EditorStructural EditorMode = "structural" @@ -80,10 +82,10 @@ func (s *Spec) activeEditor() specEditor { return s.editor } -// OpenSpec reads a spec and selects its editor once. With no option, it preserves -// the established legacy behavior. +// OpenSpec reads a spec and selects its editor once. With no option, it uses +// the structural editor. func OpenSpec(reader io.Reader, options ...OpenOption) (*Spec, error) { - config := editorOptions{mode: EditorLegacy} + config := editorOptions{mode: EditorStructural} for _, option := range options { option(&config) } diff --git a/internal/rpm/spec/spec_test.go b/internal/rpm/spec/spec_test.go index fdff73650..6d10723b2 100644 --- a/internal/rpm/spec/spec_test.go +++ b/internal/rpm/spec/spec_test.go @@ -83,14 +83,14 @@ func TestSpecZeroValueUsesLegacyEditor(t *testing.T) { assert.Equal(t, strings.Join(lines, "\n")+"\n", output.String()) } -func TestOpenSpecStructuralEditorDoesNotUseZeroValueFallback(t *testing.T) { +func TestOpenSpecDefaultsToStructuralEditor(t *testing.T) { input := strings.Join([]string{ "Name: main", `%global hidden() \`, "Name: macro-body", }, "\n") + "\n" - specification, err := spec.OpenSpec(strings.NewReader(input), spec.WithEditor(spec.EditorStructural)) + specification, err := spec.OpenSpec(strings.NewReader(input)) require.NoError(t, err) var tags []string diff --git a/scenario/__snapshots__/TestMCPServerMode_1.snap.json b/scenario/__snapshots__/TestMCPServerMode_1.snap.json index 895ecf4a4..a7fef9c42 100755 --- a/scenario/__snapshots__/TestMCPServerMode_1.snap.json +++ b/scenario/__snapshots__/TestMCPServerMode_1.snap.json @@ -89,7 +89,7 @@ "type": "boolean" }, "spec-editor": { - "description": "Select the RPM spec editor (legacy or experimental)", + "description": "Select the RPM spec editor ('structural' or deprecated 'legacy')", "type": "string" }, "spec-path": { @@ -210,7 +210,7 @@ "type": "boolean" }, "spec-editor": { - "description": "Select the RPM spec editor (legacy or experimental)", + "description": "Select the RPM spec editor ('structural' or deprecated 'legacy')", "type": "string" }, "spec-path": { @@ -324,7 +324,7 @@ "type": "string" }, "spec-editor": { - "description": "Select the RPM spec editor (legacy or experimental)", + "description": "Select the RPM spec editor ('structural' or deprecated 'legacy')", "type": "string" }, "spec-path": { @@ -428,7 +428,7 @@ "type": "boolean" }, "spec-editor": { - "description": "Select the RPM spec editor (legacy or experimental)", + "description": "Select the RPM spec editor ('structural' or deprecated 'legacy')", "type": "string" }, "spec-path": { @@ -547,7 +547,7 @@ "type": "boolean" }, "spec-editor": { - "description": "Select the RPM spec editor (legacy or experimental)", + "description": "Select the RPM spec editor ('structural' or deprecated 'legacy')", "type": "string" }, "spec-path": {