From 07d20bd0620ce9c1c75fc16eef13ee861bdcefdb Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:43:42 +0000 Subject: [PATCH 1/9] air: Shorten MLflow run names and IDs the same way in `air list` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MLflow column of `air list` cut a long run name to its first characters, but showed the last characters of the run ID when the run had no name. Rows with long names sharing a prefix looked identical. The column now shows the run's name, or its ID when the name is unknown, and shortens either one the same way: a label that doesn't fit keeps its end behind a leading "…". Co-authored-by: Isaac --- cmd/air/list.go | 4 ++-- cmd/air/mlflow.go | 25 +++++++++++++++++-------- cmd/air/mlflow_test.go | 34 ++++++++++++++++++++++++++++------ cmd/air/render.go | 3 ++- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/cmd/air/list.go b/cmd/air/list.go index cc2b27c99d4..50108b85c83 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -350,9 +350,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). diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 7cf9f867630..5f9bc99de5d 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "github.com/charmbracelet/lipgloss" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -156,14 +157,22 @@ 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 "…", since run names and IDs tend to share a prefix and +// differ in their tail. 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 || lipgloss.Width(label) <= width { + return label } - return "..." + mlflowRunID + // Drop leading runes until the rest fits beside the "…"; a wide rune takes + // two cells, so the cut is by display width, not rune count. + runes := []rune(label) + for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { + runes = runes[1:] + } + return "…" + string(runes) } diff --git a/cmd/air/mlflow_test.go b/cmd/air/mlflow_test.go index 2f316acaf74..1728ab22111 100644 --- a/cmd/air/mlflow_test.go +++ b/cmd/air/mlflow_test.go @@ -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" @@ -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) { diff --git a/cmd/air/render.go b/cmd/air/render.go index 3985ab57588..755e8540fb9 100644 --- a/cmd/air/render.go +++ b/cmd/air/render.go @@ -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) } From 14d7e6372a391e6ced78a51501d1eeffc0b77fa0 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:44:07 +0000 Subject: [PATCH 2/9] Add changelog fragment Co-authored-by: Isaac --- .nextchanges/air/7582.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7582.md diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md new file mode 100644 index 00000000000..41c227969f2 --- /dev/null +++ b/.nextchanges/air/7582.md @@ -0,0 +1 @@ +* `air list` shortens a long MLflow run name the same way as a run ID, keeping its end behind a leading `…`, so runs whose names share a prefix stay distinguishable. ([#7582](https://github.com/databricks/cli/pull/7582)) From d09a5a252ce1d49662d1c9b300203698eeeb8cef Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:51:08 +0000 Subject: [PATCH 3/9] air: Fit `air list` Experiment and User columns to the terminal width The interactive list sized every column from its content, capped at 36 cells, and never looked at the terminal width. Long Experiment and User values pushed the columns to their right past the window edge. The list now tracks the width from WindowSizeMsg and shrinks Experiment and User, widest first, down to floors of 12 and 8 cells. The one-shot table (piped, NO_COLOR, --limit) is unchanged. Co-authored-by: Isaac --- cmd/air/list_tui.go | 5 +- cmd/air/list_tui_render.go | 41 +++++++++++++++++ cmd/air/list_tui_test.go | 93 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) diff --git a/cmd/air/list_tui.go b/cmd/air/list_tui.go index af5951bca44..56ec08803c5 100644 --- a/cmd/air/list_tui.go +++ b/cmd/air/list_tui.go @@ -115,6 +115,7 @@ type listModel struct { cursor int offset int // index of the first visible row height int // terminal height, for windowing + width int // terminal width, for fitting the flexible columns; 0 until known mode int // modeList or modeDetail viewport viewport.Model // for detail pane @@ -188,6 +189,8 @@ func (m listModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: m.height = msg.Height + m.width = msg.Width + m.cols = computeListCols(m.rows).fitWidth(m.width) m.viewport.Width = msg.Width m.viewport.Height = max(msg.Height-3, 1) m.viewport.SetContent(m.wrappedDetail()) @@ -201,7 +204,7 @@ func (m listModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } m.rows = append(m.rows, msg.rows...) - m.cols = computeListCols(m.rows) + m.cols = computeListCols(m.rows).fitWidth(m.width) m.offset = m.clampedOffset() // A page with no matches but more to scan: keep paging so the cursor isn't // stuck at the end of the loaded rows. diff --git a/cmd/air/list_tui_render.go b/cmd/air/list_tui_render.go index 3f23535a8e2..c33456e9fe8 100644 --- a/cmd/air/list_tui_render.go +++ b/cmd/air/list_tui_render.go @@ -68,6 +68,47 @@ func computeListCols(rows []listRow) listCols { return c } +// Floors for the flexible columns: narrow enough to give room back to the fixed +// columns, wide enough that a truncated value is still recognizable. +const ( + experimentMinWidth = 12 + userMinWidth = 8 +) + +// tableWidth is the full width of a rendered row: every column plus the gutter +// and the two-cell separators. +func (c listCols) tableWidth() int { + const separators = 9 * 2 + return 1 + c.runID + c.experiment + c.status + c.started + c.duration + + c.progress + mlflowColWidth + c.user + c.accel + separators +} + +// fitWidth shrinks the flexible columns (Experiment, User) until the table fits +// in width cells, so a long value truncates instead of pushing the columns to +// its right off screen. It takes from the wider column first and stops at the +// floors: a terminal too narrow for the fixed columns still overflows. A width +// of 0 means the terminal size is unknown and leaves the columns alone. +func (c listCols) fitWidth(width int) listCols { + if width <= 0 { + return c + } + experimentFloor := min(c.experiment, experimentMinWidth) + userFloor := min(c.user, userMinWidth) + for overflow := c.tableWidth() - width; overflow > 0; overflow-- { + canShrinkExperiment := c.experiment > experimentFloor + canShrinkUser := c.user > userFloor + switch { + case canShrinkExperiment && (!canShrinkUser || c.experiment >= c.user): + c.experiment-- + case canShrinkUser: + c.user-- + default: + return c + } + } + return c +} + // renderHeader renders the muted column-title row. func (s listStyles) renderHeader(cols listCols) string { h := func(text string, width int, right bool) string { diff --git a/cmd/air/list_tui_test.go b/cmd/air/list_tui_test.go index f195006f222..d0b5cf4270c 100644 --- a/cmd/air/list_tui_test.go +++ b/cmd/air/list_tui_test.go @@ -344,3 +344,96 @@ func TestPadAndTruncate(t *testing.T) { assert.Equal(t, "abcd…", truncate("abcdefgh", 5)) assert.Equal(t, "abc", truncate("abc", 5)) } + +// wideListRows is a fixture whose Experiment and User values both exceed +// columnCap, with realistic widths in the fixed columns. +func wideListRows() []listRow { + return []listRow{ + {RunID: "684127395104822", Experiment: "/Users/someone.longname@example.com/quickstart/qwen-finetune-lora", User: "someone.with.a.long.name.for.testing@example.com", Status: "SUCCESS", StartedAt: new("2026-10-23T17:32:39.000000+00:00"), Duration: "1h 14m", MLflowURL: "https://h.test/ml/experiments/E/runs/04c41514fbb0", MLflowLabel: "qwen-run-001", Accelerators: "8x H100"}, + {RunID: "684127395104823", Experiment: "mixtral", User: "me@example.com", Status: "RUNNING", StartedAt: new("2026-10-23T18:43:24.000000+00:00"), Duration: "3m 32s", Progress: "81% · ~48m", MLflowURL: "-", MLflowLabel: "-", Accelerators: "1x A10"}, + } +} + +func TestListColsFitWidth(t *testing.T) { + natural := computeListCols(wideListRows()) + require.Equal(t, columnCap, natural.experiment) + require.Equal(t, columnCap, natural.user) + require.Equal(t, 186, natural.tableWidth()) + + tests := []struct { + name string + width int + wantExperiment int + wantUser int + wantFits bool + }{ + {name: "unknown width leaves columns alone", width: 0, wantExperiment: columnCap, wantUser: columnCap}, + // The fixed columns alone need 114 cells, so both flexible columns sit at + // their floors and the table still overflows. + {name: "80 columns", width: 80, wantExperiment: experimentMinWidth, wantUser: userMinWidth}, + {name: "120 columns", width: 120, wantExperiment: experimentMinWidth, wantUser: userMinWidth}, + {name: "narrowest width that fits", width: 134, wantExperiment: experimentMinWidth, wantUser: userMinWidth, wantFits: true}, + {name: "160 columns splits the shortfall", width: 160, wantExperiment: 23, wantUser: 23, wantFits: true}, + {name: "200 columns keeps natural widths", width: 200, wantExperiment: columnCap, wantUser: columnCap, wantFits: true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := natural.fitWidth(tt.width) + assert.Equal(t, tt.wantExperiment, got.experiment) + assert.Equal(t, tt.wantUser, got.user) + if tt.wantFits { + assert.LessOrEqual(t, got.tableWidth(), tt.width) + } + + // Only the flexible columns change. + got.experiment, got.user = natural.experiment, natural.user + assert.Equal(t, natural, got) + }) + } +} + +func TestListColsFitWidthFloorsNeverWiden(t *testing.T) { + // Columns already narrower than the floors stay as they are. + natural := computeListCols(testListRows()) + got := natural.fitWidth(40) + assert.Equal(t, natural.experiment, got.experiment) + assert.Equal(t, userMinWidth, got.user) +} + +func TestListModelFitsTerminalWidth(t *testing.T) { + r, _ := cmdio.NewRenderer(cmdio.MockDiscard(t.Context()), io.Discard) + rows := wideListRows() + f := &runFetcher{ctx: t.Context(), exhausted: true} + m := newListModel(r, f, rows[:1], false) + + // Before the terminal reports its size the columns keep their natural widths. + assert.Equal(t, columnCap, m.cols.experiment) + + next, _ := m.Update(tea.WindowSizeMsg{Width: 160, Height: 30}) + m = next.(listModel) + lines := strings.Split(strings.TrimRight(m.View(), "\n"), "\n") + require.Len(t, lines, 3) // header, one row, hint + for _, line := range lines[:2] { + assert.LessOrEqual(t, ansi.StringWidth(line), 160) + } + assert.Contains(t, lines[0], "Accelerators") + assert.Contains(t, lines[1], "8x H100") + assert.Contains(t, lines[1], "…", "long values truncate") + + // A lazily loaded page is laid out against the same width. + next, _ = m.Update(moreRowsMsg{rows: rows[1:]}) + m = next.(listModel) + assert.LessOrEqual(t, m.cols.tableWidth(), 160) + + // Widening the terminal restores the natural widths. + next, _ = m.Update(tea.WindowSizeMsg{Width: 200, Height: 30}) + m = next.(listModel) + assert.Equal(t, columnCap, m.cols.experiment) + assert.Equal(t, columnCap, m.cols.user) +} + +func TestStaticListTableIgnoresTerminalWidth(t *testing.T) { + r, _ := cmdio.NewRenderer(cmdio.MockDiscard(t.Context()), io.Discard) + header, _, _ := strings.Cut(staticListTable(r, wideListRows(), false), "\n") + assert.Equal(t, computeListCols(wideListRows()).tableWidth(), ansi.StringWidth(header)) +} From e80a20a47c1447b3ce2e13b4fd8b6d63cd45fac1 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:52:33 +0000 Subject: [PATCH 4/9] Add changelog fragment Co-authored-by: Isaac --- .nextchanges/air/7583.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7583.md diff --git a/.nextchanges/air/7583.md b/.nextchanges/air/7583.md new file mode 100644 index 00000000000..c71bda76748 --- /dev/null +++ b/.nextchanges/air/7583.md @@ -0,0 +1 @@ +* Shrink the Experiment and User columns of the interactive `air list` table to fit the terminal width, so long values no longer push the other columns off screen. ([#7583](https://github.com/databricks/cli/pull/7583)) From 9d6ace2ea111268fce74c04de09e49ae076f29bd Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:00:55 +0000 Subject: [PATCH 5/9] air: Test the unnamed-run MLflow label with a retry note Covers the list row's width budget when a retry note follows a shortened label, and the whole run ID in the info pane. Also corrects the label's doc comment and widens the changelog entry to cover run IDs. Co-authored-by: Isaac --- .nextchanges/air/7582.md | 2 +- cmd/air/list_detail_test.go | 50 +++++++++++++++++++++++++++++++++++++ cmd/air/mlflow.go | 7 +++--- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md index 41c227969f2..b275116fbca 100644 --- a/.nextchanges/air/7582.md +++ b/.nextchanges/air/7582.md @@ -1 +1 @@ -* `air list` shortens a long MLflow run name the same way as a run ID, keeping its end behind a leading `…`, so runs whose names share a prefix stay distinguishable. ([#7582](https://github.com/databricks/cli/pull/7582)) +* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582)) diff --git a/cmd/air/list_detail_test.go b/cmd/air/list_detail_test.go index 8cbe2c8d3b6..997b8131c48 100644 --- a/cmd/air/list_detail_test.go +++ b/cmd/air/list_detail_test.go @@ -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" @@ -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)") +} diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 5f9bc99de5d..9294552abd1 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -158,8 +158,8 @@ func fetchMLflowRunName(ctx context.Context, w *databricks.WorkspaceClient, mlfl // mlflowRunLabel is the text shown for the MLflow Run cell: the run's name, or // its run ID when the name is unknown. A label wider than width keeps its end -// behind a leading "…", since run names and IDs tend to share a prefix and -// differ in their tail. A width of 0 or less means no limit. +// 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 == "" { @@ -168,8 +168,7 @@ func mlflowRunLabel(name, mlflowRunID string, width int) string { if width <= 0 || lipgloss.Width(label) <= width { return label } - // Drop leading runes until the rest fits beside the "…"; a wide rune takes - // two cells, so the cut is by display width, not rune count. + // A wide rune takes two cells, so cut by display width, not rune count. runes := []rune(label) for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { runes = runes[1:] From 60bd00e18bc91aeaee1c3e708c939a9994c94def Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:45:03 +0000 Subject: [PATCH 6/9] air: Cut `air list` cells by display width truncate measured display width but cut by character count, so a cell with wide (for example CJK) text overflowed its column. It now cuts by display width. truncateStart is the keep-the-end variant, and the MLflow label uses it instead of its own loop. Co-authored-by: Isaac --- .nextchanges/air/7582.md | 2 +- cmd/air/list_tui_render.go | 23 +++++++++++++++++++++-- cmd/air/list_tui_test.go | 31 +++++++++++++++++++++++++++++++ cmd/air/mlflow.go | 10 ++-------- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md index b275116fbca..a6306817810 100644 --- a/.nextchanges/air/7582.md +++ b/.nextchanges/air/7582.md @@ -1 +1 @@ -* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582)) +* `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)) diff --git a/cmd/air/list_tui_render.go b/cmd/air/list_tui_render.go index 3f23535a8e2..7b9add62f47 100644 --- a/cmd/air/list_tui_render.go +++ b/cmd/air/list_tui_render.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" "github.com/muesli/termenv" ) @@ -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 } diff --git a/cmd/air/list_tui_test.go b/cmd/air/list_tui_test.go index f195006f222..89964d14619 100644 --- a/cmd/air/list_tui_test.go +++ b/cmd/air/list_tui_test.go @@ -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)) diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 9294552abd1..82a0a96ca3e 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -6,7 +6,6 @@ import ( "slices" "strings" - "github.com/charmbracelet/lipgloss" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -165,13 +164,8 @@ func mlflowRunLabel(name, mlflowRunID string, width int) string { if label == "" { label = mlflowRunID } - if width <= 0 || lipgloss.Width(label) <= width { + if width <= 0 { return label } - // A wide rune takes two cells, so cut by display width, not rune count. - runes := []rune(label) - for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { - runes = runes[1:] - } - return "…" + string(runes) + return truncateStart(label, width) } From c02f1eaf08d8bb96514d2780553df970745d23f3 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:53:00 +0000 Subject: [PATCH 7/9] air: Keep the end of a shortened Experiment name in the `air list` table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Experiment names often share a prefix and differ at the end, so a cell shrunk to fit the terminal showed the same text for different experiments. The interactive list now keeps the end of the name behind a leading "…", the same rule the MLflow column uses. User still keeps its start, and the one-shot table is unchanged. Co-authored-by: Isaac --- cmd/air/list_tui.go | 7 ++++++- cmd/air/list_tui_test.go | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/air/list_tui.go b/cmd/air/list_tui.go index 56ec08803c5..53ae3b3980f 100644 --- a/cmd/air/list_tui.go +++ b/cmd/air/list_tui.go @@ -350,7 +350,12 @@ func (m listModel) View() string { visible := m.visibleCount() lines := []string{m.styles.renderHeader(m.cols)} for i := m.offset; i < m.offset+visible && i < len(m.rows); i++ { - lines = append(lines, m.styles.renderRow(m.cols, m.rows[i], i == m.cursor, m.links)) + row := m.rows[i] + // Experiment names often share a prefix and differ at the end, so a + // shrunk cell keeps the end. The one-shot table keeps the start, so its + // output stays as scripts already see it. + row.Experiment = truncateStart(row.Experiment, m.cols.experiment) + lines = append(lines, m.styles.renderRow(m.cols, row, i == m.cursor, m.links)) } lines = append(lines, m.renderHint()) return strings.Join(lines, "\n") + "\n" diff --git a/cmd/air/list_tui_test.go b/cmd/air/list_tui_test.go index dfd057c770b..d8c129c2d5b 100644 --- a/cmd/air/list_tui_test.go +++ b/cmd/air/list_tui_test.go @@ -449,7 +449,9 @@ func TestListModelFitsTerminalWidth(t *testing.T) { } assert.Contains(t, lines[0], "Accelerators") assert.Contains(t, lines[1], "8x H100") - assert.Contains(t, lines[1], "…", "long values truncate") + // Experiment keeps its end, User its start. + assert.Contains(t, lines[1], " …tart/qwen-finetune-lora ") + assert.Contains(t, lines[1], " someone.with.a.long.nam… ") // A lazily loaded page is laid out against the same width. next, _ = m.Update(moreRowsMsg{rows: rows[1:]}) @@ -465,6 +467,8 @@ func TestListModelFitsTerminalWidth(t *testing.T) { func TestStaticListTableIgnoresTerminalWidth(t *testing.T) { r, _ := cmdio.NewRenderer(cmdio.MockDiscard(t.Context()), io.Discard) - header, _, _ := strings.Cut(staticListTable(r, wideListRows(), false), "\n") - assert.Equal(t, computeListCols(wideListRows()).tableWidth(), ansi.StringWidth(header)) + lines := strings.Split(staticListTable(r, wideListRows(), false), "\n") + assert.Equal(t, computeListCols(wideListRows()).tableWidth(), ansi.StringWidth(lines[0])) + // The one-shot table still cuts a long Experiment at its end. + assert.Contains(t, lines[1], " /Users/someone.longname@example.com… ") } From 9d345cc4d3aebf1c315e88fbf9a769bb9174e92b Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:58:17 +0000 Subject: [PATCH 8/9] Update changelog fragment Co-authored-by: Isaac --- .nextchanges/air/7583.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/air/7583.md b/.nextchanges/air/7583.md index c71bda76748..2cf218fa8fc 100644 --- a/.nextchanges/air/7583.md +++ b/.nextchanges/air/7583.md @@ -1 +1 @@ -* Shrink the Experiment and User columns of the interactive `air list` table to fit the terminal width, so long values no longer push the other columns off screen. ([#7583](https://github.com/databricks/cli/pull/7583)) +* Shrink the Experiment and User columns of the interactive `air list` table to fit the terminal width, keeping the end of a shortened experiment name. ([#7583](https://github.com/databricks/cli/pull/7583)) From 719ff0e08a613e01d2c85539cf80d0b967763687 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 08:17:43 +0000 Subject: [PATCH 9/9] Re-run checks against the stacked base Co-authored-by: Isaac