mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 09:08:35 +00:00
fix(shared): default non-finite string sample limits
This commit is contained in:
@@ -43,6 +43,15 @@ describe("summarizeStringEntries", () => {
|
||||
).toBe("a, b, c, d, e, f (+1)");
|
||||
});
|
||||
|
||||
it("uses the default limit for non-finite limits", () => {
|
||||
expect(
|
||||
summarizeStringEntries({
|
||||
entries: ["a", "b", "c", "d", "e", "f", "g"],
|
||||
limit: Number.NaN,
|
||||
}),
|
||||
).toBe("a, b, c, d, e, f (+1)");
|
||||
});
|
||||
|
||||
it("does not add a suffix when the limit exactly matches the entry count", () => {
|
||||
expect(
|
||||
summarizeStringEntries({
|
||||
|
||||
@@ -7,7 +7,8 @@ export function summarizeStringEntries(params: {
|
||||
if (entries.length === 0) {
|
||||
return params.emptyText ?? "";
|
||||
}
|
||||
const limit = Math.max(1, Math.floor(params.limit ?? 6));
|
||||
const rawLimit = params.limit ?? 6;
|
||||
const limit = Number.isFinite(rawLimit) ? Math.max(1, Math.floor(rawLimit)) : 6;
|
||||
const sample = entries.slice(0, limit);
|
||||
const suffix = entries.length > sample.length ? ` (+${entries.length - sample.length})` : "";
|
||||
return `${sample.join(", ")}${suffix}`;
|
||||
|
||||
Reference in New Issue
Block a user