ai-core-framework 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.claude-plugin/plugin.json +21 -0
  2. package/.codex-plugin/plugin.json +35 -0
  3. package/.cursor-plugin/plugin.json +22 -0
  4. package/README.md +173 -0
  5. package/bin/ai-core-framework.js +110 -0
  6. package/core/README.md +162 -0
  7. package/core/agents/README.md +32 -0
  8. package/core/agents/business-analyst.md +269 -0
  9. package/core/agents/developer.md +375 -0
  10. package/core/agents/qa-tester.md +477 -0
  11. package/core/agents/scrum-master.md +136 -0
  12. package/core/agents/tech-lead.md +345 -0
  13. package/core/config/backlog.schema.json +38 -0
  14. package/core/config/docs-policy.default.json +37 -0
  15. package/core/config/release.schema.json +120 -0
  16. package/core/config/ticket.schema.json +253 -0
  17. package/core/rules/00-global-rules.md +373 -0
  18. package/core/rules/01-git-workflow.md +388 -0
  19. package/core/rules/02-code-quality.md +77 -0
  20. package/core/rules/03-security.md +78 -0
  21. package/core/rules/04-documentation.md +72 -0
  22. package/core/rules/05-testing-mandatory.md +374 -0
  23. package/core/rules/06-approval-gates.md +388 -0
  24. package/core/rules/07-definition-of-ready.md +112 -0
  25. package/core/rules/08-definition-of-done.md +149 -0
  26. package/core/scripts/ai-core.sh +456 -0
  27. package/core/scripts/generate-views.sh +210 -0
  28. package/core/scripts/install-codex-prompts.sh +127 -0
  29. package/core/scripts/log-user-request.sh +113 -0
  30. package/core/scripts/setup-project.sh +183 -0
  31. package/core/scripts/sync-platforms.sh +322 -0
  32. package/core/scripts/validate-audit-log.sh +73 -0
  33. package/core/scripts/validate-docs.sh +365 -0
  34. package/core/scripts/validate-permissions.sh +132 -0
  35. package/core/scripts/validate-state.sh +611 -0
  36. package/core/scripts/workflow.sh +513 -0
  37. package/core/skills/README.md +21 -0
  38. package/core/skills/ai-core-commands/SKILL.md +86 -0
  39. package/core/skills/brainstorming/SKILL.md +40 -0
  40. package/core/skills/development-implement-task/SKILL.md +308 -0
  41. package/core/skills/executing-ticket/SKILL.md +28 -0
  42. package/core/skills/git-branch-status/SKILL.md +56 -0
  43. package/core/skills/git-cleanup-branches/SKILL.md +57 -0
  44. package/core/skills/git-scan-untracked/SKILL.md +50 -0
  45. package/core/skills/meta-generate-views/SKILL.md +54 -0
  46. package/core/skills/meta-request-log/SKILL.md +61 -0
  47. package/core/skills/meta-sprint-report/SKILL.md +59 -0
  48. package/core/skills/meta-sync-platforms/SKILL.md +53 -0
  49. package/core/skills/meta-ticket-health/SKILL.md +61 -0
  50. package/core/skills/meta-validate-audit-log/SKILL.md +42 -0
  51. package/core/skills/meta-validate-docs/SKILL.md +58 -0
  52. package/core/skills/meta-validate-permissions/SKILL.md +53 -0
  53. package/core/skills/meta-validate-state/SKILL.md +58 -0
  54. package/core/skills/planning-analyze-requirements/SKILL.md +471 -0
  55. package/core/skills/planning-backlog-status/SKILL.md +57 -0
  56. package/core/skills/planning-document-existing-requirements/SKILL.md +246 -0
  57. package/core/skills/planning-estimate-task/SKILL.md +60 -0
  58. package/core/skills/planning-groom-ticket/SKILL.md +442 -0
  59. package/core/skills/planning-mark-ready/SKILL.md +111 -0
  60. package/core/skills/planning-plan-refactor/SKILL.md +66 -0
  61. package/core/skills/planning-plan-sprint/SKILL.md +112 -0
  62. package/core/skills/planning-prioritize-backlog/SKILL.md +62 -0
  63. package/core/skills/planning-write-plan/SKILL.md +68 -0
  64. package/core/skills/project-detect-stack/SKILL.md +71 -0
  65. package/core/skills/project-discover-codebase/SKILL.md +74 -0
  66. package/core/skills/project-setup-project/SKILL.md +113 -0
  67. package/core/skills/qa-bug-status/SKILL.md +52 -0
  68. package/core/skills/qa-report-bug/SKILL.md +518 -0
  69. package/core/skills/qa-smoke-test/SKILL.md +387 -0
  70. package/core/skills/qa-triage-bug/SKILL.md +62 -0
  71. package/core/skills/qa-verify-fix/SKILL.md +446 -0
  72. package/core/skills/release-hotfix/SKILL.md +117 -0
  73. package/core/skills/release-release/SKILL.md +123 -0
  74. package/core/skills/release-rollback/SKILL.md +62 -0
  75. package/core/skills/review-create-pr/SKILL.md +418 -0
  76. package/core/skills/review-merge-pr/SKILL.md +425 -0
  77. package/core/skills/review-techlead-review/SKILL.md +547 -0
  78. package/core/skills/using-ai-core/SKILL.md +72 -0
  79. package/core/skills/verification-before-done/SKILL.md +35 -0
  80. package/core/skills/writing-implementation-plan/SKILL.md +45 -0
  81. package/core/templates/ci/ai-core-governance.yml +112 -0
  82. package/core/templates/ci/node-pnpm.yml +35 -0
  83. package/core/templates/pm/retrospective-template.md +47 -0
  84. package/core/templates/pm/sprint-plan-template.md +45 -0
  85. package/core/templates/pr/pull-request-template.md +247 -0
  86. package/core/templates/project/CODEOWNERS +11 -0
  87. package/core/templates/project/docs-policy.json +3 -0
  88. package/core/templates/project/project-config.yaml +137 -0
  89. package/core/templates/project/project-structure.yaml +76 -0
  90. package/core/templates/qa/bug-report-template.md +371 -0
  91. package/core/templates/qa/test-plan-template.md +57 -0
  92. package/core/templates/release/release-record-template.json +67 -0
  93. package/core/templates/requirements/PRD-template.md +58 -0
  94. package/core/templates/requirements/user-story-template.md +381 -0
  95. package/core/templates/technical/ADR-template.md +46 -0
  96. package/core/templates/technical/refactor-plan-template.md +84 -0
  97. package/core/templates/technical/tech-design-template.md +71 -0
  98. package/core/workflows/bug-lifecycle.md +56 -0
  99. package/core/workflows/feature-lifecycle.md +347 -0
  100. package/core/workflows/hotfix-lifecycle.md +65 -0
  101. package/core/workflows/sprint-lifecycle.md +56 -0
  102. package/lib/install-codex.js +85 -0
  103. package/package.json +36 -0
@@ -0,0 +1,374 @@
1
+ # 🔒 RULE 05: Testing Mandatory (Strict)
2
+
3
+ > **No code without tests**. Non-negotiable.
4
+ > Enforced by: CI coverage gates + tech-lead review + pre-commit hooks.
5
+
6
+ ---
7
+
8
+ ## 🎯 Core Principle
9
+
10
+ **Untested code = technical debt shipped to production.**
11
+
12
+ Tests are:
13
+ - Documentation for behavior
14
+ - Regression safety net
15
+ - Refactoring enabler
16
+ - Design feedback (hard to test = bad design)
17
+
18
+ ---
19
+
20
+ ## 🔒 Rules
21
+
22
+ ### RULE TEST-001: TDD mandatory
23
+
24
+ Mandatory workflow for every new feature/fix:
25
+
26
+ ```
27
+ 1. RED: Write failing test
28
+ - Test reflects AC scenario
29
+ - Run test → MUST fail
30
+ - Commit: test(TICKET-XXX): add failing test for <scenario>
31
+
32
+ 2. GREEN: Minimum code to pass
33
+ - Write simplest code to make test pass
34
+ - No extra features
35
+ - Run test → MUST pass
36
+ - Commit: feat(TICKET-XXX): implement <scenario>
37
+
38
+ 3. REFACTOR: Improve code
39
+ - Extract, rename, dedupe
40
+ - Tests must still pass
41
+ - Commit: refactor(TICKET-XXX): <what improved>
42
+ ```
43
+
44
+ **Evidence of TDD** in commit history:
45
+ - `test(...)` commit before `feat(...)` commit
46
+ - CI can check via commit order analysis
47
+
48
+ **Exception**: Exploratory spike tickets (explicit type: `spike`). Must convert to TDD when real implementation starts.
49
+
50
+ ### RULE TEST-002: Coverage thresholds
51
+
52
+ Configured in `config/project-config.yaml`:
53
+
54
+ | Metric | Threshold |
55
+ |--------|-----------|
56
+ | **Diff coverage** (new/changed lines in PR) | ≥ 80% |
57
+ | **Overall coverage** (whole codebase) | ≥ 70% |
58
+ | **Critical paths** (auth, payment, data) | ≥ 95% |
59
+
60
+ **Enforcement**:
61
+ - CI fails PR if diff coverage < 80%
62
+ - CI fails if overall drops > 1% from main
63
+ - Tech Lead review: critical path coverage ≥ 95%
64
+
65
+ **What counts as "covered"**:
66
+ - ✅ Line executed by test
67
+ - ✅ Branch taken (both true/false)
68
+ - ✅ Meaningful assertion on outcome
69
+
70
+ **What doesn't count**:
71
+ - ❌ Line executed but no assertion (hitting code without verifying)
72
+ - ❌ Mocked behavior only (must test real logic)
73
+ - ❌ `console.log` statements
74
+
75
+ ### RULE TEST-003: Test pyramid
76
+
77
+ Proportions:
78
+ ```
79
+ /\
80
+ /E2E\ 10% (critical user journeys only)
81
+ /------\
82
+ /Integra-\ 20% (API + DB + external mocks)
83
+ /tion \
84
+ /----------\
85
+ / Unit \ 70% (pure logic, fast, isolated)
86
+ /--------------\
87
+ ```
88
+
89
+ **Why**: Speed, reliability, cost.
90
+ - Unit: ms to run, 100% reliable
91
+ - Integration: sec, 99% reliable
92
+ - E2E: min, 95% reliable (flakiness risk)
93
+
94
+ ### RULE TEST-004: Test quality
95
+
96
+ Every test **MUST**:
97
+
98
+ - [ ] **Descriptive name**: `should_<expected>_when_<condition>`
99
+ - ✅ `should_return_401_when_token_expired`
100
+ - ❌ `testAuth`, `test1`
101
+
102
+ - [ ] **AAA structure**: Arrange, Act, Assert
103
+ ```javascript
104
+ it('should return 401 when token expired', async () => {
105
+ // Arrange
106
+ const expiredToken = createToken({ exp: Date.now() - 1000 });
107
+
108
+ // Act
109
+ const response = await request.get('/api/me')
110
+ .set('Authorization', `Bearer ${expiredToken}`);
111
+
112
+ // Assert
113
+ expect(response.status).toBe(401);
114
+ expect(response.body.error).toBe('TOKEN_EXPIRED');
115
+ });
116
+ ```
117
+
118
+ - [ ] **1 concept per test**: Multiple `expect` OK when they verify related state
119
+ - [ ] **No shared mutable state**: Each test independent, parallel-safe
120
+ - [ ] **Minimal mocks**: Test real code when possible. Mock only:
121
+ - External services (HTTP, DB in unit tests)
122
+ - Time (`Date.now()`)
123
+ - Randomness
124
+ - [ ] **Deterministic**: No flakiness. No `setTimeout` for "waiting".
125
+
126
+ ### RULE TEST-005: Coverage for every AC
127
+
128
+ Every AC scenario in the ticket **MUST** have corresponding test(s):
129
+
130
+ ```
131
+ Ticket AC:
132
+ Scenario 1: Happy path → Test 1
133
+ Scenario 2: Edge case → Test 2
134
+ Scenario 3: Error case → Test 3
135
+ ```
136
+
137
+ PR review checks: "AC coverage: N/N scenarios" MUST be 100%.
138
+
139
+ ### RULE TEST-006: No disabled tests
140
+
141
+ **MUST NOT** commit:
142
+ - `.skip`, `xit`, `describe.skip`, `it.skip`
143
+ - `@Disabled` (Java)
144
+ - `@pytest.mark.skip` (Python)
145
+ - Commented-out test files
146
+
147
+ **Exception**: If temporary skipping is required (known broken, fix in next ticket):
148
+ - Add `TICKET-XXX` in comment:
149
+ ```javascript
150
+ it.skip('TICKET-099: should handle concurrent requests', () => {
151
+ // Skipped pending rate limiter refactor, see TICKET-099
152
+ });
153
+ ```
154
+ - Create the follow-up ticket
155
+ - Max 1 sprint for skip duration
156
+
157
+ ### RULE TEST-007: Failing tests block merge
158
+
159
+ **MUST NOT** merge PR with failing tests. Even "unrelated flaky tests".
160
+
161
+ If test is flaky → fix flakiness first (add to tech-debt backlog if can't fix immediately).
162
+
163
+ ### RULE TEST-008: Bug fix requires regression test
164
+
165
+ Every bug fix **MUST** include test that:
166
+ 1. Fails before fix
167
+ 2. Passes after fix
168
+ 3. Named clearly references the bug: `should_<correct_behavior>_regression_TICKET-XXX`
169
+
170
+ Example:
171
+ ```javascript
172
+ describe('login endpoint - regression tests', () => {
173
+ it('should handle email with + character - regression TICKET-089', async () => {
174
+ // This test prevents regression of bug where + in email caused 500
175
+ const response = await login('user+tag@example.com', 'password');
176
+ expect(response.status).toBe(200);
177
+ });
178
+ });
179
+ ```
180
+
181
+ ### RULE TEST-009: Critical paths require extra rigor
182
+
183
+ **Critical paths** (authentication, authorization, payments, PII handling):
184
+
185
+ - Coverage ≥ 95%
186
+ - Include security tests:
187
+ - Privilege escalation attempts
188
+ - Injection attempts
189
+ - Rate limit bypass attempts
190
+ - Include concurrency tests (race conditions)
191
+ - Include failure mode tests:
192
+ - What if DB is down?
193
+ - What if external service is slow?
194
+ - What if token is malformed?
195
+
196
+ ### RULE TEST-010: Performance tests for hot paths
197
+
198
+ Endpoints on critical user flow **MUST** have performance tests:
199
+
200
+ - **p50** (median): < 200ms
201
+ - **p95**: < 500ms
202
+ - **p99**: < 1000ms
203
+
204
+ Thresholds are customizable in `config/project-config.yaml`.
205
+
206
+ CI runs perf tests on main branch, alerts if regression > 20%.
207
+
208
+ ### RULE TEST-011: Test data management
209
+
210
+ - **MUST NOT** use production data in tests
211
+ - **MUST NOT** commit real PII (even test accounts)
212
+ - Use factories/builders for test data:
213
+ ```javascript
214
+ const user = userFactory.build({ email: 'test@example.com' });
215
+ ```
216
+ - Seed data deterministic, idempotent
217
+
218
+ ### RULE TEST-012: Test types matrix
219
+
220
+ | Ticket Type | Unit | Integration | E2E | Security | Performance |
221
+ |-------------|------|-------------|-----|----------|-------------|
222
+ | Feature (UI) | ✓ | ✓ | ✓ (if critical) | - | - |
223
+ | Feature (API) | ✓ | ✓ | - | ✓ (if sensitive) | ✓ (if hot path) |
224
+ | Bug fix | ✓ (regression) | ✓ (if integration bug) | - | - | - |
225
+ | Refactor | ✓ (existing preserved) | - | - | - | ✓ (if hot path) |
226
+ | Security fix | ✓ | ✓ | - | ✓ (mandatory) | - |
227
+ | Performance fix | ✓ | - | - | - | ✓ (mandatory) |
228
+
229
+ ---
230
+
231
+ ## 🛠️ Required Test Infrastructure
232
+
233
+ ### Unit tests
234
+ - Framework: Project-specific (Vitest/Jest/Pytest/JUnit)
235
+ - Run: `pnpm test:unit` (or equivalent)
236
+ - Fast: < 10 sec for whole suite
237
+ - Parallel-safe
238
+
239
+ ### Integration tests
240
+ - Framework: Same as unit, with extended setup
241
+ - DB: Test container (testcontainers, Docker) or in-memory (SQLite)
242
+ - External services: Mocked (MSW, nock) or test containers
243
+ - Run: `pnpm test:integration`
244
+
245
+ ### E2E tests
246
+ - Framework: Playwright (recommended) or Cypress
247
+ - Environment: Staging-like
248
+ - Run: `pnpm test:e2e`
249
+ - Only run on PR + nightly
250
+
251
+ ### Coverage tool
252
+ - Collect coverage: during unit + integration tests
253
+ - Report format: `lcov` + HTML
254
+ - Upload to Codecov/Coveralls (optional)
255
+
256
+ ---
257
+
258
+ ## 🔧 CI Configuration (example GitHub Actions)
259
+
260
+ ```yaml
261
+ name: Tests
262
+ on: [pull_request]
263
+
264
+ jobs:
265
+ unit:
266
+ runs-on: ubuntu-latest
267
+ steps:
268
+ - uses: actions/checkout@v4
269
+ - uses: pnpm/action-setup@v2
270
+ - run: pnpm install
271
+ - run: pnpm test:unit --coverage
272
+ - name: Check coverage threshold
273
+ run: |
274
+ coverage=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
275
+ if (( $(echo "$coverage < 70" | bc -l) )); then
276
+ echo "❌ Coverage $coverage% below 70% threshold"
277
+ exit 1
278
+ fi
279
+ - name: Check diff coverage
280
+ run: pnpm run coverage:diff
281
+
282
+ integration:
283
+ runs-on: ubuntu-latest
284
+ services:
285
+ postgres:
286
+ image: postgres:15
287
+ steps:
288
+ - uses: actions/checkout@v4
289
+ - run: pnpm install
290
+ - run: pnpm test:integration
291
+
292
+ e2e:
293
+ runs-on: ubuntu-latest
294
+ steps:
295
+ - uses: actions/checkout@v4
296
+ - run: pnpm install
297
+ - run: pnpm test:e2e
298
+ ```
299
+
300
+ ---
301
+
302
+ ## 💡 Testing Anti-patterns
303
+
304
+ ❌ **Tautological tests** (test mocks its own mock):
305
+ ```javascript
306
+ it('should call service', () => {
307
+ const spy = vi.spyOn(service, 'doThing');
308
+ controller.handle();
309
+ expect(spy).toHaveBeenCalled(); // Useless - just verifies wiring
310
+ });
311
+ ```
312
+ ✅ Test real behavior and outcome.
313
+
314
+ ❌ **Over-mocking**:
315
+ ```javascript
316
+ // Don't mock everything
317
+ vi.mock('../user-service');
318
+ vi.mock('../email-service');
319
+ vi.mock('../token-service');
320
+ // Now you're testing mocks, not code
321
+ ```
322
+ ✅ Mock boundaries (external services only).
323
+
324
+ ❌ **Brittle selectors** in E2E:
325
+ ```javascript
326
+ await page.click('.btn-primary.mt-4.px-6'); // ❌ Breaks on CSS change
327
+ ```
328
+ ✅ Use data-testid: `await page.click('[data-testid="submit-btn"]')`
329
+
330
+ ❌ **Copy-paste tests**:
331
+ ```javascript
332
+ it('test 1', () => { /* nearly identical */ });
333
+ it('test 2', () => { /* nearly identical */ });
334
+ ```
335
+ ✅ Use `it.each`:
336
+ ```javascript
337
+ it.each([
338
+ { input: 'a', expected: 1 },
339
+ { input: 'b', expected: 2 },
340
+ ])('should return $expected for $input', ({ input, expected }) => {
341
+ expect(fn(input)).toBe(expected);
342
+ });
343
+ ```
344
+
345
+ ---
346
+
347
+ ## 🚨 Violation Consequences
348
+
349
+ | Violation | Consequence |
350
+ |-----------|-------------|
351
+ | Committed code without test | CI blocks PR (coverage < 80% diff) |
352
+ | Disabled test without ticket | PR review rejects |
353
+ | Flaky test ignored | Tech-debt ticket mandatory |
354
+ | Production data in test | IMMEDIATE: remove, rotate if PII, incident report |
355
+ | Mock-heavy tests | Tech-lead flags in review, refactor required |
356
+
357
+ ---
358
+
359
+ ## 📊 Metrics to Track
360
+
361
+ - Coverage trend (weekly)
362
+ - Test suite duration trend (weekly)
363
+ - Flaky test count (weekly)
364
+ - Bugs found in production that had no regression test (post-mortem)
365
+ - TDD adherence (commit order analysis)
366
+
367
+ Dashboard: `/sprint-report --tests`
368
+
369
+ ---
370
+
371
+ **Version**: 1.0.0
372
+ **Last updated**: 2026-04-18
373
+ **Maintainer**: Tech Lead + QA Lead
374
+ **Next review**: End of each sprint