Skip to content

@burger-editor/local: 起動時 loadResolverState 失敗の終了挙動にテストがない #754

@YusukeHirao

Description

@YusukeHirao

Context

仮想ファイルツリー機能 (virtualTree.enabled = true) で起動するとき、commands/server.ts は以下のように loadResolverState を await する:

const resolverState = userConfig.virtualTree.enabled
    ? await loadResolverState(userConfig.documentRoot, userConfig.virtualTree.pathKey)
    : null;
setRoute(app, userConfig, resolverState);

loadResolverState は frontmatter 不在 / pathKey 非文字列 / 論理パス重複の各ケースで throw する。runServerCommand 自体も async なので、throw は最終的に top-level await に伝播し、Node が uncaught exception として stack trace を吐いて exit code 1 で終了する。

Why this matters

ユーザに見える最も重要な UX のひとつ:

  1. 衝突メッセージの可読性: PathConflictError.messageConflicting logical paths in virtual tree:\n - "about.html" claimed by: 1.html, 2.html という構造化された複数行メッセージを持つが、Node のデフォルト uncaught handler は Error: プレフィックスと stack trace を一緒に出力する。ユーザにとって「最初の数行だけ読めば原因が分かる」状態になっているか保証されていない
  2. exit code が 1 であること: CI / プロセスマネージャ (PM2, systemd) がリトライ判断に使う

これらに対するテストがない(観点 5: ゴーストコード)。commands/server.ts から loadResolverState の呼び出しを消しても全テスト green。

Proposed approach

  1. commands/server.spec.ts 新規:
    • documentRoot に重複した frontmatter.path を持つ html ファイルを 2 つ置く
    • runServerCommandchild_process.spawn で起動 (or vi.spyOnprocess.exit を捕まえる)
    • exit code 1
    • stderr に Conflicting logical paths と両ファイル名が含まれること
  2. もしくは runServerCommand 内で明示的に try/catch して,PathConflictError のときは整形した message を console.error してから process.exit(1)。これなら stack trace が混じらず読みやすい。テストもシンプルになる

Out of scope of the parent PR

仮想ファイルツリー機能の本筋は完了。サーバー起動の失敗 UX 整備は別作業として切り出し。

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions