11import fs from "node:fs" ;
2- import { createRequire } from "node:module" ;
32import os from "node:os" ;
43import path from "node:path" ;
54import { pathToFileURL } from "node:url" ;
65import { afterEach , expect , it } from "vitest" ;
76
87const tempDirs : string [ ] = [ ] ;
98const REPO_ROOT = process . cwd ( ) ;
10- const require = createRequire ( import . meta. url ) ;
11- const JITI_ENTRY_PATH = require . resolve ( "jiti" ) ;
129const matrixWrapperGlobal = globalThis as typeof globalThis & {
1310 __openclawMatrixWrapperJitiOptions ?: unknown ;
1411} ;
@@ -40,14 +37,6 @@ function writeFixtureFile(fixtureRoot: string, relativePath: string, value: stri
4037 fs . writeFileSync ( fullPath , value , "utf8" ) ;
4138}
4239
43- function writeJitiFixture ( fixtureRoot : string ) {
44- writeFixtureFile (
45- fixtureRoot ,
46- "node_modules/jiti/index.js" ,
47- `module.exports = require(${ JSON . stringify ( JITI_ENTRY_PATH ) } );\n` ,
48- ) ;
49- }
50-
5140function writeCapturingJitiFixture ( fixtureRoot : string ) {
5241 writeFixtureFile (
5342 fixtureRoot ,
@@ -143,15 +132,19 @@ function writeTrustedOpenClawBinFixture(
143132 writeFixtureFile ( fixtureRoot , "dist/plugin-sdk/group-access.js" , "export {};\n" ) ;
144133}
145134
146- function writeSourceRuntimeWrapperFixture ( fixtureRoot : string ) {
135+ function writeSourceRuntimeWrapperFixture (
136+ fixtureRoot : string ,
137+ options : { runtimeExtension ?: ".js" | ".ts" } = { } ,
138+ ) {
139+ const runtimeExtension = options . runtimeExtension ?? ".js" ;
147140 writeFixtureFile (
148141 fixtureRoot ,
149142 "extensions/matrix/src/plugin-entry.runtime.js" ,
150143 MATRIX_RUNTIME_WRAPPER_SOURCE ,
151144 ) ;
152145 writeFixtureFile (
153146 fixtureRoot ,
154- " extensions/matrix/plugin-entry.handlers.runtime.js" ,
147+ ` extensions/matrix/plugin-entry.handlers.runtime${ runtimeExtension } ` ,
155148 PACKAGED_RUNTIME_STUB ,
156149 ) ;
157150}
@@ -174,7 +167,7 @@ function writeCapturingSourceRuntimeWrapperFixture(fixtureRoot: string) {
174167 delete matrixWrapperGlobal . __openclawMatrixWrapperJitiOptions ;
175168 writeOpenClawAliasFixture ( fixtureRoot ) ;
176169 writeCapturingJitiFixture ( fixtureRoot ) ;
177- writeSourceRuntimeWrapperFixture ( fixtureRoot ) ;
170+ writeSourceRuntimeWrapperFixture ( fixtureRoot , { runtimeExtension : ".ts" } ) ;
178171}
179172
180173function expectSourcePluginSdkAliases ( fixtureRoot : string ) {
@@ -198,7 +191,6 @@ it("loads the source-checkout runtime wrapper through native ESM import", async
198191 const fixtureRoot = makeFixtureRoot ( ".tmp-matrix-source-runtime-" ) ;
199192
200193 writeOpenClawPackageFixture ( fixtureRoot ) ;
201- writeJitiFixture ( fixtureRoot ) ;
202194 writeSourceRuntimeWrapperFixture ( fixtureRoot ) ;
203195
204196 expectRuntimeWrapperExports (
@@ -210,7 +202,6 @@ it("loads the packaged runtime wrapper without recursing through the stable root
210202 const fixtureRoot = makeFixtureRoot ( ".tmp-matrix-runtime-" ) ;
211203
212204 writeOpenClawPackageFixture ( fixtureRoot ) ;
213- writeJitiFixture ( fixtureRoot ) ;
214205 writeFixtureFile (
215206 fixtureRoot ,
216207 "dist/plugin-entry.runtime-C88YIa_v.js" ,
@@ -267,7 +258,7 @@ it("keeps wrapper plugin-sdk aliases deterministic and ignores unsafe subpaths",
267258 writeFixtureFile ( fixtureRoot , "src/plugin-sdk/alpha.ts" , "export {};\n" ) ;
268259 writeFixtureFile ( fixtureRoot , "src/plugin-sdk/zeta.ts" , "export {};\n" ) ;
269260 writeCapturingJitiFixture ( fixtureRoot ) ;
270- writeSourceRuntimeWrapperFixture ( fixtureRoot ) ;
261+ writeSourceRuntimeWrapperFixture ( fixtureRoot , { runtimeExtension : ".ts" } ) ;
271262 await importFixtureModule ( fixtureRoot , "extensions/matrix/src/plugin-entry.runtime.js" ) ;
272263
273264 const aliasKeys = Object . keys (
@@ -317,7 +308,7 @@ it("ignores nearby untrusted openclaw package stubs when resolving the wrapper r
317308 ) ;
318309 writeFixtureFile ( fixtureRoot , "extensions/src/plugin-sdk/group-access.ts" , "export {};\n" ) ;
319310 writeCapturingJitiFixture ( fixtureRoot ) ;
320- writeSourceRuntimeWrapperFixture ( fixtureRoot ) ;
311+ writeSourceRuntimeWrapperFixture ( fixtureRoot , { runtimeExtension : ".ts" } ) ;
321312 await importFixtureModule ( fixtureRoot , "extensions/matrix/src/plugin-entry.runtime.js" ) ;
322313
323314 expectSourcePluginSdkAliases ( fixtureRoot ) ;
@@ -329,7 +320,7 @@ it("treats string bin hints case-insensitively when trusting wrapper package roo
329320 delete matrixWrapperGlobal . __openclawMatrixWrapperJitiOptions ;
330321 writeTrustedOpenClawBinFixture ( fixtureRoot , "OpenClaw.MJS" ) ;
331322 writeCapturingJitiFixture ( fixtureRoot ) ;
332- writeSourceRuntimeWrapperFixture ( fixtureRoot ) ;
323+ writeSourceRuntimeWrapperFixture ( fixtureRoot , { runtimeExtension : ".ts" } ) ;
333324 await importFixtureModule ( fixtureRoot , "extensions/matrix/src/plugin-entry.runtime.js" ) ;
334325
335326 expect ( matrixWrapperGlobal . __openclawMatrixWrapperJitiOptions ) . toMatchObject ( {
0 commit comments