Skip to content

[Test-Coverage] Phase 2 — 覆蓋缺口補齊 + 重構前置強化 #107

Description

@cheerc

背景

承接 #61(已關閉)的成果。Phase 1 完成 10 個 sub-issue、8 個 PR,從 283 tests 增加到 502 tests(+77%)

Phase 1 成果

目前覆蓋缺口

1. 程式碼.js Backend Wiring(607 行,coverage 0%)

現況:logic 已用 DI mock 在 backend.test.js 間接測試,但 v8 instrument 追蹤不到(測的是 tests/lib/ 提取副本)。
風險:GAS API 呼叫的 wiring(SpreadsheetApp, LockService, DriveApp)在重構時可能斷裂。
建議

2. .html Inline Script Wiring(~3555 行)

現況:已提取 pure logic 到 tests/lib/(1573 行, 98.7% coverage),但 .html 檔中的 DOM wiring / event binding / render 呼叫未測。
缺口明細

檔案 行數 已提取 logic 殘餘 wiring
JavaScript.html 1442 stateHelpers, utilityFunctions, dataCollectionHelpers, interactionHelpers global init, event listeners, API bridge
UI.js.html 787 uiHelpers DOM render, classList, innerHTML
Interaction.js.html 761 interactionHelpers drag-drop DOM events, click handlers
Modals.js.html 445 frontendUtils (partial) modal DOM lifecycle, form validation
History.js.html 120 historyHelpers undo/redo stack DOM binding
建議
  • 每個 .html 加 wiring contract test(類似 factory contracts — 驗證 exported 方法清單)
  • 對 DOM-heavy 部分加 happy-dom integration test(已有 tests/setup/dom.js

3. 完全未測試的檔案

檔案 行數 說明
Elements.js.html 109 DOM element factory functions
Api.js.html 24 GAS↔frontend API bridge
Config.js.html 31 設定常數
建議
  • Elements.js.html: 提取 element factory 的 data→props mapping
  • Api.js.html: wiring contract(方法存在性)
  • Config.js.html: snapshot test(常數值不意外變更)

4. PHP 覆蓋缺口

現況:33 tests covering functions.php(Phase 1 新增 filterScheduleByTags + jsonEncodeSafe)。
缺口

  • index.php routing logic($_GET 參數處理、schedule 載入)
  • generate_iframe.php access control 完整路徑($allowed_emails 驗證、POST 處理)
  • Error handling paths(missing config, invalid input)

5. 覆蓋率基礎設施

  • Coverage threshold ratchet: vitest.config.js 從 25% 提升到 55%(防止 regression)
  • CI coverage gate: 在 GitHub Actions validate job 加入 coverage check
  • Coverage trend 追蹤: badge 或 PR comment 顯示 coverage delta

6. 重構前 Smoke Test

  • E2E-level smoke test: deploy 後驗證基本功能(clasp push → 開啟試算表 → 載入頁面 → 基本操作)
  • PHP viewer smoke test: index.php 載入 → 回傳 200 + 正確 HTML 結構

#61 的關係

本 issue 是 #61 (Phase 1) 的直接後續。Phase 1 建立了 DI extraction + test pattern 和基礎設施;Phase 2 補齊殘餘缺口,為大規模 architecture 重構提供完整安全網。

優先順序建議

  1. P0(重構前必做):Coverage threshold ratchet ([Security] Missing permission check in saveData backend API #5) + 程式碼.js wiring contract ([onboarding] classroombooking 接手 — 專案探索 + 建立開發 baseline #1)
  2. P1(重構時同步做):.html wiring contracts ([infra] 開發流程對齊 talented-easyorder — 建立 CI / dispatch book / 測試鏈 / 開發基礎設施 #2) — 重構本身就會消除這些 inline scripts
  3. P2(重構後做):PHP 完整路徑 ([Security] Stored XSS via unescaped innerHTML interpolation #4) + E2E smoke test ([Code-Quality] Draft filtering boolean bug causes data leak in PHP viewer #6)
  4. P3(nice-to-have):Elements/Api/Config 小檔 ([Security] Hardcoded AES encryption key in PHP scripts #3) + CI coverage gate ([Security] Missing permission check in saveData backend API #5)

Retro Findings(from Phase 1)

供後續 session 參考:

  1. Fresh worktree 需要 composer install(PHPUnit)
  2. gh pr diff 截斷 >500 行 → 用 gh api pulls/<N>/files
  3. DI extraction pattern 已成熟,可作 template
  4. stateHelpers.fixtures.js 應列入 Required Reads(factory helper pattern)
  5. Dispatch 帶 source line numbers 可加速 spike

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions