feat: enhance test-task-generate with Gemini enrichment and planning-notes mechanism

Implement two major enhancements to test generation workflow:

1. Gemini Test Enhancement (Phase 1.5)
   - Add Gemini CLI analysis for comprehensive test suggestions
   - Generate enriched test specifications for L1-L3 test layers
   - Focus on API contracts, integration patterns, error scenarios
   - Create gemini-enriched-suggestions.md as artifact

2. Planning Notes Mechanism (test-planning-notes.md)
   - Similar to plan.md's planning-notes pattern
   - Record Test Intent (Phase 1)
   - Embed complete Gemini enrichment (Phase 1.5)
   - Track consolidated test requirements
   - Support N+1 context with decisions and deferred items

Implementation Details:
   - Created Gemini prompt template: test-suggestions-enhancement.txt
   - Enhanced test-task-generate.md with Phase 1, 1.5, 2 logic
   - Gemini content embedded in planning-notes for single source of truth
   - test-action-planning-agent reads both TEST_ANALYSIS_RESULTS.md and test-planning-notes.md
   - Backward compatible: Phase 1.5 is optional enhancement

Benefits:
   - Comprehensive test coverage (API, integration, error scenarios)
   - Full traceability of test planning process
   - Consolidated context in one file for easy review
   - Preserved Gemini output as independent artifact
This commit is contained in:
catlog22
2026-01-30 23:51:57 +08:00
parent 81725c94b1
commit f1324a0bc8
3 changed files with 463 additions and 4 deletions

View File

@@ -38,17 +38,209 @@ Phase 1: Context Preparation (Command)
│ ├─ session_metadata_path
│ ├─ test_analysis_results_path (REQUIRED)
│ └─ test_context_package_path
─ Provide metadata (session_id, source_session_id)
─ Provide metadata (session_id, source_session_id)
└─ Create test-planning-notes.md (User Intent section)
Phase 1.5: Gemini Test Enhancement (Command)
├─ Invoke cli-execution-agent for Gemini analysis
├─ Read TEST_ANALYSIS_RESULTS.md for context
├─ Generate enriched test suggestions (API, integration, error scenarios)
└─ Record enriched suggestions to test-planning-notes.md (Gemini Enhancement section)
Phase 2: Test Document Generation (Agent)
├─ Load TEST_ANALYSIS_RESULTS.md as primary requirements source
├─ Load TEST_ANALYSIS_RESULTS.md (with enriched suggestions)
├─ Load test-planning-notes.md (consolidated context)
├─ Generate Test Task JSON Files (.task/IMPL-*.json)
│ ├─ IMPL-001: Test generation (L1-L3 layers, project-specific templates)
│ ├─ IMPL-001.3: Code validation gate (L0 + AI issue detection)
│ ├─ IMPL-001.5: Test quality gate (anti-patterns + coverage)
│ └─ IMPL-002: Test execution & fix cycle
├─ Create IMPL_PLAN.md (test_session variant)
─ Generate TODO_LIST.md with test phase indicators
─ Generate TODO_LIST.md with test phase indicators
└─ Update test-planning-notes.md (Task Generation section)
```
---
## Phase 1: Context Preparation
**Purpose**: Assemble test session paths, load test analysis context, and create test-planning-notes.md.
**Execution Steps**:
1. Parse `--session` flag to get test session ID
2. Load `workflow-session.json` for session metadata
3. Verify `TEST_ANALYSIS_RESULTS.md` exists (from test-concept-enhanced)
4. Load `test-context-package.json` for coverage data
5. Create `test-planning-notes.md` with initial context
**After Phase 1**: Initialize test-planning-notes.md
```javascript
// Create test-planning-notes.md with N+1 context support
const testPlanningNotesPath = `.workflow/active/${testSessionId}/test-planning-notes.md`
const sessionMetadata = JSON.parse(Read(`.workflow/active/${testSessionId}/workflow-session.json`))
const testAnalysis = Read(`.workflow/active/${testSessionId}/.process/TEST_ANALYSIS_RESULTS.md`)
const sourceSessionId = sessionMetadata.source_session_id || 'N/A'
// Extract key info from TEST_ANALYSIS_RESULTS.md
const projectType = testAnalysis.match(/Project Type:\s*(.+)/)?.[1] || 'Unknown'
const testFramework = testAnalysis.match(/Test Framework:\s*(.+)/)?.[1] || 'Unknown'
const coverageTarget = testAnalysis.match(/Coverage Target:\s*(.+)/)?.[1] || '80%'
Write(testPlanningNotesPath, `# Test Planning Notes
**Session**: ${testSessionId}
**Source Session**: ${sourceSessionId}
**Created**: ${new Date().toISOString()}
## Test Intent (Phase 1)
- **PROJECT_TYPE**: ${projectType}
- **TEST_FRAMEWORK**: ${testFramework}
- **COVERAGE_TARGET**: ${coverageTarget}
- **SOURCE_SESSION**: ${sourceSessionId}
---
## Context Findings (Phase 1)
### Files with Coverage Gaps
(Extracted from TEST_ANALYSIS_RESULTS.md)
### Test Framework & Conventions
- Framework: ${testFramework}
- Coverage Target: ${coverageTarget}
---
## Gemini Enhancement (Phase 1.5)
(To be filled by Gemini analysis)
### Enhanced Test Suggestions
- **L1 (Unit)**: (Pending)
- **L2.1 (Integration)**: (Pending)
- **L2.2 (API Contracts)**: (Pending)
- **L2.4 (External APIs)**: (Pending)
- **L2.5 (Failure Modes)**: (Pending)
### Gemini Analysis Summary
(Pending enrichment)
---
## Consolidated Test Requirements (Phase 2 Input)
1. [Context] ${testFramework} framework conventions
2. [Context] ${coverageTarget} coverage target
---
## Task Generation (Phase 2)
(To be filled by test-action-planning-agent)
## N+1 Context
### Decisions
| Decision | Rationale | Revisit? |
|----------|-----------|----------|
### Deferred
- [ ] (For N+1)
`)
---
## Phase 1.5: Gemini Test Enhancement
**Purpose**: Enrich test specifications with comprehensive test suggestions and record to test-planning-notes.md.
**Execution Steps**:
1. Load TEST_ANALYSIS_RESULTS.md from `.workflow/active/{test-session-id}/.process/`
2. Invoke `cli-execution-agent` with Gemini for test enhancement analysis
3. Use template: `~/.claude/workflows/cli-templates/prompts/test/test-suggestions-enhancement.txt`
4. Gemini generates enriched test suggestions across L1-L3 layers gemini-enriched-suggestions.md
5. Record enriched suggestions to test-planning-notes.md (Gemini Enhancement section)
**Agent Invocation**:
```javascript
Task(
subagent_type="cli-execution-agent",
run_in_background=false,
description="Enhance test specifications with Gemini analysis",
prompt=`
## Task Objective
Analyze TEST_ANALYSIS_RESULTS.md and generate enriched test suggestions using Gemini CLI
## Input Files
- Read: .workflow/active/{test-session-id}/.process/TEST_ANALYSIS_RESULTS.md
- Extract: Project type, test framework, coverage gaps, identified files
## Gemini Analysis Execution
Execute Gemini with comprehensive test enhancement prompt:
ccw cli -p "[comprehensive test prompt]" --tool gemini --mode analysis --rule analysis-test-strategy-enhancement --cd .workflow/active/{test-session-id}/.process
## Expected Output
Generate gemini-enriched-suggestions.md with structured test enhancements:
- L1 (Unit Tests): Edge cases, boundaries, error paths
- L2.1 (Integration): Module interactions, dependency injection
- L2.2 (API Contracts): Request/response, validation, error responses
- L2.4 (External APIs): Mock strategies, failure scenarios, timeouts
- L2.5 (Failure Modes): Exception handling, error propagation, recovery
## Validation
- gemini-enriched-suggestions.md created and complete
- Suggestions are actionable and specific (not generic)
- All L1-L3 layers covered
`
)
```
**Output**: gemini-enriched-suggestions.md (complete Gemini analysis)
**After Phase 1.5**: Update test-planning-notes.md with Gemini enhancement findings
```javascript
// Read enriched suggestions from gemini-enriched-suggestions.md
const enrichedSuggestionsPath = `.workflow/active/${testSessionId}/.process/gemini-enriched-suggestions.md`
const enrichedSuggestions = Read(enrichedSuggestionsPath)
// Update Phase 1.5 section in test-planning-notes.md with full enriched suggestions
Edit(testPlanningNotesPath, {
old: '## Gemini Enhancement (Phase 1.5)\n(To be filled by Gemini analysis)\n\n### Enhanced Test Suggestions\n- **L1 (Unit)**: (Pending)\n- **L2.1 (Integration)**: (Pending)\n- **L2.2 (API Contracts)**: (Pending)\n- **L2.4 (External APIs)**: (Pending)\n- **L2.5 (Failure Modes)**: (Pending)\n\n### Gemini Analysis Summary\n(Pending enrichment)',
new: `## Gemini Enhancement (Phase 1.5)
**Analysis Timestamp**: ${new Date().toISOString()}
**Template**: test-suggestions-enhancement.txt
**Output File**: .process/gemini-enriched-suggestions.md
### Enriched Test Suggestions (Complete Gemini Analysis)
${enrichedSuggestions}
### Gemini Analysis Summary
- **Status**: Enrichment complete
- **Layers Covered**: L1, L2.1, L2.2, L2.4, L2.5
- **Focus Areas**: API contracts, integration patterns, error scenarios, edge cases
- **Output Stored**: Full analysis in gemini-enriched-suggestions.md`
})
// Append Gemini constraints to consolidated test requirements
const geminiConstraints = [
'[Gemini] Implement all suggested L1 edge cases and boundary tests',
'[Gemini] Apply L2.1 module interaction patterns from analysis',
'[Gemini] Follow L2.2 API contract test matrix from analysis',
'[Gemini] Use L2.4 external API mock strategies from analysis',
'[Gemini] Cover L2.5 error scenarios from analysis'
]
const currentNotes = Read(testPlanningNotesPath)
const constraintCount = (currentNotes.match(/^\d+\./gm) || []).length
Edit(testPlanningNotesPath, {
old: '## Consolidated Test Requirements (Phase 2 Input)',
new: `## Consolidated Test Requirements (Phase 2 Input)
1. [Context] ${testFramework} framework conventions
2. [Context] ${coverageTarget} coverage target
${geminiConstraints.map((c, i) => `${i + 3}. ${c}`).join('\n')}`
})
```
---
@@ -70,8 +262,10 @@ IMPORTANT: This is TEST PLANNING ONLY - you are generating planning documents, N
Input:
- Session Metadata: .workflow/active/{test-session-id}/workflow-session.json
- TEST_ANALYSIS_RESULTS: .workflow/active/{test-session-id}/.process/TEST_ANALYSIS_RESULTS.md (REQUIRED)
- Test Planning Notes: .workflow/active/{test-session-id}/test-planning-notes.md (REQUIRED - contains Gemini enhancement findings)
- Test Context Package: .workflow/active/{test-session-id}/.process/test-context-package.json
- Context Package: .workflow/active/{test-session-id}/.process/context-package.json
- Enriched Suggestions: .workflow/active/{test-session-id}/.process/gemini-enriched-suggestions.md (for reference)
- Source Session Summaries: .workflow/active/{source-session-id}/.summaries/IMPL-*.md (if exists)
Output:
@@ -85,6 +279,15 @@ Workflow Type: test_session
Source Session: {source-session-id} (if exists)
MCP Capabilities: {exa_code, exa_web, code_index}
## CONSOLIDATED CONTEXT
**From test-planning-notes.md**:
- Test Intent: Project type, test framework, coverage target
- Context Findings: Coverage gaps, file analysis
- Gemini Enhancement: Complete enriched test suggestions (L1-L3 layers)
* Full analysis embedded in planning-notes.md
* API contracts, integration patterns, error scenarios
- Consolidated Requirements: Combined constraints from all phases
## YOUR SPECIFICATIONS
You are @test-action-planning-agent. Your complete test specifications are defined in:
d:\Claude_dms3\.claude\agents\test-action-planning-agent.md
@@ -148,6 +351,7 @@ This includes:
├── workflow-session.json # Session metadata
├── IMPL_PLAN.md # Test implementation plan
├── TODO_LIST.md # Task checklist
├── test-planning-notes.md # [NEW] Consolidated planning notes with full Gemini analysis
├── .task/
│ ├── IMPL-001.json # Test generation (L1-L3)
│ ├── IMPL-001.3-validation.json # Code validation gate (L0 + AI)
@@ -155,7 +359,8 @@ This includes:
│ └── IMPL-002.json # Test execution & fix cycle
└── .process/
├── test-context-package.json # Test coverage and patterns
── TEST_ANALYSIS_RESULTS.md # L0-L3 requirements (source for agent)
── gemini-enriched-suggestions.md # [NEW] Gemini-generated test enhancements
└── TEST_ANALYSIS_RESULTS.md # L0-L3 requirements (original from test-concept-enhanced)
```
### Task Summary