@@ -14,7 +14,7 @@ import {
1414 runOpenClawStateWriteTransaction ,
1515} from "../state/openclaw-state-db.js" ;
1616import {
17- resetPluginConversationBindingStateForTest ,
17+ resetPluginConversationBindingCachesForTest ,
1818 seedPluginConversationBindingApprovalForTest ,
1919} from "./conversation-binding.test-fixtures.js" ;
2020import { createEmptyPluginRegistry } from "./registry-empty.js" ;
@@ -118,6 +118,7 @@ vi.mock("./runtime.js", async () => {
118118} ) ;
119119
120120let buildPluginBindingApprovalCustomId : typeof import ( "./conversation-binding.js" ) . buildPluginBindingApprovalCustomId ;
121+ let clearPluginBindingPendingRequests : typeof import ( "./conversation-binding.js" ) . clearPluginBindingPendingRequests ;
121122let bindPluginSessionConversation : typeof import ( "./session-conversation-binding.js" ) . bindPluginSessionConversation ;
122123let detachPluginConversationBinding : typeof import ( "./conversation-binding.js" ) . detachPluginConversationBinding ;
123124let getCurrentPluginConversationBinding : typeof import ( "./conversation-binding.js" ) . getCurrentPluginConversationBinding ;
@@ -175,6 +176,7 @@ afterAll(() => {
175176beforeAll ( async ( ) => {
176177 ( {
177178 buildPluginBindingApprovalCustomId,
179+ clearPluginBindingPendingRequests,
178180 detachPluginConversationBinding,
179181 getCurrentPluginConversationBinding,
180182 parsePluginBindingApprovalCustomId,
@@ -287,7 +289,7 @@ async function approveBindingRequest(
287289async function importDuplicateConversationBindingModules ( ) {
288290 const first = await importConversationBindingModule ( `first-${ Date . now ( ) } ` ) ;
289291 const second = await importConversationBindingModule ( `second-${ Date . now ( ) } ` ) ;
290- resetPluginConversationBindingStateForTest ( ) ;
292+ resetPluginConversationBindingCachesForTest ( ) ;
291293 return { first, second } ;
292294}
293295
@@ -458,10 +460,11 @@ function insertPluginBindingApprovalRow(params: {
458460
459461describe ( "plugin conversation binding approvals" , ( ) => {
460462 beforeEach ( ( ) => {
463+ clearPluginBindingPendingRequests ( ) ;
461464 process . env . OPENCLAW_STATE_DIR = tempRoot ;
462465 clearPluginBindingApprovalRows ( ) ;
463466 sessionBindingState . reset ( ) ;
464- resetPluginConversationBindingStateForTest ( ) ;
467+ resetPluginConversationBindingCachesForTest ( ) ;
465468 setActivePluginRegistry ( createEmptyPluginRegistry ( ) ) ;
466469 unregisterSessionBindingAdapter ( { channel : "discord" , accountId : "default" } ) ;
467470 unregisterSessionBindingAdapter ( { channel : "discord" , accountId : "work" } ) ;
@@ -727,33 +730,6 @@ describe("plugin conversation binding approvals", () => {
727730 ] ) ;
728731 } ) ;
729732
730- it ( "shares pending bind approvals across duplicate module instances" , async ( ) => {
731- const { first, second } = await importDuplicateConversationBindingModules ( ) ;
732- const request = await requestPendingBinding (
733- createTelegramCodexBindRequest (
734- "-10099:topic:77" ,
735- "77" ,
736- "Bind this conversation to Codex thread abc." ,
737- ) ,
738- first . requestPluginConversationBinding ,
739- ) ;
740-
741- const approved = await approveBindingRequest (
742- request . approvalId ,
743- "allow-once" ,
744- second . resolvePluginConversationBindingApproval ,
745- ) ;
746- expect ( approved . status ) . toBe ( "approved" ) ;
747- if ( approved . status !== "approved" ) {
748- throw new Error ( "expected approved bind result" ) ;
749- }
750- expect ( approved . binding . pluginId ) . toBe ( "codex" ) ;
751- expect ( approved . binding . pluginRoot ) . toBe ( "/plugins/codex-a" ) ;
752- expect ( approved . binding . conversationId ) . toBe ( "-10099:topic:77" ) ;
753-
754- resetPluginConversationBindingStateForTest ( ) ;
755- } ) ;
756-
757733 it ( "shares persistent approvals across duplicate module instances" , async ( ) => {
758734 const { first, second } = await importDuplicateConversationBindingModules ( ) ;
759735 const request = await requestPendingBinding (
@@ -768,15 +744,15 @@ describe("plugin conversation binding approvals", () => {
768744 const approved = await approveBindingRequest (
769745 request . approvalId ,
770746 "allow-always" ,
771- second . resolvePluginConversationBindingApproval ,
747+ first . resolvePluginConversationBindingApproval ,
772748 ) ;
773749 expect ( approved . status ) . toBe ( "approved" ) ;
774750 if ( approved . status !== "approved" ) {
775751 throw new Error ( "expected approved bind result" ) ;
776752 }
777753 expect ( approved . decision ) . toBe ( "allow-always" ) ;
778754
779- const rebound = await first . requestPluginConversationBinding (
755+ const rebound = await second . requestPluginConversationBinding (
780756 createTelegramCodexBindRequest (
781757 "-10099:topic:78" ,
782758 "78" ,
@@ -786,10 +762,26 @@ describe("plugin conversation binding approvals", () => {
786762
787763 expect ( rebound . status ) . toBe ( "bound" ) ;
788764
789- resetPluginConversationBindingStateForTest ( ) ;
765+ resetPluginConversationBindingCachesForTest ( ) ;
790766 clearPluginBindingApprovalRows ( ) ;
791767 } ) ;
792768
769+ it ( "expires pending approvals when their Gateway lifecycle closes" , async ( ) => {
770+ const request = await requestPendingBinding (
771+ createTelegramCodexBindRequest (
772+ "-10099:topic:79" ,
773+ "79" ,
774+ "Bind this conversation to Codex thread ghi." ,
775+ ) ,
776+ ) ;
777+
778+ clearPluginBindingPendingRequests ( ) ;
779+
780+ await expect ( approveBindingRequest ( request . approvalId , "allow-once" ) ) . resolves . toEqual ( {
781+ status : "expired" ,
782+ } ) ;
783+ } ) ;
784+
793785 it ( "does not share persistent approvals across plugin roots even with the same plugin id" , async ( ) => {
794786 const request = await requestPluginConversationBinding (
795787 createCodexBindRequest ( {
0 commit comments