@@ -34,6 +34,10 @@ if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
3434 console.error("gh: Not Found (HTTP 404)");
3535 process.exit(1);
3636}
37+ if (args[0] === "api" && path === "repos/openclaw/clawsweeper") {
38+ console.log(JSON.stringify({ full_name: "openclaw/clawsweeper" }));
39+ process.exit(0);
40+ }
3741console.error("unexpected gh args", JSON.stringify(args));
3842process.exit(1);
3943` ;
@@ -55,3 +59,91 @@ process.exit(1);
5559 rmSync ( root , { recursive : true , force : true } ) ;
5660 }
5761} ) ;
62+
63+ test ( "apply-decisions keeps missing records queued during comment-only sync" , ( ) => {
64+ const root = mkdtempSync ( tmpPrefix ) ;
65+ try {
66+ const itemsDir = join ( root , "items" ) ;
67+ const closedDir = join ( root , "closed" ) ;
68+ const plansDir = join ( root , "plans" ) ;
69+ const reportPath = join ( root , "apply-report.json" ) ;
70+ mkdirSync ( itemsDir , { recursive : true } ) ;
71+ mkdirSync ( plansDir , { recursive : true } ) ;
72+ writeFileSync ( join ( itemsDir , "321.md" ) , implementedCloseReport ( ) , "utf8" ) ;
73+
74+ const ghMock = `
75+ const rawArgs = process.argv.slice(2);
76+ const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
77+ const path = args[1] || "";
78+ if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
79+ console.error("gh: Not Found (HTTP 404)");
80+ process.exit(1);
81+ }
82+ if (args[0] === "api" && path === "repos/openclaw/clawsweeper") {
83+ console.log(JSON.stringify({ full_name: "openclaw/clawsweeper" }));
84+ process.exit(0);
85+ }
86+ console.error("unexpected gh args", JSON.stringify(args));
87+ process.exit(1);
88+ ` ;
89+ withMockGh ( root , ghMock , ( ) => {
90+ runApplyDecisionsForTest ( {
91+ itemsDir,
92+ closedDir,
93+ plansDir,
94+ reportPath,
95+ extraArgs : [ "--sync-comments-only" ] ,
96+ } ) ;
97+ } ) ;
98+
99+ assert . ok ( existsSync ( join ( itemsDir , "321.md" ) ) ) ;
100+ assert . equal ( existsSync ( join ( closedDir , "321.md" ) ) , false ) ;
101+ assert . match ( readText ( join ( itemsDir , "321.md" ) ) , / ^ a c t i o n _ t a k e n : p r o p o s e d _ c l o s e $ / m) ;
102+ assert . deepEqual ( JSON . parse ( readText ( reportPath ) ) , [
103+ {
104+ number : 321 ,
105+ action : "skipped_already_closed" ,
106+ reason : "item not found on GitHub" ,
107+ } ,
108+ ] ) ;
109+ } finally {
110+ rmSync ( root , { recursive : true , force : true } ) ;
111+ }
112+ } ) ;
113+
114+ test ( "apply-decisions fails safely when a missing repository also returns 404" , ( ) => {
115+ const root = mkdtempSync ( tmpPrefix ) ;
116+ try {
117+ const itemsDir = join ( root , "items" ) ;
118+ const closedDir = join ( root , "closed" ) ;
119+ const plansDir = join ( root , "plans" ) ;
120+ const reportPath = join ( root , "apply-report.json" ) ;
121+ mkdirSync ( itemsDir , { recursive : true } ) ;
122+ mkdirSync ( plansDir , { recursive : true } ) ;
123+ writeFileSync ( join ( itemsDir , "321.md" ) , implementedCloseReport ( ) , "utf8" ) ;
124+
125+ const ghMock = `
126+ const rawArgs = process.argv.slice(2);
127+ const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
128+ const path = args[1] || "";
129+ if (args[0] === "api" && (/\\/issues\\/321$/.test(path) || path === "repos/openclaw/clawsweeper")) {
130+ console.error("gh: Not Found (HTTP 404)");
131+ process.exit(1);
132+ }
133+ console.error("unexpected gh args", JSON.stringify(args));
134+ process.exit(1);
135+ ` ;
136+ assert . throws (
137+ ( ) =>
138+ withMockGh ( root , ghMock , ( ) => {
139+ runApplyDecisionsForTest ( { itemsDir, closedDir, plansDir, reportPath } ) ;
140+ } ) ,
141+ / N o t F o u n d / ,
142+ ) ;
143+
144+ assert . ok ( existsSync ( join ( itemsDir , "321.md" ) ) ) ;
145+ assert . equal ( existsSync ( join ( closedDir , "321.md" ) ) , false ) ;
146+ } finally {
147+ rmSync ( root , { recursive : true , force : true } ) ;
148+ }
149+ } ) ;
0 commit comments