Skip to content

実装: hooks-stdout-policy.test.ts の AC7 タイムアウト失敗を修正する #1350

Closed
1 of 1 issue completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "pnpm test フルスイート実行時にのみ決定的にタイムアウト失敗する該当テストを修正し、baseline regression gate を安定させる"
change_kind: code

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: N/A(単独改善のため親 Issue なし)
  • Desired Destination: N/A

Current Validated Scope

  • tests/hooks/hooks-stdout-policy.test.ts の test-codex-single-composite.mjs runs within pnpm test > spawns test-codex-single-composite.mjs and all assertions pass テストのタイムアウト設定を修正する

Remaining Parent Gaps

なし

Outcome

tests/hooks/hooks-stdout-policy.test.ts の該当テスト(spawns test-codex-single-composite.mjs and all assertions pass)が pnpm test フルスイート実行でも決定的に PASS する状態。具体的には、当該 it() に、内側の spawnSync timeout(30000ms)より大きい Vitest test-level timeout(35_000 以上)を明示指定したコミットが存在し、pnpm test を連続 2 回実行して両方 PASS することで完了とする。

In Scope

  • tests/hooks/hooks-stdout-policy.test.ts の該当 it() に、内側の spawnSync timeout: 30000 より大きい Vitest test-level timeout 引数(35_000 以上)を追加する

Out of Scope

  • test-codex-single-composite.mjs 自体のロジック変更
  • 他のテストファイルの timeout 調整
  • Vitest のグローバル testTimeout 設定変更

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue の変更は既存テストの Vitest test-level timeout 引数追加のみであり、pnpm test(静的ユニットテスト実行)で完結する。新規のプロセス起動・通信・I/O を追加するものではなく、既存の spawnSync ベーステストの外側 timeout 値を調整するのみ。

Acceptance Criteria

  • AC1: tests/hooks/hooks-stdout-policy.test.ts の該当 it()(spawns test-codex-single-composite.mjs and all assertions pass)に、内側の spawnSync timeout: 30000 より大きい Vitest test-level timeout(}, 35_000))が新規に追加されている
  • AC2: pnpm test をフルスイートで連続 2 回実行し、両方とも tests/hooks/hooks-stdout-policy.test.ts の全テストが PASS する

Verification Commands

# baseline-expect: fail
# AC1
$ rg -n "}, 35_000\)" tests/hooks/hooks-stdout-policy.test.ts

# AC2
$ pnpm test
$ pnpm test

Allowed Paths

  • tests/hooks/hooks-stdout-policy.test.ts

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

なし

Scope Delta(任意)

N/A

Notes for Reviewer

  • 本 Issue は Issue 実装: Latitude telemetry distribution / argv / remote cleanup gate を real pilot 前提で強化する #1261 の issue-contract-review preflight 中に発見された。pnpm test フルスイート実行時のみ Error: Test timed out in 5000ms で当該テストが決定的に失敗するが、単体実行(pnpm vitest run tests/hooks/hooks-stdout-policy.test.ts)では PASS することを確認済み。Vitest のデフォルト test timeout(5000ms)に対し、spawnSync の内部 timeout: 30000 オプションのみが設定されており、外側の Vitest test-level timeout が明示されていないことが原因と推測される。
  • 実装: Latitude telemetry distribution / argv / remote cleanup gate を real pilot 前提で強化する #1261 は本 Issue とは独立に、人間承認による manual override コメントで contract review blocker を解消し進行中(override comment)。
  • OWNER anchor comment(comment)の敵対的レビュー指摘を反映した:
    • P0: 当初案の }, 30000) ぴったり指定は内側 spawnSync timeout: 30000 と同値で race-prone(child timeout が診断情報を返す前に Vitest 側が test case を timeout させる可能性)。AC1 / VC / In Scope / Outcome を 35_000 以上へ修正した。
    • P1: Outcome(連続2回実行)と AC2 / Verification Commands(1回のみ)の不整合を解消し、AC2 と VC を連続2回実行に統一した。
    • P1(対応せず・出典どおり Out of Scope 継続): 同ファイル内の他テストの spawnSync timeout hygiene は本 Issue の Allowed Paths / In Scope 対象外のため据え置き。必要なら別 Issue で扱う。
    • 追加提案(テスト構造をリファクタリングして pnpm test 内の nested standalone script 実行自体を無くす高速化 Issue 案)は、本 Issue の Approve 後に follow-up Issue として起票を検討する候補であり、本 Issue のスコープには含めない。

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    you asked

    message time: 2026-07-06 19:24:22

    #1350
    内容について関連Issue、PR、リポジトリ資産、コメントを参照した上で敵対的レビューして。
    取り扱う技術や配布物の実装をWEB検索し高品質化してほしい。


    chatgpt response

    Issue #1350を起点に、関連Issue/PR・差分・コメント・該当ファイルを確認したうえで、実装上の弱点と改善案を切り分けます。技術要素は一次情報・公式実装を中心に検索して、レビュー根拠を補強します。

    #1350の本文では、失敗点は「外側のVitest test-level timeoutが5秒のまま、内側のspawnSync timeoutだけ30秒」という構図です。次に、発見元の#1261と関連PR/ファイルを見て、単なるタイムアウト延長で妥当かを確認します。

    該当テストは既に spawnSync(... timeout: 30000) を持っていますが、Vitest の it() 側に timeout 引数がありません。公式仕様上、この2つは別物なので、Issueの仮説は概ね成立します。

    判定

    REQUEST_CHANGES寄り。Issue #1350 の根本仮説は正しいが、AC1 の }, 30000) 固定は品質上よくないです。
    実装前に、外側の Vitest timeout を 内側の spawnSync timeout: 30000 より大きくする契約へ直すべきです。

    #1350 は、tests/hooks/hooks-stdout-policy.test.ts の AC7 が pnpm test フルスイート時だけ Vitest の既定 5秒 timeout で落ちる、という単独改善 Issue です。本文では spawnSync の内部 timeout 30秒以上に合わせて it() 側へ test-level timeout を追加する、とされています。

    根本原因の確認

    現行の AC7 テストは、it('spawns test-codex-single-composite.mjs and all assertions pass', () => { ... }) の形で、Vitest 側の timeout 引数を持っていません。一方、内部では spawnSync(process.execPath, [scriptPath], { timeout: 30000 }) を使っています。

    Vitest 公式仕様では、test / it は第3引数に timeout milliseconds を取れます。また、既定 timeout は 5秒です。(vitest.dev)
    package.json の pnpm test は vitest run --exclude ... で、ここには timeout 引き上げがありません。 Vite config にも test timeout 設定は見当たりません。

    したがって、内側の child process は最大30秒待つ設計なのに、外側の Vitest test case は5秒で殺されるという #1350 の診断は妥当です。

    P0: }, 30000) ぴったり指定は race-prone

    #1350 の AC1 は tests/hooks/hooks-stdout-policy.test.ts に }, 30000) を追加することを要求していますが、これは内側の spawnSync timeout: 30000 と同値です。ここが弱いです。

    Node.js の spawnSync() は同期的に child process を待ち、timeout 発生時も kill signal 後に child が完全に終了するまで戻らない場合があります。(Node.js) そのため外側の Vitest timeout を内側と同じ30秒にすると、child timeout が先に診断情報を返す前に Vitest 側が test case を timeout させる可能性があります。

    推奨は 35_000 か 45_000。
    最小修正なら以下です。

    -  it('spawns test-codex-single-composite.mjs and all assertions pass', () => {
    +  it('spawns test-codex-single-composite.mjs and all assertions pass', () => {
         const scriptPath = resolve(repoRoot, 'tests', 'hooks', 'test-codex-single-composite.mjs')
         if (!existsSync(scriptPath)) {
           throw new Error('test-codex-single-composite.mjs not found — AC7 blocked')
         }
         const result = spawnSync(process.execPath, [scriptPath], {
           encoding: 'utf8',
           timeout: 30000,
           cwd: repoRoot,
         })
         expect(
           result.status,
           `test-codex-single-composite.mjs exited with code ${result.status}\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
         ).toBe(0)
    -  })
    +  }, 35_000)

    この場合、Issue の AC1 は次のように直すのが安全です。

    - [ ] AC1: `tests/hooks/hooks-stdout-policy.test.ts` の AC7 `it()` に、内側の `spawnSync timeout: 30000` より大きい Vitest test-level timeout(例: `35_000` 以上)が追加されている

    P1: Outcome と AC2 / Verification Commands がズレている

    #1350 の Outcome は pnpm test を連続2回実行して両方 PASS としていますが、AC2 と Verification Commands は pnpm test 1回だけに見えます。

    ここは、タイムアウト系の回帰 gate としては2回連続を明記したほうがよいです。

    pnpm test
    pnpm test

    またはログ上で区別しやすいように、

    for i in 1 2; do
      echo "pnpm test run $i"
      pnpm test
    done

    P1: 同ファイル内に類似リスクが残る

    hooks-stdout-policy.test.ts には他にも spawnSync の timeout が 10〜15秒のテストがあります。今回の #1350 は AC7 だけを対象にしているため、観測済み失敗だけを直すなら妥当ですが、同種の latent failure は残ります。

    ただし #1350 の Allowed Paths / In Scope は AC7 の該当 it() に限定されているため、今回のPRでは広げないほうがよいです。必要なら別 Issue で「hooks-stdout-policy.test.ts の spawnSync timeout hygiene」を扱うべきです。

    P2: test-codex-single-composite.mjs 側の実行時間上限も意識する

    AC7 が呼び出す test-codex-single-composite.mjs は、内部でさらに spawnSync(... timeout: 10000) を使います。
    このスクリプトは複数イベントを順に検証しているため、異常時の最悪ケースでは外側30秒を超える余地があります。今回は正常系がフルスイート負荷下で5秒を超える問題なので、外側 Vitest timeout を35秒にするだけで十分ですが、失敗診断を重視するなら将来的に script 側を Vitest test case に分解する余地があります。

    推奨する実装方針

    Issue契約を直せるなら:

    1. AC1 を }, 30000) 固定から「inner timeout より大きい Vitest timeout」へ変更する。
    2. 実装は }, 35_000)。
    3. spawnSync timeout: 30000 は変更しない。
    4. test-codex-single-composite.mjs は変更しない。
    5. pnpm test を2回連続実行してログに残す。

    Issue契約を直さない場合:

    }, 30000) を追加すれば #1350 のACは満たします。ただし、これは child timeout と outer timeout が同値になるため、診断情報が潰れる timeout race を残します。品質優先なら避けるべきです。

    実装エージェント向けプロンプト

    Issue #1350 を実装する。ただし、AC1 の `}, 30000)` ぴったり指定は inner `spawnSync({ timeout: 30000 })` と同値で race-prone なので、Issue本文を確認し、可能なら契約を「Vitest test-level timeout は inner spawnSync timeout より大きい値」に修正したうえで実装する。
    
    対象:
    - tests/hooks/hooks-stdout-policy.test.ts の AC7:
      `it('spawns test-codex-single-composite.mjs and all assertions pass', () => { ... })`
    
    実装:
    - `spawnSync(..., { timeout: 30000 })` は変更しない。
    - 該当 `it()` の第3引数に `35_000` を追加する。
    - `test-codex-single-composite.mjs` は変更しない。
    - 他のテストファイル、Vitest global config、package.json は変更しない。
    
    期待diff:
    - `it(..., () => { ... })`
    + `it(..., () => { ... }, 35_000)`
    
    検証:
    - `pnpm test` を2回連続で実行する。
    - 両方で `tests/hooks/hooks-stdout-policy.test.ts` が PASS することをPR本文に記録する。
    - 変更ファイルが `tests/hooks/hooks-stdout-policy.test.ts` のみであることを確認する。
    
    注意:
    - もし Issue #1350 のAC1が厳密に `}, 30000)` を要求しており、契約更新が許可されない場合は、人間レビューへエスカレーションする。inner timeout と outer timeout を同値にする実装は非推奨。
    

    最終判断としては、#1350 は必要なIssueだが、現状のACは「通すための最小修正」に寄りすぎています。35_000 以上へ契約修正してから実装するのが高品質です。


    you asked

    message time: 2026-07-06 19:31:39

    そもそもテストを高速化することはできない?できるならIssue草案を出して。


    chatgpt response

    高速化は可能です。まず AC7 が二重テスト構造になっている点を主因として切り分け、Vitest/Node の公式仕様を確認してから Issue 草案に落とします。

    できます。#1350 の timeout 延長は「落ちないようにする」対症療法で、本筋は pnpm test 内で standalone テストスクリプトをさらに spawnSync している二重実行をやめることです。

    現状は hooks-stdout-policy.test.ts から test-codex-single-composite.mjs を spawnSync(process.execPath, [scriptPath]) で丸ごと実行しています。 その standalone script 側もさらに composite hook を複数回 spawnSync します。 一方で、同じ hooks-stdout-policy.test.ts 内にも composite hook 直接実行のテスト helper と AC3 系テストが既にあります。

    test.concurrent で逃がす案は弱いです。Vitest は concurrent test を並列化できますが、同期 test は順次実行されると明記されています。現状は spawnSync なので、まず同期 child process の二重化を削るべきです。(Vitest)

    以下、Issue 草案です。

    **Document Title: **

    実装: hooks-stdout-policy AC7 の nested standalone smoke を Vitest 直実行へ統合して高速化する

    Machine-Readable Contract

    contract_schema_version: v1
    issue_kind: implementation
    parent_issue: "#1350"
    goal_ref: "hooks-stdout-policy.test.ts の AC7 タイムアウト問題を timeout 延長だけで隠さず、pnpm test 内の nested standalone script 実行を削減して deterministic かつ高速な baseline regression gate にする"
    change_kind: test

    Parent Issue

    Related Context

    Current Validated Scope

    tests/hooks/hooks-stdout-policy.test.ts の AC7 を、standalone script 丸ごと実行から Vitest 直実行の assertion へ統合する。

    Outcome

    pnpm test フルスイート内で tests/hooks/test-codex-single-composite.mjs を nested child process として実行しなくても、同等の Codex composite hook stdout policy が Vitest 上で直接検証され、AC7 timeout 問題が構造的に解消されている状態。

    In Scope

    • tests/hooks/hooks-stdout-policy.test.ts の AC7 から spawnSync(process.execPath, [scriptPath]) による standalone script 丸ごと実行を削除する。
    • test-codex-single-composite.mjs が検証している主要ケースを、hooks-stdout-policy.test.ts 内の既存 runCompositeHook() helper ベースの直接 Vitest assertions に統合する。
    • 少なくとも以下のケースを Vitest 直実行で保持する。
      • Stop allow path: stdout が valid JSON で continue boolean を持つ
      • SubagentStop allow path: stdout が valid JSON で continue boolean を持つ
      • Stop malformed payload: {"continue": true}
      • SubagentStop malformed payload: {"continue": true}
      • PreToolUse allow path: stdout empty
      • PreToolUse block path: event-specific JSON / hookSpecificOutput.permissionDecision === "deny"
      • Stop security verifier failure: {"continue": false, "stopReason": string}
    • tests/hooks/test-codex-single-composite.mjs は standalone manual smoke として残す。ただし pnpm test の通常パスからは丸ごと実行しない。
    • tests/hooks/hooks-stdout-policy.test.ts に、standalone script の存在確認は残す。

    Out of Scope

    • .codex/hooks/session-recording-composite.mjs の仕様変更
    • hook stdout policy の意味論変更
    • test-codex-single-composite.mjs の削除
    • Vitest global testTimeout 設定変更
    • package.json の pnpm test コマンド変更
    • 他テストファイルの timeout 一括調整
    • e2e / live Codex runtime trust 検証

    Acceptance Criteria

    • AC1: tests/hooks/hooks-stdout-policy.test.ts に spawnSync(process.execPath, [scriptPath] または test-codex-single-composite.mjs を丸ごと child process 実行する AC7 テストが存在しない。
    • AC2: tests/hooks/hooks-stdout-policy.test.ts に、Stop / SubagentStop / PreToolUse の stdout policy を direct Vitest assertion で検証するテストが存在する。
    • AC3: tests/hooks/test-codex-single-composite.mjs の file existence check は残っている。
    • AC4: standalone script は manual smoke として node tests/hooks/test-codex-single-composite.mjs で PASS する。
    • AC5: pnpm vitest run tests/hooks/hooks-stdout-policy.test.ts が PASS する。
    • AC6: pnpm test が PASS する。
    • AC7: pnpm test の実行ログまたは PR 本文に、変更前後の focused test wall time を best-effort evidence として記録する。ただし時間閾値そのものは CI 判定条件にしない。
    • AC8: 変更ファイルは Allowed Paths 内に収まる。

    Verification Commands

    # AC1: nested standalone execution が消えていること
    ! rg -n "spawnSync\\(process\\.execPath, \$$scriptPath\$$" tests/hooks/hooks-stdout-policy.test.ts
    
    # AC2: direct assertions が存在すること
    rg -n "SubagentStop|PreToolUse|permissionDecision|runCompositeHook" tests/hooks/hooks-stdout-policy.test.ts
    
    # AC3
    test -f tests/hooks/test-codex-single-composite.mjs
    
    # AC4: standalone manual smoke は維持
    node tests/hooks/test-codex-single-composite.mjs
    
    # AC5
    pnpm vitest run tests/hooks/hooks-stdout-policy.test.ts
    
    # AC6
    pnpm test
    
    # AC7: best-effort timing evidence。閾値 gate にはしない。
    START=$(date +%s%3N); pnpm vitest run tests/hooks/hooks-stdout-policy.test.ts; END=$(date +%s%3N); echo "focused_hooks_stdout_policy_ms=$((END-START))"

    Allowed Paths

    • tests/hooks/hooks-stdout-policy.test.ts
    • tests/hooks/test-codex-single-composite.mjs

    必要になった場合のみ、以下を追加候補とする。ただし追加前に scope delta として明示する。

    • tests/hooks/codex-composite-policy-cases.mjs

    Stop Conditions

    • .codex/hooks/session-recording-composite.mjs の本体変更が必要と判明した場合
    • hook stdout policy の仕様変更が必要と判明した場合
    • package.json の pnpm test 変更が必要と判明した場合
    • standalone script を削除しないと成立しない場合
    • test-codex-single-composite.mjs と Vitest direct assertions の期待値が衝突し、どちらが正本か人間判断が必要になった場合
    • runtime-active Codex trust 検証へスコープが波及した場合
    • CI 実行時間の絶対値 threshold を gate にしたくなった場合

    Required Skills

    • Vitest test hygiene
    • Node.js child_process / spawnSync timeout behavior
    • Hook stdout policy regression testing

    Notes for Reviewer

    この Issue の狙いは、#1350 のように外側 timeout を伸ばすことではなく、pnpm test の通常パスから nested standalone script execution を外して、同等の検証を Vitest direct assertions に統合すること。

    test.concurrent 化は主解ではない。現状の該当テストは spawnSync ベースの同期 test であり、同期 test を concurrent 指定しても構造的な child process 重複は解消しない。

    時間短縮の合否は wall time の絶対値では判定しない。CI 環境差が大きいため、AC は「nested standalone execution の除去」と「coverage preservation」を machine-readable に確認する。

    結論として、#1350 は timeout 修正、こちらはテスト構造改善です。優先するなら、この高速化Issueを先に実装し、#1350 は「まだ必要なら test-level timeout を safety margin として追加」に縮小するのがよいです。

  2. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-06T11:35:37Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1350
      body_sha256: "sha256:0dde17ad952cc6dca10b7b939807399cfa9df44adebd74fd77717095f2bade78"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  3. added
    phase/implementation
    enhancement
    agent/implementer
    triage-required
    on Jul 6, 2026
  4. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: https://github.com/squne121/loop-protocol/issues/1350#issuecomment-4892314022
        generated_at: '2026-07-06T11:12:05Z'
        body_sha256: sha256:0dde17ad952cc6dca10b7b939807399cfa9df44adebd74fd77717095f2bade78
      metadata:
        title_prefix_ready: true
        phase_label_ready: true
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: '2026-07-06T11:20:00Z'
  5. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    Follow-up Materialization

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues:
        - request_dedupe_key: "follow-up:squne121/loop-protocol:issues/1350#issuecomment-4891777985:speedup-draft"
          status: created
          issue:
            number: 1354
            url: "https://github.com/squne121/loop-protocol/issues/1354"
          reason: null
      note_only_observations: []
  6. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions