chore(modelarmor): Added floor settings tests and marked them as skip#4108
Conversation
There was a problem hiding this comment.
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
getandupdateoperations 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/updatefor Project, Folder, Organization) to standardize their structure, including renaming the main function tomainand 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
-
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. ↩
There was a problem hiding this comment.
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) { |
| async function getFolderFloorSettings() { | ||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| } |
| * floor settings. | ||
| */ | ||
| async function getOrganizationFloorSettings(organizationId) { | ||
| async function main(organizationId) { |
| async function getOrganizationFloorSettings() { | ||
| // 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) { |
| * @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated. | ||
| */ | ||
| async function updateOrganizationFloorSettings(organizationId) { | ||
| async function main(organizationId) { |
| 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; |
There was a problem hiding this comment.
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) { |
| 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; |
There was a problem hiding this comment.
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;| 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); | ||
| }); |
There was a problem hiding this comment.
glasnt
left a comment
There was a problem hiding this comment.
I believe this is the correct reversion of 832d423#diff-306d4a3158543b332531c6421c4220da9104226a1c9bdbf906b8a1ae09410038
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
npm test(see Testing)npm run lint(see Style)GoogleCloudPlatform/nodejs-docs-samples. Not a fork.