How to create dynamic reference and label?

This is an unfortunate instance of the wrong precedence being used here. The fix:

#[=== #name] #label(labelName)

Although I have to say, I’m a bit unsure why (without the show rule) the error you get is “label <test2> occurs multiple times in the document” – that is misleading.