Skip to content

Commit fcf7fee

Browse files
committed
social: cover the pre-#2308 inbound path without flybot.inbox (#3338)
The plugin keeps explicit fallbacks for a core that has no `flybot.inbox`, but no test ever exercised them. Add two cases on a plugin API without the inbox: a normal delivery is still delivered once, marked seen and advances the cursor; an owner-policy deny still reports not-delivered, marks seen and advances the cursor. Both go red when the guards are removed. Docs-not-needed: test-only coverage for the pre-#2308 inbound fallback; no production behavior or public API changed.
1 parent 18225d3 commit fcf7fee

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,74 @@ test('#2308: a turn that fails after delivery leaves failed, not a silent seen',
975975
assert.equal(after.cursors.m2, 1)
976976
})
977977

978+
// #3338: a core that predates #2308 has no `flybot.inbox`. Its inbound path must stay the old
979+
// one: deliver once, mark seen, move the cursor, and never throw for want of a claim. `scope()`
980+
// builds a fresh plugin API on every call, so the fallback is exercised on what the plugin gets.
981+
test('#3338: without flybot.inbox an inbound event is still delivered once and marked seen', async (t) => {
982+
const { ctx, received, home, stop } = await team()
983+
t.after(stop)
984+
const server = mockServer()
985+
const log = []
986+
server.tools.list_inbox = (a) => { const since = a.since_cursor ?? 0; const events = a.bot_id === 'm2' ? log.filter(e => e.cursor > since) : []; return { events, next_cursor: events.at(-1)?.cursor ?? since } }
987+
const msg = (cursor, text) => ({ cursor, event_id: `ev${cursor}`, event_type: 'message.received', from: { handle: '@coder.bob.home', display_name: 'Coder' }, untrusted_content: `<<<UNTRUSTED>>>\n{"text":"${text}"}\n<<<END>>>` })
988+
const settingsPath = join(home, 'social-settings.json')
989+
const settingsNow = () => JSON.parse(readFileSync(settingsPath, 'utf8'))
990+
delete ctx.flybot.inbox
991+
const scope = ctx.flybot.scope.bind(ctx.flybot)
992+
ctx.flybot.scope = (name) => { const scoped = scope(name); delete scoped.inbox; return scoped }
993+
assert.equal(ctx.flybot.scope('social').inbox, undefined, 'the plugin sees no inbox')
994+
const social = createSocial(ctx.flybot, { autoAccept: false, settingsPath }, { client: createMcpClient({ server: 'https://s', token: 'owner-token', fetch: server.fetch }), home: { id: 'h1', handle: '@danyang.home' } })
995+
t.after(() => social.dispose())
996+
await grantTeam(ctx.flybot)
997+
await social.registerAll()
998+
log.push(msg(1, 'one'))
999+
assert.equal(await social.pollInbox(), 1, 'the event is delivered')
1000+
assert.equal((received.get('b') ?? []).length, 1)
1001+
const saved = settingsNow()
1002+
assert.ok(saved.seen.includes('ev1'), 'the event is marked seen')
1003+
assert.equal(saved.cursors.m2, 1, 'the cursor moved past the event')
1004+
assert.equal(saved.inbox?.ev1, undefined, 'no claim record is written without flybot.inbox')
1005+
assert.equal(await social.pollInbox(), 0)
1006+
assert.equal((received.get('b') ?? []).length, 1, 'nothing is replayed')
1007+
})
1008+
1009+
// #3338: the owner-policy refusal early-exits too. Without an inbox the sender is still told the
1010+
// message was not delivered, the event is marked seen and the cursor moves, so one ungranted
1011+
// sender cannot park the queue.
1012+
test('#3338: an owner-policy deny without flybot.inbox still reports not-delivered, seen, and the cursor', async (t) => {
1013+
const { ctx, received, home, stop } = await team()
1014+
t.after(stop)
1015+
const server = mockServer()
1016+
const reported = []
1017+
server.tools.report_not_delivered = (a) => { reported.push(a); return {} }
1018+
// The grant sync a deny triggers reads the server: it still knows no grant for this Bot, so the
1019+
// second judgement stays a refusal instead of restoring the friendship from `list_friends`.
1020+
server.tools.list_bot_grants = () => ({ grants: [] })
1021+
const log = []
1022+
server.tools.list_inbox = (a) => { const since = a.since_cursor ?? 0; const events = a.bot_id === 'm2' ? log.filter(e => e.cursor > since) : []; return { events, next_cursor: events.at(-1)?.cursor ?? since } }
1023+
const msg = (cursor, text) => ({ cursor, event_id: `ev${cursor}`, message_id: `msg-${cursor}`, event_type: 'message.received', from: { handle: '@coder.bob.home', display_name: 'Coder' }, untrusted_content: `<<<UNTRUSTED>>>\n{"text":"${text}"}\n<<<END>>>` })
1024+
const settingsPath = join(home, 'social-settings.json')
1025+
const settingsNow = () => JSON.parse(readFileSync(settingsPath, 'utf8'))
1026+
delete ctx.flybot.inbox
1027+
const scope = ctx.flybot.scope.bind(ctx.flybot)
1028+
ctx.flybot.scope = (name) => { const scoped = scope(name); delete scoped.inbox; return scoped }
1029+
const social = createSocial(ctx.flybot, { autoAccept: false, settingsPath }, { client: createMcpClient({ server: 'https://s', token: 'owner-token', fetch: server.fetch }), home: { id: 'h1', handle: '@danyang.home' } })
1030+
t.after(() => social.dispose())
1031+
await grantTeam(ctx.flybot)
1032+
await social.registerAll()
1033+
// A registered identity whose grant is gone: reach() refuses this sender by owner policy.
1034+
await ctx.flybot.grants.set('b', [])
1035+
log.push(msg(1, 'nope'))
1036+
assert.equal(await social.pollInbox(), 0, 'a refusal is not a delivery')
1037+
assert.deepEqual(reported, [{ message_id: 'msg-1', reason: 'not_shared_yet' }], 'the sender is told it was not delivered')
1038+
const saved = settingsNow()
1039+
assert.ok(saved.seen.includes('ev1'), 'the refused event is marked seen')
1040+
assert.equal(saved.cursors.m2, 1, 'the cursor moved past the event')
1041+
assert.equal(saved.inbox?.ev1, undefined, 'no claim record is written without flybot.inbox')
1042+
assert.equal((received.get('b') ?? []).length, 0)
1043+
assert.equal(await social.pollInbox(), 0, 'a refusal is not retried')
1044+
})
1045+
9781046
test('legacy (#8): the conversation opened by a first text is kept for the next send', async (t) => {
9791047
const { ctx, stop } = await team()
9801048
t.after(stop)

0 commit comments

Comments
 (0)