Skip to content

chore(modelarmor): Added floor settings tests and marked them as skip#4108

Merged
glasnt merged 7 commits intoGoogleCloudPlatform:mainfrom
mihirvala08:model-armor-floorsettings-tests
Jun 16, 2025
Merged

chore(modelarmor): Added floor settings tests and marked them as skip#4108
glasnt merged 7 commits intoGoogleCloudPlatform:mainfrom
mihirvala08:model-armor-floorsettings-tests

Conversation

@mihirvala08
Copy link
Copy Markdown
Contributor

Description

Added Floor settings tests and marked tests as skip/ignore due to on going issue for Floor settings API in model armor.
Ref buganizer ticket for issue status: b/424365799

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@mihirvala08 mihirvala08 requested review from a team as code owners June 13, 2025 12:46
@product-auto-label product-auto-label Bot added api: modelarmor Issues related to the Model Armor API. samples Issues that are directly related to samples. labels Jun 13, 2025
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @mihirvala-crestdata, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces tests for the Model Armor Floor Settings API across different resource levels (Project, Folder, Organization). The tests are currently disabled due to an upstream API issue. Additionally, the associated snippet files have been refactored for consistency and direct execution capability.

Highlights

  • New Tests Added: Added new test cases for the Model Armor Floor Settings API, covering get and update operations for Project, Folder, and Organization levels.
  • Tests Skipped: The newly added Floor Settings tests are temporarily marked as skipped (it.skip) due to an ongoing issue with the Model Armor Floor Settings API (referenced by buganizer ticket b/424365799).
  • Snippet Refactoring: Refactored the Floor Settings snippet files (get/update for Project, Folder, Organization) to standardize their structure, including renaming the main function to main and adding a block for direct command-line execution.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 adds new, currently skipped, tests for Model Armor floor settings and refactors the existing snippet files to a standard executable main function pattern. The changes are generally good, with clear documentation for the skipped tests. The primary suggestion is to simplify the snippet files by removing an unnecessary layer of inner asynchronous functions, which will improve conciseness.

* @param {string} folderId - The ID of the Google Cloud folder for which to retrieve floor settings.
*/
async function getFolderFloorSettings(folderId) {
async function main(folderId) {
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

Consider renaming the main function to getFolderFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(folderId) {
async function getFolderFloorSettings(folderId) {

Comment on lines +37 to +45
async function getFolderFloorSettings() {
// Construct request
const request = {
name,
};

const [response] = await modelarmorClient.getFloorSetting(request);
return response;
const [response] = await modelarmorClient.getFloorSetting(request);
return response;
}
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

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

// Construct request
  const request = {
    name,
  };

  const [response] = await modelarmorClient.getFloorSetting(request);
  return response;

* floor settings.
*/
async function getOrganizationFloorSettings(organizationId) {
async function main(organizationId) {
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

Consider renaming the main function to getOrganizationFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(organizationId) {
async function getOrganizationFloorSettings(organizationId) {

Comment on lines +37 to +45
async function getOrganizationFloorSettings() {
// Construct request
const request = {
name,
};

// Run request
const [response] = await modelarmorClient.getFloorSetting(request);
return response;
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

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

// Construct request
  const request = {
    name,
  };

  // Run request
  const [response] = await modelarmorClient.getFloorSetting(request);
  return response;

* floor settings.
*/
async function getProjectFloorSettings(projectId) {
async function main(projectId) {
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

Consider renaming the main function to getProjectFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(projectId) {
async function getProjectFloorSettings(projectId) {

* @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated.
*/
async function updateOrganizationFloorSettings(organizationId) {
async function main(organizationId) {
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

Consider renaming the main function to updateOrganizationFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(organizationId) {
async function updateOrganizationFloorSettings(organizationId) {

Comment on lines +35 to +71
async function updateOrganizationFloorSettings() {
const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;

// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
const floorSetting = {
name: floorSettingsName,
filterConfig: {
raiSettings: {
raiFilters: [
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
.LOW_AND_ABOVE,
},
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
},
],
// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
const floorSetting = {
name: floorSettingsName,
filterConfig: {
raiSettings: {
raiFilters: [
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
.LOW_AND_ABOVE,
},
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType
.SEXUALLY_EXPLICIT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
},
],
},
},
},
enableFloorSettingEnforcement: true,
};
enableFloorSettingEnforcement: true,
};

const request = {
floorSetting: floorSetting,
};
const request = {
floorSetting: floorSetting,
};

const [response] = await client.updateFloorSetting(request);
return response;
const [response] = await client.updateFloorSetting(request);
return response;
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

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;

  // Build the floor settings with your preferred filters
  // For more details on filters, please refer to the following doc:
  // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
  const floorSetting = {
    name: floorSettingsName,
    filterConfig: {
      raiSettings: {
        raiFilters: [
          {
            filterType:
              protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
            confidenceLevel:
              protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                .LOW_AND_ABOVE,
          },
          {
            filterType:
              protos.google.cloud.modelarmor.v1.RaiFilterType
                .SEXUALLY_EXPLICIT,
            confidenceLevel:
              protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
          },
        ],
      },
    },
    enableFloorSettingEnforcement: true,
  };

  const request = {
    floorSetting: floorSetting,
  };

  const [response] = await client.updateFloorSetting(request);
  return response;

* @param {string} projectId - Google Cloud project ID for which floor settings need to be updated.
*/
async function updateProjectFloorSettings(projectId) {
async function main(projectId) {
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

Consider renaming the main function to updateProjectFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(projectId) {
async function updateProjectFloorSettings(projectId) {

Comment on lines +36 to +72
async function updateProjectFloorSettings() {
const floorSettingsName = `projects/${projectId}/locations/global/floorSetting`;

// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
const floorSetting = {
name: floorSettingsName,
filterConfig: {
raiSettings: {
raiFilters: [
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
.LOW_AND_ABOVE,
},
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
},
],
// Build the floor settings with your preferred filters
// For more details on filters, please refer to the following doc:
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
const floorSetting = {
name: floorSettingsName,
filterConfig: {
raiSettings: {
raiFilters: [
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
.LOW_AND_ABOVE,
},
{
filterType:
protos.google.cloud.modelarmor.v1.RaiFilterType
.SEXUALLY_EXPLICIT,
confidenceLevel:
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
},
],
},
},
},
enableFloorSettingEnforcement: true,
};
enableFloorSettingEnforcement: true,
};

const request = {
floorSetting: floorSetting,
};
const request = {
floorSetting: floorSetting,
};

const [response] = await client.updateFloorSetting(request);
return response;
const [response] = await client.updateFloorSetting(request);
return response;
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

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

const floorSettingsName = `projects/${projectId}/locations/global/floorSetting`;

  // Build the floor settings with your preferred filters
  // For more details on filters, please refer to the following doc:
  // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
  const floorSetting = {
    name: floorSettingsName,
    filterConfig: {
      raiSettings: {
        raiFilters: [
          {
            filterType:
              protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
            confidenceLevel:
              protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                .LOW_AND_ABOVE,
          },
          {
            filterType:
              protos.google.cloud.modelarmor.v1.RaiFilterType
                .SEXUALLY_EXPLICIT,
            confidenceLevel:
              protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
          },
        ],
      },
    },
    enableFloorSettingEnforcement: true,
  };

  const request = {
    floorSetting: floorSetting,
  };

  const [response] = await client.updateFloorSetting(request);
  return response;

Comment on lines +945 to +992
it.skip('should get organization floor settings', async () => {
const getOrganizationFloorSettings = require('../snippets/getOrganizationFloorSettings');

const output = await getOrganizationFloorSettings.main(organizationId);

const expectedName = `organizations/${organizationId}/locations/global/floorSetting`;
assert.equal(output.name, expectedName);
});

it.skip('should get folder floor settings', async () => {
const getFolderFloorSettings = require('../snippets/getFolderFloorSettings');

const output = await getFolderFloorSettings.main(folderId);

// Check for expected name format in output
const expectedName = `folders/${folderId}/locations/global/floorSetting`;
assert.equal(output.name, expectedName);
});

it.skip('should get project floor settings', async () => {
const getProjectFloorSettings = require('../snippets/getProjectFloorSettings');

const output = await getProjectFloorSettings.main(projectId);
// Check for expected name format in output
const expectedName = `projects/${projectId}/locations/global/floorSetting`;
assert.equal(output.name, expectedName);
});

it.skip('should update organization floor settings', async () => {
const updateOrganizationFloorSettings = require('../snippets/updateOrganizationFloorSettings');
const output = await updateOrganizationFloorSettings.main(organizationId);
// Check that the enableFloorSettingEnforcement=true
assert.equal(output.enableFloorSettingEnforcement, true);
});

it.skip('should update folder floor settings', async () => {
const updateFolderFloorSettings = require('../snippets/updateFolderFloorSettings');
const output = await updateFolderFloorSettings.main(folderId);
// Check that the enableFloorSettingEnforcement=true
assert.equal(output.enableFloorSettingEnforcement, true);
});

it.skip('should update project floor settings', async () => {
const updateProjectFloorSettings = require('../snippets/updateProjectFloorSettings');
const output = await updateProjectFloorSettings.main(projectId);
// Check that the enableFloorSettingEnforcement=true
assert.equal(output.enableFloorSettingEnforcement, true);
});
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

These tests are skipped due to an ongoing issue. Consider adding a comment explaining why these tests are skipped and referencing the related bug ticket.

// Tests skipped due to buganizer ticket b/424365799
it.skip('should get organization floor settings', async () => {

Copy link
Copy Markdown
Contributor

@glasnt glasnt left a comment

Choose a reason for hiding this comment

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

@glasnt glasnt merged commit 6e6208a into GoogleCloudPlatform:main Jun 16, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: modelarmor Issues related to the Model Armor API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants