Skip to content

pick the version out of the versioned library's directory - #9516

Open
rootkiller6788 wants to merge 2 commits into
googleapis:mainfrom
rootkiller6788:fix-default-version-system-tests
Open

rootkiller6788 wants to merge 2 commits into
googleapis:mainfrom
rootkiller6788:fix-default-version-system-tests

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #9342.

The version of a pre-combined library isn't a path segment of its own, it's part of the versioned library's directory name (speech-v1p1beta1-nodejs, analytics-data-v1beta-nodejs). setOnlyDefaultSystemTests was checking whether defaultVersion showed up anywhere in the absolute file path, which gets it wrong in two ways:

  • If the temp directory Librarian runs in happens to contain the version (/tmp/upgrade-nodejs-v2Mp8W), every version looks like the default one, so a non-default version's sample fixture can win the dedupe and get shipped. That's the one in the issue.
  • It doesn't even need a temp dir. With v1 as the default, the v1p1beta1 directory matches includes('v1').

So it now reads the version off the versioned library's directory - the one above system-test, stepping over the esm folder for ESM libraries - and compares it as a whole against defaultVersion.

One thing worth calling out: the fix suggested in the issue (matching the version as a path segment) doesn't work. I tried it, and it drops the default version's own fixtures too, because no path segment ever equals v1beta. It would also fail the existing 'should only have default system tests' test.

Tests: 3 of the 5 new cases fail on main and pass after the change, full suite is 53 passing. I also ran generateFinalDirectoryPath against the real google-analytics-data fixture copied into a temp dir with v1beta in its name - before this the surviving sample fixture was v1alpha, now it's v1beta.

setOnlyDefaultSystemTests decides which version's sample fixtures make it
into a combined library, so it is worth pinning down. Three of these fail on
the current implementation.
The version of a pre-combined library lives inside the directory name, like
speech-v1p1beta1-nodejs, so checking whether it appears anywhere in the file
path answered the wrong question. Anything above the library directory that
happened to mention the version - the temp dir Librarian runs in, or the v1
inside v1p1beta1 - made every version look like the default one.

So only look at that directory now.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors setOnlyDefaultSystemTests to extract and match the versioned library directory name directly, preventing false positives from paths that merely contain the version string, and adds comprehensive unit tests. Feedback on these changes suggests adding safety guards in getVersionedLibraryDir to prevent potential out-of-bounds array access when system-test is at the beginning of the path, and ensuring files are not incorrectly deleted if versionedDir cannot be resolved.

Comment on lines +301 to +308
function getVersionedLibraryDir(normalizedPath: string): string {
const parts = normalizedPath.split('/');
const systemTestIndex = parts.indexOf('system-test');
if (systemTestIndex < 0) return '';
let index = systemTestIndex - 1;
if (parts[index] === 'esm') index--;
return parts[index] ?? '';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To prevent potential out-of-bounds array access and handle cases where system-test is at the beginning of the path (index 0), we can add a guard for systemTestIndex <= 0 and ensure index is non-negative before accessing parts[index].

Suggested change
function getVersionedLibraryDir(normalizedPath: string): string {
const parts = normalizedPath.split('/');
const systemTestIndex = parts.indexOf('system-test');
if (systemTestIndex < 0) return '';
let index = systemTestIndex - 1;
if (parts[index] === 'esm') index--;
return parts[index] ?? '';
}
function getVersionedLibraryDir(normalizedPath: string): string {
const parts = normalizedPath.split('/');
const systemTestIndex = parts.indexOf('system-test');
if (systemTestIndex <= 0) return '';
let index = systemTestIndex - 1;
if (parts[index] === 'esm') index--;
return index >= 0 ? parts[index] : '';
}

Comment on lines +323 to 326
const versionedDir = getVersionedLibraryDir(normalizedPath);
if (!versionedDir.split('-').includes(defaultVersion)) {
filePaths.splice(i, 1);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If versionedDir is empty (e.g., because system-test is not a standalone segment or cannot be resolved), we should skip the file instead of deleting it. Currently, an empty versionedDir results in [''].includes(defaultVersion) which is false, causing the file to be incorrectly deleted.

    const versionedDir = getVersionedLibraryDir(normalizedPath);
    if (!versionedDir) continue;
    if (!versionedDir.split('-').includes(defaultVersion)) {
      filePaths.splice(i, 1);
    }

@rootkiller6788
rootkiller6788 marked this pull request as ready for review October 5, 2026 06:09
@rootkiller6788
rootkiller6788 requested a review from a team as a code owner October 5, 2026 06:09
@github-actions
github-actions Bot requested a review from feywind October 5, 2026 06:09

This branch has not been deployed

No deployments
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.

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

1 participant