Skip to content

Commit e75205d

Browse files
authored
[Bug Fix] component() rejects assumed_system_requirements in reqs (#523)
component_impl already collects AssumedSystemRequirementsInfo (ASR) into the upstream lobster level, and both sibling rules (component_update, dependable_element) already accept the provider - only component_test's attribute schema was missing it. This blocked SEooCs from tracing component requirements directly to ASRs without a feature-requirements layer, failing with lobster error: `unknown tracing target req <pkg>.<AssumedSystemReq>.`
2 parents abcb983 + 5fd6b4a commit e75205d

3 files changed

Lines changed: 99 additions & 15 deletions

File tree

‎bazel/rules/rules_score/private/component.bzl‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ def _component_impl(ctx):
159159
# and bubble up SphinxSourcesInfo from sub-components/units.
160160
#
161161
# Only ComponentRequirementsInfo-providing targets contribute their own
162-
# rendered RST here. feature_requirements targets are commonly also listed
163-
# in `requirements` (see below) purely so their .lobster file can resolve
164-
# derived_from references from the component requirements; they are
165-
# already rendered once at the dependable_element level, so re-rendering
166-
# them per component would duplicate the feature requirements page across
167-
# every component that references the same feature.
162+
# rendered RST here. feature_requirements / assumed_system_requirements
163+
# targets are commonly also listed in `requirements` (see below) purely so
164+
# their .lobster file can resolve derived_from references from the component
165+
# requirements; they are already rendered once at the dependable_element
166+
# level, so re-rendering them per component would duplicate the upstream
167+
# requirements page across every component that references the same item.
168168
# -------------------------------------------------------------------------
169169
req_sphinx_files = []
170170
for req_target in ctx.attr.requirements:
@@ -181,7 +181,10 @@ def _component_impl(ctx):
181181

182182
# -------------------------------------------------------------------------
183183
# Lobster Tracing: collect .lobster files from component_requirements targets
184-
# and feature_requirements targets (needed to resolve derived_from references).
184+
# and from upstream requirements targets -- feature_requirements, or
185+
# assumed_system_requirements when a SEooC traces component requirements
186+
# directly to ASRs without a feature requirements layer. Both feed the
187+
# config's upstream level, so derived_from references resolve either way.
185188
# -------------------------------------------------------------------------
186189
req_lobster_files = []
187190
req_lobster_transitive_files = []
@@ -367,8 +370,9 @@ _component_test = rule(
367370
),
368371
"requirements": attr.label_list(
369372
default = [],
370-
providers = [[ComponentRequirementsInfo], [FeatureRequirementsInfo]],
371-
doc = "Component requirements artifacts (component_requirements or feature_requirements targets)",
373+
providers = [[ComponentRequirementsInfo], [FeatureRequirementsInfo], [AssumedSystemRequirementsInfo]],
374+
doc = "Component requirements artifacts (component_requirements, feature_requirements or " +
375+
"assumed_system_requirements targets)",
372376
),
373377
"components": attr.label_list(
374378
providers = [[ComponentInfo], [UnitInfo]],
@@ -429,12 +433,16 @@ def component(
429433
name: The name of the component. Used as the target name.
430434
requirements: List of labels to component_requirements targets
431435
that define the requirements for this component. A
432-
feature_requirements target may also be listed here so its
433-
.lobster file is available to resolve derived_from references
434-
from the component requirements; only component_requirements
435-
targets contribute rendered RST to the component's Sphinx docs,
436-
so listing a feature_requirements target does not duplicate it
437-
in the generated documentation.
436+
feature_requirements or assumed_system_requirements target may
437+
also be listed here so its .lobster file is available to resolve
438+
derived_from references from the component requirements; only
439+
component_requirements targets contribute rendered RST to the
440+
component's Sphinx docs, so listing an upstream requirements
441+
target does not duplicate it in the generated documentation.
442+
A SEooC that derives its component requirements directly from
443+
Assumed System Requirements (without an intermediate feature
444+
requirements layer) lists the assumed_system_requirements target
445+
here.
438446
components: List of labels to nested component targets (for hierarchical
439447
component structures).
440448
tests: List of labels to Bazel test targets that verify the component

‎bazel/rules/rules_score/test/BUILD‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ load(
135135
)
136136
load(
137137
":unit_component_test.bzl",
138+
"component_direct_asr_test",
138139
"component_excludes_feature_req_docs_test",
139140
"component_provider_test",
140141
"component_requirements_transitive_test",
@@ -286,6 +287,14 @@ component_requirements(
286287
# (AoUs reach a dependable_element as `safety_measures` of its safety_analysis; see
287288
# :aou_root_cause_aous.)
288289

290+
# Component requirements tracing directly to an AssumedSystemReq, with no
291+
# feature_requirements layer (used by :test_component_direct_asr).
292+
component_requirements(
293+
name = "comp_req_direct_asr",
294+
srcs = ["fixtures/seooc_test/component_requirements_direct_asr.trlc"],
295+
deps = [":asr_trlc"],
296+
)
297+
289298
# - Architecture Design: wp__component_arch
290299
architectural_design(
291300
name = "arch_design",
@@ -1349,6 +1358,24 @@ component(
13491358
tests = [], # Empty for testing
13501359
)
13511360

1361+
# Test Component tracing straight to Assumed System Requirements, i.e. with no
1362+
# feature_requirements layer in between (see
1363+
# fixtures/seooc_test/component_requirements_direct_asr.trlc). The
1364+
# assumed_system_requirements target must be accepted in `requirements` so its
1365+
# .lobster file reaches the component's lobster config; otherwise lobster-trace
1366+
# fails with "unknown tracing target req TestSEooC.ASR_TEST_001".
1367+
component(
1368+
name = "test_component_direct_asr",
1369+
testonly = True,
1370+
components = [":test_unit"],
1371+
requirements = [
1372+
":comp_req_direct_asr",
1373+
":asr_trlc",
1374+
],
1375+
tags = ["manual"],
1376+
tests = [],
1377+
)
1378+
13521379
# Test Dependable Element.
13531380
# maturity = "development": this fixture intentionally omits a
13541381
# test_case_coverage.lock.yaml, so under the release traceability gate its
@@ -2054,6 +2081,14 @@ component_excludes_feature_req_docs_test(
20542081
target_under_test = ":test_component",
20552082
)
20562083

2084+
# Regression test for component() rejecting assumed_system_requirements targets
2085+
# in `requirements`, which blocked SEooCs that trace component requirements
2086+
# directly to ASRs (no feature requirements layer).
2087+
component_direct_asr_test(
2088+
name = "component_direct_asr_test",
2089+
target_under_test = ":test_component_direct_asr",
2090+
)
2091+
20572092
component_test_case_coverage_lock_test(
20582093
name = "component_test_case_coverage_lock_test",
20592094
target_under_test = ":test_component_with_test_case_coverage_lock",

‎bazel/rules/rules_score/test/unit_component_test.bzl‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,46 @@ def _component_excludes_feature_req_docs_test_impl(ctx):
211211

212212
component_excludes_feature_req_docs_test = analysistest.make(_component_excludes_feature_req_docs_test_impl)
213213

214+
def _component_direct_asr_test_impl(ctx):
215+
"""Test that a component whose component_requirements trace straight to
216+
Assumed System Requirements -- with no feature_requirements layer -- can
217+
list the assumed_system_requirements target in `requirements`, and that its
218+
.lobster file reaches the generated lobster config.
219+
220+
Regression test: the rule's `requirements` attribute used to only accept
221+
[ComponentRequirementsInfo] / [FeatureRequirementsInfo], so passing an
222+
assumed_system_requirements target failed analysis with "does not have
223+
mandatory providers" even though the implementation already handled
224+
AssumedSystemRequirementsInfo. Without the ASR .lobster in the config,
225+
lobster-trace reports "unknown tracing target req <pkg>.<AssumedSystemReq>".
226+
"""
227+
env = analysistest.begin(ctx)
228+
target_under_test = analysistest.target_under_test(env)
229+
230+
asserts.true(
231+
env,
232+
ComponentInfo in target_under_test,
233+
"Component tracing directly to ASRs should provide ComponentInfo",
234+
)
235+
236+
# The ASR .lobster must be wired into the component's lobster pipeline as an
237+
# upstream source, otherwise derived_from references cannot be resolved.
238+
input_basenames = []
239+
for action in analysistest.target_actions(env):
240+
for f in action.inputs.to_list():
241+
input_basenames.append(f.basename)
242+
243+
asserts.true(
244+
env,
245+
"asr_trlc.lobster" in input_basenames,
246+
"The assumed_system_requirements .lobster file should feed the " +
247+
"component's lobster actions (inputs found: %s)" % input_basenames,
248+
)
249+
250+
return analysistest.end(env)
251+
252+
component_direct_asr_test = analysistest.make(_component_direct_asr_test_impl)
253+
214254
# ============================================================================
215255
# Test Case Coverage Lock Tests
216256
# ============================================================================
@@ -338,6 +378,7 @@ def unit_component_test_suite(name):
338378
":component_provider_test",
339379
":component_sphinx_sources_test",
340380
":component_excludes_feature_req_docs_test",
381+
":component_direct_asr_test",
341382
":component_test_case_coverage_lock_test",
342383
":component_requirements_transitive_test",
343384
":test_case_coverage_lock_check_action_release_test",

0 commit comments

Comments
 (0)