@@ -11,13 +11,16 @@ import {
1111} from "node:fs" ;
1212import { tmpdir } from "node:os" ;
1313import { delimiter , dirname , join } from "node:path" ;
14+ import { gte as semverGte , valid as validSemver } from "semver" ;
1415import { describe , expect , it } from "vitest" ;
1516import { LOCAL_BUILD_METADATA_DIST_PATHS } from "../../scripts/lib/local-build-metadata-paths.mjs" ;
1617import { PACKAGE_INSTALL_GUARD_RELATIVE_PATH } from "../../scripts/lib/package-dist-inventory.ts" ;
1718import { WORKSPACE_TEMPLATE_PACK_PATHS } from "../../scripts/lib/workspace-bootstrap-smoke.mjs" ;
1819
1920const CHECK_SCRIPT = "scripts/check-openclaw-package-tarball.mjs" ;
2021const NODE_DEFAULT_SPAWN_MAX_BUFFER_BYTES = 1024 * 1024 ;
22+ const CODE_MODE_WORKER_PATH = "dist/agents/code-mode.worker.js" ;
23+ const FIRST_CODE_MODE_WORKER_VERSION = "2026.5.14-beta.2" ;
2124const FLAT_PLUGIN_SDK_DECLARATION = "dist/plugin-sdk/provider-entry.d.ts" ;
2225const DEEP_PLUGIN_SDK_DECLARATION = "dist/plugin-sdk/src/plugin-sdk/provider-entry.d.ts" ;
2326const AI_RUNTIME_PACKAGE_JSON = JSON . stringify ( {
@@ -55,6 +58,8 @@ function withTarball(
5558 testBody : ( tarball : string ) => void ,
5659 version = "2026.7.2" ,
5760 options : {
61+ includeCodeModeWorker ?: boolean ;
62+ includeCodeModeWorkerInInventory ?: boolean ;
5863 includeControlUi ?: boolean ;
5964 includeInstallGuard ?: boolean ;
6065 includeShrinkwrap ?: boolean ;
@@ -64,6 +69,15 @@ function withTarball(
6469) {
6570 const root = mkdtempSync ( join ( tmpdir ( ) , "openclaw-package-tarball-test-" ) ) ;
6671 try {
72+ const validVersion = validSemver ( version ) ;
73+ const includeCodeModeWorker =
74+ options . includeCodeModeWorker ??
75+ ( validVersion !== null && semverGte ( validVersion , FIRST_CODE_MODE_WORKER_VERSION ) ) ;
76+ const includeCodeModeWorkerInInventory =
77+ options . includeCodeModeWorkerInInventory ?? includeCodeModeWorker ;
78+ const packageInventory = includeCodeModeWorkerInInventory
79+ ? [ ...new Set ( [ ...inventory , CODE_MODE_WORKER_PATH ] ) ]
80+ : inventory ;
6781 const packageRoot = join ( root , "package" ) ;
6882 mkdirSync ( join ( packageRoot , "dist" ) , { recursive : true } ) ;
6983 writeFileSync (
@@ -72,7 +86,7 @@ function withTarball(
7286 ) ;
7387 writeFileSync (
7488 join ( packageRoot , "dist" , "postinstall-inventory.json" ) ,
75- JSON . stringify ( inventory ) ,
89+ JSON . stringify ( packageInventory ) ,
7690 ) ;
7791 const workspaceTemplates =
7892 options . includeWorkspaceTemplates === false
@@ -113,6 +127,7 @@ function withTarball(
113127 ...controlUiFiles ,
114128 ...installGuardFile ,
115129 ...shrinkwrapFile ,
130+ ...( includeCodeModeWorker ? { [ CODE_MODE_WORKER_PATH ] : "export {};\n" } : { } ) ,
116131 ...files ,
117132 } ;
118133 for ( const [ relativePath , body ] of Object . entries ( tarFiles ) ) {
@@ -349,6 +364,64 @@ describe("check-openclaw-package-tarball", () => {
349364 ) ;
350365 } ) ;
351366
367+ it ( "accepts historical packages published before the Code Mode worker existed" , ( ) => {
368+ withTarball (
369+ [ "dist/index.js" ] ,
370+ { "dist/index.js" : "export {};\n" } ,
371+ ( tarball ) => {
372+ const result = spawnSync ( "node" , [ CHECK_SCRIPT , tarball ] , { encoding : "utf8" } ) ;
373+
374+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
375+ expect ( result . stdout ) . toContain ( "OpenClaw package tarball integrity passed." ) ;
376+ } ,
377+ "2026.5.14-beta.1" ,
378+ ) ;
379+ } ) ;
380+
381+ it ( "rejects Code Mode packages that omit the dynamically loaded worker" , ( ) => {
382+ withTarball (
383+ [ "dist/index.js" ] ,
384+ { "dist/index.js" : "export {};\n" } ,
385+ ( tarball ) => {
386+ const result = spawnSync ( "node" , [ CHECK_SCRIPT , tarball ] , { encoding : "utf8" } ) ;
387+
388+ expect ( result . status ) . not . toBe ( 0 ) ;
389+ expect ( result . stderr ) . toContain ( `missing required tar entry ${ CODE_MODE_WORKER_PATH } ` ) ;
390+ } ,
391+ FIRST_CODE_MODE_WORKER_VERSION ,
392+ { includeCodeModeWorker : false } ,
393+ ) ;
394+ } ) ;
395+
396+ it ( "rejects Code Mode workers that postinstall would remove" , ( ) => {
397+ withTarball (
398+ [ "dist/index.js" ] ,
399+ { "dist/index.js" : "export {};\n" } ,
400+ ( tarball ) => {
401+ const result = spawnSync ( "node" , [ CHECK_SCRIPT , tarball ] , { encoding : "utf8" } ) ;
402+
403+ expect ( result . status ) . not . toBe ( 0 ) ;
404+ expect ( result . stderr ) . toContain ( `postinstall inventory omits ${ CODE_MODE_WORKER_PATH } ` ) ;
405+ } ,
406+ FIRST_CODE_MODE_WORKER_VERSION ,
407+ { includeCodeModeWorkerInInventory : false } ,
408+ ) ;
409+ } ) ;
410+
411+ it ( "accepts Code Mode packages whose worker survives postinstall" , ( ) => {
412+ withTarball (
413+ [ "dist/index.js" ] ,
414+ { "dist/index.js" : "export {};\n" } ,
415+ ( tarball ) => {
416+ const result = spawnSync ( "node" , [ CHECK_SCRIPT , tarball ] , { encoding : "utf8" } ) ;
417+
418+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
419+ expect ( result . stdout ) . toContain ( "OpenClaw package tarball integrity passed." ) ;
420+ } ,
421+ FIRST_CODE_MODE_WORKER_VERSION ,
422+ ) ;
423+ } ) ;
424+
352425 it ( "rejects dist files that import missing relative chunks" , ( ) => {
353426 withTarball (
354427 [ "dist/cli/run-main.js" ] ,
0 commit comments