mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
feat: Show untrusted status in the Footer (#6210)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@ import {
|
||||
TrustLevel,
|
||||
isWorkspaceTrusted,
|
||||
} from './trustedFolders.js';
|
||||
import { Settings } from './settings.js';
|
||||
|
||||
vi.mock('fs', async (importOriginal) => {
|
||||
const actualFs = await importOriginal<typeof fs>();
|
||||
@@ -130,6 +131,10 @@ describe('Trusted Folders Loading', () => {
|
||||
describe('isWorkspaceTrusted', () => {
|
||||
let mockCwd: string;
|
||||
const mockRules: Record<string, TrustLevel> = {};
|
||||
const mockSettings: Settings = {
|
||||
folderTrustFeature: true,
|
||||
folderTrust: true,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(process, 'cwd').mockImplementation(() => mockCwd);
|
||||
@@ -153,51 +158,51 @@ describe('isWorkspaceTrusted', () => {
|
||||
it('should return true for a directly trusted folder', () => {
|
||||
mockCwd = '/home/user/projectA';
|
||||
mockRules['/home/user/projectA'] = TrustLevel.TRUST_FOLDER;
|
||||
expect(isWorkspaceTrusted()).toBe(true);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for a child of a trusted folder', () => {
|
||||
mockCwd = '/home/user/projectA/src';
|
||||
mockRules['/home/user/projectA'] = TrustLevel.TRUST_FOLDER;
|
||||
expect(isWorkspaceTrusted()).toBe(true);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for a child of a trusted parent folder', () => {
|
||||
mockCwd = '/home/user/projectB';
|
||||
mockRules['/home/user/projectB/somefile.txt'] = TrustLevel.TRUST_PARENT;
|
||||
expect(isWorkspaceTrusted()).toBe(true);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for a directly untrusted folder', () => {
|
||||
mockCwd = '/home/user/untrusted';
|
||||
mockRules['/home/user/untrusted'] = TrustLevel.DO_NOT_TRUST;
|
||||
expect(isWorkspaceTrusted()).toBe(false);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return undefined for a child of an untrusted folder', () => {
|
||||
mockCwd = '/home/user/untrusted/src';
|
||||
mockRules['/home/user/untrusted'] = TrustLevel.DO_NOT_TRUST;
|
||||
expect(isWorkspaceTrusted()).toBeUndefined();
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined when no rules match', () => {
|
||||
mockCwd = '/home/user/other';
|
||||
mockRules['/home/user/projectA'] = TrustLevel.TRUST_FOLDER;
|
||||
mockRules['/home/user/untrusted'] = TrustLevel.DO_NOT_TRUST;
|
||||
expect(isWorkspaceTrusted()).toBeUndefined();
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should prioritize trust over distrust', () => {
|
||||
mockCwd = '/home/user/projectA/untrusted';
|
||||
mockRules['/home/user/projectA'] = TrustLevel.TRUST_FOLDER;
|
||||
mockRules['/home/user/projectA/untrusted'] = TrustLevel.DO_NOT_TRUST;
|
||||
expect(isWorkspaceTrusted()).toBe(true);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle path normalization', () => {
|
||||
mockCwd = '/home/user/projectA';
|
||||
mockRules[`/home/user/../user/${path.basename('/home/user/projectA')}`] =
|
||||
TrustLevel.TRUST_FOLDER;
|
||||
expect(isWorkspaceTrusted()).toBe(true);
|
||||
expect(isWorkspaceTrusted(mockSettings)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user