Skip to content

test(v3.2.65): New-CloudSchedule.ps1 ユニットテスト追加 — Build-CreatePrompt / New-LoopPreset 23件 - #227

Merged
Kensan196948G merged 1 commit into
mainfrom
test/new-cloud-schedule-unit-tests-v3.2.65
Apr 21, 2026
Merged

Kensan196948G merged 1 commit into
mainfrom
test/new-cloud-schedule-unit-tests-v3.2.65

Conversation

@Kensan196948G

@Kensan196948G Kensan196948G commented Apr 21, 2026 •

Copy link
Copy Markdown
Owner

概要

scripts/main/New-CloudSchedule.ps1(772行)のコアロジックに対するユニットテストがゼロだった問題を解消します(Issue #226)。

dot-source + exit→return パッチ戦略により Pester プロセスを終了させることなくスクリプト全体をロードし、New-LoopPreset と Build-CreatePrompt の両関数を 23 テストケースで網羅します。

変更内容

  • tests/unit/NewCloudSchedule.Tests.ps1 新規作成(23 テストケース)
    • New-LoopPreset: 12件(プリセット数・名前・Cron・URL注入・プロパティ検証)
    • Build-CreatePrompt: 11件(RemoteTrigger・名前/Cron埋め込み・モデル・エスケープ・UUID・CREATED_ID)
  • CHANGELOG.md: v3.2.65 エントリ追加
  • README.md: バージョン v3.2.65、テスト件数 703 件に更新
  • TASKS.md: タスク feat(boot): Issue #68 PR-B — Step 7 Agent Init を AgentTeams.psm1 でワイヤリング #80 追加

テスト結果

  • Pester: 23/23 passed
  • PSScriptAnalyzer: 0 warnings (PSUseBOMForUnicodeEncodedFile 含む)

影響範囲

テストファイル追加のみ。既存スクリプトへの変更なし。

Closes

Closes #226

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • テスト

    • New-CloudSchedule.ps1 向けユニットテスト23件を追加し、Build-CreatePrompt と New-LoopPreset 関数のカバレッジを拡充
  • バグ修正

    • テスト実行時の exit 処理に関する問題を解決
  • ドキュメント

    • バージョンを v3.2.65 に更新
    • テスト総数を 703 件に、ユニットテストを 18 件に更新

… New-LoopPreset 23件 (#226)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 21, 2026 14:26
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

scripts/main/New-CloudSchedule.ps1 に対する新規ユニットテストスイート(23件)を追加。Build-CreatePrompt と New-LoopPreset 関数の動作を検証する Pester テストを実装し、ドキュメント類を v3.2.65 に更新。

Changes

Cohort / File(s) Summary
ユニットテスト追加
tests/unit/NewCloudSchedule.Tests.ps1
New-LoopPreset(4プリセット返却、URL注入、プロパティ検証)と Build-CreatePrompt(プロンプト文字列埋め込み、エスケープ、UUID生成)に対する23件のテストケースを新規作成。dot-source 時の exit 問題を return に差し替えるパッチ戦略を採用。
ドキュメント更新
CHANGELOG.md, README.md, TASKS.md
v3.2.65 リリースノートを追加・更新。テスト追加(23件)、テスト総数(680→703件)、Unit テスト数(17→18)を反映。PSScriptAnalyzer 0 警告を記載。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 テストの花、23個咲いて
Build-CreatePrompt と LoopPreset の
返り道をチェック、チェック…✨
exit は return に変わった
心地よいテストの春だよ 🌸

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルは 「New-CloudSchedule.ps1 ユニットテスト追加」と具体的にテスト対象ファイルと追加対象関数を明記しており、変更内容を正確に反映している。
Linked Issues check ✅ Passed PR #226 の全受入基準を満たす。New-LoopPreset は 12件、Build-CreatePrompt は 11件のテストがあり、各関数で8件以上の要件を達成。Pester 23/23 pass、PSScriptAnalyzer 0 warnings が確認されており、実装方針も全て充足している。
Out of Scope Changes check ✅ Passed 変更内容は全て Issue #226 の要件に関連。テストファイル追加、CHANGELOG/README/TASKS.md への変更は新機能リリースの文書更新として適切な範囲内。既存スクリプト本体への変更はなし。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/new-cloud-schedule-unit-tests-v3.2.65

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

New-CloudSchedule.ps1 のコアロジック(New-LoopPreset / Build-CreatePrompt)に対するユニットテストを追加し、テスト未整備(Issue #226)による回帰リスクを下げるPRです。合わせて、リリース/統計/タスク記録のドキュメント更新を行います。

Changes:

  • tests/unit/NewCloudSchedule.Tests.ps1 を新規追加し、New-LoopPreset と Build-CreatePrompt を 23 ケースで検証
  • v3.2.65 反映として CHANGELOG.md / README.md / TASKS.md を更新

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/unit/NewCloudSchedule.Tests.ps1 New-CloudSchedule.ps1 の主要2関数に対する Pester ユニットテストを追加
TASKS.md Issue #226 対応タスク(#80 DONE)を追記
README.md バージョンとテスト件数の統計を v3.2.65 / 703件に更新
CHANGELOG.md v3.2.65 の変更点(ユニットテスト追加)を追記

Comment on lines +21 to +28
# --- Patch: replace 'exit <n>' with 'return' to prevent killing Pester ---
$raw = Get-Content $script:ScriptPath -Raw -Encoding UTF8
$patched = $raw -replace '(?m)^\s*exit\s+\d+\s*$', 'return'
$script:TempScript = Join-Path $script:TempDir 'NewCloudSchedule.tmp.ps1'
$patched | Set-Content $script:TempScript -Encoding UTF8

# Dot-source in NonInteractive mode: defines all functions, sets script: vars, then returns
. $script:TempScript -NonInteractive

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

exit→return パッチの正規表現が「行頭が exit の行」しか置換しないため、New-CloudSchedule.ps1 側の if ($NonInteractive) { exit 0 } / ... { exit 0 } のようなインライン exit が残ります。BeforeAll で -NonInteractive を渡して dot-source しているので、このままだとテスト実行プロセス自体が exit で終了します(Pester が落ちる)。インライン exit も確実に無効化できる置換(例: より広いパターン、AST で ExitStatement を差し替え等)にしてください。

Copilot uses AI. Check for mistakes.
$script:ScriptPath = Join-Path $script:RepoRoot 'scripts\main\New-CloudSchedule.ps1'

# --- Fake claude stub (satisfies the CLI-detection block) ---
$script:TempDir = Join-Path ([System.IO.Path]::GetTempPath()) 'pester-cloudschedule-tests'

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

一時ディレクトリが固定名 pester-cloudschedule-tests になっているため、並列実行や前回実行の残骸がある環境で衝突しやすいです。Pester の $TestDrive を使うか、$PID/GUID を含めたユニークなディレクトリ名にして競合を避けてください。

Suggested change
$script:TempDir = Join-Path ([System.IO.Path]::GetTempPath()) 'pester-cloudschedule-tests'
$uniqueTempDirName = 'pester-cloudschedule-tests-{0}-{1}' -f $PID, ([guid]::NewGuid().ToString('N'))
$script:TempDir = Join-Path ([System.IO.Path]::GetTempPath()) $uniqueTempDirName

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/unit/NewCloudSchedule.Tests.ps1 (1)

23-23: exit 置換パターンを少し広げると将来の変更に強くなります

現在は exit <数値> だけ置換対象です。exit 単体やコメント付き行が入ると、将来的に Pester 終了リスクが再発します。

💡 修正案
-    $patched = $raw -replace '(?m)^\s*exit\s+\d+\s*$', 'return'
+    $patched = $raw -replace '(?mi)^\s*exit(?:\s+\d+)?\s*(?:#.*)?$', 'return'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/NewCloudSchedule.Tests.ps1` at line 23, The current replacement
only matches "exit <number>" so update the -replace call that assigns $patched
(the expression using $raw -replace) to use a more robust regex that also
matches bare "exit", optional numeric arguments, and optional trailing comments
(e.g., allow lines like "exit", "exit 1", or "exit 1 # reason") and still
replace the whole line with 'return'; change the pattern used in the $raw
-replace expression accordingly so $patched covers these cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 30-31: The README shows inconsistent test counts: update every
occurrence of the old test total to the new value (703) so the document is
internally consistent; search for the table row with header "バージョン" and the
"テスト" row shown in the diff and replace any stale totals (e.g., older numbers
appearing elsewhere) with 703, and verify related breakdowns
(Unit/Integration/Smoke) remain correct or are updated to match the new total;
ensure the README's external-facing summary/table entries and any repeated
counts (including sections like the version row and other occurrences) are
synchronized in this PR.

In `@tests/unit/NewCloudSchedule.Tests.ps1`:
- Around line 15-25: The temp dir name is fixed via $script:TempDir causing
parallel test collisions; change how $script:TempDir is constructed (and
consequently $script:TempScript and the claude.cmd path) to include a unique
suffix (e.g., a GUID, timestamp, or [System.IO.Path]::GetRandomFileName()) when
calling Join-Path so each test run gets its own directory, then create that
directory as before and use the unique path everywhere cleanup and file writes
reference $script:TempDir/$script:TempScript.

---

Nitpick comments:
In `@tests/unit/NewCloudSchedule.Tests.ps1`:
- Line 23: The current replacement only matches "exit <number>" so update the
-replace call that assigns $patched (the expression using $raw -replace) to use
a more robust regex that also matches bare "exit", optional numeric arguments,
and optional trailing comments (e.g., allow lines like "exit", "exit 1", or
"exit 1 # reason") and still replace the whole line with 'return'; change the
pattern used in the $raw -replace expression accordingly so $patched covers
these cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a100762-7240-4f92-bb12-df57264fde06

📥 Commits

Reviewing files that changed from the base of the PR and between c4f95fd and 6701981.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • README.md
  • TASKS.md
  • tests/unit/NewCloudSchedule.Tests.ps1
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: test-and-validate
🧰 Additional context used
📓 Path-based instructions (1)
**/*.md

📄 CodeRabbit inference engine (CLAUDE.md)

Update README.md whenever: utilizable user-facing features change, setup procedures change, architecture changes, or quality gates change; maintain README as external-facing truth with clear organization, extensive use of tables and icons, and include architecture diagrams

Files:

  • TASKS.md
  • CHANGELOG.md
  • README.md
🔇 Additional comments (3)
tests/unit/NewCloudSchedule.Tests.ps1 (1)

39-180: テスト観点は十分に網羅されていて良いです

New-LoopPreset / Build-CreatePrompt ともに、件数・主要プロパティ・埋め込み・エスケープ・UUID まで押さえられており、回帰検知力が高いです。

CHANGELOG.md (1)

5-18: v3.2.65 エントリは内容・根拠ともに明確です

対象範囲、テスト戦略、結果が簡潔にまとまっており、履歴として追跡しやすいです。

TASKS.md (1)

89-89: v3.2.65 のタスク記録は妥当です

Issue と実施内容の紐づけが明確で、履歴管理として十分です。

Comment thread README.md
Comment on lines +30 to +31
| バージョン | **v3.2.65** (New-CloudSchedule.ps1 ユニットテスト 23件追加) — 旧: v3.2.64 (管理OFFA/ONA/DELA操作をプロジェクトスコープに限定) |
| テスト | **703件** — Pester (Unit 18 / Integration 11 / Smoke 1) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

README 内のテスト件数が不整合です

Line 31 は 703 件に更新されていますが、Line 96 / Line 231 / Line 507 / Line 538 などに旧値が残っており、README 単体で真値が判別しづらい状態です。

💡 修正案(同PR内で揃える)
- | **test** | `Invoke-Pester .\tests -CI` | Pester 全テスト(現在 680 件 / Unit + Integration + Smoke)。`-CI` で `testResults.xml` 生成 |
+ | **test** | `Invoke-Pester .\tests -CI` | Pester 全テスト(現在 703 件 / Unit + Integration + Smoke)。`-CI` で `testResults.xml` 生成 |

- | ⚡ CI/CD | 🔧 共通 | GitHub Actions による自動テスト (Pester 680件 — 29 test files) |
+ | ⚡ CI/CD | 🔧 共通 | GitHub Actions による自動テスト (Pester 703件 — 30 test files) |

- tests/               Pester テスト (29 files / 680件 — Unit 17 / Integration 11 / Smoke 1)
+ tests/               Pester テスト (30 files / 703件 — Unit 18 / Integration 11 / Smoke 1)

- # Pester テスト (433件 — Unit:311 / E2E:122)
+ # Pester テスト (703件 — Unit:18 / Integration:11 / Smoke:1)

As per coding guidelines **/*.md: maintain README as external-facing truth with clear organization, extensive use of tables and icons, and include architecture diagrams.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 30 - 31, The README shows inconsistent test counts:
update every occurrence of the old test total to the new value (703) so the
document is internally consistent; search for the table row with header "バージョン"
and the "テスト" row shown in the diff and replace any stale totals (e.g., older
numbers appearing elsewhere) with 703, and verify related breakdowns
(Unit/Integration/Smoke) remain correct or are updated to match the new total;
ensure the README's external-facing summary/table entries and any repeated
counts (including sections like the version row and other occurrences) are
synchronized in this PR.

Comment on lines +15 to +25
$script:TempDir = Join-Path ([System.IO.Path]::GetTempPath()) 'pester-cloudschedule-tests'
$null = New-Item -ItemType Directory -Path $script:TempDir -Force
'@echo off' | Set-Content (Join-Path $script:TempDir 'claude.cmd') -Encoding ASCII
$script:SavedPath = $env:PATH
$env:PATH = "$script:TempDir;$env:PATH"

# --- Patch: replace 'exit <n>' with 'return' to prevent killing Pester ---
$raw = Get-Content $script:ScriptPath -Raw -Encoding UTF8
$patched = $raw -replace '(?m)^\s*exit\s+\d+\s*$', 'return'
$script:TempScript = Join-Path $script:TempDir 'NewCloudSchedule.tmp.ps1'
$patched | Set-Content $script:TempScript -Encoding UTF8

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

一時ディレクトリ名が固定で並列実行時に競合します

$script:TempDir が固定値のため、同時実行時に stub/patch ファイルの上書きや削除競合でテストが不安定になります。ユニーク名にしてください。

💡 修正案
-    $script:TempDir   = Join-Path ([System.IO.Path]::GetTempPath()) 'pester-cloudschedule-tests'
+    $script:TempDir   = Join-Path ([System.IO.Path]::GetTempPath()) ("pester-cloudschedule-tests-{0}" -f [guid]::NewGuid().ToString('N'))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/NewCloudSchedule.Tests.ps1` around lines 15 - 25, The temp dir
name is fixed via $script:TempDir causing parallel test collisions; change how
$script:TempDir is constructed (and consequently $script:TempScript and the
claude.cmd path) to include a unique suffix (e.g., a GUID, timestamp, or
[System.IO.Path]::GetRandomFileName()) when calling Join-Path so each test run
gets its own directory, then create that directory as before and use the unique
path everywhere cleanup and file writes reference
$script:TempDir/$script:TempScript.

@Kensan196948G
Kensan196948G merged commit 2173216 into main Apr 21, 2026
8 checks passed
@Kensan196948G
Kensan196948G deleted the test/new-cloud-schedule-unit-tests-v3.2.65 branch April 21, 2026 14:31
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.

test(P2): New-CloudSchedule.ps1 ユニットテスト追加 — Build-CreatePrompt / New-LoopPreset

2 participants