Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/channels/base/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getGlobalQwenDir } from './paths.js';
export { getGlobalQwenDir, resolvePath } from './paths.js';
export { AcpBridge } from './AcpBridge.js';
export type {
AcpBridgeOptions,
Expand Down
25 changes: 24 additions & 1 deletion packages/channels/base/src/paths.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, afterEach } from 'vitest';
import * as path from 'node:path';
import * as os from 'node:os';
import { getGlobalQwenDir } from './paths.js';
import { getGlobalQwenDir, resolvePath } from './paths.js';

describe('channels/base paths – getGlobalQwenDir', () => {
const originalEnv = process.env['QWEN_HOME'];
Expand Down Expand Up @@ -45,3 +45,26 @@ describe('channels/base paths – getGlobalQwenDir', () => {
expect(getGlobalQwenDir()).toBe(os.homedir());
});
});

describe('channels/base paths – resolvePath', () => {
it('returns absolute paths unchanged', () => {
const abs = path.resolve('/tmp/x');
expect(resolvePath(abs)).toBe(abs);
});

it('expands bare tilde (~) to home directory', () => {
expect(resolvePath('~')).toBe(os.homedir());
});

it('expands POSIX-style tilde (~/x)', () => {
expect(resolvePath('~/xomo')).toBe(path.join(os.homedir(), 'xomo'));
});

it('expands Windows-style tilde (~\\x)', () => {
expect(resolvePath('~\\xomo')).toBe(path.join(os.homedir(), 'xomo'));
});

it('resolves relative paths against process.cwd', () => {
expect(resolvePath('relative/dir')).toBe(path.resolve('relative/dir'));
});
});
2 changes: 1 addition & 1 deletion packages/channels/base/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as os from 'node:os';
* Expands tilde and resolves relative paths to absolute.
* Mirrors Storage.resolvePath() in packages/core.
*/
function resolvePath(dir: string): string {
export function resolvePath(dir: string): string {
let resolved = dir;
if (
resolved === '~' ||
Expand Down
35 changes: 35 additions & 0 deletions packages/cli/src/commands/channel/config-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect, vi, afterEach } from 'vitest';
import * as path from 'node:path';
import * as os from 'node:os';
import { resolveEnvVars, parseChannelConfig } from './config-utils.js';

// Mock the channel-registry so we don't pull in real plugins
Expand Down Expand Up @@ -137,4 +139,37 @@ describe('parseChannelConfig', () => {
});
expect((result as Record<string, unknown>)['customField']).toBe(42);
});

it('expands tilde in cwd (~/x → $HOME/x)', async () => {
const result = await parseChannelConfig('bot', {
type: 'bare',
cwd: '~/xomo',
});
expect(result.cwd).toBe(path.join(os.homedir(), 'xomo'));
});

it('expands bare tilde (~) in cwd to home directory', async () => {
const result = await parseChannelConfig('bot', {
type: 'bare',
cwd: '~',
});
expect(result.cwd).toBe(os.homedir());
});

it('resolves relative cwd against process.cwd', async () => {
const result = await parseChannelConfig('bot', {
type: 'bare',
cwd: 'relative/dir',
});
expect(result.cwd).toBe(path.resolve('relative/dir'));
});

it('leaves absolute cwd unchanged', async () => {
const abs = path.resolve('/custom');
const result = await parseChannelConfig('bot', {
type: 'bare',
cwd: abs,
});
expect(result.cwd).toBe(abs);
});
});
3 changes: 2 additions & 1 deletion packages/cli/src/commands/channel/config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ChannelConfig } from '@qwen-code/channel-base';
import { resolvePath } from '@qwen-code/channel-base';
import * as path from 'node:path';
import { getPlugin, supportedTypes } from './channel-registry.js';

Expand Down Expand Up @@ -73,7 +74,7 @@ export async function parseChannelConfig(
allowedUsers: (rawConfig['allowedUsers'] as string[]) || [],
sessionScope:
(rawConfig['sessionScope'] as ChannelConfig['sessionScope']) || 'user',
cwd: (rawConfig['cwd'] as string) || process.cwd(),
cwd: resolvePath((rawConfig['cwd'] as string) || process.cwd()),
approvalMode: rawConfig['approvalMode'] as string | undefined,
instructions: rawConfig['instructions'] as string | undefined,
model: rawConfig['model'] as string | undefined,
Expand Down
Loading