Repository navigation
test(v3.2.65): New-CloudSchedule.ps1 ユニットテスト追加 — Build-CreatePrompt / New-LoopPreset 23件 - #227
Conversation
… New-LoopPreset 23件 (#226) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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 の変更点(ユニットテスト追加)を追記 |
| # --- 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 |
There was a problem hiding this comment.
exit→return パッチの正規表現が「行頭が exit の行」しか置換しないため、New-CloudSchedule.ps1 側の if ($NonInteractive) { exit 0 } / ... { exit 0 } のようなインライン exit が残ります。BeforeAll で -NonInteractive を渡して dot-source しているので、このままだとテスト実行プロセス自体が exit で終了します(Pester が落ちる)。インライン exit も確実に無効化できる置換(例: より広いパターン、AST で ExitStatement を差し替え等)にしてください。
| $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' |
There was a problem hiding this comment.
一時ディレクトリが固定名 pester-cloudschedule-tests になっているため、並列実行や前回実行の残骸がある環境で衝突しやすいです。Pester の $TestDrive を使うか、$PID/GUID を含めたユニークなディレクトリ名にして競合を避けてください。
| $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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
CHANGELOG.mdREADME.mdTASKS.mdtests/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.mdCHANGELOG.mdREADME.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 と実施内容の紐づけが明確で、履歴管理として十分です。
| | バージョン | **v3.2.65** (New-CloudSchedule.ps1 ユニットテスト 23件追加) — 旧: v3.2.64 (管理OFFA/ONA/DELA操作をプロジェクトスコープに限定) | | ||
| | テスト | **703件** — Pester (Unit 18 / Integration 11 / Smoke 1) | |
There was a problem hiding this comment.
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.
| $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 |
There was a problem hiding this comment.
一時ディレクトリ名が固定で並列実行時に競合します
$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.
概要
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 追加テスト結果
影響範囲
テストファイル追加のみ。既存スクリプトへの変更なし。
Closes
Closes #226
🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
テスト
バグ修正
ドキュメント