forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-cross-model.ts
More file actions
140 lines (123 loc) · 4.18 KB
/
Copy pathtest-cross-model.ts
File metadata and controls
140 lines (123 loc) · 4.18 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env npx tsx
import {
sanitizeCrossModelPayload,
getModelFamily,
} from '../src/plugin/transform/cross-model-sanitizer';
const GEMINI_THOUGHT_SIGNATURE = 'EsgQCsUQAXLI2nybuafAE150LGTo2r78fakesig123abc456def789';
const geminiHistoryWithThinkingAndToolCall = {
contents: [
{
role: 'user',
parts: [{ text: 'Check disk space. Think about which filesystems are most utilized.' }]
},
{
role: 'model',
parts: [
{
thought: true,
text: 'Let me analyze the disk usage by running df -h to see filesystem utilization...',
thoughtSignature: GEMINI_THOUGHT_SIGNATURE
},
{
functionCall: {
name: 'Bash',
args: { command: 'df -h', description: 'Check disk space' }
},
metadata: {
google: {
thoughtSignature: GEMINI_THOUGHT_SIGNATURE
}
}
}
]
},
{
role: 'function',
parts: [{
functionResponse: {
name: 'Bash',
response: {
output: 'Filesystem Size Used Avail Use% Mounted on\n/dev/sda1 100G 62G 38G 62% /'
}
}
}]
},
{
role: 'model',
parts: [{ text: 'The root filesystem is 62% utilized, which is moderate usage.' }]
}
]
};
function runTests(): void {
console.log('=== Cross-Model Sanitization E2E Test ===\n');
let passed = 0;
let failed = 0;
console.log('Test 1: Model family detection');
const geminiFamily = getModelFamily('gemini-3-pro-low');
const claudeFamily = getModelFamily('claude-opus-4-6-thinking-medium');
if (geminiFamily === 'gemini' && claudeFamily === 'claude') {
console.log(' ✅ PASS: Model families detected correctly');
passed++;
} else {
console.log(` ❌ FAIL: Expected gemini/claude, got ${geminiFamily}/${claudeFamily}`);
failed++;
}
console.log('\nTest 2: Gemini → Claude sanitization (exact bug reproduction)');
console.log(' Input: Gemini session with thinking + tool call containing thoughtSignature');
const result = sanitizeCrossModelPayload(geminiHistoryWithThinkingAndToolCall, {
targetModel: 'claude-opus-4-6-thinking-medium'
});
const payload = result.payload as any;
const modelParts = payload.contents[1].parts;
const thinkingPart = modelParts[0];
const toolPart = modelParts[1];
if (thinkingPart.thoughtSignature === undefined) {
console.log(' ✅ PASS: Top-level thoughtSignature stripped from thinking part');
passed++;
} else {
console.log(' ❌ FAIL: thoughtSignature still present on thinking part');
failed++;
}
if (toolPart.metadata?.google?.thoughtSignature === undefined) {
console.log(' ✅ PASS: Nested metadata.google.thoughtSignature stripped from tool part');
passed++;
} else {
console.log(' ❌ FAIL: metadata.google.thoughtSignature still present');
failed++;
}
if (toolPart.functionCall?.name === 'Bash') {
console.log(' ✅ PASS: functionCall structure preserved');
passed++;
} else {
console.log(' ❌ FAIL: functionCall corrupted');
failed++;
}
if (result.modified && result.signaturesStripped === 2) {
console.log(` ✅ PASS: Sanitization metrics correct (modified=true, stripped=${result.signaturesStripped})`);
passed++;
} else {
console.log(` ❌ FAIL: Metrics incorrect (modified=${result.modified}, stripped=${result.signaturesStripped})`);
failed++;
}
console.log('\nTest 3: Same model family - no sanitization');
const sameFamily = sanitizeCrossModelPayload(geminiHistoryWithThinkingAndToolCall, {
targetModel: 'gemini-3-flash'
});
if (!sameFamily.modified && sameFamily.signaturesStripped === 0) {
console.log(' ✅ PASS: No sanitization for same model family');
passed++;
} else {
console.log(' ❌ FAIL: Should not sanitize same model family');
failed++;
}
console.log('\n=== Results ===');
console.log(`Passed: ${passed}/${passed + failed}`);
console.log(`Failed: ${failed}/${passed + failed}`);
if (failed > 0) {
console.log('\n❌ Some tests failed');
process.exit(1);
} else {
console.log('\n✅ All E2E tests passed');
}
}
runTests();