|
1 | 1 | --- |
2 | | -description: |
| 2 | +description: Rules for activating and deactivating tests using manifests or decorators |
3 | 3 | globs: |
4 | 4 | alwaysApply: true |
5 | 5 | --- |
6 | | -# Activate or deactivate tests |
| 6 | +# Test Activation and Deactivation |
7 | 7 |
|
8 | | -For enabling/disabling tests, refer to these key documentation files: |
| 8 | +**Always prefer manifests over decorators.** |
9 | 9 |
|
10 | | -- @docs/edit/enable-test.md: How to enable tests and test against unmerged changes |
11 | | -- @docs/edit/manifest.md: Using manifest files for test activation/deactivation |
12 | | -- @docs/edit/skip-tests.md: Using decorators and marking tests as skipped |
13 | | -- @docs/edit/versions.md: Version specification guidelines for different languages |
| 10 | +## Key Documentation |
14 | 11 |
|
15 | | -Key points to remember to activate or deactivate tests: |
| 12 | +- @docs/edit/manifest.md: Manifest file format, entry formats, and syntax rules |
| 13 | +- @docs/edit/skip-tests.md: Decorator usage (when manifests cannot be used) |
| 14 | +- @docs/edit/enable-test.md: How to enable tests |
| 15 | +- @docs/edit/versions.md: Version specification guidelines |
16 | 16 |
|
17 | | -1. For test classes/files: Use manifest files in `manifests/` directory |
18 | | -2. For individual test methods: Use decorators in test files |
19 | | -3. Always include JIRA references for bugs using the `reason` parameter. |
20 | | -4. Never assume that not adding a test to a language's manifest will disable it - tests run by default unless explicitly disabled |
21 | | -5. Entries in the manifest file MUST be sorted in alphabetical order. After edit a manifest file ALWAYS run the scenario "TEST_THE_TEST" and format.sh before committing changes to ensure code follows the manifest rules. |
22 | | -6. When using @missing_feature/@irrelevant decorators, the condition specifies when to SKIP the test. |
23 | | -7. For update a manifest yml file, never add fields that don't exist in any other manifests files. Use the documentation [manifests files specification](mdc:docs/edit/manifest.md) to be accurate in your modifications. |
| 17 | +--- |
| 18 | + |
| 19 | +## Decision: Manifest vs Decorator |
| 20 | + |
| 21 | +``` |
| 22 | +Does the condition depend ONLY on: |
| 23 | + - Library name (java, python, nodejs, etc.) |
| 24 | + - Library version |
| 25 | + - Weblog variant |
| 26 | + - Agent version (alone) |
| 27 | +? |
| 28 | + │ |
| 29 | + ├─► YES → Use MANIFEST (preferred) |
| 30 | + │ - Library conditions → manifests/{library}.yml |
| 31 | + │ - Agent version conditions → manifests/agent.yml |
| 32 | + │ |
| 33 | + └─► NO (uses context.scenario, context.vm_name, |
| 34 | + or other attributes, or complex combinations) |
| 35 | + → Use DECORATOR (only option) |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Manifest Rules |
| 41 | + |
| 42 | +### Do NOT Create New Manifest Files |
| 43 | + |
| 44 | +The existing manifests cover all supported libraries. If creating a new manifest seems needed: |
| 45 | +1. STOP and ask the user first |
| 46 | +2. Suggest asking in **#apm-shared-testing** Slack channel |
| 47 | +3. Only proceed if explicitly confirmed |
| 48 | +4. If confirmed, also update `utils/manifest/_internal/parser.py` |
| 49 | + |
| 50 | +### Using YAML References (Anchors) |
| 51 | + |
| 52 | +is a repeating pattern in your modifications. |
| 53 | + |
| 54 | +References are defined in the `refs:` section at the top of manifests: |
| 55 | + |
| 56 | +```yaml |
| 57 | +refs: |
| 58 | + - &ref_5_0_0 v5.0.0 |
| 59 | + - &ref_5_6_0 '>=5.6.0' |
| 60 | + - &django_weblogs "django-poc, django-py3.13, python3.12" |
| 61 | +``` |
| 62 | + |
| 63 | +**Rules:** |
| 64 | +1. Check for existing references before adding a version |
| 65 | +2. Verify what a reference contains before using it |
| 66 | +3. Don't mix reference types (version refs vs declaration refs) |
| 67 | +4. You should not change existing references without explicit approval from the user. |
| 68 | +5. You can create new references only in manifests that already have references and |
| 69 | + with approval from the user. You should propose creating new references when there |
| 70 | + |
| 71 | +**Mistake to avoid:** |
| 72 | +```yaml |
| 73 | +# WRONG - using a version ref where a declaration is expected |
| 74 | +tests/path/test.py::TestClass: |
| 75 | + - declaration: *ref_5_0_0 # ref_5_0_0 is "v5.0.0", not a valid declaration! |
| 76 | + component_version: '<5.0.0' |
| 77 | + |
| 78 | +# CORRECT |
| 79 | +tests/path/test.py::TestClass: |
| 80 | + - declaration: missing_feature (Description) |
| 81 | + component_version: '<5.0.0' |
| 82 | +``` |
| 83 | + |
| 84 | +### After Modifying Manifests |
| 85 | + |
| 86 | +**ALWAYS run `./format.sh` after any manifest modification.** |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Decorator Rules |
| 91 | + |
| 92 | +### Version Format |
| 93 | + |
| 94 | +**CRITICAL**: Always use `library@version` format: |
| 95 | + |
| 96 | +```python |
| 97 | +# CORRECT |
| 98 | +@missing_feature(context.library < "python@2.5.0", reason="...") |
| 99 | + |
| 100 | +# WRONG - missing library specifier |
| 101 | +@missing_feature(context.library < "2.5.0", reason="...") |
| 102 | +``` |
| 103 | + |
| 104 | +### Always Include Reason |
| 105 | + |
| 106 | +** Rules ** |
| 107 | +1. When you don't know the reason you should ask the user |
| 108 | +2. Bugs must reference a valid JIRA ticket, you must ask the user for one |
| 109 | + |
| 110 | +```python |
| 111 | +# CORRECT |
| 112 | +@missing_feature(condition, reason="Feature not implemented yet") |
| 113 | +@bug(condition, reason="JIRA-1234") |
| 114 | + |
| 115 | +# WRONG - missing reason |
| 116 | +@missing_feature(condition) |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Quick Reference: User Request → Action |
| 122 | + |
| 123 | +| User Request | Use | Format | |
| 124 | +|--------------|-----|--------| |
| 125 | +| "Bug for {library}" | Manifest | `bug (JIRA-XXX)` in `{library}.yml` | |
| 126 | +| "Bug for {library} >= X.Y.Z" | Manifest | Explicit with `component_version` | |
| 127 | +| "Feature available from X.Y.Z" | Manifest | `vX.Y.Z` | |
| 128 | +| "Irrelevant for {library}" | Manifest | `irrelevant (reason)` | |
| 129 | +| "Flaky for {library}" | Manifest | `flaky (JIRA-XXX)` | |
| 130 | +| "Bug on {weblog} variant" | Manifest | `weblog_declaration` format | |
| 131 | +| "Bug for agent version X" | Manifest | Entry in `agent.yml` | |
| 132 | +| "Bug for scenario X" | **Decorator** | `@bug(context.scenario == ...)` | |
| 133 | +| "Bug on specific VM" | **Decorator** | `@bug(context.vm_name == ...)` | |
| 134 | +| "Bug for agent + library combo" | **Decorator** | Complex condition | |
| 135 | +| "Skip test completely" | **Decorator** | With `force_skip=True` | |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Common Mistakes to Avoid |
| 140 | + |
| 141 | +1. ❌ Using decorators when manifests can express the condition |
| 142 | +2. ❌ Forgetting the `reason` parameter in decorators |
| 143 | +3. ❌ Using `library < "2.5.0"` instead of `library < "python@2.5.0"` |
| 144 | +4. ❌ Not sorting manifest entries alphabetically |
| 145 | +5. ❌ Using `false` or invalid markers in manifests (use only: `irrelevant`, `bug`, `flaky`, `missing_feature`, `incomplete_test_app`) |
| 146 | +6. ❌ Forgetting to quote values with special YAML characters (`>`, `<`, `:`, `#`) |
| 147 | +7. ❌ Creating new manifest files without asking first |
| 148 | +8. ❌ Using `X.Y.Z` instead of `vX.Y.Z` for versions (see warning below) |
| 149 | + |
| 150 | +### Version Format Warning |
| 151 | + |
| 152 | +**If you see a version like `1.2.0` (without `v` prefix) in a manifest, ASK THE USER if this is intentional:** |
| 153 | + |
| 154 | +- `vX.Y.Z` = `>=X.Y.Z` (enabled for this version AND all future versions) ✓ Common case |
| 155 | +- `X.Y.Z` = exactly that version only ⚠️ Rarely intended |
| 156 | + |
| 157 | +```yaml |
| 158 | +# COMMON - enables test for v1.2.0 and all later versions |
| 159 | +tests/path/test.py::TestClass: v1.2.0 |
| 160 | + |
| 161 | +# RARE - enables test ONLY for exactly version 1.2.0 (not 1.2.1, not 1.3.0) |
| 162 | +tests/path/test.py::TestClass: 1.2.0 # ⚠️ Ask user: "Did you mean v1.2.0?" |
| 163 | +``` |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Examples |
| 168 | + |
| 169 | +### Example 1: Deactivate for library (all versions) |
| 170 | + |
| 171 | +**Request:** "Test X is irrelevant for java" |
| 172 | + |
| 173 | +**Action:** Add to `manifests/java.yml`: |
| 174 | +```yaml |
| 175 | + tests/path/test.py::TestClass::test_method: irrelevant (Not applicable to Java) |
| 176 | +``` |
| 177 | + |
| 178 | +### Example 2: Bug from specific version |
| 179 | + |
| 180 | +**Request:** "Bug in test X for nodejs >= 5.0.0, ticket APPSEC-123" |
| 181 | + |
| 182 | +**Action:** Add to `manifests/nodejs.yml`: |
| 183 | +```yaml |
| 184 | + tests/path/test.py::TestClass::test_method: |
| 185 | + - declaration: bug (APPSEC-123) |
| 186 | + component_version: '>=5.0.0' |
| 187 | +``` |
| 188 | + |
| 189 | +### Example 3: Feature available from version |
| 190 | + |
| 191 | +**Request:** "Test X requires python 2.5.0 or higher" |
| 192 | + |
| 193 | +**Action:** Add to `manifests/python.yml`: |
| 194 | +```yaml |
| 195 | + tests/path/test.py::TestClass::test_method: v2.5.0 |
| 196 | +``` |
| 197 | + |
| 198 | +### Example 4: Weblog-specific issue |
24 | 199 |
|
25 | | -## CRITICAL: Decorator Usage Rules |
| 200 | +**Request:** "Test X fails on fastify for nodejs" |
26 | 201 |
|
27 | | -8. **Version Format**: ALWAYS use `library@version` format in version comparisons (e.g., `context.library < "python@2.5.0"`, NOT `context.library < "2.5.0"`). The language specifier is MANDATORY. |
| 202 | +**Action:** Add to `manifests/nodejs.yml`: |
| 203 | +```yaml |
| 204 | + tests/path/test.py::TestClass: |
| 205 | + - weblog_declaration: |
| 206 | + "*": v5.0.0 |
| 207 | + fastify: bug (JIRA-123) |
| 208 | +``` |
28 | 209 |
|
29 | | -9. **Reason Parameter**: ALWAYS include the `reason` parameter for decorators: |
30 | | - - `@missing_feature(condition, reason="Feature not implemented yet")` |
31 | | - - `@bug(condition, reason="JIRA-1234")` |
32 | | - - `@irrelevant(condition, reason="Not applicable to this language")` |
33 | | - - `@incomplete_test_app(condition, reason="Weblog endpoint missing")` |
| 210 | +### Example 5: Scenario-specific (requires decorator) |
34 | 211 |
|
35 | | -10. **Decorator Behavior Differences**: |
36 | | - - `@missing_feature` and `@bug`: Test STILL RUNS, results in XPASS (if passes) or XFAIL (if fails) |
37 | | - - `@irrelevant`: Test is SKIPPED completely, never runs |
38 | | - - `@flaky`: Test is NOT executed by default |
39 | | - - Use `force_skip=True` parameter to prevent execution of `@missing_feature` or `@bug` decorated tests |
| 212 | +**Request:** "Test X doesn't apply to profiling scenario" |
40 | 213 |
|
41 | | -11. **Manifest Disable Markers**: To disable tests in manifest files, use ONLY these valid markers: |
42 | | - - `irrelevant` (with optional comment/link) |
43 | | - - `bug` (with JIRA reference in comment) |
44 | | - - `flaky` |
45 | | - - `missing_feature` |
46 | | - - NEVER use `false` or other arbitrary values |
| 214 | +**Action:** Add decorator in test file: |
| 215 | +```python |
| 216 | +@irrelevant(context.scenario == scenarios.profiling, reason="Not applicable to profiling") |
| 217 | +def test_method(self): |
| 218 | + pass |
| 219 | +``` |
47 | 220 |
|
48 | | -12. **Language-Specific Conditions**: When using decorators with version checks, ensure the condition properly targets the intended language. Example: `@missing_feature(context.library < "python@2.5.0")` will NOT skip for other languages like Node.js or Java. |
| 221 | +### Example 6: Multiple libraries |
49 | 222 |
|
50 | | -For common test activation patterns and examples of enabling/disabling tests, see: |
| 223 | +**Request:** "Test X is irrelevant for both python and nodejs" |
51 | 224 |
|
52 | | -1. @docs/edit/manifest.md#example |
53 | | -2. @docs/edit/versions.md#use-cases |
54 | | -3. @docs/edit/skip-tests.md#decorators |
| 225 | +**Action:** Add to BOTH `manifests/python.yml` AND `manifests/nodejs.yml`: |
| 226 | +```yaml |
| 227 | + tests/path/test.py::TestClass: irrelevant (Reason) |
| 228 | +``` |
0 commit comments