diff --git a/.agents/rules/code-review/activation-and-metadata.md b/.agents/rules/code-review/activation-and-metadata.md index bec7e14d122..fd9ccb5724d 100644 --- a/.agents/rules/code-review/activation-and-metadata.md +++ b/.agents/rules/code-review/activation-and-metadata.md @@ -41,7 +41,7 @@ - Old_id: claude-07 - Severity: P1 - Flag: Pick the marker that matches the cause. When one PR excludes tests for different causes, give each exclusion its own reason, and make each reason state the real cause. By default, markers other than `irrelevant` and `flaky` become a non-strict xfail, and `conftest.py` also records a fixture error as `xfailed`. When a marked test fails before its assertions, the reason must name that failure. -- Detect: A marker contradicts its cause, or several exclusions with different causes share one vague reason. A marked test fails during setup because of invalid configuration or a missing required secret that the marker does not describe. +- Detect: A marker contradicts its cause, or several exclusions with different causes share one vague reason. A marked test fails during setup because of invalid configuration or a missing required secret that the marker does not describe. A declaration has no reason. A declaration covers a whole file while some of its classes pass, so passing tests stop running. - ✅ Use `incomplete_test_app (weblog has no /ffe endpoint)` when the weblog does not implement the endpoint. - ❌ Use `missing_feature` for an endpoint that the weblog does not implement. Set `DD_TRACE_AGENT_PORT` to the literal `agent.port`, causing the library to exit at startup while the run reports an expected failure. - Ref: [Declaration decorators](../../../docs/edit/skip-tests.md#declaration-decorators) @@ -74,3 +74,11 @@ - ✅ Add, remove, or rename the workflow step in the same PR as the scenario. - ❌ Add a named scenario without its workflow step, even when its scenario groups are otherwise valid. - Ref: [End-to-end testing rules](../end-to-end-testing.md) + +### META-010: Gate each test at the versions and weblogs where it holds. +- Severity: P0 +- Flag: A manifest version must enable a test only where its expected behavior holds. If a file-level version also enables a class, check that the class works from that version. If the behavior changes between versions, give each class its own version range. If a version passes on one weblog only, do not lower it for every weblog. +- Detect: A file-level or shared version enables a class on a release that lacks its feature. A lowered version also covers weblogs that nobody tested. +- ✅ Gate the class at `v2.11.0-dev` when the file-level `v2.10.0-dev` covers a release without drop telemetry. +- ❌ Lower `Test_Lfi_StackTrace` to `v1.67.0` for every weblog when only one weblog passes there. +- Ref: [Manifest](../../../docs/edit/manifest.md) diff --git a/.agents/rules/code-review/infrastructure-and-conventions.md b/.agents/rules/code-review/infrastructure-and-conventions.md index 54b6b6d954e..bfb10aadb21 100644 --- a/.agents/rules/code-review/infrastructure-and-conventions.md +++ b/.agents/rules/code-review/infrastructure-and-conventions.md @@ -77,7 +77,7 @@ ### INFRA-011: Do not hide shell errors that select what is tested. - Severity: P0 - Flag: A shell command whose result decides what is built or tested must not hide its errors. If it fails, the script must stop with a message. It must not fall back to a default, such as the latest release instead of the jar in `binaries/`. A build image can lack a tool that another image has: the GraalVM image has no `find`. The error was hidden, the jar count was 0, and the dev job tested the release. -- Detect: The script discards stderr (`2>/dev/null`, `&>/dev/null`) or ignores a failure (`|| true`) on a command whose output is counted, parsed, or tested, and an error then looks like an empty result. A pipeline drops the failure of its first command because `pipefail` is off, as in `cmd 2>/dev/null | wc -l` or `cmd | jq`. A failed check goes silently to a fallback branch. A command runs under `if !` with its stderr discarded, so the failure message loses the cause. +- Detect: The script discards stderr (`2>/dev/null`, `&>/dev/null`) or ignores a failure (`|| true`) on a command. The script counts, parses, or tests the output of that command, so an error looks like an empty result. A pipeline drops the failure of its first command because `pipefail` is off, as in `cmd 2>/dev/null | wc -l` or `cmd | jq`. A failed check goes silently to a fallback branch. A command runs under `if !` with its stderr discarded, so the failure message loses the cause. An agent setup step such as `Restart-Service` fails and the script continues, or an install silently checks a file path instead of an import. - Not when: The check tests only whether a tool or option exists (`command -v`, `curl --retry-all-errors --version`), and the code after it fails loudly if needed. The step is best-effort cleanup or log collection that cannot change what is tested. - ✅ Look up files with a bash glob (`shopt -s nullglob`), or let `set -euo pipefail` stop the script. If a fallback is intended, print why it runs. - ❌ `count=$(find /binaries/ -name "dd-java-agent*.jar" 2>/dev/null | wc -l)`, then download the latest release when `count` is 0. diff --git a/.agents/rules/code-review/lifecycle-and-isolation.md b/.agents/rules/code-review/lifecycle-and-isolation.md index d4d86ab94bd..6d163a3028a 100644 --- a/.agents/rules/code-review/lifecycle-and-isolation.md +++ b/.agents/rules/code-review/lifecycle-and-isolation.md @@ -8,7 +8,7 @@ ### LIFE-002: Avoid fixed sleeps and unbounded waits - Severity: P1 - Flag: Do not use `time.sleep()`, fixed delays, or unbounded polling to wait for end-to-end data. Use `agent_interface_timeout` or `library_interface_timeout` for the general post-setup flush window. Use a bounded condition wait in `setup_*` when a specific condition must be observed before teardown or before triggering a subsequent action. -- Detect: A setup or test uses a fixed sleep, polls without a deadline, or increases an arbitrary delay instead of waiting for an observable condition. +- Detect: A setup or test uses a fixed sleep, polls without a deadline, or increases an arbitrary delay instead of waiting for an observable condition. A call inside a deadline loop has no timeout of its own, so it can block past the deadline. A flush timeout or wait budget is shorter than the flush interval of the library, or than other waits for the same event. - Not when: The delay itself is the behavior under test and no observable condition can represent it. - ✅ Configure the scenario flush timeout for general data collection, or use `interfaces.library.wait_for(condition, timeout=...)` for a specific condition. - ❌ Use `time.sleep(30)` before assuming that traces or Remote Config are ready. @@ -32,3 +32,17 @@ - ✅ Store the response and wait result during setup, then assert and inspect the captured data in `test_*`. - ❌ Poll for traces in `test_*` after the containers have stopped, or assert expected trace contents from `setup_*`. - Ref: [End-to-end test flow](../../../docs/understand/test-flow.md#end-to-end-scenario), [Flushing default behavior](../../../docs/edit/flushing.md#default-behavior) + +### LIFE-005: Count asynchronous data only after the flush ends. +- Severity: P0 +- Flag: Assert an exact count of flushed spans, events, or metrics only after the flush ends. A wait that returns at the expected count misses a late extra item. For scenario-wide data, count only the data of the requests of this test. +- Detect: The test asserts an exact count right after a wait that stops at that count. The test compares a scenario-wide metric count with its own requests. +- ✅ Wait for the flush window. Then count only the items of the requests of this test. +- ❌ `spans = wait_for_ai_guard_spans(test_agent, 2)` followed by an exact evaluation count check. + +### LIFE-006: Accept every outcome that a time window can produce. +- Severity: P0 +- Flag: An assertion on a result that depends on a wall-clock window must accept each valid outcome. Stats buckets and sampling windows are such windows. Do not hide this with a `flaky` manifest entry. +- Detect: The test assumes that all spans land in one stats bucket, or it reads only the first bucket. A `flaky` manifest entry hides a result that changes with a sampling window. +- ✅ Merge the stats of all buckets by aggregation key. Adjust the expected tags when the sampling window let a schema be collected. +- ❌ `assert len(buckets) == 1`, or a `flaky` manifest entry for a timing-dependent tag. diff --git a/.agents/rules/code-review/test-effectiveness.md b/.agents/rules/code-review/test-effectiveness.md index 4a68ef64fef..1e197207fc8 100644 --- a/.agents/rules/code-review/test-effectiveness.md +++ b/.agents/rules/code-review/test-effectiveness.md @@ -1,8 +1,8 @@ ### TEST-001: Do not reject valid output because of unrelated data. - Old_id: codex-09 - Severity: P1 -- Flag: When checking one protocol flag, mask that bit and accept other bits the protocol allows, unless the whole field is under test. When checking one member of a list field, such as a `tracestate` vendor or an `x-datadog-tags` entry, find that member. Do not require a count or an order that the protocol does not define. When checking for redaction leaks, use a distinctive marker or the relevant parsed field so unrelated payload values cannot count as leaked input. -- Detect: A sampled-bit assertion requires exact flags `01`. A test requires `len(tracestate) == 1` or compares `x-datadog-tags` as a raw string. A redaction check searches an entire payload for a short marker such as `1234`. +- Flag: When checking one protocol flag, mask that bit and accept other bits the protocol allows, unless the whole field is under test. When checking one member of a list field, such as a `tracestate` vendor or an `x-datadog-tags` entry, find that member. Do not require a count or an order that the protocol does not define. When checking for redaction leaks, use a distinctive marker or the relevant parsed field so unrelated payload values cannot count as leaked input. A mock server must accept a request with an extra parameter that the real service accepts. If timing selects between two valid outcomes, accept each outcome under the condition that selects it. +- Detect: A sampled-bit assertion requires exact flags `01`. A test requires `len(tracestate) == 1` or compares `x-datadog-tags` as a raw string. A redaction check searches an entire payload for a short marker such as `1234`. A test requires one stats bucket, although the tracer buckets stats by wall-clock time. A test compares serialized JSON strings instead of parsed values. - Not when: The whole field is under test. - ✅ For the sampled bit, accept `01` and `03` when the extra bit is allowed. Use `assert any(item.startswith("dd=") for item in tracestate)`. A timestamp containing `1234` must not count as leaked input. - ❌ `assert len(tracestate) == 1`. @@ -59,3 +59,16 @@ - Not when: The test intentionally validates a deliberately broken response. - ✅ Return the real backend envelope under `data.attributes`, and derive the check from the real contract. - ❌ Return the flag config as the whole body and make the self-test expect that same body. + +### TEST-009: Do not let an error pass as a valid result. +- Severity: P0 +- Flag: The test and its app must report an unexpected failure as a failure. Do not catch every exception and return success. Do not treat a failed command like an empty result. Do not coerce malformed input into a default value. If the app drops data that the test path needs, the test must fail. +- Detect: A weblog endpoint catches all exceptions and returns 200. A test treats a failed `container_exec_run` like a `pgrep` without match. An app discards decoder errors. A weblog response omits a header that the tested path needs. +- ✅ Catch only the expected `InvocationTargetException`, and return HTTP 500 for other failures. +- ❌ `} catch (Exception ignored) {}` + +### TEST-010: Assert every expectation that the shared cases define. +- Severity: P1 +- Flag: A test must check every expected field that a shared fixture or a shared assertion helper defines. Do not skip the helper that sibling tests use. +- Detect: A runner reads fixture cases and ignores an expectation field such as `result.features`. A test checks one value while its siblings call `_assert_context_evaluation`. +- ✅ Route the test through `_assert_context_evaluation`, as its siblings do.