1+ import { mkdtemp } from "node:fs/promises" ;
2+ import { tmpdir } from "node:os" ;
3+ import { join } from "node:path" ;
14import { describe , expect , it , vi } from "vitest" ;
25import type { OpenClawConfig } from "../config/types.openclaw.js" ;
36import { ClawCronUpdateError } from "./cron-update.js" ;
4- import type { PersistedClawInstall } from "./provenance.js" ;
7+ import {
8+ persistClawInstallRecord ,
9+ readClawInstallRecord ,
10+ type PersistedClawInstall ,
11+ } from "./provenance.js" ;
512import type { ClawAddPlan , ClawManifest , ClawSourceIdentity } from "./types.js" ;
613import { applyClawUpdatePlan } from "./update-apply.js" ;
714import type { ClawUpdatePlan } from "./update-plan.js" ;
@@ -259,6 +266,18 @@ describe("applyClawUpdatePlan", () => {
259266 } ) ;
260267
261268 it ( "preserves cron prerequisites when the gateway mutation outcome is uncertain" , async ( ) => {
269+ const root = await mkdtemp ( join ( tmpdir ( ) , "openclaw-claw-update-apply-" ) ) ;
270+ const env = { OPENCLAW_STATE_DIR : join ( root , "state" ) } ;
271+ const currentAddPlan : ClawAddPlan = {
272+ ...addPlan ,
273+ claw : install . claw ,
274+ planIntegrity : install . planIntegrity ,
275+ agent : {
276+ ...addPlan . agent ,
277+ config : { id : "worker" , name : "Worker" , workspace : addPlan . agent . workspace } ,
278+ } ,
279+ } ;
280+ const currentRecord = persistClawInstallRecord ( currentAddPlan , { env, nowMs : 1 } ) ;
262281 const updatePlan = plan ( [
263282 {
264283 kind : "agent" ,
@@ -281,18 +300,17 @@ describe("applyClawUpdatePlan", () => {
281300 const workspaceRollback = vi . fn ( async ( ) => undefined ) ;
282301 const mcpRollback = vi . fn ( async ( ) => undefined ) ;
283302 const packageRollback = vi . fn ( async ( ) => undefined ) ;
284- const persistInstall = vi . fn ( ( ) => ( { ...install , claw : source } ) ) ;
285303
286304 await expect (
287305 applyClawUpdatePlan (
288306 updatePlan ,
289307 { targetManifest : manifest , targetSource : source } ,
290308 {
291309 config,
310+ env,
292311 ...consent ( updatePlan ) ,
293312 rebuildPlan : vi . fn ( async ( ) => updatePlan ) ,
294313 buildAddPlan : vi . fn ( async ( ) => addPlan ) ,
295- readInstall : vi . fn ( ( ) => install ) ,
296314 applyWorkspace : vi . fn ( async ( ) => ( {
297315 appliedPaths : [ ] ,
298316 rollback : workspaceRollback ,
@@ -308,16 +326,21 @@ describe("applyClawUpdatePlan", () => {
308326 applyCron : vi . fn ( async ( ) => {
309327 throw new ClawCronUpdateError ( "cron transport closed" , true ) ;
310328 } ) ,
311- persistInstall,
312329 } ,
313330 ) ,
314331 ) . rejects . toMatchObject ( { code : "update_partial" } ) ;
315332
333+ const partialRecord = readClawInstallRecord ( "worker" , { env } ) ;
316334 expect ( config . agents ?. list ) . toEqual ( [ addPlan . agent . config ] ) ;
335+ expect ( partialRecord ) . toMatchObject ( {
336+ claw : { version : "2.0.0" , integrity : "sha256:target" } ,
337+ planIntegrity : addPlan . planIntegrity ,
338+ status : "partial" ,
339+ } ) ;
340+ expect ( partialRecord ?. agentConfigDigest ) . not . toBe ( currentRecord . agentConfigDigest ) ;
317341 expect ( packageRollback ) . not . toHaveBeenCalled ( ) ;
318342 expect ( mcpRollback ) . not . toHaveBeenCalled ( ) ;
319343 expect ( workspaceRollback ) . not . toHaveBeenCalled ( ) ;
320- expect ( persistInstall ) . not . toHaveBeenCalled ( ) ;
321344 } ) ;
322345
323346 it ( "stops before agent mutation when a package update fails" , async ( ) => {
0 commit comments