|
1 | 1 | // Sessions cleanup tests cover stale session cleanup and runtime output. |
2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | +import { visibleWidth } from "../../packages/terminal-core/src/ansi.js"; |
3 | 4 | import type { SessionEntry } from "../config/sessions.js"; |
4 | 5 | import type { RuntimeEnv } from "../runtime.js"; |
5 | 6 |
|
@@ -643,6 +644,76 @@ describe("sessionsCleanupCommand", () => { |
643 | 644 | expectLogsToInclude(logs, "Total: 3 kept, 4 pruned"); |
644 | 645 | }); |
645 | 646 |
|
| 647 | + it("aligns the label summary columns for emoji and CJK labels", async () => { |
| 648 | + mocks.enforceSessionDiskBudget.mockResolvedValue(null); |
| 649 | + mocks.runSessionsCleanup.mockResolvedValue({ |
| 650 | + mode: "warn", |
| 651 | + previewResults: [ |
| 652 | + { |
| 653 | + summary: { |
| 654 | + agentId: "main", |
| 655 | + storePath: "/resolved/sessions.json", |
| 656 | + mode: "warn", |
| 657 | + dryRun: true, |
| 658 | + beforeCount: 2, |
| 659 | + afterCount: 2, |
| 660 | + missing: 0, |
| 661 | + dmScopeRetired: 0, |
| 662 | + pruned: 0, |
| 663 | + capped: 0, |
| 664 | + unreferencedArtifacts: { |
| 665 | + scannedFiles: 0, |
| 666 | + removedFiles: 0, |
| 667 | + freedBytes: 0, |
| 668 | + olderThanMs: 604800000, |
| 669 | + }, |
| 670 | + diskBudget: null, |
| 671 | + wouldMutate: true, |
| 672 | + }, |
| 673 | + beforeStore: { |
| 674 | + emojiKept: { |
| 675 | + sessionId: "emoji-kept", |
| 676 | + updatedAt: 2, |
| 677 | + model: "test:opus", |
| 678 | + label: "🔥修复", |
| 679 | + }, |
| 680 | + plainKept: { |
| 681 | + sessionId: "plain-kept", |
| 682 | + updatedAt: 1, |
| 683 | + model: "test:opus", |
| 684 | + label: "plain", |
| 685 | + }, |
| 686 | + }, |
| 687 | + missingKeys: new Set<string>(), |
| 688 | + staleKeys: new Set<string>(), |
| 689 | + cappedKeys: new Set<string>(), |
| 690 | + budgetEvictedKeys: new Set<string>(), |
| 691 | + dmScopeRetiredKeys: new Set<string>(), |
| 692 | + }, |
| 693 | + ], |
| 694 | + appliedSummaries: [], |
| 695 | + }); |
| 696 | + |
| 697 | + const { runtime, logs } = makeRuntime(); |
| 698 | + await sessionsCleanupCommand( |
| 699 | + { |
| 700 | + dryRun: true, |
| 701 | + }, |
| 702 | + runtime, |
| 703 | + ); |
| 704 | + |
| 705 | + expectLogsToInclude(logs, "Summary by Label:"); |
| 706 | + const summaryLogs = logs.slice(logs.indexOf("Summary by Label:") + 1); |
| 707 | + const emojiLine = summaryLogs.find((line) => line.includes("🔥修复")); |
| 708 | + const plainLine = summaryLogs.find((line) => line.includes("plain")); |
| 709 | + expect(emojiLine).toBeDefined(); |
| 710 | + expect(plainLine).toBeDefined(); |
| 711 | + // "🔥修复" is 6 visible columns (wide emoji + 2 CJK) but only 5 UTF-16 code |
| 712 | + // units; padding by code-unit length would shift the counts column left. |
| 713 | + const keptColumn = (line: string) => visibleWidth(line.slice(0, line.indexOf("1 kept"))); |
| 714 | + expect(keptColumn(emojiLine ?? "")).toBe(keptColumn(plainLine ?? "")); |
| 715 | + }); |
| 716 | + |
646 | 717 | it("returns grouped JSON for --all-agents dry-runs", async () => { |
647 | 718 | mocks.resolveSessionStoreTargets.mockReturnValue([ |
648 | 719 | { agentId: "main", storePath: "/resolved/main-sessions.json" }, |
|
0 commit comments