Path: blob/main/src/vs/platform/agentHost/test/common/agentClientUri.test.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { URI } from '../../../../base/common/uri.js';7import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';8import { AGENT_CLIENT_SCHEME, fromAgentClientUri, toAgentClientUri } from '../../common/agentClientUri.js';910suite('Agent Client URI transform', () => {1112ensureNoDisposablesAreLeakedInTestSuite();1314test('round-trips a file URI', () => {15const original = URI.file('/Users/user/plugins/my-plugin/index.js');16const wrapped = toAgentClientUri(original, 'client-1');1718assert.strictEqual(wrapped.scheme, AGENT_CLIENT_SCHEME);19assert.strictEqual(wrapped.authority, 'client-1');20assert.ok(wrapped.path.startsWith('/file/'));2122const decoded = fromAgentClientUri(wrapped);23assert.strictEqual(decoded.scheme, 'file');24assert.strictEqual(decoded.path, original.path);25});2627test('round-trips a URI with authority', () => {28const original = URI.from({ scheme: 'https', authority: 'example.com', path: '/plugins/foo' });29const wrapped = toAgentClientUri(original, 'c2');3031const decoded = fromAgentClientUri(wrapped);32assert.strictEqual(decoded.scheme, 'https');33assert.strictEqual(decoded.authority, 'example.com');34assert.strictEqual(decoded.path, '/plugins/foo');35});3637test('encodes missing authority as dash', () => {38const original = URI.from({ scheme: 'inmemory', path: '/test/file.txt' });39const wrapped = toAgentClientUri(original, 'c3');4041assert.ok(wrapped.path.includes('/-/'));4243const decoded = fromAgentClientUri(wrapped);44assert.strictEqual(decoded.scheme, 'inmemory');45assert.strictEqual(decoded.authority, '');46assert.strictEqual(decoded.path, '/test/file.txt');47});4849test('preserves client ID as authority', () => {50const wrapped = toAgentClientUri(URI.file('/foo'), 'my-client');51assert.strictEqual(wrapped.authority, 'my-client');52});53});545556