Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/test/common/agentClientUri.test.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { URI } from '../../../../base/common/uri.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
9
import { AGENT_CLIENT_SCHEME, fromAgentClientUri, toAgentClientUri } from '../../common/agentClientUri.js';
10
11
suite('Agent Client URI transform', () => {
12
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
test('round-trips a file URI', () => {
16
const original = URI.file('/Users/user/plugins/my-plugin/index.js');
17
const wrapped = toAgentClientUri(original, 'client-1');
18
19
assert.strictEqual(wrapped.scheme, AGENT_CLIENT_SCHEME);
20
assert.strictEqual(wrapped.authority, 'client-1');
21
assert.ok(wrapped.path.startsWith('/file/'));
22
23
const decoded = fromAgentClientUri(wrapped);
24
assert.strictEqual(decoded.scheme, 'file');
25
assert.strictEqual(decoded.path, original.path);
26
});
27
28
test('round-trips a URI with authority', () => {
29
const original = URI.from({ scheme: 'https', authority: 'example.com', path: '/plugins/foo' });
30
const wrapped = toAgentClientUri(original, 'c2');
31
32
const decoded = fromAgentClientUri(wrapped);
33
assert.strictEqual(decoded.scheme, 'https');
34
assert.strictEqual(decoded.authority, 'example.com');
35
assert.strictEqual(decoded.path, '/plugins/foo');
36
});
37
38
test('encodes missing authority as dash', () => {
39
const original = URI.from({ scheme: 'inmemory', path: '/test/file.txt' });
40
const wrapped = toAgentClientUri(original, 'c3');
41
42
assert.ok(wrapped.path.includes('/-/'));
43
44
const decoded = fromAgentClientUri(wrapped);
45
assert.strictEqual(decoded.scheme, 'inmemory');
46
assert.strictEqual(decoded.authority, '');
47
assert.strictEqual(decoded.path, '/test/file.txt');
48
});
49
50
test('preserves client ID as authority', () => {
51
const wrapped = toAgentClientUri(URI.file('/foo'), 'my-client');
52
assert.strictEqual(wrapped.authority, 'my-client');
53
});
54
});
55
56