Skip to content

Commit 78abe81

Browse files
committed
merge(main): refresh xAI terminal outcome repair
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5': fix(channels): preserve filters in offline status diagnostics (#117570) perf(gateway): separate startup maintenance timing (#117577) refactor(tests): deduplicate database-first guard fixtures (#117594) fix(cli): align sessions cleanup label summary by visible width (#117459) perf(gateway): skip empty session reconciliation (#117589)
2 parents 46e0627 + 81e392b commit 78abe81

10 files changed

Lines changed: 987 additions & 1367 deletions

‎src/commands/channels.config-only-status-output.test.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ vi.mock("../channels/plugins/index.js", () => ({
1111
listChannelPlugins: () => activeChannelPlugins,
1212
getLoadedChannelPlugin: (id: string) => activeChannelPlugins.find((plugin) => plugin.id === id),
1313
getChannelPlugin: (id: string) => activeChannelPlugins.find((plugin) => plugin.id === id),
14+
normalizeChannelId: (value: string) => {
15+
const normalized = value.trim().toLowerCase();
16+
return normalized === "wa" || normalized === "whatsapp" ? "whatsapp" : null;
17+
},
1418
}));
1519

1620
vi.mock("../channels/plugins/read-only.js", () => ({
@@ -25,12 +29,18 @@ async function formatLocalStatusSummary(
2529
cfg: unknown,
2630
options?: {
2731
sourceConfig?: unknown;
32+
channel?: string;
2833
},
2934
) {
3035
const lines = await formatConfigChannelsStatusLines(
3136
cfg as never,
3237
{ mode: "local" },
33-
options?.sourceConfig ? { sourceConfig: options.sourceConfig as never } : undefined,
38+
options
39+
? {
40+
...(options.sourceConfig ? { sourceConfig: options.sourceConfig as never } : {}),
41+
...(options.channel !== undefined ? { channel: options.channel } : {}),
42+
}
43+
: undefined,
3444
);
3545
return lines.join("\n");
3646
}
@@ -193,6 +203,68 @@ function requireReadOnlyPluginListCall(): unknown[] {
193203
}
194204

195205
describe("config-only channels status output", () => {
206+
it.each([
207+
{
208+
label: "unregistered external channels",
209+
channel: "token-only",
210+
included: ["TokenOnly"],
211+
excluded: ["WhatsApp"],
212+
},
213+
{
214+
label: "case-insensitive external channels",
215+
channel: "TOKEN-ONLY",
216+
included: ["TokenOnly"],
217+
excluded: ["WhatsApp"],
218+
},
219+
{
220+
label: "bundled channel aliases",
221+
channel: "wa",
222+
included: ["WhatsApp"],
223+
excluded: ["TokenOnly"],
224+
},
225+
{
226+
label: "unknown channels",
227+
channel: "missing-channel",
228+
included: [],
229+
excluded: ["TokenOnly", "WhatsApp"],
230+
},
231+
{
232+
label: "no channel filter",
233+
channel: undefined,
234+
included: ["TokenOnly", "WhatsApp"],
235+
excluded: [],
236+
},
237+
{
238+
label: "blank channel filters",
239+
channel: " ",
240+
included: ["TokenOnly", "WhatsApp"],
241+
excluded: [],
242+
},
243+
])(
244+
"preserves exact config-only status filtering for $label",
245+
async ({ channel, included, excluded }) => {
246+
activeChannelPlugins.splice(
247+
0,
248+
activeChannelPlugins.length,
249+
makeUnavailableTokenPlugin(),
250+
makeIndeterminateLinkPlugin(),
251+
);
252+
253+
const summary = await formatLocalStatusSummary(
254+
{ channels: { "token-only": {}, whatsapp: {} } },
255+
{ channel },
256+
);
257+
258+
expect(summary).toContain("Gateway not reachable; showing config-only status.");
259+
for (const label of included) {
260+
expect(summary).toContain(label);
261+
}
262+
for (const label of excluded) {
263+
expect(summary).not.toContain(label);
264+
}
265+
},
266+
);
267+
196268
it("uses setup fallback plugins so configured external channels can be shown", async () => {
197269
registerSingleTestPlugin("token-only", makeUnavailableTokenPlugin());
198270
listReadOnlyChannelPluginsForConfig.mockClear();

‎src/commands/channels/status-config-format.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Config-only channel status formatter used when the gateway is unreachable.
2+
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
23
import { formatDocsLink } from "../../../packages/terminal-core/src/links.js";
34
import { theme } from "../../../packages/terminal-core/src/theme.js";
45
import {
@@ -68,7 +69,9 @@ export async function formatConfigChannelsStatusLines(
6869
});
6970

7071
const sourceConfig = opts?.sourceConfig ?? cfg;
71-
const requestedChannel = opts?.channel ? normalizeChannelId(opts.channel) : null;
72+
const requestedChannel = opts?.channel
73+
? (normalizeChannelId(opts.channel) ?? normalizeOptionalLowercaseString(opts.channel))
74+
: null;
7275
const plugins = listReadOnlyChannelPluginsForConfig(cfg, {
7376
activationSourceConfig: sourceConfig,
7477
includeSetupFallbackPlugins: true,

‎src/commands/sessions-cleanup.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Sessions cleanup tests cover stale session cleanup and runtime output.
22
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
import { visibleWidth } from "../../packages/terminal-core/src/ansi.js";
34
import type { SessionEntry } from "../config/sessions.js";
45
import type { RuntimeEnv } from "../runtime.js";
56

@@ -643,6 +644,76 @@ describe("sessionsCleanupCommand", () => {
643644
expectLogsToInclude(logs, "Total: 3 kept, 4 pruned");
644645
});
645646

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+
646717
it("returns grouped JSON for --all-agents dry-runs", async () => {
647718
mocks.resolveSessionStoreTargets.mockReturnValue([
648719
{ agentId: "main", storePath: "/resolved/main-sessions.json" },

‎src/commands/sessions-cleanup.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* It can delegate cleanup to a live gateway or run local store maintenance,
55
* with dry-run tables that explain every planned pruning action.
66
*/
7+
import { visibleWidth } from "../../packages/terminal-core/src/ansi.js";
78
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
89
import { isRich, theme } from "../../packages/terminal-core/src/theme.js";
910
import { getRuntimeConfig } from "../config/config.js";
@@ -129,15 +130,15 @@ function renderLabelSummaries(params: {
129130
if (summaries.length === 0) {
130131
return;
131132
}
132-
const labelPad = Math.max(...summaries.map((summary) => summary.label.length));
133+
const labelPad = Math.max(...summaries.map((summary) => visibleWidth(summary.label)));
133134
const totalKept = summaries.reduce((total, summary) => total + summary.kept, 0);
134135
const totalPruned = summaries.reduce((total, summary) => total + summary.pruned, 0);
135136
params.runtime.log("");
136137
params.runtime.log("Summary by Label:");
137138
for (const summary of summaries) {
138-
params.runtime.log(
139-
`${summary.label.padEnd(labelPad)} ${summary.kept} kept, ${summary.pruned} pruned`,
140-
);
139+
const remaining = labelPad - visibleWidth(summary.label);
140+
const paddedLabel = remaining > 0 ? `${summary.label}${" ".repeat(remaining)}` : summary.label;
141+
params.runtime.log(`${paddedLabel} ${summary.kept} kept, ${summary.pruned} pruned`);
141142
}
142143
params.runtime.log(`Total: ${totalKept} kept, ${totalPruned} pruned`);
143144
}

‎src/gateway/server-startup-bootstrap.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,20 @@ export async function prepareGatewayServerBootstrap(input: {
475475
const workerModule = await loadWorkerEnvironmentStartupModule();
476476
return await workerModule.loadGatewayWorkerEnvironmentStartupState();
477477
});
478-
const { prepareGatewayPluginBootstrap } = await loadStartupPluginsModule();
478+
const { prepareGatewayPluginBootstrap, runGatewayStartupMaintenance } =
479+
await loadStartupPluginsModule();
480+
await startupTrace.measure("startup.maintenance", () =>
481+
runGatewayStartupMaintenance({
482+
cfgAtStart,
483+
startupRuntimeConfig,
484+
minimalTestGateway,
485+
log,
486+
}),
487+
);
479488
const pluginBootstrap = await startupTrace.measure("plugins.bootstrap", () =>
480489
prepareGatewayPluginBootstrap({
481490
cfgAtStart,
482491
activationSourceConfig: startupActivationSourceConfig,
483-
startupRuntimeConfig,
484492
pluginMetadataSnapshot: startupConfigLoad.pluginMetadataSnapshot,
485493
workerProviderIds: workerEnvironmentStartup?.durableProviderIds ?? [],
486494
minimalTestGateway,

0 commit comments

Comments
 (0)