# Execution Plan

## Detailed Analysis Summary

### Transformation Scope
- **Transformation Type**: Single-component code quality + test coverage improvement
- **Primary Changes**: Add tests, improve code quality, add CI/CD for existing Python scripts
- **Related Components**: cronjobs/*.py, tests/, GitHub Actions

### Change Impact Assessment
- **User-facing changes**: No (internal tooling only)
- **Structural changes**: No (no new components or architecture changes)
- **Data model changes**: No
- **API changes**: No
- **NFR impact**: Yes - test coverage and CI/CD improve reliability and maintainability

### Component Relationships
```
run_cronjob_every_10mins.py (core scheduler)
    ├── cronjob.json (config for all 3 roles)
    ├── team-workflow/*.py (job scripts)
    ├── team-admin/*.py (job scripts)
    └── team-code-expert/*.py (job scripts)

tests/ (new test infrastructure)
    └── test_run_cronjob.py (unit tests for scheduler)

.github/workflows/
    └── python-ci.yml (new CI pipeline)

pyproject.toml (new dependency management)
```

### Risk Assessment
- **Risk Level**: Low (additive changes, no breaking modifications)
- **Rollback Complexity**: Easy (git revert, no deployment changes)
- **Testing Complexity**: Moderate (need to mock subprocess and Feishu API calls)

## Workflow Visualization

```mermaid
flowchart TD
    Start(["User Request"])
    
    subgraph INCEPTION["🔵 INCEPTION PHASE"]
        WD["Workspace Detection<br/><b>COMPLETED</b>"]
        RE["Reverse Engineering<br/><b>COMPLETED</b>"]
        RA["Requirements Analysis<br/><b>COMPLETED</b>"]
        US["User Stories<br/><b>SKIP</b>"]
        WP["Workflow Planning<br/><b>COMPLETED</b>"]
        AD["Application Design<br/><b>SKIP</b>"]
        UP["Units Planning<br/><b>EXECUTE</b>"]
    end
    
    subgraph CONSTRUCTION["🟢 CONSTRUCTION PHASE"]
        FD["Functional Design<br/><b>SKIP</b>"]
        NFRA["NFR Requirements<br/><b>SKIP</b>"]
        NFRD["NFR Design<br/><b>SKIP</b>"]
        ID["Infrastructure Design<br/><b>SKIP</b>"]
        CP["Code Planning<br/><b>EXECUTE</b>"]
        CG["Code Generation<br/><b>EXECUTE</b>"]
        BT["Build and Test<br/><b>EXECUTE</b>"]
    end
    
    subgraph OPERATIONS["🟡 OPERATIONS PHASE"]
        OPS["Operations<br/><b>PLACEHOLDER</b>"]
    end
    
    Start --> WD
    WD -.-> RE
    WD --> RA
    RE --> RA
    
    RA --> US
    RA --> WP
    US -.-> WP
    WP --> UP
    UP --> CP
    
    CP --> CG
    CG --> BT
    BT --> OPS
    BT --> End(["Complete"])
    OPS -.-> End
    
    style WD fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style RE fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style RA fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style WP fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style CP fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style CG fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style BT fill:#4CAF50,stroke:#1B5E20,stroke-width:3px,color:#fff
    style OPS fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    
    style US fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style AD fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style FD fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style NFRA fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style NFRD fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style ID fill:#BDBDBD,stroke:#424242,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    
    style INCEPTION fill:#BBDEFB,stroke:#1565C0,stroke-width:3px,color:#000
    style CONSTRUCTION fill:#C8E6C9,stroke:#2E7D32,stroke-width:3px,color:#000
    style OPERATIONS fill:#FFF59D,stroke:#F57F17,stroke-width:3px,color:#000
    style Start fill:#CE93D8,stroke:#6A1B9A,stroke-width:3px,color:#000
    style End fill:#CE93D8,stroke:#6A1B9A,stroke-width:3px,color:#000
    
    linkStyle default stroke:#333,stroke-width:2px
```

## Phases to Execute

### 🔵 INCEPTION PHASE
- [x] Workspace Detection — **COMPLETED** (Brownfield confirmed)
- [x] Reverse Engineering — **COMPLETED** (80+ files analyzed)
- [x] Requirements Analysis — **COMPLETED** (4 FR, 5 NFR)
- [x] User Stories — **SKIP** (Internal tooling, no user personas)
- [x] Workflow Planning — **COMPLETED** (This document)
- [ ] Application Design — **SKIP** (No new components, improvements within existing code)
- [ ] Units Planning — **EXECUTE** (Need to decompose 4 improvement areas into work units)
- [ ] Units Generation — **SKIP** (Merged into Code Planning phase)

### 🟢 CONSTRUCTION PHASE
- [ ] Functional Design — **SKIP** (No new business logic, existing functions well-defined)
- [ ] NFR Requirements — **SKIP** (Covered in requirements.md)
- [ ] NFR Design — **SKIP** (Covered in requirements.md)
- [ ] Infrastructure Design — **SKIP** (No new infrastructure)
- [ ] Code Planning — **EXECUTE** (ALWAYS) (Plan implementation approach for 4 units)
- [ ] Code Generation — **EXECUTE** (ALWAYS) (Generate real code for all 4 units)
- [ ] Build and Test — **EXECUTE** (ALWAYS) (Run tests, lint, verify)

### 🟡 OPERATIONS PHASE
- [ ] Operations — **PLACEHOLDER**

## Work Units

### Unit 1: Test Infrastructure (PRIORITY: HIGH)
- Create `pyproject.toml` with dependencies (pytest, pytest-cov, requests)
- Create `tests/conftest.py` with shared fixtures
- Create `tests/test_run_cronjob.py` for scheduler unit tests
- Create `tests/test_cron_expressions.py` for cron parsing tests

### Unit 2: CI/CD Pipeline (PRIORITY: HIGH)
- Create `.github/workflows/python-ci.yml` for lint + test on PRs
- Update `.pre-commit-config.yaml` to cover all Python files
- Update `ruff.toml` to include all Python files

### Unit 3: Code Quality Improvements (PRIORITY: MEDIUM)
- Refactor `run_cronjob_every_10mins.py`:
  - Add type annotations to all public functions
  - Extract hardcoded constants to config module
  - Add proper docstrings
  - Create `cronjobs/config.py` for shared constants

### Unit 4: Extended Test Coverage (PRIORITY: MEDIUM)
- Add tests for `import-dm-failed-job-analyze/main.py`
- Add tests for `daily-oncall-metrics/` scripts
- Add integration-style smoke tests

## Unit Update Sequence
1. **Unit 1 first** — Test infrastructure needed before writing tests for other units
2. **Unit 2 parallel** — CI pipeline doesn't depend on test implementation
3. **Unit 3 and Unit 4** — Can proceed after Unit 1, ideally in parallel

## Success Criteria
- **Primary Goal**: Achieve >80% test coverage on `run_cronjob_every_10mins.py`
- **Key Deliverables**: pyproject.toml, test suite, CI pipeline, refactored scheduler
- **Quality Gates**: ruff linting passes, pytest passes, CI green on PR
