Skip to content

Conversation

@cm-dyoshikawa
Copy link
Contributor

@cm-dyoshikawa cm-dyoshikawa commented Oct 31, 2025

📑 Summary

仕様の変更

  • Windows環境でのE2Eテストワークフローを追加しました
  • Linux環境でビルドしたzenn-cliバンドルをactions/cacheを使用してWindows環境で実行する仕組みを構築しました
  • PowerShell環境でのテスト実行に対応しました

コードの変更

  • openパッケージをESM importとして外部化し、rspackでの取り扱いを改善しました
  • openパッケージをdevDependenciesからdependenciesに移動しました
  • 全てのzenn-cliコマンド(init, new:article, new:book, list:articles, list:books, preview)のE2Eテストを追加しました
  • E2Eテスト用のヘルパー関数を実装し、クロスプラットフォームでのテスト実行をサポートしました
  • Vitest設定ファイル(vitest.e2e.config.ts)を追加しました

その他・備考

  • これにより、zenn-cliがWindows環境で正しく動作することを継続的に検証できるようになります
  • E2Eテストは一時ディレクトリで実行され、テスト後に自動的にクリーンアップされます

📋 Tasks

プルリクエストを作成いただく際、お手数ですが以下の内容についてご確認をお願いします。

  • 📖 Contribution Guide を読んだ
  • 👩‍💻 canary ブランチに対するプルリクエストである
  • zenn-cli で実行して正しく動作しているか確認する
  • 不要なコードが含まれていないか( コメントやログの消し忘れに注意 )
  • XSS になるようなコードが含まれていないか
  • モバイル端末での表示が考慮されているか
  • Pull Request の内容は妥当か( 膨らみすぎてないか )

より詳しい内容は Pull Request Policy を参照してください.

Windowsでzenn-cliが最低限動作することを確認するためのE2E workflowを追加しました。

## 仕様の変更
- Windows環境でzenn-cliのinitコマンドが正常に動作することを確認する新しいワークフローを追加

## コードの変更
- `.github/workflows/e2e.yml` を新規作成
  - buildジョブ: ubuntu-latestでビルドし、zenn-cliのdistディレクトリをキャッシュに保存
  - e2eジョブ: windows-latestでキャッシュからdistを復元し、initコマンドを実行してエラーが出ないことを確認

## その他・備考
- Windowsでのビルドは問題があるため、ubuntu-latestでビルドしたものをキャッシュ経由で共有する方式を採用

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cm-dyoshikawa cm-dyoshikawa self-assigned this Oct 31, 2025
cm-dyoshikawa and others added 6 commits October 30, 2025 23:05
LinuxとWindows間でキャッシュを共有するために enableCrossOsArchive を有効化しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
openパッケージをバンドルから除外し、外部依存として扱うことでクロスプラットフォーム対応を改善しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
openパッケージを外部依存として扱うため、実行時に必要なdependenciesに移動しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
openパッケージの依存関係の変更に伴いロックファイルを更新しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
distディレクトリの内容を確認するデバッグステップを追加しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Windows PowerShell用のコマンドに修正しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cm-dyoshikawa cm-dyoshikawa added the bug 不具合の修正 label Oct 31, 2025
cm-dyoshikawa and others added 8 commits October 30, 2025 23:36
エラー出力を確実にキャプチャするようにPowerShellスクリプトを改善しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
openパッケージをexternalとしてビルドする際にESMパッケージとして正しく扱うように修正しました。

仕様の変更:
- openパッケージをdynamic importで読み込むように変更

コードの変更:
- packages/zenn-cli/src/server/lib/server.ts
  - import文を削除し、open()呼び出し箇所でdynamic importを使用
  - listening イベントハンドラをasync関数に変更
- packages/zenn-cli/rspack.server.js
  - externals設定でopenパッケージを'import open'として扱うように変更
  - ESMパッケージであることを明示するコメントを追加

その他・備考:
- openパッケージv10はESM専用のため、CommonJSのrequireでは読み込めない問題を解決
- dynamic importを使用することでクロスプラットフォーム対応を維持

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
修正前のコメントでは「dynamic importで読み込む」と記載していたが、
実際の実装は静的なESM importを使用しているため、コメントを修正。

- 誤: dynamic importで読み込む
- 正: ESM importとして扱う

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Changed from dynamic import('open') to static import to simplify the code while maintaining the same functionality. The 'open' package is now imported at the top of the file.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
すべてのzennコマンド(init, new:article, new:book, list:articles, list:books, preview)のテストを追加しました。

主な変更点:
- new:article/new:bookコマンドの対話型プロンプトに自動応答する仕組みを実装
- ファイル/ディレクトリが正しく作成されることを検証
- previewコマンドをバックグラウンドで起動し、HTTPリクエストでサーバー起動を確認してから停止する処理を実装
- 各コマンドのエラーハンドリングとメッセージを改善

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This change streamlines the E2E workflow to focus on basic installation and execution checks:
- Use production dependencies only (--prod flag) to test the actual deployment scenario
- Remove detailed command tests (new:article, new:book, list:*, preview) which are now covered by comprehensive tests in a previous commit

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ndencies

This change modifies the E2E workflow to install all packages, removing the exclusion of devDependencies during installation. This adjustment ensures that the workflow has access to all necessary packages for testing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
仕様の変更:
- E2Eワークフローで個別のコマンドテストを廃止し、Vitestベースの統合E2Eテストスイートを実行するように変更

コードの変更:
- .github/workflows/e2e.yml: 個別のinitコマンドテストを削除し、`pnpm -C packages/zenn-cli e2e`による統合テスト実行に置き換え
- packages/zenn-cli/package.json: `e2e`スクリプトを追加
- packages/zenn-cli/e2e.ts: 全zennコマンド(init, new:article, new:book, list:articles, list:books, preview)のE2Eテストを実装
- packages/zenn-cli/vitest.e2e.config.ts: E2Eテスト用のVitest設定ファイルを追加
- packages/zenn-cli/tsconfig.e2e.json: E2Eテスト用のTypeScript設定ファイルを追加
- packages/zenn-cli/tsconfig.json: `commands.e2e.ts`をincludeに追加
- pnpm-lock.yaml: 依存関係の更新

その他・備考:
- E2Eテストは実際のファイルシステムを使用し、一時ディレクトリで実行されます
- 各テストは独立したテストディレクトリを使用し、クリーンアップも自動で行われます

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
cm-dyoshikawa and others added 11 commits November 4, 2025 21:46
- Added comments to clarify the build process for zenn-editor packages on Linux and the restoration of zenn-cli bundle files from actions/cache for E2E tests on Windows.
- This update improves the workflow's efficiency by leveraging cached artifacts across different operating systems.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
commands.e2e.ts は E2E テストファイルであり、通常のビルドプロセスに含める必要がないため、tsconfig.json の include から除外しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
E2Eテストファイルを整理し、クロスプラットフォーム対応を改善しました。

仕様の変更:
- E2Eテストファイルを packages/zenn-cli/e2e.ts から packages/zenn-cli/src/e2e/e2e.ts に移動
- src配下に配置することでプロジェクト構造を統一

コードの変更:
- e2e.ts: __dirname から process.cwd() に変更し、実行時のworking directoryを基準にパス解決
- e2e.ts: パス連結を './dist/server/zenn.js' から join('dist', 'server', 'zenn.js') に変更し、Windows環境でも正しく動作するように改善
- tsconfig.e2e.json: include パスを新しいファイル位置に更新
- vitest.e2e.config.ts: include パスを新しいファイル位置に更新

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
## 仕様の変更

なし

## コードの変更

- `src/e2e/helper.ts` を新規作成
  - `getZennCliPath()`: zenn CLI のパスを取得し、存在しない場合はエラーを投げる
  - `execZennCommand()`: zenn CLI コマンドを実行するヘルパー関数
- `src/e2e/e2e.ts` にテストを追加
  - `new:article` コマンドのE2Eテスト(デフォルトと --slug オプション)
  - `new:book` コマンドのE2Eテスト(デフォルトと --slug オプション)
  - 既存の `init` コマンドテストをリファクタリング
- `vitest.e2e.config.ts` にシングルワーカー設定を追加
  - `pool: 'forks'` と `singleFork: true` を設定

## その他・備考

- E2Eテストは必ずシングルワーカーで実行されるように設定
- ファイル作成の確認とエラーなく実行されることを検証
- すべてのテストが正常に合格

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
## 仕様の変更

なし

## コードの変更

- `src/e2e/e2e.ts` から --slug オプション付きテストを削除
  - デフォルトの動作確認のみに簡略化

## その他・備考

- テスト数を3つに削減(init, new:article, new:book)
- すべてのテストが正常に合格

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
## 仕様の変更

なし

## コードの変更

- `src/e2e/e2e.ts` にテストを追加
  - `list:articles` コマンドのE2Eテスト
  - `list:books` コマンドのE2Eテスト

## その他・備考

- 最低限のテストのみ実装(エラーなく実行されることを確認)
- すべてのテストが正常に合格

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
## 仕様の変更

なし

## コードの変更

- `src/e2e/helper.ts` に `logIfFailed` 関数を追加
  - コマンド実行結果が失敗している場合にログを出力
- `src/e2e/e2e.ts` で `logIfFailed` を使用するようリファクタリング
  - 重複していたエラーログ出力処理を共通化

## その他・備考

- コードの重複を削減
- すべてのテストが正常に合格

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
## 仕様の変更

なし

## コードの変更

- `src/e2e/helper.ts` に `execZennPreview` 関数を追加
  - preview コマンドを起動し、指定時間後に自動終了
  - 起動時エラーの有無を確認
- `src/e2e/e2e.ts` に preview コマンドのテストを追加
  - 3秒間起動してエラーがないことを確認
- すべてのテストケース名を日本語に統一

## その他・備考

- preview コマンドはフォアグラウンドで常駐するため、タイムアウトで自動終了
- 全6テストが正常に合格

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
GitHub Actions workflow上でE2Eテストの実行ステップにPowerShellを明示的に指定しました。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cm-dyoshikawa cm-dyoshikawa changed the title WindowsでのE2Eテストワークフローを追加 zenn-cliのWindows互換性を向上し、E2Eテストワークフローを追加 Nov 5, 2025
- E2EテストをUbuntuとWindowsの両方で実行するようmatrixを追加
- OS別にテスト実行ステップを条件分岐
- distディレクトリ確認ステップを削除してワークフローを簡素化

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linuxとwindowsで動作確認

Comment on lines +36 to +65
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v5

- uses: pnpm/action-setup@v4
with:
version: 10.18.3

- name: パッケージをインストール
run: pnpm install

- name: zenn-cliのdistディレクトリをキャッシュから復元
uses: actions/cache/restore@v4
with:
path: packages/zenn-cli/dist
key: zenn-cli-dist-${{ github.sha }}
enableCrossOsArchive: true

- name: zenn-cliのE2Eテストを実行 (Windows)
if: runner.os == 'Windows'
run: pnpm -C packages/zenn-cli e2e
shell: pwsh

- name: zenn-cliのE2Eテストを実行 (Linux)
if: runner.os == 'Linux'
run: pnpm -C packages/zenn-cli e2e

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI about 1 month ago

To address the issue, we need to explicitly define the permissions block for the workflow. The best approach is to add it at the root level of .github/workflows/e2e.yml, so it applies to all jobs, unless a job requires something more. Since the jobs only check out code, install packages, build, and cache artifacts, they only need read access to repository contents. We add the following at the top of the workflow:

permissions:
  contents: read

You should insert this block immediately after the workflow name: and before on: to conform to standard order and style.


Suggested changeset 1
.github/workflows/e2e.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -1,4 +1,6 @@
 name: E2E Test on Cross Platform
+permissions:
+  contents: read
 
 on:
   pull_request:
EOF
@@ -1,4 +1,6 @@
name: E2E Test on Cross Platform
permissions:
contents: read

on:
pull_request:
Copilot is powered by AI and may make mistakes. Always verify output.
"exec:zenn": "node ./dist/server/zenn.js"
},
"dependencies": {
"open": "^10.2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openを外部化し、ユーザーインストールするようにする

@cm-dyoshikawa cm-dyoshikawa marked this pull request as ready for review November 5, 2025 06:24
canaryブランチの最新変更を取り込みました。

- バージョン0.2.10-alpha.2への更新
- Windows環境でのscript実行の修正を含む変更をマージ
- package.jsonのcleanスクリプトをcanaryの形式に統一しつつ、e2eスクリプトを保持
- Added a step to build zenn-cli before restoring the dist directory from cache in the E2E workflow.
…s before restoring the dist directory from cache.
@@ -0,0 +1,155 @@
import { mkdtemp, rm, access } from 'fs/promises';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLIに対するE2Eテスト。各コマンドがコケないか、最低限の動作確認を行う

@cm-dyoshikawa
Copy link
Contributor Author

cm-dyoshikawa commented Nov 5, 2025

openパッケージをexternalにしないとこのエラーになる
https://github.com/zenn-dev/zenn-editor/actions/runs/19093832539/job/54549516242

stderr | src/e2e/e2e.ts > E2E Tests > init コマンドが正常に実行される
STDOUT: 
STDERR: node:internal/url:1489
    throw new ERR_INVALID_FILE_URL_PATH('must be absolute', url);
    ^

TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
    at getPathFromURLWin32 (node:internal/url:1489:11)
    at fileURLToPath (node:internal/url:1613:35)
    at D:\a\zenn-editor\zenn-editor\packages\zenn-cli\dist\server\zenn.js:272:1660
    at D:\a\zenn-editor\zenn-editor\packages\zenn-cli\dist\server\zenn.js:293:2027
    at Object.<anonymous> (D:\a\zenn-editor\zenn-editor\packages\zenn-cli\dist\server\zenn.js:293:2031)
    at Module._compile (node:internal/modules/cjs/loader:1706:14)
    at Object..js (node:internal/modules/cjs/loader:1839:10)
    at Module.load (node:internal/modules/cjs/loader:1441:32)
    at Function._load (node:internal/modules/cjs/loader:1263:12)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14) {
  code: 'ERR_INVALID_FILE_URL_PATH',
  input: file:///home/runner/work/zenn-editor/zenn-editor/node_modules/.pnpm/open@10.2.0/node_modules/open/index.js
}

Copy link
Member

@cm-igarashi-ryosuke cm-igarashi-ryosuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLIのE2Eテストという発想は思いつかなかったなーアプローチがすばらしい!LGTMです!

@cm-dyoshikawa cm-dyoshikawa merged commit 33ff41d into canary Nov 5, 2025
9 checks passed
@cm-dyoshikawa cm-dyoshikawa deleted the windows-gha-e2e branch November 5, 2025 07:12
This was referenced Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 不具合の修正

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants