From 147ae838448613d427579304c99741534ebce336 Mon Sep 17 00:00:00 2001 From: Mihir Vala Date: Thu, 3 Jul 2025 14:41:03 +0530 Subject: [PATCH 1/7] chore(tests): enabled floor settings tests --- model-armor/test/modelarmor.test.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index 1a176dab4f..d1c1ead614 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -940,9 +940,7 @@ describe('Model Armor tests', () => { // =================== Floor Settings Tests =================== - // TODO(b/424365799): Enable below tests once the mentioned issue is resolved - - it.skip('should get organization floor settings', async () => { + it('should get organization floor settings', async () => { const getOrganizationFloorSettings = require('../snippets/getOrganizationFloorSettings'); const output = await getOrganizationFloorSettings.main(organizationId); @@ -951,7 +949,7 @@ describe('Model Armor tests', () => { assert.equal(output.name, expectedName); }); - 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); @@ -961,7 +959,7 @@ describe('Model Armor tests', () => { assert.equal(output.name, expectedName); }); - 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); @@ -970,21 +968,21 @@ describe('Model Armor tests', () => { assert.equal(output.name, expectedName); }); - it.skip('should update organization floor settings', async () => { + 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); }); - it.skip('should update folder floor settings', async () => { + 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 update project 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 From 604d26861d4c534f741107bc8d1a59107f616e2b Mon Sep 17 00:00:00 2001 From: Mihir Vala Date: Tue, 8 Jul 2025 13:07:12 +0530 Subject: [PATCH 2/7] chore(tests): added floor setting enable flag exists on get tests --- model-armor/test/modelarmor.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index d1c1ead614..060acac231 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -947,6 +947,7 @@ describe('Model Armor tests', () => { const expectedName = `organizations/${organizationId}/locations/global/floorSetting`; assert.equal(output.name, expectedName); + assert.exists(output.enableFloorSettingEnforcement); }); it('should get folder floor settings', async () => { @@ -957,6 +958,7 @@ describe('Model Armor tests', () => { // Check for expected name format in output const expectedName = `folders/${folderId}/locations/global/floorSetting`; assert.equal(output.name, expectedName); + assert.exists(output.enableFloorSettingEnforcement); }); it('should get project floor settings', async () => { @@ -966,6 +968,7 @@ describe('Model Armor tests', () => { // Check for expected name format in output const expectedName = `projects/${projectId}/locations/global/floorSetting`; assert.equal(output.name, expectedName); + assert.exists(output.enableFloorSettingEnforcement); }); it('should update organization floor settings', async () => { From c3dacf198169546215a782dc6b0bfeea2e22c20e Mon Sep 17 00:00:00 2001 From: Mihir Vala Date: Tue, 8 Jul 2025 19:28:24 +0530 Subject: [PATCH 3/7] chore(tests): enabled floor settings clean-up --- model-armor/test/modelarmor.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index 060acac231..5f9dcab8c0 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -371,9 +371,8 @@ 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 disableFloorSettings(); await deleteTemplate(templateName); } From 90d8b328174db99bf1d8e4c9f51d195ca09e9344 Mon Sep 17 00:00:00 2001 From: Harsh Nasit <131268456+harshnasitcrest@users.noreply.github.com> Date: Tue, 5 Aug 2025 20:09:06 +0530 Subject: [PATCH 4/7] removed empty template related tests As Katie mentioned earlier in C# repo that service level tests already exists, so anyways these tests won't help. Hence, removing them --- model-armor/test/modelarmor.test.js | 63 ----------------------------- 1 file changed, 63 deletions(-) diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index 5f9dcab8c0..ae88f43be8 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -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; @@ -275,10 +274,6 @@ 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, {}); - // Create basic template with PI/Jailbreak and Malicious URI filters for sanitizeUserPrompt tests basicTemplateId = `${templateIdPrefix}-basic`; await createTemplate(basicTemplateId, { @@ -360,7 +355,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}`, @@ -727,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 () => { @@ -825,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 1l6Y2@example.com 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 = @@ -873,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 test@dot.com make available to public for feedback'; - const testModelResponse = - 'You can make support email such as contact@email.com 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 = From f2bdb733655092ba8d01aa44c078814883153027 Mon Sep 17 00:00:00 2001 From: Harsh Nasit Date: Mon, 11 Aug 2025 15:06:11 +0530 Subject: [PATCH 5/7] chore: update dependencies and improve floor settings tests --- model-armor/package.json | 10 ++-- .../snippets/updateFolderFloorSettings.js | 3 +- .../updateOrganizationFloorSettings.js | 3 +- .../snippets/updateProjectFloorSettings.js | 3 +- model-armor/test/modelarmor.test.js | 58 +++++++++++-------- 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/model-armor/package.json b/model-armor/package.json index 56649a6c2e..88b2a98f81 100644 --- a/model-armor/package.json +++ b/model-armor/package.json @@ -14,13 +14,13 @@ "test": "c8 mocha -p -j 2 --recursive test/ --timeout=60000" }, "dependencies": { - "@google-cloud/modelarmor": "^0.1.0", - "@google-cloud/dlp": "^5.0.0" + "@google-cloud/modelarmor": "^0.4.0", + "@google-cloud/dlp": "^6.3.0" }, "devDependencies": { "c8": "^10.0.0", - "chai": "^4.5.0", - "mocha": "^10.0.0", - "uuid": "^10.0.0" + "chai": "^5.2.1", + "mocha": "^11.7.1", + "uuid": "^11.1.0" } } diff --git a/model-armor/snippets/updateFolderFloorSettings.js b/model-armor/snippets/updateFolderFloorSettings.js index d34415b67d..79f77b0eba 100644 --- a/model-armor/snippets/updateFolderFloorSettings.js +++ b/model-armor/snippets/updateFolderFloorSettings.js @@ -57,7 +57,8 @@ async function main(folderId) { protos.google.cloud.modelarmor.v1.RaiFilterType .SEXUALLY_EXPLICIT, confidenceLevel: - protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH, + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, }, ], }, diff --git a/model-armor/snippets/updateOrganizationFloorSettings.js b/model-armor/snippets/updateOrganizationFloorSettings.js index d78ef47d0c..ef2c4eb461 100644 --- a/model-armor/snippets/updateOrganizationFloorSettings.js +++ b/model-armor/snippets/updateOrganizationFloorSettings.js @@ -55,7 +55,8 @@ async function main(organizationId) { protos.google.cloud.modelarmor.v1.RaiFilterType .SEXUALLY_EXPLICIT, confidenceLevel: - protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH, + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, }, ], }, diff --git a/model-armor/snippets/updateProjectFloorSettings.js b/model-armor/snippets/updateProjectFloorSettings.js index 73307187bb..8bbca77558 100644 --- a/model-armor/snippets/updateProjectFloorSettings.js +++ b/model-armor/snippets/updateProjectFloorSettings.js @@ -56,7 +56,8 @@ async function main(projectId) { protos.google.cloud.modelarmor.v1.RaiFilterType .SEXUALLY_EXPLICIT, confidenceLevel: - protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH, + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, }, ], }, diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index ae88f43be8..8a2edbc59c 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -260,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; @@ -274,6 +275,8 @@ describe('Model Armor tests', () => { .SdpBasicConfigEnforcement; const RaiFilterType = protos.google.cloud.modelarmor.v1.RaiFilterType; + await disableFloorSettings(); + // Create basic template with PI/Jailbreak and Malicious URI filters for sanitizeUserPrompt tests basicTemplateId = `${templateIdPrefix}-basic`; await createTemplate(basicTemplateId, { @@ -365,9 +368,6 @@ describe('Model Armor tests', () => { after(async () => { for (const templateName of templatesToDelete) { - // Disable floor settings to restore original state - await disableFloorSettings(); - await deleteTemplate(templateName); } @@ -873,8 +873,37 @@ describe('Model Armor tests', () => { 'NO_MATCH_FOUND' ); }); +}); + +describe('Model Armor floor setting tests', () => { + before(async () => { + projectId = await client.getProjectId(); + }); + + after(async () => { + await disableFloorSettings(); + }); + + 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); + }); - // =================== Floor Settings Tests =================== + 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('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'); @@ -906,25 +935,4 @@ describe('Model Armor tests', () => { assert.equal(output.name, expectedName); assert.exists(output.enableFloorSettingEnforcement); }); - - 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); - }); - - 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('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); - }); }); From 3a770cf018835b3c54bff4ea6b4b2dbff89667ca Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 12 Aug 2025 16:27:36 +1000 Subject: [PATCH 6/7] ci: move custard config to same level as package.json --- model-armor/{snippets => }/ci-setup.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename model-armor/{snippets => }/ci-setup.json (100%) diff --git a/model-armor/snippets/ci-setup.json b/model-armor/ci-setup.json similarity index 100% rename from model-armor/snippets/ci-setup.json rename to model-armor/ci-setup.json From ddcc5de1a716163fffe9b00930106839e9a43279 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 12 Aug 2025 16:46:03 +1000 Subject: [PATCH 7/7] ci: may not support ints here, use strings --- model-armor/ci-setup.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model-armor/ci-setup.json b/model-armor/ci-setup.json index 3fb11b81f8..9985d6afe9 100644 --- a/model-armor/ci-setup.json +++ b/model-armor/ci-setup.json @@ -1,6 +1,6 @@ { "env": { - "MA_FOLDER_ID": 695279264361, - "MA_ORG_ID": 951890214235 + "MA_FOLDER_ID": "695279264361", + "MA_ORG_ID": "951890214235" } }