2026-03-10 20:16:35 -04:00
import fs from "node:fs/promises" ;
import path from "node:path" ;
import { describe , expect , it } from "vitest" ;
import { withTempHome } from "../../test/helpers/temp-home.js" ;
import {
detectPluginInstallPathIssue ,
formatPluginInstallPathIssue ,
} from "./plugin-install-path-warnings.js" ;
2026-03-13 21:09:36 +00:00
async function detectMatrixCustomPathIssue ( sourcePath : string | ( ( pluginPath : string ) = > string ) ) {
return withTempHome ( async ( home ) = > {
const pluginPath = path . join ( home , "matrix-plugin" ) ;
await fs . mkdir ( pluginPath , { recursive : true } ) ;
const resolvedSourcePath =
typeof sourcePath === "function" ? sourcePath ( pluginPath ) : sourcePath ;
const issue = await detectPluginInstallPathIssue ( {
pluginId : "matrix" ,
install : {
source : "path" ,
sourcePath : resolvedSourcePath ,
installPath : pluginPath ,
} ,
} ) ;
return { issue , pluginPath } ;
} ) ;
}
2026-03-10 20:16:35 -04:00
describe ( "plugin install path warnings" , ( ) = > {
2026-03-13 18:58:53 +00:00
it ( "ignores non-path installs and blank path candidates" , async ( ) = > {
expect (
await detectPluginInstallPathIssue ( {
pluginId : "matrix" ,
install : null ,
} ) ,
) . toBeNull ( ) ;
expect (
await detectPluginInstallPathIssue ( {
pluginId : "matrix" ,
install : {
source : "npm" ,
sourcePath : " " ,
installPath : " " ,
} ,
} ) ,
) . toBeNull ( ) ;
} ) ;
2026-03-10 20:16:35 -04:00
it ( "detects stale custom plugin install paths" , async ( ) = > {
const issue = await detectPluginInstallPathIssue ( {
pluginId : "matrix" ,
install : {
source : "path" ,
sourcePath : "/tmp/openclaw-matrix-missing" ,
installPath : "/tmp/openclaw-matrix-missing" ,
} ,
} ) ;
expect ( issue ) . toEqual ( {
kind : "missing-path" ,
pluginId : "matrix" ,
path : "/tmp/openclaw-matrix-missing" ,
} ) ;
expect (
formatPluginInstallPathIssue ( {
issue : issue ! ,
pluginLabel : "Matrix" ,
defaultInstallCommand : "openclaw plugins install @openclaw/matrix" ,
repoInstallCommand : "openclaw plugins install ./extensions/matrix" ,
} ) ,
) . toEqual ( [
"Matrix is installed from a custom path that no longer exists: /tmp/openclaw-matrix-missing" ,
'Reinstall with "openclaw plugins install @openclaw/matrix".' ,
'If you are running from a repo checkout, you can also use "openclaw plugins install ./extensions/matrix".' ,
] ) ;
} ) ;
2026-03-13 18:58:53 +00:00
it ( "uses the second candidate path when the first one is stale" , async ( ) = > {
2026-03-13 21:09:36 +00:00
const { issue , pluginPath } = await detectMatrixCustomPathIssue ( "/tmp/openclaw-matrix-missing" ) ;
expect ( issue ) . toEqual ( {
kind : "custom-path" ,
pluginId : "matrix" ,
path : pluginPath ,
2026-03-13 18:58:53 +00:00
} ) ;
} ) ;
2026-03-10 20:16:35 -04:00
it ( "detects active custom plugin install paths" , async ( ) = > {
2026-03-13 21:09:36 +00:00
const { issue , pluginPath } = await detectMatrixCustomPathIssue (
( resolvedPluginPath ) = > resolvedPluginPath ,
) ;
expect ( issue ) . toEqual ( {
kind : "custom-path" ,
pluginId : "matrix" ,
path : pluginPath ,
2026-03-10 20:16:35 -04:00
} ) ;
} ) ;
2026-03-13 18:58:53 +00:00
it ( "applies custom command formatting in warning messages" , ( ) = > {
expect (
formatPluginInstallPathIssue ( {
issue : {
kind : "custom-path" ,
pluginId : "matrix" ,
path : "/tmp/matrix-plugin" ,
} ,
pluginLabel : "Matrix" ,
defaultInstallCommand : "openclaw plugins install @openclaw/matrix" ,
repoInstallCommand : "openclaw plugins install ./extensions/matrix" ,
formatCommand : ( command ) = > ` < ${ command } > ` ,
} ) ,
) . toEqual ( [
"Matrix is installed from a custom path: /tmp/matrix-plugin" ,
"Main updates will not automatically replace that plugin with the repo's default Matrix package." ,
'Reinstall with "<openclaw plugins install @openclaw/matrix>" when you want to return to the standard Matrix plugin.' ,
'If you are intentionally running from a repo checkout, reinstall that checkout explicitly with "<openclaw plugins install ./extensions/matrix>" after updates.' ,
] ) ;
} ) ;
2026-03-10 20:16:35 -04:00
} ) ;