Skip to content

build(typecheck): cover tests/ and scripts/ in pnpm typecheck#81

Merged
benwu95 merged 2 commits into
mainfrom
benwu95/fix/typecheck-covers-tests
Jul 7, 2026
Merged

build(typecheck): cover tests/ and scripts/ in pnpm typecheck#81
benwu95 merged 2 commits into
mainfrom
benwu95/fix/typecheck-covers-tests

Conversation

@benwu95

@benwu95 benwu95 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

問題

pnpm typecheck(tsc --noEmit)用的 tsconfig.jsoninclude src/**excludetests,所以測試檔從不被型別檢查。測試檔的型別破損(如遷移型別後仍從舊模組 import type → TS2459)會逃過 typechecktest(esbuild 於 runtime strip type-only import)、lint 三閘,只能靠對抗式 review 抓到——這正是 PB-008 記錄的 gate 盲點(源於 PR #80 review 揪出的一個 latent TS2459)。

方案

  • 新增 tsconfig.typecheck.json:extends ./tsconfig.jsoncompilerOptions.noEmit: true + rootDir: "."(消除 TS6059),include src/tests/scripts,exclude node_modules/dist
  • pnpm typecheck 改指向它;build/prepare(tsc)維持用 base tsconfig.json,只 emit srcdist(套件產物不變,dist/ 不含 tests)。
  • 修掉啟用後浮現的 54 個型別錯誤(13 個測試檔 + scripts/counts/rewrite.ts):index guard、補齊 mock 物件、MCP resource-content union 收窄(抽 firstText helper);未弱化任何斷言src/ 未動。
  • 新增 tests/contract/typecheck-config.test.ts guard:釘住「typecheck config 涵蓋 tests」(section-scoped + 負向 exclude 斷言 + script 連動),mutation-verified——重新排除 tests 即轉紅。

效果

測試檔的型別破損現在pnpm typecheck / CI 直接 FAIL,不再只能靠對抗式 review。PB-008 的盲點就此關閉;ci.yml 已跑 pnpm run typecheck,故 CI 自動涵蓋,無需另加步驟。

測試 / 品質

  • pnpm typecheck 0 errors(含 tests+scripts)、pnpm test 2090 passed、pnpm lint clean、prospec check 11/11。
  • mutation-verified 雙向:測試檔注入型別錯誤 → typecheck FAIL;重新 exclude tests → guard test 轉紅。
  • 對抗式 review:0 critical / 0 major(獨立 reviewer 確認 54 個修正皆為誠實的型別調和、無弱化斷言)。

SDD

透過 Prospec SDD 完成:story → tasks(quick,plan-time 探測後由 standard 改判)→ implement → review(clean)→ verify(grade S)→ archive。內部 dev-tooling、無 product-spec 影響,故無 feature-spec graduation。獨立於已合併的 #80

benwu95 added 2 commits July 6, 2026 18:51
- add tsconfig.typecheck.json (extends base, noEmit, rootDir ".") including
  src+tests+scripts; repoint `typecheck` script to it — build/prepare tsc stays
  on the base config and emits src -> dist only (package unchanged)
- fix 54 type errors surfaced in test/script files (index guards, complete
  mock objects, MCP resource-content union narrowing via a firstText helper);
  no assertion weakened, src untouched
- add tests/contract/typecheck-config.test.ts guarding the coverage
  (mutation-verified: re-excluding tests turns it red)
- sync test counts 2079 -> 2083; note typecheck coverage in tests README
- closes the PB-008 gate blind spot: test-file type breaks now fail
  typecheck/CI instead of only being caught at adversarial review
- typecheck now covers tests/ + scripts/ (PB-008 gate closed); quick scale, no feature-spec graduation (dev-tooling, no product-spec impact)
- add _archived-history summary; refresh raw-scan.md
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Prospec Check

Prospec drift check (structural — deterministic, zero LLM)

  PASS  req-references
  PASS  file-paths
  PASS  import-direction
  PASS  knowledge-health
  SKIP  task-completion — source unavailable: .prospec/changes/ not found (not version-controlled)
  PASS  dangling-prefix
  PASS  feature-modules
  PASS  mcp-readme-counts
  SKIP  review-provenance — source unavailable: .prospec/changes/ not found (not version-controlled)
  SKIP  metadata-completeness — source unavailable: .prospec/changes/ not found (not version-controlled)
  PASS  knowledge-size

Knowledge coverage: 6/6 modules documented

Checked 8/11 checks: 0 fail, 0 warn, 3 skipped (not counted as pass)
Semantic consistency: not-checked (run /prospec-review)
Report written: prospec-report.json

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Test Coverage

Metric Coverage Covered / Total
lines 96.95% 3152 / 3251
statements 96.32% 3457 / 3589
functions 96.46% 573 / 594
branches 93.67% 1924 / 2054

@benwu95 benwu95 merged commit 7afac8e into main Jul 7, 2026
4 checks passed
@benwu95 benwu95 deleted the benwu95/fix/typecheck-covers-tests branch July 7, 2026 01:38
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