@@ -14,6 +14,7 @@ import type { PluginInstallRecord } from "../config/types.plugins.js";
1414import { GATEWAY_SERVICE_RUNTIME_PID_ENV } from "../daemon/constants.js" ;
1515import type { ClawHubRiskAcknowledgementRequest } from "../infra/clawhub-install-trust.js" ;
1616import { isBetaTag } from "../infra/update-channels.js" ;
17+ import { applyDevUpdateTargetEnv } from "../infra/update-dev-target.js" ;
1718import {
1819 createDeferredConfiguredPluginRepairDoctorResult ,
1920 UPDATE_POST_INSTALL_DOCTOR_ADVISORY_EXIT_CODE ,
@@ -7449,6 +7450,87 @@ describe("update-cli", () => {
74497450 } ) ;
74507451 } ) ;
74517452
7453+ it . each ( [
7454+ {
7455+ name : "ref-only as detached" ,
7456+ env : { OPENCLAW_UPDATE_DEV_TARGET_REF : "frozen-sha" } ,
7457+ expected : { mode : "detached" , ref : "frozen-sha" } ,
7458+ } ,
7459+ {
7460+ name : "versioned tracked target" ,
7461+ env : applyDevUpdateTargetEnv (
7462+ { } ,
7463+ { mode : "tracked" , upstreamRef : "origin/main" , upstreamSha : "frozen-sha" } ,
7464+ ) ,
7465+ expected : { mode : "tracked" , upstreamRef : "origin/main" , upstreamSha : "frozen-sha" } ,
7466+ } ,
7467+ ] ) ( "maps the internal dev target environment $name" , async ( { env, expected } ) => {
7468+ await withEnvAsync ( env , async ( ) => {
7469+ await updateCommand ( { channel : "dev" , yes : true , restart : false } ) ;
7470+ } ) ;
7471+
7472+ expect ( vi . mocked ( runGatewayUpdate ) . mock . calls [ 0 ] ?. [ 0 ] ) . toEqual (
7473+ expect . objectContaining ( { devTarget : expected } ) ,
7474+ ) ;
7475+ } ) ;
7476+
7477+ it . each ( [
7478+ [ "malformed" , "openclaw-dev-target:v1:not+base64url" ] ,
7479+ [ "unknown version" , "openclaw-dev-target:v2:hostile-ref" ] ,
7480+ [ "unknown namespace" , "other-dev-target:v1:hostile-ref" ] ,
7481+ ] ) ( "rejects a %s tracked dev target before update side effects" , async ( _name , value ) => {
7482+ await withEnvAsync ( { OPENCLAW_UPDATE_DEV_TARGET_REF : value } , async ( ) => {
7483+ await updateCommand ( { channel : "dev" , yes : true , restart : false } ) ;
7484+ } ) ;
7485+
7486+ expect ( defaultRuntime . error ) . toHaveBeenCalledWith (
7487+ "Invalid internal OPENCLAW_UPDATE_DEV_TARGET_REF contract; expected a plain Git ref or a supported tracked-target encoding." ,
7488+ ) ;
7489+ expect ( defaultRuntime . error ) . toHaveBeenCalledTimes ( 1 ) ;
7490+ expect ( defaultRuntime . exit ) . toHaveBeenCalledWith ( 1 ) ;
7491+ expectNoSideEffects (
7492+ cleanupStaleManagedServiceUpdateHandoffs ,
7493+ runGatewayUpdate ,
7494+ launchdUpdateCleanupMocks . disableCurrentOpenClawUpdateLaunchdJob ,
7495+ ) ;
7496+ } ) ;
7497+
7498+ it ( "rejects a malformed inferred dev target before running the update" , async ( ) => {
7499+ await withEnvAsync (
7500+ { OPENCLAW_UPDATE_DEV_TARGET_REF : "openclaw-dev-target:v1:not+base64url" } ,
7501+ async ( ) => {
7502+ await updateCommand ( { yes : true , restart : false } ) ;
7503+ } ,
7504+ ) ;
7505+
7506+ expect ( defaultRuntime . error ) . toHaveBeenCalledWith (
7507+ "Invalid internal OPENCLAW_UPDATE_DEV_TARGET_REF contract; expected a plain Git ref or a supported tracked-target encoding." ,
7508+ ) ;
7509+ expect ( defaultRuntime . error ) . toHaveBeenCalledTimes ( 1 ) ;
7510+ expect ( defaultRuntime . exit ) . toHaveBeenCalledWith ( 1 ) ;
7511+ expect ( runGatewayUpdate ) . not . toHaveBeenCalled ( ) ;
7512+ expect ( launchdUpdateCleanupMocks . disableCurrentOpenClawUpdateLaunchdJob ) . not . toHaveBeenCalled ( ) ;
7513+ } ) ;
7514+
7515+ it ( "ignores a malformed dev target for a stable package update" , async ( ) => {
7516+ mockPackageInstallStatus ( createCaseDir ( "openclaw-stable-update" ) ) ;
7517+ mockCurrentProcessFreshDoctor ( ) ;
7518+
7519+ await withEnvAsync (
7520+ { OPENCLAW_UPDATE_DEV_TARGET_REF : "openclaw-dev-target:v1:not+base64url" } ,
7521+ async ( ) => {
7522+ await updateCommand ( { channel : "stable" , yes : true , restart : false } ) ;
7523+ } ,
7524+ ) ;
7525+
7526+ expect ( defaultRuntime . error ) . not . toHaveBeenCalledWith (
7527+ expect . stringContaining ( "OPENCLAW_UPDATE_DEV_TARGET_REF" ) ,
7528+ ) ;
7529+ expect ( defaultRuntime . exit ) . not . toHaveBeenCalledWith ( 1 ) ;
7530+ expect ( packageInstallCommandCall ( ) ) . toBeDefined ( ) ;
7531+ expect ( runGatewayUpdate ) . not . toHaveBeenCalled ( ) ;
7532+ } ) ;
7533+
74527534 it ( "uses ~/openclaw as the default dev checkout directory" , async ( ) => {
74537535 const homedirSpy = vi . spyOn ( os , "homedir" ) . mockReturnValue ( "/tmp/oc-home" ) ;
74547536 try {
0 commit comments