test: preload API type key と実装 key の同期を vitest で lock (#209 ①)#280
Merged
Conversation
- electron/preload/api.ts の Api type key と electron/preload/index.ts の api Object.freeze() 内 method key を正規表現で level 1 indent ベースに 抽出し、count と順序の完全一致を検証する。 - 新規 preload API 追加時に両ファイルの更新漏れがあると本テストが fail する ため、2 ファイル hardcode 構造の drift risk を CI で lock できる。 - 追加依存なし(ts-morph や TypeScript Compiler API を使わず読み取り + 正規 表現のみで完結)。 - #209 項目 ①「preload 53 メソッド hardcode の 2 ファイル同期 lint rule」の 実装(現在は 55 メソッド)。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- extractApiTypeKeys / extractApiObjectKeys の 2 wrapper が marker string のみ異なる near-identical だったため extractKeys(source, open, close) に unify。呼び出し場所で marker 文字列を渡す形にして DRY 化。 - `type key count equals impl key count` テストは `expect(implKeys).toEqual(typeKeys)` で必ず cover されるため redundant として削除(vitest の diff で count / order 両方のずれが表示される)。 - non-empty guard test は将来 extract 経路が silent empty 化した場合の 防衛として保持。imperative for-of loop は agent 提案 code の typo と RegExpMatchArray の narrowing 事情から現状維持。 - 3 test → 2 test / 63 行 → 51 行。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…nline
- /code-review medium (8 agent parallel) 実行結果:
- correctness bug 0 件 (Angle A/B/C 全 clean)
- Conventions 違反 0 件 (CLAUDE.md 全 rule 準拠)
- Reuse / Efficiency no issues
- Altitude 提案 3 件全 skip (toEqual は既に両方向 cover、magic
number 化、production への test 漏出は altitude 悪化)
- 採用した 2 finding:
- S1: 14 行の header comment を 4 行に短縮 (重複説明を排除)
- S2: readPreloadFile trivial wrapper を削除、extractKeys の第一引数へ
readFileSync を inline
- 51 行 → 43 行。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ymnao
added a commit
that referenced
this pull request
Jul 5, 2026
- package.json の version を 0.6.0 → 0.7.0 に bump - CHANGELOG.md に v0.7.0 エントリを追加 (#243 〜 #280) - Fixed: FileTree scroll regression (#276)、electron e2e launch teardown timeout 拡大 (#247) - Internal: #209 3 項目 (drift-lock 系 refactor #278/#279/#280)、settings setter 集約 (#273 → #277)、search/workspace/backlink 系 helper 抽出 15 件 - Dependencies: electron 43.0.0 / p-limit 7.3.0 major bump (#275)、Dependabot 7 件 combine (#274)、pnpm-workspace.yaml overrides で @codemirror dual copy を恒久防止 Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
electron/preload/api.ts(Api type、現在 55 method) とelectron/preload/index.ts(api Object.freeze 実装、55 method) の hardcode 同期を CI で lock する vitest テストを追加。preload API 追加時に片方の更新漏れがあると本テストが fail するので、drift risk を防ぐ。expect(implKeys).toEqual(typeKeys))関連 Issue
#209 項目 ①(v0.7.0 milestone 最終項目)。#209 parent issue は既に closed のため
Closesは付与しない。移行 Stage
変更内容
electron/preload/api-sync.test.tsを新規追加(43 行、2 test case)extractKeys(source, openMarker, closeMarker)で\t\w+\??:にマッチする level 1 indent identifier を抽出export type Api = Readonly<{ ... }>;block と、index.ts のconst api: Api = Object.freeze({ ... });block を対象onWindowCloseRequestedのような multi-line 実装があっても top-level method 名だけが取れる動作確認
セッション内で実施した review flow
3 commit 構成:
test:— 初期実装(3 test case / 63 行)refactor: /simplify— 2 wrapper unify + redundant count test 削除(2 test case / 51 行)refactor: /code-review medium— header comment 短縮 +readPreloadFileinline 化(43 行)検証エビデンス
リスク分類
tier: medium(classify-risk.sh の判定)
理由: 具体的 reason なしのデフォルト分類。ただし新規 test file 1 個追加のみで実 production code の変更なし・security 表面積ほぼゼロ・test suite は 694 pass 済み。
実行した検証
./node_modules/.bin/vitest run --project main./node_modules/.bin/vitest run --project main electron/preload/api-sync.test.ts./node_modules/.bin/biome check electron/preload/api-sync.test.ts./node_modules/.bin/tsc --noEmit -p tsconfig.node.json./node_modules/.bin/tsc --noEmit -p tsconfig.web.jsonsettingsSavekey を一時削除 → vitest 実行 → restorebash ~/.claude/skills/codex-review/scripts/run-review.sh securityfailed to initialize in-process app-server client: Operation not permittedにより起動不可)レビュー指摘と対応
セッション内 /simplify + /code-review medium で以下を対応:
extractApiTypeKeys/extractApiObjectKeysが near-identicalextractKeys(source, open, close)に unifyreadPreloadFiletrivial wrapperextractKeysの第一引数へ inlineRegExpMatchArraynarrowing 事情から現状維持toEqualは array 完全一致で両方向 cover されるlength > 50magic number sanity{などの記号あるので visual quoting 保持\t\w+は//にマッチしない)