Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .nextchanges/air/7582.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and its columns no longer overflow on wide (for example CJK) text; `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582))
4 changes: 2 additions & 2 deletions cmd/air/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ func setMLflowLinks(ctx context.Context, w *databricks.WorkspaceClient, host str
}
entries[i].row.MLflowURL = mlflowLogsURL(host, ids)
name := fetchMLflowRunName(ctx, w, ids.RunID)
// Shorten the name, not the retry note, to fit the column.
// Shorten the label, not the retry note, to fit the column.
note := ids.retryNote()
entries[i].row.MLflowLabel = truncate(mlflowRunLabel(name, ids.RunID), mlflowColWidth-len(note)) + note
entries[i].row.MLflowLabel = mlflowRunLabel(name, ids.RunID, mlflowColWidth-len(note)) + note
entries[i].row.ExperimentURL = mlflowExperimentURL(host, ids)
// The ETA needs a progress-metric history fetch, so it's computed only
// for running rows (the only ones that can have one).
Expand Down
50 changes: 50 additions & 0 deletions cmd/air/list_detail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/charmbracelet/lipgloss"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -95,3 +96,52 @@ func TestListRowAndPanesLinkTheSameOlderRetry(t *testing.T) {
assert.Contains(t, info, "MLflow URL: "+srv.URL+"/ml/experiments/E1/runs/R1\n")
assert.Contains(t, logs, "\nMLflow URL (retry 1): "+wantURL+"\n")
}

func TestUnnamedOlderRetryLabelFitsTheListColumnAndIsWholeInTheInfoPane(t *testing.T) {
// Given a failed run whose retry 0 logged to an MLflow run with no name and
// whose last retry failed before it started.
t.Setenv("DATABRICKS_CACHE_DIR", t.TempDir())
const mlflowRunID = "0123456789abcdef0123456789abcdef"
run := indexRun(7, 1000_000)
run.State.ResultState = jobs.RunResultStateFailed
task := run.Tasks[0]
run.Tasks = nil
for attempt, taskRunID := range []int64{70, 71} {
task.RunId, task.AttemptNumber = taskRunID, attempt
run.Tasks = append(run.Tasks, task)
}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case aiTrainingWorkflowsPath:
_, _ = w.Write([]byte(`{"training_workflows": [{"job_run_id": "7", "submit_time": {"seconds": 1000}}]}`))
case "/api/2.2/jobs/runs/get":
_ = json.NewEncoder(w).Encode(run)
case "/api/2.2/jobs/runs/get-output":
if r.URL.Query().Get("run_id") == "70" {
_, _ = w.Write([]byte(`{"ai_runtime_task_output": {"mlflow_experiment_id": "E1", "mlflow_run_id": "` + mlflowRunID + `"}}`))
return
}
_, _ = w.Write([]byte(`{}`))
default:
_, _ = w.Write([]byte(`{}`))
}
}))
t.Cleanup(srv.Close)
ctx := cmdio.MockDiscard(t.Context())
w := newTestWorkspaceClient(t, srv.URL)

// When the list and the info pane render the run.
rows, err := newRunFetcher(ctx, w, listQuery{
userFilter: "me@example.com", currentUser: "me@example.com", limit: 10, fetchMLflow: true,
}).next(10)
require.NoError(t, err)
info, err := runDetailText(ctx, w, 7)
require.NoError(t, err)

// Then the list row keeps the end of the ID and the whole retry note within
// the column, and the info pane shows the whole ID.
require.Len(t, rows, 1)
assert.Equal(t, "…56789abcdef (retry 0)", rows[0].MLflowLabel)
assert.Equal(t, mlflowColWidth, lipgloss.Width(rows[0].MLflowLabel))
assert.Contains(t, info, mlflowRunID+" (retry 0)")
}
23 changes: 21 additions & 2 deletions cmd/air/list_tui_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"github.com/muesli/termenv"
)

Expand Down Expand Up @@ -241,11 +242,29 @@ func pad(s string, n int, right bool) string {

// truncate shortens s to a visible width of n, appending "…" on overflow.
func truncate(s string, n int) string {
if lipgloss.Width(s) <= n {
return ansi.Truncate(s, n, "…")
}

// truncateStart shortens s to a visible width of n, keeping its end behind a
// leading "…" on overflow.
func truncateStart(s string, n int) string {
width := lipgloss.Width(s)
if width <= n {
return s
}
if n <= 1 {
return truncate(s, n)
}
// TruncateLeft never splits a character, so a cut that lands inside a
// two-cell character leaves the result one cell too wide.
cut := width - (n - 1)
out := ansi.TruncateLeft(s, cut, "…")
if lipgloss.Width(out) > n {
out = ansi.TruncateLeft(s, cut+1, "…")
}
// TruncateLeft drops the "…" when nothing of s is left.
if out == "" {
return "…"
}
return string([]rune(s)[:n-1]) + "…"
return out
}
31 changes: 31 additions & 0 deletions cmd/air/list_tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,37 @@ func TestListModelDetailLateMsgDropped(t *testing.T) {
assert.NotContains(t, m.View(), "late result")
}

func TestTruncateFitsDisplayWidth(t *testing.T) {
// A CJK character takes two cells and a combining mark none, so the cut is
// by display width and never splits a character.
const wide = "/Users/张伟/大模型微调实验第一百二十三次评估"
const accented = "xxxxxxxxxxxxxxxxxxxx\u0301yz"
tests := []struct {
name string
s string
n int
wantEnd string // truncate
wantStart string // truncateStart
}{
{name: "fits", s: "abc", n: 5, wantEnd: "abc", wantStart: "abc"},
{name: "exactly fits", s: "abcde", n: 5, wantEnd: "abcde", wantStart: "abcde"},
{name: "one cell over", s: "abcdef", n: 5, wantEnd: "abcd…", wantStart: "…cdef"},
{name: "wide characters", s: wide, n: 11, wantEnd: "/Users/张…", wantStart: "…十三次评估"},
{name: "cut inside a wide character", s: wide, n: 12, wantEnd: "/Users/张伟…", wantStart: "…十三次评估"},
{name: "wide character at width two", s: "评估评估", n: 2, wantEnd: "…", wantStart: "…"},
{name: "combining mark stays with its letter", s: accented, n: 4, wantEnd: "xxx…", wantStart: "…x\u0301yz"},
{name: "combining mark is dropped with its letter", s: accented, n: 3, wantEnd: "xx…", wantStart: "…yz"},
{name: "width of one", s: "abcdef", n: 1, wantEnd: "…", wantStart: "…"},
{name: "width of zero", s: "abcdef", n: 0, wantEnd: "", wantStart: ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.wantEnd, truncate(tt.s, tt.n))
assert.Equal(t, tt.wantStart, truncateStart(tt.s, tt.n))
})
}
}

func TestPadAndTruncate(t *testing.T) {
assert.Equal(t, "ab ", pad("ab", 5, false))
assert.Equal(t, " ab", pad("ab", 5, true))
Expand Down
18 changes: 10 additions & 8 deletions cmd/air/mlflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ func fetchMLflowRunName(ctx context.Context, w *databricks.WorkspaceClient, mlfl
}

// mlflowRunLabel is the text shown for the MLflow Run cell: the run's name, or
// "...{last 8 of run id}" when the name is unknown. Mirrors Python's
// _get_mlflow_run_name (cli_display.py).
func mlflowRunLabel(name, mlflowRunID string) string {
if name != "" {
return name
// its run ID when the name is unknown. A label wider than width keeps its end
// behind a leading "…", because run names often share a prefix and differ at
// the end. A width of 0 or less means no limit.
func mlflowRunLabel(name, mlflowRunID string, width int) string {
label := name
if label == "" {
label = mlflowRunID
}
if len(mlflowRunID) > 8 {
return "..." + mlflowRunID[len(mlflowRunID)-8:]
if width <= 0 {
return label
}
return "..." + mlflowRunID
return truncateStart(label, width)
}
34 changes: 28 additions & 6 deletions cmd/air/mlflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/charmbracelet/lipgloss"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -175,12 +176,33 @@ func TestMLflowURLs(t *testing.T) {
}

func TestMLflowRunLabel(t *testing.T) {
// Uses the run name when it is known.
assert.Equal(t, "sunny-cat-42", mlflowRunLabel("sunny-cat-42", "0123456789abcdef"))
// Falls back to the last 8 characters of a long run id.
assert.Equal(t, "...9abcdef0", mlflowRunLabel("", "0123456789abcdef0"))
// A short run id is shown in full behind the ellipsis.
assert.Equal(t, "...short", mlflowRunLabel("", "short"))
const runID = "0123456789abcdef0123456789abcdef"
tests := []struct {
name string
runName string
runID string
width int
want string
}{
{name: "long name keeps its end", runName: "qwen-finetune-2026-10-23-lr-3e-5", runID: runID, width: 22, want: "…ne-2026-10-23-lr-3e-5"},
{name: "short name is shown whole", runName: "sunny-cat-42", runID: runID, width: 22, want: "sunny-cat-42"},
{name: "name at the width is shown whole", runName: "exactly-twenty-two-chr", runID: runID, width: 22, want: "exactly-twenty-two-chr"},
{name: "unnamed run keeps the end of its ID", runID: runID, width: 22, want: "…bcdef0123456789abcdef"},
{name: "short ID is shown whole", runID: "short", width: 22, want: "short"},
{name: "wide characters count as two cells", runName: "训练运行-实验-第一百二十三次", runID: runID, width: 8, want: "…十三次"},
{name: "width of one leaves only the ellipsis", runName: "sunny-cat-42", runID: runID, width: 1, want: "…"},
{name: "no width limit shows the whole name", runName: "qwen-finetune-2026-10-23-lr-3e-5", runID: runID, want: "qwen-finetune-2026-10-23-lr-3e-5"},
{name: "no width limit shows the whole ID", runID: runID, want: runID},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := mlflowRunLabel(tt.runName, tt.runID, tt.width)
assert.Equal(t, tt.want, got)
if tt.width > 0 {
assert.LessOrEqual(t, lipgloss.Width(got), tt.width)
}
})
}
}

func TestFetchMLflowRunName(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/air/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func renderRunText(ctx context.Context, out io.Writer, w *databricks.WorkspaceCl
}

if ids != nil {
view.mlflowLabel = mlflowRunLabel(fetchMLflowRunName(ctx, w, ids.RunID), ids.RunID) + ids.retryNote()
// The box grows to fit its fields, so the label is shown whole.
view.mlflowLabel = mlflowRunLabel(fetchMLflowRunName(ctx, w, ids.RunID), ids.RunID, 0) + ids.retryNote()
view.mlflowURL = mlflowRunURL(w.Config.Host, ids)
}

Expand Down
Loading