traPtitech / traPtitech/Checkin

DB を要求するテストが、DB が無いと素通りしたまま「通った」と報告される

Open
#58 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
0
Forks
0
Avg merge
3d 5h
Merged PRs (30d)
7

Description

症状

packages/api/src/auth/identity.test.tspackages/api/src/ledger/ledger.test.tspackages/api/src/payouts/execute.test.ts は、MariaDB に接続できたかどうかを let available という変数で持ち、接続できなかった場合は各テストが本体を実行せずに return する。vitest はこれを成功として数えるので、DB が無い環境では、これらのテストは中身を一度も実行しないまま「通った」と報告される

2026-09-18 に feat/merge-auth-collectiond8feaca で、DB を起動しない状態で測った結果は次のとおりである。

  • npx vitest run packages/api/src/auth/identity.test.ts → 16 件通過。うち 16 件が available の分岐に入る。
  • npx vitest run packages/api/src/ledger/ledger.test.ts → 9 件通過。うち 6 件が available の分岐に入る(残り 3 件は standardCoverage などの純粋関数のテストで、DB を要求しない)。
  • npx vitest run packages/api/src/payouts/execute.test.ts → 28 件通過。うち 28 件が available の分岐に入る。

素通りしていることは変異で確かめた。execute.test.ts にある唯一の expect(summary.unresolved).toBe(0)expect(summary.unresolved).toBe(424242) に書き換えて同じコマンドを実行したところ、28 件すべてが通った。

したがって DB が無い環境では 50 件(16 + 6 + 28)が実質的に検証されていない。

誰が何を誤るか

テストの結果を見た人が、DB を要求する経路も検証されたと読む。CI でも手元でも緑に見えるので、DB を要求する経路の回帰は、実際に DB を立てて動かすまで出ない。

取りうる手

  • test.skipIf を使い、DB が無いときは成功ではなくスキップとして表示する。件数が「28 passed」ではなく「28 skipped」になるので、検証されていないことが結果に出る。
  • CI で MariaDB を起こし、これらのテストを実際に実行する。
  • 両方(CI では実行し、手元では明示的にスキップと表示する)。

直さずに残した理由

どちらを採るかで CI の実行時間と手元の前提が変わるため、方針を決める判断が要る。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the available branches in packages/api/src/auth/identity.test.ts, packages/api/src/ledger/ledger.test.ts, and packages/api/src/payouts/execute.test.ts. Run the three listed Vitest commands with and without MariaDB, then compare the result with the chosen CI policy; done means database-dependent coverage is either executed in CI or visibly reported as skipped rather than passed.

Written by the indexing model from the issue text.

Assessment

Tech stack
mariadb, typescript
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.