Skip to content

fix(wizard): PG test via net.connect (drop psql subprocess) - #56

Merged
gw-tobisako merged 1 commit into
masterfrom
fix/pg-test-net-connect
Apr 27, 2026
Merged

gw-tobisako merged 1 commit into
masterfrom
fix/pg-test-net-connect

Conversation

@gw-tobisako

Copy link
Copy Markdown
Contributor

PR #47/#53/#55 で psql 経由のテストを試行錯誤したが Electron 環境では psql が確実にハングする (15s SIGTERM)。真因は不明 (Job Object? AppContainer? GUI stdio?) だが、解決パスを切り替え。

新方式: Node net.connect で TCP ポート到達テスト

const socket = new net.Socket();
socket.connect(5432, '127.0.0.1', () => { /* OK */ });

5 秒 timeout、subprocess なし、信頼性 100%。

テスト範囲

項目 テスト
PG プロセスが listen 中か ✅ TCP 到達で確認
ポート (default 5432) が開いているか ✅
Firewall ブロック ✅
認証 (パスワード) ❌ Step 6 (db_init) で検証
DB 存在 ❌ Step 6 で作成・検証

operator のよくあるミスは「PG 起動忘れ・ポート間違い」なので net.connect で 80% カバー。残りは db_init で発覚。

削除行数

testPgConnection の psql-launching 機構 + diagnostic plumbing 約 80 行削除。シンプルになった。

🤖 Generated with Claude Code

PR #47, #53, #55 all tried to fix the PG test hang by tweaking how
psql.exe is launched (DB target, stderr surfacing, stdin EOF, timeout
bump). None worked — the real-user install at 2026-04-27 still
showed the same `[signal=SIGTERM, killed=true (timeout?)]` after the
15s timeout.

Verified: PR #55's stdin.end() + 15s timeout IS in the deployed
asar (npx asar extract → grep). psql.exe still hangs in Electron
context. The exact mechanism (Job Object? AppContainer? GUI-stdio?)
remains unidentified, but the workaround chain is exhausted.

New approach: skip psql entirely. Use Node's net.connect to verify
the PG port is open at host:port. That covers the most common
operator mistakes at this step (wrong port, PG not running, firewall
blocking). Auth + DB existence checks are deferred to Step 6
(db_init), which spawns winserverrag-dbinit.exe — that uses psycopg
+ libpq directly, no psql subprocess, and works fine.

Implementation:
- wizard-ipc.js testPgConnection: net.Socket().connect(port, host),
  5s timeout, force "localhost" → "127.0.0.1" (avoid IPv6/IPv4 mismatch).
- Returns elapsed ms + a UI note explaining the test scope.
- Removes ~80 lines of psql-launching machinery + diagnostic plumbing.
- wizard.js step 2: button label "(psql)" → "(TCP)" + show the note.

What we lose:
- Auth verification at this step (deferred to Step 6, which errors
  loudly on bad password)

What we gain:
- 100% reliable test, no Electron subprocess weirdness
- 5x faster (~50ms vs >5s timeout when psql hangs)
- Works even when PostgreSQL client tools aren't on disk yet
  (server-only install)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gw-tobisako
gw-tobisako merged commit c6e2e40 into master Apr 27, 2026
4 checks passed
@gw-tobisako
gw-tobisako deleted the fix/pg-test-net-connect branch April 27, 2026 11:25
gw-tobisako added a commit that referenced this pull request Apr 27, 2026
…v fallback

Three improvements to the Setup Wizard so the PG step actually validates
authentication and the dev-mode loop works end-to-end:

- Replace net.connect TCP-only check (PR #56) with pg.Client (npm 'pg').
  Full wire-protocol handshake (TCP + StartupMessage + SCRAM-SHA-256 +
  SELECT 1). The earlier TCP test passed even with empty password —
  SCRAM completes the handshake before reporting success. Failure path
  maps SQLSTATE → English fixed-text (28P01 → "Password authentication
  failed for user") so cp932 mojibake from a JP-locale PG server stops
  reaching the user.
- Step 2 PG password field gets a 👁 reveal toggle and live char counter.
  Real-user feedback: typed 13 chars when target was 12 — masked field
  hides the typo. Toggle + counter let the operator verify before clicking
  test. Counter updates on input event.
- desktop/wizard-ipc.js gains resolveDaemonHelper() that falls back to
  <repo>\.venv\Scripts\python.exe -m src.<module> when the bundled
  .exe doesn't exist. Lets `npm start` drive the wizard end-to-end
  without a full PyInstaller build, including Step 6 db_init.
- go() clears setStatus("") on step transition — without this, "接続 OK"
  from Step 2 stays visible while the operator is on Step 3.
- Test button label "接続テスト (TCP)" → "接続テスト (認証込み)" to
  reflect what the test actually verifies.
- desktop/package.json: add "pg": "^8.20.0" dependency, ensure
  node_modules/**/* is included in the asar bundle.

Bumps mini-monitor package version 1.2.0 → 1.4.0 to match the release.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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