|
| 1 | +// @flybot/workflow against the real ctx.flybot host (ds-bot's hooks.js), not the mock |
| 2 | +// (ThinkFlowLab/FlyBot#34). #1475 removed the dead `workflow/say` surface: the bot route strips |
| 3 | +// its `flybot/` prefix and asks the host for `workflow/say` (core/src/host/channel.js:701), and a |
| 4 | +// name no plugin registered is answered by the host itself (core/src/host/hooks.js:1044). So the |
| 5 | +// removed endpoint must come back as `Unknown FlyBot endpoint workflow/say` with code |
| 6 | +// `bot/not-found` — never `{ ok: true }`, never an empty object. |
| 7 | +import assert from 'node:assert/strict' |
| 8 | +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' |
| 9 | +import { tmpdir } from 'node:os' |
| 10 | +import { join } from 'node:path' |
| 11 | +import { test } from 'node:test' |
| 12 | +import { apply } from 'ds-bot' |
| 13 | +import * as workflow from '../index.js' |
| 14 | +import { fakeCordis } from './fake-cordis.js' |
| 15 | + |
| 16 | +const team = () => ({ |
| 17 | + version: 1, |
| 18 | + mainBotIds: ['a'], |
| 19 | + bots: { |
| 20 | + a: { id: 'a', name: 'Chief', role: 'Boss', sessionId: 'a', createdAt: 1 }, |
| 21 | + b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 }, |
| 22 | + }, |
| 23 | + rooms: {}, agents: {}, exchanges: [], exchangeTurns: {}, questions: {}, prefs: {}, revision: 0, |
| 24 | +}) |
| 25 | + |
| 26 | +async function start() { |
| 27 | + const home = mkdtempSync(join(tmpdir(), 'flybot-workflow-host-')) |
| 28 | + writeFileSync(join(home, 'state.json'), JSON.stringify(team())) |
| 29 | + const ctx = fakeCordis() |
| 30 | + Object.assign(ctx, { |
| 31 | + llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) }, |
| 32 | + workspaceRegistry: { get: () => undefined, resolveByPath: async () => undefined, create: async path => ({ id: 'w1', path }), archiveSession: async () => {} }, |
| 33 | + sessionController: { create: async () => ({ sessionId: 's1' }), resolveAgent: async () => undefined, selectModel: async () => {}, page: async () => ({ records: [], hasMore: false }) }, |
| 34 | + sessionTitle: { rename: async () => {} }, |
| 35 | + sessions: { flush: async () => {} }, |
| 36 | + }) |
| 37 | + let route |
| 38 | + const register = ctx.connection.fetch.register |
| 39 | + ctx.connection.fetch.register = (options) => { if (options.path.endsWith('bot')) route = options; return register(options) } |
| 40 | + apply(ctx, { home }) |
| 41 | + const call = async (endpoint, payload) => (await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))).json() |
| 42 | + const stop = async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) } |
| 43 | + return { ctx, call, stop } |
| 44 | +} |
| 45 | + |
| 46 | +test('workflow plugin on the real host: the removed say endpoint is unknown, not an empty answer', async (t) => { |
| 47 | + const h = await start() |
| 48 | + t.after(h.stop) |
| 49 | + h.ctx.plugin(workflow, { persist: false }) |
| 50 | + const state = await h.call('flybot/workflow/state') |
| 51 | + assert.equal(state.ok, true, 'the plugin is loaded, so the name is the only thing missing') |
| 52 | + assert.ok(state.value.workflows.length > 0) |
| 53 | + assert.deepEqual(await h.call('flybot/workflow/say', { workflowId: 'delivery', text: 'hi' }), { |
| 54 | + ok: false, |
| 55 | + error: { code: 'bot/not-found', message: 'Unknown FlyBot endpoint workflow/say', details: {} }, |
| 56 | + }) |
| 57 | +}) |
0 commit comments