Fix preset publication, volatile settings and client form binding

This commit is contained in:
oliver 2026-10-11 12:54:02 +08:00
parent fe0fe70d33
commit 0b9a3a82bc
66 changed files with 8546 additions and 3690 deletions

View file

@ -0,0 +1,61 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
getNetxConnection,
publishNetxConnection,
watchNetxConnection,
} from '../src/netx/runtime.ts'
import { DEFAULT_CAPABILITY_GROUPS } from '../src/netx/capability-groups.ts'
function clearConnection() {
publishNetxConnection({
apiUrl: '',
token: '',
lang: 'zh',
toolCallTimeoutMs: 1000,
groups: DEFAULT_CAPABILITY_GROUPS,
groupKbInPreset: false,
groupKbPublic: false,
})
// runtime has no reset — overwrite with a sentinel then ignore
}
test('watch-then-remount does not miss an in-flight publish', () => {
let mounts = 0
const remount = () => {
if (getNetxConnection()?.apiUrl) mounts += 1
}
// Bad order (pre-0.1.58): remount → publish → watch → miss
mounts = 0
remount()
publishNetxConnection({
apiUrl: 'http://127.0.0.1:8890',
token: 't',
lang: 'zh',
toolCallTimeoutMs: 1000,
groups: DEFAULT_CAPABILITY_GROUPS,
groupKbInPreset: true,
groupKbPublic: false,
})
const stopBad = watchNetxConnection(remount)
assert.equal(mounts, 0, 'bad order misses the publish')
stopBad()
// Good order: watch → publish → remount (and watch also fires)
mounts = 0
clearConnection()
const stopGood = watchNetxConnection(remount)
publishNetxConnection({
apiUrl: 'http://127.0.0.1:8890',
token: 't',
lang: 'zh',
toolCallTimeoutMs: 1000,
groups: DEFAULT_CAPABILITY_GROUPS,
groupKbInPreset: true,
groupKbPublic: false,
})
remount()
assert.ok(mounts >= 1, 'good order sees connection')
stopGood()
})