@@ -240,6 +240,14 @@ function installPrCliFixture(repoDir: string) {
240240 return { binDir, cli } ;
241241}
242242
243+ function installRequiredPrCommandStubs ( binDir : string ) {
244+ for ( const command of [ "gh" , "jq" , "pnpm" , "rg" ] ) {
245+ const stub = join ( binDir , command ) ;
246+ writeFileSync ( stub , "#!/bin/sh\nexit 0\n" ) ;
247+ chmodSync ( stub , 0o755 ) ;
248+ }
249+ }
250+
243251interface SupervisedFixtureOptions {
244252 accelerateTimeouts ?: boolean ;
245253 cwd ?: string ;
@@ -884,11 +892,7 @@ describePosix("scripts/pr per-PR operation lock", () => {
884892 const { binDir, cli } = installPrCliFixture ( repoDir ) ;
885893 const reviewScript = join ( repoDir , "scripts/pr-lib/review.sh" ) ;
886894 writeFileSync ( reviewScript , `${ readFileSync ( reviewScript , "utf8" ) } \nreview_init() { :; }\n` ) ;
887- for ( const command of [ "gh" , "jq" , "pnpm" , "rg" ] ) {
888- const stub = join ( binDir , command ) ;
889- writeFileSync ( stub , "#!/bin/sh\nexit 0\n" ) ;
890- chmodSync ( stub , 0o755 ) ;
891- }
895+ installRequiredPrCommandStubs ( binDir ) ;
892896 const env : NodeJS . ProcessEnv = {
893897 ...process . env ,
894898 OPENCLAW_PR_DEDICATED_PROCESS_GROUP : "1" ,
@@ -912,11 +916,7 @@ describePosix("scripts/pr per-PR operation lock", () => {
912916 reviewScript ,
913917 `${ readFileSync ( reviewScript , "utf8" ) } \nreview_init() { printf 'review ran\\n'; }\n` ,
914918 ) ;
915- for ( const command of [ "gh" , "jq" , "pnpm" , "rg" ] ) {
916- const stub = join ( binDir , command ) ;
917- writeFileSync ( stub , "#!/bin/sh\nexit 0\n" ) ;
918- chmodSync ( stub , 0o755 ) ;
919- }
919+ installRequiredPrCommandStubs ( binDir ) ;
920920 const mktempStub = join ( binDir , "mktemp" ) ;
921921 writeFileSync ( mktempStub , "#!/bin/sh\necho 'mktemp: No space left on device' >&2\nexit 1\n" ) ;
922922 chmodSync ( mktempStub , 0o755 ) ;
@@ -936,6 +936,29 @@ describePosix("scripts/pr per-PR operation lock", () => {
936936 expect ( result . stdout ) . not . toContain ( "review ran" ) ;
937937 expect ( refExists ( repoDir ) ) . toBe ( false ) ;
938938 } ) ;
939+ it ( "releases a validation-phase lock when review-init metadata fails" , ( ) => {
940+ const repoDir = createRepo ( ) ;
941+ const { binDir, cli } = installPrCliFixture ( repoDir ) ;
942+ const reviewScript = join ( repoDir , "scripts/pr-lib/review.sh" ) ;
943+ writeFileSync (
944+ reviewScript ,
945+ `${ readFileSync ( reviewScript , "utf8" ) } \nenter_worktree() { printf 'entered-worktree\\n'; }\npr_meta_json() { echo 'fixture metadata failure' >&2; return 1; }\n` ,
946+ ) ;
947+ installRequiredPrCommandStubs ( binDir ) ;
948+
949+ const result = spawnSync ( cli , [ "review-init" , "42" ] , {
950+ cwd : repoDir ,
951+ encoding : "utf8" ,
952+ env : { ...process . env , PATH : `${ binDir } :${ process . env . PATH ?? "" } ` } ,
953+ } ) ;
954+
955+ expect ( result . status , `${ result . stdout } \n${ result . stderr } ` ) . toBe ( 1 ) ;
956+ expect ( refExists ( repoDir ) , result . stderr ) . toBe ( false ) ;
957+ expect ( result . stderr ) . toContain ( "fixture metadata failure" ) ;
958+ expect ( result . stderr ) . not . toContain ( "Retaining the operation lock" ) ;
959+ expect ( result . stderr ) . not . toContain ( "scripts/pr lock-recover" ) ;
960+ expect ( result . stdout ) . not . toContain ( "entered-worktree" ) ;
961+ } ) ;
939962 it . each ( [ [ "--dryrun" ] , [ "--dry-run" , "extra" ] ] ) (
940963 "rejects invalid gc arguments before cleanup: %s" ,
941964 ( ...args : string [ ] ) => {
0 commit comments