feat(tui): persist model tier selection and fix formatting
Persist /model tier choice to ~/.local/share/flynn/preferences.json so it survives restarts. Decode HTML entities (e.g. ') in markdown renderer output. Suppress noisy logger.info and punycode deprecation warnings in TUI startup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { tmpdir } from 'os';
|
||||
import { loadPreferences, savePreference } from './preferences.js';
|
||||
|
||||
describe('preferences', () => {
|
||||
let dataDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dataDir = mkdtempSync(resolve(tmpdir(), 'flynn-prefs-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(dataDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('returns empty object when file is missing', () => {
|
||||
expect(loadPreferences(dataDir)).toEqual({});
|
||||
});
|
||||
|
||||
it('returns empty object when file is corrupt', () => {
|
||||
writeFileSync(resolve(dataDir, 'preferences.json'), 'not json!!!');
|
||||
expect(loadPreferences(dataDir)).toEqual({});
|
||||
});
|
||||
|
||||
it('round-trips a saved preference', () => {
|
||||
savePreference(dataDir, 'modelTier', 'local');
|
||||
const prefs = loadPreferences(dataDir);
|
||||
expect(prefs.modelTier).toBe('local');
|
||||
});
|
||||
|
||||
it('merges preferences without overwriting other keys', () => {
|
||||
savePreference(dataDir, 'modelTier', 'fast');
|
||||
savePreference(dataDir, 'otherKey', 42);
|
||||
const raw = JSON.parse(readFileSync(resolve(dataDir, 'preferences.json'), 'utf-8'));
|
||||
expect(raw.modelTier).toBe('fast');
|
||||
expect(raw.otherKey).toBe(42);
|
||||
});
|
||||
|
||||
it('creates parent directories if needed', () => {
|
||||
const nested = resolve(dataDir, 'sub', 'dir');
|
||||
savePreference(nested, 'modelTier', 'default');
|
||||
expect(loadPreferences(nested).modelTier).toBe('default');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user