@@ -49,6 +49,54 @@ test("plan-cluster carries worker target checkout into artifacts", () => {
4949 assert . equal ( fixArtifact . target_checkout , targetCheckout ) ;
5050} ) ;
5151
52+ test ( "plan-cluster hydrates the repository default branch instead of hard-coding main" , ( ) => {
53+ const tmp = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "clawsweeper-plan-default-branch-" ) ) ;
54+ const binDir = path . join ( tmp , "bin" ) ;
55+ const jobPath = path . join ( tmp , "job.md" ) ;
56+ const runDir = path . join ( tmp , "run" ) ;
57+ fs . mkdirSync ( binDir ) ;
58+ fs . writeFileSync ( path . join ( binDir , "gh" ) , fakeGhScript ( ) , { mode : 0o755 } ) ;
59+
60+ fs . writeFileSync (
61+ jobPath ,
62+ [
63+ "---" ,
64+ "repo: openclaw/openclaw" ,
65+ "cluster_id: issue-implementation-openclaw-openclaw-74134" ,
66+ "mode: autonomous" ,
67+ "allowed_actions:" ,
68+ " - comment" ,
69+ "canonical:" ,
70+ " - #74134" ,
71+ "candidates:" ,
72+ " - #74134" ,
73+ "allow_fix_pr: false" ,
74+ "security_policy: central_security_only" ,
75+ "security_sensitive: false" ,
76+ "---" ,
77+ "Plan this item." ,
78+ "" ,
79+ ] . join ( "\n" ) ,
80+ ) ;
81+
82+ execFileSync ( process . execPath , [ "dist/repair/plan-cluster.js" , jobPath , "--run-dir" , runDir ] , {
83+ cwd : process . cwd ( ) ,
84+ env : {
85+ ...process . env ,
86+ PATH : `${ binDir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` ,
87+ FAKE_DEFAULT_BRANCH : "master" ,
88+ } ,
89+ stdio : "pipe" ,
90+ } ) ;
91+
92+ const clusterPlan = JSON . parse ( fs . readFileSync ( path . join ( runDir , "cluster-plan.json" ) , "utf8" ) ) ;
93+ assert . deepEqual ( clusterPlan . main , {
94+ name : "master" ,
95+ sha : "master-sha" ,
96+ url : "https://github.com/openclaw/openclaw/tree/master" ,
97+ } ) ;
98+ } ) ;
99+
52100test ( "plan-cluster allows security repair for adopted PR autofix jobs" , ( ) => {
53101 const tmp = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "clawsweeper-plan-security-autofix-" ) ) ;
54102 const jobPath = path . join ( tmp , "job.md" ) ;
@@ -372,8 +420,13 @@ if (args[0] !== "api") {
372420 process.exit(1);
373421}
374422const endpoint = args[1];
375- if (endpoint === "repos/openclaw/openclaw/branches/main") {
376- write({ commit: { sha: "main-sha" }, _links: { html: "https://github.com/openclaw/openclaw/tree/main" } });
423+ const defaultBranch = process.env.FAKE_DEFAULT_BRANCH || "main";
424+ if (endpoint === "repos/openclaw/openclaw") {
425+ write({ default_branch: defaultBranch });
426+ process.exit(0);
427+ }
428+ if (endpoint === "repos/openclaw/openclaw/branches/" + encodeURIComponent(defaultBranch)) {
429+ write({ commit: { sha: defaultBranch + "-sha" }, _links: { html: "https://github.com/openclaw/openclaw/tree/" + defaultBranch } });
377430 process.exit(0);
378431}
379432if (isPaged()) {
0 commit comments