dsh-memu-memory 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -1
- package/CHANGELOG.md +11 -0
- package/README.md +33 -14
- package/README.zh.md +34 -12
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/libraries.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +19 -3
- package/docs/contributing.md +4 -2
- package/docs/env-and-commands.md +9 -1
- package/docs/graph-scale.md +214 -0
- package/docs/lexicon-recall.md +100 -0
- package/docs/mcp-porting.md +8 -6
- package/docs/memory-semantics.md +35 -3
- package/docs/pending-work.md +3 -1
- package/docs/retention.md +83 -0
- package/docs/rt-index.md +452 -0
- package/docs/scale-performance.md +101 -0
- package/docs/token-budget.md +92 -0
- package/docs/troubleshooting.md +50 -11
- package/lib/auto-link/apply.js +7 -2
- package/lib/auto-link/candidates.js +32 -10
- package/lib/backup.js +67 -32
- package/lib/binding-diagnostics.js +1 -1
- package/lib/bounded-cache.js +80 -0
- package/lib/client.js +2096 -409
- package/lib/consolidation-ledger.js +21 -4
- package/lib/consolidation-worker.js +14 -1
- package/lib/cycle.js +16 -11
- package/lib/diagnostic-context.js +372 -0
- package/lib/diagnostics.js +147 -61
- package/lib/embedding-download.js +7 -8
- package/lib/engine-sources.js +286 -0
- package/lib/engine.js +23 -10
- package/lib/entity-repair.js +43 -13
- package/lib/entity-review.js +64 -0
- package/lib/environment-check.js +348 -36
- package/lib/feedback.js +25 -0
- package/lib/global-graph.js +46 -2
- package/lib/graph-adjacency-index.js +525 -0
- package/lib/graph-overview.js +293 -0
- package/lib/graph.js +658 -105
- package/lib/inbound.js +44 -15
- package/lib/index-pages.js +57 -0
- package/lib/index.js +44 -6
- package/lib/inject.js +119 -50
- package/lib/lexicon-rt-source.js +25 -0
- package/lib/lexicon-rt-worker.js +26 -0
- package/lib/lexicon-rt.js +224 -0
- package/lib/lexicon-scope.js +56 -5
- package/lib/lexicon.js +143 -54
- package/lib/local-vector-service.js +3 -0
- package/lib/maintenance-ledger.js +542 -12
- package/lib/managed-runtime.js +260 -80
- package/lib/media.js +1 -1
- package/lib/memory.js +564 -131
- package/lib/port-surface.js +96 -11
- package/lib/private.js +47 -21
- package/lib/recall-cache.js +20 -34
- package/lib/retention.js +173 -0
- package/lib/rpc.js +135 -52
- package/lib/rt-index/builder.js +209 -0
- package/lib/rt-index/format.js +231 -0
- package/lib/rt-index/manifest.js +105 -0
- package/lib/rt-index/reader.js +673 -0
- package/lib/rt-index-retention.js +151 -0
- package/lib/rt-index-service.js +283 -0
- package/lib/rt-index-worker.js +21 -0
- package/lib/salient-wake.js +55 -4
- package/lib/state.js +195 -24
- package/lib/temporal.js +39 -13
- package/lib/token-measurement.js +126 -0
- package/lib/tools.js +101 -6
- package/lib/turn-log.js +108 -3
- package/lib/webui/graph-layout-worker.js +68 -0
- package/lib/webui/graph-local-physics.js +390 -0
- package/lib/webui/graph-spatial-grid.js +64 -0
- package/lib/webui/graph-view.bundle.js +6 -1
- package/lib/webui/graph-view.js +478 -135
- package/lib/webui/graph-webgl-renderer.js +74 -0
- package/lib/webui/standalone.js +1 -1
- package/lib/worker-pool.js +30 -4
- package/package.json +3 -2
- package/scripts/acceptance-local.mjs +4 -10
- package/scripts/bench-all-libraries.mjs +47 -0
- package/scripts/check-classic-graph-browser.mjs +189 -0
- package/scripts/check-client-browser.mjs +929 -0
- package/scripts/check-graph-browser.mjs +6 -0
- package/scripts/check-graph-elastic-browser.mjs +139 -0
- package/scripts/check-memory-review-browser.mjs +124 -0
- package/scripts/entity-dedupe.mjs +19 -3
- package/scripts/graph-artifact-provenance.mjs +30 -0
- package/scripts/graph-freeze-manifest.mjs +129 -0
- package/scripts/graph-geometry-fixture.mjs +40 -0
- package/scripts/graph-physics-bench.mjs +218 -0
- package/scripts/graph-scale-bench.mjs +213 -0
- package/scripts/graph-scale-memory.mjs +48 -0
- package/scripts/graph-service-bench.mjs +72 -0
- package/scripts/make-readme-shots.mjs +17 -5
- package/scripts/preview.mjs +1 -0
- package/scripts/rebuild-rt.mjs +18 -0
- package/scripts/scale-bench.mjs +183 -0
- package/scripts/simulate-injection.mjs +47 -8
- package/scripts/verify-host-fixtures.mjs +108 -0
- package/scripts/verify-host-recovery.mjs +565 -0
- package/scripts/verify-vector-recovery.mjs +740 -0
- package/tests/auto-link-candidates.test.mjs +20 -0
- package/tests/browser.test.mjs +16 -2
- package/tests/client-export.test.mjs +16 -1
- package/tests/client-pagination.test.mjs +1495 -0
- package/tests/client-render.test.mjs +223 -28
- package/tests/consolidation-fork.test.mjs +93 -10
- package/tests/consolidation-ledger.test.mjs +17 -1
- package/tests/diagnostic-entity-candidates.test.mjs +54 -0
- package/tests/diagnostic-report.test.mjs +429 -0
- package/tests/diagnostic-wiring.test.mjs +88 -0
- package/tests/diagnostics.test.mjs +27 -0
- package/tests/embedding-download.test.mjs +44 -0
- package/tests/engine-source-settings.test.mjs +69 -0
- package/tests/engine-sources.test.mjs +145 -0
- package/tests/entity-dedupe.test.mjs +143 -0
- package/tests/entity-merge-review.test.mjs +363 -0
- package/tests/entity-merge.test.mjs +12 -4
- package/tests/entity-review.test.mjs +87 -0
- package/tests/environment-check.test.mjs +51 -1
- package/tests/feedback.test.mjs +95 -0
- package/tests/graph-adjacency-index.test.mjs +536 -0
- package/tests/graph-cascade.test.mjs +229 -0
- package/tests/graph-import-diagnostic.test.mjs +25 -0
- package/tests/graph-overview.test.mjs +709 -0
- package/tests/graph-session-authorization.test.mjs +419 -0
- package/tests/graph-view-geometry.test.mjs +426 -0
- package/tests/graph-view-scale.test.mjs +88 -0
- package/tests/graph-view.test.mjs +444 -5
- package/tests/graph.test.mjs +43 -0
- package/tests/help-page.test.mjs +128 -54
- package/tests/inbound.test.mjs +19 -0
- package/tests/index-pagination.test.mjs +113 -0
- package/tests/index-read-view.test.mjs +212 -0
- package/tests/inject-guide.test.mjs +9 -0
- package/tests/injection-dedupe.test.mjs +213 -0
- package/tests/lexicon-recall.test.mjs +641 -0
- package/tests/lexicon-rt-lifecycle.test.mjs +196 -0
- package/tests/lexicon-rt.test.mjs +468 -0
- package/tests/local-embedding-worker.test.mjs +38 -0
- package/tests/local-vector-service.test.mjs +32 -3
- package/tests/maintenance-compat.test.mjs +128 -0
- package/tests/maintenance-settlement.test.mjs +1003 -0
- package/tests/managed-memory.test.mjs +39 -11
- package/tests/managed-runtime.test.mjs +109 -0
- package/tests/memory-fields.test.mjs +24 -12
- package/tests/observed-evidence.test.mjs +52 -0
- package/tests/port-surface.test.mjs +93 -1
- package/tests/recall-cache.test.mjs +56 -3
- package/tests/recall-dedup.test.mjs +63 -2
- package/tests/retention.test.mjs +260 -0
- package/tests/rt-index-cross-library.test.mjs +230 -0
- package/tests/rt-index-integration.test.mjs +194 -0
- package/tests/rt-index-retention.test.mjs +552 -0
- package/tests/rt-index-scale.test.mjs +204 -0
- package/tests/rt-index.test.mjs +705 -0
- package/tests/salient-date-boundaries.test.mjs +121 -0
- package/tests/salient-wake.test.mjs +29 -0
- package/tests/scale-bench.test.mjs +53 -0
- package/tests/settings-plumbing.test.mjs +25 -0
- package/tests/simulate-injection.test.mjs +15 -1
- package/tests/standalone-navigation.test.mjs +44 -0
- package/tests/state.test.mjs +51 -0
- package/tests/temporal-precision.test.mjs +102 -0
- package/tests/temporal.test.mjs +10 -6
- package/tests/token-measurement.test.mjs +98 -0
- package/tests/tool-schema.test.mjs +41 -5
- package/tests/tools.test.mjs +6 -3
- package/tests/turn-token-budget.test.mjs +149 -0
- package/tests/webui-auth.test.mjs +57 -1
- package/tests/webui.test.mjs +40 -15
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
// 引擎下载源:state.js 的校验 + rpc.js 的 allowlist/reset 名单。两者任一漏键,
|
|
8
|
+
// 设置页保存都会被静默丢弃——这正是这条用例要钉住的回归面。
|
|
9
|
+
|
|
10
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-engine-sources-'))
|
|
11
|
+
process.env.DSH_MEMU_HOME = home
|
|
12
|
+
|
|
13
|
+
const state = await import('../lib/state.js')
|
|
14
|
+
const rpc = await import('../lib/rpc.js')
|
|
15
|
+
|
|
16
|
+
test.after(() => {
|
|
17
|
+
try { state.flushState() } catch {}
|
|
18
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('updateSettings validates and normalizes the engine source keys', () => {
|
|
22
|
+
const saved = state.updateSettings({
|
|
23
|
+
engineSource: 'official',
|
|
24
|
+
engineUvMirror: 'https://mirror.example/astral-sh/uv/',
|
|
25
|
+
enginePythonMirror: 'https://mirror.example/astral-sh/python-build-standalone',
|
|
26
|
+
engineAllowUnpinned: true,
|
|
27
|
+
})
|
|
28
|
+
assert.equal(saved.engineSource, 'official')
|
|
29
|
+
assert.equal(saved.engineUvMirror, 'https://mirror.example/astral-sh/uv', 'trailing slashes are trimmed to keep <base>/<tag>/<file> stable')
|
|
30
|
+
assert.equal(saved.enginePythonMirror, 'https://mirror.example/astral-sh/python-build-standalone')
|
|
31
|
+
assert.equal(saved.engineAllowUnpinned, true)
|
|
32
|
+
|
|
33
|
+
// 空串是「没有自定义镜像」,不是错误。
|
|
34
|
+
assert.equal(state.updateSettings({ engineUvMirror: '' }).engineUvMirror, '')
|
|
35
|
+
|
|
36
|
+
for (const [patch, pattern] of [
|
|
37
|
+
[{ engineSource: 'latest' }, /invalid setting engineSource/],
|
|
38
|
+
[{ engineAllowUnpinned: 'yes' }, /must be boolean/],
|
|
39
|
+
[{ engineUvMirror: 'not a url' }, /must be an HTTP\(S\) base URL/],
|
|
40
|
+
[{ engineUvMirror: 'ftp://mirror.example/uv' }, /must be an HTTP\(S\) base URL/],
|
|
41
|
+
[{ engineUvMirror: 'https://user:pass@mirror.example/uv' }, /without embedded credentials/],
|
|
42
|
+
[{ engineUvMirror: 'https://mirror.example/uv?token=hidden' }, /query or fragment/],
|
|
43
|
+
[{ enginePythonMirror: 'https://mirror.example/python#release' }, /query or fragment/],
|
|
44
|
+
[{ enginePythonMirror: 42 }, /must be a string/],
|
|
45
|
+
]) {
|
|
46
|
+
assert.throws(() => state.updateSettings(patch), pattern, JSON.stringify(patch))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
state.updateSettings({ engineSource: 'auto', engineUvMirror: '', enginePythonMirror: '', engineAllowUnpinned: false })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('setSettings carries the engine source keys and resetSettings restores their defaults', async () => {
|
|
53
|
+
const saved = await rpc.dispatch({}, 'setSettings', {
|
|
54
|
+
patch: { engineSource: 'custom', engineUvMirror: 'https://mirror.example/uv', engineAllowUnpinned: true },
|
|
55
|
+
})
|
|
56
|
+
assert.equal(saved.engineSource, 'custom', 'allowlisted, otherwise the settings page would silently drop it')
|
|
57
|
+
assert.equal(saved.engineUvMirror, 'https://mirror.example/uv')
|
|
58
|
+
assert.equal(saved.engineAllowUnpinned, true)
|
|
59
|
+
|
|
60
|
+
// 未登记的键仍然按既有语义静默丢弃,不会把任意字段写进 state.json。
|
|
61
|
+
const dropped = await rpc.dispatch({}, 'setSettings', { patch: { engineSourceIs: 'custom' } })
|
|
62
|
+
assert.equal(dropped.engineSourceIs, undefined)
|
|
63
|
+
|
|
64
|
+
const reset = await rpc.dispatch({}, 'resetSettings', {})
|
|
65
|
+
assert.equal(reset.engineSource, 'auto')
|
|
66
|
+
assert.equal(reset.engineUvMirror, '')
|
|
67
|
+
assert.equal(reset.enginePythonMirror, '')
|
|
68
|
+
assert.equal(reset.engineAllowUnpinned, false)
|
|
69
|
+
})
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import {
|
|
4
|
+
resolveEngineSources, resolveRuntimePlatform, detectLibc, describeSources,
|
|
5
|
+
parseSha256Sum, pickLatestUvVersion, pickLatestPythonBuild, compareVersions, describeFetchError,
|
|
6
|
+
UV_VERSION, MANAGED_PYTHON, USTC_UV_BASE, UV_OFFICIAL_BASE,
|
|
7
|
+
} from '../lib/engine-sources.js'
|
|
8
|
+
|
|
9
|
+
test('platform resolution covers windows, macOS and both linux libcs', () => {
|
|
10
|
+
const win = resolveRuntimePlatform({ platform: 'win32', arch: 'x64', libc: 'gnu' })
|
|
11
|
+
assert.equal(win.key, 'win32-x64')
|
|
12
|
+
assert.equal(win.archiveKind, 'zip')
|
|
13
|
+
assert.match(win.asset, /windows-msvc/)
|
|
14
|
+
assert.ok(win.sha256)
|
|
15
|
+
|
|
16
|
+
const mac = resolveRuntimePlatform({ platform: 'darwin', arch: 'arm64', libc: 'gnu' })
|
|
17
|
+
assert.equal(mac.asset, 'uv-aarch64-apple-darwin.tar.gz')
|
|
18
|
+
assert.equal(mac.archiveKind, 'tar.gz')
|
|
19
|
+
|
|
20
|
+
const glibc = resolveRuntimePlatform({ platform: 'linux', arch: 'x64', libc: 'gnu' })
|
|
21
|
+
assert.equal(glibc.key, 'linux-x64')
|
|
22
|
+
assert.equal(glibc.asset, 'uv-x86_64-unknown-linux-gnu.tar.gz')
|
|
23
|
+
|
|
24
|
+
// musl ships a different binary; the gnuc one would not even start on Alpine.
|
|
25
|
+
const musl = resolveRuntimePlatform({ platform: 'linux', arch: 'arm64', libc: 'musl' })
|
|
26
|
+
assert.equal(musl.key, 'linux-arm64-musl')
|
|
27
|
+
assert.equal(musl.asset, 'uv-aarch64-unknown-linux-musl.tar.gz')
|
|
28
|
+
assert.equal(musl.sha256, null, 'no digest was ever verified for musl, so it must stay unpinned')
|
|
29
|
+
assert.equal(musl.pythonTriple, 'aarch64-unknown-linux-musl')
|
|
30
|
+
|
|
31
|
+
const unsupported = resolveRuntimePlatform({ platform: 'linux', arch: 'riscv64', libc: 'gnu' })
|
|
32
|
+
assert.equal(unsupported.supported, false)
|
|
33
|
+
assert.equal(unsupported.asset, null)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('libc detection prefers an explicit override and falls back to Alpine markers', () => {
|
|
37
|
+
assert.equal(detectLibc({ platform: 'linux', env: { DSH_MEMU_LIBC: 'musl' }, header: { glibcVersionRuntime: '2.39' } }), 'musl')
|
|
38
|
+
assert.equal(detectLibc({ platform: 'linux', env: { DSH_MEMU_LIBC: 'gnu' }, header: null, exists: () => true }), 'gnu')
|
|
39
|
+
assert.equal(detectLibc({ platform: 'linux', env: {}, header: { glibcVersionRuntime: '2.39' }, exists: () => true }), 'gnu')
|
|
40
|
+
assert.equal(detectLibc({ platform: 'linux', env: {}, header: null, exists: (file) => file === '/etc/alpine-release' }), 'musl')
|
|
41
|
+
assert.equal(detectLibc({ platform: 'win32', env: {} }), 'gnu')
|
|
42
|
+
assert.equal(resolveEngineSources({ platform: 'linux', arch: 'x64', env: { DSH_MEMU_LIBC: 'musl' } }).runtime.key, 'linux-x64-musl')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('mirror environment URLs reject credentials and malformed bases without echoing secrets', () => {
|
|
46
|
+
for (const value of ['file:///tmp/uv', 'https://user:secret@example.test/uv', 'https://example.test/uv?token=secret']) {
|
|
47
|
+
assert.throws(() => resolveEngineSources({ env: { DSH_MEMU_UV_MIRROR: value } }), error =>
|
|
48
|
+
/HTTP\(S\) base/.test(error.message) && !error.message.includes('secret'))
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('source order follows the preference, with custom URLs first and deduped', () => {
|
|
53
|
+
const auto = resolveEngineSources({ settings: {}, env: {}, platform: 'win32', arch: 'x64', libc: 'gnu' })
|
|
54
|
+
assert.deepEqual(auto.uv.map((s) => s.id), ['ustc', 'official'])
|
|
55
|
+
assert.deepEqual(auto.python.map((s) => s.id), ['ustc', 'official'])
|
|
56
|
+
assert.equal(auto.allowUnpinned, false)
|
|
57
|
+
assert.match(describeSources(auto), /^pinned; uv: USTC mirror/)
|
|
58
|
+
|
|
59
|
+
const official = resolveEngineSources({ settings: { engineSource: 'official' }, env: {}, platform: 'win32', arch: 'x64', libc: 'gnu' })
|
|
60
|
+
assert.deepEqual(official.uv.map((s) => s.id), ['official', 'ustc'])
|
|
61
|
+
|
|
62
|
+
const custom = resolveEngineSources({
|
|
63
|
+
settings: { engineUvMirror: 'https://mirror.example/astral-sh/uv/' },
|
|
64
|
+
env: {},
|
|
65
|
+
platform: 'win32', arch: 'x64', libc: 'gnu',
|
|
66
|
+
})
|
|
67
|
+
assert.equal(custom.uv[0].id, 'custom')
|
|
68
|
+
assert.equal(custom.uv[0].base, 'https://mirror.example/astral-sh/uv', 'trailing slash is trimmed')
|
|
69
|
+
assert.deepEqual(custom.uv.map((s) => s.id), ['custom', 'ustc', 'official'])
|
|
70
|
+
|
|
71
|
+
const duplicate = resolveEngineSources({
|
|
72
|
+
settings: { engineUvMirror: `${USTC_UV_BASE}/` },
|
|
73
|
+
env: {},
|
|
74
|
+
platform: 'linux', arch: 'x64', libc: 'gnu',
|
|
75
|
+
})
|
|
76
|
+
assert.deepEqual(duplicate.uv.map((s) => s.id), ['custom', 'official'], 'the same base is never queried twice')
|
|
77
|
+
|
|
78
|
+
const envWins = resolveEngineSources({
|
|
79
|
+
settings: { engineSource: 'official' },
|
|
80
|
+
env: { DSH_MEMU_ENGINE_SOURCE: 'custom', DSH_MEMU_UV_MIRROR: 'https://mirror.example/u' },
|
|
81
|
+
platform: 'win32', arch: 'x64', libc: 'gnu',
|
|
82
|
+
})
|
|
83
|
+
assert.deepEqual(envWins.uv.map((s) => s.id), ['custom', 'ustc', 'official'])
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('the unpinned opt-in only comes from settings or the explicit env flag', () => {
|
|
87
|
+
const off = resolveEngineSources({ settings: {}, env: {}, platform: 'win32', arch: 'x64', libc: 'gnu' })
|
|
88
|
+
assert.equal(off.allowUnpinned, false)
|
|
89
|
+
assert.equal(off.pinned.uv, UV_VERSION)
|
|
90
|
+
assert.equal(off.pinned.python, MANAGED_PYTHON)
|
|
91
|
+
|
|
92
|
+
assert.equal(resolveEngineSources({ settings: { engineAllowUnpinned: true }, env: {}, platform: 'win32', arch: 'x64', libc: 'gnu' }).allowUnpinned, true)
|
|
93
|
+
assert.equal(resolveEngineSources({ settings: {}, env: { DSH_MEMU_ALLOW_UNPINNED: '1' }, platform: 'win32', arch: 'x64', libc: 'gnu' }).allowUnpinned, true)
|
|
94
|
+
assert.equal(resolveEngineSources({ settings: { engineAllowUnpinned: true }, env: { DSH_MEMU_ALLOW_UNPINNED: '0' }, platform: 'win32', arch: 'x64', libc: 'gnu' }).allowUnpinned, false)
|
|
95
|
+
assert.equal(resolveEngineSources({ settings: {}, env: { DSH_MEMU_ALLOW_UNPINNED: 'yes' }, platform: 'win32', arch: 'x64', libc: 'gnu' }).allowUnpinned, true)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('sha256.sum parser keeps only well-formed digests', () => {
|
|
99
|
+
const text = [
|
|
100
|
+
'c74718c9167796fbb82956637e4b162303b3e10d275c3056276c6143dab713fa *source.tar.gz',
|
|
101
|
+
'297b3881fe1adfb922becc2c1613202abb41dc83ea5ff43d472aa087ca1f8683 uv-x86_64-pc-windows-msvc.zip',
|
|
102
|
+
'not-a-digest *broken.zip',
|
|
103
|
+
].join('\n')
|
|
104
|
+
const parsed = parseSha256Sum(text)
|
|
105
|
+
assert.equal(parsed.size, 2)
|
|
106
|
+
assert.equal(parsed.get('uv-x86_64-pc-windows-msvc.zip'), '297b3881fe1adfb922becc2c1613202abb41dc83ea5ff43d472aa087ca1f8683')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('rolling mirror listings resolve to the highest uv release', () => {
|
|
110
|
+
const listing = '<a href="/github-release/astral-sh/uv/0.13.9/">0.13.9</a><a href="/github-release/astral-sh/uv/0.13.10/">0.13.10</a><a href="/github-release/astral-sh/uv/LatestRelease/">latest</a>'
|
|
111
|
+
assert.equal(pickLatestUvVersion(listing), '0.13.10')
|
|
112
|
+
assert.equal(pickLatestUvVersion(''), null)
|
|
113
|
+
assert.ok(compareVersions('0.13.10', '0.13.9') > 0)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('CPython listings resolve the newest install_only build for this triple', () => {
|
|
117
|
+
const listing = [
|
|
118
|
+
'/github-release/astral-sh/python-build-standalone/20261124/cpython-3.12.14%2B20261124-x86_64-pc-windows-msvc-install_only.tar.gz',
|
|
119
|
+
'/github-release/astral-sh/python-build-standalone/20261124/cpython-3.12.16%2B20261124-x86_64-pc-windows-msvc-install_only.tar.gz',
|
|
120
|
+
'/github-release/astral-sh/python-build-standalone/20261124/cpython-3.12.16%2B20261124-aarch64-apple-darwin-install_only.tar.gz',
|
|
121
|
+
'/github-release/astral-sh/python-build-standalone/20261124/cpython-3.11.18%2B20261124-x86_64-pc-windows-msvc-install_only.tar.gz',
|
|
122
|
+
].join('\n')
|
|
123
|
+
const build = pickLatestPythonBuild(listing, { triple: 'x86_64-pc-windows-msvc', series: '3.12' })
|
|
124
|
+
assert.equal(build.version, '3.12.16')
|
|
125
|
+
assert.equal(build.build, '20261124')
|
|
126
|
+
assert.equal(pickLatestPythonBuild(listing, { triple: 'aarch64-unknown-linux-gnu', series: '3.12' }), null)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('network failures keep their real cause instead of the bare fetch failed', () => {
|
|
130
|
+
const error = new TypeError('fetch failed')
|
|
131
|
+
error.cause = Object.assign(new Error('connect ECONNRESET 20.27.177.113:443'), { code: 'ECONNRESET' })
|
|
132
|
+
assert.equal(describeFetchError(error), 'fetch failed (ECONNRESET: connect ECONNRESET 20.27.177.113:443)')
|
|
133
|
+
|
|
134
|
+
const timeout = new TypeError('fetch failed')
|
|
135
|
+
timeout.cause = Object.assign(new Error('Connect Timeout Error'), { code: 'UND_ERR_CONNECT_TIMEOUT' })
|
|
136
|
+
assert.match(describeFetchError(timeout), /UND_ERR_CONNECT_TIMEOUT/)
|
|
137
|
+
|
|
138
|
+
assert.equal(describeFetchError(new Error('pip install failed')), 'pip install failed')
|
|
139
|
+
assert.equal(describeFetchError(null), 'unknown error')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('the official base still points at the GitHub release layout', () => {
|
|
143
|
+
assert.equal(UV_OFFICIAL_BASE, 'https://github.com/astral-sh/uv/releases/download')
|
|
144
|
+
assert.equal(USTC_UV_BASE, 'https://mirrors.ustc.edu.cn/github-release/astral-sh/uv')
|
|
145
|
+
})
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Real CLI consumers must not turn an incomplete plan into a clean result or writes.
|
|
2
|
+
import test from 'node:test'
|
|
3
|
+
import assert from 'node:assert/strict'
|
|
4
|
+
import { spawnSync } from 'node:child_process'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
|
|
10
|
+
const root = fileURLToPath(new URL('../', import.meta.url))
|
|
11
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-entity-dedupe-'))
|
|
12
|
+
process.env.DSH_MEMU_HOME = home
|
|
13
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
14
|
+
const state = await import('../lib/state.js')
|
|
15
|
+
const { indexDir } = await import('../lib/paths.js')
|
|
16
|
+
|
|
17
|
+
test.after(() => {
|
|
18
|
+
state.flushState()
|
|
19
|
+
fs.rmSync(home, { recursive: true, force: true })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test.afterEach(() => {
|
|
23
|
+
for (const library of state.listLibraries()) state.archiveLibrary(library.id)
|
|
24
|
+
state.flushState()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
function fixture(name, names) {
|
|
28
|
+
const id = state.createLibrary({ name, cwd: path.join(home, name) }).id
|
|
29
|
+
const entities = Object.fromEntries(names.map((name, i) => {
|
|
30
|
+
const entityId = `ent-cli-${i}`
|
|
31
|
+
return [entityId, { id: entityId, name, kind: 'person', status: 'confirmed', aliases: [] }]
|
|
32
|
+
}))
|
|
33
|
+
state.savePrivateIndex(id, { entries: {
|
|
34
|
+
'mem-proof': { title: '南宫晚晴的午后', content: '南宫晚晴坐在窗边讲这件事。',
|
|
35
|
+
status: 'active', visibility: 'shared', layer: 'long_term' },
|
|
36
|
+
} })
|
|
37
|
+
fs.writeFileSync(path.join(indexDir(), `${id}.entities.json`), JSON.stringify({ version: 1, entities, relationships: {} }))
|
|
38
|
+
state.flushState()
|
|
39
|
+
return id
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function runCli(args = []) {
|
|
43
|
+
state.flushState()
|
|
44
|
+
const run = spawnSync(process.execPath, ['--import', './tests/loader-register.mjs', 'scripts/entity-dedupe.mjs', ...args], {
|
|
45
|
+
cwd: root, encoding: 'utf8', timeout: 30_000, windowsHide: true,
|
|
46
|
+
env: { ...process.env, DSH_MEMU_HOME: home, DSH_MEMU_MEMORY_HOME: home },
|
|
47
|
+
})
|
|
48
|
+
assert.ifError(run.error)
|
|
49
|
+
assert.equal(run.signal, null, run.stderr)
|
|
50
|
+
return run
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function truthSnapshot(ids) {
|
|
54
|
+
return [path.join(home, 'state.json'), ...ids.flatMap(id => [
|
|
55
|
+
path.join(indexDir(), `${id}.json`), path.join(indexDir(), `${id}.entities.json`),
|
|
56
|
+
])].map(file => [file, fs.readFileSync(file)])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function assertUnchanged(before, backups) {
|
|
60
|
+
for (const [file, bytes] of before) assert.deepEqual(fs.readFileSync(file), bytes, file)
|
|
61
|
+
assert.deepEqual(state.listBackups(), backups, 'an incomplete plan must not create a backup')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function assertDeferred(run) {
|
|
65
|
+
assert.equal(run.status, 2, run.stdout + run.stderr)
|
|
66
|
+
assert.match(run.stdout, /ENTITY_REPAIR_DEFERRED/)
|
|
67
|
+
assert.match(run.stdout, /规划未完成/)
|
|
68
|
+
assert.match(run.stdout, /"partial":true/)
|
|
69
|
+
assert.match(run.stdout, /"deferred":true/)
|
|
70
|
+
assert.match(run.stdout, /图管理/)
|
|
71
|
+
assert.doesNotMatch(run.stdout, /没有需要处理的实体组|没有可自动合并的组|dry-run:可自动合并|图备份:|已合并 \d+ 组/)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
test('large-library CLI dry-run and apply both expose deferral and preserve every truth file', () => {
|
|
75
|
+
const id = fixture('cli-large', Array.from({ length: 257 }, (_, i) => `Person ${String(i).padStart(4, '0')}`))
|
|
76
|
+
const before = truthSnapshot([id])
|
|
77
|
+
const backups = state.listBackups()
|
|
78
|
+
for (const flags of [[], ['--apply', '--include-similar']]) {
|
|
79
|
+
const run = runCli(['--library', id, ...flags])
|
|
80
|
+
assertDeferred(run)
|
|
81
|
+
assert.ok(run.stdout.includes(`[${id}]`), 'an empty deferred group list must still render its library')
|
|
82
|
+
assert.match(run.stdout, /"reason":"entity-limit"/)
|
|
83
|
+
assert.match(run.stdout, /"totalEntities":257/)
|
|
84
|
+
assert.match(run.stdout, /"totalEntitiesExact":true/)
|
|
85
|
+
assert.match(run.stdout, /"scanned":0/)
|
|
86
|
+
assert.match(run.stdout, /"entityLimit":256/)
|
|
87
|
+
assertUnchanged(before, backups)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('one partial library blocks all apply writes even when another library has a proven group', () => {
|
|
92
|
+
const small = fixture('cli-mixed-small', ['南宫晚', '宫晚晴'])
|
|
93
|
+
const large = fixture('cli-mixed-large', Array.from({ length: 257 }, (_, i) => `Person ${String(i).padStart(4, '0')}`))
|
|
94
|
+
const before = truthSnapshot([small, large])
|
|
95
|
+
const backups = state.listBackups()
|
|
96
|
+
const run = runCli(['--apply', '--include-similar'])
|
|
97
|
+
assertDeferred(run)
|
|
98
|
+
assert.match(run.stdout, /1 组可证明/, 'the mixed fixture must contain actual work that would otherwise write')
|
|
99
|
+
assert.match(run.stdout, /"totalEntities":259/)
|
|
100
|
+
assert.match(run.stdout, /"scanned":2/)
|
|
101
|
+
assertUnchanged(before, backups)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('an unreadable entity store is failed/deferred rather than a clean empty CLI plan', () => {
|
|
105
|
+
const id = fixture('cli-corrupt', ['南宫晚', '宫晚晴'])
|
|
106
|
+
fs.writeFileSync(path.join(indexDir(), `${id}.entities.json`), '{ not json')
|
|
107
|
+
const before = truthSnapshot([id])
|
|
108
|
+
const backups = state.listBackups()
|
|
109
|
+
const run = runCli(['--library', id, '--apply'])
|
|
110
|
+
assertDeferred(run)
|
|
111
|
+
assert.match(run.stdout, /规划失败/)
|
|
112
|
+
assert.match(run.stdout, /"totalEntitiesExact":false/)
|
|
113
|
+
assert.match(run.stdout, /"failedLibraries":1/)
|
|
114
|
+
assertUnchanged(before, backups)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('complete small CLI plans retain dry-run, backup-before-merge and clean rerun behavior', () => {
|
|
118
|
+
const id = fixture('cli-complete', ['南宫晚', '宫晚晴'])
|
|
119
|
+
const before = truthSnapshot([id])
|
|
120
|
+
const backups = state.listBackups()
|
|
121
|
+
const dry = runCli(['--library', id])
|
|
122
|
+
assert.equal(dry.status, 0, dry.stdout + dry.stderr)
|
|
123
|
+
assert.match(dry.stdout, /dry-run:可自动合并 1 组/)
|
|
124
|
+
assert.doesNotMatch(dry.stdout, /ENTITY_REPAIR_DEFERRED/)
|
|
125
|
+
assertUnchanged(before, backups)
|
|
126
|
+
|
|
127
|
+
const applied = runCli(['--library', id, '--apply'])
|
|
128
|
+
assert.equal(applied.status, 0, applied.stdout + applied.stderr)
|
|
129
|
+
assert.match(applied.stdout, /已合并 1 组/)
|
|
130
|
+
const current = JSON.parse(fs.readFileSync(path.join(indexDir(), `${id}.entities.json`), 'utf8'))
|
|
131
|
+
assert.deepEqual(Object.values(current.entities).map(row => row.name), ['南宫晚晴'])
|
|
132
|
+
const made = state.listBackups().filter(row => !backups.some(old => old.name === row.name))
|
|
133
|
+
assert.equal(made.length, 1)
|
|
134
|
+
const backedUp = path.join(made[0].dir, 'index', `${id}.entities.json`)
|
|
135
|
+
assert.deepEqual(fs.readFileSync(backedUp), before.find(([file]) => file.endsWith(`${id}.entities.json`))[1], 'backup contains the pre-merge truth')
|
|
136
|
+
const originalMemory = JSON.parse(before.find(([file]) => file.endsWith(`${id}.json`))[1])
|
|
137
|
+
const currentMemory = JSON.parse(fs.readFileSync(path.join(indexDir(), `${id}.json`), 'utf8'))
|
|
138
|
+
assert.equal(currentMemory.entries['mem-proof'].content, originalMemory.entries['mem-proof'].content)
|
|
139
|
+
const clean = runCli(['--library', id])
|
|
140
|
+
assert.equal(clean.status, 0, clean.stdout + clean.stderr)
|
|
141
|
+
assert.match(clean.stdout, /没有需要处理的实体组/)
|
|
142
|
+
assert.doesNotMatch(clean.stdout, /ENTITY_REPAIR_DEFERRED/)
|
|
143
|
+
})
|