Skip to content

fix(rates): 歷史匯率快照完整性守門與 governance 紅燈修復#536

Merged
s123104 merged 5 commits into
mainfrom
hotfix/rates-history-integrity
Jul 4, 2026
Merged

fix(rates): 歷史匯率快照完整性守門與 governance 紅燈修復#536
s123104 merged 5 commits into
mainfrom
hotfix/rates-history-integrity

Conversation

@s123104

@s123104 s123104 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

主支健康掃描發現兩個生產級問題,本 PR 為 hotfix + 防再發,並擴充為匯率資料管線整體強化(5 項):

S1 — 30 天趨勢圖 4 天壞資料(生產資料損壞,已同步止血)

台銀 06/29 bot-challenge outage 期間,update-historical-rates.yml 無資料新鮮度檢查,將 stale 的 latest.json 連續 4 天(06/30–07/03)複製為 history 快照——全部是 06/29 收盤價複本(USD 恆 32.16),用戶趨勢圖顯示假平線。實際牌價 06/30=32.12、07/01=32.16、07/02=32.19、07/03=32.215。

已完成的資料止血(data 分支,不在本 diff)

  • 以真瀏覽器通過 challenge 取得台銀官方歷史 CSV(/xrt/flcsv/0/<date>),回補 4 天真實匯率(17 幣別 + 完整 details)
  • 補建 07-04 快照(當日 cron 掉單)
  • 重生 history-30d.json aggregate 並 purge jsDelivr CDN

本 PR 防再發(管線強化 5 項)

  1. 歷史快照守門改用上游管線存活訊號(取代初版 72h 資料齡檢查):fetch 腳本只在 rates 變化時重寫 latest.json,週末/春節休市時 timestamp 凍結多天,資料齡守門會在春節 6-9 天連假誤報並拒寫正確快照。改查 update-latest-rates.yml 最近 12h runs:有 success 照常寫;零 success(持續 outage)拒寫;查詢失敗/無 run 降級 warning 照常寫(告警責任在 update-latest 的 6h staleness gate)。保留 01:30 UTC 備援 cron(冪等)。
  2. MoneyBox staleness gate(30h)update-moneybox-rates.yml 補資料齡守門(比照台銀模式);健康狀態下每日首爾日期 rollover 至少寫一次(timestamp 最舊 ~24h),30h 容忍時差與延遲,持續停更紅燈曝光。
  3. 抓取腳本寫檔前數值熔斷:台銀(幣別數 <15 拒寫、任一幣別突變 >15% 拒寫並列出異常幣別);MoneyBox(幣別數 <5、TWD.sell 超出 30-70 KRW/TWD 合理區間、TWD.sell 突變 >15% 均拒寫)。閾值 env RATE_MUTATION_THRESHOLD 可覆寫;純函式可測,補 root 單元測試。
  4. update-seo-rate-examples.yml 啟用 auto-merge:建立 PR 後 gh pr merge --auto --squash 掛上 GitHub auto-merge;合併仍由 branch protection + required checks 把關。同步 CLAUDE.md / AGENTS.md 政策。
  5. data 寫入 workflow push trigger 限 mainupdate-latest-rates.ymlupdate-historical-rates.yml 比照 moneybox 加 branches: [main],data branch 寫入權限只允許已審查的 main。

S2 — RateWise Production Governance 紅燈

Worker v5.4 起 sw.js 固定 Cache-Control: no-store(更強語義),cloudflare-cache.spec.ts 仍斷言必須含 no-cache 導致每日排程紅燈。斷言對齊實際語義:必含 no-store,並加驗禁止 max-age/immutable

Test plan

  • YAML 解析通過(4 個 workflow);資料齡計算於 data checkout 實測
  • backfill 後 raw/CDN 驗證各日 USD 值正確、aggregate 30 天窗口走勢恢復
  • sw.js 斷言與正式站實際標頭(no-store)比對
  • 熔斷單元測試(root vitest 19 案)+ CSV 檔案模式端到端驗證(首次寫入 / 突變拒寫 / env 放行)
  • node --check 兩支抓取腳本;build-scripts SSOT 測試 48 案通過
  • pre-push(typecheck + tests + build:ratewise)通過
  • CI 全綠後合併;下輪 governance 排程應轉綠

Made with Cursor

- update-historical-rates 新增 72h 資料齡守門:latest.json 過期時拒絕寫入壞快照並紅燈曝光
- 新增 01:30 UTC 備援 cron 防 GitHub scheduled run 掉單(2026-07-04 實例)
- cloudflare-cache.spec sw.js 斷言對齊 Worker v5.4 純 no-store 語義,加驗禁止 max-age/immutable
- data 分支已回補 2026-06-30..07-03 台銀真實歷史匯率並重生 30 天 aggregate(趨勢圖假平線已修正)

測試:YAML 解析通過、age 計算實測 4h、E2E 斷言比對正式站 no-store 標頭

Co-authored-by: Cursor <cursoragent@cursor.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

haotool and others added 3 commits July 4, 2026 15:09
- 歷史快照守門改用上游管線存活訊號:查 update-latest-rates.yml 最近 12 小時 runs,
  零 success 才拒寫快照;取代 72h 資料齡檢查(休市 timestamp 凍結會使春節連假誤報)
- 查詢失敗或窗口無 run 時降級為 warning 照常寫,告警責任歸 update-latest 的 6h gate
- update-moneybox-rates.yml 補 30h staleness gate:健康狀態每日 rollover 至少寫一次
  (最舊 ~24h),30h 容忍時差與延遲;持續停更紅燈曝光
- update-latest / update-historical 的 push trigger 限定 main,
  比照 moneybox:data branch 寫入權限只允許已審查的 main
- 更新 changeset 與 002 紀錄涵蓋本批管線強化

測試:python yaml.safe_load 驗證 4 個 workflow;pnpm test:root 19 案通過

Co-authored-by: Cursor <cursoragent@cursor.com>
- 台銀腳本:幣別數 <15 拒寫(CURRENCY_MAP 19 幣、正常 17 幣有現金賣出);
  任一共同幣別相對舊檔突變 >15% 拋 AbortError 並列出異常幣別與新舊值
- MoneyBox 腳本:幣別數 <5 拒寫;TWD.sell 超出 30-70 KRW/TWD 合理區間拒寫;
  TWD.sell 相對舊檔突變 >15% 拒寫
- 閾值以常數定義並支援 env RATE_MUTATION_THRESHOLD 覆寫(預設 0.15)
- 熔斷為可 export 純函式,網路模式與 CSV_INPUT_FILE 檔案模式統一在 main() 寫檔前生效;
  舊檔不存在或損毀時跳過突變檢查(首次寫入)
- 補單元測試(正常通過、幣別數不足、區間越界、突變超閾值、env 覆寫)並納入 test:root

測試:pnpm test:root 19 案通過;CSV 檔案模式端到端驗證首次寫入/突變拒寫/env 放行

Co-authored-by: Cursor <cursoragent@cursor.com>
- update-seo-rate-examples.yml 建立/更新 PR 後以 gh pr merge --auto --squash 掛上
  auto-merge;合併仍由 branch protection 與 required checks 把關,checks 未過不會合併
- 同步 CLAUDE.md 與 AGENTS.md 政策:允許並要求 workflow 掛 auto-merge,
  禁止的是繞過 checks 的直接合併
- build-scripts SSOT 測試補 auto-merge 步驟斷言

測試:yaml.safe_load 通過;build-scripts.test.ts 48 案通過

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

- liveness 守門補跨 workflow 耦合防護註解:訊號依賴 update-latest 6h staleness gate
  讓持續 outage 轉紅;該 gate 註解同步標明不可改 continue-on-error
- moneybox 移除宣稱一切正常的 API-failure summary step,fetch 失敗 summary 統一由
  staleness gate 輸出(transient 中性描述 / persistent 紅燈),保留 API URL 與 retry 資訊
- seo auto-merge 掛載改 continue-on-error + 3 次重試(間隔 5 秒),失敗以
  steps.enable-automerge.outcome 判定並發 warning + summary 附 PR 連結,不阻斷排程

測試:4 個 workflow 過 yaml.safe_load;build-scripts 48 案與 test:root 19 案通過

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@s123104 s123104 merged commit f3e389f into main Jul 4, 2026
17 checks passed
@s123104 s123104 deleted the hotfix/rates-history-integrity branch July 4, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant