11import fs from "node:fs/promises" ;
2- import os from "node:os" ;
32import path from "node:path" ;
4- import { afterEach , describe , expect , it } from "vitest" ;
3+ import { describe , expect , it } from "vitest" ;
4+ import { withTempDir } from "../test-helpers/temp-dir.js" ;
55import {
66 type ConfigDocBaselineEntry ,
77 flattenConfigDocBaselineEntries ,
@@ -10,7 +10,6 @@ import {
1010} from "./doc-baseline.js" ;
1111
1212describe ( "config doc baseline integration" , ( ) => {
13- const tempRoots : string [ ] = [ ] ;
1413 let sharedRenderedPromise : Promise <
1514 Awaited < ReturnType < typeof renderConfigDocBaselineArtifacts > >
1615 > | null = null ;
@@ -29,14 +28,6 @@ describe("config doc baseline integration", () => {
2928 return sharedByPathPromise ;
3029 }
3130
32- afterEach ( async ( ) => {
33- await Promise . all (
34- tempRoots . splice ( 0 ) . map ( async ( tempRoot ) => {
35- await fs . rm ( tempRoot , { recursive : true , force : true } ) ;
36- } ) ,
37- ) ;
38- } ) ;
39-
4031 it ( "is deterministic across repeated runs" , async ( ) => {
4132 const { baseline } = await getSharedRendered ( ) ;
4233 const first = await renderConfigDocBaselineArtifacts ( baseline ) ;
@@ -121,36 +112,36 @@ describe("config doc baseline integration", () => {
121112 } ) ;
122113
123114 it ( "supports check mode for stale hash files" , async ( ) => {
124- const tempRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-config-doc-baseline-" ) ) ;
125- tempRoots . push ( tempRoot ) ;
126- const rendered = getSharedRendered ( ) ;
127-
128- const initial = await writeConfigDocBaselineArtifacts ( {
129- repoRoot : tempRoot ,
130- rendered,
131- } ) ;
132- expect ( initial . wrote ) . toBe ( true ) ;
133-
134- const current = await writeConfigDocBaselineArtifacts ( {
135- repoRoot : tempRoot ,
136- check : true ,
137- rendered,
138- } ) ;
139- expect ( current . changed ) . toBe ( false ) ;
140-
141- // Corrupt the hash file to simulate drift
142- await fs . writeFile (
143- path . join ( tempRoot , "docs/.generated/config-baseline.sha256" ) ,
144- "0000000000000000000000000000000000000000000000000000000000000000 config-baseline.json\n" ,
145- "utf8" ,
146- ) ;
147-
148- const stale = await writeConfigDocBaselineArtifacts ( {
149- repoRoot : tempRoot ,
150- check : true ,
151- rendered,
115+ await withTempDir ( { prefix : "openclaw-config-doc-baseline-" } , async ( tempRoot ) => {
116+ const rendered = getSharedRendered ( ) ;
117+
118+ const initial = await writeConfigDocBaselineArtifacts ( {
119+ repoRoot : tempRoot ,
120+ rendered,
121+ } ) ;
122+ expect ( initial . wrote ) . toBe ( true ) ;
123+
124+ const current = await writeConfigDocBaselineArtifacts ( {
125+ repoRoot : tempRoot ,
126+ check : true ,
127+ rendered,
128+ } ) ;
129+ expect ( current . changed ) . toBe ( false ) ;
130+
131+ // Corrupt the hash file to simulate drift
132+ await fs . writeFile (
133+ path . join ( tempRoot , "docs/.generated/config-baseline.sha256" ) ,
134+ "0000000000000000000000000000000000000000000000000000000000000000 config-baseline.json\n" ,
135+ "utf8" ,
136+ ) ;
137+
138+ const stale = await writeConfigDocBaselineArtifacts ( {
139+ repoRoot : tempRoot ,
140+ check : true ,
141+ rendered,
142+ } ) ;
143+ expect ( stale . changed ) . toBe ( true ) ;
144+ expect ( stale . wrote ) . toBe ( false ) ;
152145 } ) ;
153- expect ( stale . changed ) . toBe ( true ) ;
154- expect ( stale . wrote ) . toBe ( false ) ;
155146 } ) ;
156147} ) ;
0 commit comments