forked from QwenLM/qwen-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelEncoding.test.ts
More file actions
147 lines (123 loc) · 4.75 KB
/
Copy pathmodelEncoding.test.ts
File metadata and controls
147 lines (123 loc) · 4.75 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
141
142
143
144
145
146
147
import { describe, expect, it } from 'vitest';
import {
encodeVisionModelForSetting,
extractBareModelId,
decodeVisionModelForPicker,
} from './modelEncoding';
describe('encodeVisionModelForSetting', () => {
it('encodes standard ACP format', () => {
expect(encodeVisionModelForSetting('qwen-max(qwen-oauth)')).toBe(
'qwen-oauth:qwen-max',
);
});
it('passes through non-ACP format unchanged', () => {
expect(encodeVisionModelForSetting('plain-model')).toBe('plain-model');
});
it('passes through empty parens unchanged', () => {
expect(encodeVisionModelForSetting('model()')).toBe('model()');
});
it('passes through colon-bearing IDs unchanged', () => {
expect(encodeVisionModelForSetting('openai:gpt-4o')).toBe('openai:gpt-4o');
});
it('handles nested parentheses by matching outermost ACP pattern', () => {
// The regex matches the outermost group: modelId(authType)
expect(encodeVisionModelForSetting('model(name)(extra)')).toBe(
'extra:model(name)',
);
});
it('passes through already-encoded colon format unchanged', () => {
// If someone somehow passes an already-encoded authType:modelId,
// it should be left alone — not double-encoded.
expect(encodeVisionModelForSetting('qwen-oauth:qwen-vl-max')).toBe(
'qwen-oauth:qwen-vl-max',
);
});
it('passes through malformed — bare authType only', () => {
// '(authType)' has no modelId before the parens and no text
// before the opening paren that can serve as group 1, so the
// regex won't match and we get the input back unchanged.
expect(encodeVisionModelForSetting('(authType)')).toBe('(authType)');
});
it('passes through malformed — unclosed paren', () => {
expect(encodeVisionModelForSetting('modelId(')).toBe('modelId(');
});
it('passes through malformed — double-parens inside', () => {
expect(encodeVisionModelForSetting('a((b))')).toBe('a((b))');
});
it('passes through empty string unchanged', () => {
expect(encodeVisionModelForSetting('')).toBe('');
});
});
describe('extractBareModelId', () => {
it('extracts bare model ID from ACP format', () => {
expect(extractBareModelId('qwen-max(qwen-oauth)')).toBe('qwen-max');
});
it('passes through non-ACP format unchanged', () => {
expect(extractBareModelId('plain-model')).toBe('plain-model');
});
it('passes through empty parens unchanged', () => {
// The regex requires at least one char in each capture group,
// so '()' does not match and passes through.
expect(extractBareModelId('()')).toBe('()');
});
});
describe('decodeVisionModelForPicker', () => {
it('decodes authType:modelId back to ACP format', () => {
expect(decodeVisionModelForPicker('qwen-oauth:qwen-max')).toBe(
'qwen-max(qwen-oauth)',
);
});
it('handles colon-bearing model IDs — splits on first colon only', () => {
expect(decodeVisionModelForPicker('openai:gpt-4o:online')).toBe(
'gpt-4o:online(openai)',
);
});
it('passes through values without a colon', () => {
expect(decodeVisionModelForPicker('plain-model')).toBe('plain-model');
});
it('passes through ACP-formatted values unchanged', () => {
expect(decodeVisionModelForPicker('qwen-max(qwen-oauth)')).toBe(
'qwen-max(qwen-oauth)',
);
});
it('passes through empty string unchanged', () => {
expect(decodeVisionModelForPicker('')).toBe('');
});
it('passes through leading-colon malformed input', () => {
// colonIdx === 0, which is not > 0, so passthrough
expect(decodeVisionModelForPicker(':modelId')).toBe(':modelId');
});
it('strips \\0baseUrl suffix before decoding', () => {
expect(
decodeVisionModelForPicker(
'qwen-oauth:qwen-vl-max\0https://api.example.com',
),
).toBe('qwen-vl-max(qwen-oauth)');
});
it('handles colon-bearing ID with \\0baseUrl suffix', () => {
expect(
decodeVisionModelForPicker(
'openai:gpt-4o:online\0https://api.openai.com',
),
).toBe('gpt-4o:online(openai)');
});
it('passes through bare ID with \\0baseUrl suffix but no colon', () => {
expect(
decodeVisionModelForPicker('plain-model\0https://api.example.com'),
).toBe('plain-model');
});
});
describe('round-trip: encode then decode', () => {
it('preserves the original ACP format', () => {
const original = 'qwen-vl-max(qwen-oauth)';
const encoded = encodeVisionModelForSetting(original);
const decoded = decodeVisionModelForPicker(encoded);
expect(decoded).toBe(original);
});
it('preserves colon-bearing IDs after round-trip', () => {
const original = 'gpt-4o:new-model(openai)';
const encoded = encodeVisionModelForSetting(original);
const decoded = decodeVisionModelForPicker(encoded);
expect(decoded).toBe(original);
});
});