From 2d90d4d243c4ba0f4ef8f869aeb470b715e23a15 Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:37:50 +0800 Subject: [PATCH] Bound the Approve-all failure line and the reasons it prints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One Approve all click on failing cards painted one unbounded role='alert' row: every card's reason joined with ' · ', no cap on rows and no cap on length, and errorText passed an unknown host sentence through whole. The dock's line now names at most three people and counts the rest in the window's words ('{count} more not shown' — a dictionary string already in core/src/client/i18n.js), and one reason longer than 200 code points is cut with a marked ellipsis. notSent's naked slice(0, 200), which cut on UTF-16 units and could split a surrogate pair, shares the same helper. Fixes #3158 --- changelog.d/3158.fixed.md | 1 + docs/subsystems/social.md | 2 +- plugins/social/client.js | 22 +++++-- .../social/test/approve-all-failure.test.js | 57 +++++++++++++++++++ plugins/social/test/social.test.js | 16 ++++++ 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 changelog.d/3158.fixed.md diff --git a/changelog.d/3158.fixed.md b/changelog.d/3158.fixed.md new file mode 100644 index 000000000..4b593a1ab --- /dev/null +++ b/changelog.d/3158.fixed.md @@ -0,0 +1 @@ +The chat dock's **Approve all** failure line now names at most three people and ends with `2 more not shown` (还有 2 条未显示 in a Chinese window) instead of growing with every failing card, and a failure reason the host passes through whole is cut at 200 code points, so one batch can no longer fill the alert ([#3158](https://github.com/ThinkFlowLab/FlyBot/issues/3158)). diff --git a/docs/subsystems/social.md b/docs/subsystems/social.md index 46a08e779..9f5a8b69c 100644 --- a/docs/subsystems/social.md +++ b/docs/subsystems/social.md @@ -14,7 +14,7 @@ Bot Social plugin for chatting with friends' Bots (send middleware `social` with A saved server choice that exists but cannot be read or parsed refuses instead of reading as "nothing saved yet" (#2717), and that refusal is answered on the plugin's own endpoints — the three `social/server*` endpoints and the UI endpoint list — and written once to the diagnostics log, so a damaged `flybot-social-server.json` shows its path and reason on the settings page and in Settings → Feedback instead of making Bot Social look uninstalled (#2945). -The chat dock's own memory lives outside the component: `conversation.input.dock` is session-scoped, so opening another chat unmounts the dock and coming back mounts a new one. What a failed send says, and which Retry already went out, are kept in a module-level record keyed `:` — the Map + listener shape `core/src/client/approval-claims.js` uses — and the dock only subscribes; otherwise the way back drew a failed card as a fresh wait and offered a Retry that had already gone out. Every card kind draws its reason from that record, a local hold included: the host describes a send that failed, but not a decision it refused, and the batch's one line is cleared by the next click and lost with the chat (#3093). A failure record goes when its id leaves the two lists the dock reads; a spent Retry is kept instead — at most 50 spent records, earliest-inserted dropped first — because the send did go out and the poll that still writes the hold back as failed would otherwise offer it again (#3082). +The chat dock's own memory lives outside the component: `conversation.input.dock` is session-scoped, so opening another chat unmounts the dock and coming back mounts a new one. What a failed send says, and which Retry already went out, are kept in a module-level record keyed `:` — the Map + listener shape `core/src/client/approval-claims.js` uses — and the dock only subscribes; otherwise the way back drew a failed card as a fresh wait and offered a Retry that had already gone out. Every card kind draws its reason from that record, a local hold included: the host describes a send that failed, but not a decision it refused, and the batch's one line is cleared by the next click and lost with the chat (#3093). A failure record goes when its id leaves the two lists the dock reads; a spent Retry is kept instead — at most 50 spent records, earliest-inserted dropped first — because the send did go out and the poll that still writes the hold back as failed would otherwise offer it again (#3082). That one line is bounded: it names at most three people and then counts the rest in the window's words, and a reason the host passes through whole is cut at 200 code points with a marked ellipsis, so one batch cannot fill the alert. A second, read-only window starts the social layer from the credentials file the writable window owns, so friends and messages stay visible, but it never onboards a home and never writes that file: the plugin start is a lifecycle path (`apply` → `ready` → `launch`), not an API endpoint, so the core's read-only guard cannot stop it and `startSocial` reads `config.readOnly` itself (#2675). diff --git a/plugins/social/client.js b/plugins/social/client.js index bb77bd235..d089f00d1 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -75,6 +75,14 @@ window.__ModuleLoader__.load({ } return { text, title: rows.map(row => row.label).join('\n'), ids: rows.map(row => row.id) } } + // A host sentence the plugin does not know is drawn on one line — a status row, a note, the dock's + // alert — and it can be a whole paragraph. Cut it and mark the cut; the count is code points, so a + // cut never lands inside a surrogate pair (#2438). + const ERROR_TEXT_MAX = 200 + const clipped = (text) => { + const chars = Array.from(String(text ?? '')) + return chars.length > ERROR_TEXT_MAX ? `${chars.slice(0, ERROR_TEXT_MAX - 1).join('')}…` : String(text ?? '') + } const errorText = (e) => { const code = String(e?.code ?? '') const http = code.match(/^HTTP_(\d+)$/) @@ -88,7 +96,7 @@ window.__ModuleLoader__.load({ // Only the raw server words map here. The "invite wasn't found" sentence also says "already used" (as one of its possible // causes), so matching those words would relabel every unknown or mistyped link as a used one. if (/invite_unavailable|invite is used|invite_used/i.test(message)) return 'This invite was already used. Ask your friend for a new one.' - return message + return clipped(message) } // Styles reuse ds-bot's sidebar tokens (--bt-ink, --bt-ink-2, --bt-ink-3, --bt-hover, --bt-line, @@ -2686,7 +2694,7 @@ window.__ModuleLoader__.load({ // (#3093) that record is the card's, whatever kind it is — a local hold the host marked failed // draws its own status, and a decision the host refused never reached a send to be described. const notSent = (failure) => { - const reason = String(failure?.message ?? failure).slice(0, 200) + const reason = clipped(failure?.message ?? failure) setError(reason) // A retry the host refused may be tried again; the id was never marked spent. if (retry) unmarkDockRetried(sessionId, item.id) @@ -2749,6 +2757,9 @@ window.__ModuleLoader__.load({ // #3029: the click sends several holds and they leave the dock at once, so the tail reports what // actually went out — one receipt for the people reached, and none when every send failed (those // cards keep their own error line). + // One click can fail for many people; the alert under the button is read at a glance, so it + // shows at most three rows and counts the rest in the window's own words. + const APPROVE_ALL_FAILED_ROWS = 3 const approveAll = async () => { const tr = (text, params) => (typeof t === 'function' ? t(text, params) @@ -2775,8 +2786,11 @@ window.__ModuleLoader__.load({ // #3071: written once, after the last send, so no send in the batch can clear it again; the // receipt above still names only the people reached. if (failed.size) { - const entries = [...failed].map(([name, reasons]) => (name ? `${name}: ${reasons.join(', ')}` : reasons.join(', '))) - setError(entries.join(' · ')) + const rows = [...failed].map(([name, reasons]) => (name ? `${name}: ${reasons.join(', ')}` : reasons.join(', '))) + const shown = rows.slice(0, APPROVE_ALL_FAILED_ROWS) + const rest = rows.length - shown.length + if (rest > 0) shown.push(tr('{count} more not shown', { count: rest })) + setError(shown.join(' · ')) } } // #3011: the button says what it will send and to whom, so the blast radius of a click that diff --git a/plugins/social/test/approve-all-failure.test.js b/plugins/social/test/approve-all-failure.test.js index 75fe585fa..1437237cb 100644 --- a/plugins/social/test/approve-all-failure.test.js +++ b/plugins/social/test/approve-all-failure.test.js @@ -264,3 +264,60 @@ test('a batch that fails two people separates their reasons and keeps each name' assert.equal(errorLine(after), 'Eve: the hold is stale · Bob: Bot Social is unreachable', `each failure is its own entry, saw ${JSON.stringify(errorLine(after))}`) } finally { delete globalThis.__flybot__ } }) + +// P-812 residual: the line above is one click's whole report, so its shape is bounded too. A batch +// can fail for many people at once and a host reason can be a whole paragraph; an alert read at a +// glance must not become a wall of text. The rows are capped, the rest is counted in the window's +// own words, and a single reason is cut. +test('a batch that fails many people caps the rows and counts the rest', async () => { + const app = loadDock() + const people = ['Eve', 'Bob', 'Ada', 'Cy', 'Dee'] + const holdList = people.map((name, index) => localHold(`l${index + 1}`, `@${name.toLowerCase()}.home`, name)) + const state = harness({ holdList, decide: payload => new Error(`reason-${payload.id}`) }) + try { + const first = await openChat(app, state) + const all = find(first.tree, byFlybot('approve-all')) + assert.ok(all, 'five waiting holds offer Approve all') + await all.props.onClick() + const after = render(app.ChatApprovalDock, first.inst, state.props) + const line = errorLine(after) + assert.equal(line, 'Eve: reason-l1 · Bob: reason-l2 · Ada: reason-l3 · 2 more not shown', `three rows and the count of the rest, saw ${JSON.stringify(line)}`) + assert.doesNotMatch(line, /Cy: reason-l4|Dee: reason-l5/, 'the line does not grow with the batch') + assert.equal(findAll(after, byFlybot('chat-approval')).length, 5, 'every card stays drawn, with its own reason') + } finally { delete globalThis.__flybot__ } +}) + +test('the count of the rows the line leaves out follows the window language', async () => { + const { DICTIONARY } = await import('../../../core/src/client/i18n.js') + const translate = (text, params) => String(DICTIONARY.zh[text] ?? text).replace(/\{(\w+)\}/g, (_, name) => String(params?.[name] ?? '')) + const people = ['Eve', 'Bob', 'Ada', 'Cy', 'Dee'] + const holdList = people.map((name, index) => localHold(`l${index + 1}`, `@${name.toLowerCase()}.home`, name)) + const state = harness({ holdList, decide: payload => new Error(`reason-${payload.id}`) }) + state.props = { ...state.props, t: translate } + const app = loadDock() + try { + const first = await openChat(app, state) + await find(first.tree, byFlybot('approve-all')).props.onClick() + const line = errorLine(render(app.ChatApprovalDock, first.inst, state.props)) + assert.match(line, /还有 2 条未显示$/, `the tail is the dictionary sentence, saw ${JSON.stringify(line)}`) + } finally { delete globalThis.__flybot__ } +}) + +test('a reason longer than a paragraph is cut inside the line', async () => { + const app = loadDock() + // Two holds of one person are one row, so the row cap cannot hide the length of a single reason. + const long = '🚀'.repeat(600) + const state = harness({ + holdList: [localHold('l1', '@eve.home', 'Eve'), localHold('l2', '@eve.home', 'Eve')], + decide: () => new Error(long), + }) + try { + const first = await openChat(app, state) + await find(first.tree, byFlybot('approve-all')).props.onClick() + const line = errorLine(render(app.ChatApprovalDock, first.inst, state.props)) + assert.ok(line.length < 500, `one reason does not own the whole line, saw ${line.length} characters`) + assert.match(line, /…$/, `the cut is marked, saw ${JSON.stringify(line.slice(-6))}`) + assert.ok(line.isWellFormed(), 'the cut lands on a code point, never inside an emoji') + assert.ok(!/\p{Surrogate}/u.test(line), 'no lone surrogate survives the cut') + } finally { delete globalThis.__flybot__ } +}) diff --git a/plugins/social/test/social.test.js b/plugins/social/test/social.test.js index f139a9a1a..c2af4fb8b 100644 --- a/plugins/social/test/social.test.js +++ b/plugins/social/test/social.test.js @@ -784,6 +784,22 @@ test('client.js registers a sidebar section and @ rows into the FlyBot registry' assert.deepEqual(JSON.parse(JSON.stringify(rows)), [{ name: 'Coder', description: '@coder.bob.home', section: 'Bots', value: '@coder.bob.home ' }]) }) +test('P-812: an unknown host error longer than a paragraph is cut on a code point', async () => { + const registered = [] + const sandbox = { window: { __ModuleLoader__: { load: r => registered.push(r) } }, setTimeout, clearTimeout, console } + sandbox.globalThis = sandbox + sandbox.__flybot__ = { slots: { register: () => () => {} }, call: async () => ({}) } + runInNewContext(readFileSync(new URL('../client.js', import.meta.url), 'utf8'), sandbox) + const plugin = registered[0].factory(() => ({ createElement: () => null, useEffect() {}, useState: v => [v, () => {}] })) + // A host sentence the plugin does not know is drawn on one status line; a whole paragraph cannot own it. + const text = plugin.errorText(new Error('🚀'.repeat(400))) + assert.ok(text.length < 500, `the reason is cut, saw ${text.length} characters`) + assert.match(text, /…$/, `the cut is marked, saw ${JSON.stringify(text.slice(-6))}`) + assert.ok(text.isWellFormed() && !/\p{Surrogate}/u.test(text), 'the cut lands on a code point, never inside an emoji') + // A message that fits is still returned word for word. + assert.equal(plugin.errorText(new Error('the hold is stale')), 'the hold is stale') +}) + test('#967: a friend Bot the core does not list yet is inserted under the one name the core would chip', async () => { const { remoteMentionLabel } = await import('../../../core/src/shared/remote-label.js') const friends = [