synapse-hub 2.4.3 → 2.6.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 (184) hide show
  1. package/.agents/agents/failure-analyst.md +13 -0
  2. package/.agents/agents/orchestrator.md +5 -2
  3. package/.agents/agents/pom-crafter.md +13 -0
  4. package/.agents/agents/quality-gatekeeper.md +21 -2
  5. package/.agents/agents/test-runner.md +11 -0
  6. package/.agents/rules/context-engineering.md +22 -102
  7. package/.agents/rules/mobile_appium_rules.md +19 -115
  8. package/.agents/rules/performance_testing_rules.md +18 -62
  9. package/.agents/rules/skill-precedence.md +24 -24
  10. package/.agents/rules/systematic-debugging.md +10 -27
  11. package/.agents/skills/lean-code-ladder/SKILL.md +12 -1
  12. package/.agents/skills/lean-impact-scoreboard/SKILL.md +48 -0
  13. package/.agents/skills/lean-impact-scoreboard/examples/sample_benchmark_gain.md +20 -0
  14. package/.agents/skills/lean-impact-scoreboard/examples/sample_scoreboard.md +15 -0
  15. package/.agents/skills/repo-quality-audit/SKILL.md +68 -0
  16. package/.agents/skills/repo-quality-audit/examples/sample_audit_walkthrough.md +15 -0
  17. package/.agents/skills/repo-quality-audit/examples/sample_repo_audit.md +33 -0
  18. package/.agents/skills/senior-code-review/SKILL.md +90 -0
  19. package/.agents/skills/senior-code-review/examples/sample_review_walkthrough.md +29 -0
  20. package/.agents/skills/technical-debt-harvester/SKILL.md +70 -0
  21. package/.agents/skills/technical-debt-harvester/examples/sample_debt_ledger.md +25 -0
  22. package/.agents/skills/technical-debt-harvester/examples/sample_ledger_output.md +20 -0
  23. package/.agents/skills/token-and-context-optimizer/references/context_engineering_guide.md +49 -0
  24. package/.cursor/rules/synapse-qa.mdc +4 -3
  25. package/.cursorrules +1 -0
  26. package/.windsurfrules +1 -0
  27. package/AGENTS.md +57 -180
  28. package/CLAUDE.md +5 -0
  29. package/NOTICE +40 -4
  30. package/README.en.md +33 -13
  31. package/README.md +36 -16
  32. package/bin/agent-qa.js +3 -2
  33. package/docs/ARCHITECTURE.md +39 -11
  34. package/docs/CLI_REFERENCE.md +15 -1
  35. package/docs/adopted-ecosystem-tools.md +9 -0
  36. package/docs/research/agent_skill_training_analysis.md +1357 -0
  37. package/package.json +1 -3
  38. package/skills_manifest.json +39 -3
  39. package/synapse.config.json +3 -2
  40. package/templates/ai_bridges/CLAUDE.md +5 -0
  41. package/templates/ai_bridges/copilot-instructions.md +2 -0
  42. package/templates/ai_bridges/cursor_synapse_qa.mdc +4 -3
  43. package/templates/ai_bridges/windsurfrules +1 -0
  44. package/templates/welcome.html.tmpl +34 -25
  45. package/tools/.infer_baseline.json +7 -1079
  46. package/tools/TOOLS_RUNBOOK.md +182 -13
  47. package/tools/__init__.py +1 -1
  48. package/tools/agent_canary.py +4 -4
  49. package/tools/analyze_project.py +2 -2
  50. package/tools/api_fuzzer.py +4 -4
  51. package/tools/auto_heal.py +14 -2
  52. package/tools/auto_heal_reflexion.py +172 -0
  53. package/tools/browser_helpers.js +57 -2
  54. package/tools/bump_version.py +30 -2
  55. package/tools/cache_resolver.py +6 -6
  56. package/tools/check_env.py +13 -7
  57. package/tools/cli.py +265 -197
  58. package/tools/count_tokens.py +7 -7
  59. package/tools/dashboard_generator.py +39 -23
  60. package/tools/db_sandbox.py +5 -5
  61. package/tools/debt_harvester.py +236 -0
  62. package/tools/distill_log.py +2 -2
  63. package/tools/dspy_qa_signatures.py +357 -0
  64. package/tools/flaky_detector.py +5 -5
  65. package/tools/generate_tc_from_story.py +2 -2
  66. package/tools/generate_test_reports.py +4 -4
  67. package/tools/git_pre_commit_guard.py +6 -6
  68. package/tools/infer_linter.py +12 -7
  69. package/tools/interview_story.py +117 -0
  70. package/tools/lint_ai_docs.py +3 -3
  71. package/tools/matrix_sharder.py +4 -4
  72. package/tools/mcp_excel_server.py +1 -1
  73. package/tools/mcp_server.py +3 -3
  74. package/tools/micro_mutator.py +6 -6
  75. package/tools/omni_transpiler.py +2 -2
  76. package/tools/output_formatter.py +37 -2
  77. package/tools/pinpoint_failure.py +4 -1
  78. package/tools/repo_map.py +2 -2
  79. package/tools/reversible_sandbox.py +157 -0
  80. package/tools/safety_firewall.py +30 -2
  81. package/tools/senior_code_review.py +341 -0
  82. package/tools/setup_project.py +9 -9
  83. package/tools/skill_collision_guard.py +231 -0
  84. package/tools/skill_vault.py +343 -0
  85. package/tools/skillspector.py +2 -2
  86. package/tools/synapse_qa_bench.py +190 -0
  87. package/tools/sync_agent_rules.py +14 -3
  88. package/tools/test_impact.py +4 -4
  89. package/tools/textgrad_mutation_optimizer.py +234 -0
  90. package/tools/tms_sync_bridge.py +2 -2
  91. package/tools/update_sentinel.py +17 -17
  92. package/tools/verify_all.py +47 -16
  93. package/tools/visual_som_helper.py +8 -8
  94. package/tools/watch_mode.py +7 -8
  95. package/tools/wcag_audit.py +5 -1
  96. package/tools/welcome_page.py +12 -12
  97. package/benchmarks/qa_eval/README.md +0 -71
  98. package/benchmarks/qa_eval/build_dataset.py +0 -677
  99. package/benchmarks/qa_eval/dataset/api_contract_drift/qa-challenge-06_api_contract_drift.json +0 -22
  100. package/benchmarks/qa_eval/dataset/api_contract_drift/qa-challenge-07_api_contract_drift.json +0 -22
  101. package/benchmarks/qa_eval/dataset/api_contract_drift/qa-challenge-08_api_contract_drift.json +0 -22
  102. package/benchmarks/qa_eval/dataset/api_contract_drift/qa-challenge-09_api_contract_drift.json +0 -22
  103. package/benchmarks/qa_eval/dataset/api_contract_drift/qa-challenge-10_api_contract_drift.json +0 -22
  104. package/benchmarks/qa_eval/dataset/fake_pass_tautology/qa-challenge-21_fake_pass_tautology.json +0 -21
  105. package/benchmarks/qa_eval/dataset/fake_pass_tautology/qa-challenge-22_fake_pass_tautology.json +0 -21
  106. package/benchmarks/qa_eval/dataset/fake_pass_tautology/qa-challenge-23_fake_pass_tautology.json +0 -21
  107. package/benchmarks/qa_eval/dataset/fake_pass_tautology/qa-challenge-24_fake_pass_tautology.json +0 -21
  108. package/benchmarks/qa_eval/dataset/fake_pass_tautology/qa-challenge-25_fake_pass_tautology.json +0 -21
  109. package/benchmarks/qa_eval/dataset/locator_drift/qa-challenge-01_locator_drift.json +0 -23
  110. package/benchmarks/qa_eval/dataset/locator_drift/qa-challenge-02_locator_drift.json +0 -23
  111. package/benchmarks/qa_eval/dataset/locator_drift/qa-challenge-03_locator_drift.json +0 -23
  112. package/benchmarks/qa_eval/dataset/locator_drift/qa-challenge-04_locator_drift.json +0 -23
  113. package/benchmarks/qa_eval/dataset/locator_drift/qa-challenge-05_locator_drift.json +0 -23
  114. package/benchmarks/qa_eval/dataset/stale_and_mutation/qa-challenge-16_stale_and_mutation.json +0 -22
  115. package/benchmarks/qa_eval/dataset/stale_and_mutation/qa-challenge-17_stale_and_mutation.json +0 -22
  116. package/benchmarks/qa_eval/dataset/stale_and_mutation/qa-challenge-18_stale_and_mutation.json +0 -22
  117. package/benchmarks/qa_eval/dataset/stale_and_mutation/qa-challenge-19_stale_and_mutation.json +0 -22
  118. package/benchmarks/qa_eval/dataset/stale_and_mutation/qa-challenge-20_stale_and_mutation.json +0 -23
  119. package/benchmarks/qa_eval/dataset/timing_and_race/qa-challenge-11_timing_and_race.json +0 -22
  120. package/benchmarks/qa_eval/dataset/timing_and_race/qa-challenge-12_timing_and_race.json +0 -22
  121. package/benchmarks/qa_eval/dataset/timing_and_race/qa-challenge-13_timing_and_race.json +0 -22
  122. package/benchmarks/qa_eval/dataset/timing_and_race/qa-challenge-14_timing_and_race.json +0 -22
  123. package/benchmarks/qa_eval/dataset/timing_and_race/qa-challenge-15_timing_and_race.json +0 -22
  124. package/benchmarks/qa_eval/eval_runner.py +0 -418
  125. package/examples/cypress-ecommerce-suite/README.md +0 -45
  126. package/examples/cypress-ecommerce-suite/cypress/e2e/checkout.cy.js +0 -17
  127. package/examples/cypress-ecommerce-suite/cypress/pages/BasePage.js +0 -29
  128. package/examples/cypress-ecommerce-suite/cypress/pages/CartPage.js +0 -51
  129. package/examples/cypress-ecommerce-suite/cypress.config.js +0 -13
  130. package/examples/cypress-ecommerce-suite/package.json +0 -13
  131. package/examples/katalon-suite/Keywords/pages/BasePage.groovy +0 -19
  132. package/examples/katalon-suite/Keywords/pages/DashboardPage.groovy +0 -29
  133. package/examples/katalon-suite/Keywords/pages/LoginPage.groovy +0 -45
  134. package/examples/katalon-suite/Profiles/default.glbl +0 -12
  135. package/examples/katalon-suite/README.md +0 -18
  136. package/examples/katalon-suite/Scripts/Auth/TC_LoginSuccess/Script1234567890.groovy +0 -12
  137. package/examples/katalon-suite/Scripts/Dashboard/TC_ViewSummary/Script1234567891.groovy +0 -15
  138. package/examples/katalon-suite/katalon_suite.prj +0 -21
  139. package/examples/playwright-crm-suite/README.md +0 -40
  140. package/examples/playwright-crm-suite/package.json +0 -14
  141. package/examples/playwright-crm-suite/pages/BasePage.ts +0 -37
  142. package/examples/playwright-crm-suite/pages/CustomerPage.ts +0 -57
  143. package/examples/playwright-crm-suite/pages/LoginPage.ts +0 -32
  144. package/examples/playwright-crm-suite/playwright.config.ts +0 -27
  145. package/examples/playwright-crm-suite/tests/auth.spec.ts +0 -22
  146. package/examples/playwright-crm-suite/tests/customers.spec.ts +0 -33
  147. package/examples/plugins/sample-custom-plugin/README.md +0 -14
  148. package/examples/plugins/sample-custom-plugin/plugin.json +0 -16
  149. package/examples/plugins/sample-custom-plugin/skills/custom-security-headers-audit/SKILL.md +0 -29
  150. package/examples/plugins/sample-custom-plugin/skills/custom-security-headers-audit/examples/audit_fixture.json +0 -8
  151. package/examples/plugins/sample-custom-plugin/tools/custom_security_headers.py +0 -125
  152. package/examples/practices/README.md +0 -22
  153. package/examples/practices/requirements/crm/requirements_contracts.md +0 -292
  154. package/examples/practices/requirements/crm/requirements_customers.md +0 -462
  155. package/examples/practices/requirements/crm/requirements_login.md +0 -202
  156. package/examples/practices/requirements/crm/requirements_projects.md +0 -396
  157. package/examples/practices/requirements/crm/requirements_tasks.md +0 -343
  158. package/examples/practices/requirements/ecommerce/requirements_category_brand.txt +0 -402
  159. package/examples/practices/requirements/jira/KAN-5/KAN-1/2026-04-03_04-28-27.png +0 -0
  160. package/examples/practices/requirements/jira/KAN-5/KAN-1/KAN-1_requirement.md +0 -52
  161. package/examples/practices/requirements/jira/KAN-5/KAN-4/2026-04-03_04-28-19.png +0 -0
  162. package/examples/practices/requirements/jira/KAN-5/KAN-4/2026-04-03_04-28-57.png +0 -0
  163. package/examples/practices/requirements/jira/KAN-5/KAN-4/KAN-4_requirement.md +0 -119
  164. package/examples/practices/requirements/jira/KAN-5/KAN-5_overview.md +0 -9
  165. package/examples/practices/requirements/jira/KAN-5/KAN-6/2026-04-03_05-58-08.png +0 -0
  166. package/examples/practices/requirements/jira/KAN-5/KAN-6/2026-04-03_05-58-23.png +0 -0
  167. package/examples/practices/requirements/jira/KAN-5/KAN-6/KAN-6_requirement.md +0 -32
  168. package/examples/practices/testcases/api/book_management_api_test_cases.md +0 -144
  169. package/examples/practices/testcases/api/user_management_api_test_cases.md +0 -139
  170. package/examples/practices/testcases/crm/test_cases_crm_login.md +0 -148
  171. package/examples/practices/testcases/crm/test_cases_customers.md +0 -156
  172. package/examples/pytest-api-suite/README.md +0 -45
  173. package/examples/pytest-api-suite/conftest.py +0 -31
  174. package/examples/pytest-api-suite/pages/user_api_client.py +0 -36
  175. package/examples/pytest-api-suite/requirements.txt +0 -2
  176. package/examples/pytest-api-suite/tests/test_user_api.py +0 -44
  177. package/examples/selenium-suite/README.md +0 -18
  178. package/examples/selenium-suite/pages/base_page.py +0 -27
  179. package/examples/selenium-suite/pages/login_page.py +0 -29
  180. package/examples/selenium-suite/pages/order_page.py +0 -25
  181. package/examples/selenium-suite/pytest.ini +0 -6
  182. package/examples/selenium-suite/requirements.txt +0 -2
  183. package/examples/selenium-suite/tests/test_login.py +0 -10
  184. package/examples/selenium-suite/tests/test_order.py +0 -10
@@ -8,12 +8,14 @@ skills:
8
8
  - systematic-debugging
9
9
  tools:
10
10
  - tools/auto_heal.py
11
+ - tools/auto_heal_reflexion.py
11
12
  - tools/heal_pr_automator.py
12
13
  - tools/pinpoint_failure.py
13
14
  - tools/cache_resolver.py
14
15
  - tools/bug_reporter.py
15
16
  - tools/ci_healing_hook.py
16
17
  - tools/micro_mutator.py
18
+ - tools/textgrad_mutation_optimizer.py
17
19
  ---
18
20
 
19
21
  # Failure Autopsy & Adversarial Red-Team Agent (Agent Red)
@@ -45,8 +47,19 @@ tools:
45
47
  - `tools/bug_reporter.py`: Auto-generates Jira/Markdown bug tickets with RCA and distilled stack traces.
46
48
  - `tools/ci_healing_hook.py`: Executes in-place self-healing on CI runners and generates Git PR drafts.
47
49
  - `tools/heal_pr_automator.py`: Multi-modal locator confidence scorer and automated Git PR generator.
50
+ - `tools/auto_heal_reflexion.py`: Multi-trial episodic reflection loop (K=3) for resilient self-healing.
51
+ - `tools/textgrad_mutation_optimizer.py`: Backpropagates textual loss from surviving mutants to optimize assertion synthesis.
48
52
  - `tools/pinpoint_failure.py`: Isolates line numbers and exceptions directly from test runner reports.
49
53
 
54
+ ## 🛑 Anti-Rationalization & Red Flag Guard (Addy Osmani Pattern)
55
+
56
+ | Agent Rationalization / Shortcut Attempt | Architectural Rebuttal & Invariant Enforcement |
57
+ |:---|:---|
58
+ | *"The test failed because of an AUT defect, but I changed expected to match actual so the build turns green."* | **STRICTLY FORBIDDEN:** Manufacturing a fake pass hides bugs. Report the defect honestly via `tools/bug_reporter.py`. |
59
+ | *"I repeated the same patch 5 times hoping it would pass."* | **STRICTLY FORBIDDEN:** Blind retries waste tokens. Use `tools/auto_heal_reflexion.py` with multi-trial verbal reflections and negative cache. |
60
+ | *"The mutation score was 65%, which is close enough to 80%."* | **STRICTLY FORBIDDEN:** Hard floor is 80%. Surviving mutants indicate unverified branches; reject code back to `pom-crafter`. |
61
+ | *"I didn't record a lesson learned because the fix was trivial."* | **STRICTLY FORBIDDEN:** Every healed failure must persist a 2-line lesson into SQLite memory via `tools/cache_resolver.py`. |
62
+
50
63
  ## Persona Enhancements (Adapted from wshobson/agents, MIT)
51
64
 
52
65
  > *Cherry-picked and condensed from the `debugger` agent (wshobson/agents, MIT — see NOTICE entry 21).*
@@ -9,6 +9,7 @@ skills:
9
9
  - github-actions-templates
10
10
  - meta-prompt-crafter
11
11
  - token-and-context-optimizer
12
+ - repo-quality-audit
12
13
  tools:
13
14
  - tools/setup_project.py
14
15
  - tools/analyze_project.py
@@ -20,6 +21,7 @@ tools:
20
21
  - tools/omni_transpiler.py
21
22
  - tools/mcp_server.py
22
23
  - tools/goldfish_review.py
24
+ - tools/interview_story.py
23
25
  ---
24
26
 
25
27
  # Lead QA Orchestrator Agent
@@ -49,14 +51,15 @@ tools:
49
51
  - `tools/lookup_tc.py`: Fast lookup of existing test cases, acceptance criteria, and IDs.
50
52
  - `tools/mcp_server.py`: Exposes standardized JSON-RPC 2.0 endpoints for all AI clients.
51
53
  - `tools/goldfish_review.py`: Audits test specifications against 5 completeness vectors with zero context.
54
+ - `tools/interview_story.py`: Pocock Grilling Primitive engine batching decision-frontier questions with recommended defaults.
52
55
 
53
56
  ## Single Front-Door FSM Workflow (Deterministic 5 Stages):
54
- 1. **Stage 1 (Discovery):** Invoke `live-explorer` to inspect DOM/AOM and verify selectors under 200ms.
57
+ 1. **Stage 1 (Discovery):** Invoke `live-explorer` to inspect DOM/AOM and verify selectors under 200ms. If requirements are ambiguous, trigger Pocock Grilling Primitive (`tools/interview_story.py`) to resolve decision frontiers.
55
58
  2. **Stage 1.5 (Goldfish Spec Gate):** Run `tools/goldfish_review.py` on test specifications. Block code synthesis if spec has unstated assumptions.
56
59
  3. **Stage 2 (Synthesis):** Pass Data Contract to `pom-crafter` to generate Clean POM classes and flat test scripts.
57
60
  4. **Stage 3 (Execution):** Dispatch headless execution via `test-runner`.
58
61
  5. **Stage 4 (Autopsy):** If test fails, invoke `failure-analyst` to perform RCA and auto-heal.
59
- 6. **Stage 5 (Acceptance):** Trigger `quality-gatekeeper` under Air-Gap protocol to verify all 9 Quality Gates, zero Deficit Drift, and mutation score >= 80%.
62
+ 6. **Stage 5 (Acceptance):** Trigger `quality-gatekeeper` under Air-Gap protocol to verify all 10 Quality Gates, zero Deficit Drift, and mutation score >= 80%.
60
63
 
61
64
  ## Persona Enhancements (Adapted from wshobson/agents, MIT)
62
65
 
@@ -10,6 +10,7 @@ skills:
10
10
  - db-state-verifier-and-seeder
11
11
  - surgical-coding-principles
12
12
  - lean-code-ladder
13
+ - technical-debt-harvester
13
14
  - gherkin-to-suite
14
15
  - api-network-mocking-interception
15
16
  - rbt-manual-testing
@@ -25,6 +26,7 @@ tools:
25
26
  - tools/network_mock_shield.py
26
27
  - tools/cache_resolver.py
27
28
  - tools/micro_mutator.py
29
+ - tools/skill_vault.py
28
30
  - tools/mcp_excel_server.ps1
29
31
  ---
30
32
 
@@ -83,8 +85,19 @@ tools:
83
85
  - `tools/api_drift_sentinel.py`: Flags breaking changes across OpenAPI schema versions early.
84
86
  - `tools/lookup_tc.py`: Fast query of test case specifications and acceptance criteria.
85
87
  - `tools/repo_map.py`: Verifies method signature reusability across existing Page Classes.
88
+ - `tools/skill_vault.py`: Query and register verified Page Class methods into lifelong SkillVault.
86
89
  - `tools/mcp_excel_server.ps1`: Model Context Protocol server for reading/writing Excel test datasets.
87
90
 
91
+ ## 🛑 Anti-Rationalization & Red Flag Guard (Addy Osmani Pattern)
92
+
93
+ | Agent Rationalization / Shortcut Attempt | Architectural Rebuttal & Invariant Enforcement |
94
+ |:---|:---|
95
+ | *"The test passes if I comment out or relax the assertion."* | **STRICTLY FORBIDDEN:** Zero assertions or relaxed assertions violate Gate 7 (`infer_linter`). AUT bugs must be reported honestly. |
96
+ | *"I will use raw XPath here because designing a Page Object takes too many lines."* | **STRICTLY FORBIDDEN:** Gate 3 blocks any raw XPath or CSS selector in test scripts. All selectors belong in `BasePage` subclasses. |
97
+ | *"I added `Thread.sleep(5000)` to ensure stability."* | **STRICTLY FORBIDDEN:** Invariant 4 prohibits static sleeps. Use dynamic smart waits (`waitForLoadState('networkidle')`, Angular `isStable()`). |
98
+ | *"The test data already exists in DB so I skipped uniqueCode generation."* | **STRICTLY FORBIDDEN:** Shared test data causes DB race conditions during parallel runs. Always use `uniqueCode` and automated teardown. |
99
+ | *"I will wrap this assertion in a try-catch to prevent pipeline failure."* | **STRICTLY FORBIDDEN:** Empty catch blocks swallow defects and are blocked by the Meta Infer AST linter. |
100
+
88
101
  ## Persona Enhancements (Adapted from wshobson/agents, MIT)
89
102
 
90
103
  > *Cherry-picked and condensed from the `backend-architect` agent (wshobson/agents, MIT — see NOTICE entry 21).*
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: quality-gatekeeper
3
- description: Sentinel gatekeeper enforcing 9 Quality Gates, AST mutation thresholds (>= 80%), and static verification before task completion.
3
+ description: Sentinel gatekeeper enforcing 10 Quality Gates, AST mutation thresholds (>= 80%), and static verification before task completion.
4
4
  skills:
5
5
  - antigravity-test-sentinel
6
6
  - code-refactoring-refactor-clean
@@ -10,6 +10,8 @@ skills:
10
10
  - security-dast-sentinel
11
11
  - verification-before-completion
12
12
  - skillspector-security-guard
13
+ - senior-code-review
14
+ - technical-debt-harvester
13
15
  tools:
14
16
  - tools/verify_all.py
15
17
  - tools/infer_linter.py
@@ -21,6 +23,10 @@ tools:
21
23
  - tools/git_pre_commit_guard.py
22
24
  - tools/agent_canary.py
23
25
  - tools/spec_drift_sentinel.py
26
+ - tools/senior_code_review.py
27
+ - tools/debt_harvester.py
28
+ - tools/skill_collision_guard.py
29
+ - tools/synapse_qa_bench.py
24
30
  ---
25
31
 
26
32
  # Quality Gatekeeper & Sentinel Agent
@@ -28,7 +34,7 @@ tools:
28
34
  ## Core Responsibilities:
29
35
  - **Hard Rejection Policy (Mutation Score Gate):** Strictly **REJECT and BLOCK** any newly generated or modified test case without an accompanying `tools/micro_mutator.py` evaluation confirming a Mutation Score of **at least 80%**. Tautological tests (assert true, empty catches, zero assertions) are rejected unconditionally.
30
36
  - **Zero-Context Air-Gap Protocol (Goldfish Audit Invariant):** The Gatekeeper operates strictly as an adversarial, stateless auditor. It disregards conversation transcripts, conversational excuses, or verbal assurances from earlier turns. Every verdict must be anchored exclusively on disk artifacts: `git diff`, fresh `Reports/junit.xml`, `PROJECT_STATE.md`, and deterministic CLI command outputs.
31
- - Execute `tools/verify_all.py` to enforce all 9 Definition of Done (DoD) Quality Gates.
37
+ - Execute `tools/verify_all.py` to enforce all 10 Definition of Done (DoD) Quality Gates.
32
38
  - Run static AST code analysis via `tools/infer_linter.py` to block Fake-Pass antipatterns (0 asserts or empty catches).
33
39
  - Audit specification alignment via `tools/spec_drift_sentinel.py` to reject Deficit Drift (missing acceptance criteria) and flag Scope Drift (unauthorized code bloat).
34
40
  - Validate Groovy script syntactic completeness (matching braces, unclosed quotes) via `tools/validate_groovy_scripts.py`.
@@ -51,6 +57,19 @@ tools:
51
57
  - `tools/validate_groovy_scripts.py`: Static linter verifying syntax and brace balance in Groovy test scripts.
52
58
  - `tools/git_pre_commit_guard.py`: Pre-commit git hook preventing unverified code from being staged.
53
59
  - `tools/agent_canary.py`: Injects 8 failure vectors to benchmark MTTR and autonomous recovery rate.
60
+ - `tools/senior_code_review.py`: 6-pillar code change review (Bugs, Security, Concurrency, Missing Tests, Speed, Bloat) against git diff.
61
+ - `tools/debt_harvester.py`: Harvests `shortcut:` technical debt markers across codebase into tracked debt ledger.
62
+ - `tools/skill_collision_guard.py`: Tier-2 Skill Routing & Collision Guard enforcing offline cosine similarity < 0.75 across skill descriptions.
63
+ - `tools/synapse_qa_bench.py`: Gorilla BFCL-style benchmark measuring tool-use accuracy, argument validity, and irrelevance detection.
64
+
65
+ ## 🛑 Anti-Rationalization & Red Flag Guard (Addy Osmani Pattern)
66
+
67
+ | Agent Rationalization / Shortcut Attempt | Architectural Rebuttal & Invariant Enforcement |
68
+ |:---|:---|
69
+ | *"Only 1 of 10 gates failed, so it's practically ready to ship."* | **STRICTLY FORBIDDEN:** All 10 Quality Gates must return PASS. 9/10 is a blocker, not a pass. |
70
+ | *"The mutation score is 78%, which is within rounding distance of 80%."* | **STRICTLY FORBIDDEN:** Mutation Score >= 80% is a non-negotiable hard floor. Surviving mutants must be killed. |
71
+ | *"Skill descriptions have 0.78 similarity, but they do different things."* | **STRICTLY FORBIDDEN:** Cosine similarity >= 0.75 causes LLM routing confusion. Refactor descriptions to differentiate triggers. |
72
+ | *"We can bypass the verification command since the author tested it locally."* | **STRICTLY FORBIDDEN:** Verification-before-completion requires fresh command output run directly in the current session. |
54
73
 
55
74
  ## Persona Enhancements (Adapted from wshobson/agents, MIT)
56
75
 
@@ -11,6 +11,7 @@ skills:
11
11
  - backend-load-and-stress-patterns
12
12
  tools:
13
13
  - tools/safety_firewall.py
14
+ - tools/reversible_sandbox.py
14
15
  - tools/matrix_sharder.py
15
16
  - tools/flaky_detector.py
16
17
  - tools/distill_log.py
@@ -43,6 +44,16 @@ tools:
43
44
  - `tools/pinpoint_failure.py`: Fast 0.1s failure isolation from JUnit XML reports.
44
45
  - `tools/generate_allure_report.ps1`: Builds and serves interactive Allure test execution dashboards.
45
46
  - `tools/generate_test_reports.ps1`: Compiles consolidated JUnit/HTML execution reports.
47
+ - `tools/reversible_sandbox.py`: GoEx reversible teardown stack guaranteeing zero database pollution after test runs.
48
+
49
+ ## 🛑 Anti-Rationalization & Red Flag Guard (Addy Osmani Pattern)
50
+
51
+ | Agent Rationalization / Shortcut Attempt | Architectural Rebuttal & Invariant Enforcement |
52
+ |:---|:---|
53
+ | *"The test failed on CI due to environment lag, so I'll just re-run until it passes."* | **STRICTLY FORBIDDEN:** Flaky retry laundering hides defects. Quarantine via `tools/flaky_detector.py` or fix timing via smart wait. |
54
+ | *"I bypassed `safety_firewall.py` with `--force` because teardown takes too long."* | **STRICTLY FORBIDDEN:** Bypassing the firewall without approval risks destructive mutations on live/staging databases. |
55
+ | *"The teardown step failed so I skipped it; the data shouldn't hurt."* | **STRICTLY FORBIDDEN:** Orphan data causes subsequent run collisions. Use `tools/reversible_sandbox.py` for guaranteed rollback. |
56
+ | *"Dumping the entire 3000-line CLI log helps diagnose better."* | **STRICTLY FORBIDDEN:** Context bloat degrades agent reasoning. Always use `tools/distill_log.py` to mask raw observation logs. |
46
57
 
47
58
  ## Persona Enhancements (Adapted from wshobson/agents, MIT)
48
59
 
@@ -1,111 +1,31 @@
1
- ---
2
- trigger: always_on
3
- description: Context Engineering Protocol enforcing Observation Masking, Progressive Disclosure, and KV-Cache Friendly Ordering.
4
- ---
5
-
6
1
  # Context Engineering & Token Optimization Protocol
7
2
 
8
- *(Synthesized from `muratcankoylan/Agent-Skills-for-Context-Engineering`, `alexgreensh/token-optimizer`, and `obra/superpowers`)*
9
-
10
- This mandatory protocol governs how AI Agents manage context windows, tool outputs, and attention budgets across automated test suites.
11
-
12
- ---
13
-
14
- ## 1. Pillar 1: Observation Masking
15
-
16
- 1. **The Principle:**
17
- - Raw tool outputs (CLI execution logs, Gradle builds, browser console traces) contain 90% repetitive noise and low-signal tokens.
18
- - Dumping raw logs degrades the LLM's reasoning ("Context Rot" / "Lost-in-the-Middle").
19
-
20
- 2. **Actionable Rules:**
21
- - **Log Truncation & Summarization:** When executing CLI commands, never dump thousands of lines into the active conversation. Extract only:
22
- - The exact failing line number and exception name.
23
- - The test case identifier (`TC-xxx`).
24
- - Final execution status (PASS/FAIL).
25
- - **Pointer Masking:** Use structured references pointing to files on disk:
26
- `[Full raw log saved to file://<path>; 2,400 verbose lines omitted]`
27
-
28
- ---
29
-
30
- ## 2. Pillar 2: Progressive Disclosure
31
-
32
- 1. **The Principle:**
33
- - Never load large codebases or giant classes (over 500 lines) into context at once.
34
- - Load information in 3 progressive tiers:
35
-
36
- ```mermaid
37
- flowchart TD
38
- Tier1["<b>Tier 1: High-Level Index & Repo Map (< 150 lines)</b><br/>• Read tools/repo_map.txt or SKILL.md index<br/>• Understand 500+ method signatures using ~500 tokens"]
39
- Tier2["<b>Tier 2: Graph Semantic Scoping</b><br/>• Run graphify explain '<Class>' or test_impact.py<br/>• Scope only 1-hop dependent nodes (~500 tokens)"]
40
- Tier3["<b>Tier 3: Targeted Micro-Read</b><br/>• Read exactly the 20-50 lines of target method<br/>• Zero unnecessary surrounding lines"]
41
-
42
- Tier1 --> Tier2 --> Tier3
43
- ```
44
-
45
- 2. **Actionable Rules:**
46
- - Always inspect `tools/repo_map.txt` or query the Knowledge Graph (`graphify-out/graph.json`) before opening code files.
47
- - Use line-range parameters (`StartLine`, `EndLine`) when reading large Page Classes.
3
+ > **Mandatory Rule:** Governs context windows, tool outputs, and attention budgets across all agent sessions.
4
+ > Detailed architecture guide: [context_engineering_guide.md](file://.agents/skills/token-and-context-optimizer/references/context_engineering_guide.md).
48
5
 
49
6
  ---
50
7
 
51
- ## 3. Pillar 3: KV-Cache Friendly Ordering
52
-
53
- 1. **The Principle:**
54
- - Modern LLM inference engines cache Key-Value (KV) attention states for identical prompt prefixes.
55
- - Any dynamic mutation in the middle of a prompt destroys the cache breakpoint, forcing 100% full re-computation.
56
-
57
- 2. **Actionable Rules:**
58
- - **Static Prefix First:** Maintain system instructions, rules, and tool schemas completely immutable at the top.
59
- - **Append-Only Dynamic State:** Only append new test results, user queries, and tool observations at the bottom of the context sequence.
60
- - **Predictable Format:** Use the identical pre-flight confirmation header on every turn to maximize KV-cache hit rates (aiming for > 85% cache hit).
61
-
62
- ---
63
-
64
- ## 4. Pillar 4: Scoped Context & Compaction Anchoring Protocol
65
-
66
- 1. **The Principle:**
67
- - Antigravity automatically triggers **Context Compaction** when conversation context approaches the ~135k tokens safety threshold to summarize session history and avoid out-of-memory crashes.
68
- - Without deterministic disk anchoring, automated compaction can cause lossy compression of fine-grained execution state (exact failing lines, temporary IDs, active watchpoints).
69
- - Furthermore, unbounded parallel sub-agents can collide on shared files, browser sessions, or database test data.
70
-
71
- 2. **Actionable Rules:**
72
- - **Compaction State Anchoring:** All critical state (test execution status, defect registers, active test IDs) must be persisted to disk in `PROJECT_STATE.md` or `.project_state.properties`. When compaction fires, the agent re-anchors immediately by inspecting the disk state with zero memory degradation.
73
- - **Workspace Isolation (`Workspace: 'share'`):** When launching sub-agents via `invoke_subagent`, always use isolated worktrees (`share` or `branch`) to prevent git index conflicts and dirty tree collisions.
74
- - **Zero Context Contagion:** Sub-agent tool executions (e.g., 2,000 lines of CLI stdout) remain strictly sandboxed within the sub-agent's context. Sub-agents must return only distilled 3-5 line summaries to the Lead Orchestrator.
75
- - **Data Partitioning by Agent ID:** Every sub-agent must append its agent identifier to dynamic test data (`uniqueCode = "AUTO_" + System.currentTimeMillis() + "_SUB" + agentId`) and use dedicated user sessions to prevent web session evictions.
76
-
77
- ---
78
-
79
- ## 5. Pillar 5: Semantic Context Distillation (Pure Signal, Zero Noise)
80
-
81
- 1. **The Principle:**
82
- - LLM reasoning degrades as context length increases ("Lost in the Middle"). Dumping raw HTML DOM or 1,000-line logs degrades reasoning ability.
83
- - All sensory inputs must pass through deterministic filters before reaching the LLM's attention heads (aiming for 300–500 tokens of 100% pure signal).
84
-
85
- 2. **Actionable Rules:**
86
- - **CLI Logs (`tools/distill_log.py`):** Automatically truncate 95% of verbose lines, preserving only the direct failing line, root cause exception, and the last 3 HTTP requests.
87
- - **DOM Purifier (`qa.getCompactAOM` in `browser_helpers.js`):** **Strictly forbidden to send raw HTML.** Use `qa.getCompactAOM(maxDepth=3)` to extract only interactive nodes with Role, Name, State, and TestId.
88
- - **Framework Independence (`tools/universal_ir.py`):** Author and reason over clean Universal IR representation before emitting framework-specific boilerplate (Groovy, TS, Java).
89
-
90
-
91
- ---
8
+ ## 1. Observation Masking & Log Truncation
9
+ - Never dump thousands of lines of raw tool outputs (CLI, build logs, browser traces) into the chat.
10
+ - Extract strictly: failing line number, exception name, test ID (`TC-xxx`), and status.
11
+ - Mask verbose logs with pointer references: `[Full raw log saved to file://<path>; verbose lines omitted]`.
92
12
 
93
- ## 6. Pillar 6: The Elephant-Goldfish Memory Protocol (Zero-Contamination Swarm)
13
+ ## 2. Progressive Disclosure & Micro-Reads
14
+ - Never read large files (> 150 lines) into context at once.
15
+ - Tier 1: Check `tools/repo_map.txt` for class signatures (~500 tokens).
16
+ - Tier 2: Check dependency blast radius via `tools/test_impact.py`.
17
+ - Tier 3: Micro-read targeted 20–50 lines using `StartLine` and `EndLine`.
94
18
 
95
- *(Synthesized from Google's Elephant-Goldfish Model by Dave Rensin)*
19
+ ## 3. KV-Cache Optimization & Static Prefix
20
+ - Keep system instructions and rule headers static and immutable at the top.
21
+ - Append new observations strictly at the bottom. Use identical status badges to maintain > 85% cache hit rates.
96
22
 
97
- 1. **The Principle:**
98
- - Single-agent long context inevitably breeds **Confirmation Bias** and **Context Contamination**: when the same context window designs an architecture, drafts a spec, and evaluates its own plan, it glosses over unstated assumptions and hallucinates completeness.
99
- - True engineering rigor requires decoupling deep-context coordination (**The Elephant**) from stateless, adversarial verification (**The Goldfish**).
23
+ ## 4. Compaction Anchoring & Subagent Isolation
24
+ - Persist active test registers, IDs, and state to `PROJECT_STATE.md` so automated context compaction never causes state loss.
25
+ - Always isolate subagents (`Workspace: 'share'`); subagents must return only 3–5 line distilled summaries.
26
+ - Partition test data with dynamic agent IDs (`uniqueCode = "AUTO_" + time + "_SUB" + id`).
100
27
 
101
- 2. **Actionable Rules:**
102
- - **The Elephant (Stateful Orchestrator):**
103
- - Narrows problem boundaries, gathers user intent, and drafts architectural specs / Test Matrices (`docs/specs/*.md`).
104
- - Maintains global long-term project context via `PROJECT_STATE.md`.
105
- - **Strict Invariant:** The Elephant is prohibited from generating automation test scripts or asserting its own test design validity during the initial design phase.
106
- - **The Goldfish (Stateless Subagent Swarm):**
107
- - Spun up in a fresh, isolated subagent context (`Workspace: 'share'`) with **ZERO conversation history**.
108
- - Evaluates solely the cold Markdown artifact and source code on disk using structured contracts (e.g., `tools/goldfish_review.py`).
109
- - If the Goldfish cannot execute or understand the specification without guessing, the specification is rejected back to the Elephant.
110
- - **Air-Gap Data Contract:**
111
- - Data exchanged between stages must pass via deterministic files on disk (JSON Data Contracts, Test Matrices, JUnit XML), never via raw prompt inheritance.
28
+ ## 5. Semantic Signal Distillation
29
+ - **Forbidden Raw HTML:** Never send raw HTML trees into context. Use `qa.getCompactAOM()` (< 500 tokens).
30
+ - **Universal IR First:** Reason over clean Universal IR (`tools/universal_ir.py`) before generating Groovy/TS/Java boilerplate.
31
+ - **Elephant-Goldfish Swarm:** Stateful Orchestrator writes specs to disk; stateless verification subagents audit cold files with zero context contagion.
@@ -1,132 +1,36 @@
1
1
  # Mobile Automation Standards & Appium Rules (Enterprise Standard)
2
2
 
3
- > **Scope:** Applies to all Mobile Test Automation tasks using Appium, UIAutomator2 (Android), and XCUITest (iOS).
3
+ > **Scope:** Applies to Mobile Automation using Appium, UIAutomator2 (Android), and XCUITest (iOS).
4
4
  > **Objective:** Deliver resilient, independent, flake-free mobile suites supporting parallel multi-device execution.
5
5
 
6
6
  ---
7
7
 
8
8
  ## 1. Native Locator Priority Hierarchy
9
-
10
- When interacting with Native or Hybrid mobile applications, agents **MUST** strictly adhere to the following locator priority order:
11
-
12
- ```mermaid
13
- flowchart TD
14
- L1["<b>1. Accessibility ID / Content-Desc</b><br/>• Cross-platform (iOS & Android)<br/>• Most stable, independent of layout"]
15
- L2["<b>2. Resource-ID (Android Native)</b><br/>• Example: com.app.package:id/btn_login"]
16
- L3["<b>3. iOS Predicate String / Class Chain (iOS Native)</b><br/>• Native XCUITest performance"]
17
- L4["<b>4. Dynamic XPath (Last Resort)</b><br/>• Relative XPath with text/attributes only<br/>• Absolute structural XPath is FORBIDDEN"]
18
-
19
- L1 --> L2 --> L3 --> L4
20
- ```
21
-
22
- ### Standard Implementation Examples:
23
- ```java
24
- // 1. Accessibility ID (Top priority)
25
- driver.findElement(AppiumBy.accessibilityId("btn_login"));
26
-
27
- // 2. Resource-ID Android (Android Native priority)
28
- driver.findElement(AppiumBy.id("com.enterprise.app:id/input_username"));
29
-
30
- // 3. iOS Predicate String (iOS Native priority)
31
- driver.findElement(AppiumBy.iOSNsPredicateString("label == 'Sign In' AND visible == 1"));
32
-
33
- // 4. iOS Class Chain
34
- driver.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeButton[`label == 'Submit'`]"));
35
- ```
9
+ 1. **Accessibility ID / Content-Desc** (Top priority, cross-platform): `driver.findElement(AppiumBy.accessibilityId("btn_login"))`
10
+ 2. **Resource-ID (Android Native):** `driver.findElement(AppiumBy.id("com.app:id/username"))`
11
+ 3. **iOS Predicate String (iOS Native):** `driver.findElement(AppiumBy.iOSNsPredicateString("label == 'Sign In' AND visible == 1"))`
12
+ 4. **iOS Class Chain:** `driver.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeButton[`label == 'Submit'`]"))`
13
+ 5. **Dynamic XPath (Last Resort):** Relative XPath with attributes only. Absolute structural XPath is **FORBIDDEN**.
36
14
 
37
15
  ---
38
16
 
39
17
  ## 2. Strict Anti-Patterns & Prohibitions
40
-
41
- - ❌ **FORBIDDEN: Absolute XPath based on DOM tree hierarchy:**
42
- ```java
43
- // STRICTLY FORBIDDEN:
44
- driver.findElement(By.xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.widget.Button[1]"));
45
- ```
46
- - ❌ **FORBIDDEN: Static sleeps (`Thread.sleep()`):** Introduces pipeline latency and flaky synchronization.
47
- - ❌ **FORBIDDEN: Interacting with off-screen elements without scrolling:** Always scroll into view first.
48
- - ❌ **FORBIDDEN: Hardcoded device identifiers:** UDID, Device Name, Platform Version must be dynamic via environment variables or profile configurations.
49
-
50
- ---
51
-
52
- ## 3. Screen Object Model (SOM) Architecture
53
-
54
- Following the Page Object Model design pattern, mobile test code adheres to **Screen Object Model**:
55
- - Screen class names must end with the `Screen` suffix (e.g., `LoginScreen.java`, `HomeScreen.java`, `CartScreen.java`).
56
- - Extend `BaseScreen` providing shared AppiumDriver instances and gesture helpers.
57
- - Encapsulate locators within Screen classes; test scripts call business actions only.
58
-
59
- ```java
60
- public class LoginScreen extends BaseScreen {
61
- private final By btnLogin = AppiumBy.accessibilityId("btn_submit");
62
- private final By txtEmail = AppiumBy.accessibilityId("input_email");
63
-
64
- public LoginScreen(AppiumDriver driver) {
65
- super(driver);
66
- }
67
-
68
- public HomeScreen loginWithValidCredentials(String email, String password) {
69
- waitForElementVisible(txtEmail).sendKeys(email);
70
- // ...
71
- return new HomeScreen(driver);
72
- }
73
- }
74
- ```
18
+ - ❌ **FORBIDDEN:** Absolute hierarchy XPath (e.g., `//android.widget.FrameLayout[1]/.../Button[1]`).
19
+ - ❌ **FORBIDDEN:** Static delays (`Thread.sleep()`).
20
+ - ❌ **FORBIDDEN:** Interacting with off-screen elements without scrolling into view first.
21
+ - ❌ **FORBIDDEN:** Hardcoded device identifiers (UDID, device name must come from environment/profiles).
75
22
 
76
23
  ---
77
24
 
78
- ## 4. Synchronization & Smart Mobile Waits
79
-
80
- - Always use `WebDriverWait` with explicit `Duration`:
81
- ```java
82
- WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
83
- wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("welcome_banner")));
84
- ```
85
- - Smart scroll into view:
86
- ```java
87
- // Android UIAutomator Scrollable
88
- driver.findElement(AppiumBy.androidUIAutomator(
89
- "new UiScrollable(new UiSelector().scrollable(true))" +
90
- ".scrollIntoView(new UiSelector().text(\"Confirm\"))"
91
- ));
92
- ```
25
+ ## 3. Screen Object Model (SOM) & Synchronization
26
+ - Screen classes end with `Screen` suffix (e.g., `LoginScreen.java`) extending `BaseScreen`.
27
+ - Encapsulate locators in Screen classes; test scripts call business actions only.
28
+ - **Smart Waits:** Always use `WebDriverWait` with explicit `Duration.ofSeconds(N)`.
29
+ - **Smart Scroll:** Use `UiScrollable(...).scrollIntoView(...)` or native iOS scroll gestures.
93
30
 
94
31
  ---
95
32
 
96
- ## 5. Mobile Lifecycle & Device Gestures
97
-
98
- 1. **Auto-Grant Permissions:**
99
- - Configure capabilities to auto-grant system permissions:
100
- `capabilities.setCapability("autoGrantPermissions", true);` (Android) or `"permissions": "{\"com.app\": {\"camera\": \"yes\"}}"` (iOS).
101
- 2. **Screen Orientation:**
102
- - Verify layout adaptability in both Portrait and Landscape when supported by the application.
103
- 3. **App Backgrounding:**
104
- - Test application resilience across background/foreground transitions:
105
- `driver.runAppInBackground(Duration.ofSeconds(5));`
106
- 4. **Virtual Keyboard Handling:**
107
- - Always dismiss virtual keyboards (`driver.hideKeyboard()`) after input to prevent occluding action buttons.
108
-
109
- ---
110
-
111
- ## 6. Driver Architecture & Image-Based Matching
112
-
113
- > *Borrowed and adapted from the Appium driver/plugin architecture concepts (Apache-2.0, appium/appium).*
114
-
115
- 1. **Driver isolation** — each platform driver (UIAutomator2, XCUITest)
116
- encapsulates its own locator translation and gesture mapping; Screen Object
117
- classes must never branch on driver type outside the driver layer. A
118
- `*Screen` class speaks intent ("tap primary action"), the driver layer
119
- speaks mechanics.
120
- 2. **Capabilities belong in profiles, not scripts** — device/OS/app
121
- capabilities live in versioned capability profiles; test classes receive a
122
- ready session. Hardcoding `platformVersion`/`deviceName` inside scripts is a
123
- prohibited anti-pattern (see Section 2).
124
- 3. **Image-based matching is a last-resort locator** — for canvas/maps/WebView
125
- hybrids where the accessibility tree is empty, an image-reference plugin
126
- (template match against a committed reference screenshot with a similarity
127
- threshold, e.g. ≥ 0.9) may resolve elements. It is slower and flakier than
128
- `AccessibilityID`/`ResourceID` — use only after the locator hierarchy in
129
- Section 1 is exhausted, and always commit the reference image next to the
130
- Screen class.
131
- 4. **Match the session teardown to the driver lifecycle** — quit sessions
132
- explicitly; orphaned driver processes leak devices in the grid.
33
+ ## 4. Mobile Lifecycle & Driver Invariants
34
+ - **Permissions:** Auto-grant system permissions via capabilities (`autoGrantPermissions: true`).
35
+ - **Resilience:** Validate backgrounding (`driver.runAppInBackground(...)`) and hide virtual keyboard before actions.
36
+ - **Driver Isolation:** Screen classes speak intent; platform drivers (UIAutomator2/XCUITest) encapsulate mechanics. Capabilities reside in profiles, never in scripts. Always explicitly quit sessions.
@@ -1,74 +1,30 @@
1
1
  # Performance & Load Testing Invariants (k6 · JMeter · Locust)
2
2
 
3
3
  > **Scope:** Applies whenever designing, executing, or analyzing performance, load, stress, spike, or soak test workloads.
4
- > These invariants complement `AGENTS.md` and enforce enterprise safety, workload realism, and zero-hallucination analysis.
4
+ > Complement to `AGENTS.md` enforcing enterprise safety, workload realism, and zero-hallucination analysis.
5
5
 
6
6
  ---
7
7
 
8
- ## 1. Safety Gate & Approval Invariants (Mandatory Pre-Flight)
9
-
10
- 1. **Explicit Authorization:**
11
- - Execute load tests **only** against pre-approved, dedicated environments (performance test environment or isolated sandbox).
12
- - **Strictly forbidden:** Running load tests against production, shared staging, public demo sites, or third-party APIs without formal written sign-off.
13
- 2. **Pre-Run Declaration:**
14
- - Prior to any execution above Smoke test, the agent must declare the run profile and wait for explicit confirmation:
15
- - Target host and environment owner
16
- - Test archetype (Smoke, Average Load, Stress, Spike, Soak)
17
- - Load profile (max VUs, target iterations/sec or requests/sec, duration, ramp-up/down phases)
18
- - Data volume created and teardown strategy
19
- - Kill-switch threshold (`abortOnFail`)
20
- 3. **Progressive Stepped Escalation:**
21
- - Always adhere to progressive ramp-up: **Smoke (1–5 VUs) → Baseline Average Load → Stress / Spike / Soak**.
22
- - Never initiate Stress, Spike, Soak, or Breakpoint runs autonomously.
23
- 4. **Hard Caps & Kill-Switch:**
24
- - Every script must enforce hard upper bounds on rate and VUs, finite duration, and an automatic abort condition (`abortOnFail` when error rate breaches acceptable thresholds, e.g., > 10%).
25
- - Unbounded loops or infinite duration scripts are strictly prohibited.
26
- 5. **Third-Party Isolation:**
27
- - Mock or stub third-party external dependencies (Payment Gateways, SMS providers, email senders, CAPTCHA, web analytics). Never send synthetic load to unisolated external partners.
28
- 6. **Data Safety & Idempotent Cleanup:**
29
- - Write traffic must use isolated, synthetic test data with recognizable prefixes (e.g., `PERF_AUTO_`, `PERF-`). Real customer credentials or PII must never be used.
30
- - Every creation run must be paired with an automated teardown or ephemeral DB rollback.
8
+ ## 1. Safety Gate & Pre-Flight Invariants
9
+ 1. **Dedicated Environments Only:** Never run load tests against production, shared staging, or third-party APIs without written approval.
10
+ 2. **Pre-Run Declaration:** Declare target host, archetype (Smoke, Average Load, Stress, Spike, Soak), VU/arrival profile, duration, and kill-switch threshold (`abortOnFail`).
11
+ 3. **Progressive Escalation:** Smoke (1–5 VUs) -> Baseline Average Load -> Stress / Spike / Soak. Never start high-VU runs autonomously.
12
+ 4. **Hard Caps & Kill-Switch:** Scripts must enforce finite durations, rate caps, and automated abort (`abortOnFail` when error rate > 10%). Unbounded loops are strictly forbidden.
13
+ 5. **Isolation & Cleanup:** Mock third-party providers (Payment, SMS, Captcha). Use synthetic test data (`PERF_AUTO_`); teardown after runs.
31
14
 
32
15
  ---
33
16
 
34
- ## 2. Workload Modeling Invariants
35
-
36
- 1. **Open vs. Closed Model:**
37
- - **Open Model (Arrival Rate):** Use arrival-rate executors for public web traffic or SLA requirements stated in rate (e.g., `N req/sec`). Real users arrive independently of system slowdown.
38
- - **Closed Model (Virtual Users):** Use VU-based executors only when modeling fixed concurrent sessions (e.g., internal enterprise portals).
39
- 2. **Realistic Think Time:**
40
- - Model user think time between journey steps using realistic distributions (e.g., Gaussian or uniform 1s–5s). Zero-think-time "hammer" testing is forbidden unless specifically requested for denial-of-service resilience audits.
41
- 3. **Data Realism & Cache Skew Prevention:**
42
- - Parameterize query parameters, identifiers, and payloads across realistic key spaces. Repeatedly querying identical records measures database cache hit rates rather than true backend capability.
43
- 4. **Phase-Based Evaluation:**
44
- - Structure tests into `Ramp-Up`, `Steady State`, and `Ramp-Down` phases.
45
- - Compute SLA thresholds and verdicts **strictly against the Steady State**, never against warm-up or cool-down transients.
17
+ ## 2. Workload Modeling & k6 Script Standards
18
+ 1. **Arrival Rate vs VU:** Use open arrival-rate executors for public traffic; use closed VU-based executors only for fixed employee portals.
19
+ 2. **Realistic Think Time & Cache Skew:** Parameterize queries across realistic key spaces. Model user think time (1s–5s); zero think time is forbidden.
20
+ 3. **Steady-State Evaluation:** Evaluate SLA thresholds strictly against Steady State, excluding warm-up/cool-down transients.
21
+ 4. **k6 Script Structure:** `options` -> `setup()` -> default VU function (`check()`) -> `teardown()`.
22
+ - Valid threshold syntax: `'http_req_duration{expected_response:true}': ['p(95)<500']`.
23
+ - Always pair `check()` with `'checks': ['rate>0.99']`.
24
+ - Set `discardResponseBodies: true` when responses are unparsed. Pass secrets via `__ENV`.
46
25
 
47
26
  ---
48
27
 
49
- ## 3. k6 Script Engineering Standards
50
-
51
- 1. **Script Structure:**
52
- - `options` (profile, stages, thresholds) → `setup()` (one-time auth and shared state) → default function (user journey with `check()` calls) → `teardown()` (cleanup).
53
- 2. **Valid Threshold Syntax:**
54
- - Use standard k6 threshold syntax: `metric{tag:value}: ['p(95)<500']`. Braces contain tag filters only.
55
- - Latency thresholds must evaluate successful responses: `'http_req_duration{expected_response:true}': ['p(95)<500', 'p(99)<1000']`.
56
- - Always pair `check()` with a `checks` threshold (e.g., `'checks': ['rate>0.99']`), as unasserted check failures do not alter k6 exit codes.
57
- 3. **Generator Efficiency:**
58
- - Set `discardResponseBodies: true` when response bodies are not required for subsequent extractions, minimizing memory overhead on the load generator.
59
- 4. **Strict Credential Hygiene:**
60
- - Pass tokens, usernames, and base URLs via environment variables (`__ENV.BASE_URL`). Never hardcode secrets in test plans or committed repository scripts.
61
-
62
- ---
63
-
64
- ## 4. Truth Anchor & Performance Autopsy Protocol
65
-
66
- 1. **No Lowering Thresholds (Truth Anchor):**
67
- - If an SLA threshold is breached, report the failure with root causes. **Never loosen thresholds, truncate steady states, or drop samples to manufacture a false pass.**
68
- 2. **Structured Analysis Sequence:**
69
- - Analyze results in strict sequence:
70
- 1. **Run Validity:** Confirm `dropped_iterations == 0` and generator CPU remained < 80%. If the generator was saturated, mark the run INVALID.
71
- 2. **Error Rate:** Categorize HTTP 4xx, 5xx, timeouts, connection resets.
72
- 3. **Latency Percentiles:** Report P50, P90, P95, P99, and Max. Never headline average latency.
73
- 4. **Throughput:** Compare target requests/sec vs. achieved requests/sec.
74
- 5. **Correlation:** Correlate breaches with backend APM traces (database slow queries, GC pauses, connection pool exhaustion) before attributing root causes.
28
+ ## 3. Truth Anchor & Autopsy Sequence
29
+ 1. **Truth Anchor:** If an SLA is breached, report root cause honestly. Never loosen thresholds or drop samples to manufacture a fake pass.
30
+ 2. **Analysis Sequence:** 1. Run Validity (`dropped_iterations == 0`, generator CPU < 80%) -> 2. Error Rate (4xx, 5xx, timeouts) -> 3. Latency Percentiles (P50, P90, P95, P99; never headline average) -> 4. Throughput -> 5. APM Correlation (DB slow queries, connection pool exhaustion).