Skip to content

Commit 1068c1a

Browse files
committed
fix(cli): keep commitments table columns aligned
1 parent add9f3c commit 1068c1a

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎src/commands/commitments.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ describe("commitments command", () => {
9090
]);
9191
});
9292

93+
it("keeps fixed-width table columns aligned when values are truncated", async () => {
94+
mocks.listCommitments.mockResolvedValue([
95+
commitment({
96+
id: "cm_abcdefghijklmnopqrstuvwxyz",
97+
agentId: "agent-with-a-very-long-name",
98+
channel: "telegram",
99+
to: "recipient-with-a-very-long-address",
100+
suggestedText:
101+
"This suggested text is intentionally long enough to exceed the table cell width and be truncated.",
102+
}),
103+
]);
104+
const { runtime, logs } = createRuntime();
105+
106+
await commitmentsListCommand({}, runtime);
107+
108+
const tableLines = logs.map(stripAnsi).slice(3);
109+
const [header, row] = tableLines;
110+
if (!header || !row) {
111+
throw new Error("Expected commitments table header and row");
112+
}
113+
expect(row).toContain("…");
114+
expect(row).not.toContain("...");
115+
const rowValuesByHeader = new Map([
116+
["Status", "pending"],
117+
["Kind", "event_check_in"],
118+
["Due", "2026-04-30T17:00:00.000Z"],
119+
["Scope", "agent-with-a-very-long-name"],
120+
["Suggested text", "This suggested text"],
121+
]);
122+
for (const [label, rowValue] of rowValuesByHeader) {
123+
const expectedColumn = header.indexOf(label);
124+
expect(expectedColumn).toBeGreaterThanOrEqual(0);
125+
expect(row.indexOf(rowValue)).toBe(expectedColumn);
126+
}
127+
});
128+
93129
it("tolerates Date-invalid commitment due timestamps in table output", async () => {
94130
mocks.listCommitments.mockResolvedValue([
95131
commitment({

‎src/commands/commitments.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ const STATUS_VALUES = new Set<CommitmentStatus>([
2424
]);
2525

2626
function truncate(value: string, maxChars: number): string {
27-
return value.length <= maxChars ? value : `${value.slice(0, maxChars - 1)}...`;
27+
if (value.length <= maxChars) {
28+
return value;
29+
}
30+
if (maxChars <= 1) {
31+
return value.slice(0, maxChars);
32+
}
33+
return `${value.slice(0, maxChars - 1)}…`;
2834
}
2935

3036
function safe(value: string): string {

0 commit comments

Comments
 (0)