test(ui-agent-preset): cover the surface where it is introduced

The package landed here with one store spec; the rest of its tests were written
three layers up, so this layer and the two above it failed the per-file
coverage gate on 191 locations while every test passed.

Adds the node half's invariant companion, the two components, the registration
apply, and the stores' failure paths. `currentValue` drops a `?? ''` that an
empty roster already returned before reaching — the same shape the later layer
arrived at, so the two converge instead of conflicting.
This commit is contained in:
Yichen Jiang
2026-08-07 14:58:03 +08:00
parent 5ee6b13ecb
commit c96b480bc4
5 changed files with 653 additions and 2 deletions

View File

@@ -73,7 +73,8 @@ export class AgentPresetSettingsController {
return
}
const presets = response.result.value.presets
if (presets.length === 0) {
const [first] = presets
if (first === undefined) {
this.set({ status: 'unavailable', options: [], currentValue: '' })
return
}
@@ -87,7 +88,9 @@ export class AgentPresetSettingsController {
error: null,
writable: described.result.ok && described.result.value.writable,
options: presets.map(preset => ({ id: preset.id, trust: preset.trust })),
currentValue: presets.find(preset => preset.isDefault)?.id ?? presets[0]?.id ?? '',
// A roster can mark nothing default: settings can name a preset that
// was since deleted, and the picker still has to show something.
currentValue: presets.find(preset => preset.isDefault)?.id ?? first.id,
})
} catch (error) {
this.set({ status: 'error', error: error instanceof Error ? error.message : String(error) })