mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-09 05:10:45 +08:00
Fix kbRoot browse ignoring Typert Result from directoryPicker.pick.
Unwrap { ok, value } so the chosen folder path lands in the field and auto-saves.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f64f1279e7
commit
fcdd11ac59
4 changed files with 165 additions and 57 deletions
48
test/kb-pick-result.test.mjs
Normal file
48
test/kb-pick-result.test.mjs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Directory-picker Result unwrapping (mirrors controller helper).
|
||||
*/
|
||||
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
function unwrapDirectoryPickResult(result) {
|
||||
if (result === null) return null
|
||||
if (typeof result === 'string') {
|
||||
const trimmed = result.trim()
|
||||
return trimmed === '' ? null : trimmed
|
||||
}
|
||||
if (typeof result !== 'object' || Array.isArray(result)) return undefined
|
||||
const row = result
|
||||
if (row.ok === false) {
|
||||
throw new Error(row.error?.message || 'directoryPicker/pick failed')
|
||||
}
|
||||
if ('value' in row) {
|
||||
if (row.value === null) return null
|
||||
if (typeof row.value === 'string') {
|
||||
const trimmed = row.value.trim()
|
||||
return trimmed === '' ? null : trimmed
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
test('unwrap bare string path', () => {
|
||||
assert.equal(unwrapDirectoryPickResult('D:\\kb'), 'D:\\kb')
|
||||
})
|
||||
|
||||
test('unwrap typert Result value', () => {
|
||||
assert.equal(unwrapDirectoryPickResult({ ok: true, value: 'D:\\kb\\ioh' }), 'D:\\kb\\ioh')
|
||||
})
|
||||
|
||||
test('unwrap cancel null', () => {
|
||||
assert.equal(unwrapDirectoryPickResult(null), null)
|
||||
assert.equal(unwrapDirectoryPickResult({ ok: true, value: null }), null)
|
||||
})
|
||||
|
||||
test('reject Result error', () => {
|
||||
assert.throws(
|
||||
() => unwrapDirectoryPickResult({ ok: false, error: { message: 'no native' } }),
|
||||
/no native/,
|
||||
)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue