From 4a7445fd06b59881548ac5f6ce4e0c1693364af3 Mon Sep 17 00:00:00 2001 From: rgodden <7768980+goddenrich@users.noreply.github.com> Date: Wed, 28 Jan 2026 12:41:50 +0000 Subject: [PATCH] test showing bug with whatinputs --- src/query/whatinputs_test.go | 13 +++++++++++++ test/whatinputs/BUILD | 7 +++++++ test/whatinputs/test_package/BUILD | 14 ++++++++++++++ test/whatinputs/test_package/bar.txt | 0 4 files changed, 34 insertions(+) create mode 100644 test/whatinputs/test_package/bar.txt diff --git a/src/query/whatinputs_test.go b/src/query/whatinputs_test.go index 09e82712b7..51fc10958f 100644 --- a/src/query/whatinputs_test.go +++ b/src/query/whatinputs_test.go @@ -88,3 +88,16 @@ func TestWhatInputsSourceBothTargetsHidden(t *testing.T) { inputLabels := whatInputs(graph.AllTargets(), "package1/file1.txt", true) assert.Equal(t, []core.BuildLabel{{PackageName: "package1", Name: "_target1#srcs"}, {PackageName: "package1", Name: "target1"}}, inputLabels) } + +func TestWhatInputsSingleTargetParentUnderscore(t *testing.T) { + graph := core.NewGraph() + pkg := core.NewPackage("package1") + fileSource := core.FileLabel{File: "file1.txt", Package: pkg.Name} + internalTarget := addNewTarget(graph, pkg, "__target1#srcs", []core.BuildInput{fileSource}) + addNewTarget(graph, pkg, "_target1", []core.BuildInput{fileSource, internalTarget.Label}) + graph.AddPackage(pkg) + + inputLabels := whatInputs(graph.AllTargets(), "package1/file1.txt", false) + assert.Equal(t, []core.BuildLabel{{PackageName: "package1", Name: "_target1"}}, inputLabels) +} + diff --git a/test/whatinputs/BUILD b/test/whatinputs/BUILD index 9fa9bd96cb..5fc303e0dc 100644 --- a/test/whatinputs/BUILD +++ b/test/whatinputs/BUILD @@ -7,6 +7,13 @@ plz_e2e_test( expected_output = "multiple_sources.txt", ) +plz_e2e_test( + name = "hidden_targets", + cmd = "plz query whatinputs test/whatinputs/test_package/bar.txt", + expected_failure = False, + expect_output_contains = "//test/whatinputs/test_package:_target2", +) + plz_e2e_test( name = "source_and_no_source", cmd = "plz query whatinputs making/up/a/file/path/should/be/easy test/whatinputs/test_package/foo.txt", diff --git a/test/whatinputs/test_package/BUILD b/test/whatinputs/test_package/BUILD index 18ebe28f93..2ed10830f8 100644 --- a/test/whatinputs/test_package/BUILD +++ b/test/whatinputs/test_package/BUILD @@ -4,3 +4,17 @@ genrule( outs = ["out.txt"], cmd = "cat $SRCS > $OUT", ) + +genrule( + name = "_target2", + srcs = ["_target2#child"], + outs = ["out2.txt"], + cmd = "cat $SRCS > $OUT", +) + +genrule( + name = "_target2#child", + srcs = ["bar.txt"], + outs = ["out2_child.txt"], + cmd = "cat $SRCS > $OUT", +) diff --git a/test/whatinputs/test_package/bar.txt b/test/whatinputs/test_package/bar.txt new file mode 100644 index 0000000000..e69de29bb2