This document is for contributors and maintainers of
rules_test_optimization. For consumer onboarding, start with README.md.
- Core rules/tests from repository root:
./bazelw test //tools/...
- Go companion tests from module root:
cd modules/go && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- Python companion tests from module root:
cd modules/python && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- Java companion tests from module root:
cd modules/java && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- NodeJS companion tests from module root:
cd modules/nodejs && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- .NET companion tests from module root:
cd modules/dotnet && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- Ruby companion tests from module root:
cd modules/ruby && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
- Integration harness:
- Linux/macOS:
tools/tests/integration/run_mock_server_tests.sh - Windows:
tools/tests/integration/run_mock_server_tests.ps1
- Linux/macOS:
- Hermetic lane parity (local smoke):
- Run the same commands with sandbox/network-blocking flags used in CI.
- Version alignment guard:
python3 tools/dev/check_module_versions.py
- Root workspace resolves
@datadog-rules-test-optimization-gothroughtools/dev/go_bootstrap.bzl(dev-only wiring). - Root workspace resolves
@datadog-rules-test-optimization-pythonand@datadog-rules-test-optimization-javathrough corresponding dev-only bootstrap extensions undertools/dev/. - Root workspace resolves
@datadog-rules-test-optimization-nodejs,@datadog-rules-test-optimization-dotnet, and@datadog-rules-test-optimization-rubythrough corresponding dev-only bootstrap extensions undertools/dev/. go_bootstrap.local_go_companion(path = "...")must stay repository-relative (no absolute paths, drive prefixes, or..traversal) and must point to a real module root containingMODULE.bazel.- Do not add a root
bazel_depedge from core to the Go companion; that creates a dependency cycle (core -> companion -> core). The same constraint applies to Python, Java, NodeJS, .NET, and Ruby companions. - Schema ownership remains in core:
tools/core/schemas/*tools/core/validate_payload_schema.py
- Keep
tools/runtime-agnostic (tools/core,tools/tests,tools/dev); do not add placeholder language packages undertools/<language>. Language-specific orchestration belongs inmodules/<language>/.
Use this checklist when adding dd_topt_<language>_test support.
-
Wrapper macro
- Add a companion module under
modules/<language>/with a wrapper macro (notools/<language>placeholder package) that accepts:nametopt_data(single-service dict or multi-service mapping)topt_service(optional for multi-service selection)- language test-rule symbol injection (similar to
go_test_rule)
- Ensure it appends selector + manifest labels to
dataand sets:DD_TEST_OPTIMIZATION_MANIFEST_FILEDD_TEST_OPTIMIZATION_PAYLOADS_IN_FILES = "true"
- Default
DD_SERVICEfromtopt_data["service_name"]when callers do not provide it explicitly; preserve caller-providedDD_SERVICEand leaveenv = select(...)unchanged unless you add dedicated configurable-merge support.
- Add a companion module under
-
Selector / inference rule
- Add analysis-time selection logic in
modules/<language>/:- precedence: explicit identifier -> inferred identifier -> fallback identifier -> full bundle
- module label resolution should match
module_<sanitized>names from sync outputs
- Keep fallback-to-full-bundle behavior non-fatal.
- Add analysis-time selection logic in
-
Companion module dependency policy
- Keep root core module (
datadog-rules-test-optimization) free of language-specific rule dependencies. - Put language-specific dependencies (for example
rules_go,rules_python, etc.) in the companion module only. - Use repo-qualified loads back to core shared helpers when needed.
- Keep root core module (
-
Runtime metadata keys
- Extend sync-exported runtime metadata under:
topt_data["runtimes"]["<language>"]
- Keep core keys stable (
repo_name,service_name,manifest_path,labels,set) and avoid changing generated public label names.
- Extend sync-exported runtime metadata under:
-
Tests
- Add unit tests for:
- macro service-selection and data/env wiring
- selector precedence + fallback behavior
- sync export shape for runtime metadata
- Extend integration harness coverage if language runtime inference/selection adds new branches.
- Add unit tests for:
This repository includes bazelw to forward repo env vars consistently:
- In CI-provider mode, preserves provider-derived branch and PR metadata and only fills Git gaps such as current commit author and committer identity.
- Outside supported CI providers, computes Git metadata from the local repo and
forwards it via
--repo_env. - Exported
DD_GIT_*values override computed metadata. - Repository policy: keep root
.bazelrcabsent; prefer explicit flags in CI and example-local.bazelrcfiles.
Examples:
# Refresh only on git environment variables
./bazelw build //tools/... //examples/...
# Refresh on an hourly TTL
FETCH_SALT_TTL=3600 ./bazelw build //tools/... //examples/...
# Override computed Git metadata
DD_GIT_REPOSITORY_URL=https://github.com/acme/api.git \
DD_GIT_BRANCH=main \
DD_GIT_COMMIT_SHA=$(git rev-parse HEAD) \
DD_GIT_COMMIT_AUTHOR_NAME="$(git log -1 --format=%an)" \
DD_GIT_COMMIT_COMMITTER_EMAIL="$(git log -1 --format=%ce)" \
./bazelw test //tools/...# Refresh only on git environment variables
.\bazelw build //tools/... //examples/...
# Refresh on an hourly TTL
$env:FETCH_SALT_TTL = "3600"
.\bazelw build //tools/... //examples/...
# Override computed Git metadata
$env:DD_GIT_REPOSITORY_URL = "https://github.com/acme/api.git"
$env:DD_GIT_BRANCH = "main"
$env:DD_GIT_COMMIT_SHA = (git rev-parse HEAD)
$env:DD_GIT_COMMIT_AUTHOR_NAME = (git log -1 --format=%an)
$env:DD_GIT_COMMIT_COMMITTER_EMAIL = (git log -1 --format=%ce)
.\bazelw test //tools/...Run full sync + uploader flow locally (without hitting Datadog):
tools/tests/integration/run_mock_server_tests.shUpdate integration snapshots intentionally when payload shape changes:
UPDATE_SNAPSHOTS=1 tools/tests/integration/run_mock_server_tests.shWindows entrypoints:
.\tools\tests\integration\run_mock_server_tests.ps1tools\tests\integration\run_mock_server_tests.cmdNotes:
- The PowerShell entrypoint is native and self-contained (no Git Bash dependency). Linux/macOS keep the Bash harness.
- Test-only endpoint overrides:
DD_TEST_OPTIMIZATION_AGENTLESS_URL(shared direct URL override for sync + uploader agentless path)DD_TEST_OPTIMIZATION_AGENT_URL(uploader, EVP proxy path)
- The harness asserts CODEOWNERS enrichment/preservation and runfile manifest fallback behavior, and prints focused diagnostics on assertion failures.
- The harness requires
jqfor snapshot/enrichment assertions. - Snapshot fixture contract:
citestcov_event.jsonremains a JSON object with a non-emptyeventslist.citestcov_coverage.jsonremains a JSON object withversionand a non-emptyfileslist containingfilename+segments.
- CODEOWNERS discovery intentionally checks both
docs/CODEOWNERSand.docs/CODEOWNERS; the.docspath is retained as a legacy compatibility fallback for repositories that still keep ownership files there.
WORKSPACEis intentionally present in sync env discovery/forwarding lists (alongsideGITHUB_WORKSPACE,CI_PROJECT_DIR, etc.) to preserve workspace root resolution in heterogeneous CI environments.UPLOADER_VERSIONandRULES_VERSIONare intentionally independent: uploader script/runtime evolution can ship without forcing a rules contract bump, while payload metadata still carries both values for observability.
- CI includes a Linux hermetic lane (
bazel-tests-hermetic) with sandboxed execution and network blocking, plus cross-platformbazel-testsand mock server integration coverage. - Hermetic scope policy is intentionally Linux-only today to keep CI runtime bounded while preserving one strict sandboxed signal in every PR.
- CI intentionally stays cacheless for Bazel execution in
bazel-tests.- Rationale: each run should re-evaluate repository rules from a fresh state.
- Guardrail: do not add Bazel cache steps (
actions/cache, disk cache, remote cache) without explicit maintainer approval.
- CI includes a lightweight tools coverage signal (
coverage-tools) to ensure line-coverage artifacts are generated and stay above a minimum floor. - Shell linting scope includes integration harnesses,
bazelw, and exampleruntests.shscripts. - CI runs example
runtests.shscripts inRUNTESTS_DRY_RUN=1mode to verify wiring without requiring Datadog credentials in PR checks. - Repository tracks both
.bazelversionandMODULE.bazel.lockin git to reduce local/CI drift. .bazelversionis intentionally duplicated at repository root and companion module roots (modules/go/,modules/python/,modules/java/,modules/nodejs/,modules/dotnet/,modules/ruby/) so either workspace entrypoint resolves the same Bazel line.- CI also keeps a dedicated WORKSPACE-compat probe on Bazel
8.4.1(separate from the8.5.1baseline lanes) so legacy--enable_workspacebehavior is continuously exercised during Bazel 9 migration. - Current PR baseline checks:
./bazelw test //tools/...
cd modules/go && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
cd modules/python && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
cd modules/java && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
cd modules/nodejs && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
cd modules/dotnet && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../..
cd modules/ruby && ../../bazelw test //... --override_module=datadog-rules-test-optimization=../...\bazelw test //tools/...
Push-Location modules/go
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-Location
Push-Location modules\python
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-Location
Push-Location modules\java
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-Location
Push-Location modules\nodejs
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-Location
Push-Location modules\dotnet
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-Location
Push-Location modules\ruby
..\..\bazelw test //... --override_module=datadog-rules-test-optimization=../..
Pop-LocationSource of truth:
tools/core/schemas/agentless-schema.yaml
Regenerate runtime JSON schema:
python3 tools/core/schemas/sync_agentless_schema.pypython3 tools/core/schemas/sync_agentless_schema.pyCheck schema sync status (CI/pre-commit friendly):
python3 tools/core/schemas/sync_agentless_schema.py --checkpython3 tools/core/schemas/sync_agentless_schema.py --checkThe helper uses PyYAML when available and falls back to Ruby's built-in YAML parser.
tools/core/test_optimization_sync.bzl is intentionally being decomposed in
guarded slices rather than one large move. Current slices are:
- shared split-by-module extraction helper (
_split_json_payload_by_module) - env/URL normalization hardening extracted into dedicated helpers
Planned next slices:
- move HTTP transport/retry helpers into a focused module
- isolate repository output/rendering helpers
- keep parity tests green on every slice before removing legacy wrappers
This repository currently uses pre-publication install paths in README
(git_override / commit pin). When publishing to BCR, update and verify:
- Module entries for:
datadog-rules-test-optimizationdatadog-rules-test-optimization-godatadog-rules-test-optimization-pythondatadog-rules-test-optimization-javadatadog-rules-test-optimization-nodejsdatadog-rules-test-optimization-dotnetdatadog-rules-test-optimization-ruby
- Per-module BCR files:
MODULE.bazelmetadata.jsonsource.json
- Companion module
source.jsonmaps archive root tomodules/goviastrip_prefix(and similarly formodules/python,modules/java,modules/nodejs,modules/dotnet, andmodules/ruby).