Test Strategy
Developer-facing description of how rules_score is tested. Tests are
layered; every behaviour is asserted at the lowest level that can observe it.
Levels
Level |
Location |
Module |
Framework |
Run |
|---|---|---|---|---|
L0 tool unit |
|
root |
|
|
L1 Starlark logic |
|
root |
skylib |
|
L2 analysis contract |
|
|
skylib |
|
L3 artifacts |
|
|
golden files ( |
|
L4 end-to-end |
|
own module |
|
|
test/ and integration_test/ are separate Bazel modules (ignored by the
root workspace, consuming score_tooling via local_path_override), so they
are run from their own directory and have their own CI jobs. L1 runs in the root
CI step //bazel/rules/rules_score/... -//bazel/rules/rules_score/examples/...;
the L0 tools run there (src/) and in the //plantuml/... step (parsers).
The legacy test/BUILD stays in place; its tests move into the level
directories rule by rule. analysis/dependable_element is the template for
new L2 tests, analysis/rst_to_trlc and artifacts/rst_to_trlc show the
single-action case, artifacts/component is the template for new L3 tests,
the L1 tests below are the template for new L1 tests.
L2 conventions
One
<rule>_test.bzlper rule intest/analysis/<rule>/, exposing a<rule>_test_suite(name)macro that is instantiated in that directory’sBUILD(rules_testinganalysis_test+test_suite). Each test is a_<case>_test(name)function creating its fixtures and an_<case>_impl(env, target)function with the assertions.Shared helpers live in
test/lib/:analysis.bzl(find_action,argv_of,flag_value,file_write_json,output_path,template_substitutions,expect_maturity_flags,expect_failure_message) andfixtures.bzl(minimalmanualfixtures such asfixture_dependable_element, built withutil.helper_target). Derive fixture labels from the subject’s label, not from literal names.The subject is the target that owns the actions, for example
<name>_indexof adependable_element. Pick actions by mnemonic and output name, not by position, and assert flags by presence or absence (flag_valuefor flag/value pairs).Positive cases check providers, action arguments and
FileWritecontent. Negative cases useexpect_failure = Trueforfail()paths reachable at analysis time; adevelopmentfixture asserts that the same input does not fail (the warning itself is not observable). Execution-time failures (validation CLI, lobster, coverage lock check) are not observable here; they belong to L0 and L4.Fixtures may violate release gates if the tested contract is analysis-only. This is allowed because they are
manualhelper targets that are never built.--analysis_testing_deps_limitonly applies to tests that use a configuration transition (config_settings) and counts the direct edges of the test rule (4 for adependable_elementsubject), so the default limit is no obstacle.Migrating a legacy skylib
analysistestfromtest/: port the assertions into the matchinganalysis/<rule>/suite, check the old targets withbazel query 'rdeps(//..., <old target>)', then delete the old rule, itsBUILDtargets, suite entries and fixtures in the same change.
L3 conventions
One package per rule in
test/artifacts/<rule>/. ItsBUILDbuilds a real chain (requirements → rule) and diffs the output against a checked-in golden.componentanddependable_elementare test rules: tag themmanualsobazel test //...only runs the golden and log checks.Helpers live in
test/lib/artifacts.bzl:golden_test(wrapswrite_source_files; its<name>target refreshes the golden, it is not a test itself),output_file(exposes the one file whose path ends insuffixfromDefaultInfoor an output group) andcomponent_architecture_lobster(readsComponentInfo.architecture). They aretestonly; no output group is added to the shipped rules for tests.Name goldens
<output>.golden. The suffix keeps formatters and the header check off generated content.bazel run //artifacts/<rule>:<name>refreshes a golden,//artifacts/<rule>:<name>_testdiffs it. Review the golden diff like code.Execution-time logs (for example validation PASS/FAIL) are read with
output_filefrom thedebugoutput group and checked by a smallsh_test; they are not goldens.
L1 conventions
One
<module>_test.bzlper testedprivate/<module>.bzlinprivate/tests/, exposing a<module>_test_suite(name)macro that is instantiated inprivate/tests/BUILD. Thel1test suite aggregates all.Tests use skylib
loadingtest: one test target perloadingtest.equalscase, named<suite>_<case>. Only functions that need no realctxor action belong here; fake files and contexts withstruct(...).@score_toolingis the main repository in the root module. For external-repository cases use a dependency label such as@bazel_skylib//lib:...and assert that itsworkspace_nameis not empty.fail()paths and anything observing providers or actions are tested at L2.
L0 Python conventions
One
<tool>_test.pyper tool insrc/tests/, declared with thepytest_testmacro (src/tests/pytest_test.bzl), which runs pytest on the file, writes the JUnit XML and maps--test_filterto-k. Tests are plainunittest.TestCaseclasses run by pytest; there is nounittest.main(). Theteststest suite aggregates all.Data files are passed as
$(rlocationpath ...)env vars and resolved withpython.runfiles, not relative paths.src/tests/is a separate package so that the non-recursivesrc/*.pyglobs (:py_srcs, traceability) stay unchanged.Lint gate: ruff and ty must be clean for
src/tests/...:bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation \ //bazel/rules/rules_score/src/tests/...
The “Python lint” workflow runs this as a blocking step; the tools in
src/are not yet covered by the gate.
Level responsibilities
Level |
Observes |
Asserts |
Does not assert |
|---|---|---|---|
L0 |
Tool process with hand-written inputs |
Parser/checker logic, exit codes, messages on broken input |
Rule wiring |
L1 |
Pure |
Label keys, scope calculation, config building, view layout, provenance |
Providers, actions |
L2 |
Providers, actions, |
Action arguments (maturity flags), |
Anything an action produces at execution time |
L3 |
Real action outputs of one in-process build |
Goldens for contract outputs, targeted assertions for the rest |
User workflows, bzlmod consumption |
L4 |
A consumer’s |
Outcome (pass/fail) and stderr pattern per case, |
Output content (covered by L3) |
Example, “release gate fails the build”: L0 checks that the tool exits non-zero
on broken input, L2 checks that no --warn-on-errors is passed under
maturity = "release", L4 checks that one broken fixture fails with the
expected message. Each level covers a different link of the chain.
Golden policy
Diff tests are used only at L3 and only for structured, execution-time contract
outputs (for example *_architecture.lobster). They are not used for
pass/fail logs, HTML, or content already readable at L2
(validation_inputs.json, architecture.json). Goldens are declared with
write_source_files (aspect_bazel_lib): bazel run of the <name>
target refreshes the golden, <name>_test diffs it. The .golden suffix
keeps formatters and header checks off generated content.
Fixture policy
Positive fixtures use
maturity = "release": any finding fails their verdict, so previously hidden errors surface.Negative fixtures use
maturity = "development"(findings stay warnings) or are L4 expected-failure cases.Examples under
examples/are positive end-to-end fixtures. Negative and workflow fixtures live only inintegration_test/, never in examples.
Dependencies
test/:rules_testing(new analysis tests) next to skylib (existing tests),aspect_bazel_lib(golden update targets). Adiff_testkeeps the module’s own.bazelversionin sync with the root one.integration_test/:rules_bazel_integration_test. The nested Bazel version is read from the root.bazelversion; adiff_testkeeps the module’s own.bazelversionin sync.