Skip to content

Commit 2d98472

Browse files
committed
test(social): pin that a co-seat never clears face_room_auto_send_off on a room-share line
A Bot that sits in a room as someone else's seat is not the owner pressing that Bot's own in-room Auto-send switch. Bot Social holds such a line with `face_room_auto_send_off`, and only the face-room path clears that name: `autoSendFaceLine` (`plugins/social/src/social.js:4574`) reads it through `holdAllowsFaceAutoSend`, and only while that Bot's in-room switch is on. A room envelope is a different consent - the click that added the Bot - so `autoSendRoomEnvelope` (`:2043`) clears the blanket hold and an ordinary room `policy` hold, never the switch; the comment above `FACE_ROOM_AUTO_SEND_OFF` (`:171-189`) says the same in one place. The case pins both halves of that today, not a fix: - a `send_as_member` line under `via: 'room-share'` held for `face_room_auto_send_off` comes back pending (`'kept'`), on its card, with the reason on it, and sharing the room approves nothing; - the reverse, in the same case: the same Bot's in-room line is held while that switch is off and leaves once the owner turns it on. The source is untouched: `plugins/social/src/social.js` here hashes the same as the `77a6b4d4` blob (`a54efebdce49257e526ffb40b8596ae3c69c03f0fd77f72ded9f0098fe086aa1`). The code is already right, so the case is checked with a mutation instead of a red-first run: adding `|| holdAllowsFaceAutoSend(held)` to the clearing condition at `:2043` turns the new case red (1 test / 0 pass / 1 fail), and reverting that line restores the file byte for byte. At this tip the social file runs 450 tests without the case and 451 with it; the case alone is 1/1; plugin lint reports social 36 warnings / 0 errors. Fixes #2209 Docs-not-needed: test-only; the clearing rule and the documented behaviour are unchanged.
1 parent 77a6b4d commit 2d98472

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

‎plugins/social/test/social.test.js‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,103 @@ test('#457: a Bot whose face-room Auto-send is on has its clean held line approv
21992199
assert.equal(approvals().length, 2)
22002200
})
22012201

2202+
// #1175: a co-seat is not an authorization. Bot Social holds a face-room line it would otherwise send
2203+
// with `face_room_auto_send_off`, and only the face-room path clears that name: `autoSendFaceLine`
2204+
// (`social.js:4574`) reads it through `holdAllowsFaceAutoSend`, and only while that Bot's own in-room
2205+
// Auto-send switch is on. A room envelope is a different consent — the click that added the Bot — and
2206+
// `autoSendRoomEnvelope` (`social.js:2043`) clears the blanket hold (#847) and an ordinary room `policy`
2207+
// hold (#1113, #1118), never the switch; the comment above `FACE_ROOM_AUTO_SEND_OFF`
2208+
// (`social.js:171-189`) says the same in one place. Two Bot homes sharing a row is not the owner
2209+
// pressing that switch, so the room-share line has to come back `'kept'`, on its card.
2210+
// `face_room_auto_send_off` = that Bot's own in-room Auto-send switch is off; `blanket` / `policy`
2211+
// remainders mean the clearing path failed — that is the real bug.
2212+
test('#1175: a co-seat is not the Auto-send switch: a room-share row held for `face_room_auto_send_off` stays on its card, and the same Bot in a face room clears it', async (t) => {
2213+
// The room this home seated a stranger's Bot in (#883): a room share goes under the room's id.
2214+
const seated = {
2215+
war: {
2216+
id: 'war', name: 'Launch plan', members: ['a', 'b'], admin: 'a', named: true, log: [], seq: 0, seen: {},
2217+
participants: [
2218+
{ kind: 'bot', id: 'a', role: 'admin', displayName: 'Chief', joinedSeq: 0, joinedAt: 1 },
2219+
{ kind: 'bot', id: 'b', role: 'member', displayName: 'Writer', joinedSeq: 0, joinedAt: 1 },
2220+
{ kind: 'bot', remote: true, id: '@guest.eve.home', handle: '@guest.eve.home', ownerHome: '@eve.home', ownerName: 'Eve', displayName: 'Guest', role: 'member', admittedBy: 'ticket', ticket: 'TktSeatAbCdEfGhIjKlMnO', hostBotId: 'a', joinedSeq: 1, joinedAt: 1 },
2221+
],
2222+
},
2223+
}
2224+
{
2225+
// The room-share half: `send_as_member` comes back pending with the switch's own reason on it.
2226+
const { ctx, call, home, stop } = await team({ rooms: seated })
2227+
t.after(stop)
2228+
const server = holdingServer({ holdReason: 'face_room_auto_send_off' })
2229+
const social = createSocial(ctx.flybot, { autoAccept: false, inboxPollMs: 0, settingsPath: join(home, 'flybot-social-settings.json') }, {
2230+
client: createMcpClient({ server: 'https://s', token: 'owner-token', fetch: server.fetch }),
2231+
home: { id: 'h1', handle: '@danyang.home' },
2232+
})
2233+
t.after(() => social.dispose())
2234+
await grantTeam(ctx.flybot)
2235+
await social.registerAll()
2236+
const envelope = `FLYBOT-ROOM-SHARE\n${JSON.stringify({ v: 1, op: 'line', roomId: 'war', text: 'we are in the same room' })}`
2237+
const refused = await ctx.flybot.bot.send({ from: 'a', to: '@guest.eve.home', text: envelope, via: 'room-share', meta: { roomId: 'war', scope: 'war' } })
2238+
.then(value => ({ value }), error => ({ error }))
2239+
// `pending_approval` is `autoSendRoomEnvelope` answering `'kept'`: `sendTicketShare` maps `kept` to
2240+
// that code and a hold Bot Social has not listed yet to `pending_unlisted`, so the row was read.
2241+
assert.equal(refused.error?.code, 'pending_approval', JSON.stringify(refused.value ?? refused.error?.message))
2242+
assert.equal(server.calls.some(c => c.name === 'decide_approval'), false, 'sharing the room approves nothing on Bot Social')
2243+
assert.equal(server.queue.length, 1, 'the hold is still pending for the owner')
2244+
const pending = (await call('flybot/social/status', {})).value.approvals
2245+
assert.equal(pending.length, 1, 'it waits on its card, where the owner decides it')
2246+
assert.equal(pending[0].holdReason, 'face_room_auto_send_off', 'the card names the switch, so the clearing path is visible')
2247+
}
2248+
{
2249+
// The face-room half: the same Bot, the same hold name, and its own in-room switch decides.
2250+
const { ctx, call, stop } = await team()
2251+
t.after(stop)
2252+
const server = withFaceRooms(mockServer())
2253+
// Bot Social's real shape for this hold (#457, #865): the switch's name, the blanket reason beside
2254+
// it, no finding of its own.
2255+
const heldItem = () => ({
2256+
approval_id: 'apr-face-1', kind: 'face_room_message', status: 'pending', sender_kind: 'bot', bot_id: 'm1',
2257+
room_id: 'frm_123456', hold_reason: 'face_room_auto_send_off', reasons: ['mvp.all_outbound_requires_approval'],
2258+
message: { payload: { text: 'hold me' } }, summary: 'To the room: hold me',
2259+
})
2260+
let queue = []
2261+
server.tools.list_approvals = () => ({ approvals: queue })
2262+
server.tools.decide_approval = a => {
2263+
if (a.confirm_code === undefined) return { status: 'confirmation_required', confirm_code: 'C0DE02' }
2264+
queue = queue.filter(item => item.approval_id !== a.approval_id)
2265+
return { approval_id: a.approval_id, decision: a.decision }
2266+
}
2267+
let fanout
2268+
const origScope = ctx.flybot.scope.bind(ctx.flybot)
2269+
ctx.flybot.scope = (name) => {
2270+
const scoped = origScope(name)
2271+
const origOn = scoped.rooms.onFaceLine.bind(scoped.rooms)
2272+
scoped.rooms.onFaceLine = (fn) => { fanout = fn; return origOn(fn) }
2273+
return scoped
2274+
}
2275+
const social = createSocial(ctx.flybot, { server: 'https://s', token: 'owner-token', fetch: server.fetch, inboxPollMs: 0, autoAccept: false }, {
2276+
client: createMcpClient({ server: 'https://s', token: 'owner-token', fetch: server.fetch }),
2277+
home: { id: 'h1', handle: '@danyang.home' },
2278+
})
2279+
t.after(() => social.dispose())
2280+
await grantTeam(ctx.flybot)
2281+
await social.registerAll()
2282+
await call('flybot/social/face-join', { start: true, code: '123456' })
2283+
const room = ctx.flybot.rooms.ofFace('frm_123456')
2284+
// `hold me` is this mock's hold trigger (`withFaceRooms`); the text itself is not what is under test.
2285+
const line = () => ({ authorKind: 'bot', botId: 'a', authorId: 'a', who: 'Chief', text: 'hold me' })
2286+
const approvals = () => server.calls.filter(c => c.name === 'decide_approval' && c.args.confirm_code !== undefined)
2287+
// Switch off (the default): the line waits on its card, exactly like the room-share row above.
2288+
queue = [heldItem()]
2289+
assert.deepEqual(await fanout(room, line()), { held: true, approvalId: 'apr-face-1' })
2290+
assert.equal(approvals().length, 0)
2291+
// Switch on: the same hold name now leaves, because the owner pressed that switch for this Bot.
2292+
await call('flybot/social/face-auto', { botId: 'a', on: true })
2293+
queue = [heldItem()]
2294+
assert.equal(await fanout(room, line()), undefined)
2295+
assert.deepEqual(approvals().map(c => [c.args.approval_id, c.args.decision]), [['apr-face-1', 'approved']])
2296+
}
2297+
})
2298+
22022299
test('approvalView: outbound draft text is sanitized, friend requests stay out', () => {
22032300
const view = approvalView({
22042301
approval_id: 'apr1',

0 commit comments

Comments
 (0)