@@ -10,7 +10,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1010import { buildGroupChatContext , buildGroupIntro } from "../../auto-reply/reply/groups.js" ;
1111import type { ChannelPlugin } from "../../channels/plugins/types.plugin.js" ;
1212import type { OpenClawConfig } from "../../config/types.openclaw.js" ;
13- import { registerLegacyContextEngine } from "../../context-engine/legacy.registration.js" ;
1413import { registerContextEngineForOwner } from "../../context-engine/registry.js" ;
1514import type { ContextEngine } from "../../context-engine/types.js" ;
1615import type { CliBackendPlugin } from "../../plugins/cli-backend.types.js" ;
@@ -19,7 +18,9 @@ import {
1918 clearMemoryPluginState ,
2019 registerTestMemoryPromptBuilder ,
2120} from "../../plugins/memory-state.test-fixtures.js" ;
21+ import { createPluginRegistry } from "../../plugins/registry.js" ;
2222import { setActivePluginRegistry } from "../../plugins/runtime.js" ;
23+ import type { PluginRuntime } from "../../plugins/runtime/types.js" ;
2324import {
2425 createChannelTestPluginBase ,
2526 createTestRegistry ,
@@ -66,6 +67,21 @@ function registerTestContextEngine(
6667 } ) ;
6768}
6869
70+ function installTestPluginRegistry ( ) {
71+ const builder = createPluginRegistry ( {
72+ logger : {
73+ info ( ) { } ,
74+ warn ( ) { } ,
75+ error ( ) { } ,
76+ debug ( ) { } ,
77+ } ,
78+ runtime : { } as PluginRuntime ,
79+ activateGlobalSideEffects : true ,
80+ } ) ;
81+ setActivePluginRegistry ( builder . registry ) ;
82+ return builder ;
83+ }
84+
6985const getRuntimeConfigMock = vi . hoisted ( ( ) => vi . fn ( ( ) => ( { } ) ) ) ;
7086const ensureSandboxWorkspaceForSessionMock = vi . hoisted ( ( ) =>
7187 vi . fn < ( ) => Promise < SandboxWorkspaceInfo | null > > ( async ( ) => null ) ,
@@ -1945,16 +1961,28 @@ describe("prepareCliRunContext", () => {
19451961 expect ( dispose ) . not . toHaveBeenCalled ( ) ;
19461962 } ) ;
19471963
1948- it ( "cleans up prepared CLI backend when context-engine resolution fails" , async ( ) => {
1964+ it ( "cleans up prepared CLI backend when context-engine host validation fails" , async ( ) => {
1965+ installTestPluginRegistry ( ) ;
1966+ const engineId = `cli-cleanup-engine-${ Date . now ( ) . toString ( 36 ) } ` ;
19491967 const cleanup = vi . fn ( async ( ) => { } ) ;
19501968 const prepareExecution = vi . fn ( async ( ) => ( { cleanup } ) ) ;
1951- registerContextEngineForOwner (
1952- "legacy" ,
1953- ( ) => {
1954- throw new Error ( "context engine failed" ) ;
1955- } ,
1956- "core" ,
1957- { allowSameOwnerRefresh : true } ,
1969+ registerTestContextEngine (
1970+ engineId ,
1971+ ( ) : ContextEngine => ( {
1972+ info : {
1973+ id : engineId ,
1974+ name : "CLI cleanup engine" ,
1975+ hostRequirements : {
1976+ "agent-run" : {
1977+ requiredCapabilities : [ "assemble-before-prompt" ] ,
1978+ unsupportedMessage : "context engine failed" ,
1979+ } ,
1980+ } ,
1981+ } ,
1982+ ingest : vi . fn ( async ( ) => ( { ingested : true } ) ) ,
1983+ assemble : vi . fn ( async ( { messages } ) => ( { messages, estimatedTokens : 0 } ) ) ,
1984+ compact : vi . fn ( async ( ) => ( { ok : true , compacted : false } ) ) ,
1985+ } ) ,
19581986 ) ;
19591987 setRawCliBackendForPrepareTest ( {
19601988 id : "test-cli" ,
@@ -1972,14 +2000,14 @@ describe("prepareCliRunContext", () => {
19722000 } ,
19732001 } ) ;
19742002
1975- try {
1976- await expect ( fixture . prepare ( { } ) ) . rejects . toThrow ( "context engine failed" ) ;
2003+ await expect (
2004+ fixture . prepare ( {
2005+ config : { plugins : { slots : { contextEngine : engineId } } } ,
2006+ } ) ,
2007+ ) . rejects . toThrow ( "context engine failed" ) ;
19772008
1978- expect ( prepareExecution ) . toHaveBeenCalledOnce ( ) ;
1979- expect ( cleanup ) . toHaveBeenCalledOnce ( ) ;
1980- } finally {
1981- registerLegacyContextEngine ( ) ;
1982- }
2009+ expect ( prepareExecution ) . toHaveBeenCalledOnce ( ) ;
2010+ expect ( cleanup ) . toHaveBeenCalledOnce ( ) ;
19832011 } ) ;
19842012
19852013 it ( "rejects CLI runs for context engines that require pre-prompt assembly" , async ( ) => {
0 commit comments