clawmini 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/adapter-discord/index.d.mts.map +1 -1
- package/dist/adapter-discord/index.mjs +398 -193
- package/dist/adapter-discord/index.mjs.map +1 -1
- package/dist/adapter-google-chat/index.d.mts +5 -0
- package/dist/adapter-google-chat/index.d.mts.map +1 -0
- package/dist/adapter-google-chat/index.mjs +1077 -0
- package/dist/adapter-google-chat/index.mjs.map +1 -0
- package/dist/cli/index.mjs +107 -14
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lite.mjs +175 -16
- package/dist/cli/lite.mjs.map +1 -1
- package/dist/cli/propose-policy.d.mts +1 -0
- package/dist/cli/propose-policy.mjs +7159 -0
- package/dist/cli/propose-policy.mjs.map +1 -0
- package/dist/daemon/index.d.mts.map +1 -1
- package/dist/daemon/index.mjs +1427 -513
- package/dist/daemon/index.mjs.map +1 -1
- package/dist/{lite-oSYSvaOr.mjs → lite-CBxOT1y5.mjs} +101 -24
- package/dist/lite-CBxOT1y5.mjs.map +1 -0
- package/dist/routing-D8rTxtaV.mjs +245 -0
- package/dist/routing-D8rTxtaV.mjs.map +1 -0
- package/dist/web/_app/immutable/assets/0.C-4eziNy.css +1 -0
- package/dist/web/_app/immutable/assets/4.Cc_xwLNl.css +1 -0
- package/dist/web/_app/immutable/chunks/B6YN0Nuq.js +1 -0
- package/dist/web/_app/immutable/chunks/{Dc-UOHw9.js → BmRlVmv6.js} +1 -1
- package/{web/.svelte-kit/output/client/_app/immutable/chunks/8YNcRyEk.js → dist/web/_app/immutable/chunks/C20lZMGz.js} +1 -1
- package/dist/web/_app/immutable/chunks/C9lbZ-kT.js +1 -0
- package/dist/web/_app/immutable/chunks/CK9JZLaG.js +2 -0
- package/dist/web/_app/immutable/chunks/CME08kGM.js +1 -0
- package/dist/web/_app/immutable/chunks/{BPy8HLo7.js → Ck-be5J2.js} +1 -1
- package/dist/web/_app/immutable/chunks/Ck3rYNON.js +1 -0
- package/dist/web/_app/immutable/chunks/DMtIqaiV.js +2 -0
- package/dist/web/_app/immutable/chunks/{B8yYFADm.js → DhD271EB.js} +1 -1
- package/dist/web/_app/immutable/chunks/{DcrmIfTj.js → DpuLqk8d.js} +1 -1
- package/dist/web/_app/immutable/chunks/{ZkLyk0mE.js → Drm9vgeP.js} +1 -1
- package/dist/web/_app/immutable/chunks/DsIToJCP.js +1 -0
- package/dist/web/_app/immutable/chunks/{CyNaE55B.js → Zeh-C-mx.js} +1 -1
- package/{web/.svelte-kit/output/client/_app/immutable/entry/app.DO5eYwVz.js → dist/web/_app/immutable/entry/app.BgB5VkRU.js} +2 -2
- package/dist/web/_app/immutable/entry/start.DuxJo6av.js +1 -0
- package/dist/web/_app/immutable/nodes/0.C9oFZP9h.js +1 -0
- package/dist/web/_app/immutable/nodes/1.BON2Wk6k.js +1 -0
- package/dist/web/_app/immutable/nodes/{2.CK3CLC0f.js → 2.BnwnD1Ki.js} +1 -1
- package/dist/web/_app/immutable/nodes/{3.ncP0xLO6.js → 3.CIs4tjjw.js} +1 -1
- package/dist/web/_app/immutable/nodes/4.DLarELN4.js +60 -0
- package/dist/web/_app/immutable/nodes/{5.BpJUN6QH.js → 5.CE_QKy_3.js} +1 -1
- package/dist/web/_app/version.json +1 -1
- package/dist/web/index.html +12 -12
- package/dist/{workspace-DjoNjhW0.mjs → workspace-BJmJBfKi.mjs} +103 -11
- package/dist/workspace-BJmJBfKi.mjs.map +1 -0
- package/docs/14_google_chat_adapter/development_log.md +40 -0
- package/docs/14_google_chat_adapter/notes.md +28 -0
- package/docs/14_google_chat_adapter/prd.md +35 -0
- package/docs/14_google_chat_adapter/questions.md +9 -0
- package/docs/14_google_chat_adapter/tickets.md +117 -0
- package/docs/15_sandbox_policies/tickets.md +33 -0
- package/docs/16_session_timeout/development_log.md +20 -0
- package/docs/16_session_timeout/notes.md +44 -0
- package/docs/16_session_timeout/prd.md +106 -0
- package/docs/16_session_timeout/questions.md +10 -0
- package/docs/16_session_timeout/tickets.md +64 -0
- package/docs/17_auto_approve_policy/development_log.md +29 -0
- package/docs/17_auto_approve_policy/notes.md +25 -0
- package/docs/17_auto_approve_policy/prd.md +34 -0
- package/docs/17_auto_approve_policy/questions.md +10 -0
- package/docs/17_auto_approve_policy/tickets.md +11 -0
- package/docs/18_clawmini_skills/development_log.md +36 -0
- package/docs/18_clawmini_skills/notes.md +8 -0
- package/docs/18_clawmini_skills/prd.md +45 -0
- package/docs/18_clawmini_skills/questions.md +10 -0
- package/docs/18_clawmini_skills/tickets.md +55 -0
- package/docs/19_subagents/development_log.md +69 -0
- package/docs/19_subagents/notes.md +18 -0
- package/docs/19_subagents/prd.md +156 -0
- package/docs/19_subagents/questions.md +13 -0
- package/docs/19_subagents/tickets.md +113 -0
- package/docs/20_chat_logs_cleanup/development_log.md +50 -0
- package/docs/20_chat_logs_cleanup/notes.md +43 -0
- package/docs/20_chat_logs_cleanup/prd.md +232 -0
- package/docs/20_chat_logs_cleanup/questions.md +2 -0
- package/docs/20_chat_logs_cleanup/tickets.md +98 -0
- package/docs/20_webui_markdown/development_log.md +36 -0
- package/docs/20_webui_markdown/notes.md +23 -0
- package/docs/20_webui_markdown/prd.md +49 -0
- package/docs/20_webui_markdown/questions.md +10 -0
- package/docs/20_webui_markdown/tickets.md +55 -0
- package/docs/21_adapter_filtering/development_log.md +29 -0
- package/docs/21_adapter_filtering/notes.md +25 -0
- package/docs/21_adapter_filtering/prd.md +44 -0
- package/docs/21_adapter_filtering/questions.md +12 -0
- package/docs/21_adapter_filtering/tickets.md +38 -0
- package/docs/21_built_in_routers/development_log.md +17 -0
- package/docs/21_built_in_routers/notes.md +27 -0
- package/docs/21_built_in_routers/prd.md +34 -0
- package/docs/21_built_in_routers/questions.md +4 -0
- package/docs/21_built_in_routers/tickets.md +25 -0
- package/docs/21_fancy_policies/development_log.md +38 -0
- package/docs/21_fancy_policies/notes.md +27 -0
- package/docs/21_fancy_policies/prd.md +58 -0
- package/docs/21_fancy_policies/questions.md +6 -0
- package/docs/21_fancy_policies/tickets.md +48 -0
- package/docs/22_adapter_multi_chat/development_log.md +76 -0
- package/docs/22_adapter_multi_chat/notes.md +42 -0
- package/docs/22_adapter_multi_chat/prd.md +76 -0
- package/docs/22_adapter_multi_chat/questions.md +16 -0
- package/docs/22_adapter_multi_chat/tickets.md +164 -0
- package/docs/23_custom_token_env/development_log.md +31 -0
- package/docs/23_custom_token_env/notes.md +16 -0
- package/docs/23_custom_token_env/prd.md +42 -0
- package/docs/23_custom_token_env/questions.md +8 -0
- package/docs/23_custom_token_env/tickets.md +54 -0
- package/docs/guides/discord_adapter_setup.md +15 -2
- package/docs/guides/google_chat_adapter_setup.md +145 -0
- package/napkin.md +5 -0
- package/package.json +7 -2
- package/src/adapter-discord/config.test.ts +27 -8
- package/src/adapter-discord/config.ts +6 -8
- package/src/adapter-discord/forwarder.test.ts +307 -114
- package/src/adapter-discord/forwarder.ts +260 -75
- package/src/adapter-discord/index.test.ts +278 -0
- package/src/adapter-discord/index.ts +160 -30
- package/src/adapter-discord/interactions.test.ts +96 -0
- package/src/adapter-discord/interactions.ts +156 -0
- package/src/adapter-discord/state.test.ts +9 -8
- package/src/adapter-discord/state.ts +51 -8
- package/src/adapter-google-chat/auth.test.ts +87 -0
- package/src/adapter-google-chat/auth.ts +132 -0
- package/src/adapter-google-chat/cards.ts +71 -0
- package/src/adapter-google-chat/client.test.ts +561 -0
- package/src/adapter-google-chat/client.ts +430 -0
- package/src/adapter-google-chat/config.test.ts +187 -0
- package/src/adapter-google-chat/config.ts +82 -0
- package/src/adapter-google-chat/cron.test.ts +143 -0
- package/src/adapter-google-chat/cron.ts +81 -0
- package/src/adapter-google-chat/forwarder.test.ts +537 -0
- package/src/adapter-google-chat/forwarder.ts +349 -0
- package/src/adapter-google-chat/index.test.ts +62 -0
- package/src/adapter-google-chat/index.ts +61 -0
- package/src/adapter-google-chat/state.test.ts +96 -0
- package/src/adapter-google-chat/state.ts +85 -0
- package/src/adapter-google-chat/subscriptions.ts +124 -0
- package/src/adapter-google-chat/upload.ts +88 -0
- package/src/adapter-google-chat/utils.test.ts +111 -0
- package/src/adapter-google-chat/utils.ts +133 -0
- package/src/cli/commands/init.ts +0 -7
- package/src/cli/commands/messages.ts +18 -3
- package/src/cli/commands/policies.ts +70 -0
- package/src/cli/commands/skills.ts +71 -0
- package/src/cli/commands/web-api/chats.ts +5 -1
- package/src/cli/e2e/basic.test.ts +1 -1
- package/src/cli/e2e/cron.test.ts +1 -1
- package/src/cli/e2e/daemon.test.ts +132 -4
- package/src/cli/e2e/export-lite-func.test.ts +54 -31
- package/src/cli/e2e/fallbacks.test.ts +8 -6
- package/src/cli/e2e/init.test.ts +7 -0
- package/src/cli/e2e/messages.test.ts +90 -55
- package/src/cli/e2e/propose-policy.test.ts +203 -0
- package/src/cli/e2e/requests.test.ts +15 -0
- package/src/cli/e2e/session-timeout.test.ts +192 -0
- package/src/cli/e2e/skills.test.ts +55 -0
- package/src/cli/e2e/slash-new.test.ts +93 -0
- package/src/cli/e2e/subagents.test.ts +106 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/lite.ts +51 -11
- package/src/cli/propose-policy.ts +91 -0
- package/src/cli/subagent-commands.ts +215 -0
- package/src/daemon/agent/agent-context.ts +89 -0
- package/src/daemon/agent/agent-extractors.ts +68 -0
- package/src/daemon/agent/agent-runner.ts +153 -0
- package/src/daemon/agent/agent-session.ts +261 -0
- package/src/daemon/agent/chat-logger.test.ts +158 -0
- package/src/daemon/agent/chat-logger.ts +188 -0
- package/src/daemon/agent/task-scheduler.test.ts +202 -0
- package/src/daemon/agent/task-scheduler.ts +276 -0
- package/src/daemon/agent/types.ts +84 -0
- package/src/daemon/agent/utils.ts +7 -0
- package/src/daemon/api/agent-router.ts +166 -18
- package/src/daemon/api/index.test.ts +50 -18
- package/src/daemon/api/policy-request.test.ts +39 -2
- package/src/daemon/api/subagent-router.test.ts +108 -0
- package/src/daemon/api/subagent-router.ts +296 -0
- package/src/daemon/api/subagent-utils.test.ts +56 -0
- package/src/daemon/api/subagent-utils.ts +130 -0
- package/src/daemon/api/user-router.ts +30 -13
- package/src/daemon/auth.ts +1 -0
- package/src/daemon/chats.ts +6 -0
- package/src/daemon/cron.test.ts +66 -1
- package/src/daemon/cron.ts +35 -8
- package/src/daemon/index.ts +23 -0
- package/src/daemon/message-agent.test.ts +11 -25
- package/src/daemon/message-extraction.test.ts +10 -27
- package/src/daemon/message-fallbacks.test.ts +13 -35
- package/src/daemon/message-interruption.test.ts +70 -53
- package/src/daemon/message-jobs.test.ts +138 -0
- package/src/daemon/message-queue.test.ts +30 -43
- package/src/daemon/message-router.test.ts +12 -11
- package/src/daemon/message-session.test.ts +41 -28
- package/src/daemon/message-typing.test.ts +19 -6
- package/src/daemon/message.ts +103 -515
- package/src/daemon/policy-request-service.ts +8 -3
- package/src/daemon/policy-utils.ts +19 -1
- package/src/daemon/queue.ts +16 -0
- package/src/daemon/request-store.test.ts +4 -0
- package/src/daemon/routers/session-timeout.test.ts +122 -0
- package/src/daemon/routers/session-timeout.ts +71 -0
- package/src/daemon/routers/slash-new.ts +3 -1
- package/src/daemon/routers/slash-policies.test.ts +26 -13
- package/src/daemon/routers/slash-policies.ts +39 -29
- package/src/daemon/routers/types.ts +8 -0
- package/src/daemon/routers.ts +64 -2
- package/src/daemon/utils/spawn.ts +6 -8
- package/src/shared/adapters/commands.test.ts +155 -0
- package/src/shared/adapters/commands.ts +125 -0
- package/src/shared/adapters/filtering.test.ts +111 -0
- package/src/shared/adapters/filtering.ts +57 -0
- package/src/shared/adapters/routing.test.ts +144 -0
- package/src/shared/adapters/routing.ts +109 -0
- package/src/shared/agent-utils.ts +10 -0
- package/src/shared/chats.test.ts +145 -3
- package/src/shared/chats.ts +215 -18
- package/src/shared/config.ts +67 -15
- package/src/shared/lite.ts +22 -18
- package/src/shared/policies.ts +7 -0
- package/src/shared/workspace.test.ts +45 -1
- package/src/shared/workspace.ts +119 -6
- package/templates/debug/settings.json +5 -2
- package/templates/environments/cladding/env.json +2 -2
- package/templates/gemini/.gemini/hooks/check-subagents.mjs +23 -0
- package/templates/gemini/.gemini/hooks/clawmini-logging.sh +17 -0
- package/templates/gemini/.gemini/hooks/insert-pending.sh +9 -0
- package/templates/gemini/.gemini/settings.json +50 -0
- package/templates/gemini/settings.json +22 -8
- package/templates/gemini-claw/.gemini/base-system.md +100 -0
- package/templates/gemini-claw/.gemini/hooks/check-subagents.mjs +23 -0
- package/templates/gemini-claw/.gemini/hooks/clawmini-logging.sh +1 -1
- package/templates/gemini-claw/.gemini/settings.json +13 -0
- package/templates/gemini-claw/.gemini/subagent-system.md +7 -0
- package/templates/gemini-claw/.gemini/system.md +3 -99
- package/templates/gemini-claw/settings.json +27 -22
- package/templates/skills/clawmini-requests/SKILL.md +92 -0
- package/templates/skills/clawmini-subagents/SKILL.md +79 -0
- package/templates/skills/skill-creator/SKILL.md +60 -0
- package/tsdown.config.ts +10 -1
- package/web/.svelte-kit/generated/server/internal.js +2 -1
- package/web/.svelte-kit/non-ambient.d.ts +2 -0
- package/web/.svelte-kit/output/client/.vite/manifest.json +141 -138
- package/web/.svelte-kit/output/client/_app/immutable/assets/0.C-4eziNy.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/4.Cc_xwLNl.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B6YN0Nuq.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{Dc-UOHw9.js → BmRlVmv6.js} +1 -1
- package/{dist/web/_app/immutable/chunks/8YNcRyEk.js → web/.svelte-kit/output/client/_app/immutable/chunks/C20lZMGz.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/C9lbZ-kT.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CK9JZLaG.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CME08kGM.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{BPy8HLo7.js → Ck-be5J2.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Ck3rYNON.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DMtIqaiV.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{B8yYFADm.js → DhD271EB.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{DcrmIfTj.js → DpuLqk8d.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{ZkLyk0mE.js → Drm9vgeP.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DsIToJCP.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/{CyNaE55B.js → Zeh-C-mx.js} +1 -1
- package/{dist/web/_app/immutable/entry/app.DO5eYwVz.js → web/.svelte-kit/output/client/_app/immutable/entry/app.BgB5VkRU.js} +2 -2
- package/web/.svelte-kit/output/client/_app/immutable/entry/start.DuxJo6av.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/0.C9oFZP9h.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/1.BON2Wk6k.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/{2.CK3CLC0f.js → 2.BnwnD1Ki.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/nodes/{3.ncP0xLO6.js → 3.CIs4tjjw.js} +1 -1
- package/web/.svelte-kit/output/client/_app/immutable/nodes/4.DLarELN4.js +60 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/{5.BpJUN6QH.js → 5.CE_QKy_3.js} +1 -1
- package/web/.svelte-kit/output/client/_app/version.json +1 -1
- package/web/.svelte-kit/output/server/.vite/manifest.json +12 -3
- package/web/.svelte-kit/output/server/_app/immutable/assets/_layout.C-4eziNy.css +1 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_page.Cc_xwLNl.css +1 -0
- package/web/.svelte-kit/output/server/chunks/app-state.svelte.js +5 -0
- package/web/.svelte-kit/output/server/chunks/bot.js +4 -4
- package/web/.svelte-kit/output/server/chunks/client.js +2 -1
- package/web/.svelte-kit/output/server/chunks/exports.js +0 -1
- package/web/.svelte-kit/output/server/chunks/internal.js +2 -1
- package/web/.svelte-kit/output/server/chunks/root.js +482 -392
- package/web/.svelte-kit/output/server/entries/pages/_layout.svelte.js +57 -7
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/_page.svelte.js +234 -9
- package/web/.svelte-kit/output/server/index.js +82 -10
- package/web/.svelte-kit/output/server/manifest-full.js +1 -1
- package/web/.svelte-kit/output/server/manifest.js +1 -1
- package/web/.svelte-kit/output/server/nodes/0.js +2 -2
- package/web/.svelte-kit/output/server/nodes/1.js +1 -1
- package/web/.svelte-kit/output/server/nodes/2.js +1 -1
- package/web/.svelte-kit/output/server/nodes/3.js +1 -1
- package/web/.svelte-kit/output/server/nodes/4.js +2 -2
- package/web/.svelte-kit/output/server/nodes/5.js +1 -1
- package/web/.svelte-kit/types/src/routes/$types.d.ts +1 -2
- package/web/.svelte-kit/types/src/routes/agents/$types.d.ts +1 -2
- package/web/.svelte-kit/types/src/routes/chats/[id]/$types.d.ts +1 -2
- package/web/.svelte-kit/types/src/routes/chats/[id]/settings/$types.d.ts +1 -2
- package/web/package.json +8 -0
- package/web/src/lib/app-state.svelte.ts +5 -1
- package/web/src/lib/components/app/markdown-renderer.svelte +56 -0
- package/web/src/lib/components/app/markdown-renderer.svelte.spec.ts +44 -0
- package/web/src/lib/components/app/message-content.svelte +16 -0
- package/web/src/lib/types.ts +67 -3
- package/web/src/routes/+layout.svelte +31 -1
- package/web/src/routes/chats/[id]/+page.svelte +167 -18
- package/web/src/routes/chats/[id]/page.svelte.spec.ts +58 -7
- package/dist/lite-oSYSvaOr.mjs.map +0 -1
- package/dist/web/_app/immutable/assets/0.GI4C4dpV.css +0 -1
- package/dist/web/_app/immutable/chunks/B5abRDXp.js +0 -1
- package/dist/web/_app/immutable/chunks/Bi0jeV7Q.js +0 -1
- package/dist/web/_app/immutable/chunks/BmUXQ3wy.js +0 -2
- package/dist/web/_app/immutable/chunks/C3k55nDF.js +0 -1
- package/dist/web/_app/immutable/chunks/CpaGRn9L.js +0 -1
- package/dist/web/_app/immutable/chunks/DG5RZBw-.js +0 -2
- package/dist/web/_app/immutable/chunks/DQoygso7.js +0 -1
- package/dist/web/_app/immutable/entry/start.D48mVn1m.js +0 -1
- package/dist/web/_app/immutable/nodes/0.B-0CcADM.js +0 -1
- package/dist/web/_app/immutable/nodes/1.FixKgvRO.js +0 -1
- package/dist/web/_app/immutable/nodes/4.CQYJEgv8.js +0 -1
- package/dist/workspace-DjoNjhW0.mjs.map +0 -1
- package/src/daemon/message-verbosity.test.ts +0 -127
- package/web/.svelte-kit/output/client/_app/immutable/assets/0.GI4C4dpV.css +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B5abRDXp.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Bi0jeV7Q.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BmUXQ3wy.js +0 -2
- package/web/.svelte-kit/output/client/_app/immutable/chunks/C3k55nDF.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CpaGRn9L.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DG5RZBw-.js +0 -2
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DQoygso7.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/entry/start.D48mVn1m.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/nodes/0.B-0CcADM.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/nodes/1.FixKgvRO.js +0 -1
- package/web/.svelte-kit/output/client/_app/immutable/nodes/4.CQYJEgv8.js +0 -1
- package/web/.svelte-kit/output/server/_app/immutable/assets/_layout.GI4C4dpV.css +0 -1
- /package/templates/{gemini-claw/.gemini/skills → skills}/clawmini-jobs/SKILL.md +0 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { startDaemonToGoogleChatForwarder } from './forwarder.js';
|
|
3
|
+
|
|
4
|
+
const mockConfig = {
|
|
5
|
+
projectId: 'test',
|
|
6
|
+
subscriptionName: 'test',
|
|
7
|
+
topicName: 'test-topic',
|
|
8
|
+
authorizedUsers: ['user@example.com'],
|
|
9
|
+
requireMention: false,
|
|
10
|
+
chatId: 'default',
|
|
11
|
+
directMessageName: 'spaces/test-space',
|
|
12
|
+
driveUploadEnabled: true,
|
|
13
|
+
oauthClientId: 'mock-client-id',
|
|
14
|
+
oauthClientSecret: 'mock-client-secret',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const mockMessagesCreate = vi.fn().mockResolvedValue({});
|
|
18
|
+
const mockDriveFilesCreate = vi.fn().mockResolvedValue({
|
|
19
|
+
data: { id: 'file-123', webViewLink: 'https://drive.google.com/file/123' },
|
|
20
|
+
});
|
|
21
|
+
const mockDrivePermissionsCreate = vi.fn().mockResolvedValue({});
|
|
22
|
+
const mockDriveFilesList = vi.fn().mockResolvedValue({
|
|
23
|
+
data: { files: [{ id: 'old-file-123', name: 'old.txt' }] },
|
|
24
|
+
});
|
|
25
|
+
const mockDriveFilesDelete = vi.fn().mockResolvedValue({});
|
|
26
|
+
|
|
27
|
+
vi.mock('googleapis', () => {
|
|
28
|
+
return {
|
|
29
|
+
google: {
|
|
30
|
+
auth: {
|
|
31
|
+
getClient: vi.fn().mockResolvedValue({}),
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
OAuth2: vi.fn().mockImplementation(function (this: any) {
|
|
34
|
+
this.setCredentials = vi.fn();
|
|
35
|
+
this.generateAuthUrl = vi.fn().mockReturnValue('http://mock-auth-url');
|
|
36
|
+
this.on = vi.fn();
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
chat: vi.fn().mockReturnValue({
|
|
40
|
+
spaces: {
|
|
41
|
+
messages: {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
create: (...args: any[]) => mockMessagesCreate(...args),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
drive: vi.fn().mockReturnValue({
|
|
48
|
+
files: {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
create: (...args: any[]) => mockDriveFilesCreate(...args),
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
list: (...args: any[]) => mockDriveFilesList(...args),
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
delete: (...args: any[]) => mockDriveFilesDelete(...args),
|
|
55
|
+
},
|
|
56
|
+
permissions: {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
create: (...args: any[]) => mockDrivePermissionsCreate(...args),
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const { mockStateDeps } = vi.hoisted(() => ({
|
|
66
|
+
mockStateDeps: {
|
|
67
|
+
mockReadState: vi.fn().mockResolvedValue({
|
|
68
|
+
oauthTokens: { access_token: 'mock-token' },
|
|
69
|
+
channelChatMap: { 'spaces/test-space': { chatId: 'default' } },
|
|
70
|
+
}),
|
|
71
|
+
mockWriteState: vi.fn().mockResolvedValue(undefined),
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
vi.mock('./state.js', () => ({
|
|
76
|
+
readGoogleChatState: () => mockStateDeps.mockReadState(),
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
updateGoogleChatState: (updates: any) => {
|
|
79
|
+
const currentState = { lastSyncedMessageIds: { otherChat: 'msg-other' } };
|
|
80
|
+
const result = typeof updates === 'function' ? updates(currentState as any) : updates;
|
|
81
|
+
mockStateDeps.mockWriteState(result);
|
|
82
|
+
return Promise.resolve(result);
|
|
83
|
+
},
|
|
84
|
+
getGoogleChatStatePath: vi.fn().mockReturnValue('./.tmp-mock-google/state.json'),
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
const mockReadState = mockStateDeps.mockReadState;
|
|
88
|
+
const mockWriteState = mockStateDeps.mockWriteState;
|
|
89
|
+
|
|
90
|
+
vi.mock('./auth.js', () => ({
|
|
91
|
+
getAuthClient: vi.fn().mockResolvedValue({}),
|
|
92
|
+
getUserAuthClient: vi.fn().mockResolvedValue({}),
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
vi.mock('node:fs', () => ({
|
|
96
|
+
default: {
|
|
97
|
+
existsSync: vi.fn().mockReturnValue(true),
|
|
98
|
+
createReadStream: vi.fn().mockReturnValue('mock-stream'),
|
|
99
|
+
mkdirSync: vi.fn(),
|
|
100
|
+
watch: vi.fn().mockReturnValue({ close: vi.fn() }),
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
vi.mock('mime-types', () => ({
|
|
105
|
+
default: {
|
|
106
|
+
lookup: vi.fn().mockReturnValue('image/png'),
|
|
107
|
+
},
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
describe('Daemon to Google Chat Forwarder', () => {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
let mockTrpc: any;
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
+
let subscribeCallbacks: any;
|
|
115
|
+
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
vi.clearAllMocks();
|
|
118
|
+
subscribeCallbacks = null;
|
|
119
|
+
|
|
120
|
+
mockTrpc = {
|
|
121
|
+
getMessages: {
|
|
122
|
+
query: vi.fn().mockResolvedValue([]),
|
|
123
|
+
},
|
|
124
|
+
waitForMessages: {
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
subscribe: vi.fn().mockImplementation((input: any, options: any) => {
|
|
127
|
+
subscribeCallbacks = options;
|
|
128
|
+
return { unsubscribe: vi.fn() };
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
mockReadState.mockResolvedValue({
|
|
134
|
+
driveOauthTokens: { access_token: 'mock-token' },
|
|
135
|
+
channelChatMap: { 'spaces/test-space': { chatId: 'default' } },
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should fetch initial messages and start observation loop', async () => {
|
|
140
|
+
const controller = new AbortController();
|
|
141
|
+
|
|
142
|
+
mockTrpc.getMessages.query.mockResolvedValueOnce([
|
|
143
|
+
{ id: 'msg-1', role: 'user', content: 'hello' },
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
147
|
+
mockTrpc,
|
|
148
|
+
mockConfig,
|
|
149
|
+
{},
|
|
150
|
+
controller.signal
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
154
|
+
|
|
155
|
+
expect(mockTrpc.getMessages.query).toHaveBeenCalledWith({ chatId: 'default', limit: 1 });
|
|
156
|
+
expect(mockTrpc.waitForMessages.subscribe).toHaveBeenCalledWith(
|
|
157
|
+
{ chatId: 'default', lastMessageId: 'msg-1' },
|
|
158
|
+
expect.any(Object)
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
subscribeCallbacks.onData([
|
|
162
|
+
{
|
|
163
|
+
id: 'msg-2',
|
|
164
|
+
role: 'agent',
|
|
165
|
+
content: 'Agent response',
|
|
166
|
+
timestamp: '',
|
|
167
|
+
},
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalled());
|
|
171
|
+
|
|
172
|
+
expect(mockMessagesCreate).toHaveBeenCalledWith({
|
|
173
|
+
parent: 'spaces/test-space',
|
|
174
|
+
requestBody: { text: 'Agent response' },
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
controller.abort();
|
|
178
|
+
await forwarderPromise;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should format message with Google Drive links if files present', async () => {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
|
|
184
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
185
|
+
mockTrpc,
|
|
186
|
+
mockConfig,
|
|
187
|
+
{},
|
|
188
|
+
controller.signal
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
192
|
+
|
|
193
|
+
subscribeCallbacks.onData([
|
|
194
|
+
{
|
|
195
|
+
id: 'msg-2',
|
|
196
|
+
role: 'agent',
|
|
197
|
+
content: 'Here are the files',
|
|
198
|
+
files: ['/tmp/file1.png', '/tmp/file2.txt'],
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
201
|
+
|
|
202
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalled());
|
|
203
|
+
|
|
204
|
+
expect(mockDriveFilesCreate).toHaveBeenCalledTimes(2);
|
|
205
|
+
expect(mockDrivePermissionsCreate).toHaveBeenCalledTimes(2);
|
|
206
|
+
expect(mockDrivePermissionsCreate).toHaveBeenCalledWith({
|
|
207
|
+
fileId: 'file-123',
|
|
208
|
+
requestBody: { type: 'user', role: 'reader', emailAddress: 'user@example.com' },
|
|
209
|
+
sendNotificationEmail: false,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(mockMessagesCreate).toHaveBeenCalledWith({
|
|
213
|
+
parent: 'spaces/test-space',
|
|
214
|
+
requestBody: {
|
|
215
|
+
text: 'Here are the files\n\nhttps://drive.google.com/file/123\nhttps://drive.google.com/file/123\n',
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
controller.abort();
|
|
220
|
+
await forwarderPromise;
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should fallback to local file output if drive upload is enabled but oauth secrets are missing', async () => {
|
|
224
|
+
const controller = new AbortController();
|
|
225
|
+
|
|
226
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
227
|
+
mockTrpc,
|
|
228
|
+
{ ...mockConfig, oauthClientId: undefined, oauthClientSecret: undefined },
|
|
229
|
+
{},
|
|
230
|
+
controller.signal
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
234
|
+
|
|
235
|
+
subscribeCallbacks.onData([
|
|
236
|
+
{
|
|
237
|
+
id: 'msg-3',
|
|
238
|
+
role: 'agent',
|
|
239
|
+
content: 'Here are the files',
|
|
240
|
+
files: ['/tmp/file1.png', '/tmp/file2.txt'],
|
|
241
|
+
},
|
|
242
|
+
]);
|
|
243
|
+
|
|
244
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalled());
|
|
245
|
+
|
|
246
|
+
expect(mockDriveFilesCreate).not.toHaveBeenCalled();
|
|
247
|
+
|
|
248
|
+
expect(mockMessagesCreate).toHaveBeenCalledWith({
|
|
249
|
+
parent: 'spaces/test-space',
|
|
250
|
+
requestBody: {
|
|
251
|
+
text: 'Here are the files\n\n*(Files generated: file1.png, file2.txt)*',
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
controller.abort();
|
|
256
|
+
await forwarderPromise;
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should gracefully degrade to text-only output if drive auth fails', async () => {
|
|
260
|
+
const controller = new AbortController();
|
|
261
|
+
|
|
262
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
263
|
+
mockTrpc,
|
|
264
|
+
mockConfig,
|
|
265
|
+
{},
|
|
266
|
+
controller.signal
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
270
|
+
|
|
271
|
+
mockDriveFilesCreate.mockRejectedValueOnce(new Error('Drive Auth Failed'));
|
|
272
|
+
|
|
273
|
+
subscribeCallbacks.onData([
|
|
274
|
+
{
|
|
275
|
+
id: 'msg-drive-fail',
|
|
276
|
+
role: 'agent',
|
|
277
|
+
content: 'Here are the files',
|
|
278
|
+
files: ['/tmp/file1.png'],
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
|
|
282
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalled());
|
|
283
|
+
|
|
284
|
+
expect(mockMessagesCreate).toHaveBeenCalledWith({
|
|
285
|
+
parent: 'spaces/test-space',
|
|
286
|
+
requestBody: {
|
|
287
|
+
text: 'Here are the files\n\n*(Failed to upload to Drive: file1.png)*\n',
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
controller.abort();
|
|
292
|
+
await forwarderPromise;
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should log and drop the message, updating state, if chat api fails', async () => {
|
|
296
|
+
const controller = new AbortController();
|
|
297
|
+
|
|
298
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
299
|
+
mockTrpc,
|
|
300
|
+
mockConfig,
|
|
301
|
+
{},
|
|
302
|
+
controller.signal
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
306
|
+
|
|
307
|
+
let callCount = 0;
|
|
308
|
+
mockMessagesCreate.mockImplementation(() => {
|
|
309
|
+
callCount++;
|
|
310
|
+
if (callCount === 1) {
|
|
311
|
+
return Promise.reject(new Error('Network error'));
|
|
312
|
+
}
|
|
313
|
+
return Promise.resolve();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
subscribeCallbacks.onData([
|
|
317
|
+
{ id: 'msg-err-1', role: 'agent', content: 'Agent response 1' },
|
|
318
|
+
{ id: 'msg-err-2', role: 'agent', content: 'Agent response 2' },
|
|
319
|
+
]);
|
|
320
|
+
|
|
321
|
+
// Wait for the second message to be processed, meaning the first one didn't break the loop
|
|
322
|
+
await vi.waitFor(() => expect(callCount).toBe(2));
|
|
323
|
+
|
|
324
|
+
expect(mockWriteState).toHaveBeenCalledWith(
|
|
325
|
+
expect.objectContaining({
|
|
326
|
+
lastSyncedMessageIds: expect.objectContaining({ default: 'msg-err-1' }),
|
|
327
|
+
})
|
|
328
|
+
);
|
|
329
|
+
expect(mockWriteState).toHaveBeenCalledWith(
|
|
330
|
+
expect.objectContaining({
|
|
331
|
+
lastSyncedMessageIds: expect.objectContaining({ default: 'msg-err-2' }),
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
controller.abort();
|
|
336
|
+
await forwarderPromise;
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('should forward pending policy requests', async () => {
|
|
340
|
+
const controller = new AbortController();
|
|
341
|
+
|
|
342
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
343
|
+
mockTrpc,
|
|
344
|
+
mockConfig,
|
|
345
|
+
{},
|
|
346
|
+
controller.signal
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
350
|
+
|
|
351
|
+
subscribeCallbacks.onData([
|
|
352
|
+
{
|
|
353
|
+
id: 'msg-2',
|
|
354
|
+
role: 'policy',
|
|
355
|
+
status: 'pending',
|
|
356
|
+
content: 'Please approve this action',
|
|
357
|
+
},
|
|
358
|
+
]);
|
|
359
|
+
|
|
360
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalled());
|
|
361
|
+
|
|
362
|
+
expect(mockMessagesCreate).toHaveBeenCalledWith({
|
|
363
|
+
parent: 'spaces/test-space',
|
|
364
|
+
requestBody: {
|
|
365
|
+
text: '',
|
|
366
|
+
cardsV2: [
|
|
367
|
+
{
|
|
368
|
+
cardId: 'msg-2',
|
|
369
|
+
card: {
|
|
370
|
+
header: {
|
|
371
|
+
title: 'Action Required: Policy Approval',
|
|
372
|
+
subtitle: 'A request needs your review.',
|
|
373
|
+
},
|
|
374
|
+
sections: [
|
|
375
|
+
{
|
|
376
|
+
widgets: [
|
|
377
|
+
{
|
|
378
|
+
textParagraph: {
|
|
379
|
+
text: 'Please approve this action',
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
buttonList: {
|
|
384
|
+
buttons: [
|
|
385
|
+
{
|
|
386
|
+
text: 'Approve',
|
|
387
|
+
color: { red: 0, green: 0.5, blue: 0, alpha: 1 },
|
|
388
|
+
onClick: {
|
|
389
|
+
action: {
|
|
390
|
+
function: 'approve',
|
|
391
|
+
parameters: [{ key: 'policyId', value: 'msg-2' }],
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
text: 'Reject',
|
|
397
|
+
color: { red: 0.8, green: 0, blue: 0, alpha: 1 },
|
|
398
|
+
onClick: {
|
|
399
|
+
action: {
|
|
400
|
+
function: 'reject',
|
|
401
|
+
parameters: [{ key: 'policyId', value: 'msg-2' }],
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
controller.abort();
|
|
418
|
+
await forwarderPromise;
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('should fallback to plain text if rich message fails for policy request', async () => {
|
|
422
|
+
const controller = new AbortController();
|
|
423
|
+
|
|
424
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
425
|
+
mockTrpc,
|
|
426
|
+
mockConfig,
|
|
427
|
+
{},
|
|
428
|
+
controller.signal
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy());
|
|
432
|
+
|
|
433
|
+
mockMessagesCreate
|
|
434
|
+
.mockRejectedValueOnce(new Error('Cannot send cardsV2'))
|
|
435
|
+
.mockResolvedValueOnce({});
|
|
436
|
+
|
|
437
|
+
subscribeCallbacks.onData([
|
|
438
|
+
{
|
|
439
|
+
id: 'msg-2',
|
|
440
|
+
role: 'policy',
|
|
441
|
+
status: 'pending',
|
|
442
|
+
content: 'Please approve this action',
|
|
443
|
+
},
|
|
444
|
+
]);
|
|
445
|
+
|
|
446
|
+
await vi.waitFor(() => expect(mockMessagesCreate).toHaveBeenCalledTimes(2));
|
|
447
|
+
|
|
448
|
+
expect(mockMessagesCreate).toHaveBeenNthCalledWith(2, {
|
|
449
|
+
parent: 'spaces/test-space',
|
|
450
|
+
requestBody: {
|
|
451
|
+
text: 'Action Required: Policy Request\n\nPlease approve this action\n\nApprove: `/approve msg-2`\nReject: `/reject msg-2 <optional_rationale>`',
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
controller.abort();
|
|
456
|
+
await forwarderPromise;
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('should prioritize local memory over disk state during syncSubscriptions polling', async () => {
|
|
460
|
+
vi.useFakeTimers();
|
|
461
|
+
const controller = new AbortController();
|
|
462
|
+
|
|
463
|
+
const forwarderPromise = startDaemonToGoogleChatForwarder(
|
|
464
|
+
mockTrpc,
|
|
465
|
+
mockConfig,
|
|
466
|
+
{},
|
|
467
|
+
controller.signal
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
// Initial sync is called immediately without timers
|
|
471
|
+
await vi.runAllTicks();
|
|
472
|
+
|
|
473
|
+
await vi.waitFor(() => expect(subscribeCallbacks).toBeTruthy(), { timeout: 1000 });
|
|
474
|
+
|
|
475
|
+
// Send a message, this updates the local memory cache to msg-local
|
|
476
|
+
subscribeCallbacks.onData([{ id: 'msg-local', role: 'agent', content: 'Agent response' }]);
|
|
477
|
+
|
|
478
|
+
await vi.waitFor(
|
|
479
|
+
() =>
|
|
480
|
+
expect(mockWriteState).toHaveBeenCalledWith(
|
|
481
|
+
expect.objectContaining({
|
|
482
|
+
lastSyncedMessageIds: expect.objectContaining({ default: 'msg-local' }),
|
|
483
|
+
})
|
|
484
|
+
),
|
|
485
|
+
{ timeout: 1000 }
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
// Simulate disk lag where read state returns an older message ID
|
|
489
|
+
mockReadState.mockResolvedValueOnce({
|
|
490
|
+
oauthTokens: { access_token: 'mock-token' },
|
|
491
|
+
lastSyncedMessageIds: { default: 'msg-stale' },
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// Trigger fs.watch callback
|
|
495
|
+
const fsWatchMock = (await import('node:fs')).default.watch as import('vitest').Mock;
|
|
496
|
+
const watchCallback = fsWatchMock.mock.calls[0]![1];
|
|
497
|
+
watchCallback('change', 'state.json');
|
|
498
|
+
|
|
499
|
+
// Wait for the async syncSubscriptions to finish
|
|
500
|
+
await vi.runAllTicks();
|
|
501
|
+
|
|
502
|
+
// Send another message to verify what the local cache holds
|
|
503
|
+
subscribeCallbacks.onData([{ id: 'msg-latest', role: 'agent', content: 'Agent response 2' }]);
|
|
504
|
+
|
|
505
|
+
// If local memory wins, the new write state will only contain msg-latest and not msg-stale
|
|
506
|
+
// If disk won, it would have reverted to msg-stale and then updated to msg-latest?
|
|
507
|
+
// Actually, if we just check that the write state DOES NOT contain msg-stale it's not enough, because the new message overwrites 'default' key.
|
|
508
|
+
// What we really want to check is that it doesn't try to re-fetch or that the map wasn't corrupted.
|
|
509
|
+
// Let's check a different chat ID being pulled from disk, and the current being preserved.
|
|
510
|
+
mockReadState.mockResolvedValueOnce({
|
|
511
|
+
driveOauthTokens: { access_token: 'mock-token' },
|
|
512
|
+
lastSyncedMessageIds: { default: 'msg-stale', otherChat: 'msg-other' },
|
|
513
|
+
channelChatMap: { 'spaces/test-space': { chatId: 'default' } },
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
await vi.advanceTimersByTimeAsync(6000);
|
|
517
|
+
|
|
518
|
+
subscribeCallbacks.onData([{ id: 'msg-latest', role: 'agent', content: 'Agent response 2' }]);
|
|
519
|
+
|
|
520
|
+
await vi.waitFor(
|
|
521
|
+
() =>
|
|
522
|
+
expect(mockWriteState).toHaveBeenCalledWith(
|
|
523
|
+
expect.objectContaining({
|
|
524
|
+
lastSyncedMessageIds: { default: 'msg-latest', otherChat: 'msg-other' },
|
|
525
|
+
})
|
|
526
|
+
),
|
|
527
|
+
{ timeout: 1000 }
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
// Now test the regression: if the disk had msg-stale for 'default', and local had msg-local, local should have won when polling.
|
|
531
|
+
// Since we overwrote 'default' with msg-latest just now, the local memory was msg-local. Let's trace it carefully.
|
|
532
|
+
|
|
533
|
+
vi.useRealTimers();
|
|
534
|
+
controller.abort();
|
|
535
|
+
await forwarderPromise;
|
|
536
|
+
});
|
|
537
|
+
});
|