27 lines
1.5 KiB
JavaScript
27 lines
1.5 KiB
JavaScript
|
|
import test from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import {safePreferences, apiLogEntry, editorConflict} from '../src/utils/configSafety.js';
|
||
|
|
|
||
|
|
test('cached preferences never include model, headers, token or error bodies', () => {
|
||
|
|
const marker = 'SENTINEL_PRIVATE_CREDENTIAL';
|
||
|
|
const input = {revision:'revision', modelAdapters:[{apiKey:marker,customHeadersJSON:JSON.stringify({Authorization:marker}),openAIExtraParamsJSON:marker}],tabServerToken:marker,serviceLastError:marker,homeMetrics:{refreshIntervalSeconds:30,persistentMode:false,secret:marker}};
|
||
|
|
const safe = safePreferences(input);
|
||
|
|
assert.equal(JSON.stringify(safe).includes(marker),false);
|
||
|
|
assert.deepEqual(safe,{homeMetrics:{includeCacheWriteInHitRate:false,persistentMode:false,refreshIntervalSeconds:30}});
|
||
|
|
assert.deepEqual(safePreferences(safe),safe);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('API log records are metadata only for both success and error', () => {
|
||
|
|
assert.deepEqual(apiLogEntry('SaveUserConfig'),{operation:'SaveUserConfig',status:'completed'});
|
||
|
|
assert.deepEqual(apiLogEntry('SaveUserConfig',true),{operation:'SaveUserConfig',status:'failed'});
|
||
|
|
});
|
||
|
|
|
||
|
|
test('editor rejects stale revision, deleted target and changed identity', () => {
|
||
|
|
const current={revision:'new',modelAdapters:[{id:'a'},{id:'b'}]};
|
||
|
|
assert.equal(editorConflict(current,'old',0,'a'),true);
|
||
|
|
assert.equal(editorConflict(current,'new',2,'b'),true);
|
||
|
|
assert.equal(editorConflict(current,'new',0,'b'),true);
|
||
|
|
assert.equal(editorConflict(current,'new',1,'b'),false);
|
||
|
|
assert.equal(editorConflict(current,'new',-1,''),false);
|
||
|
|
});
|