@@ -1549,4 +1549,133 @@ describe("config io write", () => {
15491549 expect ( persisted . logging ?. level ) . toBe ( "debug" ) ;
15501550 } ) ;
15511551 } ) ;
1552+
1553+ it ( "preserves user-set meta.lastTouchedVersion when explicitSetPaths includes meta.lastTouchedVersion" , async ( ) => {
1554+ await withSuiteHome ( async ( home ) => {
1555+ const configPath = path . join ( home , ".openclaw" , "openclaw.json" ) ;
1556+ await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } ) ;
1557+ const original = {
1558+ gateway : { mode : "local" } ,
1559+ } satisfies ConfigFileSnapshot [ "config" ] ;
1560+ const originalRaw = `${ JSON . stringify ( original , null , 2 ) } \n` ;
1561+ await fs . writeFile ( configPath , originalRaw , "utf-8" ) ;
1562+ const io = createConfigIO ( {
1563+ env : { VITEST : "true" } as NodeJS . ProcessEnv ,
1564+ homedir : ( ) => home ,
1565+ logger : silentLogger ,
1566+ } ) ;
1567+ const baseSnapshot = {
1568+ path : configPath ,
1569+ exists : true ,
1570+ raw : originalRaw ,
1571+ parsed : original ,
1572+ sourceConfig : original ,
1573+ resolved : original ,
1574+ valid : true ,
1575+ runtimeConfig : original ,
1576+ config : original ,
1577+ issues : [ ] ,
1578+ warnings : [ ] ,
1579+ legacyIssues : [ ] ,
1580+ } satisfies ConfigFileSnapshot ;
1581+
1582+ const userVersion = "2099.12.31" ;
1583+ const next = {
1584+ meta : { lastTouchedVersion : userVersion , lastTouchedAt : "2099-01-01T00:00:00.000Z" } ,
1585+ gateway : { mode : "local" } ,
1586+ } satisfies OpenClawConfig ;
1587+
1588+ await io . writeConfigFile ( next , {
1589+ baseSnapshot,
1590+ explicitSetPaths : [ [ "meta" , "lastTouchedVersion" ] ] ,
1591+ explicitSetValueSource : next ,
1592+ } ) ;
1593+
1594+ const persisted = JSON . parse ( await fs . readFile ( configPath , "utf-8" ) ) as OpenClawConfig ;
1595+ expect ( persisted . meta ?. lastTouchedVersion ) . toBe ( userVersion ) ;
1596+ } ) ;
1597+ } ) ;
1598+
1599+ it ( "preserves user-set meta.lastTouchedAt when explicitSetPaths includes meta.lastTouchedAt" , async ( ) => {
1600+ await withSuiteHome ( async ( home ) => {
1601+ const configPath = path . join ( home , ".openclaw" , "openclaw.json" ) ;
1602+ await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } ) ;
1603+ const original = {
1604+ gateway : { mode : "local" } ,
1605+ } satisfies ConfigFileSnapshot [ "config" ] ;
1606+ const originalRaw = `${ JSON . stringify ( original , null , 2 ) } \n` ;
1607+ await fs . writeFile ( configPath , originalRaw , "utf-8" ) ;
1608+ const io = createConfigIO ( {
1609+ env : { VITEST : "true" } as NodeJS . ProcessEnv ,
1610+ homedir : ( ) => home ,
1611+ logger : silentLogger ,
1612+ } ) ;
1613+ const baseSnapshot = {
1614+ path : configPath ,
1615+ exists : true ,
1616+ raw : originalRaw ,
1617+ parsed : original ,
1618+ sourceConfig : original ,
1619+ resolved : original ,
1620+ valid : true ,
1621+ runtimeConfig : original ,
1622+ config : original ,
1623+ issues : [ ] ,
1624+ warnings : [ ] ,
1625+ legacyIssues : [ ] ,
1626+ } satisfies ConfigFileSnapshot ;
1627+
1628+ const userAt = "2099-01-01T00:00:00.000Z" ;
1629+ const next = {
1630+ meta : { lastTouchedVersion : "2099.12.31" , lastTouchedAt : userAt } ,
1631+ gateway : { mode : "local" } ,
1632+ } satisfies OpenClawConfig ;
1633+
1634+ await io . writeConfigFile ( next , {
1635+ baseSnapshot,
1636+ explicitSetPaths : [ [ "meta" , "lastTouchedAt" ] ] ,
1637+ explicitSetValueSource : next ,
1638+ } ) ;
1639+
1640+ const persisted = JSON . parse ( await fs . readFile ( configPath , "utf-8" ) ) as OpenClawConfig ;
1641+ expect ( persisted . meta ?. lastTouchedAt ) . toBe ( userAt ) ;
1642+ } ) ;
1643+ } ) ;
1644+
1645+ it ( "still stamps meta fields on writes without explicitSetPaths" , async ( ) => {
1646+ await withSuiteHome ( async ( home ) => {
1647+ const configPath = path . join ( home , ".openclaw" , "openclaw.json" ) ;
1648+ await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } ) ;
1649+ const original = {
1650+ gateway : { mode : "local" } ,
1651+ } satisfies ConfigFileSnapshot [ "config" ] ;
1652+ const originalRaw = `${ JSON . stringify ( original , null , 2 ) } \n` ;
1653+ await fs . writeFile ( configPath , originalRaw , "utf-8" ) ;
1654+ const io = createConfigIO ( {
1655+ env : { VITEST : "true" } as NodeJS . ProcessEnv ,
1656+ homedir : ( ) => home ,
1657+ logger : silentLogger ,
1658+ } ) ;
1659+ const baseSnapshot = {
1660+ path : configPath ,
1661+ exists : true ,
1662+ raw : originalRaw ,
1663+ parsed : original ,
1664+ sourceConfig : original ,
1665+ resolved : original ,
1666+ valid : true ,
1667+ runtimeConfig : original ,
1668+ config : original ,
1669+ issues : [ ] ,
1670+ warnings : [ ] ,
1671+ legacyIssues : [ ] ,
1672+ } satisfies ConfigFileSnapshot ;
1673+
1674+ await io . writeConfigFile ( { gateway : { mode : "local" } } , { baseSnapshot } ) ;
1675+
1676+ const persisted = JSON . parse ( await fs . readFile ( configPath , "utf-8" ) ) as OpenClawConfig ;
1677+ expect ( typeof persisted . meta ?. lastTouchedVersion ) . toBe ( "string" ) ;
1678+ expect ( typeof persisted . meta ?. lastTouchedAt ) . toBe ( "string" ) ;
1679+ } ) ;
1680+ } ) ;
15521681} ) ;
0 commit comments