Files
llm-intelligence/scripts/report_utils.sh
phamnazage-jpg a8999abcb0 feat(runtime): harden daily pipeline audit and verification
Tighten real-ingestion success rules, separate scheduled reports from historical rebuilds, and persist source-level runtime audit across daily pipeline runs.

Also add the Phase 5 CI workflow contract plus verification updates and supporting docs so the full uncommitted change set can be validated together.
2026-05-14 16:17:39 +08:00

154 lines
4.3 KiB
Bash

#!/usr/bin/env bash
report_date_value() {
printf '%s\n' "${1:-$(date +%Y-%m-%d)}"
}
report_output_dir() {
printf '%s\n' "reports/daily"
}
report_html_dir() {
printf '%s\n' "$(report_output_dir)/html"
}
report_markdown_path() {
local report_date
report_date="$(report_date_value "${1:-}")"
printf '%s\n' "$(report_output_dir)/daily_report_${report_date}.md"
}
report_html_path() {
local report_date
report_date="$(report_date_value "${1:-}")"
printf '%s\n' "$(report_html_dir)/daily_report_${report_date}.html"
}
report_archive_dir() {
local report_date
report_date="$(report_date_value "${1:-}")"
printf '%s\n' "$(report_output_dir)/${report_date:0:4}/${report_date:5:2}"
}
report_archive_markdown_path() {
local report_date
report_date="$(report_date_value "${1:-}")"
printf '%s\n' "$(report_archive_dir "$report_date")/daily_report_${report_date}.md"
}
report_archive_html_path() {
local report_date
report_date="$(report_date_value "${1:-}")"
printf '%s\n' "$(report_archive_dir "$report_date")/daily_report_${report_date}.html"
}
archive_report_artifacts() {
local report_date markdown_path html_path archive_dir
report_date="$(report_date_value "${1:-}")"
markdown_path="$(report_markdown_path "$report_date")"
html_path="$(report_html_path "$report_date")"
archive_dir="$(report_archive_dir "$report_date")"
mkdir -p "$archive_dir"
cp "$markdown_path" "$(report_archive_markdown_path "$report_date")"
cp "$html_path" "$(report_archive_html_path "$report_date")"
}
track_report_state() {
local db_url report_date status model_count summary_md output_path error_message run_kind trigger_source is_official_daily
db_url="$1"
report_date="$2"
status="$3"
model_count="${4:-}"
summary_md="${5:-}"
output_path="${6:-}"
error_message="${7:-}"
run_kind="${8:-manual}"
trigger_source="${9:-cli}"
is_official_daily="${10:-false}"
psql "$db_url" \
-v ON_ERROR_STOP=1 \
--set=report_date="$report_date" \
--set=status="$status" \
--set=model_count="$model_count" \
--set=summary_md="$summary_md" \
--set=output_path="$output_path" \
--set=error_message="$error_message" \
--set=run_kind="$run_kind" \
--set=trigger_source="$trigger_source" \
--set=is_official_daily="$is_official_daily" <<'SQL'
INSERT INTO daily_report (
report_date,
status,
model_count,
summary_md,
output_path,
error_message,
run_kind,
trigger_source,
is_official_daily,
created_at,
updated_at
)
VALUES (
:'report_date',
:'status',
NULLIF(:'model_count', '')::INTEGER,
NULLIF(:'summary_md', ''),
NULLIF(:'output_path', ''),
NULLIF(:'error_message', ''),
NULLIF(:'run_kind', ''),
NULLIF(:'trigger_source', ''),
NULLIF(:'is_official_daily', '')::BOOLEAN,
NOW(),
NOW()
)
ON CONFLICT (report_date) DO UPDATE SET
status = EXCLUDED.status,
model_count = COALESCE(EXCLUDED.model_count, daily_report.model_count),
summary_md = COALESCE(EXCLUDED.summary_md, daily_report.summary_md),
output_path = COALESCE(EXCLUDED.output_path, daily_report.output_path),
error_message = EXCLUDED.error_message,
run_kind = CASE
WHEN EXCLUDED.is_official_daily THEN EXCLUDED.run_kind
WHEN daily_report.trigger_source = 'legacy_backfill' THEN EXCLUDED.run_kind
ELSE daily_report.run_kind
END,
trigger_source = CASE
WHEN EXCLUDED.is_official_daily THEN EXCLUDED.trigger_source
WHEN daily_report.trigger_source = 'legacy_backfill' THEN EXCLUDED.trigger_source
ELSE daily_report.trigger_source
END,
is_official_daily = CASE
WHEN EXCLUDED.is_official_daily THEN TRUE
WHEN daily_report.trigger_source = 'legacy_backfill' THEN EXCLUDED.is_official_daily
ELSE daily_report.is_official_daily
END,
updated_at = NOW();
INSERT INTO report_runs (
source,
report_date,
status,
summary_md,
output_path,
error_message,
run_kind,
trigger_source,
is_official_daily
)
VALUES (
'pipeline',
:'report_date',
:'status',
NULLIF(:'summary_md', ''),
NULLIF(:'output_path', ''),
NULLIF(:'error_message', ''),
NULLIF(:'run_kind', ''),
NULLIF(:'trigger_source', ''),
NULLIF(:'is_official_daily', '')::BOOLEAN
);
SQL
}