@@ -1729,6 +1729,67 @@ describe("resolvePluginTools optional tools", () => {
17291729 expect ( loadOpenClawPluginsMock ) . not . toHaveBeenCalled ( ) ;
17301730 } ) ;
17311731
1732+ it ( "rechecks cached optional tool availability when provider auth changes" , ( ) => {
1733+ const config = createContext ( ) . config ;
1734+ const env = { } ;
1735+ installToolManifestSnapshot ( {
1736+ config,
1737+ env,
1738+ plugin : {
1739+ id : "multi" ,
1740+ origin : "bundled" ,
1741+ enabledByDefault : true ,
1742+ channels : [ ] ,
1743+ providers : [ ] ,
1744+ setup : {
1745+ providers : [ { id : "xai" , envVars : [ "XAI_API_KEY" ] } ] ,
1746+ } ,
1747+ contracts : {
1748+ tools : [ "other_tool" , "optional_tool" ] ,
1749+ } ,
1750+ toolMetadata : {
1751+ optional_tool : {
1752+ optional : true ,
1753+ authSignals : [ { provider : "xai" } ] ,
1754+ } ,
1755+ } ,
1756+ } ,
1757+ } ) ;
1758+ const factory = vi . fn ( ( ) => [ makeTool ( "other_tool" ) , makeTool ( "optional_tool" ) ] ) ;
1759+ setActivePluginRegistry (
1760+ createToolRegistry ( [
1761+ {
1762+ pluginId : "multi" ,
1763+ optional : false ,
1764+ source : "/tmp/multi.js" ,
1765+ names : [ "other_tool" , "optional_tool" ] ,
1766+ declaredNames : [ "other_tool" , "optional_tool" ] ,
1767+ factory,
1768+ } ,
1769+ ] ) as never ,
1770+ "test-tool-registry" ,
1771+ "gateway-bindable" ,
1772+ "/tmp" ,
1773+ ) ;
1774+ const resolveWithAuth = ( hasAuth : boolean ) =>
1775+ resolvePluginTools ( {
1776+ ...createResolveToolsParams ( {
1777+ context : {
1778+ ...createContext ( ) ,
1779+ config,
1780+ } ,
1781+ env,
1782+ toolAllowlist : [ DEFAULT_PLUGIN_TOOLS_ALLOWLIST_ENTRY , "optional_tool" ] ,
1783+ } ) ,
1784+ hasAuthForProvider : ( providerId ) => providerId === "xai" && hasAuth ,
1785+ } ) ;
1786+
1787+ expectResolvedToolNames ( resolveWithAuth ( true ) , [ "other_tool" , "optional_tool" ] ) ;
1788+ expectResolvedToolNames ( resolveWithAuth ( false ) , [ "other_tool" ] ) ;
1789+ expectResolvedToolNames ( resolveWithAuth ( true ) , [ "other_tool" , "optional_tool" ] ) ;
1790+ expect ( factory ) . toHaveBeenCalledTimes ( 1 ) ;
1791+ } ) ;
1792+
17321793 it ( "does not materialize manifest-optional sibling tools from non-optional factories by default" , async ( ) => {
17331794 const config = createContext ( ) . config ;
17341795 installToolManifestSnapshot ( {
0 commit comments