@@ -4,10 +4,6 @@ import os from "node:os";
44import path from "node:path" ;
55import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
66import { clearConfigCache , clearRuntimeConfigSnapshot } from "../config/config.js" ;
7- import { clearPluginDiscoveryCache } from "../plugins/discovery.js" ;
8- import { clearPluginLoaderCache } from "../plugins/loader.js" ;
9- import { clearPluginManifestRegistryCache } from "../plugins/manifest-registry.js" ;
10- import { resetPluginRuntimeStateForTest } from "../plugins/runtime.js" ;
117import { buildSystemRunPreparePayload } from "../test-utils/system-run-prepare-payload.js" ;
128
139vi . mock ( "./tools/gateway.js" , ( ) => ( {
@@ -28,7 +24,6 @@ vi.mock("../infra/outbound/message.js", () => ({
2824
2925let callGatewayTool : typeof import ( "./tools/gateway.js" ) . callGatewayTool ;
3026let createExecTool : typeof import ( "./bash-tools.exec.js" ) . createExecTool ;
31- let getExecApprovalApproverDmNoticeText : typeof import ( "../infra/exec-approval-reply.js" ) . getExecApprovalApproverDmNoticeText ;
3227let sendMessage : typeof import ( "../infra/outbound/message.js" ) . sendMessage ;
3328
3429function buildPreparedSystemRunPayload ( rawInvokeParams : unknown ) {
@@ -45,42 +40,12 @@ function buildPreparedSystemRunPayload(rawInvokeParams: unknown) {
4540 return buildSystemRunPreparePayload ( params ) ;
4641}
4742
48- function getTestConfigPath ( ) {
49- return path . join ( process . env . HOME ?? "" , ".openclaw" , "openclaw.json" ) ;
50- }
51-
52- async function writeOpenClawConfig ( config : Record < string , unknown > , pretty = false ) {
53- const configPath = getTestConfigPath ( ) ;
54- await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } ) ;
55- await fs . writeFile ( configPath , JSON . stringify ( config , null , pretty ? 2 : undefined ) ) ;
56- }
57-
5843async function writeExecApprovalsConfig ( config : Record < string , unknown > ) {
5944 const approvalsPath = path . join ( process . env . HOME ?? "" , ".openclaw" , "exec-approvals.json" ) ;
6045 await fs . mkdir ( path . dirname ( approvalsPath ) , { recursive : true } ) ;
6146 await fs . writeFile ( approvalsPath , JSON . stringify ( config , null , 2 ) ) ;
6247}
6348
64- function resetPluginState ( ) {
65- clearPluginDiscoveryCache ( ) ;
66- clearPluginLoaderCache ( ) ;
67- clearPluginManifestRegistryCache ( ) ;
68- resetPluginRuntimeStateForTest ( ) ;
69- clearRuntimeConfigSnapshot ( ) ;
70- clearConfigCache ( ) ;
71- }
72-
73- async function withBundledChannels < T > ( run : ( ) => Promise < T > ) {
74- delete process . env . OPENCLAW_DISABLE_BUNDLED_PLUGINS ;
75- resetPluginState ( ) ;
76- try {
77- return await run ( ) ;
78- } finally {
79- process . env . OPENCLAW_DISABLE_BUNDLED_PLUGINS = "1" ;
80- resetPluginState ( ) ;
81- }
82- }
83-
8449function acceptedApprovalResponse ( params : unknown ) {
8550 return { status : "accepted" , id : ( params as { id ?: string } ) ?. id } ;
8651}
@@ -272,7 +237,6 @@ describe("exec approvals", () => {
272237 process . env . OPENCLAW_DISABLE_BUNDLED_PLUGINS = "1" ;
273238 ( { callGatewayTool } = await import ( "./tools/gateway.js" ) ) ;
274239 ( { createExecTool } = await import ( "./bash-tools.exec.js" ) ) ;
275- ( { getExecApprovalApproverDmNoticeText } = await import ( "../infra/exec-approval-reply.js" ) ) ;
276240 ( { sendMessage } = await import ( "../infra/outbound/message.js" ) ) ;
277241 vi . mocked ( callGatewayTool ) . mockReset ( ) ;
278242 vi . mocked ( sendMessage ) . mockClear ( ) ;
@@ -1391,95 +1355,4 @@ describe("exec approvals", () => {
13911355 } ) ,
13921356 ) . rejects . toThrow ( "Cron runs cannot wait for interactive exec approval" ) ;
13931357 } ) ;
1394-
1395- it ( "returns an unavailable reply when discord exec approvals are disabled" , async ( ) => {
1396- await writeOpenClawConfig ( {
1397- channels : {
1398- discord : {
1399- enabled : true ,
1400- execApprovals : { enabled : false } ,
1401- } ,
1402- } ,
1403- } ) ;
1404-
1405- mockPendingApprovalRegistration ( ) ;
1406-
1407- const tool = createExecTool ( {
1408- host : "gateway" ,
1409- ask : "always" ,
1410- approvalRunningNoticeMs : 0 ,
1411- messageProvider : "discord" ,
1412- accountId : "default" ,
1413- currentChannelId : "1234567890" ,
1414- } ) ;
1415-
1416- const result = await withBundledChannels ( async ( ) =>
1417- tool . execute ( "call-unavailable" , {
1418- command : "npm view diver name version description" ,
1419- } ) ,
1420- ) ;
1421-
1422- expect ( result . details . status ) . toBe ( "approval-unavailable" ) ;
1423- expect ( result . details ) . toMatchObject ( {
1424- reason : "initiating-platform-disabled" ,
1425- channel : "discord" ,
1426- channelLabel : "Discord" ,
1427- accountId : "default" ,
1428- host : "gateway" ,
1429- } ) ;
1430- expect ( getResultText ( result ) ) . toContain (
1431- "native chat exec approvals are not configured on Discord" ,
1432- ) ;
1433- expect ( getResultText ( result ) ) . not . toContain ( "/approve" ) ;
1434- expect ( getResultText ( result ) ) . not . toContain ( "Pending command:" ) ;
1435- } ) ;
1436-
1437- it ( "keeps the Telegram unavailable reply when Discord DM approvals are not fully configured" , async ( ) => {
1438- await writeOpenClawConfig (
1439- {
1440- channels : {
1441- telegram : {
1442- enabled : true ,
1443- execApprovals : { enabled : false } ,
1444- } ,
1445- discord : {
1446- enabled : true ,
1447- execApprovals : { enabled : true , approvers : [ "123" ] , target : "dm" } ,
1448- } ,
1449- } ,
1450- } ,
1451- true ,
1452- ) ;
1453-
1454- mockPendingApprovalRegistration ( ) ;
1455-
1456- const tool = createExecTool ( {
1457- host : "gateway" ,
1458- ask : "always" ,
1459- approvalRunningNoticeMs : 0 ,
1460- messageProvider : "telegram" ,
1461- accountId : "default" ,
1462- currentChannelId : "-1003841603622" ,
1463- } ) ;
1464-
1465- const result = await withBundledChannels ( async ( ) =>
1466- tool . execute ( "call-tg-unavailable" , {
1467- command : "npm view diver name version description" ,
1468- } ) ,
1469- ) ;
1470-
1471- expect ( result . details . status ) . toBe ( "approval-unavailable" ) ;
1472- expect ( result . details ) . toMatchObject ( {
1473- reason : "initiating-platform-disabled" ,
1474- channel : "telegram" ,
1475- channelLabel : "Telegram" ,
1476- accountId : "default" ,
1477- sentApproverDms : false ,
1478- host : "gateway" ,
1479- } ) ;
1480- expect ( getResultText ( result ) ) . toContain (
1481- "native chat exec approvals are not configured on Telegram" ,
1482- ) ;
1483- expect ( getResultText ( result ) ) . not . toContain ( getExecApprovalApproverDmNoticeText ( ) ) ;
1484- } ) ;
14851358} ) ;
0 commit comments