mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-09 08:00:45 +08:00
Fix bizMonitor tool results failing DSH lossless JSON (strip undefined holes).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
b235957c34
commit
4dd628b7cc
13 changed files with 414 additions and 136 deletions
40
test/json-safe.test.mjs
Normal file
40
test/json-safe.test.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Lossless JSON helpers for DSH tool results.
|
||||
*/
|
||||
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { omitUndefined, toLosslessJson } from '../src/netx/json-safe.ts'
|
||||
|
||||
test('omitUndefined drops undefined keys but keeps null/false/0', () => {
|
||||
assert.deepEqual(
|
||||
omitUndefined({ a: 1, b: undefined, c: null, d: false, e: 0 }),
|
||||
{ a: 1, c: null, d: false, e: 0 },
|
||||
)
|
||||
})
|
||||
|
||||
test('toLosslessJson strips undefined holes (listBizMonitors-style payload)', () => {
|
||||
const raw = {
|
||||
ok: true,
|
||||
data: {
|
||||
kind: 'projects',
|
||||
projects: [{ id: 'p1', name: 'demo' }],
|
||||
tasks: undefined,
|
||||
next: 'go',
|
||||
},
|
||||
}
|
||||
const safe = toLosslessJson(raw)
|
||||
assert.equal(safe.ok, true)
|
||||
const data = safe.data
|
||||
assert.ok(data && typeof data === 'object' && !Array.isArray(data))
|
||||
assert.equal(Object.hasOwn(data, 'tasks'), false)
|
||||
assert.deepEqual(data.projects, [{ id: 'p1', name: 'demo' }])
|
||||
})
|
||||
|
||||
test('toLosslessJson keeps failure envelopes serializable', () => {
|
||||
const safe = toLosslessJson({ ok: false, error: 'x', detail: undefined })
|
||||
assert.equal(safe.ok, false)
|
||||
assert.equal(safe.error, 'x')
|
||||
assert.equal(Object.hasOwn(safe, 'detail'), false)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue