Skip to content

Conversation

mafreud
Copy link
Contributor

@mafreud mafreud commented Sep 28, 2025

  • Updated package.json to include vitest and supertest for testing.
  • Created a GitHub Actions workflow for running tests on push and pull request events.
  • Added a sample test for the helloWorld function to verify it returns a 200 status code and the expected response.

Summary by CodeRabbit

  • テスト

    • Firebase Functions の helloWorld に対する統合テストを追加(GETで200と応答本文を検証)。
    • npm scripts に test(vitest run)を追加し、@types/supertest・supertest・firebase-functions-test・vitest を開発依存に追加。
  • チョア

    • Firebase Functions のテスト用 GitHub Actions ワークフローを新規追加(push/PR、Node 20/22、npm ci → npm test、対象ディレクトリ指定)。
    • GitHub Apps のテスト用ワークフローを更新(パスフィルタ、contents: read 権限、Node 20/22 マトリクス、作業ディレクトリ設定)。

- Updated package.json to include vitest and supertest for testing.
- Created a GitHub Actions workflow for running tests on push and pull request events.
- Added a sample test for the helloWorld function to verify it returns a 200 status code and the expected response.
Copy link

linear bot commented Sep 28, 2025

Copy link
Contributor

coderabbitai bot commented Sep 28, 2025

Walkthrough

Firebase Functions にテスト基盤を追加。functions 配下に Vitest/Supertest を導入し、helloWorld のテストを新規作成。Firebase Functions 用の GitHub Actions ワークフローを新規追加。既存の GitHub Apps 用ワークフローはパスフィルタや Node マトリクス対応に更新。

Changes

Cohort / File(s) Summary
Firebase Functions: テスト環境追加
openci-runner/firebase/functions/package.json, openci-runner/firebase/functions/test/hello-world.test.ts
package.json に test スクリプトと devDependencies(vitest, supertest, @types/supertest, firebase-functions-test)を追加。helloWorld の HTTP 200/応答本文を検証するテストを新規作成(params.defineSecret をモック、Express にマウントして検証)。
CI: Firebase Functions テスト用ワークフロー新規
.github/workflows/firebase-functions-tests.yml
main/develop への push/pr(対象パス限定)で起動。Node 20/22 マトリクスで npm cinpm testopenci-runner/firebase/functions 直下で実行。
CI: GitHub Apps ワークフロー更新
.github/workflows/github-apps-tests.yml
対象パスフィルタを追加(openci-runner/github-apps/**)。permissions を contents: read に設定。Node 20/22 のマトリクス化。実行ディレクトリを openci-runner/github-apps に設定。Node セットアップを matrix.node-version 参照に変更。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant GH as GitHub
  participant CI as Actions Runner
  participant Job as "Workflow Job (matrix: Node 20/22)"
  participant NPM as npm
  participant VT as Vitest
  participant Fn as helloWorld (Express)

  Dev->>GH: Push / Pull Request (paths filtered)
  GH-->>CI: Trigger workflow (firebase-functions-tests.yml)
  CI->>Job: Start job in openci-runner/firebase/functions
  Job->>NPM: npm ci
  Job->>NPM: npm test
  NPM->>VT: Run tests
  VT->>Fn: Supertest GET /
  Fn-->>VT: 200 "Hello from Firebase!"
  VT-->>Job: Report test results
  Job-->>GH: Status (success/failure)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

ぴょんと跳ねてテストが増えた
緑の灯り、CIが歌う
「Hello」と返す雲の関数
にんじん色のログが踊り
未来へ駆けるビルドの足音 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed タイトルは「Firebase functionsのテスト機能を追加する」というプルリクの主要変更を短くかつ明確に表しており、ファイルリストや曖昧な用語を含まず要件を満たしています。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch op-280

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ba3df9b and 10bd9f0.

📒 Files selected for processing (2)
  • .github/workflows/firebase-functions-tests.yml (1 hunks)
  • .github/workflows/github-apps-tests.yml (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Webhook ハンドラに対する Vitest スイートを実行する
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Vitest のテストスイートは github-apps/test/ に配置する
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: github-apps ワークスペースは npm install 後 npm run dev でサンドボックス起動し、npm test で Vitest を実行する

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mafreud mafreud marked this pull request as ready for review September 28, 2025 02:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (9)
.github/workflows/firebase-functions-test.yml (4)

20-23: Node バージョンのマトリクス化+npm キャッシュを有効化

Node 22 固定だと将来の互換性/実行環境差異でCIがブレます。Node 20/LTS も並行で回し、依存キャッシュで速度も確保しましょう。

       - name: Set up Node.js
         uses: actions/setup-node@v4
         with:
-          node-version: "22"
+          node-version: ${{ matrix.node-version }}
+          cache: npm
+          cache-dependency-path: openci-runner/firebase/functions/package-lock.json

11-15: Node マトリクスの導入

上記の node-version 置換に合わせてマトリクスを追加してください。

   test:
     runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        node-version: [20, 22]
     defaults:
       run:
         working-directory: openci-runner/firebase/functions

11-11: ワークフロー権限の最小化

読み取りのみで十分です。明示指定でセキュリティ姿勢を強化できます。

   test:
     runs-on: ubuntu-latest
+    permissions:
+      contents: read

3-7: 不要実行の抑制(paths フィルタ)

対象ディレクトリに変更がない場合は走らないようにできます。CIコスト削減に有効です。

 on:
   push:
-    branches: [main, develop]
+    branches: [main, develop]
+    paths:
+      - 'openci-runner/firebase/functions/**'
+      - '.github/workflows/firebase-functions-test.yml'
   pull_request:
-    branches: [main, develop]
+    branches: [main, develop]
+    paths:
+      - 'openci-runner/firebase/functions/**'
+      - '.github/workflows/firebase-functions-test.yml'
openci-runner/firebase/functions/test/hello-world.test.ts (3)

12-13: any の排除と Biome 抑止コメントの解消

型を付ければ biome-ignore は不要です。テストの可読性も上がります。

-import express from "express";
+import express, { type Request, type Response } from "express";
@@
-// biome-ignore lint/suspicious/noExplicitAny: <explanation>
-let helloWorld: (req: any, res: any) => unknown;
+let helloWorld: (req: Request, res: Response) => unknown;

5-10: firebase-functions/params の部分モック化

将来 params の他の export を使った際の破壊的影響を避けるため、実体を取り込みつつ defineSecret のみ差し替える形が堅牢です。

-vi.mock("firebase-functions/params", () => ({
-	defineSecret: (name: string) => ({
-		name,
-		value: () => JSON.stringify({ projectId: "demo-project" }),
-	}),
-}));
+vi.mock("firebase-functions/params", async () => {
+	const actual = await vi.importActual<typeof import("firebase-functions/params")>(
+		"firebase-functions/params",
+	);
+	return {
+		...actual,
+		defineSecret: (name: string) => ({
+			name,
+			value: () => JSON.stringify({ projectId: "demo-project" }),
+		}),
+	};
+});

21-28: ルーティングの記述を簡潔に

挙動は同じですが app.use(helloWorld) の方が意図が明確です。

-    const app = express();
-    app.all("*", (req, res) => helloWorld(req, res));
+    const app = express();
+    app.use((req, res) => helloWorld(req, res));
openci-runner/firebase/functions/package.json (2)

21-27: テスト実行の直接依存として express を明示追加

express を直接 import しているため、ホイストに依存せず devDependencies に追加してください。型も合わせて入れると前述の any 排除が可能です。

   "devDependencies": {
+    "@types/express": "^4.17.21",
     "@types/supertest": "^6.0.3",
     "firebase-functions-test": "^3.1.0",
+    "express": "^4.19.2",
     "supertest": "^7.0.0",
-    "typescript": "^4.9.0",
+    "typescript": "^5.4.0",
     "vitest": "^1.6.0"
   },

typescript@^5.4.0 は一例です。現行の vitestfirebase-functions@^6 との互換最新安定バージョンをご確認のうえ調整してください。


21-27: firebase-functions-test が未使用のようです
リポジトリ全体を検索したところ、テストコード内に該当パッケージの参照が見つかりませんでした(package.jsonpackage-lock.json のみ)。将来利用予定がなければ、devDependencies から削除してインストール時間を短縮することを検討してください。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 37ac08b and ba3df9b.

⛔ Files ignored due to path filters (1)
  • openci-runner/firebase/functions/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .github/workflows/firebase-functions-test.yml (1 hunks)
  • openci-runner/firebase/functions/package.json (2 hunks)
  • openci-runner/firebase/functions/test/hello-world.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Webhook ハンドラに対する Vitest スイートを実行する
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Vitest のテストスイートは github-apps/test/ に配置する
📚 Learning: 2025-09-27T13:05:21.009Z
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Webhook ハンドラに対する Vitest スイートを実行する

Applied to files:

  • openci-runner/firebase/functions/test/hello-world.test.ts
🧬 Code graph analysis (1)
openci-runner/firebase/functions/test/hello-world.test.ts (1)
openci-runner/firebase/functions/src/index.ts (1)
  • helloWorld (7-15)
🔇 Additional comments (3)
openci-runner/firebase/functions/package.json (1)

14-15: engines.node=22 のままで問題ありません
Node.js 22 は Cloud Functions (2nd gen/Cloud Run functions) および Firebase Functions で正式サポートされているため、"node": "22" のままデプロイして問題ありません。 (cloud.google.com)

.github/workflows/firebase-functions-test.yml (2)

24-28: lockfileの存在を確認しました openci-runner/firebase/functions/package-lock.json がリポジトリ内に存在するため、npm ci は正常に実行されます。


20-23: Firebase Functions (第2世代) で Node.js 22 はサポート済み
Firebase Functions (第2世代) は Node.js 22 をサポートしています。プレビューは 2024年5月17日、GA は 2024年11月18日に提供開始され、公式ドキュメントにも Node.js 22 がリストされています (cloud.google.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