|
| 1 | +# Testing & Metrics Guide |
| 2 | + |
| 3 | +The UI5 Guidelines plugin uses a unified test framework for structure validation, triggering tests, and performance checks. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Run all tests |
| 9 | +npm test |
| 10 | + |
| 11 | +# Specific test suites |
| 12 | +npm run test:structure # Plugin structure validation |
| 13 | +npm run test:triggering # Skill triggering accuracy |
| 14 | +npm run test:performance # Context budget checks |
| 15 | +``` |
| 16 | + |
| 17 | +## Test Suites |
| 18 | + |
| 19 | +### 1. Structure Tests |
| 20 | + |
| 21 | +Validates plugin integrity: |
| 22 | +- ✅ `plugin.json` is valid JSON |
| 23 | +- ✅ All referenced skills exist |
| 24 | +- ✅ SKILL.md files have proper YAML frontmatter |
| 25 | +- ✅ No broken internal links |
| 26 | + |
| 27 | +### 2. Triggering Tests |
| 28 | + |
| 29 | +Validates skill selection accuracy: |
| 30 | +- Test cases defined in `test/fixtures/trigger-cases.json` |
| 31 | +- Checks skills trigger on appropriate prompts |
| 32 | +- Reports accuracy (target: >90%) |
| 33 | + |
| 34 | +**Add test cases when**: |
| 35 | +- A skill doesn't trigger when expected |
| 36 | +- New triggering keywords are added |
| 37 | + |
| 38 | +### 3. Performance Tests |
| 39 | + |
| 40 | +Validates context budget: |
| 41 | +- Main skill files under 900 lines (warning >700) |
| 42 | +- Total context reasonable (<3000 lines) |
| 43 | +- Large skills use reference files |
| 44 | + |
| 45 | +## Metrics |
| 46 | + |
| 47 | +### View Analytics |
| 48 | + |
| 49 | +```bash |
| 50 | +# Load sample data (for testing) |
| 51 | +npm run seed-metrics |
| 52 | + |
| 53 | +# View dashboard |
| 54 | +npm run metrics # Last 7 days |
| 55 | +npm run metrics:week # Last 7 days |
| 56 | +npm run metrics:month # Last 30 days |
| 57 | +npm run metrics:optimize # With optimization tips |
| 58 | +``` |
| 59 | + |
| 60 | +### Tracked Data |
| 61 | + |
| 62 | +The plugin tracks (stored in `.metrics/usage.jsonl`, gitignored): |
| 63 | +- Skill invocations |
| 64 | +- Context size (lines & tokens) |
| 65 | +- Session IDs |
| 66 | +- Timestamps |
| 67 | + |
| 68 | +### Metrics Output |
| 69 | + |
| 70 | +``` |
| 71 | +📊 UI5 Guidelines Plugin - Usage Analytics (Last 7 days) |
| 72 | +
|
| 73 | +Overall Stats: |
| 74 | + Total sessions: 45 |
| 75 | + Total skill invocations: 128 |
| 76 | + Average context: 2,156 lines (~8,624 tokens) |
| 77 | +
|
| 78 | +Per-Skill Breakdown: |
| 79 | + ui5-best-practices: 48 invocations (37.5%) |
| 80 | + ui5-typescript-expert: 42 invocations (32.8%) |
| 81 | + ui5-integration-cards: 38 invocations (29.7%) |
| 82 | +``` |
| 83 | + |
| 84 | +## Test Configuration |
| 85 | + |
| 86 | +### Matching Algorithm |
| 87 | + |
| 88 | +Configuration in `test/config/matching-config.json`: |
| 89 | + |
| 90 | +```json |
| 91 | +{ |
| 92 | + "weights": { |
| 93 | + "keywordMatch": 3, |
| 94 | + "exactPhrase": 10, |
| 95 | + "wordOverlap": 0.2 |
| 96 | + }, |
| 97 | + "ui5Terms": ["ui5", "sapui5", "openui5", ...], |
| 98 | + "antiPatterns": ["react hook", "python", "django", ...], |
| 99 | + "exactPhrases": ["component metadata", "minui5version"] |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +**Tune weights** to adjust skill selection accuracy. |
| 104 | + |
| 105 | +## Adding Test Cases |
| 106 | + |
| 107 | +Edit `test/fixtures/trigger-cases.json`: |
| 108 | + |
| 109 | +```json |
| 110 | +{ |
| 111 | + "tests": [ |
| 112 | + { |
| 113 | + "prompt": "How do I set up async module loading?", |
| 114 | + "expected_skill": "ui5-best-practices", |
| 115 | + "should_trigger": true |
| 116 | + }, |
| 117 | + { |
| 118 | + "prompt": "React hooks tutorial", |
| 119 | + "expected_skill": null, |
| 120 | + "should_trigger": false, |
| 121 | + "reason": "React, not UI5" |
| 122 | + } |
| 123 | + ] |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Current Test Results |
| 128 | + |
| 129 | +**Structure**: 16/16 passing (100%) |
| 130 | +**Triggering**: 45/46 passing (97.8%) |
| 131 | +**Performance**: 6/7 passing |
| 132 | + |
| 133 | +## Troubleshooting |
| 134 | + |
| 135 | +### Low Triggering Accuracy |
| 136 | + |
| 137 | +1. Add missing keywords to skill YAML frontmatter |
| 138 | +2. Update `test/config/matching-config.json` weights |
| 139 | +3. Add specific test cases |
| 140 | + |
| 141 | +### Slow Tests |
| 142 | + |
| 143 | +1. Check test framework isn't loading unnecessary files |
| 144 | +2. Reduce number of test cases if needed |
| 145 | +3. Use `npm run test:triggering` for quick checks |
| 146 | + |
| 147 | +## Test Framework Details |
| 148 | + |
| 149 | +**Technology**: TypeScript ESM with strict mode |
| 150 | + |
| 151 | +**Structure**: |
| 152 | +``` |
| 153 | +test/ |
| 154 | +├── index.ts # Test runner |
| 155 | +├── types.ts # Type definitions |
| 156 | +├── lib/ |
| 157 | +│ └── test-framework.ts # Core test framework |
| 158 | +├── suites/ |
| 159 | +│ ├── structure.test.ts # Structure validation |
| 160 | +│ ├── triggering.test.ts # Triggering accuracy |
| 161 | +│ └── performance.test.ts # Context budget |
| 162 | +├── config/ |
| 163 | +│ ├── matching-config.json # Matching algorithm config |
| 164 | +│ └── matching-config.ts # Config loader |
| 165 | +└── fixtures/ |
| 166 | + ├── trigger-cases.json # Test cases |
| 167 | + └── sample-metrics.jsonl # Sample analytics data |
| 168 | +``` |
| 169 | + |
| 170 | +## Best Practices |
| 171 | + |
| 172 | +✅ **DO**: |
| 173 | +- Run tests before committing |
| 174 | +- Add test cases for new keywords |
| 175 | +- Keep test execution fast (<5s) |
| 176 | +- Use sample metrics for analytics testing |
| 177 | + |
| 178 | +❌ **DON'T**: |
| 179 | +- Modify test framework without understanding impact |
| 180 | +- Commit `.metrics/` directory (gitignored) |
| 181 | +- Skip tests when changing skill descriptions |
| 182 | +- Hardcode test expectations in code (use JSON) |
0 commit comments