canopycms-cdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructs/cms-service.d.ts +64 -2
- package/dist/constructs/cms-service.js +216 -16
- package/dist/constructs/worker-lifecycle.d.ts +7 -1
- package/dist/constructs/worker-lifecycle.js +7 -0
- package/package.json +4 -4
- package/worker/canopy-github.service +1 -1
- package/worker/canopy-worker.service +1 -1
- package/worker/dist/index.js +1602 -855
- package/worker/dist/index.js.contract +1 -1
- package/worker/dist/index.js.sha256 +1 -1
- package/worker/dist/instance-files.sh +2 -2
- package/worker/gateway.env.example +12 -0
package/worker/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// canopy-worker-contract:
|
|
2
|
+
// canopy-worker-contract: 3
|
|
3
3
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -67,54 +67,54 @@ var require_polyfills = __commonJS({
|
|
|
67
67
|
}
|
|
68
68
|
var chdir;
|
|
69
69
|
module.exports = patch;
|
|
70
|
-
function patch(
|
|
70
|
+
function patch(fs33) {
|
|
71
71
|
if (constants2.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
|
|
72
|
-
patchLchmod(
|
|
73
|
-
}
|
|
74
|
-
if (!
|
|
75
|
-
patchLutimes(
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
72
|
+
patchLchmod(fs33);
|
|
73
|
+
}
|
|
74
|
+
if (!fs33.lutimes) {
|
|
75
|
+
patchLutimes(fs33);
|
|
76
|
+
}
|
|
77
|
+
fs33.chown = chownFix(fs33.chown);
|
|
78
|
+
fs33.fchown = chownFix(fs33.fchown);
|
|
79
|
+
fs33.lchown = chownFix(fs33.lchown);
|
|
80
|
+
fs33.chmod = chmodFix(fs33.chmod);
|
|
81
|
+
fs33.fchmod = chmodFix(fs33.fchmod);
|
|
82
|
+
fs33.lchmod = chmodFix(fs33.lchmod);
|
|
83
|
+
fs33.chownSync = chownFixSync(fs33.chownSync);
|
|
84
|
+
fs33.fchownSync = chownFixSync(fs33.fchownSync);
|
|
85
|
+
fs33.lchownSync = chownFixSync(fs33.lchownSync);
|
|
86
|
+
fs33.chmodSync = chmodFixSync(fs33.chmodSync);
|
|
87
|
+
fs33.fchmodSync = chmodFixSync(fs33.fchmodSync);
|
|
88
|
+
fs33.lchmodSync = chmodFixSync(fs33.lchmodSync);
|
|
89
|
+
fs33.stat = statFix(fs33.stat);
|
|
90
|
+
fs33.fstat = statFix(fs33.fstat);
|
|
91
|
+
fs33.lstat = statFix(fs33.lstat);
|
|
92
|
+
fs33.statSync = statFixSync(fs33.statSync);
|
|
93
|
+
fs33.fstatSync = statFixSync(fs33.fstatSync);
|
|
94
|
+
fs33.lstatSync = statFixSync(fs33.lstatSync);
|
|
95
|
+
if (fs33.chmod && !fs33.lchmod) {
|
|
96
|
+
fs33.lchmod = function(path36, mode, cb) {
|
|
97
97
|
if (cb) process.nextTick(cb);
|
|
98
98
|
};
|
|
99
|
-
|
|
99
|
+
fs33.lchmodSync = function() {
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
102
|
+
if (fs33.chown && !fs33.lchown) {
|
|
103
|
+
fs33.lchown = function(path36, uid, gid, cb) {
|
|
104
104
|
if (cb) process.nextTick(cb);
|
|
105
105
|
};
|
|
106
|
-
|
|
106
|
+
fs33.lchownSync = function() {
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
if (platform2 === "win32") {
|
|
110
|
-
|
|
110
|
+
fs33.rename = typeof fs33.rename !== "function" ? fs33.rename : (function(fs$rename) {
|
|
111
111
|
function rename(from, to, cb) {
|
|
112
112
|
var start = Date.now();
|
|
113
113
|
var backoff = 0;
|
|
114
114
|
fs$rename(from, to, function CB(er) {
|
|
115
115
|
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
116
116
|
setTimeout(function() {
|
|
117
|
-
|
|
117
|
+
fs33.stat(to, function(stater, st) {
|
|
118
118
|
if (stater && stater.code === "ENOENT")
|
|
119
119
|
fs$rename(from, to, CB);
|
|
120
120
|
else
|
|
@@ -130,9 +130,9 @@ var require_polyfills = __commonJS({
|
|
|
130
130
|
}
|
|
131
131
|
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
132
132
|
return rename;
|
|
133
|
-
})(
|
|
133
|
+
})(fs33.rename);
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
fs33.read = typeof fs33.read !== "function" ? fs33.read : (function(fs$read) {
|
|
136
136
|
function read(fd, buffer, offset, length, position, callback_) {
|
|
137
137
|
var callback;
|
|
138
138
|
if (callback_ && typeof callback_ === "function") {
|
|
@@ -140,22 +140,22 @@ var require_polyfills = __commonJS({
|
|
|
140
140
|
callback = function(er, _3, __) {
|
|
141
141
|
if (er && er.code === "EAGAIN" && eagCounter < 10) {
|
|
142
142
|
eagCounter++;
|
|
143
|
-
return fs$read.call(
|
|
143
|
+
return fs$read.call(fs33, fd, buffer, offset, length, position, callback);
|
|
144
144
|
}
|
|
145
145
|
callback_.apply(this, arguments);
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
return fs$read.call(
|
|
148
|
+
return fs$read.call(fs33, fd, buffer, offset, length, position, callback);
|
|
149
149
|
}
|
|
150
150
|
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
|
|
151
151
|
return read;
|
|
152
|
-
})(
|
|
153
|
-
|
|
152
|
+
})(fs33.read);
|
|
153
|
+
fs33.readSync = typeof fs33.readSync !== "function" ? fs33.readSync : /* @__PURE__ */ (function(fs$readSync) {
|
|
154
154
|
return function(fd, buffer, offset, length, position) {
|
|
155
155
|
var eagCounter = 0;
|
|
156
156
|
while (true) {
|
|
157
157
|
try {
|
|
158
|
-
return fs$readSync.call(
|
|
158
|
+
return fs$readSync.call(fs33, fd, buffer, offset, length, position);
|
|
159
159
|
} catch (er) {
|
|
160
160
|
if (er.code === "EAGAIN" && eagCounter < 10) {
|
|
161
161
|
eagCounter++;
|
|
@@ -165,11 +165,11 @@ var require_polyfills = __commonJS({
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
})(
|
|
169
|
-
function patchLchmod(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
})(fs33.readSync);
|
|
169
|
+
function patchLchmod(fs34) {
|
|
170
|
+
fs34.lchmod = function(path36, mode, callback) {
|
|
171
|
+
fs34.open(
|
|
172
|
+
path36,
|
|
173
173
|
constants2.O_WRONLY | constants2.O_SYMLINK,
|
|
174
174
|
mode,
|
|
175
175
|
function(err, fd) {
|
|
@@ -177,80 +177,80 @@ var require_polyfills = __commonJS({
|
|
|
177
177
|
if (callback) callback(err);
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
fs34.fchmod(fd, mode, function(err2) {
|
|
181
|
+
fs34.close(fd, function(err22) {
|
|
182
182
|
if (callback) callback(err2 || err22);
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
);
|
|
187
187
|
};
|
|
188
|
-
|
|
189
|
-
var fd =
|
|
188
|
+
fs34.lchmodSync = function(path36, mode) {
|
|
189
|
+
var fd = fs34.openSync(path36, constants2.O_WRONLY | constants2.O_SYMLINK, mode);
|
|
190
190
|
var threw = true;
|
|
191
191
|
var ret;
|
|
192
192
|
try {
|
|
193
|
-
ret =
|
|
193
|
+
ret = fs34.fchmodSync(fd, mode);
|
|
194
194
|
threw = false;
|
|
195
195
|
} finally {
|
|
196
196
|
if (threw) {
|
|
197
197
|
try {
|
|
198
|
-
|
|
198
|
+
fs34.closeSync(fd);
|
|
199
199
|
} catch (er) {
|
|
200
200
|
}
|
|
201
201
|
} else {
|
|
202
|
-
|
|
202
|
+
fs34.closeSync(fd);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
return ret;
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
function patchLutimes(
|
|
209
|
-
if (constants2.hasOwnProperty("O_SYMLINK") &&
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
function patchLutimes(fs34) {
|
|
209
|
+
if (constants2.hasOwnProperty("O_SYMLINK") && fs34.futimes) {
|
|
210
|
+
fs34.lutimes = function(path36, at, mt, cb) {
|
|
211
|
+
fs34.open(path36, constants2.O_SYMLINK, function(er, fd) {
|
|
212
212
|
if (er) {
|
|
213
213
|
if (cb) cb(er);
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
fs34.futimes(fd, at, mt, function(er2) {
|
|
217
|
+
fs34.close(fd, function(er22) {
|
|
218
218
|
if (cb) cb(er2 || er22);
|
|
219
219
|
});
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
};
|
|
223
|
-
|
|
224
|
-
var fd =
|
|
223
|
+
fs34.lutimesSync = function(path36, at, mt) {
|
|
224
|
+
var fd = fs34.openSync(path36, constants2.O_SYMLINK);
|
|
225
225
|
var ret;
|
|
226
226
|
var threw = true;
|
|
227
227
|
try {
|
|
228
|
-
ret =
|
|
228
|
+
ret = fs34.futimesSync(fd, at, mt);
|
|
229
229
|
threw = false;
|
|
230
230
|
} finally {
|
|
231
231
|
if (threw) {
|
|
232
232
|
try {
|
|
233
|
-
|
|
233
|
+
fs34.closeSync(fd);
|
|
234
234
|
} catch (er) {
|
|
235
235
|
}
|
|
236
236
|
} else {
|
|
237
|
-
|
|
237
|
+
fs34.closeSync(fd);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
return ret;
|
|
241
241
|
};
|
|
242
|
-
} else if (
|
|
243
|
-
|
|
242
|
+
} else if (fs34.futimes) {
|
|
243
|
+
fs34.lutimes = function(_a4, _b, _c9, cb) {
|
|
244
244
|
if (cb) process.nextTick(cb);
|
|
245
245
|
};
|
|
246
|
-
|
|
246
|
+
fs34.lutimesSync = function() {
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
function chmodFix(orig) {
|
|
251
251
|
if (!orig) return orig;
|
|
252
252
|
return function(target, mode, cb) {
|
|
253
|
-
return orig.call(
|
|
253
|
+
return orig.call(fs33, target, mode, function(er) {
|
|
254
254
|
if (chownErOk(er)) er = null;
|
|
255
255
|
if (cb) cb.apply(this, arguments);
|
|
256
256
|
});
|
|
@@ -260,7 +260,7 @@ var require_polyfills = __commonJS({
|
|
|
260
260
|
if (!orig) return orig;
|
|
261
261
|
return function(target, mode) {
|
|
262
262
|
try {
|
|
263
|
-
return orig.call(
|
|
263
|
+
return orig.call(fs33, target, mode);
|
|
264
264
|
} catch (er) {
|
|
265
265
|
if (!chownErOk(er)) throw er;
|
|
266
266
|
}
|
|
@@ -269,7 +269,7 @@ var require_polyfills = __commonJS({
|
|
|
269
269
|
function chownFix(orig) {
|
|
270
270
|
if (!orig) return orig;
|
|
271
271
|
return function(target, uid, gid, cb) {
|
|
272
|
-
return orig.call(
|
|
272
|
+
return orig.call(fs33, target, uid, gid, function(er) {
|
|
273
273
|
if (chownErOk(er)) er = null;
|
|
274
274
|
if (cb) cb.apply(this, arguments);
|
|
275
275
|
});
|
|
@@ -279,7 +279,7 @@ var require_polyfills = __commonJS({
|
|
|
279
279
|
if (!orig) return orig;
|
|
280
280
|
return function(target, uid, gid) {
|
|
281
281
|
try {
|
|
282
|
-
return orig.call(
|
|
282
|
+
return orig.call(fs33, target, uid, gid);
|
|
283
283
|
} catch (er) {
|
|
284
284
|
if (!chownErOk(er)) throw er;
|
|
285
285
|
}
|
|
@@ -299,13 +299,13 @@ var require_polyfills = __commonJS({
|
|
|
299
299
|
}
|
|
300
300
|
if (cb) cb.apply(this, arguments);
|
|
301
301
|
}
|
|
302
|
-
return options ? orig.call(
|
|
302
|
+
return options ? orig.call(fs33, target, options, callback) : orig.call(fs33, target, callback);
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
function statFixSync(orig) {
|
|
306
306
|
if (!orig) return orig;
|
|
307
307
|
return function(target, options) {
|
|
308
|
-
var stats = options ? orig.call(
|
|
308
|
+
var stats = options ? orig.call(fs33, target, options) : orig.call(fs33, target);
|
|
309
309
|
if (stats) {
|
|
310
310
|
if (stats.uid < 0) stats.uid += 4294967296;
|
|
311
311
|
if (stats.gid < 0) stats.gid += 4294967296;
|
|
@@ -334,16 +334,16 @@ var require_legacy_streams = __commonJS({
|
|
|
334
334
|
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js"(exports, module) {
|
|
335
335
|
var Stream = __require("stream").Stream;
|
|
336
336
|
module.exports = legacy;
|
|
337
|
-
function legacy(
|
|
337
|
+
function legacy(fs33) {
|
|
338
338
|
return {
|
|
339
339
|
ReadStream: ReadStream2,
|
|
340
340
|
WriteStream
|
|
341
341
|
};
|
|
342
|
-
function ReadStream2(
|
|
343
|
-
if (!(this instanceof ReadStream2)) return new ReadStream2(
|
|
342
|
+
function ReadStream2(path36, options) {
|
|
343
|
+
if (!(this instanceof ReadStream2)) return new ReadStream2(path36, options);
|
|
344
344
|
Stream.call(this);
|
|
345
345
|
var self2 = this;
|
|
346
|
-
this.path =
|
|
346
|
+
this.path = path36;
|
|
347
347
|
this.fd = null;
|
|
348
348
|
this.readable = true;
|
|
349
349
|
this.paused = false;
|
|
@@ -377,7 +377,7 @@ var require_legacy_streams = __commonJS({
|
|
|
377
377
|
});
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
fs33.open(this.path, this.flags, this.mode, function(err, fd) {
|
|
381
381
|
if (err) {
|
|
382
382
|
self2.emit("error", err);
|
|
383
383
|
self2.readable = false;
|
|
@@ -388,10 +388,10 @@ var require_legacy_streams = __commonJS({
|
|
|
388
388
|
self2._read();
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
|
-
function WriteStream(
|
|
392
|
-
if (!(this instanceof WriteStream)) return new WriteStream(
|
|
391
|
+
function WriteStream(path36, options) {
|
|
392
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path36, options);
|
|
393
393
|
Stream.call(this);
|
|
394
|
-
this.path =
|
|
394
|
+
this.path = path36;
|
|
395
395
|
this.fd = null;
|
|
396
396
|
this.writable = true;
|
|
397
397
|
this.flags = "w";
|
|
@@ -416,7 +416,7 @@ var require_legacy_streams = __commonJS({
|
|
|
416
416
|
this.busy = false;
|
|
417
417
|
this._queue = [];
|
|
418
418
|
if (this.fd === null) {
|
|
419
|
-
this._open =
|
|
419
|
+
this._open = fs33.open;
|
|
420
420
|
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
|
|
421
421
|
this.flush();
|
|
422
422
|
}
|
|
@@ -451,7 +451,7 @@ var require_clone = __commonJS({
|
|
|
451
451
|
// ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
|
|
452
452
|
var require_graceful_fs = __commonJS({
|
|
453
453
|
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js"(exports, module) {
|
|
454
|
-
var
|
|
454
|
+
var fs33 = __require("fs");
|
|
455
455
|
var polyfills = require_polyfills();
|
|
456
456
|
var legacy = require_legacy_streams();
|
|
457
457
|
var clone = require_clone();
|
|
@@ -483,12 +483,12 @@ var require_graceful_fs = __commonJS({
|
|
|
483
483
|
m7 = "GFS4: " + m7.split(/\n/).join("\nGFS4: ");
|
|
484
484
|
console.error(m7);
|
|
485
485
|
};
|
|
486
|
-
if (!
|
|
486
|
+
if (!fs33[gracefulQueue]) {
|
|
487
487
|
queue = global[gracefulQueue] || [];
|
|
488
|
-
publishQueue(
|
|
489
|
-
|
|
488
|
+
publishQueue(fs33, queue);
|
|
489
|
+
fs33.close = (function(fs$close) {
|
|
490
490
|
function close(fd, cb) {
|
|
491
|
-
return fs$close.call(
|
|
491
|
+
return fs$close.call(fs33, fd, function(err) {
|
|
492
492
|
if (!err) {
|
|
493
493
|
resetQueue();
|
|
494
494
|
}
|
|
@@ -500,48 +500,48 @@ var require_graceful_fs = __commonJS({
|
|
|
500
500
|
value: fs$close
|
|
501
501
|
});
|
|
502
502
|
return close;
|
|
503
|
-
})(
|
|
504
|
-
|
|
503
|
+
})(fs33.close);
|
|
504
|
+
fs33.closeSync = (function(fs$closeSync) {
|
|
505
505
|
function closeSync(fd) {
|
|
506
|
-
fs$closeSync.apply(
|
|
506
|
+
fs$closeSync.apply(fs33, arguments);
|
|
507
507
|
resetQueue();
|
|
508
508
|
}
|
|
509
509
|
Object.defineProperty(closeSync, previousSymbol, {
|
|
510
510
|
value: fs$closeSync
|
|
511
511
|
});
|
|
512
512
|
return closeSync;
|
|
513
|
-
})(
|
|
513
|
+
})(fs33.closeSync);
|
|
514
514
|
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
|
|
515
515
|
process.on("exit", function() {
|
|
516
|
-
debug2(
|
|
517
|
-
__require("assert").equal(
|
|
516
|
+
debug2(fs33[gracefulQueue]);
|
|
517
|
+
__require("assert").equal(fs33[gracefulQueue].length, 0);
|
|
518
518
|
});
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
var queue;
|
|
522
522
|
if (!global[gracefulQueue]) {
|
|
523
|
-
publishQueue(global,
|
|
524
|
-
}
|
|
525
|
-
module.exports = patch(clone(
|
|
526
|
-
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !
|
|
527
|
-
module.exports = patch(
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
function patch(
|
|
531
|
-
polyfills(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
var fs$readFile =
|
|
536
|
-
|
|
537
|
-
function readFile3(
|
|
523
|
+
publishQueue(global, fs33[gracefulQueue]);
|
|
524
|
+
}
|
|
525
|
+
module.exports = patch(clone(fs33));
|
|
526
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs33.__patched) {
|
|
527
|
+
module.exports = patch(fs33);
|
|
528
|
+
fs33.__patched = true;
|
|
529
|
+
}
|
|
530
|
+
function patch(fs34) {
|
|
531
|
+
polyfills(fs34);
|
|
532
|
+
fs34.gracefulify = patch;
|
|
533
|
+
fs34.createReadStream = createReadStream;
|
|
534
|
+
fs34.createWriteStream = createWriteStream;
|
|
535
|
+
var fs$readFile = fs34.readFile;
|
|
536
|
+
fs34.readFile = readFile3;
|
|
537
|
+
function readFile3(path36, options, cb) {
|
|
538
538
|
if (typeof options === "function")
|
|
539
539
|
cb = options, options = null;
|
|
540
|
-
return go$readFile(
|
|
541
|
-
function go$readFile(
|
|
542
|
-
return fs$readFile(
|
|
540
|
+
return go$readFile(path36, options, cb);
|
|
541
|
+
function go$readFile(path37, options2, cb2, startTime) {
|
|
542
|
+
return fs$readFile(path37, options2, function(err) {
|
|
543
543
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
544
|
-
enqueue([go$readFile, [
|
|
544
|
+
enqueue([go$readFile, [path37, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
545
545
|
else {
|
|
546
546
|
if (typeof cb2 === "function")
|
|
547
547
|
cb2.apply(this, arguments);
|
|
@@ -549,16 +549,16 @@ var require_graceful_fs = __commonJS({
|
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
var fs$writeFile =
|
|
553
|
-
|
|
554
|
-
function writeFile(
|
|
552
|
+
var fs$writeFile = fs34.writeFile;
|
|
553
|
+
fs34.writeFile = writeFile;
|
|
554
|
+
function writeFile(path36, data3, options, cb) {
|
|
555
555
|
if (typeof options === "function")
|
|
556
556
|
cb = options, options = null;
|
|
557
|
-
return go$writeFile(
|
|
558
|
-
function go$writeFile(
|
|
559
|
-
return fs$writeFile(
|
|
557
|
+
return go$writeFile(path36, data3, options, cb);
|
|
558
|
+
function go$writeFile(path37, data4, options2, cb2, startTime) {
|
|
559
|
+
return fs$writeFile(path37, data4, options2, function(err) {
|
|
560
560
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
561
|
-
enqueue([go$writeFile, [
|
|
561
|
+
enqueue([go$writeFile, [path37, data4, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
562
562
|
else {
|
|
563
563
|
if (typeof cb2 === "function")
|
|
564
564
|
cb2.apply(this, arguments);
|
|
@@ -566,17 +566,17 @@ var require_graceful_fs = __commonJS({
|
|
|
566
566
|
});
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
|
-
var fs$appendFile =
|
|
569
|
+
var fs$appendFile = fs34.appendFile;
|
|
570
570
|
if (fs$appendFile)
|
|
571
|
-
|
|
572
|
-
function appendFile(
|
|
571
|
+
fs34.appendFile = appendFile;
|
|
572
|
+
function appendFile(path36, data3, options, cb) {
|
|
573
573
|
if (typeof options === "function")
|
|
574
574
|
cb = options, options = null;
|
|
575
|
-
return go$appendFile(
|
|
576
|
-
function go$appendFile(
|
|
577
|
-
return fs$appendFile(
|
|
575
|
+
return go$appendFile(path36, data3, options, cb);
|
|
576
|
+
function go$appendFile(path37, data4, options2, cb2, startTime) {
|
|
577
|
+
return fs$appendFile(path37, data4, options2, function(err) {
|
|
578
578
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
579
|
-
enqueue([go$appendFile, [
|
|
579
|
+
enqueue([go$appendFile, [path37, data4, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
580
580
|
else {
|
|
581
581
|
if (typeof cb2 === "function")
|
|
582
582
|
cb2.apply(this, arguments);
|
|
@@ -584,9 +584,9 @@ var require_graceful_fs = __commonJS({
|
|
|
584
584
|
});
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
-
var fs$copyFile =
|
|
587
|
+
var fs$copyFile = fs34.copyFile;
|
|
588
588
|
if (fs$copyFile)
|
|
589
|
-
|
|
589
|
+
fs34.copyFile = copyFile;
|
|
590
590
|
function copyFile(src, dest, flags, cb) {
|
|
591
591
|
if (typeof flags === "function") {
|
|
592
592
|
cb = flags;
|
|
@@ -604,34 +604,34 @@ var require_graceful_fs = __commonJS({
|
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
|
-
var fs$readdir =
|
|
608
|
-
|
|
607
|
+
var fs$readdir = fs34.readdir;
|
|
608
|
+
fs34.readdir = readdir;
|
|
609
609
|
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
610
|
-
function readdir(
|
|
610
|
+
function readdir(path36, options, cb) {
|
|
611
611
|
if (typeof options === "function")
|
|
612
612
|
cb = options, options = null;
|
|
613
|
-
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(
|
|
614
|
-
return fs$readdir(
|
|
615
|
-
|
|
613
|
+
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path37, options2, cb2, startTime) {
|
|
614
|
+
return fs$readdir(path37, fs$readdirCallback(
|
|
615
|
+
path37,
|
|
616
616
|
options2,
|
|
617
617
|
cb2,
|
|
618
618
|
startTime
|
|
619
619
|
));
|
|
620
|
-
} : function go$readdir2(
|
|
621
|
-
return fs$readdir(
|
|
622
|
-
|
|
620
|
+
} : function go$readdir2(path37, options2, cb2, startTime) {
|
|
621
|
+
return fs$readdir(path37, options2, fs$readdirCallback(
|
|
622
|
+
path37,
|
|
623
623
|
options2,
|
|
624
624
|
cb2,
|
|
625
625
|
startTime
|
|
626
626
|
));
|
|
627
627
|
};
|
|
628
|
-
return go$readdir(
|
|
629
|
-
function fs$readdirCallback(
|
|
628
|
+
return go$readdir(path36, options, cb);
|
|
629
|
+
function fs$readdirCallback(path37, options2, cb2, startTime) {
|
|
630
630
|
return function(err, files) {
|
|
631
631
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
632
632
|
enqueue([
|
|
633
633
|
go$readdir,
|
|
634
|
-
[
|
|
634
|
+
[path37, options2, cb2],
|
|
635
635
|
err,
|
|
636
636
|
startTime || Date.now(),
|
|
637
637
|
Date.now()
|
|
@@ -646,21 +646,21 @@ var require_graceful_fs = __commonJS({
|
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
if (process.version.substr(0, 4) === "v0.8") {
|
|
649
|
-
var legStreams = legacy(
|
|
649
|
+
var legStreams = legacy(fs34);
|
|
650
650
|
ReadStream2 = legStreams.ReadStream;
|
|
651
651
|
WriteStream = legStreams.WriteStream;
|
|
652
652
|
}
|
|
653
|
-
var fs$ReadStream =
|
|
653
|
+
var fs$ReadStream = fs34.ReadStream;
|
|
654
654
|
if (fs$ReadStream) {
|
|
655
655
|
ReadStream2.prototype = Object.create(fs$ReadStream.prototype);
|
|
656
656
|
ReadStream2.prototype.open = ReadStream$open;
|
|
657
657
|
}
|
|
658
|
-
var fs$WriteStream =
|
|
658
|
+
var fs$WriteStream = fs34.WriteStream;
|
|
659
659
|
if (fs$WriteStream) {
|
|
660
660
|
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
661
661
|
WriteStream.prototype.open = WriteStream$open;
|
|
662
662
|
}
|
|
663
|
-
Object.defineProperty(
|
|
663
|
+
Object.defineProperty(fs34, "ReadStream", {
|
|
664
664
|
get: function() {
|
|
665
665
|
return ReadStream2;
|
|
666
666
|
},
|
|
@@ -670,7 +670,7 @@ var require_graceful_fs = __commonJS({
|
|
|
670
670
|
enumerable: true,
|
|
671
671
|
configurable: true
|
|
672
672
|
});
|
|
673
|
-
Object.defineProperty(
|
|
673
|
+
Object.defineProperty(fs34, "WriteStream", {
|
|
674
674
|
get: function() {
|
|
675
675
|
return WriteStream;
|
|
676
676
|
},
|
|
@@ -681,7 +681,7 @@ var require_graceful_fs = __commonJS({
|
|
|
681
681
|
configurable: true
|
|
682
682
|
});
|
|
683
683
|
var FileReadStream = ReadStream2;
|
|
684
|
-
Object.defineProperty(
|
|
684
|
+
Object.defineProperty(fs34, "FileReadStream", {
|
|
685
685
|
get: function() {
|
|
686
686
|
return FileReadStream;
|
|
687
687
|
},
|
|
@@ -692,7 +692,7 @@ var require_graceful_fs = __commonJS({
|
|
|
692
692
|
configurable: true
|
|
693
693
|
});
|
|
694
694
|
var FileWriteStream = WriteStream;
|
|
695
|
-
Object.defineProperty(
|
|
695
|
+
Object.defineProperty(fs34, "FileWriteStream", {
|
|
696
696
|
get: function() {
|
|
697
697
|
return FileWriteStream;
|
|
698
698
|
},
|
|
@@ -702,7 +702,7 @@ var require_graceful_fs = __commonJS({
|
|
|
702
702
|
enumerable: true,
|
|
703
703
|
configurable: true
|
|
704
704
|
});
|
|
705
|
-
function ReadStream2(
|
|
705
|
+
function ReadStream2(path36, options) {
|
|
706
706
|
if (this instanceof ReadStream2)
|
|
707
707
|
return fs$ReadStream.apply(this, arguments), this;
|
|
708
708
|
else
|
|
@@ -722,7 +722,7 @@ var require_graceful_fs = __commonJS({
|
|
|
722
722
|
}
|
|
723
723
|
});
|
|
724
724
|
}
|
|
725
|
-
function WriteStream(
|
|
725
|
+
function WriteStream(path36, options) {
|
|
726
726
|
if (this instanceof WriteStream)
|
|
727
727
|
return fs$WriteStream.apply(this, arguments), this;
|
|
728
728
|
else
|
|
@@ -740,22 +740,22 @@ var require_graceful_fs = __commonJS({
|
|
|
740
740
|
}
|
|
741
741
|
});
|
|
742
742
|
}
|
|
743
|
-
function createReadStream(
|
|
744
|
-
return new
|
|
743
|
+
function createReadStream(path36, options) {
|
|
744
|
+
return new fs34.ReadStream(path36, options);
|
|
745
745
|
}
|
|
746
|
-
function createWriteStream(
|
|
747
|
-
return new
|
|
746
|
+
function createWriteStream(path36, options) {
|
|
747
|
+
return new fs34.WriteStream(path36, options);
|
|
748
748
|
}
|
|
749
|
-
var fs$open =
|
|
750
|
-
|
|
751
|
-
function open(
|
|
749
|
+
var fs$open = fs34.open;
|
|
750
|
+
fs34.open = open;
|
|
751
|
+
function open(path36, flags, mode, cb) {
|
|
752
752
|
if (typeof mode === "function")
|
|
753
753
|
cb = mode, mode = null;
|
|
754
|
-
return go$open(
|
|
755
|
-
function go$open(
|
|
756
|
-
return fs$open(
|
|
754
|
+
return go$open(path36, flags, mode, cb);
|
|
755
|
+
function go$open(path37, flags2, mode2, cb2, startTime) {
|
|
756
|
+
return fs$open(path37, flags2, mode2, function(err, fd) {
|
|
757
757
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
758
|
-
enqueue([go$open, [
|
|
758
|
+
enqueue([go$open, [path37, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
759
759
|
else {
|
|
760
760
|
if (typeof cb2 === "function")
|
|
761
761
|
cb2.apply(this, arguments);
|
|
@@ -763,20 +763,20 @@ var require_graceful_fs = __commonJS({
|
|
|
763
763
|
});
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
|
-
return
|
|
766
|
+
return fs34;
|
|
767
767
|
}
|
|
768
768
|
function enqueue(elem) {
|
|
769
769
|
debug2("ENQUEUE", elem[0].name, elem[1]);
|
|
770
|
-
|
|
770
|
+
fs33[gracefulQueue].push(elem);
|
|
771
771
|
retry2();
|
|
772
772
|
}
|
|
773
773
|
var retryTimer;
|
|
774
774
|
function resetQueue() {
|
|
775
775
|
var now = Date.now();
|
|
776
|
-
for (var i10 = 0; i10 <
|
|
777
|
-
if (
|
|
778
|
-
|
|
779
|
-
|
|
776
|
+
for (var i10 = 0; i10 < fs33[gracefulQueue].length; ++i10) {
|
|
777
|
+
if (fs33[gracefulQueue][i10].length > 2) {
|
|
778
|
+
fs33[gracefulQueue][i10][3] = now;
|
|
779
|
+
fs33[gracefulQueue][i10][4] = now;
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
782
|
retry2();
|
|
@@ -784,9 +784,9 @@ var require_graceful_fs = __commonJS({
|
|
|
784
784
|
function retry2() {
|
|
785
785
|
clearTimeout(retryTimer);
|
|
786
786
|
retryTimer = void 0;
|
|
787
|
-
if (
|
|
787
|
+
if (fs33[gracefulQueue].length === 0)
|
|
788
788
|
return;
|
|
789
|
-
var elem =
|
|
789
|
+
var elem = fs33[gracefulQueue].shift();
|
|
790
790
|
var fn = elem[0];
|
|
791
791
|
var args = elem[1];
|
|
792
792
|
var err = elem[2];
|
|
@@ -808,7 +808,7 @@ var require_graceful_fs = __commonJS({
|
|
|
808
808
|
debug2("RETRY", fn.name, args);
|
|
809
809
|
fn.apply(null, args.concat([startTime]));
|
|
810
810
|
} else {
|
|
811
|
-
|
|
811
|
+
fs33[gracefulQueue].push(elem);
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
814
|
if (retryTimer === void 0) {
|
|
@@ -1243,10 +1243,10 @@ var require_mtime_precision = __commonJS({
|
|
|
1243
1243
|
"../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
|
|
1244
1244
|
"use strict";
|
|
1245
1245
|
var cacheSymbol = Symbol();
|
|
1246
|
-
function probe(file,
|
|
1247
|
-
const cachedPrecision =
|
|
1246
|
+
function probe(file, fs33, callback) {
|
|
1247
|
+
const cachedPrecision = fs33[cacheSymbol];
|
|
1248
1248
|
if (cachedPrecision) {
|
|
1249
|
-
return
|
|
1249
|
+
return fs33.stat(file, (err, stat) => {
|
|
1250
1250
|
if (err) {
|
|
1251
1251
|
return callback(err);
|
|
1252
1252
|
}
|
|
@@ -1254,16 +1254,16 @@ var require_mtime_precision = __commonJS({
|
|
|
1254
1254
|
});
|
|
1255
1255
|
}
|
|
1256
1256
|
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
1257
|
-
|
|
1257
|
+
fs33.utimes(file, mtime, mtime, (err) => {
|
|
1258
1258
|
if (err) {
|
|
1259
1259
|
return callback(err);
|
|
1260
1260
|
}
|
|
1261
|
-
|
|
1261
|
+
fs33.stat(file, (err2, stat) => {
|
|
1262
1262
|
if (err2) {
|
|
1263
1263
|
return callback(err2);
|
|
1264
1264
|
}
|
|
1265
1265
|
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
1266
|
-
Object.defineProperty(
|
|
1266
|
+
Object.defineProperty(fs33, cacheSymbol, { value: precision });
|
|
1267
1267
|
callback(null, stat.mtime, precision);
|
|
1268
1268
|
});
|
|
1269
1269
|
});
|
|
@@ -1284,8 +1284,8 @@ var require_mtime_precision = __commonJS({
|
|
|
1284
1284
|
var require_lockfile = __commonJS({
|
|
1285
1285
|
"../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
|
|
1286
1286
|
"use strict";
|
|
1287
|
-
var
|
|
1288
|
-
var
|
|
1287
|
+
var path36 = __require("path");
|
|
1288
|
+
var fs33 = require_graceful_fs();
|
|
1289
1289
|
var retry2 = require_retry2();
|
|
1290
1290
|
var onExit = require_signal_exit();
|
|
1291
1291
|
var mtimePrecision = require_mtime_precision();
|
|
@@ -1295,7 +1295,7 @@ var require_lockfile = __commonJS({
|
|
|
1295
1295
|
}
|
|
1296
1296
|
function resolveCanonicalPath(file, options, callback) {
|
|
1297
1297
|
if (!options.realpath) {
|
|
1298
|
-
return callback(null,
|
|
1298
|
+
return callback(null, path36.resolve(file));
|
|
1299
1299
|
}
|
|
1300
1300
|
options.fs.realpath(file, callback);
|
|
1301
1301
|
}
|
|
@@ -1416,7 +1416,7 @@ var require_lockfile = __commonJS({
|
|
|
1416
1416
|
update: null,
|
|
1417
1417
|
realpath: true,
|
|
1418
1418
|
retries: 0,
|
|
1419
|
-
fs:
|
|
1419
|
+
fs: fs33,
|
|
1420
1420
|
onCompromised: (err) => {
|
|
1421
1421
|
throw err;
|
|
1422
1422
|
},
|
|
@@ -1460,7 +1460,7 @@ var require_lockfile = __commonJS({
|
|
|
1460
1460
|
}
|
|
1461
1461
|
function unlock(file, options, callback) {
|
|
1462
1462
|
options = {
|
|
1463
|
-
fs:
|
|
1463
|
+
fs: fs33,
|
|
1464
1464
|
realpath: true,
|
|
1465
1465
|
...options
|
|
1466
1466
|
};
|
|
@@ -1482,7 +1482,7 @@ var require_lockfile = __commonJS({
|
|
|
1482
1482
|
options = {
|
|
1483
1483
|
stale: 1e4,
|
|
1484
1484
|
realpath: true,
|
|
1485
|
-
fs:
|
|
1485
|
+
fs: fs33,
|
|
1486
1486
|
...options
|
|
1487
1487
|
};
|
|
1488
1488
|
options.stale = Math.max(options.stale || 0, 2e3);
|
|
@@ -1521,16 +1521,16 @@ var require_lockfile = __commonJS({
|
|
|
1521
1521
|
var require_adapter = __commonJS({
|
|
1522
1522
|
"../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
|
|
1523
1523
|
"use strict";
|
|
1524
|
-
var
|
|
1525
|
-
function createSyncFs(
|
|
1524
|
+
var fs33 = require_graceful_fs();
|
|
1525
|
+
function createSyncFs(fs34) {
|
|
1526
1526
|
const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
|
|
1527
|
-
const newFs = { ...
|
|
1527
|
+
const newFs = { ...fs34 };
|
|
1528
1528
|
methods.forEach((method) => {
|
|
1529
1529
|
newFs[method] = (...args) => {
|
|
1530
1530
|
const callback = args.pop();
|
|
1531
1531
|
let ret;
|
|
1532
1532
|
try {
|
|
1533
|
-
ret =
|
|
1533
|
+
ret = fs34[`${method}Sync`](...args);
|
|
1534
1534
|
} catch (err) {
|
|
1535
1535
|
return callback(err);
|
|
1536
1536
|
}
|
|
@@ -1568,7 +1568,7 @@ var require_adapter = __commonJS({
|
|
|
1568
1568
|
}
|
|
1569
1569
|
function toSyncOptions(options) {
|
|
1570
1570
|
options = { ...options };
|
|
1571
|
-
options.fs = createSyncFs(options.fs ||
|
|
1571
|
+
options.fs = createSyncFs(options.fs || fs33);
|
|
1572
1572
|
if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
|
|
1573
1573
|
throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
|
|
1574
1574
|
}
|
|
@@ -2058,10 +2058,10 @@ var require_browser = __commonJS({
|
|
|
2058
2058
|
exports.useColors = useColors;
|
|
2059
2059
|
exports.storage = localstorage();
|
|
2060
2060
|
exports.destroy = /* @__PURE__ */ (() => {
|
|
2061
|
-
let
|
|
2061
|
+
let warned3 = false;
|
|
2062
2062
|
return () => {
|
|
2063
|
-
if (!
|
|
2064
|
-
|
|
2063
|
+
if (!warned3) {
|
|
2064
|
+
warned3 = true;
|
|
2065
2065
|
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2066
2066
|
}
|
|
2067
2067
|
};
|
|
@@ -2530,10 +2530,10 @@ var require_src2 = __commonJS({
|
|
|
2530
2530
|
var fs_1 = __require("fs");
|
|
2531
2531
|
var debug_1 = __importDefault2(require_src());
|
|
2532
2532
|
var log6 = debug_1.default("@kwsites/file-exists");
|
|
2533
|
-
function check(
|
|
2534
|
-
log6(`checking %s`,
|
|
2533
|
+
function check(path36, isFile, isDirectory) {
|
|
2534
|
+
log6(`checking %s`, path36);
|
|
2535
2535
|
try {
|
|
2536
|
-
const stat = fs_1.statSync(
|
|
2536
|
+
const stat = fs_1.statSync(path36);
|
|
2537
2537
|
if (stat.isFile() && isFile) {
|
|
2538
2538
|
log6(`[OK] path represents a file`);
|
|
2539
2539
|
return true;
|
|
@@ -2553,8 +2553,8 @@ var require_src2 = __commonJS({
|
|
|
2553
2553
|
throw e9;
|
|
2554
2554
|
}
|
|
2555
2555
|
}
|
|
2556
|
-
function exists3(
|
|
2557
|
-
return check(
|
|
2556
|
+
function exists3(path36, type = exports.READABLE) {
|
|
2557
|
+
return check(path36, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
|
|
2558
2558
|
}
|
|
2559
2559
|
exports.exists = exists3;
|
|
2560
2560
|
exports.FILE = 1;
|
|
@@ -3029,8 +3029,8 @@ var init_parseUtil = __esm({
|
|
|
3029
3029
|
init_errors();
|
|
3030
3030
|
init_en();
|
|
3031
3031
|
makeIssue = (params) => {
|
|
3032
|
-
const { data: data3, path:
|
|
3033
|
-
const fullPath = [...
|
|
3032
|
+
const { data: data3, path: path36, errorMaps, issueData } = params;
|
|
3033
|
+
const fullPath = [...path36, ...issueData.path || []];
|
|
3034
3034
|
const fullIssue = {
|
|
3035
3035
|
...issueData,
|
|
3036
3036
|
path: fullPath
|
|
@@ -3338,11 +3338,11 @@ var init_types = __esm({
|
|
|
3338
3338
|
init_parseUtil();
|
|
3339
3339
|
init_util2();
|
|
3340
3340
|
ParseInputLazyPath = class {
|
|
3341
|
-
constructor(parent, value,
|
|
3341
|
+
constructor(parent, value, path36, key) {
|
|
3342
3342
|
this._cachedPath = [];
|
|
3343
3343
|
this.parent = parent;
|
|
3344
3344
|
this.data = value;
|
|
3345
|
-
this._path =
|
|
3345
|
+
this._path = path36;
|
|
3346
3346
|
this._key = key;
|
|
3347
3347
|
}
|
|
3348
3348
|
get path() {
|
|
@@ -7003,9 +7003,28 @@ var require_dist3 = __commonJS({
|
|
|
7003
7003
|
}
|
|
7004
7004
|
});
|
|
7005
7005
|
|
|
7006
|
+
// ../canopycms/src/paths/branch-name.ts
|
|
7007
|
+
function sanitizeBranchName(branchName) {
|
|
7008
|
+
const replaced = branchName.replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
7009
|
+
const squashed = replaced.replace(/-+/g, "-");
|
|
7010
|
+
const trimmedDots = squashed.replace(/^\.+/, "").replace(/(?<!\.)\.+$/, "");
|
|
7011
|
+
return trimmedDots || "branch";
|
|
7012
|
+
}
|
|
7013
|
+
function isSettingsBranchName(branchName, settingsBranchName) {
|
|
7014
|
+
const sanitized = sanitizeBranchName(branchName);
|
|
7015
|
+
return sanitized.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX) || settingsBranchName !== void 0 && sanitized === sanitizeBranchName(settingsBranchName);
|
|
7016
|
+
}
|
|
7017
|
+
var RESERVED_SETTINGS_BRANCH_PREFIX;
|
|
7018
|
+
var init_branch_name = __esm({
|
|
7019
|
+
"../canopycms/src/paths/branch-name.ts"() {
|
|
7020
|
+
"use strict";
|
|
7021
|
+
RESERVED_SETTINGS_BRANCH_PREFIX = "canopycms-settings-";
|
|
7022
|
+
}
|
|
7023
|
+
});
|
|
7024
|
+
|
|
7006
7025
|
// ../canopycms/src/paths/normalize.ts
|
|
7007
|
-
function normalizeFilesystemPath(
|
|
7008
|
-
return
|
|
7026
|
+
function normalizeFilesystemPath(path36) {
|
|
7027
|
+
return path36.split(/[\\/]+/).filter(Boolean).join("/");
|
|
7009
7028
|
}
|
|
7010
7029
|
var init_normalize = __esm({
|
|
7011
7030
|
"../canopycms/src/paths/normalize.ts"() {
|
|
@@ -7013,6 +7032,57 @@ var init_normalize = __esm({
|
|
|
7013
7032
|
}
|
|
7014
7033
|
});
|
|
7015
7034
|
|
|
7035
|
+
// ../canopycms/src/paths/validation.ts
|
|
7036
|
+
function isValidContentId(id) {
|
|
7037
|
+
return CONTENT_ID_PATTERN.test(id);
|
|
7038
|
+
}
|
|
7039
|
+
function parseBranchRef(name2) {
|
|
7040
|
+
if (!name2 || typeof name2 !== "string") {
|
|
7041
|
+
return { ok: false, error: "Branch name is required" };
|
|
7042
|
+
}
|
|
7043
|
+
if (name2.length > MAX_BRANCH_NAME_LENGTH) {
|
|
7044
|
+
return { ok: false, error: `Branch name too long (max ${MAX_BRANCH_NAME_LENGTH} characters)` };
|
|
7045
|
+
}
|
|
7046
|
+
if (name2.includes("..")) {
|
|
7047
|
+
return { ok: false, error: 'Branch name cannot contain ".."' };
|
|
7048
|
+
}
|
|
7049
|
+
if (name2.startsWith("/") || name2.endsWith("/") || name2.includes("//")) {
|
|
7050
|
+
return { ok: false, error: "Invalid branch name format (invalid slashes)" };
|
|
7051
|
+
}
|
|
7052
|
+
if (name2.includes(" ")) {
|
|
7053
|
+
return { ok: false, error: "Branch name cannot contain spaces" };
|
|
7054
|
+
}
|
|
7055
|
+
if (name2.startsWith("-")) {
|
|
7056
|
+
return { ok: false, error: 'Branch name cannot start with "-"' };
|
|
7057
|
+
}
|
|
7058
|
+
if (name2.startsWith(".") || name2.endsWith(".")) {
|
|
7059
|
+
return { ok: false, error: "Branch name cannot start or end with a dot" };
|
|
7060
|
+
}
|
|
7061
|
+
if (name2.includes("@{")) {
|
|
7062
|
+
return { ok: false, error: 'Branch name cannot contain "@{"' };
|
|
7063
|
+
}
|
|
7064
|
+
if (name2 === "HEAD" || name2 === "@") {
|
|
7065
|
+
return { ok: false, error: 'Branch name cannot be the reserved ref "HEAD" or "@"' };
|
|
7066
|
+
}
|
|
7067
|
+
if (/[~^:?*[\\\x00-\x1f\x7f]/.test(name2)) {
|
|
7068
|
+
return { ok: false, error: "Branch name contains invalid characters" };
|
|
7069
|
+
}
|
|
7070
|
+
if (name2.endsWith(".lock")) {
|
|
7071
|
+
return { ok: false, error: 'Branch name cannot end with ".lock"' };
|
|
7072
|
+
}
|
|
7073
|
+
return { ok: true, name: name2 };
|
|
7074
|
+
}
|
|
7075
|
+
var BASE58_PATTERN, CONTENT_ID_PATTERN, PHYSICAL_SEGMENT_PATTERN, MAX_BRANCH_NAME_LENGTH;
|
|
7076
|
+
var init_validation = __esm({
|
|
7077
|
+
"../canopycms/src/paths/validation.ts"() {
|
|
7078
|
+
"use strict";
|
|
7079
|
+
BASE58_PATTERN = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]";
|
|
7080
|
+
CONTENT_ID_PATTERN = new RegExp(`^${BASE58_PATTERN}{12}$`);
|
|
7081
|
+
PHYSICAL_SEGMENT_PATTERN = new RegExp(`\\.${BASE58_PATTERN}{12}(?:\\.[a-z]+)?$`);
|
|
7082
|
+
MAX_BRANCH_NAME_LENGTH = 250;
|
|
7083
|
+
}
|
|
7084
|
+
});
|
|
7085
|
+
|
|
7016
7086
|
// ../canopycms/src/paths/types.ts
|
|
7017
7087
|
var ROOT_COLLECTION_ID;
|
|
7018
7088
|
var init_types2 = __esm({
|
|
@@ -8258,15 +8328,15 @@ var require_dist_node9 = __commonJS({
|
|
|
8258
8328
|
octokit.log.debug("request", options);
|
|
8259
8329
|
const start = Date.now();
|
|
8260
8330
|
const requestOptions = octokit.request.endpoint.parse(options);
|
|
8261
|
-
const
|
|
8331
|
+
const path36 = requestOptions.url.replace(options.baseUrl, "");
|
|
8262
8332
|
return request(options).then((response) => {
|
|
8263
8333
|
octokit.log.info(
|
|
8264
|
-
`${requestOptions.method} ${
|
|
8334
|
+
`${requestOptions.method} ${path36} - ${response.status} in ${Date.now() - start}ms`
|
|
8265
8335
|
);
|
|
8266
8336
|
return response;
|
|
8267
8337
|
}).catch((error3) => {
|
|
8268
8338
|
octokit.log.info(
|
|
8269
|
-
`${requestOptions.method} ${
|
|
8339
|
+
`${requestOptions.method} ${path36} - ${error3.status} in ${Date.now() - start}ms`
|
|
8270
8340
|
);
|
|
8271
8341
|
throw error3;
|
|
8272
8342
|
});
|
|
@@ -12360,7 +12430,7 @@ var require_dist_node13 = __commonJS({
|
|
|
12360
12430
|
];
|
|
12361
12431
|
function routeMatcher(paths) {
|
|
12362
12432
|
const regexes = paths.map(
|
|
12363
|
-
(
|
|
12433
|
+
(path36) => path36.split("/").map((c11) => c11.startsWith("{") ? "(?:.+?)" : c11).join("/")
|
|
12364
12434
|
);
|
|
12365
12435
|
const regex2 = `^(?:${regexes.map((r10) => `(?:${r10})`).join("|")})[^/]*$`;
|
|
12366
12436
|
return new RegExp(regex2, "i");
|
|
@@ -12530,6 +12600,92 @@ var init_deployment_name = __esm({
|
|
|
12530
12600
|
}
|
|
12531
12601
|
});
|
|
12532
12602
|
|
|
12603
|
+
// ../canopycms/src/operating-mode/branch-namespace.ts
|
|
12604
|
+
function warnOnce(message2) {
|
|
12605
|
+
if (warned2) return;
|
|
12606
|
+
warned2 = true;
|
|
12607
|
+
canopyLogWarn(message2);
|
|
12608
|
+
}
|
|
12609
|
+
function branchNamespaceProblem(namespace) {
|
|
12610
|
+
if (!namespace.endsWith("/")) return 'it must end with "/"';
|
|
12611
|
+
const sample = `${namespace}x`;
|
|
12612
|
+
if (!/^[\x21-\x7e]+$/.test(namespace)) return "it is not printable ASCII without spaces";
|
|
12613
|
+
if (/["%{}]/.test(namespace)) return 'it contains ", %, { or }';
|
|
12614
|
+
if (/^(?:refs|heads|tags|remotes)\//i.test(namespace)) {
|
|
12615
|
+
return "it starts with 'refs/', 'heads/', 'tags/' or 'remotes/'";
|
|
12616
|
+
}
|
|
12617
|
+
const parsed = parseBranchRef(sample);
|
|
12618
|
+
if (!parsed.ok) return `a branch in it would be refused (${parsed.error})`;
|
|
12619
|
+
if (sample.split("/").some((part) => part.startsWith(".") || part.endsWith(".lock"))) {
|
|
12620
|
+
return "a part of it starts with '.' or ends with '.lock'";
|
|
12621
|
+
}
|
|
12622
|
+
const directoryPrefix = sanitizeBranchName(namespace);
|
|
12623
|
+
if (RESERVED_SETTINGS_BRANCH_PREFIX.startsWith(directoryPrefix) || sanitizeBranchName(sample).startsWith(RESERVED_SETTINGS_BRANCH_PREFIX)) {
|
|
12624
|
+
return `some branches in it would be ${RESERVED_SETTINGS_BRANCH_PREFIX}* settings branches`;
|
|
12625
|
+
}
|
|
12626
|
+
return null;
|
|
12627
|
+
}
|
|
12628
|
+
function namespaceAncestors(namespace) {
|
|
12629
|
+
const parts = namespace.split("/").filter(Boolean);
|
|
12630
|
+
return parts.map((_3, i10) => parts.slice(0, i10 + 1).join("/"));
|
|
12631
|
+
}
|
|
12632
|
+
function resolveBranchNamespaceTemplate(template, deploymentName, source) {
|
|
12633
|
+
const unknown = template.replaceAll(DEPLOYMENT_PLACEHOLDER, "").match(/\{[^}]*\}?/);
|
|
12634
|
+
if (unknown) {
|
|
12635
|
+
throw new Error(
|
|
12636
|
+
`CanopyCMS: invalid branch namespace ${JSON.stringify(template)} (from ${source}): ${JSON.stringify(unknown[0])} is not a placeholder; the only one is ${DEPLOYMENT_PLACEHOLDER}`
|
|
12637
|
+
);
|
|
12638
|
+
}
|
|
12639
|
+
const namespace = template.replaceAll(DEPLOYMENT_PLACEHOLDER, deploymentName);
|
|
12640
|
+
const problem = branchNamespaceProblem(namespace);
|
|
12641
|
+
if (problem !== null) {
|
|
12642
|
+
throw new Error(
|
|
12643
|
+
`CanopyCMS: invalid branch namespace ${JSON.stringify(namespace)} (from ${source}): ${problem}`
|
|
12644
|
+
);
|
|
12645
|
+
}
|
|
12646
|
+
return namespace;
|
|
12647
|
+
}
|
|
12648
|
+
function resolveBranchNamespace(config, modeDefault, env2 = process.env) {
|
|
12649
|
+
const fromEnv2 = env2[BRANCH_NAMESPACE_ENV]?.trim();
|
|
12650
|
+
const [template, source] = fromEnv2 ? [fromEnv2, BRANCH_NAMESPACE_ENV] : config.branchNamespace !== void 0 ? [config.branchNamespace, "config.branchNamespace"] : [DEFAULT_BRANCH_NAMESPACE_TEMPLATE, "the default"];
|
|
12651
|
+
const deploymentName = resolveDeploymentName(
|
|
12652
|
+
{ deploymentName: config.deploymentName },
|
|
12653
|
+
modeDefault
|
|
12654
|
+
);
|
|
12655
|
+
const namespace = resolveBranchNamespaceTemplate(template, deploymentName, source);
|
|
12656
|
+
if (fromEnv2 && config.branchNamespace !== void 0) {
|
|
12657
|
+
let fromConfig = null;
|
|
12658
|
+
try {
|
|
12659
|
+
fromConfig = resolveBranchNamespaceTemplate(
|
|
12660
|
+
config.branchNamespace,
|
|
12661
|
+
deploymentName,
|
|
12662
|
+
"config.branchNamespace"
|
|
12663
|
+
);
|
|
12664
|
+
} catch {
|
|
12665
|
+
}
|
|
12666
|
+
if (fromConfig !== namespace) {
|
|
12667
|
+
warnOnce(
|
|
12668
|
+
`CanopyCMS: ${BRANCH_NAMESPACE_ENV} (${JSON.stringify(fromEnv2)}) and config.branchNamespace (${JSON.stringify(config.branchNamespace)}) do not resolve to the same valid namespace; using the environment variable, which infrastructure stamps per stack.`
|
|
12669
|
+
);
|
|
12670
|
+
}
|
|
12671
|
+
}
|
|
12672
|
+
return namespace;
|
|
12673
|
+
}
|
|
12674
|
+
var warned2, DEPLOYMENT_PLACEHOLDER, DEFAULT_BRANCH_NAMESPACE_TEMPLATE, BRANCH_NAMESPACE_ENV;
|
|
12675
|
+
var init_branch_namespace = __esm({
|
|
12676
|
+
"../canopycms/src/operating-mode/branch-namespace.ts"() {
|
|
12677
|
+
"use strict";
|
|
12678
|
+
init_branch_name();
|
|
12679
|
+
init_validation();
|
|
12680
|
+
init_logger();
|
|
12681
|
+
init_deployment_name();
|
|
12682
|
+
warned2 = false;
|
|
12683
|
+
DEPLOYMENT_PLACEHOLDER = "{deployment}";
|
|
12684
|
+
DEFAULT_BRANCH_NAMESPACE_TEMPLATE = `canopycms/${DEPLOYMENT_PLACEHOLDER}/`;
|
|
12685
|
+
BRANCH_NAMESPACE_ENV = "CANOPYCMS_BRANCH_NAMESPACE";
|
|
12686
|
+
}
|
|
12687
|
+
});
|
|
12688
|
+
|
|
12533
12689
|
// ../canopycms/src/task-queue/worker-status.ts
|
|
12534
12690
|
import fs12 from "node:fs/promises";
|
|
12535
12691
|
import path13 from "node:path";
|
|
@@ -13375,9 +13531,9 @@ var init_createPaginator = __esm({
|
|
|
13375
13531
|
command5 = withCommand(command5) ?? command5;
|
|
13376
13532
|
return await client.send(command5, ...args);
|
|
13377
13533
|
};
|
|
13378
|
-
get = (fromObject,
|
|
13534
|
+
get = (fromObject, path36) => {
|
|
13379
13535
|
let cursor3 = fromObject;
|
|
13380
|
-
const pathComponents =
|
|
13536
|
+
const pathComponents = path36.split(".");
|
|
13381
13537
|
for (const step of pathComponents) {
|
|
13382
13538
|
if (!cursor3 || typeof cursor3 !== "object") {
|
|
13383
13539
|
return void 0;
|
|
@@ -14395,12 +14551,12 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
14395
14551
|
const password = request.password ?? "";
|
|
14396
14552
|
auth = `${username}:${password}`;
|
|
14397
14553
|
}
|
|
14398
|
-
let
|
|
14554
|
+
let path36 = request.path;
|
|
14399
14555
|
if (queryString) {
|
|
14400
|
-
|
|
14556
|
+
path36 += `?${queryString}`;
|
|
14401
14557
|
}
|
|
14402
14558
|
if (request.fragment) {
|
|
14403
|
-
|
|
14559
|
+
path36 += `#${request.fragment}`;
|
|
14404
14560
|
}
|
|
14405
14561
|
let hostname = request.hostname ?? "";
|
|
14406
14562
|
if (hostname[0] === "[" && hostname.endsWith("]")) {
|
|
@@ -14412,7 +14568,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
14412
14568
|
headers: request.headers,
|
|
14413
14569
|
host: hostname,
|
|
14414
14570
|
method: request.method,
|
|
14415
|
-
path:
|
|
14571
|
+
path: path36,
|
|
14416
14572
|
port: request.port,
|
|
14417
14573
|
agent,
|
|
14418
14574
|
auth
|
|
@@ -14695,16 +14851,16 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
14695
14851
|
reject(err);
|
|
14696
14852
|
};
|
|
14697
14853
|
const queryString = querystringBuilder.buildQueryString(query || {});
|
|
14698
|
-
let
|
|
14854
|
+
let path36 = request.path;
|
|
14699
14855
|
if (queryString) {
|
|
14700
|
-
|
|
14856
|
+
path36 += `?${queryString}`;
|
|
14701
14857
|
}
|
|
14702
14858
|
if (request.fragment) {
|
|
14703
|
-
|
|
14859
|
+
path36 += `#${request.fragment}`;
|
|
14704
14860
|
}
|
|
14705
14861
|
const req = session.request({
|
|
14706
14862
|
...request.headers,
|
|
14707
|
-
[http2.constants.HTTP2_HEADER_PATH]:
|
|
14863
|
+
[http2.constants.HTTP2_HEADER_PATH]: path36,
|
|
14708
14864
|
[http2.constants.HTTP2_HEADER_METHOD]: method
|
|
14709
14865
|
});
|
|
14710
14866
|
session.ref();
|
|
@@ -14891,13 +15047,13 @@ var require_dist_cjs14 = __commonJS({
|
|
|
14891
15047
|
const abortError = buildAbortError(abortSignal);
|
|
14892
15048
|
return Promise.reject(abortError);
|
|
14893
15049
|
}
|
|
14894
|
-
let
|
|
15050
|
+
let path36 = request.path;
|
|
14895
15051
|
const queryString = querystringBuilder.buildQueryString(request.query || {});
|
|
14896
15052
|
if (queryString) {
|
|
14897
|
-
|
|
15053
|
+
path36 += `?${queryString}`;
|
|
14898
15054
|
}
|
|
14899
15055
|
if (request.fragment) {
|
|
14900
|
-
|
|
15056
|
+
path36 += `#${request.fragment}`;
|
|
14901
15057
|
}
|
|
14902
15058
|
let auth = "";
|
|
14903
15059
|
if (request.username != null || request.password != null) {
|
|
@@ -14906,7 +15062,7 @@ var require_dist_cjs14 = __commonJS({
|
|
|
14906
15062
|
auth = `${username}:${password}@`;
|
|
14907
15063
|
}
|
|
14908
15064
|
const { port, method } = request;
|
|
14909
|
-
const url = `${request.protocol}//${auth}${request.hostname}${port ? `:${port}` : ""}${
|
|
15065
|
+
const url = `${request.protocol}//${auth}${request.hostname}${port ? `:${port}` : ""}${path36}`;
|
|
14910
15066
|
const body = method === "GET" || method === "HEAD" ? void 0 : request.body;
|
|
14911
15067
|
const requestOptions = {
|
|
14912
15068
|
body,
|
|
@@ -17138,13 +17294,13 @@ function __disposeResources(env2) {
|
|
|
17138
17294
|
}
|
|
17139
17295
|
return next();
|
|
17140
17296
|
}
|
|
17141
|
-
function __rewriteRelativeImportExtension(
|
|
17142
|
-
if (typeof
|
|
17143
|
-
return
|
|
17297
|
+
function __rewriteRelativeImportExtension(path36, preserveJsx) {
|
|
17298
|
+
if (typeof path36 === "string" && /^\.\.?\//.test(path36)) {
|
|
17299
|
+
return path36.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m7, tsx, d9, ext, cm) {
|
|
17144
17300
|
return tsx ? preserveJsx ? ".jsx" : ".js" : d9 && (!ext || !cm) ? m7 : d9 + ext + "." + cm.toLowerCase() + "js";
|
|
17145
17301
|
});
|
|
17146
17302
|
}
|
|
17147
|
-
return
|
|
17303
|
+
return path36;
|
|
17148
17304
|
}
|
|
17149
17305
|
var extendStatics, __assign, __createBinding, __setModuleDefault, ownKeys, _SuppressedError, tslib_es6_default;
|
|
17150
17306
|
var init_tslib_es6 = __esm({
|
|
@@ -18042,11 +18198,11 @@ var init_HttpBindingProtocol = __esm({
|
|
|
18042
18198
|
const opTraits = translateTraits(operationSchema.traits);
|
|
18043
18199
|
if (opTraits.http) {
|
|
18044
18200
|
request.method = opTraits.http[0];
|
|
18045
|
-
const [
|
|
18201
|
+
const [path36, search] = opTraits.http[1].split("?");
|
|
18046
18202
|
if (request.path == "/") {
|
|
18047
|
-
request.path =
|
|
18203
|
+
request.path = path36;
|
|
18048
18204
|
} else {
|
|
18049
|
-
request.path +=
|
|
18205
|
+
request.path += path36;
|
|
18050
18206
|
}
|
|
18051
18207
|
const traitSearchParams = new URLSearchParams(search ?? "");
|
|
18052
18208
|
Object.assign(query, Object.fromEntries(traitSearchParams));
|
|
@@ -18449,8 +18605,8 @@ var init_requestBuilder = __esm({
|
|
|
18449
18605
|
return this;
|
|
18450
18606
|
}
|
|
18451
18607
|
p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
|
|
18452
|
-
this.resolvePathStack.push((
|
|
18453
|
-
this.path = resolvedPath(
|
|
18608
|
+
this.resolvePathStack.push((path36) => {
|
|
18609
|
+
this.path = resolvedPath(path36, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
|
|
18454
18610
|
});
|
|
18455
18611
|
return this;
|
|
18456
18612
|
}
|
|
@@ -19100,18 +19256,18 @@ var require_dist_cjs20 = __commonJS({
|
|
|
19100
19256
|
}
|
|
19101
19257
|
};
|
|
19102
19258
|
var booleanEquals2 = (value1, value2) => value1 === value2;
|
|
19103
|
-
var getAttrPathList2 = (
|
|
19104
|
-
const parts =
|
|
19259
|
+
var getAttrPathList2 = (path36) => {
|
|
19260
|
+
const parts = path36.split(".");
|
|
19105
19261
|
const pathList = [];
|
|
19106
19262
|
for (const part of parts) {
|
|
19107
19263
|
const squareBracketIndex = part.indexOf("[");
|
|
19108
19264
|
if (squareBracketIndex !== -1) {
|
|
19109
19265
|
if (part.indexOf("]") !== part.length - 1) {
|
|
19110
|
-
throw new EndpointError2(`Path: '${
|
|
19266
|
+
throw new EndpointError2(`Path: '${path36}' does not end with ']'`);
|
|
19111
19267
|
}
|
|
19112
19268
|
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
|
|
19113
19269
|
if (Number.isNaN(parseInt(arrayIndex))) {
|
|
19114
|
-
throw new EndpointError2(`Invalid array index: '${arrayIndex}' in path: '${
|
|
19270
|
+
throw new EndpointError2(`Invalid array index: '${arrayIndex}' in path: '${path36}'`);
|
|
19115
19271
|
}
|
|
19116
19272
|
if (squareBracketIndex !== 0) {
|
|
19117
19273
|
pathList.push(part.slice(0, squareBracketIndex));
|
|
@@ -19123,9 +19279,9 @@ var require_dist_cjs20 = __commonJS({
|
|
|
19123
19279
|
}
|
|
19124
19280
|
return pathList;
|
|
19125
19281
|
};
|
|
19126
|
-
var getAttr2 = (value,
|
|
19282
|
+
var getAttr2 = (value, path36) => getAttrPathList2(path36).reduce((acc, index) => {
|
|
19127
19283
|
if (typeof acc !== "object") {
|
|
19128
|
-
throw new EndpointError2(`Index '${index}' in '${
|
|
19284
|
+
throw new EndpointError2(`Index '${index}' in '${path36}' not found in '${JSON.stringify(value)}'`);
|
|
19129
19285
|
} else if (Array.isArray(acc)) {
|
|
19130
19286
|
return acc[parseInt(index)];
|
|
19131
19287
|
}
|
|
@@ -19144,8 +19300,8 @@ var require_dist_cjs20 = __commonJS({
|
|
|
19144
19300
|
return value;
|
|
19145
19301
|
}
|
|
19146
19302
|
if (typeof value === "object" && "hostname" in value) {
|
|
19147
|
-
const { hostname: hostname2, port, protocol: protocol2 = "", path:
|
|
19148
|
-
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${
|
|
19303
|
+
const { hostname: hostname2, port, protocol: protocol2 = "", path: path36 = "", query = {} } = value;
|
|
19304
|
+
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${path36}`);
|
|
19149
19305
|
url.search = Object.entries(query).map(([k10, v5]) => `${k10}=${v5}`).join("&");
|
|
19150
19306
|
return url;
|
|
19151
19307
|
}
|
|
@@ -20590,10 +20746,10 @@ ${longDate}
|
|
|
20590
20746
|
${credentialScope}
|
|
20591
20747
|
${utilHexEncoding.toHex(hashedRequest)}`;
|
|
20592
20748
|
}
|
|
20593
|
-
getCanonicalPath({ path:
|
|
20749
|
+
getCanonicalPath({ path: path36 }) {
|
|
20594
20750
|
if (this.uriEscapePath) {
|
|
20595
20751
|
const normalizedPathSegments = [];
|
|
20596
|
-
for (const pathSegment of
|
|
20752
|
+
for (const pathSegment of path36.split("/")) {
|
|
20597
20753
|
if (pathSegment?.length === 0)
|
|
20598
20754
|
continue;
|
|
20599
20755
|
if (pathSegment === ".")
|
|
@@ -20604,11 +20760,11 @@ ${utilHexEncoding.toHex(hashedRequest)}`;
|
|
|
20604
20760
|
normalizedPathSegments.push(pathSegment);
|
|
20605
20761
|
}
|
|
20606
20762
|
}
|
|
20607
|
-
const normalizedPath = `${
|
|
20763
|
+
const normalizedPath = `${path36?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path36?.endsWith("/") ? "/" : ""}`;
|
|
20608
20764
|
const doubleEncoded = utilUriEscape.escapeUri(normalizedPath);
|
|
20609
20765
|
return doubleEncoded.replace(/%2F/g, "/");
|
|
20610
20766
|
}
|
|
20611
|
-
return
|
|
20767
|
+
return path36;
|
|
20612
20768
|
}
|
|
20613
20769
|
validateResolvedCredentials(credentials) {
|
|
20614
20770
|
if (typeof credentials !== "object" || typeof credentials.accessKeyId !== "string" || typeof credentials.secretAccessKey !== "string") {
|
|
@@ -21912,11 +22068,11 @@ var init_SmithyRpcV2CborProtocol = __esm({
|
|
|
21912
22068
|
}
|
|
21913
22069
|
}
|
|
21914
22070
|
const { service, operation: operation3 } = (0, import_util_middleware5.getSmithyContext)(context);
|
|
21915
|
-
const
|
|
22071
|
+
const path36 = `/service/${service}/operation/${operation3}`;
|
|
21916
22072
|
if (request.path.endsWith("/")) {
|
|
21917
|
-
request.path +=
|
|
22073
|
+
request.path += path36.slice(1);
|
|
21918
22074
|
} else {
|
|
21919
|
-
request.path +=
|
|
22075
|
+
request.path += path36;
|
|
21920
22076
|
}
|
|
21921
22077
|
return request;
|
|
21922
22078
|
}
|
|
@@ -27561,14 +27717,14 @@ var require_readFile = __commonJS({
|
|
|
27561
27717
|
var promises_1 = __require("node:fs/promises");
|
|
27562
27718
|
exports.filePromises = {};
|
|
27563
27719
|
exports.fileIntercept = {};
|
|
27564
|
-
var readFile3 = (
|
|
27565
|
-
if (exports.fileIntercept[
|
|
27566
|
-
return exports.fileIntercept[
|
|
27720
|
+
var readFile3 = (path36, options) => {
|
|
27721
|
+
if (exports.fileIntercept[path36] !== void 0) {
|
|
27722
|
+
return exports.fileIntercept[path36];
|
|
27567
27723
|
}
|
|
27568
|
-
if (!exports.filePromises[
|
|
27569
|
-
exports.filePromises[
|
|
27724
|
+
if (!exports.filePromises[path36] || options?.ignoreCache) {
|
|
27725
|
+
exports.filePromises[path36] = (0, promises_1.readFile)(path36, "utf8");
|
|
27570
27726
|
}
|
|
27571
|
-
return exports.filePromises[
|
|
27727
|
+
return exports.filePromises[path36];
|
|
27572
27728
|
};
|
|
27573
27729
|
exports.readFile = readFile3;
|
|
27574
27730
|
}
|
|
@@ -27581,7 +27737,7 @@ var require_dist_cjs33 = __commonJS({
|
|
|
27581
27737
|
var getHomeDir2 = require_getHomeDir();
|
|
27582
27738
|
var getSSOTokenFilepath2 = require_getSSOTokenFilepath();
|
|
27583
27739
|
var getSSOTokenFromFile2 = require_getSSOTokenFromFile();
|
|
27584
|
-
var
|
|
27740
|
+
var path36 = __require("path");
|
|
27585
27741
|
var types = require_dist_cjs();
|
|
27586
27742
|
var readFile3 = require_readFile();
|
|
27587
27743
|
var ENV_PROFILE2 = "AWS_PROFILE";
|
|
@@ -27603,9 +27759,9 @@ var require_dist_cjs33 = __commonJS({
|
|
|
27603
27759
|
...data3.default && { default: data3.default }
|
|
27604
27760
|
});
|
|
27605
27761
|
var ENV_CONFIG_PATH2 = "AWS_CONFIG_FILE";
|
|
27606
|
-
var getConfigFilepath2 = () => process.env[ENV_CONFIG_PATH2] ||
|
|
27762
|
+
var getConfigFilepath2 = () => process.env[ENV_CONFIG_PATH2] || path36.join(getHomeDir2.getHomeDir(), ".aws", "config");
|
|
27607
27763
|
var ENV_CREDENTIALS_PATH2 = "AWS_SHARED_CREDENTIALS_FILE";
|
|
27608
|
-
var getCredentialsFilepath2 = () => process.env[ENV_CREDENTIALS_PATH2] ||
|
|
27764
|
+
var getCredentialsFilepath2 = () => process.env[ENV_CREDENTIALS_PATH2] || path36.join(getHomeDir2.getHomeDir(), ".aws", "credentials");
|
|
27609
27765
|
var prefixKeyRegex2 = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
|
|
27610
27766
|
var profileNameBlockList2 = ["__proto__", "profile __proto__"];
|
|
27611
27767
|
var parseIni2 = (iniData) => {
|
|
@@ -27660,11 +27816,11 @@ var require_dist_cjs33 = __commonJS({
|
|
|
27660
27816
|
const relativeHomeDirPrefix = "~/";
|
|
27661
27817
|
let resolvedFilepath = filepath;
|
|
27662
27818
|
if (filepath.startsWith(relativeHomeDirPrefix)) {
|
|
27663
|
-
resolvedFilepath =
|
|
27819
|
+
resolvedFilepath = path36.join(homeDir, filepath.slice(2));
|
|
27664
27820
|
}
|
|
27665
27821
|
let resolvedConfigFilepath = configFilepath;
|
|
27666
27822
|
if (configFilepath.startsWith(relativeHomeDirPrefix)) {
|
|
27667
|
-
resolvedConfigFilepath =
|
|
27823
|
+
resolvedConfigFilepath = path36.join(homeDir, configFilepath.slice(2));
|
|
27668
27824
|
}
|
|
27669
27825
|
const parsedFiles = await Promise.all([
|
|
27670
27826
|
readFile3.readFile(resolvedConfigFilepath, {
|
|
@@ -27703,8 +27859,8 @@ var require_dist_cjs33 = __commonJS({
|
|
|
27703
27859
|
getFileRecord() {
|
|
27704
27860
|
return readFile3.fileIntercept;
|
|
27705
27861
|
},
|
|
27706
|
-
interceptFile(
|
|
27707
|
-
readFile3.fileIntercept[
|
|
27862
|
+
interceptFile(path37, contents) {
|
|
27863
|
+
readFile3.fileIntercept[path37] = Promise.resolve(contents);
|
|
27708
27864
|
},
|
|
27709
27865
|
getTokenRecord() {
|
|
27710
27866
|
return getSSOTokenFromFile2.tokenIntercept;
|
|
@@ -28029,8 +28185,8 @@ var require_dist_cjs36 = __commonJS({
|
|
|
28029
28185
|
return endpoint.url.href;
|
|
28030
28186
|
}
|
|
28031
28187
|
if ("hostname" in endpoint) {
|
|
28032
|
-
const { protocol, hostname, port, path:
|
|
28033
|
-
return `${protocol}//${hostname}${port ? ":" + port : ""}${
|
|
28188
|
+
const { protocol, hostname, port, path: path36 } = endpoint;
|
|
28189
|
+
return `${protocol}//${hostname}${port ? ":" + port : ""}${path36}`;
|
|
28034
28190
|
}
|
|
28035
28191
|
}
|
|
28036
28192
|
return endpoint;
|
|
@@ -38064,14 +38220,14 @@ var init_readFile = __esm({
|
|
|
38064
38220
|
"../../node_modules/.pnpm/@smithy+core@3.29.7/node_modules/@smithy/core/dist-es/submodules/config/shared-ini-file-loader/readFile.js"() {
|
|
38065
38221
|
filePromises = {};
|
|
38066
38222
|
fileIntercept = {};
|
|
38067
|
-
readFile2 = (
|
|
38068
|
-
if (fileIntercept[
|
|
38069
|
-
return fileIntercept[
|
|
38223
|
+
readFile2 = (path36, options) => {
|
|
38224
|
+
if (fileIntercept[path36] !== void 0) {
|
|
38225
|
+
return fileIntercept[path36];
|
|
38070
38226
|
}
|
|
38071
|
-
if (!filePromises[
|
|
38072
|
-
filePromises[
|
|
38227
|
+
if (!filePromises[path36] || options?.ignoreCache) {
|
|
38228
|
+
filePromises[path36] = fsReadFile(path36, "utf8");
|
|
38073
38229
|
}
|
|
38074
|
-
return filePromises[
|
|
38230
|
+
return filePromises[path36];
|
|
38075
38231
|
};
|
|
38076
38232
|
}
|
|
38077
38233
|
});
|
|
@@ -38183,8 +38339,8 @@ var init_externalDataInterceptor = __esm({
|
|
|
38183
38339
|
getFileRecord() {
|
|
38184
38340
|
return fileIntercept;
|
|
38185
38341
|
},
|
|
38186
|
-
interceptFile(
|
|
38187
|
-
fileIntercept[
|
|
38342
|
+
interceptFile(path36, contents) {
|
|
38343
|
+
fileIntercept[path36] = Promise.resolve(contents);
|
|
38188
38344
|
},
|
|
38189
38345
|
getTokenRecord() {
|
|
38190
38346
|
return tokenIntercept;
|
|
@@ -41118,8 +41274,8 @@ var init_createConfigValueProvider = __esm({
|
|
|
41118
41274
|
return endpoint.url.href;
|
|
41119
41275
|
}
|
|
41120
41276
|
if ("hostname" in endpoint) {
|
|
41121
|
-
const { protocol, hostname, port, path:
|
|
41122
|
-
return `${protocol}//${hostname}${port ? ":" + port : ""}${
|
|
41277
|
+
const { protocol, hostname, port, path: path36 } = endpoint;
|
|
41278
|
+
return `${protocol}//${hostname}${port ? ":" + port : ""}${path36}`;
|
|
41123
41279
|
}
|
|
41124
41280
|
}
|
|
41125
41281
|
return endpoint;
|
|
@@ -41494,18 +41650,18 @@ var getAttrPathList;
|
|
|
41494
41650
|
var init_getAttrPathList = __esm({
|
|
41495
41651
|
"../../node_modules/.pnpm/@smithy+core@3.29.7/node_modules/@smithy/core/dist-es/submodules/endpoints/util-endpoints/lib/getAttrPathList.js"() {
|
|
41496
41652
|
init_types4();
|
|
41497
|
-
getAttrPathList = (
|
|
41498
|
-
const parts =
|
|
41653
|
+
getAttrPathList = (path36) => {
|
|
41654
|
+
const parts = path36.split(".");
|
|
41499
41655
|
const pathList = [];
|
|
41500
41656
|
for (const part of parts) {
|
|
41501
41657
|
const squareBracketIndex = part.indexOf("[");
|
|
41502
41658
|
if (squareBracketIndex !== -1) {
|
|
41503
41659
|
if (part.indexOf("]") !== part.length - 1) {
|
|
41504
|
-
throw new EndpointError(`Path: '${
|
|
41660
|
+
throw new EndpointError(`Path: '${path36}' does not end with ']'`);
|
|
41505
41661
|
}
|
|
41506
41662
|
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
|
|
41507
41663
|
if (Number.isNaN(parseInt(arrayIndex))) {
|
|
41508
|
-
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${
|
|
41664
|
+
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path36}'`);
|
|
41509
41665
|
}
|
|
41510
41666
|
if (squareBracketIndex !== 0) {
|
|
41511
41667
|
pathList.push(part.slice(0, squareBracketIndex));
|
|
@@ -41526,9 +41682,9 @@ var init_getAttr = __esm({
|
|
|
41526
41682
|
"../../node_modules/.pnpm/@smithy+core@3.29.7/node_modules/@smithy/core/dist-es/submodules/endpoints/util-endpoints/lib/getAttr.js"() {
|
|
41527
41683
|
init_types4();
|
|
41528
41684
|
init_getAttrPathList();
|
|
41529
|
-
getAttr = (value,
|
|
41685
|
+
getAttr = (value, path36) => getAttrPathList(path36).reduce((acc, index) => {
|
|
41530
41686
|
if (typeof acc !== "object") {
|
|
41531
|
-
throw new EndpointError(`Index '${index}' in '${
|
|
41687
|
+
throw new EndpointError(`Index '${index}' in '${path36}' not found in '${JSON.stringify(value)}'`);
|
|
41532
41688
|
} else if (Array.isArray(acc)) {
|
|
41533
41689
|
const i10 = parseInt(index);
|
|
41534
41690
|
return acc[i10 < 0 ? acc.length + i10 : i10];
|
|
@@ -41589,8 +41745,8 @@ var init_parseURL = __esm({
|
|
|
41589
41745
|
return value;
|
|
41590
41746
|
}
|
|
41591
41747
|
if (typeof value === "object" && "hostname" in value) {
|
|
41592
|
-
const { hostname: hostname2, port, protocol: protocol2 = "", path:
|
|
41593
|
-
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${
|
|
41748
|
+
const { hostname: hostname2, port, protocol: protocol2 = "", path: path36 = "", query = {} } = value;
|
|
41749
|
+
const url = new URL(`${protocol2}//${hostname2}${port ? `:${port}` : ""}${path36}`);
|
|
41594
41750
|
url.search = Object.entries(query).map(([k10, v5]) => `${k10}=${v5}`).join("&");
|
|
41595
41751
|
return url;
|
|
41596
41752
|
}
|
|
@@ -44827,11 +44983,11 @@ var init_HttpBindingProtocol2 = __esm({
|
|
|
44827
44983
|
const opTraits = translateTraits2(operationSchema.traits);
|
|
44828
44984
|
if (opTraits.http) {
|
|
44829
44985
|
request.method = opTraits.http[0];
|
|
44830
|
-
const [
|
|
44986
|
+
const [path36, search] = opTraits.http[1].split("?");
|
|
44831
44987
|
if (request.path == "/") {
|
|
44832
|
-
request.path =
|
|
44988
|
+
request.path = path36;
|
|
44833
44989
|
} else {
|
|
44834
|
-
request.path +=
|
|
44990
|
+
request.path += path36;
|
|
44835
44991
|
}
|
|
44836
44992
|
const traitSearchParams = new URLSearchParams(search ?? "");
|
|
44837
44993
|
for (const [key, value] of traitSearchParams) {
|
|
@@ -45232,8 +45388,8 @@ var init_requestBuilder3 = __esm({
|
|
|
45232
45388
|
return this;
|
|
45233
45389
|
}
|
|
45234
45390
|
p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
|
|
45235
|
-
this.resolvePathStack.push((
|
|
45236
|
-
this.path = resolvedPath2(
|
|
45391
|
+
this.resolvePathStack.push((path36) => {
|
|
45392
|
+
this.path = resolvedPath2(path36, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
|
|
45237
45393
|
});
|
|
45238
45394
|
return this;
|
|
45239
45395
|
}
|
|
@@ -45872,9 +46028,9 @@ var init_createPaginator2 = __esm({
|
|
|
45872
46028
|
command5 = withCommand(command5) ?? command5;
|
|
45873
46029
|
return await client.send(command5, ...args);
|
|
45874
46030
|
};
|
|
45875
|
-
get2 = (fromObject,
|
|
46031
|
+
get2 = (fromObject, path36) => {
|
|
45876
46032
|
let cursor3 = fromObject;
|
|
45877
|
-
const pathComponents =
|
|
46033
|
+
const pathComponents = path36.split(".");
|
|
45878
46034
|
for (const step of pathComponents) {
|
|
45879
46035
|
if (!cursor3 || typeof cursor3 !== "object") {
|
|
45880
46036
|
return void 0;
|
|
@@ -49445,10 +49601,10 @@ ${longDate}
|
|
|
49445
49601
|
${credentialScope}
|
|
49446
49602
|
${toHex2(hashedRequest)}`;
|
|
49447
49603
|
}
|
|
49448
|
-
getCanonicalPath({ path:
|
|
49604
|
+
getCanonicalPath({ path: path36 }) {
|
|
49449
49605
|
if (this.uriEscapePath) {
|
|
49450
49606
|
const normalizedPathSegments = [];
|
|
49451
|
-
for (const pathSegment of
|
|
49607
|
+
for (const pathSegment of path36.split("/")) {
|
|
49452
49608
|
if (pathSegment?.length === 0)
|
|
49453
49609
|
continue;
|
|
49454
49610
|
if (pathSegment === ".")
|
|
@@ -49459,11 +49615,11 @@ ${toHex2(hashedRequest)}`;
|
|
|
49459
49615
|
normalizedPathSegments.push(pathSegment);
|
|
49460
49616
|
}
|
|
49461
49617
|
}
|
|
49462
|
-
const normalizedPath = `${
|
|
49618
|
+
const normalizedPath = `${path36?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path36?.endsWith("/") ? "/" : ""}`;
|
|
49463
49619
|
const doubleEncoded = escapeUri2(normalizedPath);
|
|
49464
49620
|
return doubleEncoded.replace(/%2F/g, "/");
|
|
49465
49621
|
}
|
|
49466
|
-
return
|
|
49622
|
+
return path36;
|
|
49467
49623
|
}
|
|
49468
49624
|
validateResolvedCredentials(credentials) {
|
|
49469
49625
|
if (typeof credentials !== "object" || typeof credentials.accessKeyId !== "string" || typeof credentials.secretAccessKey !== "string") {
|
|
@@ -51032,11 +51188,11 @@ var init_SmithyRpcV2CborProtocol2 = __esm({
|
|
|
51032
51188
|
}
|
|
51033
51189
|
}
|
|
51034
51190
|
const { service, operation: operation3 } = getSmithyContext11(context);
|
|
51035
|
-
const
|
|
51191
|
+
const path36 = `/service/${service}/operation/${operation3}`;
|
|
51036
51192
|
if (request.path.endsWith("/")) {
|
|
51037
|
-
request.path +=
|
|
51193
|
+
request.path += path36.slice(1);
|
|
51038
51194
|
} else {
|
|
51039
|
-
request.path +=
|
|
51195
|
+
request.path += path36;
|
|
51040
51196
|
}
|
|
51041
51197
|
return request;
|
|
51042
51198
|
}
|
|
@@ -54440,12 +54596,12 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
54440
54596
|
const password = request.password ?? "";
|
|
54441
54597
|
auth = `${username}:${password}`;
|
|
54442
54598
|
}
|
|
54443
|
-
let
|
|
54599
|
+
let path36 = request.path;
|
|
54444
54600
|
if (queryString) {
|
|
54445
|
-
|
|
54601
|
+
path36 += `?${queryString}`;
|
|
54446
54602
|
}
|
|
54447
54603
|
if (request.fragment) {
|
|
54448
|
-
|
|
54604
|
+
path36 += `#${request.fragment}`;
|
|
54449
54605
|
}
|
|
54450
54606
|
let hostname = request.hostname ?? "";
|
|
54451
54607
|
if (hostname[0] === "[" && hostname.endsWith("]")) {
|
|
@@ -54457,7 +54613,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
54457
54613
|
headers: request.headers,
|
|
54458
54614
|
host: hostname,
|
|
54459
54615
|
method: request.method,
|
|
54460
|
-
path:
|
|
54616
|
+
path: path36,
|
|
54461
54617
|
port: request.port,
|
|
54462
54618
|
agent,
|
|
54463
54619
|
auth
|
|
@@ -54860,16 +55016,16 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
54860
55016
|
reject(err);
|
|
54861
55017
|
};
|
|
54862
55018
|
const queryString = query ? buildQueryString2(query) : "";
|
|
54863
|
-
let
|
|
55019
|
+
let path36 = request.path;
|
|
54864
55020
|
if (queryString) {
|
|
54865
|
-
|
|
55021
|
+
path36 += `?${queryString}`;
|
|
54866
55022
|
}
|
|
54867
55023
|
if (request.fragment) {
|
|
54868
|
-
|
|
55024
|
+
path36 += `#${request.fragment}`;
|
|
54869
55025
|
}
|
|
54870
55026
|
const clientHttp2Stream = session.request({
|
|
54871
55027
|
...request.headers,
|
|
54872
|
-
[constants2.HTTP2_HEADER_PATH]:
|
|
55028
|
+
[constants2.HTTP2_HEADER_PATH]: path36,
|
|
54873
55029
|
[constants2.HTTP2_HEADER_METHOD]: method
|
|
54874
55030
|
});
|
|
54875
55031
|
if (effectiveRequestTimeout) {
|
|
@@ -54951,7 +55107,7 @@ var require_dist_cjs60 = __commonJS({
|
|
|
54951
55107
|
var { setCredentialFeature: setCredentialFeature3 } = (init_client4(), __toCommonJS(client_exports3));
|
|
54952
55108
|
var { CredentialsProviderError: CredentialsProviderError2 } = (init_config3(), __toCommonJS(config_exports));
|
|
54953
55109
|
var { NodeHttpHandler } = require_dist_cjs59();
|
|
54954
|
-
var
|
|
55110
|
+
var fs33 = __require("node:fs/promises");
|
|
54955
55111
|
var { HttpRequest: HttpRequest11 } = (init_protocols3(), __toCommonJS(protocols_exports3));
|
|
54956
55112
|
var { sdkStreamMixin: sdkStreamMixin4, parseRfc3339DateTime: parseRfc3339DateTime3 } = (init_serde2(), __toCommonJS(serde_exports2));
|
|
54957
55113
|
var ECS_CONTAINER_HOST = "169.254.170.2";
|
|
@@ -55075,7 +55231,7 @@ Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
|
|
|
55075
55231
|
const provider = retryWrapper(async () => {
|
|
55076
55232
|
const request = createGetRequest(url);
|
|
55077
55233
|
if (tokenFile) {
|
|
55078
|
-
request.headers.Authorization = validateToken((await
|
|
55234
|
+
request.headers.Authorization = validateToken((await fs33.readFile(tokenFile)).toString());
|
|
55079
55235
|
} else if (token) {
|
|
55080
55236
|
request.headers.Authorization = validateToken(token);
|
|
55081
55237
|
}
|
|
@@ -71319,7 +71475,7 @@ var require_commonjs = __commonJS({
|
|
|
71319
71475
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71320
71476
|
exports.LRUCache = void 0;
|
|
71321
71477
|
var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
71322
|
-
var
|
|
71478
|
+
var warned3 = /* @__PURE__ */ new Set();
|
|
71323
71479
|
var PROCESS = typeof process === "object" && !!process ? process : {};
|
|
71324
71480
|
var emitWarning = (msg, type, code, fn) => {
|
|
71325
71481
|
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
@@ -71360,7 +71516,7 @@ var require_commonjs = __commonJS({
|
|
|
71360
71516
|
emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
|
|
71361
71517
|
};
|
|
71362
71518
|
}
|
|
71363
|
-
var shouldWarn = (code) => !
|
|
71519
|
+
var shouldWarn = (code) => !warned3.has(code);
|
|
71364
71520
|
var TYPE = Symbol("type");
|
|
71365
71521
|
var isPosInt = (n7) => n7 && n7 === Math.floor(n7) && n7 > 0 && isFinite(n7);
|
|
71366
71522
|
var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
|
|
@@ -71654,7 +71810,7 @@ var require_commonjs = __commonJS({
|
|
|
71654
71810
|
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
|
71655
71811
|
const code = "LRU_CACHE_UNBOUNDED";
|
|
71656
71812
|
if (shouldWarn(code)) {
|
|
71657
|
-
|
|
71813
|
+
warned3.add(code);
|
|
71658
71814
|
const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
|
|
71659
71815
|
emitWarning(msg, "UnboundedCacheWarning", code, _LRUCache);
|
|
71660
71816
|
}
|
|
@@ -73157,9 +73313,9 @@ var require_dist_node20 = __commonJS({
|
|
|
73157
73313
|
// ../canopycms/src/worker/cms-worker.ts
|
|
73158
73314
|
var import_proper_lockfile3 = __toESM(require_proper_lockfile(), 1);
|
|
73159
73315
|
import { createHash as createHash2 } from "node:crypto";
|
|
73160
|
-
import
|
|
73316
|
+
import fs31 from "node:fs/promises";
|
|
73161
73317
|
import os from "node:os";
|
|
73162
|
-
import
|
|
73318
|
+
import path33 from "node:path";
|
|
73163
73319
|
|
|
73164
73320
|
// ../canopycms/src/utils/debug.ts
|
|
73165
73321
|
var envFlag = (name2) => typeof process !== "undefined" && process.env[name2] === "true";
|
|
@@ -74344,8 +74500,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
74344
74500
|
function forEachLineWithContent(input, callback) {
|
|
74345
74501
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
74346
74502
|
}
|
|
74347
|
-
function folderExists(
|
|
74348
|
-
return (0, import_file_exists.exists)(
|
|
74503
|
+
function folderExists(path36) {
|
|
74504
|
+
return (0, import_file_exists.exists)(path36, import_file_exists.FOLDER);
|
|
74349
74505
|
}
|
|
74350
74506
|
function append(target, item) {
|
|
74351
74507
|
if (Array.isArray(target)) {
|
|
@@ -74747,8 +74903,8 @@ function checkIsRepoRootTask() {
|
|
|
74747
74903
|
commands: commands9,
|
|
74748
74904
|
format: "utf-8",
|
|
74749
74905
|
onError,
|
|
74750
|
-
parser(
|
|
74751
|
-
return /^\.(git)?$/.test(
|
|
74906
|
+
parser(path36) {
|
|
74907
|
+
return /^\.(git)?$/.test(path36.trim());
|
|
74752
74908
|
}
|
|
74753
74909
|
};
|
|
74754
74910
|
}
|
|
@@ -75182,11 +75338,11 @@ function parseGrep(grep) {
|
|
|
75182
75338
|
const paths = /* @__PURE__ */ new Set();
|
|
75183
75339
|
const results = {};
|
|
75184
75340
|
forEachLineWithContent(grep, (input) => {
|
|
75185
|
-
const [
|
|
75186
|
-
paths.add(
|
|
75187
|
-
(results[
|
|
75341
|
+
const [path36, line, preview] = input.split(NULL);
|
|
75342
|
+
paths.add(path36);
|
|
75343
|
+
(results[path36] = results[path36] || []).push({
|
|
75188
75344
|
line: asNumber(line),
|
|
75189
|
-
path:
|
|
75345
|
+
path: path36,
|
|
75190
75346
|
preview
|
|
75191
75347
|
});
|
|
75192
75348
|
});
|
|
@@ -75950,14 +76106,14 @@ var init_hash_object = __esm2({
|
|
|
75950
76106
|
init_task();
|
|
75951
76107
|
}
|
|
75952
76108
|
});
|
|
75953
|
-
function parseInit(bare,
|
|
76109
|
+
function parseInit(bare, path36, text) {
|
|
75954
76110
|
const response = String(text).trim();
|
|
75955
76111
|
let result;
|
|
75956
76112
|
if (result = initResponseRegex.exec(response)) {
|
|
75957
|
-
return new InitSummary(bare,
|
|
76113
|
+
return new InitSummary(bare, path36, false, result[1]);
|
|
75958
76114
|
}
|
|
75959
76115
|
if (result = reInitResponseRegex.exec(response)) {
|
|
75960
|
-
return new InitSummary(bare,
|
|
76116
|
+
return new InitSummary(bare, path36, true, result[1]);
|
|
75961
76117
|
}
|
|
75962
76118
|
let gitDir = "";
|
|
75963
76119
|
const tokens = response.split(" ");
|
|
@@ -75968,7 +76124,7 @@ function parseInit(bare, path35, text) {
|
|
|
75968
76124
|
break;
|
|
75969
76125
|
}
|
|
75970
76126
|
}
|
|
75971
|
-
return new InitSummary(bare,
|
|
76127
|
+
return new InitSummary(bare, path36, /^re/i.test(response), gitDir);
|
|
75972
76128
|
}
|
|
75973
76129
|
var InitSummary;
|
|
75974
76130
|
var initResponseRegex;
|
|
@@ -75977,9 +76133,9 @@ var init_InitSummary = __esm2({
|
|
|
75977
76133
|
"src/lib/responses/InitSummary.ts"() {
|
|
75978
76134
|
"use strict";
|
|
75979
76135
|
InitSummary = class {
|
|
75980
|
-
constructor(bare,
|
|
76136
|
+
constructor(bare, path36, existing, gitDir) {
|
|
75981
76137
|
this.bare = bare;
|
|
75982
|
-
this.path =
|
|
76138
|
+
this.path = path36;
|
|
75983
76139
|
this.existing = existing;
|
|
75984
76140
|
this.gitDir = gitDir;
|
|
75985
76141
|
}
|
|
@@ -75991,7 +76147,7 @@ var init_InitSummary = __esm2({
|
|
|
75991
76147
|
function hasBareCommand(command5) {
|
|
75992
76148
|
return command5.includes(bareCommand);
|
|
75993
76149
|
}
|
|
75994
|
-
function initTask(bare = false,
|
|
76150
|
+
function initTask(bare = false, path36, customArgs) {
|
|
75995
76151
|
const commands9 = ["init", ...customArgs];
|
|
75996
76152
|
if (bare && !hasBareCommand(commands9)) {
|
|
75997
76153
|
commands9.splice(1, 0, bareCommand);
|
|
@@ -76000,7 +76156,7 @@ function initTask(bare = false, path35, customArgs) {
|
|
|
76000
76156
|
commands: commands9,
|
|
76001
76157
|
format: "utf-8",
|
|
76002
76158
|
parser(text) {
|
|
76003
|
-
return parseInit(commands9.includes("--bare"),
|
|
76159
|
+
return parseInit(commands9.includes("--bare"), path36, text);
|
|
76004
76160
|
}
|
|
76005
76161
|
};
|
|
76006
76162
|
}
|
|
@@ -76815,12 +76971,12 @@ var init_FileStatusSummary = __esm2({
|
|
|
76815
76971
|
"use strict";
|
|
76816
76972
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
76817
76973
|
FileStatusSummary = class {
|
|
76818
|
-
constructor(
|
|
76819
|
-
this.path =
|
|
76974
|
+
constructor(path36, index, working_dir) {
|
|
76975
|
+
this.path = path36;
|
|
76820
76976
|
this.index = index;
|
|
76821
76977
|
this.working_dir = working_dir;
|
|
76822
76978
|
if (index === "R" || working_dir === "R") {
|
|
76823
|
-
const detail = fromPathRegex.exec(
|
|
76979
|
+
const detail = fromPathRegex.exec(path36) || [null, path36, path36];
|
|
76824
76980
|
this.from = detail[2] || "";
|
|
76825
76981
|
this.path = detail[1] || "";
|
|
76826
76982
|
}
|
|
@@ -76851,14 +77007,14 @@ function splitLine(result, lineStr) {
|
|
|
76851
77007
|
default:
|
|
76852
77008
|
return;
|
|
76853
77009
|
}
|
|
76854
|
-
function data3(index, workingDir,
|
|
77010
|
+
function data3(index, workingDir, path36) {
|
|
76855
77011
|
const raw = `${index}${workingDir}`;
|
|
76856
77012
|
const handler = parsers6.get(raw);
|
|
76857
77013
|
if (handler) {
|
|
76858
|
-
handler(result,
|
|
77014
|
+
handler(result, path36);
|
|
76859
77015
|
}
|
|
76860
77016
|
if (raw !== "##" && raw !== "!!") {
|
|
76861
|
-
result.files.push(new FileStatusSummary(
|
|
77017
|
+
result.files.push(new FileStatusSummary(path36, index, workingDir));
|
|
76862
77018
|
}
|
|
76863
77019
|
}
|
|
76864
77020
|
}
|
|
@@ -77209,9 +77365,9 @@ var init_simple_git_api = __esm2({
|
|
|
77209
77365
|
next
|
|
77210
77366
|
);
|
|
77211
77367
|
}
|
|
77212
|
-
hashObject(
|
|
77368
|
+
hashObject(path36, write) {
|
|
77213
77369
|
return this._runTask(
|
|
77214
|
-
hashObjectTask(
|
|
77370
|
+
hashObjectTask(path36, write === true),
|
|
77215
77371
|
trailingFunctionArgument(arguments)
|
|
77216
77372
|
);
|
|
77217
77373
|
}
|
|
@@ -77565,8 +77721,8 @@ var init_branch = __esm2({
|
|
|
77565
77721
|
}
|
|
77566
77722
|
});
|
|
77567
77723
|
function toPath(input) {
|
|
77568
|
-
const
|
|
77569
|
-
return
|
|
77724
|
+
const path36 = input.trim().replace(/^["']|["']$/g, "");
|
|
77725
|
+
return path36 && normalize(path36);
|
|
77570
77726
|
}
|
|
77571
77727
|
var parseCheckIgnore;
|
|
77572
77728
|
var init_CheckIgnore = __esm2({
|
|
@@ -77851,8 +78007,8 @@ __export2(sub_module_exports, {
|
|
|
77851
78007
|
subModuleTask: () => subModuleTask,
|
|
77852
78008
|
updateSubModuleTask: () => updateSubModuleTask
|
|
77853
78009
|
});
|
|
77854
|
-
function addSubModuleTask(repo,
|
|
77855
|
-
return subModuleTask(["add", repo,
|
|
78010
|
+
function addSubModuleTask(repo, path36) {
|
|
78011
|
+
return subModuleTask(["add", repo, path36]);
|
|
77856
78012
|
}
|
|
77857
78013
|
function initSubModuleTask(customArgs) {
|
|
77858
78014
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -78166,8 +78322,8 @@ var require_git = __commonJS2({
|
|
|
78166
78322
|
}
|
|
78167
78323
|
return this._runTask(straightThroughStringTask2(command5, this._trimmed), next);
|
|
78168
78324
|
};
|
|
78169
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
78170
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
78325
|
+
Git2.prototype.submoduleAdd = function(repo, path36, then) {
|
|
78326
|
+
return this._runTask(addSubModuleTask2(repo, path36), trailingFunctionArgument2(arguments));
|
|
78171
78327
|
};
|
|
78172
78328
|
Git2.prototype.submoduleUpdate = function(args, then) {
|
|
78173
78329
|
return this._runTask(
|
|
@@ -78784,16 +78940,7 @@ function isGenerationCurrent(snapshotToken, read) {
|
|
|
78784
78940
|
|
|
78785
78941
|
// ../canopycms/src/id.ts
|
|
78786
78942
|
var import_short_uuid = __toESM(require_dist3(), 1);
|
|
78787
|
-
|
|
78788
|
-
// ../canopycms/src/paths/validation.ts
|
|
78789
|
-
var BASE58_PATTERN = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]";
|
|
78790
|
-
var CONTENT_ID_PATTERN = new RegExp(`^${BASE58_PATTERN}{12}$`);
|
|
78791
|
-
var PHYSICAL_SEGMENT_PATTERN = new RegExp(`\\.${BASE58_PATTERN}{12}(?:\\.[a-z]+)?$`);
|
|
78792
|
-
function isValidContentId(id) {
|
|
78793
|
-
return CONTENT_ID_PATTERN.test(id);
|
|
78794
|
-
}
|
|
78795
|
-
|
|
78796
|
-
// ../canopycms/src/id.ts
|
|
78943
|
+
init_validation();
|
|
78797
78944
|
var isValidId = isValidContentId;
|
|
78798
78945
|
|
|
78799
78946
|
// ../canopycms/src/utils/format.ts
|
|
@@ -79008,6 +79155,201 @@ async function tryAcquireProvisioningLock(lockTargetDir2, lockName, onCompromise
|
|
|
79008
79155
|
return releaseIgnoringAlreadyReleased(release2, lockPath);
|
|
79009
79156
|
}
|
|
79010
79157
|
|
|
79158
|
+
// ../canopycms/src/worker/git-process.ts
|
|
79159
|
+
init_error();
|
|
79160
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
79161
|
+
import { Readable, Transform, Writable } from "node:stream";
|
|
79162
|
+
import { pipeline } from "node:stream/promises";
|
|
79163
|
+
var GitProcessError = class extends Error {
|
|
79164
|
+
constructor(message2, exitCode, stderr) {
|
|
79165
|
+
super(message2);
|
|
79166
|
+
this.exitCode = exitCode;
|
|
79167
|
+
this.stderr = stderr;
|
|
79168
|
+
this.name = "GitProcessError";
|
|
79169
|
+
}
|
|
79170
|
+
};
|
|
79171
|
+
var STDERR_CAP_BYTES = 64 * 1024;
|
|
79172
|
+
var KILL_GRACE_MS = 2e3;
|
|
79173
|
+
function spawnGit(args, options) {
|
|
79174
|
+
const child = spawn2("git", [...(options.config ?? []).flatMap((c11) => ["-c", c11]), ...args], {
|
|
79175
|
+
cwd: options.cwd,
|
|
79176
|
+
// An app's own ProcessEnv augmentation (Next.js requires NODE_ENV) says nothing about git's.
|
|
79177
|
+
env: options.env,
|
|
79178
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
79179
|
+
// Its own process group, so a stop reaches what git spawned too (bundle create's
|
|
79180
|
+
// pack-objects), which would otherwise outlive it holding the pipes open.
|
|
79181
|
+
detached: process.platform !== "win32"
|
|
79182
|
+
});
|
|
79183
|
+
const { stdout } = child;
|
|
79184
|
+
if (stdout === null) throw new Error("git was spawned without a stdout pipe");
|
|
79185
|
+
const command5 = args.find((arg) => !arg.startsWith("-")) ?? "git";
|
|
79186
|
+
let stderr = "";
|
|
79187
|
+
let stderrBytes = 0;
|
|
79188
|
+
let killedFor = null;
|
|
79189
|
+
let closed = false;
|
|
79190
|
+
let exitedCleanly = false;
|
|
79191
|
+
let inactivity;
|
|
79192
|
+
const idle = () => {
|
|
79193
|
+
if (stdout.readableLength > 0 && !stdout.destroyed) {
|
|
79194
|
+
inactivity = setTimeout(idle, options.inactivityTimeoutMs);
|
|
79195
|
+
return;
|
|
79196
|
+
}
|
|
79197
|
+
stop(`git ${command5} wrote nothing for ${options.inactivityTimeoutMs}ms`);
|
|
79198
|
+
};
|
|
79199
|
+
const touch = () => {
|
|
79200
|
+
options.onActivity?.();
|
|
79201
|
+
clearTimeout(inactivity);
|
|
79202
|
+
if (exitedCleanly) return;
|
|
79203
|
+
inactivity = setTimeout(idle, options.inactivityTimeoutMs);
|
|
79204
|
+
};
|
|
79205
|
+
const stop = (reason) => {
|
|
79206
|
+
if (closed || killedFor !== null) return;
|
|
79207
|
+
if (child.exitCode === 0 || child.exitCode === null && child.signalCode === null) {
|
|
79208
|
+
killedFor = reason;
|
|
79209
|
+
}
|
|
79210
|
+
terminate(child);
|
|
79211
|
+
stdout.destroy();
|
|
79212
|
+
};
|
|
79213
|
+
child.on("exit", (code) => {
|
|
79214
|
+
if (code !== 0) return;
|
|
79215
|
+
exitedCleanly = true;
|
|
79216
|
+
clearTimeout(inactivity);
|
|
79217
|
+
clearTimeout(deadline);
|
|
79218
|
+
});
|
|
79219
|
+
child.stderr?.on("data", (chunk) => {
|
|
79220
|
+
touch();
|
|
79221
|
+
if (stderrBytes < STDERR_CAP_BYTES) {
|
|
79222
|
+
stderr += chunk.subarray(0, STDERR_CAP_BYTES - stderrBytes).toString("utf8");
|
|
79223
|
+
}
|
|
79224
|
+
stderrBytes += chunk.length;
|
|
79225
|
+
});
|
|
79226
|
+
stdout.on("data", touch);
|
|
79227
|
+
const deadline = options.deadlineMs === void 0 ? void 0 : setTimeout(
|
|
79228
|
+
() => stop(`git ${command5} ran longer than ${options.deadlineMs}ms`),
|
|
79229
|
+
options.deadlineMs
|
|
79230
|
+
);
|
|
79231
|
+
const onAbort = () => stop(`git ${command5} was aborted`);
|
|
79232
|
+
if (options.signal?.aborted) onAbort();
|
|
79233
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
79234
|
+
const input = feedStdin(
|
|
79235
|
+
child,
|
|
79236
|
+
options.stdin,
|
|
79237
|
+
touch,
|
|
79238
|
+
(err) => stop(`git ${command5}'s input failed: ${getErrorMessage(err)}`)
|
|
79239
|
+
);
|
|
79240
|
+
input.catch(() => void 0);
|
|
79241
|
+
touch();
|
|
79242
|
+
const exited = new Promise((resolve, reject) => {
|
|
79243
|
+
child.on("error", (err) => {
|
|
79244
|
+
if (child.pid === void 0) {
|
|
79245
|
+
clearTimeout(inactivity);
|
|
79246
|
+
clearTimeout(deadline);
|
|
79247
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
79248
|
+
reject(new GitProcessError(`git ${command5} could not run: ${err.message}`, null, ""));
|
|
79249
|
+
}
|
|
79250
|
+
});
|
|
79251
|
+
child.on("close", (code, signal) => {
|
|
79252
|
+
closed = true;
|
|
79253
|
+
clearTimeout(inactivity);
|
|
79254
|
+
clearTimeout(deadline);
|
|
79255
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
79256
|
+
const written = stderrBytes > STDERR_CAP_BYTES ? `${stderr}
|
|
79257
|
+
[stderr truncated]` : stderr;
|
|
79258
|
+
if (killedFor === null && code === 0) {
|
|
79259
|
+
input.then(
|
|
79260
|
+
resolve,
|
|
79261
|
+
(err) => reject(
|
|
79262
|
+
new GitProcessError(
|
|
79263
|
+
`git ${command5}'s input failed: ${getErrorMessage(err)}`,
|
|
79264
|
+
0,
|
|
79265
|
+
written
|
|
79266
|
+
)
|
|
79267
|
+
)
|
|
79268
|
+
);
|
|
79269
|
+
return;
|
|
79270
|
+
}
|
|
79271
|
+
const why = killedFor ?? (written.trim() || (code === null ? `git ${command5} was killed by ${signal ?? "a signal"}` : `git ${command5} exited with code ${code}`));
|
|
79272
|
+
reject(new GitProcessError(why, code, written));
|
|
79273
|
+
});
|
|
79274
|
+
});
|
|
79275
|
+
exited.catch(() => void 0);
|
|
79276
|
+
return { stdout, exited, kill: stop };
|
|
79277
|
+
}
|
|
79278
|
+
async function runGit(args, options) {
|
|
79279
|
+
const max = options.maxStdoutBytes ?? 64 * 1024 * 1024;
|
|
79280
|
+
const proc = spawnGit(args, options);
|
|
79281
|
+
const chunks = [];
|
|
79282
|
+
let total = 0;
|
|
79283
|
+
const collect = new Writable({
|
|
79284
|
+
write(chunk, _encoding, callback) {
|
|
79285
|
+
total += chunk.length;
|
|
79286
|
+
if (total > max) {
|
|
79287
|
+
proc.kill(`git printed more than ${max} bytes`);
|
|
79288
|
+
callback();
|
|
79289
|
+
return;
|
|
79290
|
+
}
|
|
79291
|
+
chunks.push(chunk);
|
|
79292
|
+
callback();
|
|
79293
|
+
}
|
|
79294
|
+
});
|
|
79295
|
+
try {
|
|
79296
|
+
await Promise.all([pipeline(proc.stdout, collect).catch(() => void 0), proc.exited]);
|
|
79297
|
+
} catch (err) {
|
|
79298
|
+
if (options.stdoutInFailure && err instanceof GitProcessError && chunks.length > 0) {
|
|
79299
|
+
throw new GitProcessError(
|
|
79300
|
+
`${Buffer.concat(chunks).toString("utf8")}${err.message}`,
|
|
79301
|
+
err.exitCode,
|
|
79302
|
+
err.stderr
|
|
79303
|
+
);
|
|
79304
|
+
}
|
|
79305
|
+
throw err;
|
|
79306
|
+
}
|
|
79307
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
79308
|
+
}
|
|
79309
|
+
function terminate(child) {
|
|
79310
|
+
signalGroup(child, "SIGTERM");
|
|
79311
|
+
const timer = setTimeout(() => signalGroup(child, "SIGKILL"), KILL_GRACE_MS);
|
|
79312
|
+
timer.unref();
|
|
79313
|
+
child.once("close", () => clearTimeout(timer));
|
|
79314
|
+
}
|
|
79315
|
+
function signalGroup(child, signal) {
|
|
79316
|
+
if (child.pid !== void 0 && process.platform !== "win32") {
|
|
79317
|
+
try {
|
|
79318
|
+
process.kill(-child.pid, signal);
|
|
79319
|
+
return;
|
|
79320
|
+
} catch {
|
|
79321
|
+
}
|
|
79322
|
+
}
|
|
79323
|
+
child.kill(signal);
|
|
79324
|
+
}
|
|
79325
|
+
function feedStdin(child, source, touch, onSourceError) {
|
|
79326
|
+
const sink = child.stdin;
|
|
79327
|
+
if (sink === null) return Promise.resolve();
|
|
79328
|
+
sink.on("error", () => void 0);
|
|
79329
|
+
if (source === void 0) {
|
|
79330
|
+
sink.end();
|
|
79331
|
+
return Promise.resolve();
|
|
79332
|
+
}
|
|
79333
|
+
const readable = typeof source === "string" ? Readable.from([Buffer.from(source)]) : source;
|
|
79334
|
+
const counted = new Transform({
|
|
79335
|
+
transform(chunk, _encoding, callback) {
|
|
79336
|
+
touch();
|
|
79337
|
+
callback(null, chunk);
|
|
79338
|
+
}
|
|
79339
|
+
});
|
|
79340
|
+
return new Promise((resolve, reject) => {
|
|
79341
|
+
readable.once("error", (err) => {
|
|
79342
|
+
onSourceError(err);
|
|
79343
|
+
reject(err);
|
|
79344
|
+
});
|
|
79345
|
+
sink.once("close", () => {
|
|
79346
|
+
if (!readable.readableEnded) readable.destroy();
|
|
79347
|
+
resolve();
|
|
79348
|
+
});
|
|
79349
|
+
readable.pipe(counted).pipe(sink);
|
|
79350
|
+
});
|
|
79351
|
+
}
|
|
79352
|
+
|
|
79011
79353
|
// ../canopycms/src/git-manager.ts
|
|
79012
79354
|
var log2 = createDebugLogger({ prefix: "GitManager" });
|
|
79013
79355
|
var GIT_ENV_PASSTHROUGH = /^(PATH|HOME|USER|LANG|LC_[A-Z]+|TZ|TMPDIR|GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL|DATE)|GIT_TERMINAL_PROMPT|GIT_TRACE[0-9A-Z_]*)$/;
|
|
@@ -79285,201 +79627,6 @@ function hasOnlyHead(header, sha, branch) {
|
|
|
79285
79627
|
return header.heads.length === 1 && header.heads[0].equals(expectedHead(sha, branch));
|
|
79286
79628
|
}
|
|
79287
79629
|
|
|
79288
|
-
// ../canopycms/src/worker/git-process.ts
|
|
79289
|
-
init_error();
|
|
79290
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
79291
|
-
import { Readable, Transform, Writable } from "node:stream";
|
|
79292
|
-
import { pipeline } from "node:stream/promises";
|
|
79293
|
-
var GitProcessError = class extends Error {
|
|
79294
|
-
constructor(message2, exitCode, stderr) {
|
|
79295
|
-
super(message2);
|
|
79296
|
-
this.exitCode = exitCode;
|
|
79297
|
-
this.stderr = stderr;
|
|
79298
|
-
this.name = "GitProcessError";
|
|
79299
|
-
}
|
|
79300
|
-
};
|
|
79301
|
-
var STDERR_CAP_BYTES = 64 * 1024;
|
|
79302
|
-
var KILL_GRACE_MS = 2e3;
|
|
79303
|
-
function spawnGit(args, options) {
|
|
79304
|
-
const child = spawn2("git", [...(options.config ?? []).flatMap((c11) => ["-c", c11]), ...args], {
|
|
79305
|
-
cwd: options.cwd,
|
|
79306
|
-
// An app's own ProcessEnv augmentation (Next.js requires NODE_ENV) says nothing about git's.
|
|
79307
|
-
env: options.env,
|
|
79308
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
79309
|
-
// Its own process group, so a stop reaches what git spawned too (bundle create's
|
|
79310
|
-
// pack-objects), which would otherwise outlive it holding the pipes open.
|
|
79311
|
-
detached: process.platform !== "win32"
|
|
79312
|
-
});
|
|
79313
|
-
const { stdout } = child;
|
|
79314
|
-
if (stdout === null) throw new Error("git was spawned without a stdout pipe");
|
|
79315
|
-
const command5 = args.find((arg) => !arg.startsWith("-")) ?? "git";
|
|
79316
|
-
let stderr = "";
|
|
79317
|
-
let stderrBytes = 0;
|
|
79318
|
-
let killedFor = null;
|
|
79319
|
-
let closed = false;
|
|
79320
|
-
let exitedCleanly = false;
|
|
79321
|
-
let inactivity;
|
|
79322
|
-
const idle = () => {
|
|
79323
|
-
if (stdout.readableLength > 0 && !stdout.destroyed) {
|
|
79324
|
-
inactivity = setTimeout(idle, options.inactivityTimeoutMs);
|
|
79325
|
-
return;
|
|
79326
|
-
}
|
|
79327
|
-
stop(`git ${command5} wrote nothing for ${options.inactivityTimeoutMs}ms`);
|
|
79328
|
-
};
|
|
79329
|
-
const touch = () => {
|
|
79330
|
-
options.onActivity?.();
|
|
79331
|
-
clearTimeout(inactivity);
|
|
79332
|
-
if (exitedCleanly) return;
|
|
79333
|
-
inactivity = setTimeout(idle, options.inactivityTimeoutMs);
|
|
79334
|
-
};
|
|
79335
|
-
const stop = (reason) => {
|
|
79336
|
-
if (closed || killedFor !== null) return;
|
|
79337
|
-
if (child.exitCode === 0 || child.exitCode === null && child.signalCode === null) {
|
|
79338
|
-
killedFor = reason;
|
|
79339
|
-
}
|
|
79340
|
-
terminate(child);
|
|
79341
|
-
stdout.destroy();
|
|
79342
|
-
};
|
|
79343
|
-
child.on("exit", (code) => {
|
|
79344
|
-
if (code !== 0) return;
|
|
79345
|
-
exitedCleanly = true;
|
|
79346
|
-
clearTimeout(inactivity);
|
|
79347
|
-
clearTimeout(deadline);
|
|
79348
|
-
});
|
|
79349
|
-
child.stderr?.on("data", (chunk) => {
|
|
79350
|
-
touch();
|
|
79351
|
-
if (stderrBytes < STDERR_CAP_BYTES) {
|
|
79352
|
-
stderr += chunk.subarray(0, STDERR_CAP_BYTES - stderrBytes).toString("utf8");
|
|
79353
|
-
}
|
|
79354
|
-
stderrBytes += chunk.length;
|
|
79355
|
-
});
|
|
79356
|
-
stdout.on("data", touch);
|
|
79357
|
-
const deadline = options.deadlineMs === void 0 ? void 0 : setTimeout(
|
|
79358
|
-
() => stop(`git ${command5} ran longer than ${options.deadlineMs}ms`),
|
|
79359
|
-
options.deadlineMs
|
|
79360
|
-
);
|
|
79361
|
-
const onAbort = () => stop(`git ${command5} was aborted`);
|
|
79362
|
-
if (options.signal?.aborted) onAbort();
|
|
79363
|
-
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
79364
|
-
const input = feedStdin(
|
|
79365
|
-
child,
|
|
79366
|
-
options.stdin,
|
|
79367
|
-
touch,
|
|
79368
|
-
(err) => stop(`git ${command5}'s input failed: ${getErrorMessage(err)}`)
|
|
79369
|
-
);
|
|
79370
|
-
input.catch(() => void 0);
|
|
79371
|
-
touch();
|
|
79372
|
-
const exited = new Promise((resolve, reject) => {
|
|
79373
|
-
child.on("error", (err) => {
|
|
79374
|
-
if (child.pid === void 0) {
|
|
79375
|
-
clearTimeout(inactivity);
|
|
79376
|
-
clearTimeout(deadline);
|
|
79377
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
79378
|
-
reject(new GitProcessError(`git ${command5} could not run: ${err.message}`, null, ""));
|
|
79379
|
-
}
|
|
79380
|
-
});
|
|
79381
|
-
child.on("close", (code, signal) => {
|
|
79382
|
-
closed = true;
|
|
79383
|
-
clearTimeout(inactivity);
|
|
79384
|
-
clearTimeout(deadline);
|
|
79385
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
79386
|
-
const written = stderrBytes > STDERR_CAP_BYTES ? `${stderr}
|
|
79387
|
-
[stderr truncated]` : stderr;
|
|
79388
|
-
if (killedFor === null && code === 0) {
|
|
79389
|
-
input.then(
|
|
79390
|
-
resolve,
|
|
79391
|
-
(err) => reject(
|
|
79392
|
-
new GitProcessError(
|
|
79393
|
-
`git ${command5}'s input failed: ${getErrorMessage(err)}`,
|
|
79394
|
-
0,
|
|
79395
|
-
written
|
|
79396
|
-
)
|
|
79397
|
-
)
|
|
79398
|
-
);
|
|
79399
|
-
return;
|
|
79400
|
-
}
|
|
79401
|
-
const why = killedFor ?? (written.trim() || (code === null ? `git ${command5} was killed by ${signal ?? "a signal"}` : `git ${command5} exited with code ${code}`));
|
|
79402
|
-
reject(new GitProcessError(why, code, written));
|
|
79403
|
-
});
|
|
79404
|
-
});
|
|
79405
|
-
exited.catch(() => void 0);
|
|
79406
|
-
return { stdout, exited, kill: stop };
|
|
79407
|
-
}
|
|
79408
|
-
async function runGit(args, options) {
|
|
79409
|
-
const max = options.maxStdoutBytes ?? 64 * 1024 * 1024;
|
|
79410
|
-
const proc = spawnGit(args, options);
|
|
79411
|
-
const chunks = [];
|
|
79412
|
-
let total = 0;
|
|
79413
|
-
const collect = new Writable({
|
|
79414
|
-
write(chunk, _encoding, callback) {
|
|
79415
|
-
total += chunk.length;
|
|
79416
|
-
if (total > max) {
|
|
79417
|
-
proc.kill(`git printed more than ${max} bytes`);
|
|
79418
|
-
callback();
|
|
79419
|
-
return;
|
|
79420
|
-
}
|
|
79421
|
-
chunks.push(chunk);
|
|
79422
|
-
callback();
|
|
79423
|
-
}
|
|
79424
|
-
});
|
|
79425
|
-
try {
|
|
79426
|
-
await Promise.all([pipeline(proc.stdout, collect).catch(() => void 0), proc.exited]);
|
|
79427
|
-
} catch (err) {
|
|
79428
|
-
if (options.stdoutInFailure && err instanceof GitProcessError && chunks.length > 0) {
|
|
79429
|
-
throw new GitProcessError(
|
|
79430
|
-
`${Buffer.concat(chunks).toString("utf8")}${err.message}`,
|
|
79431
|
-
err.exitCode,
|
|
79432
|
-
err.stderr
|
|
79433
|
-
);
|
|
79434
|
-
}
|
|
79435
|
-
throw err;
|
|
79436
|
-
}
|
|
79437
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
79438
|
-
}
|
|
79439
|
-
function terminate(child) {
|
|
79440
|
-
signalGroup(child, "SIGTERM");
|
|
79441
|
-
const timer = setTimeout(() => signalGroup(child, "SIGKILL"), KILL_GRACE_MS);
|
|
79442
|
-
timer.unref();
|
|
79443
|
-
child.once("close", () => clearTimeout(timer));
|
|
79444
|
-
}
|
|
79445
|
-
function signalGroup(child, signal) {
|
|
79446
|
-
if (child.pid !== void 0 && process.platform !== "win32") {
|
|
79447
|
-
try {
|
|
79448
|
-
process.kill(-child.pid, signal);
|
|
79449
|
-
return;
|
|
79450
|
-
} catch {
|
|
79451
|
-
}
|
|
79452
|
-
}
|
|
79453
|
-
child.kill(signal);
|
|
79454
|
-
}
|
|
79455
|
-
function feedStdin(child, source, touch, onSourceError) {
|
|
79456
|
-
const sink = child.stdin;
|
|
79457
|
-
if (sink === null) return Promise.resolve();
|
|
79458
|
-
sink.on("error", () => void 0);
|
|
79459
|
-
if (source === void 0) {
|
|
79460
|
-
sink.end();
|
|
79461
|
-
return Promise.resolve();
|
|
79462
|
-
}
|
|
79463
|
-
const readable = typeof source === "string" ? Readable.from([Buffer.from(source)]) : source;
|
|
79464
|
-
const counted = new Transform({
|
|
79465
|
-
transform(chunk, _encoding, callback) {
|
|
79466
|
-
touch();
|
|
79467
|
-
callback(null, chunk);
|
|
79468
|
-
}
|
|
79469
|
-
});
|
|
79470
|
-
return new Promise((resolve, reject) => {
|
|
79471
|
-
readable.once("error", (err) => {
|
|
79472
|
-
onSourceError(err);
|
|
79473
|
-
reject(err);
|
|
79474
|
-
});
|
|
79475
|
-
sink.once("close", () => {
|
|
79476
|
-
if (!readable.readableEnded) readable.destroy();
|
|
79477
|
-
resolve();
|
|
79478
|
-
});
|
|
79479
|
-
readable.pipe(counted).pipe(sink);
|
|
79480
|
-
});
|
|
79481
|
-
}
|
|
79482
|
-
|
|
79483
79630
|
// ../canopycms/src/worker/github-gateway.ts
|
|
79484
79631
|
import fs10 from "node:fs/promises";
|
|
79485
79632
|
import path11 from "node:path";
|
|
@@ -79490,6 +79637,12 @@ var import_plugin_throttling = __toESM(require_dist_node13(), 1);
|
|
|
79490
79637
|
init_error();
|
|
79491
79638
|
init_logger();
|
|
79492
79639
|
|
|
79640
|
+
// ../canopycms/src/auth/person-name.ts
|
|
79641
|
+
function personName(id, name2) {
|
|
79642
|
+
const trimmed2 = name2?.trim();
|
|
79643
|
+
return trimmed2 && trimmed2 !== id ? trimmed2 : void 0;
|
|
79644
|
+
}
|
|
79645
|
+
|
|
79493
79646
|
// ../canopycms/src/editor-url.ts
|
|
79494
79647
|
function editorDeepLink(editorUrl, branch, entryPath) {
|
|
79495
79648
|
const url = new URL(editorUrl);
|
|
@@ -79504,6 +79657,8 @@ var PR_SECTION_START = "<!-- canopycms:submission:start -->";
|
|
|
79504
79657
|
var PR_SECTION_END = "<!-- canopycms:submission:end -->";
|
|
79505
79658
|
var PR_COMMENTS_START = "<!-- canopycms:comments:start -->";
|
|
79506
79659
|
var PR_COMMENTS_END = "<!-- canopycms:comments:end -->";
|
|
79660
|
+
var PR_REVIEW_START = "<!-- canopycms:review:start -->";
|
|
79661
|
+
var PR_REVIEW_END = "<!-- canopycms:review:end -->";
|
|
79507
79662
|
var INVISIBLE_OR_CONTROL = /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/gu;
|
|
79508
79663
|
var STRUCTURAL = /[<>()`\\]/g;
|
|
79509
79664
|
function truncate(value, max) {
|
|
@@ -79519,6 +79674,9 @@ function cleanText(raw, max) {
|
|
|
79519
79674
|
const cleaned = raw.normalize("NFKC").replace(INVISIBLE_OR_CONTROL, " ").replace(STRUCTURAL, "").replace(/\s+/g, " ").trim();
|
|
79520
79675
|
return cleaned ? truncate(cleaned, max) : void 0;
|
|
79521
79676
|
}
|
|
79677
|
+
function sanitizeDisplayName(raw) {
|
|
79678
|
+
return cleanText(raw, MAX_NAME_LENGTH);
|
|
79679
|
+
}
|
|
79522
79680
|
function codeSpan(value) {
|
|
79523
79681
|
return `\`${value}\``;
|
|
79524
79682
|
}
|
|
@@ -79531,6 +79689,24 @@ function markdownHref(href) {
|
|
|
79531
79689
|
function editorLinker(branch, editorUrl) {
|
|
79532
79690
|
return (entryPath) => branch && editorUrl ? markdownHref(editorDeepLink(editorUrl, branch, entryPath)) : void 0;
|
|
79533
79691
|
}
|
|
79692
|
+
var REVIEW_NOT_A_GITHUB_REVIEW = "Approval in CanopyCMS is not a GitHub review.";
|
|
79693
|
+
function reviewTime(at) {
|
|
79694
|
+
const time3 = typeof at === "string" ? new Date(at) : void 0;
|
|
79695
|
+
return time3 && !Number.isNaN(time3.getTime()) ? `${time3.toISOString().slice(0, 16).replace("T", " ")} UTC` : void 0;
|
|
79696
|
+
}
|
|
79697
|
+
function buildReviewBlock(review) {
|
|
79698
|
+
const verdict = review?.state === "approved" ? "Approved" : review?.state === "changes-requested" ? "Changes requested" : void 0;
|
|
79699
|
+
let status = "Not yet reviewed in CanopyCMS.";
|
|
79700
|
+
if (review && verdict) {
|
|
79701
|
+
const name2 = personName(review.by.userId, sanitizeDisplayName(review.by.name));
|
|
79702
|
+
const when = reviewTime(review.at);
|
|
79703
|
+
status = `${verdict} in CanopyCMS by ${name2 ? codeSpan(name2) : "a reviewer"}${when ? ` on ${when}` : ""}.`;
|
|
79704
|
+
}
|
|
79705
|
+
return `${PR_REVIEW_START}
|
|
79706
|
+
${status}
|
|
79707
|
+
${REVIEW_NOT_A_GITHUB_REVIEW}
|
|
79708
|
+
${PR_REVIEW_END}`;
|
|
79709
|
+
}
|
|
79534
79710
|
var MAX_LISTED_THREADS = 50;
|
|
79535
79711
|
var MAX_EXCERPT_LENGTH = 80;
|
|
79536
79712
|
var MAX_COMMENTS_LENGTH = 15e3;
|
|
@@ -79611,6 +79787,15 @@ function mergeCommentsBlock(existing, block) {
|
|
|
79611
79787
|
if (start < 0 || end < 0 || end > section.end) return void 0;
|
|
79612
79788
|
return body.slice(0, start) + block + body.slice(end + PR_COMMENTS_END.length);
|
|
79613
79789
|
}
|
|
79790
|
+
function mergeReviewBlock(existing, block) {
|
|
79791
|
+
const body = existing ?? "";
|
|
79792
|
+
const section = findPrSection(body);
|
|
79793
|
+
if (!section) return void 0;
|
|
79794
|
+
const start = body.indexOf(PR_REVIEW_START, section.start);
|
|
79795
|
+
const end = start < 0 ? -1 : body.indexOf(PR_REVIEW_END, start);
|
|
79796
|
+
if (start < 0 || end < 0 || end > section.end) return void 0;
|
|
79797
|
+
return body.slice(0, start) + block + body.slice(end + PR_REVIEW_END.length);
|
|
79798
|
+
}
|
|
79614
79799
|
|
|
79615
79800
|
// ../canopycms/src/github-service.ts
|
|
79616
79801
|
var ThrottledOctokit = import_rest.Octokit.plugin(import_plugin_throttling.throttling);
|
|
@@ -79948,22 +80133,11 @@ async function walk(dir, visit) {
|
|
|
79948
80133
|
}
|
|
79949
80134
|
}
|
|
79950
80135
|
|
|
79951
|
-
// ../canopycms/src/paths/branch-name.ts
|
|
79952
|
-
function sanitizeBranchName(branchName) {
|
|
79953
|
-
const replaced = branchName.replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
79954
|
-
const squashed = replaced.replace(/-+/g, "-");
|
|
79955
|
-
const trimmedDots = squashed.replace(/^\.+/, "").replace(/(?<!\.)\.+$/, "");
|
|
79956
|
-
return trimmedDots || "branch";
|
|
79957
|
-
}
|
|
79958
|
-
var RESERVED_SETTINGS_BRANCH_PREFIX = "canopycms-settings-";
|
|
79959
|
-
function isSettingsBranchName(branchName, settingsBranchName) {
|
|
79960
|
-
const sanitized = sanitizeBranchName(branchName);
|
|
79961
|
-
return sanitized.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX) || settingsBranchName !== void 0 && sanitized === sanitizeBranchName(settingsBranchName);
|
|
79962
|
-
}
|
|
79963
|
-
|
|
79964
80136
|
// ../canopycms/src/worker/branch-policy.ts
|
|
80137
|
+
init_branch_namespace();
|
|
80138
|
+
init_branch_name();
|
|
79965
80139
|
var DEFAULT_BRANCH_TTL_MS = 10 * 6e4;
|
|
79966
|
-
var
|
|
80140
|
+
var MAX_BRANCH_NAME_LENGTH2 = 255;
|
|
79967
80141
|
var MAX_PULL_REQUEST_TITLE_LENGTH = 1024;
|
|
79968
80142
|
var MAX_PULL_REQUEST_BODY_LENGTH = 65536;
|
|
79969
80143
|
var GatewayRefusalError = class extends Error {
|
|
@@ -79978,9 +80152,30 @@ var GatewayRefusalError = class extends Error {
|
|
|
79978
80152
|
var deleting = (branch) => `Refusing to delete ${JSON.stringify(branch)} on GitHub`;
|
|
79979
80153
|
var openingFrom = (head) => `Refusing to open a pull request from ${JSON.stringify(head)}`;
|
|
79980
80154
|
var PROTECTED_WHY = "it is protected (the base branch, GitHub's default branch, or a name protectedBranches lists), which the CanopyCMS worker never changes. Nothing in CanopyCMS queues this; find out what wrote this task.";
|
|
80155
|
+
var outsideNamespaceWhy = (namespace) => `it is outside this deployment's branch namespace (names starting ${namespace}), and is neither its settings branch nor on its legacyBranches list. CanopyCMS creates every branch it edits in that namespace; a branch made before it reaches GitHub only once legacyBranches lists it.`;
|
|
80156
|
+
var outsideNamespaceDeleteWhy = (namespace) => `it is outside this deployment's branch namespace (names starting ${namespace}), and is neither its settings branch nor on its legacyBranches list, so the branch stays on GitHub. To delete it there, add it to legacyBranches, retry this task in System health, then remove the entry.`;
|
|
80157
|
+
function pushRefusalMessage(branch, reason, namespace) {
|
|
80158
|
+
const refusing = `Refusing to push ${JSON.stringify(branch)} to GitHub`;
|
|
80159
|
+
switch (reason) {
|
|
80160
|
+
case "protected":
|
|
80161
|
+
return `${refusing}: ${PROTECTED_WHY}`;
|
|
80162
|
+
case "settings":
|
|
80163
|
+
return `${refusing} under a lease: a settings branch only ever fast-forwards. Find out what set a history-rewrite marker on it.`;
|
|
80164
|
+
case "other-settings":
|
|
80165
|
+
return `${refusing}: it is a settings branch, and not this deployment's, which is the only one this gateway pushes. Check that CANOPYCMS_DEPLOYMENT_NAME and CANOPYCMS_SETTINGS_BRANCH match the CMS's own settings branch; if they do, find out what asked for this push.`;
|
|
80166
|
+
case "outside-namespace":
|
|
80167
|
+
return `${refusing}: ${outsideNamespaceWhy(namespace)}`;
|
|
80168
|
+
}
|
|
80169
|
+
}
|
|
80170
|
+
function namespaceBlockedMessage(branch, blocker) {
|
|
80171
|
+
return `Refusing to push ${JSON.stringify(branch)} to GitHub: GitHub has a branch named ${JSON.stringify(blocker)}, which is part of this deployment's branch namespace, and git cannot hold a branch inside another. Rename or delete that branch on GitHub.`;
|
|
80172
|
+
}
|
|
80173
|
+
function branchInsideMessage(branch, inside) {
|
|
80174
|
+
return `Refusing to push ${JSON.stringify(branch)} to GitHub: GitHub has a branch named ${JSON.stringify(inside)} inside it, and git cannot hold both. Rename or delete that branch on GitHub.`;
|
|
80175
|
+
}
|
|
79981
80176
|
function branchNameProblem(branch) {
|
|
79982
|
-
if (branch.length === 0 || branch.length >
|
|
79983
|
-
return `a branch name is 1 to ${
|
|
80177
|
+
if (branch.length === 0 || branch.length > MAX_BRANCH_NAME_LENGTH2) {
|
|
80178
|
+
return `a branch name is 1 to ${MAX_BRANCH_NAME_LENGTH2} characters`;
|
|
79984
80179
|
}
|
|
79985
80180
|
if (!/^[\x21-\x7e]+$/.test(branch)) return "it is not printable ASCII";
|
|
79986
80181
|
if (/["%{}]/.test(branch)) return 'it contains ", %, { or }';
|
|
@@ -80006,6 +80201,20 @@ function protectedPatternProblem(pattern) {
|
|
|
80006
80201
|
}
|
|
80007
80202
|
return null;
|
|
80008
80203
|
}
|
|
80204
|
+
function legacyBranchProblem(entry) {
|
|
80205
|
+
if (entry.includes("*")) return "an entry is an exact branch name, and * is not a wildcard here";
|
|
80206
|
+
if (entry.includes(",")) return "it contains a comma, which separates entries";
|
|
80207
|
+
if (entry.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX)) {
|
|
80208
|
+
return "it is a settings branch, which the gateway pushes without being listed";
|
|
80209
|
+
}
|
|
80210
|
+
const problem = protectedPatternProblem(entry);
|
|
80211
|
+
if (problem !== null) return problem;
|
|
80212
|
+
if (entry === "HEAD" || entry === "@") return `git reserves ${JSON.stringify(entry)}`;
|
|
80213
|
+
if (entry.split("/").some((part) => part.startsWith(".") || part.endsWith(".lock"))) {
|
|
80214
|
+
return "a part of it starts with '.' or ends with '.lock', which git refuses";
|
|
80215
|
+
}
|
|
80216
|
+
return null;
|
|
80217
|
+
}
|
|
80009
80218
|
function matchesBranchPattern(pattern, name2) {
|
|
80010
80219
|
const parts = pattern.split("*");
|
|
80011
80220
|
const first2 = parts[0];
|
|
@@ -80023,10 +80232,38 @@ function matchesBranchPattern(pattern, name2) {
|
|
|
80023
80232
|
return true;
|
|
80024
80233
|
}
|
|
80025
80234
|
var MAX_PROTECTED_BRANCHES = 1024;
|
|
80235
|
+
var MAX_LEGACY_BRANCHES = 1024;
|
|
80236
|
+
var DEFAULT_BRANCH_NAMESPACE = resolveBranchNamespaceTemplate(
|
|
80237
|
+
DEFAULT_BRANCH_NAMESPACE_TEMPLATE,
|
|
80238
|
+
"prod",
|
|
80239
|
+
"the default"
|
|
80240
|
+
);
|
|
80026
80241
|
var BranchPolicy = class {
|
|
80027
80242
|
constructor(options = {}) {
|
|
80028
80243
|
this.githubDefault = null;
|
|
80029
80244
|
this.now = options.now ?? (() => Date.now());
|
|
80245
|
+
this.namespace = options.namespace ?? DEFAULT_BRANCH_NAMESPACE;
|
|
80246
|
+
const namespaceProblem = branchNamespaceProblem(this.namespace);
|
|
80247
|
+
if (namespaceProblem !== null) {
|
|
80248
|
+
throw new Error(
|
|
80249
|
+
`Invalid branch namespace ${JSON.stringify(this.namespace)}: ${namespaceProblem}`
|
|
80250
|
+
);
|
|
80251
|
+
}
|
|
80252
|
+
for (const [what, name2] of [
|
|
80253
|
+
["base branch", options.baseBranch],
|
|
80254
|
+
["settings branch", options.settingsBranch]
|
|
80255
|
+
]) {
|
|
80256
|
+
if (name2 !== void 0 && (name2.startsWith(this.namespace) || sanitizeBranchName(name2).startsWith(sanitizeBranchName(this.namespace)))) {
|
|
80257
|
+
throw new Error(
|
|
80258
|
+
`The ${what} ${JSON.stringify(name2)} is inside the branch namespace ${JSON.stringify(this.namespace)}, or shares a workspace directory with a branch in it, and the namespace holds only the branches editors create; choose a namespace it is outside`
|
|
80259
|
+
);
|
|
80260
|
+
}
|
|
80261
|
+
if (name2 !== void 0 && this.namespace.startsWith(`${name2}/`)) {
|
|
80262
|
+
throw new Error(
|
|
80263
|
+
`The ${what} ${JSON.stringify(name2)} is a branch named after part of the branch namespace ${JSON.stringify(this.namespace)}, so git can hold no branch in it; choose another namespace`
|
|
80264
|
+
);
|
|
80265
|
+
}
|
|
80266
|
+
}
|
|
80030
80267
|
const entries = [...options.protectedBranches ?? []];
|
|
80031
80268
|
if (entries.length > MAX_PROTECTED_BRANCHES) {
|
|
80032
80269
|
throw new Error(
|
|
@@ -80042,26 +80279,87 @@ var BranchPolicy = class {
|
|
|
80042
80279
|
if (options.baseBranch !== void 0) entries.push(options.baseBranch);
|
|
80043
80280
|
this.exact = entries.filter((entry) => !entry.includes("*"));
|
|
80044
80281
|
this.globs = entries.filter((entry) => entry.includes("*"));
|
|
80282
|
+
const settingsBranch = options.settingsBranch;
|
|
80283
|
+
if (settingsBranch !== void 0) {
|
|
80284
|
+
const problem = branchNameProblem(settingsBranch);
|
|
80285
|
+
if (problem !== null) {
|
|
80286
|
+
throw new Error(`Invalid settings branch ${JSON.stringify(settingsBranch)}: ${problem}`);
|
|
80287
|
+
}
|
|
80288
|
+
}
|
|
80289
|
+
this.settingsBranch = settingsBranch ?? null;
|
|
80290
|
+
const legacy = options.legacyBranches ?? [];
|
|
80291
|
+
if (legacy.length > MAX_LEGACY_BRANCHES) {
|
|
80292
|
+
throw new Error(
|
|
80293
|
+
`legacyBranches has ${legacy.length} entries; the most it takes is ${MAX_LEGACY_BRANCHES}`
|
|
80294
|
+
);
|
|
80295
|
+
}
|
|
80296
|
+
for (const entry of legacy) {
|
|
80297
|
+
const problem = entry.startsWith(this.namespace) ? `it starts with ${this.namespace}, so it is already in the namespace` : this.namespace.startsWith(`${entry}/`) ? `it is a branch named after part of the namespace ${this.namespace}, so git can hold no branch in it` : legacyBranchProblem(entry);
|
|
80298
|
+
if (problem !== null) {
|
|
80299
|
+
throw new Error(`Invalid legacyBranches entry ${JSON.stringify(entry)}: ${problem}`);
|
|
80300
|
+
}
|
|
80301
|
+
}
|
|
80302
|
+
if (new Set(legacy).size !== legacy.length) {
|
|
80303
|
+
throw new Error("legacyBranches lists a branch more than once");
|
|
80304
|
+
}
|
|
80305
|
+
this.legacy = new Set(legacy);
|
|
80045
80306
|
}
|
|
80046
|
-
/** The
|
|
80307
|
+
/** The policy as it stands. */
|
|
80047
80308
|
describe() {
|
|
80048
80309
|
return {
|
|
80049
80310
|
configured: [...this.exact, ...this.globs],
|
|
80050
|
-
githubDefault: this.githubDefault?.name ?? null
|
|
80311
|
+
githubDefault: this.githubDefault?.name ?? null,
|
|
80312
|
+
namespace: this.namespace,
|
|
80313
|
+
legacy: [...this.legacy],
|
|
80314
|
+
settingsBranch: this.settingsBranch
|
|
80051
80315
|
};
|
|
80052
80316
|
}
|
|
80317
|
+
/** Whether the gateway may write `branch` at all: the namespace, the settings branch, the list. */
|
|
80318
|
+
inNamespace(branch) {
|
|
80319
|
+
return branch.startsWith(this.namespace) || branch === this.settingsBranch || this.legacy.has(branch);
|
|
80320
|
+
}
|
|
80321
|
+
/**
|
|
80322
|
+
* Whether the gateway opens and updates a pull request from `head`, protection aside: a branch it
|
|
80323
|
+
* writes that is not a settings branch. `isProtected`, which may read GitHub, judges the rest.
|
|
80324
|
+
*/
|
|
80325
|
+
takesPullRequestFrom(head) {
|
|
80326
|
+
return !this.isSettings(head) && this.inNamespace(head);
|
|
80327
|
+
}
|
|
80328
|
+
/**
|
|
80329
|
+
* The branch among `branches` named after part of the namespace, or null. While one exists git
|
|
80330
|
+
* holds no branch in the namespace, so the gateway refuses a push into it rather than send it.
|
|
80331
|
+
*/
|
|
80332
|
+
namespaceBlocker(branches) {
|
|
80333
|
+
return namespaceAncestors(this.namespace).find((name2) => branches.has(name2)) ?? null;
|
|
80334
|
+
}
|
|
80053
80335
|
/** Whether `branch` is protected; GitHub's default is read only when nothing else matches. */
|
|
80054
80336
|
async isProtected(branch, readDefault) {
|
|
80055
80337
|
if (this.matchesConfigured(branch)) return true;
|
|
80056
80338
|
const githubDefault = await this.githubDefaultBranch(readDefault);
|
|
80057
80339
|
return githubDefault !== null && sameBranch(githubDefault, branch);
|
|
80058
80340
|
}
|
|
80059
|
-
/**
|
|
80341
|
+
/**
|
|
80342
|
+
* Whether `branch` is GitHub's default branch as last read, even once that read has expired:
|
|
80343
|
+
* what protection is judged by when a fresh read fails.
|
|
80344
|
+
*/
|
|
80345
|
+
matchesLastReadDefault(branch) {
|
|
80346
|
+
const name2 = this.githubDefault?.name ?? null;
|
|
80347
|
+
return name2 !== null && sameBranch(name2, branch);
|
|
80348
|
+
}
|
|
80349
|
+
/**
|
|
80350
|
+
* Refuse a push to a protected branch, a leased push to a settings branch, a push to another
|
|
80351
|
+
* deployment's settings branch, and a push outside the namespace.
|
|
80352
|
+
*/
|
|
80060
80353
|
async assertPushAllowed(branch, lease, readDefault, refuse) {
|
|
80061
|
-
|
|
80062
|
-
if (
|
|
80354
|
+
const refusal2 = (reason) => refuse(reason, pushRefusalMessage(branch, reason, this.namespace));
|
|
80355
|
+
if (await this.isProtected(branch, readDefault)) throw refusal2("protected");
|
|
80356
|
+
if (this.isSettings(branch)) {
|
|
80357
|
+
if (lease !== void 0) throw refusal2("settings");
|
|
80358
|
+
if (branch !== this.settingsBranch) throw refusal2("other-settings");
|
|
80359
|
+
}
|
|
80360
|
+
if (!this.inNamespace(branch)) throw refusal2("outside-namespace");
|
|
80063
80361
|
}
|
|
80064
|
-
/** Refuse to delete a protected branch
|
|
80362
|
+
/** Refuse to delete a protected branch, a settings branch, or one outside the namespace. */
|
|
80065
80363
|
async assertDeleteAllowed(branch, readDefault) {
|
|
80066
80364
|
if (this.isSettings(branch)) {
|
|
80067
80365
|
throw new GatewayRefusalError(
|
|
@@ -80079,21 +80377,36 @@ var BranchPolicy = class {
|
|
|
80079
80377
|
`${deleting(branch)}: ${PROTECTED_WHY}`
|
|
80080
80378
|
);
|
|
80081
80379
|
}
|
|
80380
|
+
if (!this.inNamespace(branch)) {
|
|
80381
|
+
throw new GatewayRefusalError(
|
|
80382
|
+
"delete",
|
|
80383
|
+
branch,
|
|
80384
|
+
"outside-namespace",
|
|
80385
|
+
`${deleting(branch)}: ${outsideNamespaceDeleteWhy(this.namespace)}`
|
|
80386
|
+
);
|
|
80387
|
+
}
|
|
80082
80388
|
}
|
|
80083
80389
|
/**
|
|
80084
|
-
* Refuse a pull request whose head is protected
|
|
80085
|
-
* cap. The base is not restricted: a branch keeps the base it was created
|
|
80086
|
-
* adopter moves theirs, and a pull request merges nothing by itself.
|
|
80390
|
+
* Refuse a pull request whose head is protected, a settings branch or outside the namespace, or
|
|
80391
|
+
* whose text is over its cap. The base is not restricted: a branch keeps the base it was created
|
|
80392
|
+
* from after the adopter moves theirs, and a pull request merges nothing by itself.
|
|
80087
80393
|
*/
|
|
80088
80394
|
async assertPullRequestAllowed(request, readDefault) {
|
|
80089
80395
|
const { head } = request;
|
|
80090
80396
|
assertPullRequestText(openingFrom(head), head, request);
|
|
80397
|
+
await this.assertPullRequestHeadAllowed(openingFrom(head), head, readDefault);
|
|
80398
|
+
}
|
|
80399
|
+
/**
|
|
80400
|
+
* Refuse a pull request head the gateway may not open one from, or act on one with. `refusing`
|
|
80401
|
+
* opens the message and names `head`, which the rest calls "it".
|
|
80402
|
+
*/
|
|
80403
|
+
async assertPullRequestHeadAllowed(refusing, head, readDefault) {
|
|
80091
80404
|
if (this.isSettings(head)) {
|
|
80092
80405
|
throw new GatewayRefusalError(
|
|
80093
80406
|
"pull-request",
|
|
80094
80407
|
head,
|
|
80095
80408
|
"settings",
|
|
80096
|
-
`${
|
|
80409
|
+
`${refusing}: it is a settings branch, which never gets one`
|
|
80097
80410
|
);
|
|
80098
80411
|
}
|
|
80099
80412
|
if (await this.isProtected(head, readDefault)) {
|
|
@@ -80101,12 +80414,20 @@ var BranchPolicy = class {
|
|
|
80101
80414
|
"pull-request",
|
|
80102
80415
|
head,
|
|
80103
80416
|
"protected",
|
|
80104
|
-
`${
|
|
80417
|
+
`${refusing}: ${PROTECTED_WHY}`
|
|
80418
|
+
);
|
|
80419
|
+
}
|
|
80420
|
+
if (!this.takesPullRequestFrom(head)) {
|
|
80421
|
+
throw new GatewayRefusalError(
|
|
80422
|
+
"pull-request",
|
|
80423
|
+
head,
|
|
80424
|
+
"outside-namespace",
|
|
80425
|
+
`${refusing}: ${outsideNamespaceWhy(this.namespace)}`
|
|
80105
80426
|
);
|
|
80106
80427
|
}
|
|
80107
80428
|
}
|
|
80108
80429
|
isSettings(branch) {
|
|
80109
|
-
return branch.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX);
|
|
80430
|
+
return branch.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX) || branch === this.settingsBranch;
|
|
80110
80431
|
}
|
|
80111
80432
|
matchesConfigured(branch) {
|
|
80112
80433
|
return this.exact.some((name2) => sameBranch(name2, branch)) || // A glob never takes in a settings branch, whose one allowed push (plain) the worker needs:
|
|
@@ -80131,6 +80452,16 @@ var BranchPolicy = class {
|
|
|
80131
80452
|
return name2;
|
|
80132
80453
|
}
|
|
80133
80454
|
};
|
|
80455
|
+
function publishesBranch(policy, branch) {
|
|
80456
|
+
if (policy.namespace === "") return false;
|
|
80457
|
+
const settings = branch.startsWith(RESERVED_SETTINGS_BRANCH_PREFIX) || branch === policy.settingsBranch;
|
|
80458
|
+
const protectedMatch = policy.configured.some(
|
|
80459
|
+
(entry) => entry.includes("*") ? !settings && matchesBranchPattern(entry, branch) : sameBranch(entry, branch)
|
|
80460
|
+
) || policy.githubDefault !== null && sameBranch(policy.githubDefault, branch);
|
|
80461
|
+
if (protectedMatch) return false;
|
|
80462
|
+
if (settings) return branch === policy.settingsBranch;
|
|
80463
|
+
return branch.startsWith(policy.namespace) || policy.legacy.includes(branch);
|
|
80464
|
+
}
|
|
80134
80465
|
function assertPullRequestText(refusing, branch, text) {
|
|
80135
80466
|
const over = (text.title?.length ?? 0) > MAX_PULL_REQUEST_TITLE_LENGTH ? `its title is longer than ${MAX_PULL_REQUEST_TITLE_LENGTH} characters` : (text.body?.length ?? 0) > MAX_PULL_REQUEST_BODY_LENGTH ? `its body is longer than ${MAX_PULL_REQUEST_BODY_LENGTH} characters` : null;
|
|
80136
80467
|
if (over !== null) {
|
|
@@ -81066,12 +81397,12 @@ async function assertOwnDirectory(dir) {
|
|
|
81066
81397
|
}
|
|
81067
81398
|
}
|
|
81068
81399
|
var RefusedPushError = class extends GatewayRefusalError {
|
|
81069
|
-
constructor(branch, reason, sha) {
|
|
81400
|
+
constructor(branch, reason, sha, message2) {
|
|
81070
81401
|
super(
|
|
81071
81402
|
"push",
|
|
81072
81403
|
branch,
|
|
81073
81404
|
reason,
|
|
81074
|
-
reason === "invalid" ? `Refusing to push ${JSON.stringify(branch)} to GitHub: it is not a valid branch name.` : reason === "
|
|
81405
|
+
message2 ?? (reason === "invalid" ? `Refusing to push ${JSON.stringify(branch)} to GitHub: it is not a valid branch name.` : reason === "not-a-commit" ? `Refusing to push "${branch}" to GitHub: ${sha ?? "the object asked for"} is not a commit, and a branch can only point at one. Find out what put it at refs/heads/${branch} in remote.git.` : `Refusing to push ${JSON.stringify(branch)} to GitHub (${reason}).`)
|
|
81075
81406
|
);
|
|
81076
81407
|
this.name = "RefusedPushError";
|
|
81077
81408
|
}
|
|
@@ -81083,7 +81414,7 @@ async function assertPlainBranchName(branch, git = simpleGit(), operation3 = "pu
|
|
|
81083
81414
|
"invalid",
|
|
81084
81415
|
`Refusing ${JSON.stringify(branch)}: it is not a valid branch name (${why}).`
|
|
81085
81416
|
);
|
|
81086
|
-
const problem = shape ? branchNameProblem(branch) : branch.startsWith("-") ? "it starts with '-'" : branch.length >
|
|
81417
|
+
const problem = shape ? branchNameProblem(branch) : branch.startsWith("-") ? "it starts with '-'" : branch.length > MAX_BRANCH_NAME_LENGTH2 ? `it is longer than ${MAX_BRANCH_NAME_LENGTH2} characters` : null;
|
|
81087
81418
|
if (problem !== null) throw invalid(problem);
|
|
81088
81419
|
let normalized;
|
|
81089
81420
|
try {
|
|
@@ -81403,8 +81734,29 @@ var MirrorSession = class {
|
|
|
81403
81734
|
`Could not read GitHub's default branch before pushing ${branch}: ` + redactEgress(getErrorMessage(err)).trim()
|
|
81404
81735
|
);
|
|
81405
81736
|
}),
|
|
81406
|
-
(reason) => new RefusedPushError(branch, reason)
|
|
81737
|
+
(reason, message2) => new RefusedPushError(branch, reason, void 0, message2)
|
|
81407
81738
|
);
|
|
81739
|
+
if (branch.startsWith(options.policy.namespace)) {
|
|
81740
|
+
const heads = await this.heads();
|
|
81741
|
+
const blocker = options.policy.namespaceBlocker(heads);
|
|
81742
|
+
if (blocker !== null) {
|
|
81743
|
+
throw new RefusedPushError(
|
|
81744
|
+
branch,
|
|
81745
|
+
"invalid",
|
|
81746
|
+
void 0,
|
|
81747
|
+
namespaceBlockedMessage(branch, blocker)
|
|
81748
|
+
);
|
|
81749
|
+
}
|
|
81750
|
+
const inside = [...heads.keys()].find((name2) => name2.startsWith(`${branch}/`));
|
|
81751
|
+
if (inside !== void 0) {
|
|
81752
|
+
throw new RefusedPushError(
|
|
81753
|
+
branch,
|
|
81754
|
+
"invalid",
|
|
81755
|
+
void 0,
|
|
81756
|
+
branchInsideMessage(branch, inside)
|
|
81757
|
+
);
|
|
81758
|
+
}
|
|
81759
|
+
}
|
|
81408
81760
|
options.onPushing?.();
|
|
81409
81761
|
const status = await this.githubBound(
|
|
81410
81762
|
credential,
|
|
@@ -81677,7 +82029,10 @@ var LocalGitHubGateway = class {
|
|
|
81677
82029
|
);
|
|
81678
82030
|
this.policy = new BranchPolicy({
|
|
81679
82031
|
baseBranch: options.baseBranch,
|
|
81680
|
-
protectedBranches: options.protectedBranches
|
|
82032
|
+
protectedBranches: options.protectedBranches,
|
|
82033
|
+
settingsBranch: options.settingsBranch,
|
|
82034
|
+
legacyBranches: options.legacyBranches,
|
|
82035
|
+
namespace: options.branchNamespace
|
|
81681
82036
|
});
|
|
81682
82037
|
}
|
|
81683
82038
|
get repo() {
|
|
@@ -81919,7 +82274,7 @@ var LocalGitHubGateway = class {
|
|
|
81919
82274
|
fatalError,
|
|
81920
82275
|
preflight: this.preflight,
|
|
81921
82276
|
clerkConfigured: this.options.authSnapshot !== void 0,
|
|
81922
|
-
|
|
82277
|
+
branchPolicy: this.policy.describe()
|
|
81923
82278
|
};
|
|
81924
82279
|
}
|
|
81925
82280
|
/**
|
|
@@ -82184,7 +82539,9 @@ var LocalGitHubGateway = class {
|
|
|
82184
82539
|
}
|
|
82185
82540
|
updatePullRequest(number, update, signal) {
|
|
82186
82541
|
return this.credentialed(signal, async (reach) => {
|
|
82187
|
-
|
|
82542
|
+
const refusing = `Refusing to ${update.state === "closed" ? "close" : "update"} pull request #${number}`;
|
|
82543
|
+
assertPullRequestText(refusing, `#${number}`, update);
|
|
82544
|
+
await this.assertOwnPullRequest(reach, number, refusing, signal);
|
|
82188
82545
|
await this.api(
|
|
82189
82546
|
reach,
|
|
82190
82547
|
() => this.octokit.pulls.update({
|
|
@@ -82196,14 +82553,67 @@ var LocalGitHubGateway = class {
|
|
|
82196
82553
|
);
|
|
82197
82554
|
});
|
|
82198
82555
|
}
|
|
82556
|
+
/**
|
|
82557
|
+
* Pull request `number`'s merge state, for any number, and its body only when `updatePullRequest`
|
|
82558
|
+
* would take its head: a branch of this repository that `BranchPolicy.takesPullRequestFrom`
|
|
82559
|
+
* admits (the namespace or a `legacyBranches` entry) and that is not protected, whoever opened
|
|
82560
|
+
* the pull request. Withholding more would protect nothing a write cannot change. When GitHub's
|
|
82561
|
+
* default branch cannot be read, the configured protected set and the default as last read
|
|
82562
|
+
* decide. The number comes from the worker, which a compromised CMS Lambda can steer; the head is
|
|
82563
|
+
* GitHub's record.
|
|
82564
|
+
*/
|
|
82199
82565
|
getPullRequest(number, signal) {
|
|
82200
|
-
return this.credentialed(signal, (reach) =>
|
|
82566
|
+
return this.credentialed(signal, async (reach) => {
|
|
82567
|
+
const { data: data3 } = await this.api(
|
|
82568
|
+
reach,
|
|
82569
|
+
() => this.octokit.pulls.get({ ...this.repo, pull_number: number, request: { signal } })
|
|
82570
|
+
);
|
|
82571
|
+
const head = data3.head.ref;
|
|
82572
|
+
let ours = data3.head.repo?.id === data3.base.repo.id && this.policy.takesPullRequestFrom(head);
|
|
82573
|
+
if (ours) {
|
|
82574
|
+
try {
|
|
82575
|
+
ours = !await this.policy.isProtected(head, () => this.readDefaultBranch(reach, signal));
|
|
82576
|
+
} catch (err) {
|
|
82577
|
+
if (signal?.aborted) throw err;
|
|
82578
|
+
if (this.policy.matchesLastReadDefault(head)) ours = false;
|
|
82579
|
+
gatewayLogWarn(
|
|
82580
|
+
`Could not read GitHub's default branch for pull request #${number} (${redactEgress(getErrorMessage(err))}); judging its head by the configured protected set and the default as last read`
|
|
82581
|
+
);
|
|
82582
|
+
}
|
|
82583
|
+
}
|
|
82584
|
+
return {
|
|
82585
|
+
merged: data3.merged,
|
|
82586
|
+
merged_at: data3.merged_at,
|
|
82587
|
+
state: data3.state,
|
|
82588
|
+
node_id: data3.node_id,
|
|
82589
|
+
body: ours ? data3.body ?? "" : null
|
|
82590
|
+
};
|
|
82591
|
+
});
|
|
82201
82592
|
}
|
|
82202
|
-
|
|
82593
|
+
/**
|
|
82594
|
+
* Read pull request `number` and refuse it unless its head is a branch of this repository that
|
|
82595
|
+
* a pull request may come from (`BranchPolicy.assertPullRequestHeadAllowed`). The number comes
|
|
82596
|
+
* from the worker; the head is GitHub's record, which the worker cannot choose.
|
|
82597
|
+
*/
|
|
82598
|
+
async assertOwnPullRequest(reach, number, refusing, signal) {
|
|
82203
82599
|
const { data: data3 } = await this.api(
|
|
82204
82600
|
reach,
|
|
82205
82601
|
() => this.octokit.pulls.get({ ...this.repo, pull_number: number, request: { signal } })
|
|
82206
82602
|
);
|
|
82603
|
+
const head = data3.head.ref;
|
|
82604
|
+
if (data3.head.repo?.id !== data3.base.repo.id) {
|
|
82605
|
+
throw new GatewayRefusalError(
|
|
82606
|
+
"pull-request",
|
|
82607
|
+
head,
|
|
82608
|
+
"outside-namespace",
|
|
82609
|
+
`${refusing}: its head is not a branch of this repository`
|
|
82610
|
+
);
|
|
82611
|
+
}
|
|
82612
|
+
await this.policy.assertPullRequestHeadAllowed(
|
|
82613
|
+
`${refusing}, whose head is ${JSON.stringify(head)}`,
|
|
82614
|
+
head,
|
|
82615
|
+
() => this.readDefaultBranch(reach, signal)
|
|
82616
|
+
);
|
|
82207
82617
|
return data3;
|
|
82208
82618
|
}
|
|
82209
82619
|
createOrUpdatePullRequest(request, signal) {
|
|
@@ -82223,7 +82633,12 @@ var LocalGitHubGateway = class {
|
|
|
82223
82633
|
}
|
|
82224
82634
|
convertPullRequestToDraft(number, signal) {
|
|
82225
82635
|
return this.credentialed(signal, async (reach) => {
|
|
82226
|
-
const pr = await this.
|
|
82636
|
+
const pr = await this.assertOwnPullRequest(
|
|
82637
|
+
reach,
|
|
82638
|
+
number,
|
|
82639
|
+
`Refusing to convert pull request #${number} to a draft`,
|
|
82640
|
+
signal
|
|
82641
|
+
);
|
|
82227
82642
|
await this.api(
|
|
82228
82643
|
reach,
|
|
82229
82644
|
() => this.octokit.graphql(
|
|
@@ -82655,12 +83070,14 @@ async function trackingTips(gitDir, branches) {
|
|
|
82655
83070
|
var OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
82656
83071
|
|
|
82657
83072
|
// ../canopycms/src/worker/cms-worker.ts
|
|
83073
|
+
init_branch_name();
|
|
83074
|
+
init_branch_namespace();
|
|
82658
83075
|
init_deployment_name();
|
|
82659
83076
|
init_error();
|
|
82660
83077
|
init_worker_status();
|
|
82661
83078
|
|
|
82662
83079
|
// ../canopycms/src/version.ts
|
|
82663
|
-
var CANOPYCMS_VERSION = "0.
|
|
83080
|
+
var CANOPYCMS_VERSION = "0.8.0";
|
|
82664
83081
|
|
|
82665
83082
|
// ../canopycms/src/worker/schema-gate.ts
|
|
82666
83083
|
import fs14 from "node:fs/promises";
|
|
@@ -82909,8 +83326,9 @@ async function decideBaseAdvance(input) {
|
|
|
82909
83326
|
return { kind: "advance-expired", hold: { ...hold, expired: true } };
|
|
82910
83327
|
}
|
|
82911
83328
|
|
|
82912
|
-
// ../canopycms/src/worker/
|
|
82913
|
-
import
|
|
83329
|
+
// ../canopycms/src/worker/unpublishable-branches.ts
|
|
83330
|
+
import fs19 from "node:fs/promises";
|
|
83331
|
+
import path20 from "node:path";
|
|
82914
83332
|
|
|
82915
83333
|
// ../canopycms/src/branch-metadata.ts
|
|
82916
83334
|
import fs18 from "node:fs/promises";
|
|
@@ -82987,7 +83405,13 @@ var branchMetadataShape = {
|
|
|
82987
83405
|
historyRewrittenFrom: external_exports.string().optional(),
|
|
82988
83406
|
syncFailureReason: external_exports.string().optional(),
|
|
82989
83407
|
editors: external_exports.array(external_exports.string()).optional(),
|
|
82990
|
-
uncommittedEditors: external_exports.array(external_exports.string()).optional()
|
|
83408
|
+
uncommittedEditors: external_exports.array(external_exports.string()).optional(),
|
|
83409
|
+
// Dropped when malformed: it only decorates the PR body, so it never fails a read.
|
|
83410
|
+
review: external_exports.object({
|
|
83411
|
+
state: external_exports.enum(["approved", "changes-requested"]),
|
|
83412
|
+
by: external_exports.object({ userId: external_exports.string(), name: external_exports.string().optional() }),
|
|
83413
|
+
at: external_exports.string()
|
|
83414
|
+
}).optional().catch(void 0)
|
|
82991
83415
|
};
|
|
82992
83416
|
var branchMetadataSchema = external_exports.object(branchMetadataShape).passthrough();
|
|
82993
83417
|
var branchMetadataFileSchema = external_exports.object({
|
|
@@ -83130,12 +83554,21 @@ var BranchRegistry = class {
|
|
|
83130
83554
|
* genuinely-absent branch costs at most one extra scan per window.
|
|
83131
83555
|
*/
|
|
83132
83556
|
async get(name2) {
|
|
83133
|
-
|
|
83134
|
-
|
|
83557
|
+
return this.find((b10) => b10.branch.name === name2);
|
|
83558
|
+
}
|
|
83559
|
+
/**
|
|
83560
|
+
* Returns the branch whose workspace directory is `key` (`sanitizeBranchName` of its ref),
|
|
83561
|
+
* whatever its name, with {@link get}'s backstop.
|
|
83562
|
+
*/
|
|
83563
|
+
async getByKey(key) {
|
|
83564
|
+
return this.find((b10) => path17.basename(b10.branchRoot) === key);
|
|
83565
|
+
}
|
|
83566
|
+
async find(matches2) {
|
|
83567
|
+
const found = (await this.list()).find(matches2);
|
|
83135
83568
|
if (found) return found;
|
|
83136
83569
|
if (!this.shouldForceRefresh()) return void 0;
|
|
83137
83570
|
const refreshed = await this.regenerate();
|
|
83138
|
-
return refreshed.find(
|
|
83571
|
+
return refreshed.find(matches2);
|
|
83139
83572
|
}
|
|
83140
83573
|
shouldForceRefresh() {
|
|
83141
83574
|
const now = Date.now();
|
|
@@ -83612,9 +84045,8 @@ function mergeBranchMetadata(existing, version, incoming, now = (/* @__PURE__ */
|
|
|
83612
84045
|
}
|
|
83613
84046
|
};
|
|
83614
84047
|
}
|
|
83615
|
-
function buildMergedBranchUpdate(
|
|
84048
|
+
function buildMergedBranchUpdate(now = /* @__PURE__ */ new Date()) {
|
|
83616
84049
|
return {
|
|
83617
|
-
name: branchName,
|
|
83618
84050
|
status: "archived",
|
|
83619
84051
|
pullRequestState: "merged",
|
|
83620
84052
|
mergedAt: now.toISOString(),
|
|
@@ -83627,7 +84059,110 @@ var getBranchMetadataFileManager = (branchRoot, baseRoot, options) => {
|
|
|
83627
84059
|
return BranchMetadataFileManager.get(branchRoot, baseRoot, options);
|
|
83628
84060
|
};
|
|
83629
84061
|
|
|
84062
|
+
// ../canopycms/src/worker/unpublishable-branches.ts
|
|
84063
|
+
init_branch_namespace();
|
|
84064
|
+
init_worker_status();
|
|
84065
|
+
init_error();
|
|
84066
|
+
var MAX_UNPUBLISHABLE_LISTED = 50;
|
|
84067
|
+
function reasonFor(name2, namespace) {
|
|
84068
|
+
if (namespace.startsWith(`${name2}/`)) return "blocks-namespace";
|
|
84069
|
+
if (legacyBranchProblem(name2) !== null) return "unlistable";
|
|
84070
|
+
return void 0;
|
|
84071
|
+
}
|
|
84072
|
+
async function findUnpublishableBranches(ctx, policy) {
|
|
84073
|
+
let entries;
|
|
84074
|
+
try {
|
|
84075
|
+
entries = await fs19.readdir(ctx.contentBranchesPath, { withFileTypes: true });
|
|
84076
|
+
} catch (err) {
|
|
84077
|
+
if (!isNodeError(err) || err.code !== "ENOENT") throw err;
|
|
84078
|
+
if (typeof err.path !== "string" || path20.resolve(err.path) !== path20.resolve(ctx.contentBranchesPath)) {
|
|
84079
|
+
throw err;
|
|
84080
|
+
}
|
|
84081
|
+
entries = [];
|
|
84082
|
+
}
|
|
84083
|
+
const dirs = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
84084
|
+
const branches = [];
|
|
84085
|
+
for (const dir of dirs.sort()) {
|
|
84086
|
+
if (dir.startsWith(".") || dir === ctx.sanitizedBaseBranch) continue;
|
|
84087
|
+
let meta;
|
|
84088
|
+
try {
|
|
84089
|
+
meta = await BranchMetadataFileManager.loadOnly(path20.join(ctx.contentBranchesPath, dir));
|
|
84090
|
+
} catch (err) {
|
|
84091
|
+
const notABranch = err instanceof BranchMetadataCorruptError || isNodeError(err) && err.code === "ENOENT";
|
|
84092
|
+
if (!notABranch) throw err;
|
|
84093
|
+
meta = null;
|
|
84094
|
+
}
|
|
84095
|
+
const branch = meta?.branch;
|
|
84096
|
+
if (!branch || branch.status === "archived") continue;
|
|
84097
|
+
if (publishesBranch(policy, branch.name)) continue;
|
|
84098
|
+
const reason = reasonFor(branch.name, policy.namespace);
|
|
84099
|
+
branches.push(reason ? { name: branch.name, reason } : { name: branch.name });
|
|
84100
|
+
}
|
|
84101
|
+
return { branches: branches.slice(0, MAX_UNPUBLISHABLE_LISTED), count: branches.length };
|
|
84102
|
+
}
|
|
84103
|
+
var REASONS = /* @__PURE__ */ new Set([
|
|
84104
|
+
"blocks-namespace",
|
|
84105
|
+
"unlistable"
|
|
84106
|
+
]);
|
|
84107
|
+
function isReason(value) {
|
|
84108
|
+
return REASONS.has(value);
|
|
84109
|
+
}
|
|
84110
|
+
var MAX_CARRIED_COUNT = 1e5;
|
|
84111
|
+
var MAX_CARRIED_AT_LENGTH = 32;
|
|
84112
|
+
function carriedReport(value) {
|
|
84113
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
84114
|
+
if (!("branches" in value) || !("count" in value) || !("at" in value)) return void 0;
|
|
84115
|
+
const { branches, count, at } = value;
|
|
84116
|
+
if (typeof at !== "string" || at.length > MAX_CARRIED_AT_LENGTH || !Number.isFinite(Date.parse(at)) || !Array.isArray(branches) || branches.length > MAX_UNPUBLISHABLE_LISTED || typeof count !== "number" || !Number.isInteger(count) || count < branches.length || count > MAX_CARRIED_COUNT) {
|
|
84117
|
+
return void 0;
|
|
84118
|
+
}
|
|
84119
|
+
const carried = [];
|
|
84120
|
+
for (const entry of branches) {
|
|
84121
|
+
if (typeof entry !== "object" || entry === null || !("name" in entry) || typeof entry.name !== "string" || entry.name.length > MAX_BRANCH_NAME_LENGTH2) {
|
|
84122
|
+
return void 0;
|
|
84123
|
+
}
|
|
84124
|
+
if (!("reason" in entry)) {
|
|
84125
|
+
carried.push({ name: entry.name });
|
|
84126
|
+
} else if (isReason(entry.reason)) {
|
|
84127
|
+
carried.push({ name: entry.name, reason: entry.reason });
|
|
84128
|
+
} else {
|
|
84129
|
+
return void 0;
|
|
84130
|
+
}
|
|
84131
|
+
}
|
|
84132
|
+
return { branches: carried, count, at };
|
|
84133
|
+
}
|
|
84134
|
+
async function readCarriedUnpublishableBranches(taskDir) {
|
|
84135
|
+
const parsed = await readStatusObject(taskDir);
|
|
84136
|
+
if (parsed === void 0 || !("unpublishableBranches" in parsed)) return void 0;
|
|
84137
|
+
return carriedReport(parsed.unpublishableBranches);
|
|
84138
|
+
}
|
|
84139
|
+
async function readCarriedGatewayPolicy(taskDir) {
|
|
84140
|
+
const parsed = await readStatusObject(taskDir);
|
|
84141
|
+
if (parsed === void 0 || !("gatewayBranchNamespace" in parsed)) return {};
|
|
84142
|
+
const namespace = parsed.gatewayBranchNamespace;
|
|
84143
|
+
if (typeof namespace !== "string" || branchNamespaceProblem(namespace) !== null) return {};
|
|
84144
|
+
const names = "gatewayProtectedBranches" in parsed ? parsed.gatewayProtectedBranches : void 0;
|
|
84145
|
+
return isExactNameList(names) ? { gatewayBranchNamespace: namespace, gatewayProtectedBranches: names } : { gatewayBranchNamespace: namespace };
|
|
84146
|
+
}
|
|
84147
|
+
function isExactNameList(value) {
|
|
84148
|
+
return Array.isArray(value) && value.length <= MAX_PROTECTED_BRANCHES + 1 && value.every(
|
|
84149
|
+
(name2) => typeof name2 === "string" && name2.length > 0 && name2.length <= MAX_BRANCH_NAME_LENGTH2 && !name2.includes("*")
|
|
84150
|
+
);
|
|
84151
|
+
}
|
|
84152
|
+
async function readStatusObject(taskDir) {
|
|
84153
|
+
try {
|
|
84154
|
+
const parsed = JSON.parse(
|
|
84155
|
+
await fs19.readFile(path20.join(taskDir, WORKER_STATUS_FILE), "utf-8")
|
|
84156
|
+
);
|
|
84157
|
+
return typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
84158
|
+
} catch {
|
|
84159
|
+
return void 0;
|
|
84160
|
+
}
|
|
84161
|
+
}
|
|
84162
|
+
|
|
83630
84163
|
// ../canopycms/src/worker/task-runner.ts
|
|
84164
|
+
import fs21 from "node:fs/promises";
|
|
84165
|
+
init_branch_name();
|
|
83631
84166
|
init_error();
|
|
83632
84167
|
|
|
83633
84168
|
// ../canopycms/src/worker/github-gateway-wire.ts
|
|
@@ -83689,9 +84224,12 @@ var answers = {
|
|
|
83689
84224
|
fatalError: message.nullable(),
|
|
83690
84225
|
preflight: external_exports.enum(["not-an-app", "verified", "unverified", "pending"]),
|
|
83691
84226
|
clerkConfigured: external_exports.boolean(),
|
|
83692
|
-
|
|
84227
|
+
branchPolicy: external_exports.object({
|
|
83693
84228
|
configured: external_exports.array(name).max(MAX_PROTECTED_BRANCHES + 1),
|
|
83694
|
-
githubDefault: name.nullable()
|
|
84229
|
+
githubDefault: name.nullable(),
|
|
84230
|
+
namespace: name,
|
|
84231
|
+
legacy: external_exports.array(name).max(MAX_LEGACY_BRANCHES),
|
|
84232
|
+
settingsBranch: name.nullable()
|
|
83695
84233
|
}).strict()
|
|
83696
84234
|
}).strict(),
|
|
83697
84235
|
defaultBranch: external_exports.object({ branch: name }).strict(),
|
|
@@ -83793,7 +84331,15 @@ var errorEnvelope = external_exports.discriminatedUnion("kind", [
|
|
|
83793
84331
|
push: external_exports.boolean(),
|
|
83794
84332
|
operation: external_exports.enum(["push", "delete", "pull-request"]),
|
|
83795
84333
|
branch: name,
|
|
83796
|
-
reason: external_exports.enum([
|
|
84334
|
+
reason: external_exports.enum([
|
|
84335
|
+
"invalid",
|
|
84336
|
+
"protected",
|
|
84337
|
+
"settings",
|
|
84338
|
+
"other-settings",
|
|
84339
|
+
"outside-namespace",
|
|
84340
|
+
"not-a-commit",
|
|
84341
|
+
"too-long"
|
|
84342
|
+
]),
|
|
83797
84343
|
message
|
|
83798
84344
|
}).strict(),
|
|
83799
84345
|
external_exports.object({
|
|
@@ -83995,7 +84541,8 @@ function decodePushHeader(value) {
|
|
|
83995
84541
|
}
|
|
83996
84542
|
|
|
83997
84543
|
// ../canopycms/src/worker/history-rewrite.ts
|
|
83998
|
-
import
|
|
84544
|
+
import path21 from "node:path";
|
|
84545
|
+
init_branch_name();
|
|
83999
84546
|
init_error();
|
|
84000
84547
|
async function readPublishedSha(ctx, branchRef) {
|
|
84001
84548
|
try {
|
|
@@ -84010,19 +84557,26 @@ async function readPublishedSha(ctx, branchRef) {
|
|
|
84010
84557
|
return null;
|
|
84011
84558
|
}
|
|
84012
84559
|
}
|
|
84013
|
-
async function markHistoryRewritten(ctx, branchPath,
|
|
84014
|
-
const current = await BranchMetadataFileManager.loadOnly(branchPath);
|
|
84015
|
-
if (typeof current?.branch.historyRewrittenFrom === "string") return;
|
|
84560
|
+
async function markHistoryRewritten(ctx, branchPath, branchRef, expectedSha) {
|
|
84016
84561
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84017
|
-
|
|
84562
|
+
let marked = false;
|
|
84563
|
+
await meta.update((current) => {
|
|
84564
|
+
marked = current?.branch.name === branchRef;
|
|
84565
|
+
if (!marked || typeof current?.branch.historyRewrittenFrom === "string") return null;
|
|
84566
|
+
return { branch: { historyRewrittenFrom: expectedSha } };
|
|
84567
|
+
});
|
|
84568
|
+
return marked;
|
|
84018
84569
|
}
|
|
84019
|
-
async function clearHistoryRewrittenMarker(ctx, branchPath,
|
|
84570
|
+
async function clearHistoryRewrittenMarker(ctx, branchPath, branchRef) {
|
|
84020
84571
|
try {
|
|
84021
84572
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84022
|
-
await meta.
|
|
84573
|
+
await meta.saveIf(
|
|
84574
|
+
{ branch: { historyRewrittenFrom: void 0 } },
|
|
84575
|
+
(current) => current?.branch.name === branchRef && typeof current.branch.historyRewrittenFrom === "string"
|
|
84576
|
+
);
|
|
84023
84577
|
} catch (err) {
|
|
84024
84578
|
workerLogWarn(
|
|
84025
|
-
` Failed to clear history-rewrite marker for ${
|
|
84579
|
+
` Failed to clear history-rewrite marker for ${branchRef}: ${getErrorMessage(err)}`
|
|
84026
84580
|
);
|
|
84027
84581
|
}
|
|
84028
84582
|
}
|
|
@@ -84050,7 +84604,13 @@ async function forcePublishToLocalRemote(ctx, branchPath, branchRef, expectedSha
|
|
|
84050
84604
|
return false;
|
|
84051
84605
|
}
|
|
84052
84606
|
}
|
|
84053
|
-
async function enqueueGitHubPush(ctx, branchRef) {
|
|
84607
|
+
async function enqueueGitHubPush(ctx, branchRef, gatewayPolicy) {
|
|
84608
|
+
if (gatewayPolicy && !publishesBranch(gatewayPolicy, branchRef)) {
|
|
84609
|
+
workerLog(
|
|
84610
|
+
` Not queueing a GitHub push for ${escapeForLog(branchRef)}: the GitHub gateway would refuse it`
|
|
84611
|
+
);
|
|
84612
|
+
return;
|
|
84613
|
+
}
|
|
84054
84614
|
try {
|
|
84055
84615
|
for (const status of ["pending", "processing"]) {
|
|
84056
84616
|
const inFlight = await listTasks(ctx.taskDir, status);
|
|
@@ -84065,7 +84625,7 @@ async function enqueueGitHubPush(ctx, branchRef) {
|
|
|
84065
84625
|
}
|
|
84066
84626
|
}
|
|
84067
84627
|
async function reconcilePendingRewrite(ctx, options) {
|
|
84068
|
-
const { branchPath, branchDir, branchRef, headSha, marker } = options;
|
|
84628
|
+
const { branchPath, branchDir, branchRef, headSha, marker, gatewayPolicy } = options;
|
|
84069
84629
|
const publishedSha = await readPublishedSha(ctx, branchRef);
|
|
84070
84630
|
if (publishedSha === null) {
|
|
84071
84631
|
workerLogWarn(
|
|
@@ -84074,12 +84634,12 @@ async function reconcilePendingRewrite(ctx, options) {
|
|
|
84074
84634
|
return;
|
|
84075
84635
|
}
|
|
84076
84636
|
if (publishedSha === headSha) {
|
|
84077
|
-
await enqueueGitHubPush(ctx, branchRef);
|
|
84637
|
+
await enqueueGitHubPush(ctx, branchRef, gatewayPolicy);
|
|
84078
84638
|
return;
|
|
84079
84639
|
}
|
|
84080
84640
|
if (publishedSha === marker) {
|
|
84081
84641
|
if (await forcePublishToLocalRemote(ctx, branchPath, branchRef, marker)) {
|
|
84082
|
-
await enqueueGitHubPush(ctx, branchRef);
|
|
84642
|
+
await enqueueGitHubPush(ctx, branchRef, gatewayPolicy);
|
|
84083
84643
|
}
|
|
84084
84644
|
return;
|
|
84085
84645
|
}
|
|
@@ -84089,7 +84649,7 @@ async function reconcilePendingRewrite(ctx, options) {
|
|
|
84089
84649
|
}
|
|
84090
84650
|
async function hasPendingHistoryRewrite(ctx, branchName) {
|
|
84091
84651
|
try {
|
|
84092
|
-
const branchPath =
|
|
84652
|
+
const branchPath = path21.join(ctx.contentBranchesPath, sanitizeBranchName(branchName));
|
|
84093
84653
|
const metaFile = await BranchMetadataFileManager.loadOnly(branchPath);
|
|
84094
84654
|
return typeof metaFile?.branch.historyRewrittenFrom === "string";
|
|
84095
84655
|
} catch {
|
|
@@ -84101,8 +84661,8 @@ async function hasPendingHistoryRewrite(ctx, branchName) {
|
|
|
84101
84661
|
init_worker_status();
|
|
84102
84662
|
|
|
84103
84663
|
// ../canopycms/src/comment-store.ts
|
|
84104
|
-
import
|
|
84105
|
-
import
|
|
84664
|
+
import fs20 from "node:fs/promises";
|
|
84665
|
+
import path22 from "node:path";
|
|
84106
84666
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
84107
84667
|
init_error();
|
|
84108
84668
|
var CommentStoreConflictError = class extends Error {
|
|
@@ -84114,9 +84674,11 @@ var CommentStoreConflictError = class extends Error {
|
|
|
84114
84674
|
function ownThread(data3, threadId) {
|
|
84115
84675
|
return Object.prototype.hasOwnProperty.call(data3.threads, threadId) ? data3.threads[threadId] : void 0;
|
|
84116
84676
|
}
|
|
84677
|
+
var CommentsFileMalformedError = class extends Error {
|
|
84678
|
+
};
|
|
84117
84679
|
var CommentStore = class {
|
|
84118
84680
|
constructor(branchRoot, options) {
|
|
84119
|
-
this.filePath =
|
|
84681
|
+
this.filePath = path22.join(path22.resolve(branchRoot), ".canopy-meta", "comments.json");
|
|
84120
84682
|
this.settleMs = options?.settleMs;
|
|
84121
84683
|
}
|
|
84122
84684
|
/**
|
|
@@ -84126,7 +84688,7 @@ var CommentStore = class {
|
|
|
84126
84688
|
async listThreadsStrict() {
|
|
84127
84689
|
let content;
|
|
84128
84690
|
try {
|
|
84129
|
-
content = await
|
|
84691
|
+
content = await fs20.readFile(this.filePath, "utf-8");
|
|
84130
84692
|
} catch (err) {
|
|
84131
84693
|
if (isNotFoundError2(err)) return [];
|
|
84132
84694
|
throw err;
|
|
@@ -84134,7 +84696,7 @@ var CommentStore = class {
|
|
|
84134
84696
|
const parsed = JSON.parse(content);
|
|
84135
84697
|
const threads = typeof parsed === "object" && parsed !== null ? parsed.threads : void 0;
|
|
84136
84698
|
if (typeof threads !== "object" || threads === null) {
|
|
84137
|
-
throw new
|
|
84699
|
+
throw new CommentsFileMalformedError("comments.json has no threads object");
|
|
84138
84700
|
}
|
|
84139
84701
|
return Object.values(threads);
|
|
84140
84702
|
}
|
|
@@ -84150,7 +84712,7 @@ var CommentStore = class {
|
|
|
84150
84712
|
*/
|
|
84151
84713
|
async loadWithVersion() {
|
|
84152
84714
|
try {
|
|
84153
|
-
const content = await
|
|
84715
|
+
const content = await fs20.readFile(this.filePath, "utf-8");
|
|
84154
84716
|
const parsed = JSON.parse(content);
|
|
84155
84717
|
const version = parsed.version ?? 0;
|
|
84156
84718
|
return { data: { ...parsed, version }, version };
|
|
@@ -84321,24 +84883,48 @@ var CommentStore = class {
|
|
|
84321
84883
|
init_error();
|
|
84322
84884
|
var SYNC_PR_COMMENTS_ACTION = "sync-pr-comments";
|
|
84323
84885
|
async function renderPrCommentsBody(options) {
|
|
84324
|
-
const
|
|
84325
|
-
|
|
84326
|
-
|
|
84327
|
-
|
|
84328
|
-
|
|
84329
|
-
|
|
84886
|
+
const original = options.body;
|
|
84887
|
+
let next = original;
|
|
84888
|
+
try {
|
|
84889
|
+
const threads = await new CommentStore(options.branchRoot).listThreadsStrict();
|
|
84890
|
+
next = mergeCommentsBlock(next, buildCommentsBlock(threads, options.branch, options.editorUrl)) ?? next;
|
|
84891
|
+
} catch (err) {
|
|
84892
|
+
if (!(err instanceof SyntaxError || err instanceof CommentsFileMalformedError)) throw err;
|
|
84893
|
+
options.warn(
|
|
84894
|
+
`Could not read the editor comments of ${options.branch}; the PR keeps its summary: ${getErrorMessage(err)}`
|
|
84895
|
+
);
|
|
84896
|
+
}
|
|
84897
|
+
try {
|
|
84898
|
+
const file = await readBranchMetadataFile(options.branchRoot);
|
|
84899
|
+
if (file) next = mergeReviewBlock(next, buildReviewBlock(file.branch.review)) ?? next;
|
|
84900
|
+
} catch (err) {
|
|
84901
|
+
if (!(err instanceof BranchMetadataCorruptError)) throw err;
|
|
84902
|
+
options.warn(
|
|
84903
|
+
`Could not read the review state of ${options.branch}; the PR keeps its review block: ${getErrorMessage(err)}`
|
|
84904
|
+
);
|
|
84905
|
+
}
|
|
84906
|
+
return next === original ? void 0 : next;
|
|
84330
84907
|
}
|
|
84331
84908
|
async function refreshCommentsBlock(options) {
|
|
84909
|
+
let section = options.section;
|
|
84332
84910
|
try {
|
|
84333
84911
|
const threads = await new CommentStore(options.branchRoot).listThreadsStrict();
|
|
84334
84912
|
const block = buildCommentsBlock(threads, options.branch, options.editorUrl);
|
|
84335
|
-
|
|
84913
|
+
section = mergeCommentsBlock(section, block) ?? section;
|
|
84336
84914
|
} catch (err) {
|
|
84337
84915
|
options.warn(
|
|
84338
84916
|
`Could not re-read the editor comments of ${options.branch}; the PR gets the summary from submit time: ${getErrorMessage(err)}`
|
|
84339
84917
|
);
|
|
84340
|
-
return options.section;
|
|
84341
84918
|
}
|
|
84919
|
+
try {
|
|
84920
|
+
const file = await readBranchMetadataFile(options.branchRoot);
|
|
84921
|
+
if (file) section = mergeReviewBlock(section, buildReviewBlock(file.branch.review)) ?? section;
|
|
84922
|
+
} catch (err) {
|
|
84923
|
+
options.warn(
|
|
84924
|
+
`Could not re-read the review state of ${options.branch}; the PR gets it from submit time: ${getErrorMessage(err)}`
|
|
84925
|
+
);
|
|
84926
|
+
}
|
|
84927
|
+
return section;
|
|
84342
84928
|
}
|
|
84343
84929
|
|
|
84344
84930
|
// ../canopycms/src/worker/task-runner.ts
|
|
@@ -84492,7 +85078,7 @@ async function executeTask(ctx, task, signal) {
|
|
|
84492
85078
|
{
|
|
84493
85079
|
head: branch,
|
|
84494
85080
|
base: optionalString(payload3, "baseBranch", ctx.baseBranch),
|
|
84495
|
-
title: optionalString(payload3, "title", `Submit ${branch}`),
|
|
85081
|
+
title: optionalString(payload3, "title", `Submit ${editorBranchOf(payload3, branch)}`),
|
|
84496
85082
|
body: optionalString(payload3, "body", "")
|
|
84497
85083
|
},
|
|
84498
85084
|
signal
|
|
@@ -84507,7 +85093,7 @@ async function executeTask(ctx, task, signal) {
|
|
|
84507
85093
|
await ctx.github().updatePullRequest(
|
|
84508
85094
|
prNumber2,
|
|
84509
85095
|
{
|
|
84510
|
-
title: optionalString(payload3, "title", `Submit ${branch}`),
|
|
85096
|
+
title: optionalString(payload3, "title", `Submit ${editorBranchOf(payload3, branch)}`),
|
|
84511
85097
|
body: optionalString(payload3, "body", "")
|
|
84512
85098
|
},
|
|
84513
85099
|
signal
|
|
@@ -84533,7 +85119,7 @@ async function executeTask(ctx, task, signal) {
|
|
|
84533
85119
|
const queuedBody = optionalString(payload3, "body", "");
|
|
84534
85120
|
const body = mergeSectionIntoBody ? await refreshCommentsBlock({
|
|
84535
85121
|
branchRoot: ctx.branchWorkspacePath(branch),
|
|
84536
|
-
branch,
|
|
85122
|
+
branch: editorBranchOf(payload3, branch),
|
|
84537
85123
|
editorUrl: typeof payload3.editorUrl === "string" ? payload3.editorUrl : void 0,
|
|
84538
85124
|
section: queuedBody,
|
|
84539
85125
|
warn: workerLogWarn
|
|
@@ -84544,7 +85130,7 @@ async function executeTask(ctx, task, signal) {
|
|
|
84544
85130
|
{
|
|
84545
85131
|
head: branch,
|
|
84546
85132
|
base,
|
|
84547
|
-
title: optionalString(payload3, "title", `Submit ${branch}`),
|
|
85133
|
+
title: optionalString(payload3, "title", `Submit ${editorBranchOf(payload3, branch)}`),
|
|
84548
85134
|
body,
|
|
84549
85135
|
// Content submits (api/github-sync.ts) set both.
|
|
84550
85136
|
markReadyIfDraft: payload3.markReadyIfDraft === true,
|
|
@@ -84633,57 +85219,67 @@ async function executeTask(ctx, task, signal) {
|
|
|
84633
85219
|
}
|
|
84634
85220
|
const pr = await ctx.github().getPullRequest(prNumber2, signal);
|
|
84635
85221
|
if (pr.state !== "open") return { updated: false, skipped: "not-open" };
|
|
85222
|
+
if (pr.body === null) {
|
|
85223
|
+
workerLog(`Not updating PR #${prNumber2} for ${branch}: the gateway withholds its body`);
|
|
85224
|
+
return { updated: false, skipped: "body-withheld" };
|
|
85225
|
+
}
|
|
84636
85226
|
const body = await renderPrCommentsBody({
|
|
84637
85227
|
branchRoot: branchPath,
|
|
84638
|
-
branch,
|
|
85228
|
+
branch: editorBranchOf(payload3, branch),
|
|
84639
85229
|
editorUrl,
|
|
84640
|
-
body: pr.body
|
|
84641
|
-
|
|
84642
|
-
if (err instanceof SyntaxError) throw new PermanentTaskError(getErrorMessage(err));
|
|
84643
|
-
throw err;
|
|
85230
|
+
body: pr.body,
|
|
85231
|
+
warn: workerLogWarn
|
|
84644
85232
|
});
|
|
84645
85233
|
if (body === void 0) return { updated: false, skipped: "unchanged" };
|
|
84646
85234
|
await ctx.github().updatePullRequest(prNumber2, { body }, signal);
|
|
84647
|
-
workerLog(`Updated the
|
|
85235
|
+
workerLog(`Updated the comment and review blocks of PR #${prNumber2} for ${branch}`);
|
|
84648
85236
|
return { updated: true };
|
|
84649
85237
|
}
|
|
84650
85238
|
default:
|
|
84651
85239
|
throw new PermanentTaskError(`Unknown task action: ${action}`);
|
|
84652
85240
|
}
|
|
84653
85241
|
}
|
|
85242
|
+
function editorBranchOf(payload3, branch) {
|
|
85243
|
+
return optionalString(payload3, "editorBranch", branch);
|
|
85244
|
+
}
|
|
84654
85245
|
function metadataBranchOf(task) {
|
|
84655
85246
|
if (task.action === "delete-remote-branch" || task.action === SYNC_PR_COMMENTS_ACTION) return null;
|
|
84656
85247
|
return typeof task.payload.branch === "string" ? task.payload.branch : null;
|
|
84657
85248
|
}
|
|
85249
|
+
function noMetadataToRecord(branch, what) {
|
|
85250
|
+
workerLogWarn(`Not recording the ${what} for ${branch}: its workspace has no branch.json for it`);
|
|
85251
|
+
}
|
|
84658
85252
|
async function updateBranchMetadata(ctx, task, result) {
|
|
84659
85253
|
const branch = metadataBranchOf(task);
|
|
84660
85254
|
if (!branch) return;
|
|
84661
85255
|
const branchPath = ctx.branchWorkspacePath(branch);
|
|
84662
85256
|
try {
|
|
84663
|
-
await
|
|
85257
|
+
await fs21.stat(branchPath);
|
|
84664
85258
|
} catch {
|
|
84665
85259
|
return;
|
|
84666
85260
|
}
|
|
84667
85261
|
try {
|
|
84668
85262
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84669
|
-
const
|
|
84670
|
-
name
|
|
84671
|
-
|
|
84672
|
-
|
|
84673
|
-
|
|
84674
|
-
|
|
84675
|
-
|
|
84676
|
-
|
|
84677
|
-
|
|
84678
|
-
|
|
84679
|
-
|
|
84680
|
-
|
|
84681
|
-
|
|
84682
|
-
|
|
84683
|
-
|
|
84684
|
-
|
|
84685
|
-
|
|
84686
|
-
|
|
85263
|
+
const saved = await meta.update((existing) => {
|
|
85264
|
+
if (existing?.branch.name !== branch) return null;
|
|
85265
|
+
const updates = {
|
|
85266
|
+
syncStatus: "synced",
|
|
85267
|
+
// save()'s merge only overwrites keys present in this update, so a prior
|
|
85268
|
+
// syncFailureReason would survive this successful sync forever unless
|
|
85269
|
+
// cleared explicitly (same pattern as rebaseFailure elsewhere).
|
|
85270
|
+
syncFailureReason: void 0
|
|
85271
|
+
};
|
|
85272
|
+
if (result.prUrl) updates.pullRequestUrl = result.prUrl;
|
|
85273
|
+
if (result.prNumber) {
|
|
85274
|
+
updates.pullRequestNumber = result.prNumber;
|
|
85275
|
+
const terminal = existing.branch.status === "archived" || existing.branch.pullRequestState === "merged" || existing.branch.pullRequestState === "closed";
|
|
85276
|
+
if (!terminal) {
|
|
85277
|
+
updates.pullRequestState = "open";
|
|
85278
|
+
}
|
|
85279
|
+
}
|
|
85280
|
+
return { branch: updates };
|
|
85281
|
+
});
|
|
85282
|
+
if (saved === null) noMetadataToRecord(branch, `${task.action} outcome`);
|
|
84687
85283
|
} catch (err) {
|
|
84688
85284
|
workerLogError(
|
|
84689
85285
|
`Failed to update metadata for ${branch}:`,
|
|
@@ -84696,13 +85292,13 @@ async function updateBranchMetadataOnFailure(ctx, task, error3, options) {
|
|
|
84696
85292
|
if (!branch) return;
|
|
84697
85293
|
const branchPath = ctx.branchWorkspacePath(branch);
|
|
84698
85294
|
try {
|
|
84699
|
-
await
|
|
85295
|
+
await fs21.stat(branchPath);
|
|
84700
85296
|
} catch {
|
|
84701
85297
|
return;
|
|
84702
85298
|
}
|
|
84703
85299
|
try {
|
|
84704
85300
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84705
|
-
const failed = {
|
|
85301
|
+
const failed = { syncStatus: "sync-failed", syncFailureReason: error3 };
|
|
84706
85302
|
const submittedAt = task.payload.submittedAt;
|
|
84707
85303
|
const unlocked = options.unlock && typeof submittedAt === "string" && await meta.saveIf(
|
|
84708
85304
|
{
|
|
@@ -84712,9 +85308,15 @@ async function updateBranchMetadataOnFailure(ctx, task, error3, options) {
|
|
|
84712
85308
|
syncFailureReason: `${error3} The branch is unlocked for editing; save a change, then submit again.`
|
|
84713
85309
|
}
|
|
84714
85310
|
},
|
|
84715
|
-
(existing) => existing?.branch.status === "submitted" && existing.branch.pullRequestNumber === void 0 && existing.branch.submittedAt === submittedAt
|
|
85311
|
+
(existing) => existing?.branch.name === branch && existing.branch.status === "submitted" && existing.branch.pullRequestNumber === void 0 && existing.branch.submittedAt === submittedAt
|
|
84716
85312
|
) !== null;
|
|
84717
|
-
if (!unlocked)
|
|
85313
|
+
if (!unlocked) {
|
|
85314
|
+
const saved = await meta.saveIf(
|
|
85315
|
+
{ branch: failed },
|
|
85316
|
+
(existing) => existing?.branch.name === branch
|
|
85317
|
+
);
|
|
85318
|
+
if (saved === null) noMetadataToRecord(branch, `${task.action} failure`);
|
|
85319
|
+
}
|
|
84718
85320
|
} catch (err) {
|
|
84719
85321
|
workerLogError(
|
|
84720
85322
|
`Failed to update failure metadata for ${branch}:`,
|
|
@@ -84808,32 +85410,35 @@ function logPushOutcome(ctx, branch, outcome, note) {
|
|
|
84808
85410
|
async function recordPushedToGitHub(ctx, branchPath, branch) {
|
|
84809
85411
|
if (isSettingsBranch(branch)) return;
|
|
84810
85412
|
try {
|
|
84811
|
-
await
|
|
85413
|
+
await fs21.stat(branchPath);
|
|
84812
85414
|
} catch {
|
|
84813
85415
|
return;
|
|
84814
85416
|
}
|
|
84815
85417
|
try {
|
|
84816
|
-
await getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath).
|
|
84817
|
-
branch: {
|
|
84818
|
-
|
|
85418
|
+
const saved = await getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath).saveIf(
|
|
85419
|
+
{ branch: { pushedToGitHubAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
85420
|
+
(existing) => existing?.branch.name === branch
|
|
85421
|
+
);
|
|
85422
|
+
if (saved === null) noMetadataToRecord(branch, "GitHub push");
|
|
84819
85423
|
} catch (err) {
|
|
84820
85424
|
workerLogError(`Failed to record the GitHub push for ${branch}:`, getErrorMessage(err));
|
|
84821
85425
|
}
|
|
84822
85426
|
}
|
|
84823
85427
|
|
|
84824
85428
|
// ../canopycms/src/worker/rebase.ts
|
|
84825
|
-
import
|
|
84826
|
-
import
|
|
85429
|
+
import fs23 from "node:fs/promises";
|
|
85430
|
+
import path25 from "node:path";
|
|
85431
|
+
init_branch_name();
|
|
84827
85432
|
init_normalize();
|
|
84828
85433
|
init_types2();
|
|
84829
85434
|
|
|
84830
85435
|
// ../canopycms/src/utils/content-write-lock.ts
|
|
84831
85436
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
84832
|
-
import
|
|
85437
|
+
import path23 from "node:path";
|
|
84833
85438
|
var META_DIR2 = ".canopy-meta";
|
|
84834
85439
|
var CONTENT_WRITE_LOCK_NAME = "content-write.lock";
|
|
84835
85440
|
function lockTargetDir(branchRoot) {
|
|
84836
|
-
return
|
|
85441
|
+
return path23.join(path23.resolve(branchRoot), META_DIR2);
|
|
84837
85442
|
}
|
|
84838
85443
|
var CONTENT_WRITE_LOCK_STALE_MS = 3e4;
|
|
84839
85444
|
function tryAcquireContentWriteLock(branchRoot, onCompromised) {
|
|
@@ -84848,8 +85453,8 @@ function tryAcquireContentWriteLock(branchRoot, onCompromised) {
|
|
|
84848
85453
|
var heldRoots = new AsyncLocalStorage();
|
|
84849
85454
|
|
|
84850
85455
|
// ../canopycms/src/worker/provisioned-workspace.ts
|
|
84851
|
-
import
|
|
84852
|
-
import
|
|
85456
|
+
import fs22 from "node:fs/promises";
|
|
85457
|
+
import path24 from "node:path";
|
|
84853
85458
|
init_error();
|
|
84854
85459
|
async function holdProvisionedWorkspace(contentBranchesPath, dirName) {
|
|
84855
85460
|
let release2;
|
|
@@ -84869,13 +85474,13 @@ async function holdProvisionedWorkspace(contentBranchesPath, dirName) {
|
|
|
84869
85474
|
if (isNodeError(err) && err.code === "ELOCKED") return { kind: "locked" };
|
|
84870
85475
|
throw err;
|
|
84871
85476
|
}
|
|
84872
|
-
const root5 =
|
|
85477
|
+
const root5 = path24.join(contentBranchesPath, dirName);
|
|
84873
85478
|
const [gitIsDir, hasMetadata] = await Promise.all([
|
|
84874
|
-
|
|
85479
|
+
fs22.stat(path24.join(root5, ".git")).then(
|
|
84875
85480
|
(stat) => stat.isDirectory(),
|
|
84876
85481
|
() => false
|
|
84877
85482
|
),
|
|
84878
|
-
|
|
85483
|
+
fs22.stat(path24.join(root5, BRANCH_META_DIR, BRANCH_META_FILE)).then(
|
|
84879
85484
|
() => true,
|
|
84880
85485
|
() => false
|
|
84881
85486
|
)
|
|
@@ -84897,34 +85502,35 @@ init_error();
|
|
|
84897
85502
|
async function pollMergeState(ctx, branchDir, branchPath, metaFile) {
|
|
84898
85503
|
const prNumber2 = metaFile?.branch.pullRequestNumber;
|
|
84899
85504
|
if (!prNumber2) return;
|
|
85505
|
+
const sameBranch2 = (current) => current?.branch.name === metaFile?.branch.name;
|
|
84900
85506
|
const controller = new AbortController();
|
|
84901
85507
|
const timer = setTimeout(() => controller.abort(), ctx.taskTimeoutMs);
|
|
84902
85508
|
try {
|
|
84903
85509
|
const data3 = await ctx.github().getPullRequest(prNumber2, controller.signal);
|
|
84904
85510
|
if (data3.merged) {
|
|
84905
85511
|
const meta2 = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84906
|
-
await meta2.
|
|
84907
|
-
|
|
84908
|
-
|
|
84909
|
-
|
|
84910
|
-
|
|
84911
|
-
|
|
84912
|
-
workerLog(` PR #${prNumber2} for ${branchDir} is merged -> archived`);
|
|
85512
|
+
const saved2 = await meta2.saveIf(
|
|
85513
|
+
{
|
|
85514
|
+
branch: buildMergedBranchUpdate(data3.merged_at ? new Date(data3.merged_at) : void 0)
|
|
85515
|
+
},
|
|
85516
|
+
sameBranch2
|
|
85517
|
+
);
|
|
85518
|
+
if (saved2) workerLog(` PR #${prNumber2} for ${branchDir} is merged -> archived`);
|
|
84913
85519
|
return;
|
|
84914
85520
|
}
|
|
84915
85521
|
const newState = data3.state === "closed" ? "closed" : "open";
|
|
84916
85522
|
const currentMeta = await BranchMetadataFileManager.loadOnly(branchPath);
|
|
84917
85523
|
if (currentMeta?.branch.pullRequestState === newState) return;
|
|
84918
85524
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84919
|
-
await meta.
|
|
84920
|
-
workerLog(` PR #${prNumber2} for ${branchDir}: pullRequestState -> ${newState}`);
|
|
85525
|
+
const saved = await meta.saveIf({ branch: { pullRequestState: newState } }, sameBranch2);
|
|
85526
|
+
if (saved) workerLog(` PR #${prNumber2} for ${branchDir}: pullRequestState -> ${newState}`);
|
|
84921
85527
|
} catch (err) {
|
|
84922
85528
|
workerLogWarn(` Failed to poll PR #${prNumber2} for ${branchDir}: ${getErrorMessage(err)}`);
|
|
84923
85529
|
} finally {
|
|
84924
85530
|
clearTimeout(timer);
|
|
84925
85531
|
}
|
|
84926
85532
|
}
|
|
84927
|
-
async function recordRebaseFailure(ctx, branchPath, branchDir, message2) {
|
|
85533
|
+
async function recordRebaseFailure(ctx, branchPath, branchDir, message2, branchRef) {
|
|
84928
85534
|
const RECORD_REFRESH_MS = 60 * 60 * 1e3;
|
|
84929
85535
|
const redactedMessage = redactCredentials(message2);
|
|
84930
85536
|
try {
|
|
@@ -84941,12 +85547,10 @@ async function recordRebaseFailure(ctx, branchPath, branchDir, message2) {
|
|
|
84941
85547
|
const nowIso = now.toISOString();
|
|
84942
85548
|
const firstAt = sameMessage ? prior.firstAt : nowIso;
|
|
84943
85549
|
const meta = getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath);
|
|
84944
|
-
await meta.
|
|
84945
|
-
branch: {
|
|
84946
|
-
|
|
84947
|
-
|
|
84948
|
-
}
|
|
84949
|
-
});
|
|
85550
|
+
await meta.saveIf(
|
|
85551
|
+
{ branch: { rebaseFailure: { message: redactedMessage, firstAt, lastAt: nowIso } } },
|
|
85552
|
+
(current) => current !== null && (branchRef === void 0 || current.branch.name === branchRef)
|
|
85553
|
+
);
|
|
84950
85554
|
} catch (err) {
|
|
84951
85555
|
workerLogWarn(` Failed to record rebase failure for ${branchDir}: ${getErrorMessage(err)}`);
|
|
84952
85556
|
}
|
|
@@ -85015,13 +85619,13 @@ async function runRebaseRounds(ctx, branchGit, branchDir, fetchedBaseTip, isLock
|
|
|
85015
85619
|
function conflictFilesToContentIds(conflictedFiles, contentRoot) {
|
|
85016
85620
|
const normalizedContentRoot = normalizeFilesystemPath(contentRoot);
|
|
85017
85621
|
const conflictIds = [...new Set(conflictedFiles)].map((f9) => {
|
|
85018
|
-
const fileId = extractIdFromFilename(
|
|
85622
|
+
const fileId = extractIdFromFilename(path25.basename(f9));
|
|
85019
85623
|
if (fileId) return fileId;
|
|
85020
|
-
const parentDir =
|
|
85624
|
+
const parentDir = path25.basename(path25.dirname(f9));
|
|
85021
85625
|
const dirId = extractIdFromFilename(parentDir);
|
|
85022
85626
|
if (dirId) return dirId;
|
|
85023
|
-
const parentPath = normalizeFilesystemPath(
|
|
85024
|
-
if (
|
|
85627
|
+
const parentPath = normalizeFilesystemPath(path25.dirname(f9));
|
|
85628
|
+
if (path25.basename(f9) === ".collection.json" && parentPath === normalizedContentRoot) {
|
|
85025
85629
|
return ROOT_COLLECTION_ID;
|
|
85026
85630
|
}
|
|
85027
85631
|
return null;
|
|
@@ -85036,28 +85640,33 @@ function recordConflicts(recorded, found) {
|
|
|
85036
85640
|
};
|
|
85037
85641
|
}
|
|
85038
85642
|
async function carryForwardRewrittenHistory(ctx, args) {
|
|
85039
|
-
const { branchPath, branchDir, branchRef, publishedSha, preRebaseHead } = args;
|
|
85643
|
+
const { branchPath, branchDir, branchRef, publishedSha, preRebaseHead, gatewayPolicy } = args;
|
|
85040
85644
|
if (publishedSha !== null) {
|
|
85041
85645
|
if (publishedSha === preRebaseHead) {
|
|
85042
|
-
await markHistoryRewritten(ctx, branchPath,
|
|
85646
|
+
if (!await markHistoryRewritten(ctx, branchPath, branchRef, publishedSha)) {
|
|
85647
|
+
workerLogWarn(
|
|
85648
|
+
` ${branchDir}: rebased, but its branch.json is gone or names another branch than ${branchRef}, so the rewrite is not published`
|
|
85649
|
+
);
|
|
85650
|
+
return;
|
|
85651
|
+
}
|
|
85043
85652
|
if (await forcePublishToLocalRemote(ctx, branchPath, branchRef, publishedSha)) {
|
|
85044
|
-
await enqueueGitHubPush(ctx, branchRef);
|
|
85653
|
+
await enqueueGitHubPush(ctx, branchRef, gatewayPolicy);
|
|
85045
85654
|
}
|
|
85046
85655
|
} else {
|
|
85047
85656
|
const divergence = `rebased locally, but remote.git holds ${publishedSha} for ${branchRef}, which this clone never had (a direct push to the branch?). Left untouched -- reconcile it before submitting again.`;
|
|
85048
85657
|
workerLogWarn(` ${branchDir}: ${divergence}`);
|
|
85049
|
-
await recordRebaseFailure(ctx, branchPath, branchDir, divergence);
|
|
85658
|
+
await recordRebaseFailure(ctx, branchPath, branchDir, divergence, branchRef);
|
|
85050
85659
|
}
|
|
85051
85660
|
}
|
|
85052
85661
|
}
|
|
85053
|
-
async function runRebaseCycle(ctx) {
|
|
85662
|
+
async function runRebaseCycle(ctx, gatewayPolicy) {
|
|
85054
85663
|
const rebased = [];
|
|
85055
85664
|
const skippedDirty = [];
|
|
85056
85665
|
const skippedLocked = [];
|
|
85057
85666
|
const failed = [];
|
|
85058
85667
|
let branchDirs;
|
|
85059
85668
|
try {
|
|
85060
|
-
branchDirs = await
|
|
85669
|
+
branchDirs = await fs23.readdir(ctx.contentBranchesPath);
|
|
85061
85670
|
} catch {
|
|
85062
85671
|
return { rebased, skippedDirty, skippedLocked, failed };
|
|
85063
85672
|
}
|
|
@@ -85069,10 +85678,10 @@ async function runRebaseCycle(ctx) {
|
|
|
85069
85678
|
if (branchDir.startsWith(".") || branchDir === "branches.json") {
|
|
85070
85679
|
continue;
|
|
85071
85680
|
}
|
|
85072
|
-
const branchPath =
|
|
85073
|
-
const gitDir =
|
|
85681
|
+
const branchPath = path25.join(ctx.contentBranchesPath, branchDir);
|
|
85682
|
+
const gitDir = path25.join(branchPath, ".git");
|
|
85074
85683
|
try {
|
|
85075
|
-
const stat = await
|
|
85684
|
+
const stat = await fs23.stat(gitDir);
|
|
85076
85685
|
if (!stat.isDirectory()) {
|
|
85077
85686
|
workerLog(` Skipping ${branchDir}: .git is not a directory`);
|
|
85078
85687
|
continue;
|
|
@@ -85089,7 +85698,7 @@ async function runRebaseCycle(ctx) {
|
|
|
85089
85698
|
workerLogWarn(` Skipping ${branchDir}: settings branch, never a content workspace`);
|
|
85090
85699
|
continue;
|
|
85091
85700
|
}
|
|
85092
|
-
const outcome = await holdAndRebaseOneBranch(ctx, branchDir, branchPath);
|
|
85701
|
+
const outcome = await holdAndRebaseOneBranch(ctx, branchDir, branchPath, gatewayPolicy);
|
|
85093
85702
|
if (outcome.kind === "rebased") rebased.push(branchDir);
|
|
85094
85703
|
else if (outcome.kind === "skippedDirty") skippedDirty.push(branchDir);
|
|
85095
85704
|
else if (outcome.kind === "skippedLocked") skippedLocked.push(branchDir);
|
|
@@ -85100,7 +85709,41 @@ async function runRebaseCycle(ctx) {
|
|
|
85100
85709
|
}
|
|
85101
85710
|
return { rebased, skippedDirty, skippedLocked, failed };
|
|
85102
85711
|
}
|
|
85103
|
-
async function
|
|
85712
|
+
async function readCloneRef(branchPath) {
|
|
85713
|
+
try {
|
|
85714
|
+
const head = (await fs23.readFile(path25.join(branchPath, ".git", "HEAD"), "utf-8")).trim();
|
|
85715
|
+
return head.startsWith("ref: refs/heads/") ? head.slice("ref: refs/heads/".length) : null;
|
|
85716
|
+
} catch {
|
|
85717
|
+
return null;
|
|
85718
|
+
}
|
|
85719
|
+
}
|
|
85720
|
+
async function restoreRenamedBranch(ctx, branchDir, branchPath, metaFile, namespace) {
|
|
85721
|
+
if (metaFile === null || namespace === void 0 || metaFile.branch.name.startsWith(namespace)) {
|
|
85722
|
+
return metaFile;
|
|
85723
|
+
}
|
|
85724
|
+
const staleName = metaFile.branch.name;
|
|
85725
|
+
const ref = await readCloneRef(branchPath);
|
|
85726
|
+
if (ref === null || !ref.startsWith(namespace) || sanitizeBranchName(ref) !== branchDir) {
|
|
85727
|
+
return metaFile;
|
|
85728
|
+
}
|
|
85729
|
+
try {
|
|
85730
|
+
const restored = await getBranchMetadataFileManager(branchPath, ctx.contentBranchesPath).update(
|
|
85731
|
+
(existing) => existing?.branch.name === staleName ? { branch: { name: ref } } : null,
|
|
85732
|
+
{ keepUpdatedAt: true }
|
|
85733
|
+
);
|
|
85734
|
+
if (restored === null) return BranchMetadataFileManager.loadOnly(branchPath);
|
|
85735
|
+
workerLog(
|
|
85736
|
+
` ${branchDir}: restored its name ${escapeForLog(ref)} from ${escapeForLog(staleName)}`
|
|
85737
|
+
);
|
|
85738
|
+
return restored;
|
|
85739
|
+
} catch (err) {
|
|
85740
|
+
workerLogWarn(
|
|
85741
|
+
` ${branchDir}: could not restore its name ${escapeForLog(ref)}: ${getErrorMessage(err)}`
|
|
85742
|
+
);
|
|
85743
|
+
return metaFile;
|
|
85744
|
+
}
|
|
85745
|
+
}
|
|
85746
|
+
async function holdAndRebaseOneBranch(ctx, branchDir, branchPath, gatewayPolicy) {
|
|
85104
85747
|
let hold;
|
|
85105
85748
|
try {
|
|
85106
85749
|
hold = await holdProvisionedWorkspace(ctx.contentBranchesPath, branchDir);
|
|
@@ -85115,15 +85758,21 @@ async function holdAndRebaseOneBranch(ctx, branchDir, branchPath) {
|
|
|
85115
85758
|
}
|
|
85116
85759
|
if (hold.kind === "not-provisioned") return { kind: "none" };
|
|
85117
85760
|
try {
|
|
85118
|
-
return await rebaseOneBranch(ctx, branchDir, branchPath, hold.isCompromised);
|
|
85761
|
+
return await rebaseOneBranch(ctx, branchDir, branchPath, hold.isCompromised, gatewayPolicy);
|
|
85119
85762
|
} finally {
|
|
85120
85763
|
await releaseProvisionedWorkspace(hold.release, branchDir);
|
|
85121
85764
|
}
|
|
85122
85765
|
}
|
|
85123
|
-
async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCompromised) {
|
|
85766
|
+
async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCompromised, gatewayPolicy) {
|
|
85124
85767
|
let didRebase = false;
|
|
85125
85768
|
try {
|
|
85126
|
-
const metaFile = await
|
|
85769
|
+
const metaFile = await restoreRenamedBranch(
|
|
85770
|
+
ctx,
|
|
85771
|
+
branchDir,
|
|
85772
|
+
branchPath,
|
|
85773
|
+
await BranchMetadataFileManager.loadOnly(branchPath),
|
|
85774
|
+
gatewayPolicy?.namespace
|
|
85775
|
+
);
|
|
85127
85776
|
const branchStatus2 = metaFile?.branch.status;
|
|
85128
85777
|
if (branchStatus2 === "submitted" || branchStatus2 === "approved") {
|
|
85129
85778
|
workerLog(` Skipping ${branchDir} (${branchStatus2})`);
|
|
@@ -85204,7 +85853,8 @@ async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCom
|
|
|
85204
85853
|
branchDir,
|
|
85205
85854
|
branchRef,
|
|
85206
85855
|
headSha: (await branchGit.revparse(["HEAD"])).trim(),
|
|
85207
|
-
marker: metaFile.branch.historyRewrittenFrom
|
|
85856
|
+
marker: metaFile.branch.historyRewrittenFrom,
|
|
85857
|
+
gatewayPolicy
|
|
85208
85858
|
});
|
|
85209
85859
|
}
|
|
85210
85860
|
await fetchFromRemoteGit(branchGit, ctx.remoteGitPath, ctx.baseBranch);
|
|
@@ -85219,7 +85869,11 @@ async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCom
|
|
|
85219
85869
|
if (currentMeta?.branch.rebaseFailure === void 0) {
|
|
85220
85870
|
return { kind: "none" };
|
|
85221
85871
|
}
|
|
85222
|
-
|
|
85872
|
+
const storedName = currentMeta.branch.name;
|
|
85873
|
+
await meta.saveIf(
|
|
85874
|
+
{ branch: { rebaseFailure: void 0 } },
|
|
85875
|
+
(existing) => existing?.branch.name === storedName
|
|
85876
|
+
);
|
|
85223
85877
|
return { kind: "none" };
|
|
85224
85878
|
}
|
|
85225
85879
|
workerLog(`Rebasing ${branchDir} (${behindCount} commits behind)...`);
|
|
@@ -85264,22 +85918,24 @@ async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCom
|
|
|
85264
85918
|
workerLog(
|
|
85265
85919
|
hadConflicts ? ` Rebased ${branchDir} (kept branch version for ${conflictIdsDeduped.length} conflicting file(s))` : ` Rebased ${branchDir} successfully`
|
|
85266
85920
|
);
|
|
85267
|
-
await meta.update(
|
|
85268
|
-
branch
|
|
85269
|
-
|
|
85270
|
-
|
|
85271
|
-
|
|
85272
|
-
|
|
85273
|
-
|
|
85274
|
-
|
|
85275
|
-
|
|
85921
|
+
await meta.update(
|
|
85922
|
+
(existing) => existing !== null && existing.branch.name === metaFile?.branch.name ? {
|
|
85923
|
+
branch: {
|
|
85924
|
+
...recordConflicts(existing.branch.conflictFiles, conflictIdsDeduped),
|
|
85925
|
+
// The cycle completed, so clear any prior failure record regardless
|
|
85926
|
+
// of the conflict outcome.
|
|
85927
|
+
rebaseFailure: void 0
|
|
85928
|
+
}
|
|
85929
|
+
} : null
|
|
85930
|
+
);
|
|
85276
85931
|
didRebase = true;
|
|
85277
85932
|
await carryForwardRewrittenHistory(ctx, {
|
|
85278
85933
|
branchPath,
|
|
85279
85934
|
branchDir,
|
|
85280
85935
|
branchRef,
|
|
85281
85936
|
publishedSha,
|
|
85282
|
-
preRebaseHead
|
|
85937
|
+
preRebaseHead,
|
|
85938
|
+
gatewayPolicy
|
|
85283
85939
|
});
|
|
85284
85940
|
return { kind: "rebased" };
|
|
85285
85941
|
} finally {
|
|
@@ -85311,16 +85967,17 @@ async function rebaseOneBranch(ctx, branchDir, branchPath, isProvisioningLockCom
|
|
|
85311
85967
|
}
|
|
85312
85968
|
|
|
85313
85969
|
// ../canopycms/src/worker/git-sync.ts
|
|
85314
|
-
import
|
|
85315
|
-
import
|
|
85970
|
+
import fs28 from "node:fs/promises";
|
|
85971
|
+
import path30 from "node:path";
|
|
85316
85972
|
|
|
85317
85973
|
// ../canopycms/src/branch-health.ts
|
|
85318
85974
|
var ORPHAN_YOUTH_THRESHOLD_MS = 15 * 6e4;
|
|
85319
85975
|
|
|
85320
85976
|
// ../canopycms/src/branch-provisioning.ts
|
|
85321
85977
|
import { createHash, randomBytes as randomBytes2 } from "node:crypto";
|
|
85322
|
-
import
|
|
85323
|
-
import
|
|
85978
|
+
import fs24 from "node:fs/promises";
|
|
85979
|
+
import path26 from "node:path";
|
|
85980
|
+
init_branch_name();
|
|
85324
85981
|
init_error();
|
|
85325
85982
|
init_logger();
|
|
85326
85983
|
var STAGING_MAX_AGE_MS = 20 * 6e4;
|
|
@@ -85352,7 +86009,7 @@ var DELETING_PREFIX = ".deleting-";
|
|
|
85352
86009
|
var NO_GIT = { hasGitDir: false, configLock: false, hasIndex: false };
|
|
85353
86010
|
async function listDir(dirPath) {
|
|
85354
86011
|
try {
|
|
85355
|
-
return await
|
|
86012
|
+
return await fs24.readdir(dirPath);
|
|
85356
86013
|
} catch (err) {
|
|
85357
86014
|
if (isNodeError(err) && (err.code === "ENOENT" || err.code === "ENOTDIR")) return null;
|
|
85358
86015
|
throw err;
|
|
@@ -85374,19 +86031,19 @@ function gitConfigRemoteUrls(text) {
|
|
|
85374
86031
|
}
|
|
85375
86032
|
function sameRemote(url, expected) {
|
|
85376
86033
|
if (isNetworkRemoteUrl(url) || isNetworkRemoteUrl(expected)) return url === expected;
|
|
85377
|
-
const local = (value) =>
|
|
86034
|
+
const local = (value) => path26.resolve(value.replace(/^file:\/\//i, ""));
|
|
85378
86035
|
return local(url) === local(expected);
|
|
85379
86036
|
}
|
|
85380
86037
|
async function classifyFinalDir(dirPath, expectedRemoteUrl) {
|
|
85381
86038
|
let stat;
|
|
85382
86039
|
try {
|
|
85383
|
-
stat = await
|
|
86040
|
+
stat = await fs24.lstat(dirPath);
|
|
85384
86041
|
} catch (err) {
|
|
85385
86042
|
if (isNotFoundError2(err)) return { kind: "vacant" };
|
|
85386
86043
|
throw err;
|
|
85387
86044
|
}
|
|
85388
86045
|
if (!stat.isDirectory()) return { kind: "residue", signature: NO_GIT };
|
|
85389
|
-
const metaEntries = await listDir(
|
|
86046
|
+
const metaEntries = await listDir(path26.join(dirPath, BRANCH_META_DIR)) ?? [];
|
|
85390
86047
|
if (metaEntries.includes(BRANCH_META_FILE)) {
|
|
85391
86048
|
try {
|
|
85392
86049
|
return await readBranchMetadataFile(dirPath) ? { kind: "live" } : { kind: "protected" };
|
|
@@ -85398,10 +86055,10 @@ async function classifyFinalDir(dirPath, expectedRemoteUrl) {
|
|
|
85398
86055
|
if (metaEntries.some((name2) => name2.startsWith(`${BRANCH_META_FILE}.corrupt-`))) {
|
|
85399
86056
|
return { kind: "protected" };
|
|
85400
86057
|
}
|
|
85401
|
-
const gitPath =
|
|
86058
|
+
const gitPath = path26.join(dirPath, ".git");
|
|
85402
86059
|
let gitStat;
|
|
85403
86060
|
try {
|
|
85404
|
-
gitStat = await
|
|
86061
|
+
gitStat = await fs24.lstat(gitPath);
|
|
85405
86062
|
} catch (err) {
|
|
85406
86063
|
if (isNotFoundError2(err)) return { kind: "residue", signature: NO_GIT };
|
|
85407
86064
|
throw err;
|
|
@@ -85415,7 +86072,7 @@ async function classifyFinalDir(dirPath, expectedRemoteUrl) {
|
|
|
85415
86072
|
};
|
|
85416
86073
|
let config;
|
|
85417
86074
|
try {
|
|
85418
|
-
config = await
|
|
86075
|
+
config = await fs24.readFile(path26.join(gitPath, "config"), "utf8");
|
|
85419
86076
|
} catch {
|
|
85420
86077
|
return { kind: "residue", signature };
|
|
85421
86078
|
}
|
|
@@ -85424,7 +86081,7 @@ async function classifyFinalDir(dirPath, expectedRemoteUrl) {
|
|
|
85424
86081
|
async function quietAgeMs(dirPath, now = Date.now()) {
|
|
85425
86082
|
const mtimes = await Promise.all(
|
|
85426
86083
|
["", ".git", BRANCH_META_DIR].map(
|
|
85427
|
-
(sub) =>
|
|
86084
|
+
(sub) => fs24.lstat(path26.join(dirPath, sub)).then(
|
|
85428
86085
|
(stat) => stat.mtimeMs,
|
|
85429
86086
|
() => 0
|
|
85430
86087
|
)
|
|
@@ -85433,25 +86090,25 @@ async function quietAgeMs(dirPath, now = Date.now()) {
|
|
|
85433
86090
|
return now - Math.max(...mtimes);
|
|
85434
86091
|
}
|
|
85435
86092
|
async function quarantineResidueAt(baseRoot, dirName, options) {
|
|
85436
|
-
const finalPath =
|
|
86093
|
+
const finalPath = path26.join(baseRoot, dirName);
|
|
85437
86094
|
let inode;
|
|
85438
86095
|
try {
|
|
85439
|
-
inode = (await
|
|
86096
|
+
inode = (await fs24.lstat(finalPath)).ino;
|
|
85440
86097
|
} catch (err) {
|
|
85441
86098
|
if (isNotFoundError2(err)) return { kind: "vacant" };
|
|
85442
86099
|
throw err;
|
|
85443
86100
|
}
|
|
85444
86101
|
const candidateName = stampedName(REPAIR_PREFIX, dirName, /* @__PURE__ */ new Date());
|
|
85445
|
-
const candidate =
|
|
86102
|
+
const candidate = path26.join(baseRoot, candidateName);
|
|
85446
86103
|
try {
|
|
85447
|
-
await
|
|
86104
|
+
await fs24.rename(finalPath, candidate);
|
|
85448
86105
|
} catch (err) {
|
|
85449
86106
|
if (isNotFoundError2(err)) return { kind: "vacant" };
|
|
85450
86107
|
throw err;
|
|
85451
86108
|
}
|
|
85452
86109
|
const moveBack = async (why) => {
|
|
85453
86110
|
try {
|
|
85454
|
-
await
|
|
86111
|
+
await fs24.rename(candidate, finalPath);
|
|
85455
86112
|
} catch (err) {
|
|
85456
86113
|
canopyLogError(
|
|
85457
86114
|
`[canopy] Could not move '${dirName}' back from ${candidateName} after ${why}: ${getErrorMessage(err)}. The worker's sweep restores or trashes it.`
|
|
@@ -85466,7 +86123,7 @@ async function quarantineResidueAt(baseRoot, dirName, options) {
|
|
|
85466
86123
|
);
|
|
85467
86124
|
if (reason === void 0 && state3.kind === "residue") {
|
|
85468
86125
|
const trashName = stampedName(TRASH_PREFIX, dirName, /* @__PURE__ */ new Date());
|
|
85469
|
-
await
|
|
86126
|
+
await fs24.rename(candidate, path26.join(baseRoot, trashName));
|
|
85470
86127
|
const { hasGitDir, configLock, hasIndex } = state3.signature;
|
|
85471
86128
|
canopyLogWarn(
|
|
85472
86129
|
`[canopy] Quarantined unfinished branch directory '${dirName}' as ${trashName} (git=${hasGitDir} config.lock=${configLock} index=${hasIndex} quiet=${Math.round(quiet / 1e3)}s)`
|
|
@@ -85478,7 +86135,7 @@ async function quarantineResidueAt(baseRoot, dirName, options) {
|
|
|
85478
86135
|
}
|
|
85479
86136
|
async function judgeQuarantineCandidate(candidate, inode, options) {
|
|
85480
86137
|
const state3 = await classifyFinalDir(candidate, options.expectedRemoteUrl);
|
|
85481
|
-
const moved = await
|
|
86138
|
+
const moved = await fs24.lstat(candidate).catch(() => null);
|
|
85482
86139
|
const quiet = await quietAgeMs(candidate, options.now);
|
|
85483
86140
|
let reason;
|
|
85484
86141
|
if (!moved || moved.ino !== inode) reason = "replaced";
|
|
@@ -85495,7 +86152,7 @@ async function sweepByAge(root5, rules, now) {
|
|
|
85495
86152
|
const stamp = rule ? parseDirStamp(name2) : null;
|
|
85496
86153
|
if (!rule || !stamp || now - stamp.getTime() < rule.maxAgeMs) continue;
|
|
85497
86154
|
try {
|
|
85498
|
-
await
|
|
86155
|
+
await fs24.rm(path26.join(root5, name2), {
|
|
85499
86156
|
recursive: true,
|
|
85500
86157
|
force: true,
|
|
85501
86158
|
maxRetries: 3,
|
|
@@ -85509,7 +86166,7 @@ async function sweepByAge(root5, rules, now) {
|
|
|
85509
86166
|
return actions;
|
|
85510
86167
|
}
|
|
85511
86168
|
async function recoverRepairDir(baseRoot, name2) {
|
|
85512
|
-
const repairPath =
|
|
86169
|
+
const repairPath = path26.join(baseRoot, name2);
|
|
85513
86170
|
const meta = await readBranchMetadataFile(repairPath).catch(() => null);
|
|
85514
86171
|
const dirName = meta ? sanitizeBranchName(meta.branch.name) : void 0;
|
|
85515
86172
|
if (dirName && name2.startsWith(`${REPAIR_PREFIX}${shortDirName(dirName)}-`)) {
|
|
@@ -85523,9 +86180,9 @@ async function recoverRepairDir(baseRoot, name2) {
|
|
|
85523
86180
|
throw err;
|
|
85524
86181
|
}
|
|
85525
86182
|
try {
|
|
85526
|
-
const finalPath =
|
|
85527
|
-
if (await
|
|
85528
|
-
await
|
|
86183
|
+
const finalPath = path26.join(baseRoot, dirName);
|
|
86184
|
+
if (await fs24.lstat(finalPath).catch(() => null) === null) {
|
|
86185
|
+
await fs24.rename(repairPath, finalPath);
|
|
85529
86186
|
return { name: name2, action: "restored", detail: dirName };
|
|
85530
86187
|
}
|
|
85531
86188
|
} finally {
|
|
@@ -85534,7 +86191,7 @@ async function recoverRepairDir(baseRoot, name2) {
|
|
|
85534
86191
|
}
|
|
85535
86192
|
}
|
|
85536
86193
|
const trashName = `${TRASH_PREFIX}${name2.slice(REPAIR_PREFIX.length)}`;
|
|
85537
|
-
await
|
|
86194
|
+
await fs24.rename(repairPath, path26.join(baseRoot, trashName));
|
|
85538
86195
|
return { name: name2, action: "trashed", detail: trashName };
|
|
85539
86196
|
}
|
|
85540
86197
|
async function sweepProvisioningLeftovers(baseRoot, workspaceRoot, now = Date.now()) {
|
|
@@ -85569,6 +86226,7 @@ async function sweepProvisioningLeftovers(baseRoot, workspaceRoot, now = Date.no
|
|
|
85569
86226
|
}
|
|
85570
86227
|
|
|
85571
86228
|
// ../canopycms/src/worker/git-sync.ts
|
|
86229
|
+
init_branch_name();
|
|
85572
86230
|
init_error();
|
|
85573
86231
|
init_worker_status();
|
|
85574
86232
|
|
|
@@ -85584,12 +86242,12 @@ async function maintainRemoteGit(gitDir) {
|
|
|
85584
86242
|
}
|
|
85585
86243
|
|
|
85586
86244
|
// ../canopycms/src/worker/sparse-cone.ts
|
|
85587
|
-
import
|
|
85588
|
-
import
|
|
86245
|
+
import fs26 from "node:fs/promises";
|
|
86246
|
+
import path28 from "node:path";
|
|
85589
86247
|
|
|
85590
86248
|
// ../canopycms/src/branch-sparse.ts
|
|
85591
|
-
import
|
|
85592
|
-
import
|
|
86249
|
+
import fs25 from "node:fs/promises";
|
|
86250
|
+
import path27 from "node:path";
|
|
85593
86251
|
init_error();
|
|
85594
86252
|
function sameCone(a9, b10) {
|
|
85595
86253
|
if (a9 === null || b10 === null) return a9 === b10;
|
|
@@ -85598,12 +86256,12 @@ function sameCone(a9, b10) {
|
|
|
85598
86256
|
}
|
|
85599
86257
|
var SPARSE_CONE_RECORD = ".sparse-cone.json";
|
|
85600
86258
|
function isConeDir(dir) {
|
|
85601
|
-
return typeof dir === "string" && dir.length > 0 && !
|
|
86259
|
+
return typeof dir === "string" && dir.length > 0 && !path27.isAbsolute(dir) && !dir.split("/").some((segment) => segment === "" || segment === "." || segment === "..");
|
|
85602
86260
|
}
|
|
85603
86261
|
async function readRecordedSparseCone(contentBranchesRoot) {
|
|
85604
86262
|
let raw;
|
|
85605
86263
|
try {
|
|
85606
|
-
raw = await
|
|
86264
|
+
raw = await fs25.readFile(path27.join(contentBranchesRoot, SPARSE_CONE_RECORD), "utf8");
|
|
85607
86265
|
} catch (err) {
|
|
85608
86266
|
if (isNodeError(err) && err.code === "ENOENT") return void 0;
|
|
85609
86267
|
throw err;
|
|
@@ -85636,15 +86294,15 @@ async function reapplySparseCones(ctx) {
|
|
|
85636
86294
|
if (!recorded) return report;
|
|
85637
86295
|
let entries;
|
|
85638
86296
|
try {
|
|
85639
|
-
entries = await
|
|
86297
|
+
entries = await fs26.readdir(ctx.contentBranchesPath, { withFileTypes: true });
|
|
85640
86298
|
} catch (err) {
|
|
85641
86299
|
if (isNodeError(err) && err.code === "ENOENT") return report;
|
|
85642
86300
|
throw err;
|
|
85643
86301
|
}
|
|
85644
86302
|
const dirNames = entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).sort();
|
|
85645
86303
|
for (const dirName of dirNames) {
|
|
85646
|
-
const branchPath =
|
|
85647
|
-
const isClone = await
|
|
86304
|
+
const branchPath = path28.join(ctx.contentBranchesPath, dirName);
|
|
86305
|
+
const isClone = await fs26.stat(path28.join(branchPath, ".git")).then(
|
|
85648
86306
|
(stat) => stat.isDirectory(),
|
|
85649
86307
|
() => false
|
|
85650
86308
|
);
|
|
@@ -85676,7 +86334,7 @@ async function reapplySparseCones(ctx) {
|
|
|
85676
86334
|
return report;
|
|
85677
86335
|
}
|
|
85678
86336
|
async function reapplyOne(contentBranchesPath, dirName, git, target) {
|
|
85679
|
-
const branchPath =
|
|
86337
|
+
const branchPath = path28.join(contentBranchesPath, dirName);
|
|
85680
86338
|
const hold = await holdProvisionedWorkspace(contentBranchesPath, dirName);
|
|
85681
86339
|
if (hold.kind !== "held") return "skipped";
|
|
85682
86340
|
try {
|
|
@@ -85715,11 +86373,12 @@ async function reapplyOne(contentBranchesPath, dirName, git, target) {
|
|
|
85715
86373
|
}
|
|
85716
86374
|
|
|
85717
86375
|
// ../canopycms/src/worker/stale-mirror.ts
|
|
85718
|
-
|
|
85719
|
-
import
|
|
86376
|
+
init_branch_name();
|
|
86377
|
+
import fs27 from "node:fs/promises";
|
|
86378
|
+
import path29 from "node:path";
|
|
85720
86379
|
init_error();
|
|
85721
86380
|
async function readEditorWork(ctx) {
|
|
85722
|
-
const workspaces = new Set(await
|
|
86381
|
+
const workspaces = new Set(await fs27.readdir(ctx.contentBranchesPath).catch(() => []));
|
|
85723
86382
|
const queuedPushes = /* @__PURE__ */ new Set();
|
|
85724
86383
|
for (const status of ["pending", "processing"]) {
|
|
85725
86384
|
for (const task of await listTasks(ctx.taskDir, status, Number.POSITIVE_INFINITY)) {
|
|
@@ -85754,7 +86413,7 @@ async function settleStaleMirror(ctx, git, head, ownSettingsBranch, editorWork,
|
|
|
85754
86413
|
throw err;
|
|
85755
86414
|
}
|
|
85756
86415
|
try {
|
|
85757
|
-
if ((await
|
|
86416
|
+
if ((await fs27.readdir(ctx.contentBranchesPath)).includes(dirName)) {
|
|
85758
86417
|
return { kind: "kept", state: "workspace" };
|
|
85759
86418
|
}
|
|
85760
86419
|
const ref = `refs/heads/${name2}`;
|
|
@@ -85764,7 +86423,7 @@ async function settleStaleMirror(ctx, git, head, ownSettingsBranch, editorWork,
|
|
|
85764
86423
|
);
|
|
85765
86424
|
} catch (err) {
|
|
85766
86425
|
const message2 = getErrorMessage(err);
|
|
85767
|
-
if (lockHeld(message2) ===
|
|
86426
|
+
if (lockHeld(message2) === path29.join(ctx.remoteGitPath, "packed-refs.lock")) {
|
|
85768
86427
|
return { kind: "packed-refs-locked" };
|
|
85769
86428
|
}
|
|
85770
86429
|
if (/cannot lock ref|Unable to create '[^']*\.lock': File exists/.test(message2)) {
|
|
@@ -85779,7 +86438,7 @@ async function settleStaleMirror(ctx, git, head, ownSettingsBranch, editorWork,
|
|
|
85779
86438
|
}
|
|
85780
86439
|
function lockHeld(message2) {
|
|
85781
86440
|
const match2 = /Unable to create '([^']*)': File exists/.exec(message2);
|
|
85782
|
-
return match2 ?
|
|
86441
|
+
return match2 ? path29.normalize(match2[1]) : null;
|
|
85783
86442
|
}
|
|
85784
86443
|
async function sharesHistory(git, head, baseTip) {
|
|
85785
86444
|
try {
|
|
@@ -85991,7 +86650,7 @@ async function reconcileTrackedBranches(ctx, git, githubTips) {
|
|
|
85991
86650
|
else if (outcome.error !== void 0) uncheckedOrphans.push({ name: name2, error: outcome.error });
|
|
85992
86651
|
}
|
|
85993
86652
|
}
|
|
85994
|
-
|
|
86653
|
+
warnOnce2(ctx.warnedDivergences(), [
|
|
85995
86654
|
...diverged.map(divergedWarning),
|
|
85996
86655
|
...uncheckedOrphans.map(({ name: name2, error: error3 }) => ({
|
|
85997
86656
|
// ':' cannot appear in a ref name, so this key never collides with a branch's.
|
|
@@ -86048,12 +86707,12 @@ function divergedWarning({ name: name2, local, github, state: state3, error: err
|
|
|
86048
86707
|
line: ` Tracked-branch reconcile: ${escapeForLog(name2)} diverged from GitHub and was left untouched, because ${EDITOR_STATE_WORDS[state3]}${error3 === void 0 ? "" : ` (${escapeForLog(error3)})`} (here ${local}, GitHub ${github}). Publishing it fails until the two are reconciled; System health lists it.`
|
|
86049
86708
|
};
|
|
86050
86709
|
}
|
|
86051
|
-
function
|
|
86710
|
+
function warnOnce2(warned3, lines) {
|
|
86052
86711
|
const current = new Set(lines.map((entry) => entry.key));
|
|
86053
|
-
for (const key of
|
|
86712
|
+
for (const key of warned3.keys()) if (!current.has(key)) warned3.delete(key);
|
|
86054
86713
|
for (const { key, said, line } of lines) {
|
|
86055
|
-
if (
|
|
86056
|
-
|
|
86714
|
+
if (warned3.get(key) === said) continue;
|
|
86715
|
+
warned3.set(key, said);
|
|
86057
86716
|
workerLogWarn(line);
|
|
86058
86717
|
}
|
|
86059
86718
|
}
|
|
@@ -86105,9 +86764,39 @@ async function syncGit(ctx) {
|
|
|
86105
86764
|
if (stoppedForDrain(ctx, "the base-branch refresh")) return;
|
|
86106
86765
|
const baseRefresh = await refreshBaseBranchWorkspace(ctx);
|
|
86107
86766
|
if (stoppedForDrain(ctx, "the rebase cycle")) return;
|
|
86108
|
-
|
|
86767
|
+
let health;
|
|
86768
|
+
try {
|
|
86769
|
+
health = await ctx.github().health(ctx.shutdownSignal());
|
|
86770
|
+
} catch (err) {
|
|
86771
|
+
workerLogWarn(`Could not read the GitHub gateway's branch policy: ${getErrorMessage(err)}`);
|
|
86772
|
+
}
|
|
86773
|
+
const branchPolicy = health && health.branchPolicy.namespace !== "" ? health.branchPolicy : void 0;
|
|
86774
|
+
if (branchPolicy) {
|
|
86775
|
+
const report2 = ctx.ensureStatusReport();
|
|
86776
|
+
report2.gatewayBranchNamespace = branchPolicy.namespace;
|
|
86777
|
+
report2.gatewayProtectedBranches = branchPolicy.configured.filter((n7) => !n7.includes("*"));
|
|
86778
|
+
await writeWorkerStatus(ctx.taskDir, report2).catch(
|
|
86779
|
+
(writeErr) => workerLogError("Failed to write worker status:", getErrorMessage(writeErr))
|
|
86780
|
+
);
|
|
86781
|
+
}
|
|
86782
|
+
const rebaseSummary = await runRebaseCycle(ctx, branchPolicy);
|
|
86109
86783
|
if (stoppedForDrain(ctx, "the cleanup sweeps")) return;
|
|
86110
86784
|
await cleanupOldTasks(ctx.taskDir, void 0, ctx.log);
|
|
86785
|
+
if (health && branchPolicy) {
|
|
86786
|
+
const report2 = ctx.ensureStatusReport();
|
|
86787
|
+
if (health.fatalError === null) {
|
|
86788
|
+
try {
|
|
86789
|
+
const unpublishable = await findUnpublishableBranches(ctx, branchPolicy);
|
|
86790
|
+
if (unpublishable.count > 0) {
|
|
86791
|
+
report2.unpublishableBranches = { ...unpublishable, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
86792
|
+
} else delete report2.unpublishableBranches;
|
|
86793
|
+
} catch (err) {
|
|
86794
|
+
workerLogWarn(
|
|
86795
|
+
`Could not list the branches the gateway will not publish: ${getErrorMessage(err)}`
|
|
86796
|
+
);
|
|
86797
|
+
}
|
|
86798
|
+
}
|
|
86799
|
+
}
|
|
86111
86800
|
const trashRemoved = await cleanupTrashedBranchDirs(ctx);
|
|
86112
86801
|
if (trashRemoved > 0) {
|
|
86113
86802
|
workerLog(`Removed ${trashRemoved} expired trashed branch dir(s)`);
|
|
@@ -86130,6 +86819,7 @@ async function syncGit(ctx) {
|
|
|
86130
86819
|
await writeWorkerStatus(ctx.taskDir, report).catch(
|
|
86131
86820
|
(writeErr) => workerLogError("Failed to write worker status:", getErrorMessage(writeErr))
|
|
86132
86821
|
);
|
|
86822
|
+
workerLog("Git sync complete");
|
|
86133
86823
|
} catch (err) {
|
|
86134
86824
|
const report = ctx.ensureStatusReport();
|
|
86135
86825
|
report.lastGitSyncError = {
|
|
@@ -86151,7 +86841,7 @@ var reportedForeignDirs = /* @__PURE__ */ new Set();
|
|
|
86151
86841
|
async function repairBranchDirResidue(ctx, now = Date.now()) {
|
|
86152
86842
|
let entries;
|
|
86153
86843
|
try {
|
|
86154
|
-
entries = await
|
|
86844
|
+
entries = await fs28.readdir(ctx.contentBranchesPath, { withFileTypes: true });
|
|
86155
86845
|
} catch (err) {
|
|
86156
86846
|
if (isNodeError(err) && err.code === "ENOENT") return;
|
|
86157
86847
|
throw err;
|
|
@@ -86166,7 +86856,7 @@ async function repairBranchDirResidue(ctx, now = Date.now()) {
|
|
|
86166
86856
|
}
|
|
86167
86857
|
const leftovers = await sweepProvisioningLeftovers(
|
|
86168
86858
|
ctx.contentBranchesPath,
|
|
86169
|
-
|
|
86859
|
+
path30.dirname(ctx.contentBranchesPath),
|
|
86170
86860
|
now
|
|
86171
86861
|
);
|
|
86172
86862
|
for (const { name: name2, action, detail } of leftovers) {
|
|
@@ -86177,8 +86867,8 @@ async function repairBranchDirResidue(ctx, now = Date.now()) {
|
|
|
86177
86867
|
}
|
|
86178
86868
|
}
|
|
86179
86869
|
async function repairOneBranchDir(ctx, dirName, now) {
|
|
86180
|
-
const dirPath =
|
|
86181
|
-
const hasMeta = await
|
|
86870
|
+
const dirPath = path30.join(ctx.contentBranchesPath, dirName);
|
|
86871
|
+
const hasMeta = await fs28.access(path30.join(dirPath, BRANCH_META_DIR, BRANCH_META_FILE)).then(
|
|
86182
86872
|
() => true,
|
|
86183
86873
|
() => false
|
|
86184
86874
|
);
|
|
@@ -86214,7 +86904,7 @@ async function repairOneBranchDir(ctx, dirName, now) {
|
|
|
86214
86904
|
async function cleanupTrashedBranchDirs(ctx) {
|
|
86215
86905
|
let entries;
|
|
86216
86906
|
try {
|
|
86217
|
-
entries = await
|
|
86907
|
+
entries = await fs28.readdir(ctx.contentBranchesPath);
|
|
86218
86908
|
} catch (err) {
|
|
86219
86909
|
if (isNodeError(err) && err.code === "ENOENT") return 0;
|
|
86220
86910
|
throw err;
|
|
@@ -86234,7 +86924,7 @@ async function cleanupTrashedBranchDirs(ctx) {
|
|
|
86234
86924
|
}
|
|
86235
86925
|
if (now - stampDate.getTime() < TRASH_RETENTION_MS) continue;
|
|
86236
86926
|
try {
|
|
86237
|
-
await
|
|
86927
|
+
await fs28.rm(path30.join(ctx.contentBranchesPath, name2), {
|
|
86238
86928
|
recursive: true,
|
|
86239
86929
|
force: true,
|
|
86240
86930
|
maxRetries: 3,
|
|
@@ -86252,7 +86942,7 @@ async function cleanupTrashedBranchDirs(ctx) {
|
|
|
86252
86942
|
}
|
|
86253
86943
|
var warnedTrackedCanopyState = /* @__PURE__ */ new Set();
|
|
86254
86944
|
async function refreshBaseBranchWorkspace(ctx) {
|
|
86255
|
-
const basePath37 =
|
|
86945
|
+
const basePath37 = path30.join(ctx.contentBranchesPath, ctx.sanitizedBaseBranch);
|
|
86256
86946
|
let trackedCanopyMeta;
|
|
86257
86947
|
let releaseProvisioning;
|
|
86258
86948
|
let releaseContentLock;
|
|
@@ -86410,10 +87100,10 @@ async function refreshBaseBranchWorkspace(ctx) {
|
|
|
86410
87100
|
// ../canopycms/src/worker/github-gateway-http.ts
|
|
86411
87101
|
init_error();
|
|
86412
87102
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
86413
|
-
import
|
|
87103
|
+
import fs29 from "node:fs/promises";
|
|
86414
87104
|
import http from "node:http";
|
|
86415
87105
|
import net from "node:net";
|
|
86416
|
-
import
|
|
87106
|
+
import path31 from "node:path";
|
|
86417
87107
|
import { PassThrough } from "node:stream";
|
|
86418
87108
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
86419
87109
|
var MAX_POLL_WAIT_MS = 25e3;
|
|
@@ -86436,11 +87126,11 @@ async function serveGitHubGateway(gateway, listen, options = {}) {
|
|
|
86436
87126
|
if ("fd" in listen) {
|
|
86437
87127
|
await listenOn(server, { fd: listen.fd });
|
|
86438
87128
|
} else {
|
|
86439
|
-
await assertPrivateDirectory(
|
|
87129
|
+
await assertPrivateDirectory(path31.dirname(listen.path));
|
|
86440
87130
|
await removeStaleSocket(listen.path);
|
|
86441
87131
|
await listenOn(server, { path: listen.path });
|
|
86442
87132
|
try {
|
|
86443
|
-
await
|
|
87133
|
+
await fs29.chmod(listen.path, 384);
|
|
86444
87134
|
} catch (err) {
|
|
86445
87135
|
await closeServer(server, handler);
|
|
86446
87136
|
throw err;
|
|
@@ -86481,7 +87171,7 @@ function listenOn(server, options) {
|
|
|
86481
87171
|
});
|
|
86482
87172
|
}
|
|
86483
87173
|
async function assertPrivateDirectory(dir) {
|
|
86484
|
-
const stat = await
|
|
87174
|
+
const stat = await fs29.lstat(dir);
|
|
86485
87175
|
const uid = process.getuid?.();
|
|
86486
87176
|
if (!stat.isDirectory() || uid !== void 0 && (stat.uid !== uid || (stat.mode & 63) !== 0)) {
|
|
86487
87177
|
throw new Error(
|
|
@@ -86492,7 +87182,7 @@ async function assertPrivateDirectory(dir) {
|
|
|
86492
87182
|
async function removeStaleSocket(socketPath) {
|
|
86493
87183
|
let stat;
|
|
86494
87184
|
try {
|
|
86495
|
-
stat = await
|
|
87185
|
+
stat = await fs29.lstat(socketPath);
|
|
86496
87186
|
} catch (err) {
|
|
86497
87187
|
if (isNodeError(err) && err.code === "ENOENT") return;
|
|
86498
87188
|
throw err;
|
|
@@ -86508,7 +87198,7 @@ async function removeStaleSocket(socketPath) {
|
|
|
86508
87198
|
`Refusing to serve the GitHub gateway at ${socketPath}: a gateway already serves there`
|
|
86509
87199
|
);
|
|
86510
87200
|
}
|
|
86511
|
-
await
|
|
87201
|
+
await fs29.unlink(socketPath);
|
|
86512
87202
|
}
|
|
86513
87203
|
function isServed(socketPath) {
|
|
86514
87204
|
return new Promise((resolve) => {
|
|
@@ -86572,7 +87262,7 @@ var GatewayRequestHandler = class {
|
|
|
86572
87262
|
number,
|
|
86573
87263
|
signal
|
|
86574
87264
|
);
|
|
86575
|
-
return { merged, merged_at, state: state3, node_id, body
|
|
87265
|
+
return { merged, merged_at, state: state3, node_id, body };
|
|
86576
87266
|
},
|
|
86577
87267
|
createOrUpdatePullRequest: async (input, signal) => {
|
|
86578
87268
|
const { number, url, created } = await gateway.createOrUpdatePullRequest(input, signal);
|
|
@@ -87237,11 +87927,14 @@ async function readAnswer(res, schema, signal) {
|
|
|
87237
87927
|
return value.data;
|
|
87238
87928
|
}
|
|
87239
87929
|
|
|
87930
|
+
// ../canopycms/src/worker/cms-worker.ts
|
|
87931
|
+
init_branch_namespace();
|
|
87932
|
+
|
|
87240
87933
|
// ../canopycms/src/worker/self-checks.ts
|
|
87241
87934
|
init_error();
|
|
87242
|
-
import
|
|
87935
|
+
import fs30 from "node:fs/promises";
|
|
87243
87936
|
import net2 from "node:net";
|
|
87244
|
-
import
|
|
87937
|
+
import path32 from "node:path";
|
|
87245
87938
|
var IMDS_HOST = "169.254.169.254";
|
|
87246
87939
|
var IMDS_CONNECT_TIMEOUT_MS = 1e3;
|
|
87247
87940
|
var NO_ROUTE_CODES = /* @__PURE__ */ new Set(["ENETUNREACH", "EAFNOSUPPORT"]);
|
|
@@ -87296,10 +87989,10 @@ async function imdsUnreachable(environment = {}) {
|
|
|
87296
87989
|
};
|
|
87297
87990
|
}
|
|
87298
87991
|
async function onlyLoopback(environment = {}) {
|
|
87299
|
-
const file =
|
|
87992
|
+
const file = path32.join(rootOf(environment), "proc", "self", "net", "dev");
|
|
87300
87993
|
let text;
|
|
87301
87994
|
try {
|
|
87302
|
-
text = await
|
|
87995
|
+
text = await fs30.readFile(file, "utf8");
|
|
87303
87996
|
} catch (err) {
|
|
87304
87997
|
return {
|
|
87305
87998
|
check: "network-namespace",
|
|
@@ -87316,21 +88009,21 @@ async function onlyLoopback(environment = {}) {
|
|
|
87316
88009
|
};
|
|
87317
88010
|
}
|
|
87318
88011
|
async function procShowsOnlyOwnProcesses(environment = {}) {
|
|
87319
|
-
const proc =
|
|
88012
|
+
const proc = path32.join(rootOf(environment), "proc");
|
|
87320
88013
|
const uid = environment.uid ?? process.getuid?.();
|
|
87321
88014
|
if (uid === void 0) {
|
|
87322
88015
|
return { check: "proc", ok: false, detail: "this platform has no process uid to compare" };
|
|
87323
88016
|
}
|
|
87324
88017
|
let entries;
|
|
87325
88018
|
try {
|
|
87326
|
-
entries = await
|
|
88019
|
+
entries = await fs30.readdir(proc);
|
|
87327
88020
|
} catch (err) {
|
|
87328
88021
|
return { check: "proc", ok: false, detail: `cannot list ${proc}: ${getErrorMessage(err)}` };
|
|
87329
88022
|
}
|
|
87330
88023
|
const others = [];
|
|
87331
88024
|
for (const entry of entries.filter((name2) => /^\d+$/.test(name2))) {
|
|
87332
88025
|
try {
|
|
87333
|
-
const stat = await
|
|
88026
|
+
const stat = await fs30.stat(path32.join(proc, entry));
|
|
87334
88027
|
if (stat.uid !== uid) others.push(`${entry} (uid ${stat.uid})`);
|
|
87335
88028
|
} catch (err) {
|
|
87336
88029
|
if (!(isNodeError(err) && err.code === "ENOENT")) {
|
|
@@ -87346,9 +88039,9 @@ async function procShowsOnlyOwnProcesses(environment = {}) {
|
|
|
87346
88039
|
};
|
|
87347
88040
|
}
|
|
87348
88041
|
async function homeIsEmpty(environment = {}) {
|
|
87349
|
-
const home =
|
|
88042
|
+
const home = path32.join(rootOf(environment), "home");
|
|
87350
88043
|
try {
|
|
87351
|
-
const entries = await
|
|
88044
|
+
const entries = await fs30.readdir(home);
|
|
87352
88045
|
return {
|
|
87353
88046
|
check: "home",
|
|
87354
88047
|
ok: entries.length === 0,
|
|
@@ -87371,9 +88064,9 @@ function noSecretsInEnv(environment = {}) {
|
|
|
87371
88064
|
};
|
|
87372
88065
|
}
|
|
87373
88066
|
async function efsUnreadable(environment = {}) {
|
|
87374
|
-
const efs =
|
|
88067
|
+
const efs = path32.join(rootOf(environment), "mnt", "efs");
|
|
87375
88068
|
try {
|
|
87376
|
-
await
|
|
88069
|
+
await fs30.readdir(efs);
|
|
87377
88070
|
} catch (err) {
|
|
87378
88071
|
const code = isNodeError(err) ? err.code : void 0;
|
|
87379
88072
|
const denied = code === "EACCES" || code === "EPERM";
|
|
@@ -87390,9 +88083,9 @@ async function efsUnreadable(environment = {}) {
|
|
|
87390
88083
|
};
|
|
87391
88084
|
}
|
|
87392
88085
|
async function corePatternNotPiped(environment = {}) {
|
|
87393
|
-
const file =
|
|
88086
|
+
const file = path32.join(rootOf(environment), "proc", "sys", "kernel", "core_pattern");
|
|
87394
88087
|
try {
|
|
87395
|
-
const pattern = (await
|
|
88088
|
+
const pattern = (await fs30.readFile(file, "utf8")).trim();
|
|
87396
88089
|
const ok = !pattern.startsWith("|");
|
|
87397
88090
|
return {
|
|
87398
88091
|
check: "core-pattern",
|
|
@@ -87408,10 +88101,10 @@ async function corePatternNotPiped(environment = {}) {
|
|
|
87408
88101
|
}
|
|
87409
88102
|
}
|
|
87410
88103
|
async function coreLimitZero(environment = {}) {
|
|
87411
|
-
const file =
|
|
88104
|
+
const file = path32.join(rootOf(environment), "proc", "self", "limits");
|
|
87412
88105
|
let text;
|
|
87413
88106
|
try {
|
|
87414
|
-
text = await
|
|
88107
|
+
text = await fs30.readFile(file, "utf8");
|
|
87415
88108
|
} catch (err) {
|
|
87416
88109
|
return {
|
|
87417
88110
|
check: "core-limit",
|
|
@@ -87433,11 +88126,11 @@ async function socketAccessIsOthers(environment = {}) {
|
|
|
87433
88126
|
const uid = environment.uid ?? process.getuid?.();
|
|
87434
88127
|
if (uid === void 0) return fail("this platform has no process uid to compare");
|
|
87435
88128
|
const fd = environment.listenFd ?? 3;
|
|
87436
|
-
const proc =
|
|
88129
|
+
const proc = path32.join(rootOf(environment), "proc", "self");
|
|
87437
88130
|
let socketPath;
|
|
87438
88131
|
try {
|
|
87439
|
-
const inode = (await
|
|
87440
|
-
const table = await
|
|
88132
|
+
const inode = (await fs30.stat(path32.join(proc, "fd", String(fd)))).ino;
|
|
88133
|
+
const table = await fs30.readFile(path32.join(proc, "net", "unix"), "utf8");
|
|
87441
88134
|
for (const line of table.split("\n").slice(1)) {
|
|
87442
88135
|
const fields = line.trim().split(/\s+/);
|
|
87443
88136
|
if (fields[6] === String(inode) && fields.length > 7) socketPath = fields.slice(7).join(" ");
|
|
@@ -87445,12 +88138,12 @@ async function socketAccessIsOthers(environment = {}) {
|
|
|
87445
88138
|
} catch (err) {
|
|
87446
88139
|
return fail(`cannot find the socket on descriptor ${fd}: ${getErrorMessage(err)}`);
|
|
87447
88140
|
}
|
|
87448
|
-
if (socketPath === void 0 || !
|
|
88141
|
+
if (socketPath === void 0 || !path32.isAbsolute(socketPath)) {
|
|
87449
88142
|
return fail(`the socket on descriptor ${fd} is not bound to a path`);
|
|
87450
88143
|
}
|
|
87451
88144
|
let node;
|
|
87452
88145
|
try {
|
|
87453
|
-
node = await
|
|
88146
|
+
node = await fs30.lstat(socketPath);
|
|
87454
88147
|
} catch (err) {
|
|
87455
88148
|
return fail(`cannot read ${socketPath}: ${getErrorMessage(err)}`);
|
|
87456
88149
|
}
|
|
@@ -87497,8 +88190,8 @@ function tcpConnect(host, port, timeoutMs) {
|
|
|
87497
88190
|
|
|
87498
88191
|
// ../canopycms/src/worker/cms-worker.ts
|
|
87499
88192
|
function defaultStateDirectory(workspacePath) {
|
|
87500
|
-
const key = createHash2("sha256").update(
|
|
87501
|
-
return
|
|
88193
|
+
const key = createHash2("sha256").update(path33.resolve(workspacePath)).digest("hex").slice(0, 16);
|
|
88194
|
+
return path33.join(os.tmpdir(), `canopycms-worker-${key}`);
|
|
87502
88195
|
}
|
|
87503
88196
|
var MAX_REFS_LISTED = 20;
|
|
87504
88197
|
var RemoteGitKeptError = class extends Error {
|
|
@@ -87523,6 +88216,9 @@ async function listRemoteGitRefs(gitDir) {
|
|
|
87523
88216
|
function sameRefs(a9, b10) {
|
|
87524
88217
|
return a9.size === b10.size && [...a9].every(([ref, id]) => b10.get(ref) === id);
|
|
87525
88218
|
}
|
|
88219
|
+
function resolveWorkerSettingsBranch(config) {
|
|
88220
|
+
return config.settingsBranch ?? `${RESERVED_SETTINGS_BRANCH_PREFIX}${resolveDeploymentName({ deploymentName: config.deploymentName }, "prod")}`;
|
|
88221
|
+
}
|
|
87526
88222
|
var DEFAULT_TASK_TIMEOUT = 6e4;
|
|
87527
88223
|
var DEFAULT_MAX_RETRIES2 = 3;
|
|
87528
88224
|
var DEFAULT_LOCK_STALE_MS = 6e4;
|
|
@@ -87546,7 +88242,7 @@ function lockWorkerTaskDir(taskDir, lockStaleMs, options) {
|
|
|
87546
88242
|
const waitMs = options.waitMs ?? 0;
|
|
87547
88243
|
const intervalMs = Math.max(250, Math.min(5e3, Math.floor(lockStaleMs / 4)));
|
|
87548
88244
|
return import_proper_lockfile3.default.lock(taskDir, {
|
|
87549
|
-
lockfilePath:
|
|
88245
|
+
lockfilePath: path33.join(taskDir, ".worker-lock"),
|
|
87550
88246
|
stale: lockStaleMs,
|
|
87551
88247
|
onCompromised: options.onCompromised,
|
|
87552
88248
|
...waitMs > 0 ? {
|
|
@@ -87562,22 +88258,25 @@ function lockWorkerTaskDir(taskDir, lockStaleMs, options) {
|
|
|
87562
88258
|
async function readCarriedFields(taskDir) {
|
|
87563
88259
|
const { lastFatalError, lastShutdown } = await readCarriedOverStatus(taskDir);
|
|
87564
88260
|
const baseHold = await readCarriedBaseHold(taskDir);
|
|
88261
|
+
const unpublishableBranches = await readCarriedUnpublishableBranches(taskDir);
|
|
87565
88262
|
return {
|
|
87566
88263
|
...lastFatalError ? { lastFatalError } : {},
|
|
87567
88264
|
...lastShutdown ? { lastShutdown } : {},
|
|
87568
|
-
...baseHold ? { baseHold } : {}
|
|
88265
|
+
...baseHold ? { baseHold } : {},
|
|
88266
|
+
...unpublishableBranches ? { unpublishableBranches } : {},
|
|
88267
|
+
...await readCarriedGatewayPolicy(taskDir)
|
|
87569
88268
|
};
|
|
87570
88269
|
}
|
|
87571
88270
|
async function recordWorkerStartupFailure(options) {
|
|
87572
|
-
const taskDir =
|
|
88271
|
+
const taskDir = path33.join(options.workspacePath, ".tasks");
|
|
87573
88272
|
let release2;
|
|
87574
88273
|
try {
|
|
87575
|
-
await
|
|
88274
|
+
await fs31.mkdir(taskDir, { recursive: true });
|
|
87576
88275
|
release2 = await lockWorkerTaskDir(taskDir, 2 * (options.lockStaleMs ?? DEFAULT_LOCK_STALE_MS), {
|
|
87577
88276
|
onCompromised: (err) => workerLogError("Worker lock lost while recording a startup failure:", getErrorMessage(err))
|
|
87578
88277
|
});
|
|
87579
88278
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
87580
|
-
const { lastFatalError,
|
|
88279
|
+
const { lastFatalError, ...carried } = await readCarriedFields(taskDir);
|
|
87581
88280
|
if (lastFatalError && options.keepRecordedFatal && lastFatalError.workerStartedAt === await readWorkerStatusStartedAt(taskDir) && options.keepRecordedFatal(lastFatalError)) {
|
|
87582
88281
|
return;
|
|
87583
88282
|
}
|
|
@@ -87586,8 +88285,7 @@ async function recordWorkerStartupFailure(options) {
|
|
|
87586
88285
|
workerVersion: CANOPYCMS_VERSION,
|
|
87587
88286
|
startedAt: now,
|
|
87588
88287
|
updatedAt: now,
|
|
87589
|
-
...
|
|
87590
|
-
...baseHold ? { baseHold } : {},
|
|
88288
|
+
...carried,
|
|
87591
88289
|
lastFatalError: {
|
|
87592
88290
|
// [REDACT] Served to the browser by the admin panel and the API's not-ready answer.
|
|
87593
88291
|
message: redactCredentials(getErrorMessage(options.error)),
|
|
@@ -87628,17 +88326,17 @@ var CmsWorker = class {
|
|
|
87628
88326
|
this.selfStopped = new Promise((resolve) => {
|
|
87629
88327
|
this.settleSelfStopped = resolve;
|
|
87630
88328
|
});
|
|
87631
|
-
this.taskDir =
|
|
87632
|
-
this.remoteGitPath =
|
|
87633
|
-
this.stateDirectory =
|
|
88329
|
+
this.taskDir = path33.join(config.workspacePath, ".tasks");
|
|
88330
|
+
this.remoteGitPath = path33.join(path33.resolve(config.workspacePath), "remote.git");
|
|
88331
|
+
this.stateDirectory = path33.resolve(
|
|
87634
88332
|
config.stateDirectory ?? defaultStateDirectory(config.workspacePath)
|
|
87635
88333
|
);
|
|
87636
|
-
this.contentBranchesPath =
|
|
88334
|
+
this.contentBranchesPath = path33.join(config.workspacePath, "content-branches");
|
|
87637
88335
|
if (config.baseBranch !== void 0) this.setBaseBranch(config.baseBranch);
|
|
87638
88336
|
this.maxTasksPerCycle = config.maxTasksPerCycle ?? 10;
|
|
87639
88337
|
this.taskTimeoutMs = config.taskTimeoutMs ?? DEFAULT_TASK_TIMEOUT;
|
|
87640
88338
|
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES2;
|
|
87641
|
-
this.lockFilePath =
|
|
88339
|
+
this.lockFilePath = path33.join(config.workspacePath, ".tasks", ".worker-lock");
|
|
87642
88340
|
this.lockStaleMs = config.lockStaleMs ?? DEFAULT_LOCK_STALE_MS;
|
|
87643
88341
|
this.drainDeadlineMs = config.drainDeadlineMs ?? DEFAULT_DRAIN_DEADLINE_MS;
|
|
87644
88342
|
this.contentRoot = config.contentRoot ?? "content";
|
|
@@ -87687,7 +88385,7 @@ var CmsWorker = class {
|
|
|
87687
88385
|
*/
|
|
87688
88386
|
ensureSettingsBranch() {
|
|
87689
88387
|
if (this.settingsBranchResolved === void 0) {
|
|
87690
|
-
this.settingsBranchResolved =
|
|
88388
|
+
this.settingsBranchResolved = resolveWorkerSettingsBranch(this.config);
|
|
87691
88389
|
}
|
|
87692
88390
|
return this.settingsBranchResolved;
|
|
87693
88391
|
}
|
|
@@ -87748,10 +88446,8 @@ var CmsWorker = class {
|
|
|
87748
88446
|
this.ensureStatusReport();
|
|
87749
88447
|
await this.acquireLock();
|
|
87750
88448
|
try {
|
|
87751
|
-
const { lastFatalError,
|
|
87752
|
-
const report = this.ensureStatusReport();
|
|
87753
|
-
if (lastShutdown) report.lastShutdown = lastShutdown;
|
|
87754
|
-
if (baseHold) report.baseHold = baseHold;
|
|
88449
|
+
const { lastFatalError, ...carried } = await readCarriedFields(this.taskDir);
|
|
88450
|
+
const report = Object.assign(this.ensureStatusReport(), carried);
|
|
87755
88451
|
await writeWorkerStatus(this.taskDir, {
|
|
87756
88452
|
...report,
|
|
87757
88453
|
...lastFatalError ? { lastFatalError } : {}
|
|
@@ -87932,7 +88628,7 @@ var CmsWorker = class {
|
|
|
87932
88628
|
* is negligible at the default TTL; a badly wrong clock misjudges liveness.
|
|
87933
88629
|
*/
|
|
87934
88630
|
async acquireLock() {
|
|
87935
|
-
await
|
|
88631
|
+
await fs31.mkdir(this.taskDir, { recursive: true });
|
|
87936
88632
|
try {
|
|
87937
88633
|
this.releaseLockFn = await lockWorkerTaskDir(this.taskDir, this.lockStaleMs, {
|
|
87938
88634
|
onCompromised: (err) => {
|
|
@@ -88066,7 +88762,7 @@ var CmsWorker = class {
|
|
|
88066
88762
|
);
|
|
88067
88763
|
let remoteGitExists;
|
|
88068
88764
|
try {
|
|
88069
|
-
remoteGitExists = await
|
|
88765
|
+
remoteGitExists = await fs31.stat(this.remoteGitPath).then(
|
|
88070
88766
|
() => true,
|
|
88071
88767
|
(err) => {
|
|
88072
88768
|
if (isNodeError(err) && err.code === "ENOENT") return false;
|
|
@@ -88144,7 +88840,7 @@ var CmsWorker = class {
|
|
|
88144
88840
|
);
|
|
88145
88841
|
if (current === this.baseBranch) return;
|
|
88146
88842
|
await sharedRepoGit(gitDir, "bare").raw(["symbolic-ref", "HEAD", ref]);
|
|
88147
|
-
workerLog(`${
|
|
88843
|
+
workerLog(`${path33.basename(gitDir)} HEAD now names the base branch '${this.baseBranch}'`);
|
|
88148
88844
|
}
|
|
88149
88845
|
/**
|
|
88150
88846
|
* Whether the bare repo at `gitDir` has a local `refs/heads/<baseBranch>`.
|
|
@@ -88244,7 +88940,7 @@ var CmsWorker = class {
|
|
|
88244
88940
|
async ensureRemoteGit() {
|
|
88245
88941
|
let exists3;
|
|
88246
88942
|
try {
|
|
88247
|
-
await
|
|
88943
|
+
await fs31.stat(this.remoteGitPath);
|
|
88248
88944
|
exists3 = true;
|
|
88249
88945
|
} catch {
|
|
88250
88946
|
exists3 = false;
|
|
@@ -88264,7 +88960,7 @@ var CmsWorker = class {
|
|
|
88264
88960
|
}
|
|
88265
88961
|
workerLog("Initializing remote.git from GitHub...");
|
|
88266
88962
|
const stagingPath = await this.seedRemoteGitStaging();
|
|
88267
|
-
await
|
|
88963
|
+
await fs31.rename(stagingPath, this.remoteGitPath);
|
|
88268
88964
|
workerLog("remote.git initialized");
|
|
88269
88965
|
}
|
|
88270
88966
|
/**
|
|
@@ -88320,7 +89016,7 @@ var CmsWorker = class {
|
|
|
88320
89016
|
if (err instanceof RemoteGitKeptError) throw err;
|
|
88321
89017
|
throw notReplaced(redactCredentials(getErrorMessage(err)));
|
|
88322
89018
|
});
|
|
88323
|
-
const discardStaging = () =>
|
|
89019
|
+
const discardStaging = () => fs31.rm(stagingPath, { recursive: true, force: true });
|
|
88324
89020
|
let current;
|
|
88325
89021
|
try {
|
|
88326
89022
|
current = await listRemoteGitRefs(this.remoteGitPath);
|
|
@@ -88338,21 +89034,21 @@ var CmsWorker = class {
|
|
|
88338
89034
|
}
|
|
88339
89035
|
const replaced = `${this.remoteGitPath}.replaced-${Date.now()}`;
|
|
88340
89036
|
try {
|
|
88341
|
-
await
|
|
89037
|
+
await fs31.rename(this.remoteGitPath, replaced);
|
|
88342
89038
|
} catch (err) {
|
|
88343
89039
|
await discardStaging();
|
|
88344
89040
|
throw err;
|
|
88345
89041
|
}
|
|
88346
89042
|
try {
|
|
88347
|
-
await
|
|
89043
|
+
await fs31.rename(stagingPath, this.remoteGitPath);
|
|
88348
89044
|
} catch (err) {
|
|
88349
|
-
await
|
|
89045
|
+
await fs31.rename(replaced, this.remoteGitPath);
|
|
88350
89046
|
await discardStaging();
|
|
88351
89047
|
throw err;
|
|
88352
89048
|
}
|
|
88353
89049
|
const after = await listRemoteGitRefs(replaced).catch(() => null);
|
|
88354
89050
|
if (after !== null && sameRefs(refs, after)) {
|
|
88355
|
-
await
|
|
89051
|
+
await fs31.rm(replaced, { recursive: true, force: true, maxRetries: 3 }).catch((err) => {
|
|
88356
89052
|
workerLogWarn(
|
|
88357
89053
|
`Could not remove the replaced remote.git at ${replaced}: ${getErrorMessage(err)}`
|
|
88358
89054
|
);
|
|
@@ -88372,7 +89068,7 @@ var CmsWorker = class {
|
|
|
88372
89068
|
*/
|
|
88373
89069
|
async seedRemoteGitStaging(check) {
|
|
88374
89070
|
const stagingPath = `${this.remoteGitPath}.cloning`;
|
|
88375
|
-
await
|
|
89071
|
+
await fs31.rm(stagingPath, { recursive: true, force: true });
|
|
88376
89072
|
try {
|
|
88377
89073
|
const githubBranches = await seedFromGitHub(
|
|
88378
89074
|
this.transferContext(),
|
|
@@ -88388,7 +89084,7 @@ var CmsWorker = class {
|
|
|
88388
89084
|
if (!(err instanceof RemoteGitKeptError)) {
|
|
88389
89085
|
workerLogError(`remote.git seeding failed: ${redactCredentials(getErrorMessage(err))}`);
|
|
88390
89086
|
}
|
|
88391
|
-
await
|
|
89087
|
+
await fs31.rm(stagingPath, { recursive: true, force: true });
|
|
88392
89088
|
if (err instanceof RemoteGitKeptError) throw err;
|
|
88393
89089
|
if (err instanceof SharedRepoRefusalError) {
|
|
88394
89090
|
throw new SharedRepoRefusalError(
|
|
@@ -88446,9 +89142,11 @@ var CmsWorker = class {
|
|
|
88446
89142
|
if (this.config.githubAppAuth !== void 0) conflicting.push("githubAppAuth");
|
|
88447
89143
|
if (this.config.refreshGitHubToken !== void 0) conflicting.push("refreshGitHubToken");
|
|
88448
89144
|
if ((this.config.protectedBranches?.length ?? 0) > 0) conflicting.push("protectedBranches");
|
|
89145
|
+
if ((this.config.legacyBranches?.length ?? 0) > 0) conflicting.push("legacyBranches");
|
|
89146
|
+
if (this.config.branchNamespace !== void 0) conflicting.push("branchNamespace");
|
|
88449
89147
|
if (conflicting.length > 0) {
|
|
88450
89148
|
throw new Error(
|
|
88451
|
-
`CmsWorker: githubGateway is exclusive with ${conflicting.join(", ")}, which configure the in-process gateway; the gateway it is given holds the credential and the
|
|
89149
|
+
`CmsWorker: githubGateway is exclusive with ${conflicting.join(", ")}, which configure the in-process gateway; the gateway it is given holds the credential and the branch policy`
|
|
88452
89150
|
);
|
|
88453
89151
|
}
|
|
88454
89152
|
this.gateway = githubGateway;
|
|
@@ -88473,7 +89171,10 @@ var CmsWorker = class {
|
|
|
88473
89171
|
workspacePath: this.config.workspacePath,
|
|
88474
89172
|
timeoutMs: this.taskTimeoutMs,
|
|
88475
89173
|
baseBranch: this.config.baseBranch,
|
|
88476
|
-
protectedBranches: this.config.protectedBranches
|
|
89174
|
+
protectedBranches: this.config.protectedBranches,
|
|
89175
|
+
settingsBranch: this.ensureSettingsBranch(),
|
|
89176
|
+
legacyBranches: this.config.legacyBranches,
|
|
89177
|
+
branchNamespace: resolveBranchNamespace(this.config, "prod")
|
|
88477
89178
|
};
|
|
88478
89179
|
}
|
|
88479
89180
|
/**
|
|
@@ -88492,7 +89193,7 @@ var CmsWorker = class {
|
|
|
88492
89193
|
* sanitized.
|
|
88493
89194
|
*/
|
|
88494
89195
|
branchWorkspacePath(branchRefName) {
|
|
88495
|
-
return
|
|
89196
|
+
return path33.join(this.contentBranchesPath, sanitizeBranchName(branchRefName));
|
|
88496
89197
|
}
|
|
88497
89198
|
/**
|
|
88498
89199
|
* Test-only seam: awaited inside `rebaseActiveBranches()`'s conflict round,
|
|
@@ -88526,8 +89227,8 @@ var CmsWorker = class {
|
|
|
88526
89227
|
// `rebaseActiveBranches` also has a consumer outside the test files:
|
|
88527
89228
|
// apps/test-app/app/api/e2e-test/rebase/route.ts drives it from an e2e
|
|
88528
89229
|
// fixture route. Do not delete it as unused.
|
|
88529
|
-
async rebaseActiveBranches() {
|
|
88530
|
-
return runRebaseCycle(this.ctx());
|
|
89230
|
+
async rebaseActiveBranches(gatewayPolicy) {
|
|
89231
|
+
return runRebaseCycle(this.ctx(), gatewayPolicy);
|
|
88531
89232
|
}
|
|
88532
89233
|
// --- Git-sync cluster (worker/git-sync.ts) -----------------------------
|
|
88533
89234
|
//
|
|
@@ -88567,24 +89268,24 @@ var CmsWorker = class {
|
|
|
88567
89268
|
};
|
|
88568
89269
|
|
|
88569
89270
|
// ../canopycms/src/auth/file-based-auth-cache.ts
|
|
88570
|
-
import
|
|
88571
|
-
import
|
|
89271
|
+
import fs32 from "node:fs/promises";
|
|
89272
|
+
import path34 from "node:path";
|
|
88572
89273
|
var log5 = createDebugLogger({ prefix: "FileBasedAuthCache" });
|
|
88573
89274
|
async function writeAuthCacheSnapshot(cachePath, files) {
|
|
88574
|
-
await
|
|
89275
|
+
await fs32.mkdir(cachePath, { recursive: true });
|
|
88575
89276
|
const timestamp2 = Date.now();
|
|
88576
|
-
const snapshotDir =
|
|
88577
|
-
await
|
|
89277
|
+
const snapshotDir = path34.join(cachePath, `snapshot-${timestamp2}`);
|
|
89278
|
+
await fs32.mkdir(snapshotDir, { recursive: true });
|
|
88578
89279
|
for (const [fileName, data3] of Object.entries(files)) {
|
|
88579
|
-
const tmpPath =
|
|
88580
|
-
const finalPath =
|
|
88581
|
-
await
|
|
88582
|
-
await
|
|
88583
|
-
}
|
|
88584
|
-
const currentLink =
|
|
88585
|
-
const tmpLink =
|
|
88586
|
-
await
|
|
88587
|
-
await
|
|
89280
|
+
const tmpPath = path34.join(snapshotDir, `${fileName}.tmp`);
|
|
89281
|
+
const finalPath = path34.join(snapshotDir, fileName);
|
|
89282
|
+
await fs32.writeFile(tmpPath, JSON.stringify(data3, null, 2), "utf-8");
|
|
89283
|
+
await fs32.rename(tmpPath, finalPath);
|
|
89284
|
+
}
|
|
89285
|
+
const currentLink = path34.join(cachePath, "current");
|
|
89286
|
+
const tmpLink = path34.join(cachePath, `current-${timestamp2}`);
|
|
89287
|
+
await fs32.symlink(path34.basename(snapshotDir), tmpLink);
|
|
89288
|
+
await fs32.rename(tmpLink, currentLink);
|
|
88588
89289
|
await cleanupOldSnapshots(cachePath, 2);
|
|
88589
89290
|
return snapshotDir;
|
|
88590
89291
|
}
|
|
@@ -88601,14 +89302,14 @@ async function writeAuthSnapshot(cachePath, snapshot) {
|
|
|
88601
89302
|
async function cleanupOldSnapshots(cachePath, keepCount) {
|
|
88602
89303
|
let entries;
|
|
88603
89304
|
try {
|
|
88604
|
-
entries = await
|
|
89305
|
+
entries = await fs32.readdir(cachePath);
|
|
88605
89306
|
} catch {
|
|
88606
89307
|
return;
|
|
88607
89308
|
}
|
|
88608
89309
|
const snapshots = entries.filter((e9) => e9.startsWith("snapshot-")).sort().reverse();
|
|
88609
89310
|
for (const snapshot of snapshots.slice(keepCount)) {
|
|
88610
89311
|
try {
|
|
88611
|
-
await
|
|
89312
|
+
await fs32.rm(path34.join(cachePath, snapshot), {
|
|
88612
89313
|
recursive: true,
|
|
88613
89314
|
force: true
|
|
88614
89315
|
});
|
|
@@ -88755,7 +89456,8 @@ var GITHUB_GATEWAY_SOCKET_ENV = "CANOPYCMS_GITHUB_GATEWAY_SOCKET";
|
|
|
88755
89456
|
var GATEWAY_SPLIT_CONTRACT = 2;
|
|
88756
89457
|
var WORKER_CONTRACT_REQUIREMENTS = [
|
|
88757
89458
|
"StateDirectory=canopy-worker",
|
|
88758
|
-
`canopy-github.socket and canopy-github.service, and ${GITHUB_GATEWAY_SOCKET_ENV} on the worker unit
|
|
89459
|
+
`canopy-github.socket and canopy-github.service, and ${GITHUB_GATEWAY_SOCKET_ENV} on the worker unit`,
|
|
89460
|
+
"CANOPYCMS_DEPLOYMENT_NAME, and CANOPYCMS_SETTINGS_BRANCH when set, in gateway.env"
|
|
88759
89461
|
];
|
|
88760
89462
|
var WORKER_CONTRACT_VERSION = WORKER_CONTRACT_REQUIREMENTS.length;
|
|
88761
89463
|
var WORKER_CONTRACT_ENV = "CANOPYCMS_WORKER_CONTRACT";
|
|
@@ -88859,7 +89561,7 @@ async function completeTerminationLifecycleAction(options = {}) {
|
|
|
88859
89561
|
|
|
88860
89562
|
// worker/run.ts
|
|
88861
89563
|
init_error();
|
|
88862
|
-
import
|
|
89564
|
+
import path35 from "node:path";
|
|
88863
89565
|
|
|
88864
89566
|
// worker/github-app-auth.ts
|
|
88865
89567
|
var import_auth_app = __toESM(require_dist_node20(), 1);
|
|
@@ -93244,10 +93946,10 @@ var SessionAPI = class extends AbstractAPI {
|
|
|
93244
93946
|
*/
|
|
93245
93947
|
async getToken(sessionId, template, expiresInSeconds) {
|
|
93246
93948
|
this.requireId(sessionId);
|
|
93247
|
-
const
|
|
93949
|
+
const path36 = template ? joinPaths(basePath29, sessionId, "tokens", template) : joinPaths(basePath29, sessionId, "tokens");
|
|
93248
93950
|
const requestOptions = {
|
|
93249
93951
|
method: "POST",
|
|
93250
|
-
path:
|
|
93952
|
+
path: path36
|
|
93251
93953
|
};
|
|
93252
93954
|
if (expiresInSeconds !== void 0) {
|
|
93253
93955
|
requestOptions.bodyParams = { expires_in_seconds: expiresInSeconds };
|
|
@@ -95997,12 +96699,12 @@ function buildRequest(options) {
|
|
|
95997
96699
|
userAgent = USER_AGENT2,
|
|
95998
96700
|
skipApiVersionInUrl = false
|
|
95999
96701
|
} = options;
|
|
96000
|
-
const { path:
|
|
96702
|
+
const { path: path36, method, queryParams, headerParams, bodyParams, formData, options: opts } = requestOptions;
|
|
96001
96703
|
const { deepSnakecaseBodyParamKeys = false } = opts || {};
|
|
96002
96704
|
if (requireSecretKey) {
|
|
96003
96705
|
assertValidSecretKey(secretKey);
|
|
96004
96706
|
}
|
|
96005
|
-
const url = skipApiVersionInUrl ? joinPaths(apiUrl,
|
|
96707
|
+
const url = skipApiVersionInUrl ? joinPaths(apiUrl, path36) : joinPaths(apiUrl, apiVersion, path36);
|
|
96006
96708
|
const finalUrl = new URL(url);
|
|
96007
96709
|
if (queryParams) {
|
|
96008
96710
|
const snakecasedQueryParams = snakecase_keys_default({ ...queryParams });
|
|
@@ -98400,8 +99102,16 @@ function isRecentGatewayFatal(recorded, now = Date.now()) {
|
|
|
98400
99102
|
return recorded.phase === "startup" && recorded.message.startsWith(GATEWAY_FATAL_PREFIX) && age >= 0 && age < GATEWAY_AWAY_KEEP_MS;
|
|
98401
99103
|
}
|
|
98402
99104
|
var PROTECTED_BRANCHES_ENV = "CANOPYCMS_PROTECTED_BRANCHES";
|
|
99105
|
+
var BRANCH_NAMESPACE_ENV2 = "CANOPYCMS_BRANCH_NAMESPACE";
|
|
99106
|
+
var LEGACY_BRANCHES_ENV = "CANOPYCMS_LEGACY_BRANCHES";
|
|
99107
|
+
function parseBranchList(env2, name2) {
|
|
99108
|
+
return (env2[name2] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
99109
|
+
}
|
|
98403
99110
|
function parseProtectedBranches(env2) {
|
|
98404
|
-
return (env2
|
|
99111
|
+
return parseBranchList(env2, PROTECTED_BRANCHES_ENV);
|
|
99112
|
+
}
|
|
99113
|
+
function parseLegacyBranches(env2) {
|
|
99114
|
+
return parseBranchList(env2, LEGACY_BRANCHES_ENV);
|
|
98405
99115
|
}
|
|
98406
99116
|
var WORKER_STATE_DIRECTORY_MISSING = 'StateDirectory=canopy-worker is not set on the worker unit, and every worker contract requires it, so the worker does not start without it. Add it to the [Service] section of canopy-worker.service (see "The worker instance" in docs/deploying-to-aws.md).';
|
|
98407
99117
|
function readRepoEnv(env2, missingStateDirectory) {
|
|
@@ -98518,7 +99228,7 @@ async function buildSingleProcessWorker(deps, workspacePath) {
|
|
|
98518
99228
|
const { githubToken, githubTokenSecret, githubAppAuth, clerkSecret } = await readWorkerCredentials(env2, deps.getSecret);
|
|
98519
99229
|
const refreshAuthCache = createClerkAuthCacheRefresher({
|
|
98520
99230
|
secret: clerkSecret,
|
|
98521
|
-
cachePath:
|
|
99231
|
+
cachePath: path35.join(workspacePath, ".cache"),
|
|
98522
99232
|
useOrganizationsAsGroups
|
|
98523
99233
|
});
|
|
98524
99234
|
const worker = deps.createWorker({
|
|
@@ -98533,6 +99243,8 @@ async function buildSingleProcessWorker(deps, workspacePath) {
|
|
|
98533
99243
|
refreshGitHubToken: () => githubTokenSecret.refresh(),
|
|
98534
99244
|
refreshAuthCache,
|
|
98535
99245
|
protectedBranches: parseProtectedBranches(env2),
|
|
99246
|
+
legacyBranches: parseLegacyBranches(env2),
|
|
99247
|
+
branchNamespace: env2[BRANCH_NAMESPACE_ENV2]?.trim() || void 0,
|
|
98536
99248
|
...commonWorkerConfig(env2)
|
|
98537
99249
|
});
|
|
98538
99250
|
return {
|
|
@@ -98551,10 +99263,16 @@ async function buildSplitWorker(deps, workspacePath, socketPath, onGatewayWait)
|
|
|
98551
99263
|
env2,
|
|
98552
99264
|
WORKER_STATE_DIRECTORY_MISSING
|
|
98553
99265
|
);
|
|
98554
|
-
|
|
98555
|
-
|
|
98556
|
-
|
|
98557
|
-
)
|
|
99266
|
+
for (const [name2, entries] of [
|
|
99267
|
+
[PROTECTED_BRANCHES_ENV, parseProtectedBranches(env2)],
|
|
99268
|
+
[LEGACY_BRANCHES_ENV, parseLegacyBranches(env2)],
|
|
99269
|
+
[BRANCH_NAMESPACE_ENV2, env2[BRANCH_NAMESPACE_ENV2]?.trim() ? [env2[BRANCH_NAMESPACE_ENV2]] : []]
|
|
99270
|
+
]) {
|
|
99271
|
+
if (entries.length > 0) {
|
|
99272
|
+
throw new Error(
|
|
99273
|
+
`${name2} is set on the worker unit, but beside the GitHub gateway it is the gateway's setting: move it to the gateway's environment (gateway.env)`
|
|
99274
|
+
);
|
|
99275
|
+
}
|
|
98558
99276
|
}
|
|
98559
99277
|
if (env2[CLERK_ORGANIZATIONS_AS_GROUPS_ENV]) {
|
|
98560
99278
|
throw new Error(
|
|
@@ -98578,9 +99296,19 @@ async function buildSplitWorker(deps, workspacePath, socketPath, onGatewayWait)
|
|
|
98578
99296
|
throw new Error(`${GATEWAY_FATAL_PREFIX}${health.fatalError}`);
|
|
98579
99297
|
}
|
|
98580
99298
|
if (!health.ready) throw new Error("The GitHub gateway is not ready");
|
|
99299
|
+
const settingsBranch = resolveWorkerSettingsBranch({
|
|
99300
|
+
settingsBranch: env2.CANOPYCMS_SETTINGS_BRANCH,
|
|
99301
|
+
deploymentName: env2.CANOPYCMS_DEPLOYMENT_NAME
|
|
99302
|
+
});
|
|
99303
|
+
const gatewaySettingsBranch = health.branchPolicy.settingsBranch;
|
|
99304
|
+
if (gatewaySettingsBranch !== settingsBranch) {
|
|
99305
|
+
throw new Error(
|
|
99306
|
+
`The GitHub gateway pushes the settings branch ${JSON.stringify(gatewaySettingsBranch)}, but this worker's is ${JSON.stringify(settingsBranch)}: set CANOPYCMS_DEPLOYMENT_NAME and CANOPYCMS_SETTINGS_BRANCH alike in the worker's .env and gateway.env`
|
|
99307
|
+
);
|
|
99308
|
+
}
|
|
98581
99309
|
const refreshAuthCache = health.clerkConfigured ? async () => {
|
|
98582
99310
|
const snapshot = await gateway.authSnapshot();
|
|
98583
|
-
await deps.writeAuthSnapshot(
|
|
99311
|
+
await deps.writeAuthSnapshot(path35.join(workspacePath, ".cache"), snapshot);
|
|
98584
99312
|
workerLog(` ${snapshot.users.length} users, ${snapshot.groups.length} groups`);
|
|
98585
99313
|
} : void 0;
|
|
98586
99314
|
const worker = deps.createWorker({
|
|
@@ -98761,6 +99489,19 @@ async function buildGateway(deps, listen) {
|
|
|
98761
99489
|
timeoutMs: DEFAULT_TASK_TIMEOUT,
|
|
98762
99490
|
baseBranch: env2.CANOPYCMS_BASE_BRANCH || void 0,
|
|
98763
99491
|
protectedBranches: parseProtectedBranches(env2),
|
|
99492
|
+
// Resolved as the worker resolves its own (`CANOPYCMS_SETTINGS_BRANCH`, else from
|
|
99493
|
+
// `CANOPYCMS_DEPLOYMENT_NAME`), so the one settings branch pushed is the worker's.
|
|
99494
|
+
settingsBranch: resolveWorkerSettingsBranch({
|
|
99495
|
+
settingsBranch: env2.CANOPYCMS_SETTINGS_BRANCH,
|
|
99496
|
+
deploymentName: env2.CANOPYCMS_DEPLOYMENT_NAME
|
|
99497
|
+
}),
|
|
99498
|
+
legacyBranches: parseLegacyBranches(env2),
|
|
99499
|
+
// From this unit's own environment: never from anything the CMS Lambda can write.
|
|
99500
|
+
branchNamespace: resolveBranchNamespace(
|
|
99501
|
+
{ deploymentName: env2.CANOPYCMS_DEPLOYMENT_NAME },
|
|
99502
|
+
"prod",
|
|
99503
|
+
env2
|
|
99504
|
+
),
|
|
98764
99505
|
authSnapshot: createClerkSnapshotFetcher({
|
|
98765
99506
|
secret: clerkSecret,
|
|
98766
99507
|
useOrganizationsAsGroups,
|
|
@@ -98780,7 +99521,13 @@ function failedGateway(message2, instance) {
|
|
|
98780
99521
|
fatalError: message2,
|
|
98781
99522
|
preflight: "pending",
|
|
98782
99523
|
clerkConfigured: false,
|
|
98783
|
-
|
|
99524
|
+
branchPolicy: {
|
|
99525
|
+
configured: [],
|
|
99526
|
+
githubDefault: null,
|
|
99527
|
+
namespace: "",
|
|
99528
|
+
legacy: [],
|
|
99529
|
+
settingsBranch: null
|
|
99530
|
+
}
|
|
98784
99531
|
}),
|
|
98785
99532
|
defaultBranch: refuse,
|
|
98786
99533
|
isProtectedBranch: refuse,
|