@tradejs/cli 3.1.21-beta.237 → 3.1.22-beta.238
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/cli.js +1643 -806
- package/dist/lib/runtimeEvidenceProducer.js +98 -0
- package/dist/lib/runtimeEvidenceSync.js +8 -3
- package/dist/lib/runtimeFeedbackArtifacts.js +566 -0
- package/dist/lib/runtimeFeedbackReplay.js +808 -0
- package/dist/lib/runtimeFeedbackSync.js +350 -0
- package/dist/scripts/replay.js +9 -6
- package/dist/scripts/replayRunner.js +9 -6
- package/dist/scripts/replayRuntimeEvidence.js +4 -0
- package/dist/scripts/runtimeEvidence.js +62 -7
- package/dist/scripts/runtimeFeedbackReplay.js +850 -0
- package/dist/scripts/runtimeFeedbackSync.js +411 -0
- package/dist/scripts/runtimeScorecard.js +217 -39
- package/package.json +9 -7
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/scripts/runtimeFeedbackSync.ts
|
|
31
|
+
var runtimeFeedbackSync_exports = {};
|
|
32
|
+
__export(runtimeFeedbackSync_exports, {
|
|
33
|
+
main: () => main,
|
|
34
|
+
runtimeFeedbackSync: () => runtimeFeedbackSync
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(runtimeFeedbackSync_exports);
|
|
37
|
+
var import_node_path6 = __toESM(require("path"));
|
|
38
|
+
var import_args = __toESM(require("args"));
|
|
39
|
+
var import_chalk = __toESM(require("chalk"));
|
|
40
|
+
|
|
41
|
+
// src/lib/runtimeFeedbackSync.ts
|
|
42
|
+
var import_node_child_process2 = require("child_process");
|
|
43
|
+
var import_promises5 = __toESM(require("fs/promises"));
|
|
44
|
+
var import_node_path5 = __toESM(require("path"));
|
|
45
|
+
var import_node_util2 = require("util");
|
|
46
|
+
|
|
47
|
+
// src/lib/runtimeFeedbackArtifacts.ts
|
|
48
|
+
var import_node_crypto3 = require("crypto");
|
|
49
|
+
var import_promises3 = __toESM(require("fs/promises"));
|
|
50
|
+
var import_node_path3 = __toESM(require("path"));
|
|
51
|
+
|
|
52
|
+
// src/lib/runtimeEvidenceDeployment.ts
|
|
53
|
+
var import_runtimeStrategies = require("@tradejs/node/runtimeStrategies");
|
|
54
|
+
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
55
|
+
var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
56
|
+
var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
|
|
57
|
+
([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
|
|
58
|
+
);
|
|
59
|
+
var INTERVALS = /* @__PURE__ */ new Set([
|
|
60
|
+
"1",
|
|
61
|
+
"3",
|
|
62
|
+
"5",
|
|
63
|
+
"15",
|
|
64
|
+
"30",
|
|
65
|
+
"60",
|
|
66
|
+
"120",
|
|
67
|
+
"240",
|
|
68
|
+
"360",
|
|
69
|
+
"720",
|
|
70
|
+
"D",
|
|
71
|
+
"W",
|
|
72
|
+
"M"
|
|
73
|
+
]);
|
|
74
|
+
var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
|
|
75
|
+
var isRuntimeStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => key === "tickers") && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every((ticker) => isNonEmptyString(ticker));
|
|
76
|
+
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
77
|
+
if (!isRecord(value) || value.schemaVersion !== 2 || !isNonEmptyString(value.id) || !isNonEmptyString(value.deploymentCompositionId) || !/^dc1:[a-f0-9]{16}$/.test(value.deploymentCompositionId) || !isNonEmptyString(value.label) || !isNonEmptyString(value.connectorName) || !isNonEmptyString(value.provider) || !isNonEmptyString(value.accountId) || typeof value.enabled !== "boolean" || !Array.isArray(value.strategies)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"Runtime evidence deployment snapshot is missing or invalid"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const strategies = value.strategies.map((candidate) => {
|
|
83
|
+
if (!isRecord(candidate) || !isNonEmptyString(candidate.strategyName) || !isNonEmptyString(candidate.strategyRevision) || !/^sr1:[a-f0-9]{16}$/.test(candidate.strategyRevision) || typeof candidate.enabled !== "boolean" || !["active", "entries_paused"].includes(String(candidate.controlState)) || !INTERVALS.has(String(candidate.interval)) || !UNIVERSES.has(String(candidate.universe)) || !isNonEmptyString(candidate.strategyPackage) || !isNonEmptyString(candidate.strategyPackageVersion) || !isPackageVersionMap(candidate.strategyDependencyVersions) || !isNonEmptyString(candidate.runtimePackageVersion) || !isRecord(candidate.strategyConfig) || !isRuntimeStrategySelection(candidate.selection)) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Runtime evidence deployment strategy snapshot is invalid"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return candidate;
|
|
99
|
+
});
|
|
100
|
+
const identities = /* @__PURE__ */ new Set();
|
|
101
|
+
for (const strategy of strategies) {
|
|
102
|
+
if (identities.has(strategy.strategyName)) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
identities.add(strategy.strategyName);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
...value,
|
|
111
|
+
strategies
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
115
|
+
|
|
116
|
+
// src/lib/runtimeEvidenceArtifacts.ts
|
|
117
|
+
var import_node_crypto = require("crypto");
|
|
118
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
119
|
+
var import_node_path = __toESM(require("path"));
|
|
120
|
+
|
|
121
|
+
// src/lib/runtimeEvidenceProducer.ts
|
|
122
|
+
var import_node_crypto2 = require("crypto");
|
|
123
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
124
|
+
var import_node_path2 = __toESM(require("path"));
|
|
125
|
+
var isRecord2 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
126
|
+
var parseRuntimeEvidenceProducer = (value) => {
|
|
127
|
+
const producer = isRecord2(value) ? value : null;
|
|
128
|
+
const runtimePackageManifest = isRecord2(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
|
|
129
|
+
if (producer?.schemaVersion !== 1 || typeof producer.projectSha !== "string" || !/^[a-f0-9]{40}$/.test(producer.projectSha) || typeof producer.imageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(producer.imageDigest) || runtimePackageManifest?.file !== "runtime-package-manifest.json" || typeof runtimePackageManifest.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimePackageManifest.sha256)) {
|
|
130
|
+
throw new Error("Runtime evidence producer image identity is invalid");
|
|
131
|
+
}
|
|
132
|
+
return producer;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/lib/runtimeFeedbackArtifacts.ts
|
|
136
|
+
var RUNTIME_FEEDBACK_MANIFEST_FILE = "manifest.json";
|
|
137
|
+
var RUNTIME_FEEDBACK_REPLAY_FILE = "replay-runtime-evidence.json";
|
|
138
|
+
var RUNTIME_FEEDBACK_LOG_FILE = "replay.log";
|
|
139
|
+
var RUNTIME_FEEDBACK_COMPLETE_FILE = ".complete";
|
|
140
|
+
var isRecord3 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
141
|
+
var sha256 = (value) => (0, import_node_crypto3.createHash)("sha256").update(value).digest("hex");
|
|
142
|
+
var parsePayload = (value, expectedFile) => {
|
|
143
|
+
const payload = isRecord3(value) ? value : null;
|
|
144
|
+
if (payload?.file !== expectedFile || typeof payload.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(payload.sha256) || typeof payload.bytes !== "number" || !Number.isFinite(payload.bytes) || payload.bytes < 0) {
|
|
145
|
+
throw new Error(`Invalid runtime feedback payload: ${expectedFile}`);
|
|
146
|
+
}
|
|
147
|
+
return payload;
|
|
148
|
+
};
|
|
149
|
+
var parseManifest = (value) => {
|
|
150
|
+
const manifest = isRecord3(value) ? value : null;
|
|
151
|
+
const window = isRecord3(manifest?.window) ? manifest.window : null;
|
|
152
|
+
const runtimeEvidence = isRecord3(manifest?.runtimeEvidence) ? manifest.runtimeEvidence : null;
|
|
153
|
+
const safety = isRecord3(manifest?.safety) ? manifest.safety : null;
|
|
154
|
+
const payloads = isRecord3(manifest?.payloads) ? manifest.payloads : null;
|
|
155
|
+
if (manifest?.schemaVersion !== 1 || manifest.reportType !== "runtime-feedback-replay" || typeof manifest.artifactId !== "string" || !manifest.artifactId.trim() || typeof manifest.runId !== "string" || !manifest.runId.trim() || typeof manifest.deploymentId !== "string" || !manifest.deploymentId.trim() || typeof manifest.deploymentCompositionId !== "string" || !/^dc1:[a-f0-9]{16}$/.test(manifest.deploymentCompositionId) || typeof manifest.userName !== "string" || !manifest.userName.trim() || typeof manifest.createdAt !== "number" || typeof window?.startTime !== "number" || typeof window.endTime !== "number" || typeof runtimeEvidence?.artifactId !== "string" || typeof runtimeEvidence.payloadSha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimeEvidence.payloadSha256) || !Array.isArray(manifest.activeStrategies) || manifest.activeStrategies.length === 0 || !manifest.activeStrategies.every(
|
|
156
|
+
(strategy) => typeof strategy === "string" && strategy.trim()
|
|
157
|
+
) || typeof manifest.cycleCount !== "number" || !Number.isFinite(manifest.cycleCount) || manifest.cycleCount <= 0 || safety?.cacheOnly !== true || safety.externalOrderPlacement !== false || safety.redis !== "isolated" || safety.timescale !== "read_only") {
|
|
158
|
+
throw new Error("Invalid runtime feedback replay manifest");
|
|
159
|
+
}
|
|
160
|
+
const replayEvidence = parsePayload(
|
|
161
|
+
payloads?.replayEvidence,
|
|
162
|
+
RUNTIME_FEEDBACK_REPLAY_FILE
|
|
163
|
+
);
|
|
164
|
+
const log = parsePayload(payloads?.log, RUNTIME_FEEDBACK_LOG_FILE);
|
|
165
|
+
return {
|
|
166
|
+
...manifest,
|
|
167
|
+
producer: parseRuntimeEvidenceProducer(manifest.producer),
|
|
168
|
+
payloads: {
|
|
169
|
+
replayEvidence: {
|
|
170
|
+
...replayEvidence,
|
|
171
|
+
file: RUNTIME_FEEDBACK_REPLAY_FILE
|
|
172
|
+
},
|
|
173
|
+
log: { ...log, file: RUNTIME_FEEDBACK_LOG_FILE }
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
var verifyRuntimeFeedbackReplayBundle = async (bundleDir) => {
|
|
178
|
+
const manifestPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_MANIFEST_FILE);
|
|
179
|
+
const replayEvidencePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_REPLAY_FILE);
|
|
180
|
+
const logPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_LOG_FILE);
|
|
181
|
+
const completePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_COMPLETE_FILE);
|
|
182
|
+
const [manifestText, replayPayload, logPayload, completeText] = await Promise.all([
|
|
183
|
+
import_promises3.default.readFile(manifestPath, "utf8"),
|
|
184
|
+
import_promises3.default.readFile(replayEvidencePath),
|
|
185
|
+
import_promises3.default.readFile(logPath),
|
|
186
|
+
import_promises3.default.readFile(completePath, "utf8")
|
|
187
|
+
]);
|
|
188
|
+
const manifest = parseManifest(JSON.parse(manifestText));
|
|
189
|
+
if (completeText.trim() !== manifest.artifactId) {
|
|
190
|
+
throw new Error(`Invalid runtime feedback completion marker: ${bundleDir}`);
|
|
191
|
+
}
|
|
192
|
+
for (const [payload, descriptor] of [
|
|
193
|
+
[replayPayload, manifest.payloads.replayEvidence],
|
|
194
|
+
[logPayload, manifest.payloads.log]
|
|
195
|
+
]) {
|
|
196
|
+
if (payload.byteLength !== descriptor.bytes) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`Runtime feedback payload size mismatch: ${descriptor.file}`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
if (sha256(payload) !== descriptor.sha256) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Runtime feedback payload checksum mismatch: ${descriptor.file}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const replayEvidence = JSON.parse(replayPayload.toString("utf8"));
|
|
208
|
+
if (replayEvidence.reportType !== "replay-runtime-evidence") {
|
|
209
|
+
throw new Error("Invalid runtime feedback replay evidence payload");
|
|
210
|
+
}
|
|
211
|
+
const replayWindow = isRecord3(replayEvidence.window) ? replayEvidence.window : null;
|
|
212
|
+
const replay = isRecord3(replayEvidence.replay) ? replayEvidence.replay : null;
|
|
213
|
+
const replayDeployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
214
|
+
replayEvidence.deployment
|
|
215
|
+
);
|
|
216
|
+
const replayStrategies = activeRuntimeEvidenceStrategies(replayDeployment).map(({ strategyName }) => strategyName).sort();
|
|
217
|
+
if (replayEvidence.userName !== manifest.userName || replayWindow?.startTime !== manifest.window.startTime || replayWindow.endTime !== manifest.window.endTime || replayDeployment.id !== manifest.deploymentId || replayDeployment.deploymentCompositionId !== manifest.deploymentCompositionId || Number(replay?.cycleCount) !== manifest.cycleCount || JSON.stringify(replayStrategies) !== JSON.stringify([...manifest.activeStrategies].sort())) {
|
|
218
|
+
throw new Error("Runtime feedback replay payload does not match manifest");
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
bundleDir,
|
|
222
|
+
manifestPath,
|
|
223
|
+
replayEvidencePath,
|
|
224
|
+
logPath,
|
|
225
|
+
manifest,
|
|
226
|
+
replayEvidence
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
var discoverRuntimeFeedbackReplayBundles = async (rootDir) => {
|
|
230
|
+
const bundles = [];
|
|
231
|
+
const visit = async (directory, depth) => {
|
|
232
|
+
if (depth > 10) return;
|
|
233
|
+
let entries;
|
|
234
|
+
try {
|
|
235
|
+
entries = await import_promises3.default.readdir(directory, { withFileTypes: true });
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error.code === "ENOENT") return;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
const names = new Set(entries.map((entry) => entry.name));
|
|
241
|
+
if (names.has(RUNTIME_FEEDBACK_MANIFEST_FILE) && names.has(RUNTIME_FEEDBACK_REPLAY_FILE) && names.has(RUNTIME_FEEDBACK_LOG_FILE) && names.has(RUNTIME_FEEDBACK_COMPLETE_FILE)) {
|
|
242
|
+
bundles.push(directory);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
await Promise.all(
|
|
246
|
+
entries.filter(
|
|
247
|
+
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.includes(".tmp-")
|
|
248
|
+
).map((entry) => visit(import_node_path3.default.join(directory, entry.name), depth + 1))
|
|
249
|
+
);
|
|
250
|
+
};
|
|
251
|
+
await visit(rootDir, 0);
|
|
252
|
+
return bundles.sort();
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/lib/runtimeEvidenceSync.ts
|
|
256
|
+
var import_node_child_process = require("child_process");
|
|
257
|
+
var import_promises4 = __toESM(require("fs/promises"));
|
|
258
|
+
var import_node_path4 = __toESM(require("path"));
|
|
259
|
+
var import_node_util = require("util");
|
|
260
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
261
|
+
var withTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
|
|
262
|
+
var buildRuntimeEvidenceRsyncArgs = ({
|
|
263
|
+
source,
|
|
264
|
+
destination
|
|
265
|
+
}) => [
|
|
266
|
+
"--recursive",
|
|
267
|
+
"--times",
|
|
268
|
+
"--partial",
|
|
269
|
+
"--partial-dir=.rsync-partial",
|
|
270
|
+
"--prune-empty-dirs",
|
|
271
|
+
withTrailingSlash(source),
|
|
272
|
+
withTrailingSlash(destination)
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
// src/lib/runtimeFeedbackSync.ts
|
|
276
|
+
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
|
|
277
|
+
var isExistingDestinationError = (error) => {
|
|
278
|
+
const code = error.code;
|
|
279
|
+
return code === "EEXIST" || code === "ENOTEMPTY";
|
|
280
|
+
};
|
|
281
|
+
var safeSegment = (value, fallback) => {
|
|
282
|
+
const normalized = value.trim().replace(/[^a-zA-Z0-9._-]+/g, "-");
|
|
283
|
+
return normalized && normalized !== "." && normalized !== ".." ? normalized : fallback;
|
|
284
|
+
};
|
|
285
|
+
var dateParts = (timestamp) => {
|
|
286
|
+
const date = new Date(timestamp);
|
|
287
|
+
return [
|
|
288
|
+
String(date.getUTCFullYear()),
|
|
289
|
+
String(date.getUTCMonth() + 1).padStart(2, "0"),
|
|
290
|
+
String(date.getUTCDate()).padStart(2, "0")
|
|
291
|
+
];
|
|
292
|
+
};
|
|
293
|
+
var syncRuntimeFeedbackReplayBundles = async ({
|
|
294
|
+
source,
|
|
295
|
+
feedbackRoot,
|
|
296
|
+
deploymentId,
|
|
297
|
+
runRsync = async (args2) => {
|
|
298
|
+
const result = await execFileAsync2("rsync", args2, {
|
|
299
|
+
maxBuffer: 10 * 1024 * 1024
|
|
300
|
+
});
|
|
301
|
+
return { stdout: result.stdout, stderr: result.stderr };
|
|
302
|
+
}
|
|
303
|
+
}) => {
|
|
304
|
+
const safeDeploymentId = safeSegment(deploymentId, "production");
|
|
305
|
+
const inboxRoot = import_node_path5.default.join(feedbackRoot, "inbox", safeDeploymentId);
|
|
306
|
+
const artifactsRoot = import_node_path5.default.join(feedbackRoot, "artifacts", safeDeploymentId);
|
|
307
|
+
await Promise.all([
|
|
308
|
+
import_promises5.default.mkdir(inboxRoot, { recursive: true }),
|
|
309
|
+
import_promises5.default.mkdir(artifactsRoot, { recursive: true })
|
|
310
|
+
]);
|
|
311
|
+
const rsyncArgs = buildRuntimeEvidenceRsyncArgs({
|
|
312
|
+
source,
|
|
313
|
+
destination: inboxRoot
|
|
314
|
+
});
|
|
315
|
+
const transfer = await runRsync(rsyncArgs);
|
|
316
|
+
const discovered = await discoverRuntimeFeedbackReplayBundles(inboxRoot);
|
|
317
|
+
const received = [];
|
|
318
|
+
for (const bundleDir of discovered) {
|
|
319
|
+
const verified = await verifyRuntimeFeedbackReplayBundle(bundleDir);
|
|
320
|
+
if (verified.manifest.deploymentId !== safeDeploymentId) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`Runtime feedback deployment mismatch: expected ${safeDeploymentId}, received ${verified.manifest.deploymentId}`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
const destinationDir = import_node_path5.default.join(
|
|
326
|
+
artifactsRoot,
|
|
327
|
+
...dateParts(verified.manifest.window.endTime),
|
|
328
|
+
safeSegment(verified.manifest.runtimeEvidence.artifactId, "artifact"),
|
|
329
|
+
safeSegment(verified.manifest.runId, "run")
|
|
330
|
+
);
|
|
331
|
+
await import_promises5.default.mkdir(import_node_path5.default.dirname(destinationDir), { recursive: true });
|
|
332
|
+
try {
|
|
333
|
+
await import_promises5.default.rename(bundleDir, destinationDir);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (!isExistingDestinationError(error)) throw error;
|
|
336
|
+
const existing = await verifyRuntimeFeedbackReplayBundle(destinationDir);
|
|
337
|
+
if (existing.manifest.payloads.replayEvidence.sha256 !== verified.manifest.payloads.replayEvidence.sha256) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Conflicting runtime feedback replay ${verified.manifest.artifactId}`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
await import_promises5.default.rm(bundleDir, { recursive: true, force: true });
|
|
343
|
+
}
|
|
344
|
+
received.push(await verifyRuntimeFeedbackReplayBundle(destinationDir));
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
rsyncArgs,
|
|
348
|
+
stdout: String(transfer.stdout ?? ""),
|
|
349
|
+
stderr: String(transfer.stderr ?? ""),
|
|
350
|
+
received
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// src/scripts/runtimeFeedbackSync.ts
|
|
355
|
+
import_args.default.option(
|
|
356
|
+
"source",
|
|
357
|
+
"Rsync source ending at the runtime feedback ready directory",
|
|
358
|
+
process.env.RUNTIME_FEEDBACK_RSYNC_SOURCE
|
|
359
|
+
);
|
|
360
|
+
import_args.default.option(
|
|
361
|
+
"deployment",
|
|
362
|
+
"Deployment id expected in runtime feedback manifests",
|
|
363
|
+
process.env.RUNTIME_EVIDENCE_DEPLOYMENT_ID || "production"
|
|
364
|
+
);
|
|
365
|
+
import_args.default.option(
|
|
366
|
+
"dir",
|
|
367
|
+
"Local runtime feedback storage root",
|
|
368
|
+
process.env.RUNTIME_FEEDBACK_LOCAL_DIR || "data/runtime-feedback"
|
|
369
|
+
);
|
|
370
|
+
var flags = import_args.default.parse(process.argv);
|
|
371
|
+
var projectRoot = String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
|
|
372
|
+
var runtimeFeedbackSync = async () => {
|
|
373
|
+
const source = String(flags.source ?? "").trim();
|
|
374
|
+
if (!source) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
"Provide --source or RUNTIME_FEEDBACK_RSYNC_SOURCE for runtime feedback sync."
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
const feedbackRoot = import_node_path6.default.resolve(projectRoot, String(flags.dir));
|
|
380
|
+
const result = await syncRuntimeFeedbackReplayBundles({
|
|
381
|
+
source,
|
|
382
|
+
feedbackRoot,
|
|
383
|
+
deploymentId: String(flags.deployment)
|
|
384
|
+
});
|
|
385
|
+
console.log(
|
|
386
|
+
import_chalk.default.green(
|
|
387
|
+
`Runtime feedback sync completed: received=${result.received.length}`
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
console.log(
|
|
391
|
+
JSON.stringify(
|
|
392
|
+
{
|
|
393
|
+
feedbackRoot,
|
|
394
|
+
received: result.received.map((bundle) => ({
|
|
395
|
+
artifactId: bundle.manifest.artifactId,
|
|
396
|
+
bundleDir: bundle.bundleDir,
|
|
397
|
+
replayEvidencePath: bundle.replayEvidencePath,
|
|
398
|
+
runtimeEvidence: bundle.manifest.runtimeEvidence
|
|
399
|
+
}))
|
|
400
|
+
},
|
|
401
|
+
null,
|
|
402
|
+
2
|
|
403
|
+
)
|
|
404
|
+
);
|
|
405
|
+
};
|
|
406
|
+
var main = runtimeFeedbackSync;
|
|
407
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
408
|
+
0 && (module.exports = {
|
|
409
|
+
main,
|
|
410
|
+
runtimeFeedbackSync
|
|
411
|
+
});
|