Skip to content

Commit 3e8c76c

Browse files
feat: don't match test derivations
1 parent e3ead57 commit 3e8c76c

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/shared/listeners/automatic_linkage.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,17 @@ def produce_linkage_candidates(
9191
# TODO: record what is used to expand the candidate list.
9292
candidates: dict[NixDerivation, ProvenanceFlags] = {}
9393
# TODO: improve accuracy by using bigrams similarity with a `| Q(...)` query.
94-
matches = NixDerivation.objects.filter(
95-
package_q | product_q,
96-
parent_evaluation__in=list(latest_complete_channels),
97-
).annotate(**annotations)
94+
matches = (
95+
NixDerivation.objects.exclude(
96+
# Test derivations are a Nixpkgs implementation detail and never represent software to be distributed.
97+
attribute__startswith="tests.",
98+
)
99+
.filter(
100+
package_q | product_q,
101+
parent_evaluation__in=list(latest_complete_channels),
102+
)
103+
.annotate(**annotations)
104+
)
98105
for drv in matches.iterator():
99106
flags = getattr(drv, "package_match", 0) | getattr(drv, "product_match", 0)
100107
candidates[drv] = ProvenanceFlags(flags)

src/shared/tests/test_linkage.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ def test_mixed_cpe_parts_skips_hardware_only_affected_products(
229229
suggestion = CVEDerivationClusterProposal.objects.get(cve=app_container.cve)
230230
assert suggestion.derivations.filter(name__startswith="myapp").exists()
231231
assert not suggestion.derivations.filter(name__startswith="some_router").exists()
232+
233+
234+
def test_ignore_tests(
235+
cve: Container,
236+
make_drv: Callable[..., NixDerivation],
237+
) -> None:
238+
drv1 = make_drv(attribute="foo")
239+
drv2 = make_drv(attribute="tests.foo")
240+
241+
assert build_new_links(cve)
242+
243+
suggestion = CVEDerivationClusterProposal.objects.get(cve=cve.cve)
244+
assert suggestion.derivations.filter(attribute=drv1.attribute).exists()
245+
assert not suggestion.derivations.filter(attribute=drv2.attribute).exists()

0 commit comments

Comments
 (0)