Skip to content

VSTestBridge BuildFilter misclassifies a FullyQualifiedName that is a valid GUID as an Id= filter #9784

Closed

Description

Describe the bug

ContextAdapterBase.BuildFilter (in src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ContextAdapterBase.cs) uses a heuristic to decide whether a TestNodeUid should be turned into an Id=<guid> clause or a FullyQualifiedName=<name> clause:

if (Guid.TryParse(testNodesUid[i].Value, out Guid guid))
{
    filter.Append("Id=");
    filter.Append(guid.ToString());
    continue;
}

The UID value comes from ObjectModelConverters.ToTestNode, which sets it to either testCase.FullyQualifiedName or testCase.Id.ToString() depending on useFullyQualifiedNameAsUid. When useFullyQualifiedNameAsUid is true, the UID is a FullyQualifiedName. If that FQN happens to be a string that Guid.TryParse accepts (e.g. a data-driven/parameterized test whose display name is exactly a GUID-shaped string), BuildFilter will incorrectly emit Id=<guid> instead of FullyQualifiedName=<value>, so the reconstructed TestCaseFilter selects by the wrong property and the intended test may not be selected/run.

This is a pre-existing latent issue, noticed during review of #9771 (which fixed a separate IndexOutOfRangeException in the same method). It is intentionally out of scope for that PR.

Version used

main (as of the #9771 review).

Steps To Reproduce

  1. Have a VSTest-bridged adapter reporting nodes with useFullyQualifiedNameAsUid = true.
  2. Produce a test whose FullyQualifiedName parses as a Guid (any of the formats Guid.TryParse accepts, e.g. 12345678-1234-1234-1234-1234567890ab).
  3. Select that test by UID over the server protocol (e.g. run the single test from an IDE Test Explorer).
  4. BuildFilter emits Id=<guid> instead of FullyQualifiedName=<name>.

Expected behavior

The clause type should reflect how the UID was produced (FullyQualifiedName vs Id), not a Guid.TryParse heuristic on the value — so a FQN that is coincidentally GUID-shaped is still emitted as FullyQualifiedName=....

Actual behavior

A GUID-shaped FullyQualifiedName is emitted as an Id=<guid> clause, potentially selecting the wrong test (or no test).

Additional context

Possible directions:

  • Carry the discriminator (FQN vs Id) explicitly through the TestNodeUid / filter pipeline instead of re-deriving it with Guid.TryParse in BuildFilter.
  • Or key the decision off the same useFullyQualifiedNameAsUid signal used when the UID was created.

Related: #9771.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions