Package the portable DSH profiles, local plugins, desktop integration, Firefox wrapper, and ownership-aware installer lifecycle. Bundle checksum-pinned OpenVSCode, editor extensions, translation assets, and cloudflared so unreliable upstream artifact downloads cannot break a clean installation.
80 lines
3.5 KiB
JavaScript
80 lines
3.5 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFile } from 'node:fs/promises'
|
|
import test from 'node:test'
|
|
import vm from 'node:vm'
|
|
|
|
const source = await readFile(new URL('../editor-preferences/extension.js', import.meta.url), 'utf8')
|
|
|
|
function preferencesHarness({ initialized = false, defaultsVersion = initialized ? 2 : 0, settings = {} } = {}) {
|
|
const updates = []
|
|
const commands = []
|
|
const stored = new Map([['defaultsVersion', defaultsVersion]])
|
|
const configuration = {
|
|
inspect: key => ({ globalValue: settings[key] }),
|
|
update: async (key, value, target) => { updates.push({ key, value, target }); settings[key] = value },
|
|
}
|
|
const vscode = {
|
|
ConfigurationTarget: { Global: 1 },
|
|
workspace: { getConfiguration: () => configuration },
|
|
commands: { executeCommand: async command => { commands.push(command) } },
|
|
}
|
|
const sandbox = { exports: {}, require: name => { assert.equal(name, 'vscode'); return vscode } }
|
|
vm.runInNewContext(source, sandbox)
|
|
const context = {
|
|
globalState: {
|
|
get: key => stored.get(key),
|
|
update: async (key, value) => { stored.set(key, value) },
|
|
},
|
|
}
|
|
return { activate: () => sandbox.exports.activate(context), updates, commands, settings, stored }
|
|
}
|
|
|
|
test('first activation applies requested trust, theme, and sidebar preferences globally', async () => {
|
|
const harness = preferencesHarness({ settings: { 'editor.fontSize': 16 } })
|
|
await harness.activate()
|
|
assert.deepEqual(harness.settings, {
|
|
'editor.fontSize': 16,
|
|
'security.workspace.trust.enabled': false,
|
|
'workbench.colorTheme': 'Default Dark Modern',
|
|
'workbench.secondarySideBar.defaultVisibility': 'hidden',
|
|
'editor.fontFamily': "'JetBrains Mono', monospace",
|
|
})
|
|
assert.equal(harness.updates.every(update => update.target === 1), true)
|
|
assert.deepEqual(harness.commands, ['workbench.action.closeAuxiliaryBar'])
|
|
assert.equal(harness.stored.get('defaultsVersion'), 2)
|
|
})
|
|
|
|
test('later activation preserves customized preferences while closing the sidebar', async () => {
|
|
const harness = preferencesHarness({ initialized: true, settings: {
|
|
'security.workspace.trust.enabled': true,
|
|
'workbench.colorTheme': 'Other Theme',
|
|
'workbench.secondarySideBar.defaultVisibility': 'visible',
|
|
'editor.fontFamily': 'Other Font',
|
|
} })
|
|
await harness.activate()
|
|
assert.deepEqual(harness.updates, [])
|
|
assert.deepEqual(harness.commands, ['workbench.action.closeAuxiliaryBar'])
|
|
})
|
|
|
|
test('upgrading existing preferences changes only the newly requested font', async () => {
|
|
const harness = preferencesHarness({ defaultsVersion: 1, settings: {
|
|
'security.workspace.trust.enabled': true,
|
|
'workbench.colorTheme': 'Other Theme',
|
|
'workbench.secondarySideBar.defaultVisibility': 'visible',
|
|
'editor.fontFamily': 'Old Font',
|
|
} })
|
|
await harness.activate()
|
|
assert.deepEqual(harness.updates, [{ key: 'editor.fontFamily', value: "'JetBrains Mono', monospace", target: 1 }])
|
|
assert.equal(harness.settings['workbench.colorTheme'], 'Other Theme')
|
|
assert.equal(harness.stored.get('defaultsVersion'), 2)
|
|
await harness.activate()
|
|
assert.equal(harness.updates.length, 1)
|
|
})
|
|
|
|
test('a new browser origin receives missing defaults even when global state already exists', async () => {
|
|
const harness = preferencesHarness({ initialized: true })
|
|
await harness.activate()
|
|
assert.equal(harness.updates.length, 4)
|
|
assert.equal(harness.settings['security.workspace.trust.enabled'], false)
|
|
assert.equal(harness.settings['workbench.colorTheme'], 'Default Dark Modern')
|
|
})
|