mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 20:17:03 +00:00
refactor(dashboard): reuse compatible CLI settings editor stack
- add shared backend JSON file probe/write utilities for compatible CLI settings - add shared frontend raw JSON editor panel and wire Droid page to it - support PUT save flow with validation and mtime conflict handling
This commit is contained in:
1 parent
c6d2e71ec2
commit
e9eab712b3
7 files changed
+542
-148
No files matched your search
@@ -3,9 +3,12 @@ import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import {
|
||||
DroidRawSettingsConflictError,
|
||||
DroidRawSettingsValidationError,
|
||||
getDroidRawSettings,
|
||||
maskApiKeyPreview,
|
||||
resolveDroidConfigPaths,
|
||||
saveDroidRawSettings,
|
||||
summarizeDroidCustomModels,
|
||||
} from '../../../src/web-server/services/droid-dashboard-service';
|
||||
|
||||
@@ -106,4 +109,40 @@ describe('droid-dashboard-service', () => {
|
||||
expect(raw.settings).toBeNull();
|
||||
expect(raw.rawText).toContain('invalid-json');
|
||||
});
|
||||
|
||||
it('saves valid raw settings content', () => {
|
||||
const result = saveDroidRawSettings({
|
||||
rawText: JSON.stringify({
|
||||
model: 'custom:test-model',
|
||||
customModels: [],
|
||||
}),
|
||||
});
|
||||
|
||||
const settingsPath = path.join(testRoot, '.factory', 'settings.json');
|
||||
const written = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.mtime).toBeGreaterThan(0);
|
||||
expect(written.model).toBe('custom:test-model');
|
||||
});
|
||||
|
||||
it('rejects invalid JSON while saving raw settings', () => {
|
||||
expect(() => saveDroidRawSettings({ rawText: '{ invalid-json' })).toThrow(
|
||||
DroidRawSettingsValidationError
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects stale writes with conflict error', () => {
|
||||
const settingsDir = path.join(testRoot, '.factory');
|
||||
fs.mkdirSync(settingsDir, { recursive: true });
|
||||
const settingsPath = path.join(settingsDir, 'settings.json');
|
||||
fs.writeFileSync(settingsPath, JSON.stringify({ customModels: [] }));
|
||||
|
||||
expect(() =>
|
||||
saveDroidRawSettings({
|
||||
rawText: JSON.stringify({ model: 'custom:next', customModels: [] }),
|
||||
expectedMtime: 1,
|
||||
})
|
||||
).toThrow(DroidRawSettingsConflictError);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user