diff --git a/internal/cli/version.go b/internal/cli/version.go index ca862a4..a4b8a8c 100644 --- a/internal/cli/version.go +++ b/internal/cli/version.go @@ -64,7 +64,7 @@ func VersionCommands(cli *Instance) *cobra.Command { promoteCmd := &cobra.Command{ Use: "promote ", Short: "Promote a specific version to current", - Long: "Updates the current symlink to point to the specified " + + Long: "Rewrites the secret's current file to name the specified " + "version. The versions' own times are left unchanged; secret " + "list then gives the time of the promote as the secret's last " + "update.", @@ -293,7 +293,7 @@ func (cli *Instance) PromoteVersion( version, vault.ErrVersionNotFound, secretName) } - // Update the current symlink using the proper function + // Rewrite the secret's current file to name the version err = secret.SetCurrentVersion(cli.fs, secretDir, version) if err != nil { return fmt.Errorf("failed to update current version: %w", err) diff --git a/internal/cli/version_test.go b/internal/cli/version_test.go index 018b5d3..41b319a 100644 --- a/internal/cli/version_test.go +++ b/internal/cli/version_test.go @@ -6,6 +6,8 @@ // - TestListVersionsNonExistentSecret: Tests error handling for missing secrets // - TestPromoteVersionCommand: Tests `secret version promote` command // - TestPromoteNonExistentVersion: Tests error handling for invalid promotion +// - TestPromoteHelpSaysCurrentFileIsRewritten: Tests `secret version promote +// --help` text // - TestGetSecretWithVersion: Tests `secret get --version` flag functionality // - TestGetSecretWritesBinaryValue: Tests `secret get` output of binary values // - TestVersionCommandStructure: Tests command structure and help text @@ -268,6 +270,23 @@ func TestPromoteNonExistentVersion(t *testing.T) { require.ErrorIs(t, err, vault.ErrVersionNotFound) } +// TestPromoteHelpSaysCurrentFileIsRewritten is a regression test for +// https://git.eeqj.de/sneak/secret/issues/153: `secret version promote +// --help` said it updates a symlink, but promote rewrites the secret's +// `current` file, which is a plain file. +// +//nolint:paralleltest // executes the CLI in-process and sets the environment +func TestPromoteHelpSaysCurrentFileIsRewritten(t *testing.T) { + env := map[string]string{secret.EnvStateDir: t.TempDir()} + + output, err := ExecuteCommandInProcess( + []string{"version", "promote", "--help"}, "", env) + require.NoError(t, err) + + assert.NotContains(t, output, "symlink") + assert.Contains(t, output, "current file") +} + func TestGetSecretWithVersion(t *testing.T) { t.Parallel()