summaryrefslogtreecommitdiff
path: root/packages/cli/src/config/settings.test.ts
diff options
context:
space:
mode:
authorJacob MacDonald <[email protected]>2025-08-07 07:34:40 -0700
committerGitHub <[email protected]>2025-08-07 14:34:40 +0000
commit6ae75c9f32a968efa50857a8f24b958a58a84fd6 (patch)
tree6daccaf6fba4ac462a19ed75e198c02840f6a1a3 /packages/cli/src/config/settings.test.ts
parent36750ca49b1b2fa43a3d7904416b876203a1850f (diff)
Add a context percentage threshold setting for auto compression (#5721)
Diffstat (limited to 'packages/cli/src/config/settings.test.ts')
-rw-r--r--packages/cli/src/config/settings.test.ts118
1 files changed, 118 insertions, 0 deletions
diff --git a/packages/cli/src/config/settings.test.ts b/packages/cli/src/config/settings.test.ts
index d0266720..f68b13e3 100644
--- a/packages/cli/src/config/settings.test.ts
+++ b/packages/cli/src/config/settings.test.ts
@@ -113,6 +113,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
expect(settings.errors.length).toBe(0);
});
@@ -147,6 +148,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
@@ -181,6 +183,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
@@ -213,6 +216,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
@@ -251,6 +255,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
@@ -301,6 +306,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
@@ -622,6 +628,116 @@ describe('Settings Loading and Merging', () => {
expect(settings.merged.mcpServers).toEqual({});
});
+ it('should merge chatCompression settings, with workspace taking precedence', () => {
+ (mockFsExistsSync as Mock).mockReturnValue(true);
+ const userSettingsContent = {
+ chatCompression: { contextPercentageThreshold: 0.5 },
+ };
+ const workspaceSettingsContent = {
+ chatCompression: { contextPercentageThreshold: 0.8 },
+ };
+
+ (fs.readFileSync as Mock).mockImplementation(
+ (p: fs.PathOrFileDescriptor) => {
+ if (p === USER_SETTINGS_PATH)
+ return JSON.stringify(userSettingsContent);
+ if (p === MOCK_WORKSPACE_SETTINGS_PATH)
+ return JSON.stringify(workspaceSettingsContent);
+ return '{}';
+ },
+ );
+
+ const settings = loadSettings(MOCK_WORKSPACE_DIR);
+
+ expect(settings.user.settings.chatCompression).toEqual({
+ contextPercentageThreshold: 0.5,
+ });
+ expect(settings.workspace.settings.chatCompression).toEqual({
+ contextPercentageThreshold: 0.8,
+ });
+ expect(settings.merged.chatCompression).toEqual({
+ contextPercentageThreshold: 0.8,
+ });
+ });
+
+ it('should handle chatCompression when only in user settings', () => {
+ (mockFsExistsSync as Mock).mockImplementation(
+ (p: fs.PathLike) => p === USER_SETTINGS_PATH,
+ );
+ const userSettingsContent = {
+ chatCompression: { contextPercentageThreshold: 0.5 },
+ };
+ (fs.readFileSync as Mock).mockImplementation(
+ (p: fs.PathOrFileDescriptor) => {
+ if (p === USER_SETTINGS_PATH)
+ return JSON.stringify(userSettingsContent);
+ return '{}';
+ },
+ );
+
+ const settings = loadSettings(MOCK_WORKSPACE_DIR);
+ expect(settings.merged.chatCompression).toEqual({
+ contextPercentageThreshold: 0.5,
+ });
+ });
+
+ it('should have chatCompression as an empty object if not in any settings file', () => {
+ (mockFsExistsSync as Mock).mockReturnValue(false); // No settings files exist
+ (fs.readFileSync as Mock).mockReturnValue('{}');
+ const settings = loadSettings(MOCK_WORKSPACE_DIR);
+ expect(settings.merged.chatCompression).toEqual({});
+ });
+
+ it('should ignore chatCompression if contextPercentageThreshold is invalid', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ (mockFsExistsSync as Mock).mockImplementation(
+ (p: fs.PathLike) => p === USER_SETTINGS_PATH,
+ );
+ const userSettingsContent = {
+ chatCompression: { contextPercentageThreshold: 1.5 },
+ };
+ (fs.readFileSync as Mock).mockImplementation(
+ (p: fs.PathOrFileDescriptor) => {
+ if (p === USER_SETTINGS_PATH)
+ return JSON.stringify(userSettingsContent);
+ return '{}';
+ },
+ );
+
+ const settings = loadSettings(MOCK_WORKSPACE_DIR);
+ expect(settings.merged.chatCompression).toBeUndefined();
+ expect(warnSpy).toHaveBeenCalledWith(
+ 'Invalid value for chatCompression.contextPercentageThreshold: "1.5". Please use a value between 0 and 1. Using default compression settings.',
+ );
+ warnSpy.mockRestore();
+ });
+
+ it('should deep merge chatCompression settings', () => {
+ (mockFsExistsSync as Mock).mockReturnValue(true);
+ const userSettingsContent = {
+ chatCompression: { contextPercentageThreshold: 0.5 },
+ };
+ const workspaceSettingsContent = {
+ chatCompression: {},
+ };
+
+ (fs.readFileSync as Mock).mockImplementation(
+ (p: fs.PathOrFileDescriptor) => {
+ if (p === USER_SETTINGS_PATH)
+ return JSON.stringify(userSettingsContent);
+ if (p === MOCK_WORKSPACE_SETTINGS_PATH)
+ return JSON.stringify(workspaceSettingsContent);
+ return '{}';
+ },
+ );
+
+ const settings = loadSettings(MOCK_WORKSPACE_DIR);
+
+ expect(settings.merged.chatCompression).toEqual({
+ contextPercentageThreshold: 0.5,
+ });
+ });
+
it('should merge includeDirectories from all scopes', () => {
(mockFsExistsSync as Mock).mockReturnValue(true);
const systemSettingsContent = {
@@ -695,6 +811,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
// Check that error objects are populated in settings.errors
@@ -1132,6 +1249,7 @@ describe('Settings Loading and Merging', () => {
customThemes: {},
mcpServers: {},
includeDirectories: [],
+ chatCompression: {},
});
});
});