forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckAiMlUsage.test.js
More file actions
92 lines (74 loc) · 2.85 KB
/
checkAiMlUsage.test.js
File metadata and controls
92 lines (74 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const { exec } = require('../src/proxy/processors/push-action/checkForAiMlUsage.js');
const sinon = require('sinon');
const { Action } = require('../src/proxy/actions/Action.js');
const { Step } = require('../src/proxy/actions/Step.js');
describe('Detect AI/ML usage from git diff', () => {
let logStub;
beforeEach(() => {
// Stub console.log and config.getCommitConfig for isolation in each test case
logStub = sinon.stub(console, 'log');
});
afterEach(() => {
// Restore stubs to avoid cross-test interference
logStub.restore();
// configStub.restore();
});
const createDiffContent = (filePaths) => {
// Creates diff-like content for each file path to simulate actual git diff output
return filePaths.map((filePath) => `diff --git a/${filePath} b/${filePath}`).join('\n');
};
it('Block push if AI/ML file extensions detected', async () => {
// Create action and step instances with test data that should trigger blocking
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
const filePaths = [
'test/test_data/ai_test_data/model.h5',
'test/test_data/ai_test_data/dataset.csv',
];
step.setContent(createDiffContent(filePaths));
action.addStep(step);
await exec(null, action);
// Check that console.log was called with the blocking message
sinon.assert.calledWith(
logStub,
sinon.match(
/Your push has been blocked due to AI\/ML usage detection/,
),
);
});
it('Block push if AI/ML file content detected', async () => {
// Create action and step instances with test data that should trigger blocking
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
const filePaths = [
'test/test_data/ai_test_data/ai_script.py',
'test/test_data/ai_test_data/ai_config.json',
];
step.setContent(createDiffContent(filePaths));
action.addStep(step);
await exec(null, action);
// Check that console.log was called with the blocking message
sinon.assert.calledWith(
logStub,
sinon.match(
/Your push has been blocked due to AI\/ML usage detection/,
),
);
});
it('Allow push if no AI/ML usage is detected', async () => {
// Configure with no sensitive EXIF parameters
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
const filePaths = ['test/test_data/ai_test_data/non_ai_script.py'];
step.setContent(createDiffContent(filePaths));
action.addStep(step);
await exec(null, action);
// Ensure no blocking message was logged
sinon.assert.neverCalledWith(
logStub,
sinon.match(
/Your push has been blocked due to AI\/ML usage detection/,
),
);
});
});