From 00fb74c76a9bc1ab000e68500ed06c8f6efdaf64 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Fri, 5 Jun 2026 09:59:18 +0200 Subject: [PATCH] feat(ingest): Improve general script robustness and cleanup --- skills/ingest/scripts/log-append.sh | 2 +- skills/ingest/scripts/run-ingest.sh | 13 ++++++++++++- skills/ingest/scripts/scoped-lint.sh | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/skills/ingest/scripts/log-append.sh b/skills/ingest/scripts/log-append.sh index 32e6ca0..b3108a2 100644 --- a/skills/ingest/scripts/log-append.sh +++ b/skills/ingest/scripts/log-append.sh @@ -35,7 +35,7 @@ esac [[ -f "$LOG_FILE" ]] || { echo "log-append: not found: $LOG_FILE" >&2; exit 1; } -run_id="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)" +run_id="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid 2>/dev/null || python3 -c 'import uuid; print(uuid.uuid4())')" today="$(date +%Y-%m-%d)" { diff --git a/skills/ingest/scripts/run-ingest.sh b/skills/ingest/scripts/run-ingest.sh index 032761c..4ffbd1f 100644 --- a/skills/ingest/scripts/run-ingest.sh +++ b/skills/ingest/scripts/run-ingest.sh @@ -46,6 +46,11 @@ all_paths=( "${created_paths[@]}" "${modified_paths[@]}" ) conflict_label="" +# NOTE: no rollback. Steps below mutate the working tree in order (index → log → commit). +# All are idempotent on re-run EXCEPT log-append (append-only). If a step fails midway, +# nothing is committed (open-pr is the only committer) — the operator re-runs, or inspects +# wiki/ if log-append already wrote a line. The manifest is removed only on full success. + # --- 1. index entries (created pages only), inserted in order --- while IFS=$'\t' read -r path summary maturity; do [[ -z "$path" ]] && continue @@ -119,4 +124,10 @@ jq -nc \ --arg detail "$pr_out" \ '{status:$status, slug:$slug, pr_url:$pr_url, lint_clean:$lint_clean, conflict:$conflict, detail:$detail}' -[[ $pr_rc -eq 0 ]] +# The manifest is a single file overwritten by each pi run (not accumulating), but on full +# success we remove it so a stale manifest can never be re-processed by mistake. +if [[ $pr_rc -eq 0 ]]; then + rm -f "$manifest" +else + exit 1 +fi diff --git a/skills/ingest/scripts/scoped-lint.sh b/skills/ingest/scripts/scoped-lint.sh index a064fd9..ded50a1 100644 --- a/skills/ingest/scripts/scoped-lint.sh +++ b/skills/ingest/scripts/scoped-lint.sh @@ -12,7 +12,12 @@ # ============================================================================= set -euo pipefail -: "${KG_LIB_DIR:?set KG_LIB_DIR to the framework lib/ dir (e.g. /opt/knowledge-genome-setup/lib)}" +: "${KG_LIB_DIR:?set KG_LIB_DIR to the framework lib/ dir (e.g. /opt/knowledge-genome-orchestrator/lib)}" + +# Fail clearly if the lib files are missing, rather than a raw `source: No such file`. +for _f in output.sh lint.sh; do + [[ -f "${KG_LIB_DIR}/${_f}" ]] || { echo "scoped-lint: missing ${KG_LIB_DIR}/${_f}" >&2; exit 1; } +done # shellcheck source=/dev/null source "${KG_LIB_DIR}/output.sh"