@@ -32,6 +32,18 @@ const PACKAGE_NAME = "@openclaw/discord";
3232const TARBALL = "openclaw-discord-2026.8.1-beta.1.tgz" ;
3333const SCRIPT = path . resolve ( "scripts/prepublish-plugin-registry-artifact.mjs" ) ;
3434const tempDirs : string [ ] = [ ] ;
35+ const packageTarballs = new Map < string , Buffer > ( ) ;
36+ const fixtureCommitArgs = [
37+ "-c" ,
38+ 39+ "-c" ,
40+ "user.name=Release Test" ,
41+ "-c" ,
42+ "commit.gpgsign=false" ,
43+ "commit" ,
44+ "-m" ,
45+ "test: seed release source" ,
46+ ] ;
3547
3648afterEach ( ( ) => {
3749 vi . restoreAllMocks ( ) ;
@@ -44,19 +56,30 @@ function sha256(file: string): string {
4456 return createHash ( "sha256" ) . update ( readFileSync ( file ) ) . digest ( "hex" ) ;
4557}
4658
59+ function writeFixtureTarball ( root : string , tarballPath : string , name : string ) {
60+ const cached = packageTarballs . get ( name ) ;
61+ if ( cached ) {
62+ writeFileSync ( tarballPath , cached ) ;
63+ return ;
64+ }
65+ const packageRoot = path . join ( root , "package" ) ;
66+ mkdirSync ( packageRoot , { recursive : true } ) ;
67+ writeFileSync (
68+ path . join ( packageRoot , "package.json" ) ,
69+ `${ JSON . stringify ( { name, version : VERSION } ) } \n` ,
70+ ) ;
71+ execFileSync ( "tar" , [ "-czf" , tarballPath , "-C" , root , "package" ] ) ;
72+ // Each test mutates its own file; only original archive bytes survive cleanup.
73+ packageTarballs . set ( name , readFileSync ( tarballPath ) ) ;
74+ }
75+
4776function fixture ( packageName = PACKAGE_NAME ) {
4877 const root = mkdtempSync ( path . join ( tmpdir ( ) , "openclaw-prepublish-plugin-registry-" ) ) ;
4978 tempDirs . push ( root ) ;
50- const packageRoot = path . join ( root , "package" ) ;
5179 const artifactDir = path . join ( root , "artifact" ) ;
52- mkdirSync ( packageRoot ) ;
5380 mkdirSync ( artifactDir ) ;
54- writeFileSync (
55- path . join ( packageRoot , "package.json" ) ,
56- `${ JSON . stringify ( { name : packageName , version : VERSION } ) } \n` ,
57- ) ;
5881 const tarballPath = path . join ( artifactDir , TARBALL ) ;
59- execFileSync ( "tar" , [ "-czf" , tarballPath , "-C" , root , "package" ] ) ;
82+ writeFixtureTarball ( root , tarballPath , packageName ) ;
6083 const manifestPath = path . join ( artifactDir , PREPUBLISH_PLUGIN_REGISTRY_MANIFEST ) ;
6184 const manifest = {
6285 schema : "openclaw.prepublish-plugin-registry/v1" ,
@@ -102,14 +125,8 @@ function addCompanionPackage(paths: ReturnType<typeof fixture>) {
102125 const name = "@openclaw/feishu" ;
103126 const tarball = "openclaw-feishu-2026.8.1-beta.1.tgz" ;
104127 const archiveRoot = path . join ( path . dirname ( paths . artifactDir ) , "feishu-package" ) ;
105- const packageRoot = path . join ( archiveRoot , "package" ) ;
106- mkdirSync ( packageRoot , { recursive : true } ) ;
107- writeFileSync (
108- path . join ( packageRoot , "package.json" ) ,
109- `${ JSON . stringify ( { name, version : VERSION } ) } \n` ,
110- ) ;
111128 const tarballPath = path . join ( paths . artifactDir , tarball ) ;
112- execFileSync ( "tar" , [ "-czf" , tarballPath , "-C" , archiveRoot , "package" ] ) ;
129+ writeFixtureTarball ( archiveRoot , tarballPath , name ) ;
113130 paths . manifest . packages . push ( {
114131 name,
115132 version : VERSION ,
@@ -158,13 +175,8 @@ console.log("package manifest stdout");
158175` ,
159176 ) ;
160177 execFileSync ( "git" , [ "init" ] , { cwd : repoRoot } ) ;
161- execFileSync ( "git" , [ "config" , "user.email" , "[email protected] " ] , { 162- cwd : repoRoot ,
163- } ) ;
164- execFileSync ( "git" , [ "config" , "user.name" , "Release Test" ] , { cwd : repoRoot } ) ;
165- execFileSync ( "git" , [ "config" , "commit.gpgsign" , "false" ] , { cwd : repoRoot } ) ;
166178 execFileSync ( "git" , [ "add" , "." ] , { cwd : repoRoot } ) ;
167- execFileSync ( "git" , [ "commit" , "-m" , "test: seed release source" ] , { cwd : repoRoot } ) ;
179+ execFileSync ( "git" , fixtureCommitArgs , { cwd : repoRoot } ) ;
168180 const sourceSha = execFileSync ( "git" , [ "rev-parse" , "HEAD" ] , {
169181 cwd : repoRoot ,
170182 encoding : "utf8" ,
@@ -348,13 +360,8 @@ describe("prepublish plugin registry artifact", () => {
348360 `${ JSON . stringify ( { name : "openclaw" , version : VERSION } ) } \n` ,
349361 ) ;
350362 execFileSync ( "git" , [ "init" ] , { cwd : repoRoot } ) ;
351- execFileSync ( "git" , [ "config" , "user.email" , "[email protected] " ] , { 352- cwd : repoRoot ,
353- } ) ;
354- execFileSync ( "git" , [ "config" , "user.name" , "Release Test" ] , { cwd : repoRoot } ) ;
355- execFileSync ( "git" , [ "config" , "commit.gpgsign" , "false" ] , { cwd : repoRoot } ) ;
356363 execFileSync ( "git" , [ "add" , "package.json" ] , { cwd : repoRoot } ) ;
357- execFileSync ( "git" , [ "commit" , "-m" , "test: seed release source" ] , { cwd : repoRoot } ) ;
364+ execFileSync ( "git" , fixtureCommitArgs , { cwd : repoRoot } ) ;
358365 const sourceSha = execFileSync ( "git" , [ "rev-parse" , "HEAD" ] , {
359366 cwd : repoRoot ,
360367 encoding : "utf8" ,
0 commit comments