Skip to content

Overhaul E2E tests: dynamic dates and strict error handling - #11

Merged
utahta merged 2 commits into
mainfrom
e2e-cleanup
Jul 19, 2026
Merged

utahta merged 2 commits into
mainfrom
e2e-cleanup

Conversation

@utahta

@utahta utahta commented Jul 19, 2026

Copy link
Copy Markdown
Owner

概要

E2Eテストの2つの構造的問題を解消する: 固定テスト日付(20250613)による将来の一斉破損と、エラー握りつぶしによる「成功パスを一度も検証していないテスト」の混在。

背景

indices のテストが仕様上必ず400になるリクエストを t.Logf + return で握りつぶしており、一度も成功パスを通っていなかったことが PR #9 で発覚した。同じパターンが他に11箇所存在し、また固定日付はプランのデータ保持期間を外れた時点で日付ベースの全テストを壊す。

変更内容

テスト日付の動的解決

  • TestMain で取引カレンダーAPIから直近の営業日一覧を取得し、テスト基準日を動的に決定(取得失敗時は土日を除く平日にフォールバック)
  • ラグは JQUANTS_TEST_LAG_DAYS で明示指定可能(不正値はpanicで即失敗)。未指定時は株価APIへの軽量プローブでデータ遅延プラン(Free=12週遅延)を自動検出し、13週ラグに切り替える。プローブのエラーは遅延と誤診せず即失敗させる
  • 固定日付だった日付範囲(daily_margin_interest の 20250601)も基準日からの相対指定に変更

エラーハンドリングの厳格化(11箇所)

  • 実APIの契約を確認: 有効なクエリでデータがない場合は200+空配列が返り、4xxは常に本物の問題(不正パラメータ等)。したがって予期しないエラーはすべて t.Fatalf に変更し、Skipはサブスクリプション制限と正当な空データのみに限定
  • listed の InvalidCode テストは異常系として正当なため維持

イベント駆動データセットの検証強化

  • statements / fs_details: 開示は毎営業日あるとは限らないため、findPopulatedTestDate で直近5営業日から開示のある日を解決。実行日依存のSkipを排除
  • investor-types(trades_spec): from/toが公表日でフィルタされることを実APIで確認し、単日クエリは直近30日から特定した最新公表日を対象に変更。データがあることが確定しているため空ならFatal
  • 調査過程で発覚した死にテストを修正: セクション "All" は無効値で永遠に0件→Skipだった(有効な TokyoNagoya に変更し、523件を実際に検証)

テスト

  • 実APIでE2Eスイート全体(全18エンドポイント)がパス
  • ラグの明示指定・不正値・自動検出の各パスを動作確認

utahta added 2 commits July 19, 2026 09:42
The suite relied on a hardcoded trading day (20250613), which would
break for every date-based test once it left a plan's data retention
window. TestMain now resolves recent trading days via the trading
calendar API (weekday fallback if unavailable) with a configurable
lag (JQUANTS_TEST_LAG_DAYS, rejected loudly when invalid).

When no lag is specified, a one-shot probe against the daily quotes
API detects delayed plans (valid queries return empty data, never an
error) and falls back to a 13-week lag so Free-plan runs still
exercise the endpoints; probe errors fail the run instead of being
misdiagnosed as a plan limitation.
Eleven subtests logged API errors and returned silently, so they
never verified their success paths (the pattern that hid the invalid
indices query fixed earlier). Unexpected errors now fail the test;
skips remain only for subscription limits and legitimately empty
datasets, since the API returns 200 with empty data rather than 4xx
when a valid query has no data.

Event-driven datasets no longer depend on the run date: statements
and fs_details resolve a recent disclosure day via
findPopulatedTestDate, and the investor-types single-day query targets
the latest publication date found in a 30-day range (from/to filter
on publication date), failing instead of skipping when that date
returns nothing. This surfaced two dead spots: section "All" is not
a valid investor-types section (now TokyoNagoya) and the single-day
query never matched period dates.

Also derive the daily margin interest range start from the resolved
test date instead of a fixed 20250601.
@utahta
utahta merged commit 55609ee into main Jul 19, 2026
4 checks passed
@utahta
utahta deleted the e2e-cleanup branch July 19, 2026 00:46
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