@@ -12,10 +12,10 @@ import { afterAll } from "vitest";
1212import { createTempDirTracker } from "../helpers/temp-dir.js" ;
1313
1414const templateDirs = createTempDirTracker ( ) ;
15- let performanceTemplate : string | undefined ;
15+ const performanceTemplates = new Map < "base" | "publish" , string > ( ) ;
1616afterAll ( ( ) => {
1717 templateDirs . cleanup ( ) ;
18- performanceTemplate = undefined ;
18+ performanceTemplates . clear ( ) ;
1919} ) ;
2020
2121export type PerformanceFixtureOptions = {
@@ -65,9 +65,11 @@ export function preparePerformanceFixture(root: string, options: PerformanceFixt
6565 run ( cwd , "commit" , "-m" , "fixture report" ) ;
6666 } ;
6767 const reuseDefault = ! options . baseline && ! options . duplicate ;
68+ const templateKind = options . mode === "publish" ? "publish" : "base" ;
69+ const template = reuseDefault ? performanceTemplates . get ( templateKind ) : undefined ;
6870 const copyOptions = { recursive : true , mode : fsConstants . COPYFILE_FICLONE } ;
69- if ( reuseDefault && performanceTemplate ) {
70- cpSync ( performanceTemplate , workspace , copyOptions ) ;
71+ if ( template ) {
72+ cpSync ( template , workspace , copyOptions ) ;
7173 } else {
7274 mkdirSync ( temp , { recursive : true } ) ;
7375 mkdirSync ( seed ) ;
@@ -87,26 +89,29 @@ export function preparePerformanceFixture(root: string, options: PerformanceFixt
8789 write ( path . join ( workspace , "src/config/zod-schema.agent-defaults.ts" ) , " mediaModels: z\n" ) ;
8890 run ( workspace , "add" , "src" ) ;
8991 run ( workspace , "commit" , "-m" , "fixture target" ) ;
92+ mkdirSync ( reports ) ;
93+ if ( options . mode === "publish" ) {
94+ run ( reports , "init" , "--initial-branch=main" ) ;
95+ run ( reports , "remote" , "add" , "origin" , "https://github.com/openclaw/clawgrit-reports.git" ) ;
96+ // Keep FETCH_HEAD's source description valid when the snapshot is copied.
97+ run ( reports , "fetch" , "--depth=1" , path . relative ( reports , remote ) , "main" ) ;
98+ run ( reports , "checkout" , "-B" , "main" , "FETCH_HEAD" ) ;
99+ run ( reports , "config" , "core.hooksPath" , "/dev/null" ) ;
100+ commitReport ( reports , dest ) ;
101+ write ( path . join ( reports , ".git/preexisting.lock" ) , "not invocation-owned\n" ) ;
102+ }
90103 if ( reuseDefault ) {
91104 // Snapshot complete repositories before any scenario mutation. Copies own
92105 // their refs, index and objects; no live process or absolute remote is shared.
93- const template = templateDirs . make ( " openclaw-performance-template-" ) ;
106+ const template = templateDirs . make ( ` openclaw-performance-${ templateKind } - template-` ) ;
94107 cpSync ( workspace , template , copyOptions ) ;
95- performanceTemplate = template ;
108+ performanceTemplates . set ( templateKind , template ) ;
96109 }
97110 }
98111 const target = run ( workspace , "rev-parse" , "HEAD" ) ;
99- mkdirSync ( reports ) ;
100112 let reportCommit = "a" . repeat ( 40 ) ;
101113 if ( options . mode === "publish" ) {
102- run ( reports , "init" , "--initial-branch=main" ) ;
103- run ( reports , "remote" , "add" , "origin" , "https://github.com/openclaw/clawgrit-reports.git" ) ;
104- run ( reports , "fetch" , "--depth=1" , remote , "main" ) ;
105- run ( reports , "checkout" , "-B" , "main" , "FETCH_HEAD" ) ;
106- run ( reports , "config" , "core.hooksPath" , "/dev/null" ) ;
107- commitReport ( reports , dest ) ;
108114 reportCommit = run ( reports , "rev-parse" , "HEAD" ) ;
109- write ( path . join ( reports , ".git/preexisting.lock" ) , "not invocation-owned\n" ) ;
110115 if ( options . race ) {
111116 commitReport ( seed , "openclaw-performance/main/200-1/mock-provider" ) ;
112117 run ( seed , "push" , remote , "HEAD:main" ) ;
0 commit comments