Adds API filter registry, style theme registry, SW bitmask cache clear, KV namespacing, session expiry checks, accessibility improvements, and expanded test coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
import { beforeEach, describe, test } from 'node:test';
|
|
import assert from 'node:assert';
|
|
import { KeyValueStore, KV_KEY_PREFIX } from '../src/platform/storage.js';
|
|
|
|
describe('KeyValueStore namespacing', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
});
|
|
|
|
test('isolates values by provider name', async () => {
|
|
const configStore = new KeyValueStore('config', 'localStorage');
|
|
const securityStore = new KeyValueStore('security.basic', 'localStorage');
|
|
|
|
await configStore.set('theme.mode', 'dark');
|
|
await securityStore.set('security.basic.session', { user_id: 'u1' });
|
|
|
|
assert.strictEqual(await configStore.get('theme.mode'), 'dark');
|
|
assert.deepStrictEqual(await securityStore.get('security.basic.session'), { user_id: 'u1' });
|
|
assert.strictEqual(await configStore.get('security.basic.session', null), null);
|
|
|
|
assert.strictEqual(
|
|
localStorage.getItem(`${KV_KEY_PREFIX}config:theme.mode`),
|
|
JSON.stringify('dark')
|
|
);
|
|
assert.strictEqual(
|
|
localStorage.getItem(`${KV_KEY_PREFIX}security.basic:security.basic.session`),
|
|
JSON.stringify({ user_id: 'u1' })
|
|
);
|
|
});
|
|
|
|
test('clear removes only keys owned by the provider', async () => {
|
|
const configStore = new KeyValueStore('config', 'localStorage');
|
|
const securityStore = new KeyValueStore('security.basic', 'localStorage');
|
|
|
|
await configStore.set('theme.mode', 'dark');
|
|
await securityStore.set('security.basic.session', { user_id: 'u1' });
|
|
|
|
await configStore.clear();
|
|
|
|
assert.strictEqual(await configStore.get('theme.mode', null), null);
|
|
assert.deepStrictEqual(await securityStore.get('security.basic.session'), { user_id: 'u1' });
|
|
});
|
|
|
|
test('config provider reads legacy flat keys as fallback', async () => {
|
|
localStorage.setItem('theme.mode', JSON.stringify('light'));
|
|
|
|
const configStore = new KeyValueStore('config', 'localStorage');
|
|
assert.strictEqual(await configStore.get('theme.mode'), 'light');
|
|
});
|
|
});
|