Skip to content

bug(gapic-node-processing): setOnlyDefaultSystemTests incorrectly matches substring on absolute path #9342

Description

@zhumin8

Description

In gapic-node-processing/src/combine-libraries.ts, setOnlyDefaultSystemTests() filters out sample test fixtures from non-default versions when combining multi-version libraries (e.g., google-iam with v2 and v3).

It currently uses .includes(defaultVersion) on the full absolute file path:

function setOnlyDefaultSystemTests(defaultVersion: string, filePaths: FilePaths[]) {
  const systemTestRegex = new RegExp('system-test/fixtures/sample/src');
  for (let i = filePaths.length - 1; i >= 0; i--) {
    const filePathObj = filePaths[i];
    const normalizedPath = filePathObj.filePath.replace(/\\/g, '/');
    if (systemTestRegex.test(normalizedPath) &&
        !normalizedPath.includes(defaultVersion)) {
      filePaths.splice(i, 1);
    }
  }
}

Bug Behavior

If the workspace or temporary directory path where Librarian/generator runs happens to contain the substring defaultVersion (for example, /tmp/upgrade-nodejs-v2Mp8W containing "v2"), normalizedPath.includes("v2") evaluates to true for all API versions (including v3).

As a result:

  1. !normalizedPath.includes(defaultVersion) evaluates to false.
  2. v3 fixture files are not filtered out.
  3. v3 sample fixtures overwrite v2 sample fixtures, generating unintended client diffs (e.g., packages/google-iam/system-test/fixtures/sample/src/index.ts exporting AccessPoliciesClient instead of PoliciesClient).

Reference PR & CI Breakage

This issue was observed during Librarian version upgrade in:

Suggested Fix

Match the version directory boundary specifically rather than performing an unconstrained substring check across the absolute path:

const versionDirRegex = new RegExp(`(^|/)${defaultVersion}(/|$)`);
if (systemTestRegex.test(normalizedPath) && !versionDirRegex.test(normalizedPath)) {
  filePaths.splice(i, 1);
}

Activity

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions