feat(guard): enhance build architecture guard with Android protection and feedback system

- Add Android-specific build validation for asset management and API routing
- Implement feedback collection system for continuous guard improvement
- Enhance sensitive path detection to include capacitor-assets.config.json and resources/
- Add Android change detection with specific testing guidance
- Integrate feedback analysis command for maintainer insights
- Update guard rules to reflect enhanced Android build system complexity

The guard now protects sophisticated Android build features including asset validation,
resource generation, and platform-specific API routing while collecting usage data
for continuous improvement.
This commit is contained in:
Matthew Raymer
2025-08-22 08:43:21 +00:00
parent 8fc9118d50
commit 9f2ef24b2b
4 changed files with 291 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ alwaysApply: false
# Build Architecture Guard Directive
**Author**: Matthew Raymer
**Date**: 2025-08-20
**Date**: 2025-08-22
**Status**: 🎯 **ACTIVE** - Build system protection guidelines
## Purpose
@@ -17,6 +17,8 @@ could break the multi-platform build pipeline, deployment processes, or
development workflow. This directive ensures all build system modifications
follow proper review, testing, and documentation procedures.
**Note**: Recent Android build system enhancements (2025-08-22) include sophisticated asset validation, platform-specific API routing, and automatic resource regeneration. These features require enhanced testing and validation procedures.
## Protected Architecture Components
### Core Build Infrastructure
@@ -29,6 +31,14 @@ follow proper review, testing, and documentation procedures.
- **Docker Configuration**: `Dockerfile`, `docker-compose.yml`
- **Environment Files**: `.env.*`, `.nvmrc`, `.node-version`
### Android-Specific Build Validation
- **Asset Validation Scripts**: `validate_android_assets()` function and resource checking
- **Resource Generation**: `capacitor-assets` integration and verification
- **Platform-Specific IP Handling**: Android emulator vs physical device API routing
- **Build Mode Validation**: Development/test/production mode handling
- **Resource Fallback Logic**: Automatic regeneration of missing Android resources
### Critical Build Dependencies
- **Build Tools**: Vite, Capacitor, Electron, Android SDK, Xcode
@@ -54,6 +64,9 @@ follow proper review, testing, and documentation procedures.
- Environment variable changes
- Dependency version updates
- Platform-specific optimizations
- **Build script argument parsing**: New flag handling (--api-ip, --auto-run, --deploy)
- **Platform-specific environment overrides**: Android API server IP customization
- **Asset regeneration logic**: Automatic fallback for missing Android resources
**Process**: Code review + platform testing + documentation update
@@ -115,6 +128,12 @@ follow proper review, testing, and documentation procedures.
- **Android**: `npm run build:android:test` or `:prod` - confirm assets copied
- **iOS**: `npm run build:ios:test` or `:prod` - verify build succeeds
### Android Platform (Enhanced)
- **Development Mode**: `npm run build:android --dev` - verify 10.0.2.2 API routing
- **Custom IP Mode**: `npm run build:android --dev --api-ip 192.168.1.100` - verify custom IP
- **Asset Validation**: `npm run build:android --assets` - verify resource generation
- **Deploy Mode**: `npm run build:android --deploy` - verify device deployment
### Desktop Platform
- **Electron**: `npm run build:electron:dev` and packaging for target OS
@@ -194,6 +213,16 @@ follow proper review, testing, and documentation procedures.
- **Trigger**: New base image, build args
- **Validation**: Build image locally; run container; list produced `/dist`
### Android Asset Management
- **Trigger**: Changes to `validate_android_assets()` function or resource paths
- **Validation**: Run `npm run build:android --assets` and verify all mipmap/drawable resources
- **Risk**: Missing splash screens or app icons causing build failures
### Android API Routing
- **Trigger**: Changes to Android-specific API server IP logic
- **Validation**: Test both emulator (10.0.2.2) and custom IP modes
- **Risk**: API connectivity failures on different device types
### Signing/Notarization
- **Trigger**: Cert path/profiles
@@ -226,6 +255,13 @@ follow proper review, testing, and documentation procedures.
- **Desktop**: `npm run build:electron:dev` and packaging commands
- **Clean**: Run relevant `clean:*` scripts and verify re-build works
### Android-Specific Rollback Verification
- **Asset Generation**: `npm run build:android --assets` - verify resources regenerate
- **API Routing**: Test both `--dev` and `--dev --api-ip <custom>` modes
- **Resource Validation**: Check `android/app/src/main/res/` for all required assets
- **Build Modes**: Verify development, test, and production modes all work
- **Resource Fallback**: Confirm missing resources trigger automatic regeneration
## ADR Trigger List
Raise an ADR when you propose any of:
@@ -236,6 +272,10 @@ Raise an ADR when you propose any of:
- **New service worker assembly** strategy or cache policy
- **New Docker base** or multi-stage pipeline
- **Relocation of build outputs** or directory conventions
- **New Android build modes** or argument parsing logic
- **Changes to asset validation** or resource generation strategy
- **Modifications to platform-specific API routing** (Android emulator vs physical)
- **New Android deployment strategies** or device management
**ADR must include**: motivation, alternatives, risks, validation plan, rollback,
doc diffs.
@@ -285,6 +325,44 @@ Raise an ADR when you propose any of:
- [ ] **Team Review**: Have appropriate stakeholders been consulted?
- [ ] **CI/CD**: Will this pass the build pipeline?
## Continuous Improvement & Feedback
### Feedback Collection
The Build Architecture Guard system includes feedback mechanisms to continuously improve its effectiveness:
- **User Feedback**: Script includes feedback prompts for guard improvements
- **Pattern Analysis**: Monitor which file patterns trigger false positives/negatives
- **Documentation Gaps**: Track which changes lack proper documentation
- **Testing Effectiveness**: Measure how often guard catches actual issues
### Feedback Integration Process
1. **Collect Feedback**: Monitor guard execution logs and user reports
2. **Analyze Patterns**: Identify common false positives or missed patterns
3. **Update Rules**: Modify `build_architecture_guard.mdc` based on feedback
4. **Enhance Script**: Update `build-arch-guard.sh` with new validations
5. **Test Changes**: Verify guard improvements don't introduce new issues
6. **Document Updates**: Update guard documentation with new patterns
### Feedback Categories
- **False Positives**: Files flagged as sensitive that shouldn't be
- **False Negatives**: Sensitive files that weren't caught
- **Missing Patterns**: New file types that should be protected
- **Overly Strict**: Patterns that are too restrictive
- **Documentation Gaps**: Missing guidance for specific change types
- **Testing Improvements**: Better validation procedures
### Feedback Reporting
When reporting guard issues, include:
- **File patterns** that triggered false positives/negatives
- **Build system changes** that weren't properly caught
- **Documentation gaps** in current guard rules
- **Testing procedures** that could be improved
- **User experience** issues with guard enforcement
---
**Status**: Active build system protection
@@ -292,4 +370,4 @@ Raise an ADR when you propose any of:
**Estimated Effort**: Ongoing vigilance
**Dependencies**: All build system components
**Stakeholders**: Development team, DevOps, Platform owners
**Next Review**: 2025-09-20
**Next Review**: 2025-09-22