fix: strip trailing slash from workspace path in status display
Paths like `/home/user/project/` caused empty project name because LastIndex found the trailing slash. TrimRight ensures correct extraction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
deebe3e7e8
commit
5aa7473e14
2 changed files with 22 additions and 5 deletions
|
|
@ -1152,11 +1152,11 @@ func buildRichStatus(task *activeTask, isBackground bool, workspace string) stri
|
||||||
// Workspace: always emit for fixed height (show project name only)
|
// Workspace: always emit for fixed height (show project name only)
|
||||||
sb.WriteString("\U0001F4C1 ")
|
sb.WriteString("\U0001F4C1 ")
|
||||||
if workspace != "" {
|
if workspace != "" {
|
||||||
project := workspace
|
project := strings.TrimRight(workspace, "/\\")
|
||||||
if idx := strings.LastIndex(workspace, "/"); idx >= 0 {
|
if idx := strings.LastIndex(project, "/"); idx >= 0 {
|
||||||
project = workspace[idx+1:]
|
project = project[idx+1:]
|
||||||
} else if idx := strings.LastIndex(workspace, "\\"); idx >= 0 {
|
} else if idx := strings.LastIndex(project, "\\"); idx >= 0 {
|
||||||
project = workspace[idx+1:]
|
project = project[idx+1:]
|
||||||
}
|
}
|
||||||
sb.WriteString(project)
|
sb.WriteString(project)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1569,6 +1569,23 @@ func TestBuildRichStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildRichStatus_TrailingSlash(t *testing.T) {
|
||||||
|
task := &activeTask{
|
||||||
|
Iteration: 1,
|
||||||
|
MaxIter: 10,
|
||||||
|
toolLog: []toolLogEntry{
|
||||||
|
{Name: "exec", ArgsSnip: "ls", Result: "✓ 0.1s"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Trailing slash should not break project name extraction
|
||||||
|
for _, ws := range []string{"/home/user/terra-py-form/", "/home/user/terra-py-form", "C:\\Users\\dev\\terra-py-form\\"} {
|
||||||
|
got := buildRichStatus(task, false, ws)
|
||||||
|
if !strings.Contains(got, "terra-py-form") {
|
||||||
|
t.Errorf("workspace %q: expected 'terra-py-form' in output, got:\n%s", ws, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildRichStatus_FixedHeight(t *testing.T) {
|
func TestBuildRichStatus_FixedHeight(t *testing.T) {
|
||||||
// Test that output has the same number of lines regardless of entry count
|
// Test that output has the same number of lines regardless of entry count
|
||||||
countLines := func(s string) int {
|
countLines := func(s string) int {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue