Repository navigation
test(persona): cover output-style rollback when retired style removal fails #5712
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
decode2
merged 4 commits into
Gentleman-Programming:main
from
0wex:fix/persona-output-style-rollback
Oct 29, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d15b50
test(persona): cover output-style rollback when retired style removalβ¦
0wex e4dddd7
test(persona): assert files stay settled after the idempotent sync
0wex c8a2247
test(persona): fail the real retired style removal in CLI rollback tests
0wex e6105f7
test(persona): baseline the removal seam and assert recovery keeps usβ¦
0wex 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/gentleman-programming/gentle-ai/v4/internal/agents/claude" | ||
| "github.com/gentleman-programming/gentle-ai/v4/internal/components/persona" | ||
| "github.com/gentleman-programming/gentle-ai/v4/internal/model" | ||
| "github.com/gentleman-programming/gentle-ai/v4/internal/system" | ||
| ) | ||
|
|
||
| var errInjectedRetiredStyleRemoval = errors.New("injected retired output style removal failure") | ||
|
|
||
| // outputStyleTransitionFixture is a Claude home with the Gentleman persona | ||
| // applied, plus a user-owned output style and an unrelated settings key. | ||
| type outputStyleTransitionFixture struct { | ||
| home string | ||
| gentleman string | ||
| neutral string | ||
| settings string | ||
| before map[string][]byte | ||
| } | ||
|
|
||
| func newOutputStyleTransitionFixture(t *testing.T, home string) outputStyleTransitionFixture { | ||
| t.Helper() | ||
| claudeDir := filepath.Join(home, ".claude") | ||
| f := outputStyleTransitionFixture{ | ||
| home: home, | ||
| gentleman: filepath.Join(claudeDir, "output-styles", "gentleman.md"), | ||
| neutral: filepath.Join(claudeDir, "output-styles", "neutral.md"), | ||
| settings: filepath.Join(claudeDir, "settings.json"), | ||
| } | ||
| userStyle := filepath.Join(claudeDir, "output-styles", "user-owned.md") | ||
| mustWriteFile(t, f.settings, []byte(`{"permissions":{"allow":["Read"]}}`)) | ||
| mustWriteFile(t, userStyle, []byte("user-owned style\n")) | ||
|
|
||
| if _, err := persona.Inject(home, claude.NewAdapter(), model.PersonaGentleman); err != nil { | ||
| t.Fatalf("Inject(gentleman) error = %v", err) | ||
| } | ||
|
|
||
| f.before = map[string][]byte{} | ||
| for _, path := range []string{f.gentleman, f.settings, userStyle, filepath.Join(claudeDir, "CLAUDE.md")} { | ||
| content, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatalf("precondition: read %s: %v", path, err) | ||
| } | ||
| f.before[path] = content | ||
| } | ||
| if !strings.Contains(string(f.before[f.settings]), `"outputStyle": "Gentleman"`) { | ||
| t.Fatalf("precondition: settings do not select Gentleman: %s", f.before[f.settings]) | ||
| } | ||
| if _, err := os.Stat(f.neutral); !os.IsNotExist(err) { | ||
| t.Fatalf("precondition: neutral output style should be absent, stat err=%v", err) | ||
| } | ||
| return f | ||
| } | ||
|
|
||
| // failRetiredGentlemanRemoval makes the real persona injection fail when it | ||
| // removes the retired gentleman.md, after the Neutral style and settings have | ||
| // been published. reached records that the removal was attempted in that state. | ||
| // Every other removal goes through os.Remove. | ||
| func (f outputStyleTransitionFixture) failRetiredGentlemanRemoval(t *testing.T, reached *bool) { | ||
| t.Helper() | ||
| persona.SetRemoveForTest(t, func(path string) error { | ||
| if path != f.gentleman { | ||
| return os.Remove(path) | ||
| } | ||
| settings, err := os.ReadFile(f.settings) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if _, err := os.Stat(f.neutral); err == nil && strings.Contains(string(settings), `"outputStyle": "Neutral"`) { | ||
| *reached = true | ||
| } | ||
| return errInjectedRetiredStyleRemoval | ||
| }) | ||
| } | ||
|
|
||
| func (f outputStyleTransitionFixture) assertRestored(t *testing.T) { | ||
| t.Helper() | ||
| for path, want := range f.before { | ||
| got, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatalf("after rollback: read %s: %v", path, err) | ||
| } | ||
| if !bytes.Equal(got, want) { | ||
| t.Fatalf("after rollback %s = %q, want exact before-image %q", path, got, want) | ||
| } | ||
| } | ||
| if _, err := os.Stat(f.neutral); !os.IsNotExist(err) { | ||
| t.Fatalf("after rollback a partially published neutral output style remains, stat err=%v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallRollsBackOutputStyleSwitchWhenRetiredStyleRemovalFails(t *testing.T) { | ||
| home := installTestHome(t) | ||
| f := newOutputStyleTransitionFixture(t, home) | ||
|
|
||
| reached := false | ||
| f.failRetiredGentlemanRemoval(t, &reached) | ||
|
|
||
| _, err := RunInstall([]string{"--agent", "claude-code", "--component", "persona", "--persona", "neutral"}, system.DetectionResult{}) | ||
| if !errors.Is(err, errInjectedRetiredStyleRemoval) { | ||
| t.Fatalf("RunInstall() error = %v, want injected retired style removal failure", err) | ||
| } | ||
| if !reached { | ||
| t.Fatal("injection never published the Neutral style and settings before failing") | ||
| } | ||
| f.assertRestored(t) | ||
| } | ||
|
|
||
| func TestSyncRollsBackOutputStyleSwitchWhenRetiredStyleRemovalFails(t *testing.T) { | ||
| f := newOutputStyleTransitionFixture(t, t.TempDir()) | ||
| selection := model.Selection{ | ||
| Agents: []model.AgentID{model.AgentClaudeCode}, | ||
| Components: []model.ComponentID{model.ComponentPersona}, | ||
| Persona: model.PersonaNeutral, | ||
| } | ||
|
|
||
| reached := false | ||
| f.failRetiredGentlemanRemoval(t, &reached) | ||
|
|
||
| if _, err := RunSyncWithSelection(f.home, selection); !errors.Is(err, errInjectedRetiredStyleRemoval) { | ||
| t.Fatalf("RunSyncWithSelection() error = %v, want injected retired style removal failure", err) | ||
| } | ||
| if !reached { | ||
| t.Fatal("injection never published the Neutral style and settings before failing") | ||
| } | ||
| f.assertRestored(t) | ||
|
|
||
| // Once removal succeeds, the switch completes and a rerun is a no-op. | ||
| persona.SetRemoveForTest(t, os.Remove) | ||
| if _, err := RunSyncWithSelection(f.home, selection); err != nil { | ||
| t.Fatalf("recovery RunSyncWithSelection() error = %v", err) | ||
| } | ||
| if _, err := os.Stat(f.gentleman); !os.IsNotExist(err) { | ||
| t.Fatalf("recovery sync left retired gentleman output style, stat err=%v", err) | ||
| } | ||
| if _, err := os.Stat(f.neutral); err != nil { | ||
| t.Fatalf("recovery sync did not publish neutral output style: %v", err) | ||
| } | ||
| settled := map[string][]byte{} | ||
| for path := range f.before { | ||
| if path == f.gentleman { | ||
| continue | ||
| } | ||
| settled[path] = nil | ||
| } | ||
| settled[f.neutral] = nil | ||
| for path := range settled { | ||
| content, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatalf("after recovery: read %s: %v", path, err) | ||
| } | ||
| settled[path] = content | ||
| } | ||
| second, err := RunSyncWithSelection(f.home, selection) | ||
| if err != nil { | ||
| t.Fatalf("second RunSyncWithSelection() error = %v", err) | ||
| } | ||
| if second.FilesChanged != 0 || !second.NoOp { | ||
| t.Fatalf("second sync files changed = %d, no-op = %t; want idempotent no-op", second.FilesChanged, second.NoOp) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| if _, err := os.Stat(f.gentleman); !os.IsNotExist(err) { | ||
| t.Fatalf("second sync restored retired gentleman output style, stat err=%v", err) | ||
| } | ||
| for path, want := range settled { | ||
| got, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatalf("after second sync: read %s: %v", path, err) | ||
| } | ||
| if !bytes.Equal(got, want) { | ||
| t.Fatalf("second sync changed %s = %q, want %q", path, got, want) | ||
| } | ||
| } | ||
| } | ||
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
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.