Skip to content

Commit f67f34b

Browse files
committed
chore: failing discovery tests
1 parent 67d4d7b commit f67f34b

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

internal/discovery/discovery.go

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,8 @@ func (d *Discovery) Discover(
12511251
}
12521252
}
12531253

1254+
allComponents := components
1255+
12541256
if len(d.filters) > 0 {
12551257
filtered, evaluateErr := d.filters.Evaluate(l, components)
12561258
if evaluateErr != nil {
@@ -1285,12 +1287,10 @@ func (d *Discovery) Discover(
12851287
return components, errors.Join(errs...)
12861288
}
12871289

1288-
// When filter queries include ONLY dependents (e.g., ...{target}) and NO dependencies,
1289-
// apply additional pruning to retain only the target(s) and their transitive dependents.
1290-
// Skip this when dependency expressions exist (e.g., ...{target}...) since those require
1291-
// keeping both dependencies AND dependents.
1292-
if len(d.dependencyTargetExpressions) == 0 {
1293-
components = d.applyDependentTargeting(l, components)
1290+
// When filter queries include dependents (e.g., ...{target}), re-expand the filtered set
1291+
// to include the target(s) and their transitive dependents from the full component graph.
1292+
if len(d.dependentTargetExpressions) > 0 {
1293+
components = d.applyDependentTargeting(allComponents, components)
12941294
}
12951295

12961296
if d.graphTarget != "" {
@@ -1326,43 +1326,32 @@ func (d *Discovery) filterGraphTarget(components component.Components) (componen
13261326
return filterByAllowSet(components, allowed), nil
13271327
}
13281328

1329-
// applyDependentTargeting prunes the discovered components to the union of all
1330-
// filter targets that requested dependents (via ... prefix) and their transitive dependents.
1331-
// This aligns behavior with --graph-target pruning when the filter queries specify dependents.
1332-
func (d *Discovery) applyDependentTargeting(l log.Logger, components component.Components) component.Components {
1329+
// applyDependentTargeting re-expands the filtered set of components to include
1330+
// the target(s) selected by dependent filter expressions and their transitive dependents.
1331+
func (d *Discovery) applyDependentTargeting(full component.Components, filtered component.Components) component.Components {
13331332
if len(d.dependentTargetExpressions) == 0 {
1334-
return components
1333+
return filtered
13351334
}
13361335

1337-
// Build dependents index once over the full component graph.
1338-
dependentUnits := buildDependentsIndex(components)
1336+
dependentUnits := buildDependentsIndex(full)
13391337
propagateTransitiveDependents(dependentUnits)
13401338

13411339
allowed := make(map[string]struct{})
13421340

1343-
for _, targetExpr := range d.dependentTargetExpressions {
1344-
matched, err := filter.Evaluate(l, targetExpr, components)
1345-
if err != nil {
1346-
l.Warnf("Failed to evaluate dependent target expression %q: %v", targetExpr, err)
1347-
1348-
continue
1349-
}
1350-
1351-
for _, c := range matched {
1352-
targetPath := resolvePath(c.Path())
1353-
allowed[targetPath] = struct{}{}
1341+
for _, target := range filtered {
1342+
targetPath := resolvePath(target.Path())
1343+
allowed[targetPath] = struct{}{}
13541344

1355-
for _, dep := range dependentUnits[targetPath] {
1356-
allowed[dep] = struct{}{}
1357-
}
1345+
for _, dep := range dependentUnits[targetPath] {
1346+
allowed[dep] = struct{}{}
13581347
}
13591348
}
13601349

13611350
if len(allowed) == 0 {
1362-
return components
1351+
return filtered
13631352
}
13641353

1365-
return filterByAllowSet(components, allowed)
1354+
return filterByAllowSet(full, allowed)
13661355
}
13671356

13681357
// canonicalizeGraphTarget resolves the graph target to an absolute, cleaned path with symlinks resolved.

internal/discovery/discovery_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import (
1414
"github.com/stretchr/testify/require"
1515
)
1616

17+
func normPath(p string) string {
18+
if resolved, err := filepath.EvalSymlinks(p); err == nil {
19+
return resolved
20+
}
21+
22+
return p
23+
}
24+
1725
func TestDiscovery(t *testing.T) {
1826
t.Parallel()
1927

@@ -230,7 +238,7 @@ func TestDiscoveryWithDependencies(t *testing.T) {
230238

231239
for i, c := range components {
232240
want := wantDiscovery[i]
233-
assert.Equal(t, want.Path(), c.Path(), "Component path mismatch at index %d", i)
241+
assert.Equal(t, normPath(want.Path()), normPath(c.Path()), "Component path mismatch at index %d", i)
234242
assert.Equal(t, want.Kind(), c.Kind(), "Component kind mismatch at index %d", i)
235243
assert.Equal(t, want.External(), c.External(), "Component external flag mismatch at index %d", i)
236244

@@ -241,7 +249,7 @@ func TestDiscoveryWithDependencies(t *testing.T) {
241249

242250
for j, dep := range cfgDeps {
243251
wantDep := wantDeps[j]
244-
assert.Equal(t, wantDep.Path(), dep.Path(), "Dependency path mismatch at component %d, dependency %d", i, j)
252+
assert.Equal(t, normPath(wantDep.Path()), normPath(dep.Path()), "Dependency path mismatch at component %d, dependency %d", i, j)
245253
assert.Equal(t, wantDep.Kind(), dep.Kind(), "Dependency kind mismatch at component %d, dependency %d", i, j)
246254
assert.Equal(t, wantDep.External(), dep.External(), "Dependency external flag mismatch at component %d, dependency %d", i, j)
247255

@@ -252,7 +260,7 @@ func TestDiscoveryWithDependencies(t *testing.T) {
252260

253261
for k, nestedDep := range depDeps {
254262
wantNestedDep := wantDepDeps[k]
255-
assert.Equal(t, wantNestedDep.Path(), nestedDep.Path(), "Nested dependency path mismatch")
263+
assert.Equal(t, normPath(wantNestedDep.Path()), normPath(nestedDep.Path()), "Nested dependency path mismatch")
256264
}
257265
}
258266
}

test/integration_report_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,19 @@ func TestReportWithExternalDependenciesExcluded(t *testing.T) {
542542
// Verify that the report file contains the expected content
543543
assert.Len(t, report, 2)
544544

545+
depPath := dep
546+
if resolved, err := filepath.EvalSymlinks(dep); err == nil {
547+
depPath = resolved
548+
}
549+
545550
expected := []struct {
546551
name string
547552
result string
548553
reason string
549554
}{
550555
// The first run is always going to be the external dependency,
551556
// as it has an instant runtime.
552-
{name: dep, result: "excluded", reason: "--queue-exclude-external"},
557+
{name: depPath, result: "excluded", reason: "--queue-exclude-external"},
553558
{name: "external-dependency", result: "succeeded"},
554559
}
555560

0 commit comments

Comments
 (0)