Skip to content

Fix shortened label list when querying files#828

Open
KoltesDigital wants to merge 1 commit into
bazelbuild:mainfrom
KoltesDigital:fix
Open

Fix shortened label list when querying files#828
KoltesDigital wants to merge 1 commit into
bazelbuild:mainfrom
KoltesDigital:fix

Conversation

@KoltesDigital

Copy link
Copy Markdown

While making the other PR I stumbled across this bug by chance.

@KoltesDigital KoltesDigital requested a review from achew22 as a code owner June 2, 2026 13:26
Comment thread internal/ibazel/ibazel.go
if realPath, ok := localRepositories[repo]; ok {
label = strings.Replace(target, ":", string(filepath.Separator), 1)
toWatch = append(toWatch, filepath.Join(realPath, label))
break

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good change. Can you help me understand what exactly is being fixed here by adding an e2e test that demonstrates the underlying issue

@KoltesDigital KoltesDigital force-pushed the fix branch 2 times, most recently from c5f3e17 to 6d28232 Compare June 4, 2026 16:26
@KoltesDigital

KoltesDigital commented Jun 4, 2026

Copy link
Copy Markdown
Author

@achew22 I've added a unit test to directly test the offending labelsToWatch function. Since the break exits the loop for an external label, I've interleaved internal and external labels.
Edit: Windows doesn't follow symlinks.

}
}

func TestIBazelConvertLabelsToPaths(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but it doesn't really confirm the true behavior of the failure. It confirms that it works the way the mock set it up. Is three any way to add an e2e test case to this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. The wrong behavior is on the map-filter of a list. The mock acts as the filter condition. But the issue is that the map-filter implementation is broken. Bring back the break and you'll see the test fail.

Regarding e2e I believe it'd be impossible to test because this behavior is not accurately exposed. I stumbled on the bug by chance, I noticed updating a particular file in a particular workspace triggered no rebuild, and I found the bug: it happened only because bazel query listed the file after other external files. But AFAIK the order of bazel query is not specified and might even change between invocations. From the CLI, there's no way to display query results and watched files, so no way to reliably detect that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sine that is the case then the periodic execution of the e2e test would demonstrate that it is flaky and result in a test failure, wouldn't it?

@KoltesDigital

Copy link
Copy Markdown
Author

@achew22 I've added a e2e test. I couldn't use sh_library like in local_repository or nested_module because Bazel 6.5.0 lists local files before external files... But then, I'm afraid the test only runs against 7.6.2, while current version is 9.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants