fix: address monitor ingest review blockers
This commit is contained in:
@@ -15,9 +15,13 @@ export class MonitorIngestFailedError extends Error {
|
||||
|
||||
export function buildMonitorTerminalIngest(identity: MonitorTerminalIdentity, report: Record<string, unknown>, artifacts: readonly MonitorTerminalArtifact[], locatorOwner: Pick<MonitorArtifactLocator, "ownerNode" | "ownerLane" | "ownerPvc" | "stateDir">): MonitorCentralIngest {
|
||||
const immutableReport = JSON.parse(monitorCentralStableJson(report)) as Record<string, unknown>;
|
||||
if (!identity.runId) throw new MonitorIngestFailedError({ reason: "run_id_missing", valuesRedacted: true });
|
||||
const updatedAt = stringValue(immutableReport.updatedAt) ?? stringValue(immutableReport.analyzedAt);
|
||||
if (!updatedAt) throw new MonitorIngestFailedError({ reason: "terminal_timestamp_missing", runId: identity.runId, valuesRedacted: true });
|
||||
for (const artifact of artifacts) if (!/^sha256:[a-f0-9]{64}$/u.test(artifact.sha256) || !Number.isSafeInteger(artifact.sizeBytes) || artifact.sizeBytes < 1) throw new MonitorIngestFailedError({ reason: "terminal_artifact_unverified", runId: identity.runId, relativePath: artifact.relativePath, valuesRedacted: true });
|
||||
return normalizeMonitorCentralIngest({
|
||||
...identity,
|
||||
updatedAt: stringValue(immutableReport.updatedAt) ?? stringValue(immutableReport.analyzedAt) ?? new Date().toISOString(),
|
||||
updatedAt,
|
||||
status: stringValue(immutableReport.status) ?? (immutableReport.ok === true ? "ok" : "blocked"),
|
||||
payload: { report: immutableReport, artifacts: artifacts.map((artifact) => ({ ...artifact })) },
|
||||
findings: recordArray(immutableReport.findings),
|
||||
@@ -57,13 +61,22 @@ function sleep(delayMs: number): Promise<void> { return new Promise((resolve) =>
|
||||
export interface MonitorTerminalWriterConfig { readonly mode: "legacy-sqlite" | "central"; readonly ingest?: MonitorTerminalIngestConfig; }
|
||||
|
||||
export function resolveMonitorTerminalWriter(runtime: Record<string, unknown>): MonitorTerminalWriterConfig {
|
||||
const sqlite = runtime.sqlite;
|
||||
const sqlitePath = sqlite && typeof sqlite === "object" && !Array.isArray(sqlite) ? stringValue((sqlite as Record<string, unknown>).path) : undefined;
|
||||
const monitor = runtime.monitor;
|
||||
const writer = monitor && typeof monitor === "object" && !Array.isArray(monitor) ? (monitor as Record<string, unknown>).terminalWriter : null;
|
||||
if (!writer || typeof writer !== "object" || Array.isArray(writer)) return { mode: "legacy-sqlite" };
|
||||
if (!writer || typeof writer !== "object" || Array.isArray(writer)) {
|
||||
if (sqlitePath) return { mode: "legacy-sqlite" };
|
||||
throw new Error("terminal writer authority is undeclared: sqlite.path or monitor.terminalWriter is required");
|
||||
}
|
||||
const value = writer as Record<string, unknown>;
|
||||
const mode = value.mode;
|
||||
if (mode !== "legacy-sqlite" && mode !== "central") throw new Error("monitor.terminalWriter.mode must be legacy-sqlite or central");
|
||||
if (mode === "legacy-sqlite") return { mode };
|
||||
if (mode === "legacy-sqlite") {
|
||||
if (!sqlitePath) throw new Error("sqlite.path is required when mode=legacy-sqlite");
|
||||
return { mode };
|
||||
}
|
||||
if (sqlitePath) throw new Error("central terminal writer and sqlite.path are mutually exclusive");
|
||||
const ingest = value.ingest;
|
||||
if (!ingest || typeof ingest !== "object" || Array.isArray(ingest)) throw new Error("monitor.terminalWriter.ingest is required when mode=central");
|
||||
const config = ingest as Record<string, unknown>;
|
||||
|
||||
Reference in New Issue
Block a user