-
Notifications
You must be signed in to change notification settings - Fork 2k
chore(modelarmor): enabled floor settings tests #4123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
glasnt
merged 10 commits into
GoogleCloudPlatform:main
from
mihirvala-crestdata:model-armor-enable-floor-settings-tests
Aug 12, 2025
+54
−106
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
147ae83
chore(tests): enabled floor settings tests
mihirvala-crestdata 604d268
chore(tests): added floor setting enable flag exists on get tests
mihirvala-crestdata c3dacf1
chore(tests): enabled floor settings clean-up
mihirvala-crestdata 97d9dd5
Merge branch 'GoogleCloudPlatform:main' into model-armor-enable-floor…
harshnasitcrest 7c0c0f7
Merge branch 'main' into model-armor-enable-floor-settings-tests
glasnt a37a29f
Merge branch 'main' into model-armor-enable-floor-settings-tests
harshnasitcrest 90d8b32
removed empty template related tests
harshnasitcrest f2bdb73
chore: update dependencies and improve floor settings tests
harshnasitcrest 3a770cf
ci: move custard config to same level as package.json
glasnt ddcc5de
ci: may not support ints here, use strings
glasnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"env": { | ||
"MA_FOLDER_ID": "695279264361", | ||
"MA_ORG_ID": "951890214235" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ const options = { | |
const client = new ModelArmorClient(options); | ||
const templateIdPrefix = `test-template-${uuidv4().substring(0, 8)}`; | ||
|
||
let emptyTemplateId; | ||
let basicTemplateId; | ||
let basicSdpTemplateId; | ||
let advanceSdpTemplateId; | ||
|
@@ -261,6 +260,7 @@ describe('Model Armor tests', () => { | |
before(async () => { | ||
projectId = await client.getProjectId(); | ||
const {protos} = require('@google-cloud/modelarmor'); | ||
|
||
// Import necessary enums | ||
const DetectionConfidenceLevel = | ||
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel; | ||
|
@@ -275,9 +275,7 @@ describe('Model Armor tests', () => { | |
.SdpBasicConfigEnforcement; | ||
const RaiFilterType = protos.google.cloud.modelarmor.v1.RaiFilterType; | ||
|
||
// Create empty template for sanitizeUserPrompt tests | ||
emptyTemplateId = `${templateIdPrefix}-empty`; | ||
await createTemplate(emptyTemplateId, {}); | ||
await disableFloorSettings(); | ||
|
||
// Create basic template with PI/Jailbreak and Malicious URI filters for sanitizeUserPrompt tests | ||
basicTemplateId = `${templateIdPrefix}-basic`; | ||
|
@@ -360,7 +358,6 @@ describe('Model Armor tests', () => { | |
}); | ||
|
||
templatesToDelete.push( | ||
`projects/${projectId}/locations/${locationId}/templates/${emptyTemplateId}`, | ||
`projects/${projectId}/locations/${locationId}/templates/${basicTemplateId}`, | ||
`projects/${projectId}/locations/${locationId}/templates/${basicSdpTemplateId}`, | ||
`projects/${projectId}/locations/${locationId}/templates/${advanceSdpTemplateId}`, | ||
|
@@ -371,10 +368,6 @@ describe('Model Armor tests', () => { | |
|
||
after(async () => { | ||
for (const templateName of templatesToDelete) { | ||
// TODO(b/424365799): Uncomment below code once the mentioned issue is resolved | ||
// Disable floor settings to restore original state | ||
// await disableFloorSettings(); | ||
|
||
await deleteTemplate(templateName); | ||
} | ||
|
||
|
@@ -728,24 +721,6 @@ describe('Model Armor tests', () => { | |
); | ||
}); | ||
|
||
it('should not detect issues in user prompt with empty template', async () => { | ||
const sanitizeUserPrompt = require('../snippets/sanitizeUserPrompt'); | ||
const testUserPrompt = | ||
'Can you describe this link? https://testsafebrowsing.appspot.com/s/malware.html,'; | ||
|
||
const response = await sanitizeUserPrompt( | ||
projectId, | ||
locationId, | ||
emptyTemplateId, | ||
testUserPrompt | ||
); | ||
|
||
assert.equal( | ||
response.sanitizationResult.filterMatchState, | ||
'NO_MATCH_FOUND' | ||
); | ||
}); | ||
|
||
// =================== Model Response Sanitization Tests =================== | ||
|
||
it('should detect malicious URL in model response', async () => { | ||
|
@@ -826,24 +801,6 @@ describe('Model Armor tests', () => { | |
); | ||
}); | ||
|
||
it('should not detect issues in model response with empty template', async () => { | ||
const sanitizeModelResponse = require('../snippets/sanitizeModelResponse'); | ||
const testModelResponse = | ||
'For following email [email protected] found following associated phone number: 954-321-7890 and this ITIN: 988-86-1234'; | ||
|
||
const response = await sanitizeModelResponse( | ||
projectId, | ||
locationId, | ||
emptyTemplateId, | ||
testModelResponse | ||
); | ||
|
||
assert.equal( | ||
response.sanitizationResult.filterMatchState, | ||
'NO_MATCH_FOUND' | ||
); | ||
}); | ||
|
||
it('should detect PII in model response with basic SDP template', async () => { | ||
const sanitizeModelResponse = require('../snippets/sanitizeModelResponse'); | ||
const testModelResponse = | ||
|
@@ -874,27 +831,6 @@ describe('Model Armor tests', () => { | |
|
||
// =================== Model Response with User Prompt Tests =================== | ||
|
||
it('should not detect issues in model response with user prompt using empty template', async () => { | ||
const sanitizeModelResponseWithUserPrompt = require('../snippets/sanitizeModelResponseWithUserPrompt'); | ||
const testUserPrompt = | ||
'How can I make my email address [email protected] make available to public for feedback'; | ||
const testModelResponse = | ||
'You can make support email such as [email protected] for getting feedback from your customer'; | ||
|
||
const response = await sanitizeModelResponseWithUserPrompt( | ||
projectId, | ||
locationId, | ||
emptyTemplateId, | ||
testModelResponse, | ||
testUserPrompt | ||
); | ||
|
||
assert.equal( | ||
response.sanitizationResult.filterMatchState, | ||
'NO_MATCH_FOUND' | ||
); | ||
}); | ||
|
||
it('should sanitize model response with user prompt using advanced SDP template', async () => { | ||
const sanitizeModelResponseWithUserPrompt = require('../snippets/sanitizeModelResponseWithUserPrompt'); | ||
const testUserPrompt = | ||
|
@@ -937,57 +873,66 @@ describe('Model Armor tests', () => { | |
'NO_MATCH_FOUND' | ||
); | ||
}); | ||
}); | ||
|
||
describe('Model Armor floor setting tests', () => { | ||
before(async () => { | ||
projectId = await client.getProjectId(); | ||
}); | ||
|
||
after(async () => { | ||
await disableFloorSettings(); | ||
}); | ||
|
||
// =================== Floor Settings Tests =================== | ||
it('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); | ||
}); | ||
|
||
// TODO(b/424365799): Enable below tests once the mentioned issue is resolved | ||
it('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 get organization floor settings', async () => { | ||
it('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); | ||
}); | ||
|
||
it('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); | ||
assert.exists(output.enableFloorSettingEnforcement); | ||
}); | ||
|
||
it.skip('should get folder floor settings', async () => { | ||
it('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); | ||
assert.exists(output.enableFloorSettingEnforcement); | ||
}); | ||
|
||
it.skip('should get project floor settings', async () => { | ||
it('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); | ||
assert.exists(output.enableFloorSettingEnforcement); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.