Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3158.fixed.md
Original file line number Diff line number Diff line change
@@ -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)).
2 changes: 1 addition & 1 deletion docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<approval id>:<session id>` — 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 `<approval id>:<session id>` — 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).

Expand Down
22 changes: 18 additions & 4 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+)$/)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
57 changes: 57 additions & 0 deletions plugins/social/test/approve-all-failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__ }
})
16 changes: 16 additions & 0 deletions plugins/social/test/social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading