Files
deepseek-harness/examples/desktop/test/hub-model.test.js
ZiyaZhang e8f5c0b51b feat(desktop): DSH Electron desktop shell — harness internals visualized
Minimal Electron shell over the DSH JSON-RPC runtime — a first-look at
what a ChatGPT.app-style host on top of the DeepSeek Harness looks
like, with the harness's normally-invisible internals (trace timeline,
context surface, subagent tree, compaction, plugin registry, rubrics)
brought forward as first-class UI surfaces so plugin authors and
researchers can see what the agent is actually doing.

Runs against three keyless-to-live profiles (stdio-echo works on
master out of the box; daemon-echo / daemon-vibe-echo activate once
the daemon-demo lands; stdio-deepseek and daemon-vibe hit the real
DeepSeek API when you supply a key). HARNESS_DEV auto-resolves to the
in-repo runtime when this shell ships under examples/desktop/, so a
fresh clone launches without config; env DSH_DEV_ROOT overrides for
custom layouts, and a sibling deepseek-harness-dev/ checkout is the
original dev workflow.

Cold-clone gate (P0 fixes for first-time-clone usability):
- HARNESS_DEV: 3-candidate resolver (env → walk-up in-repo marker →
  sibling), unit-tested via mock fs so ordering is locked without
  needing either real layout on disk.
- config yml leaves rewritten at assemble time so the sibling-clone
  paths (../../deepseek-harness-dev/examples/echo-agent/…) become
  the in-repo paths (../../echo-agent/…) in the released tree —
  source yml stays usable for local dev, released tree ships a
  working shape.
- pnpm-workspace.yaml allowBuilds.electron = true (was placeholder).
- missing-key card in stdio-deepseek offers a one-click switch to
  stdio-echo (the keyless profile that works on master) rather than
  daemon-echo (blocked on the not-yet-shipped daemon-demo).
- assemble-oss-release.sh rewrites the source-side breadcrumb name
  'dsh-desktop-demo' → 'dsh-desktop' for the released package.json.

FOUC guard on the onboarding gate (41fc5df carried) keeps the
first-launch splash from flashing before the runtime probe finishes.

Test suite (1634 tests in source, 3990 in the runtime repo) covers
resolver ordering, renderer classifiers, trace timeline shape,
compaction diff rendering, rubric parity, and the missing-key
onboarding paths.
2026-07-18 12:59:34 -07:00

160 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Unit tests for src/renderer/hub-model.js — the pure Hub data module.
'use strict'
const test = require('node:test')
const assert = require('node:assert/strict')
const H = require('../src/renderer/hub-model.js')
test('KIND_ORDER puts plugin first', () => {
assert.equal(H.KIND_ORDER[0], 'plugin')
assert.equal(H.KIND_ORDER.length, 7)
assert.deepEqual(
[...H.KIND_ORDER],
['plugin', 'skill', 'prompt', 'rubric', 'profile', 'dataset', 'script'],
)
})
test('normaliseRow fills defaults + preserves kind-specific fields', () => {
const r = H.normaliseRow('script', { name: 'dedup', lang: 'python', lastStatus: 'ok' })
assert.equal(r.kind, 'script')
assert.equal(r.name, 'dedup')
assert.equal(r.version, 'v1')
assert.equal(r.lang, 'python')
assert.equal(r.lastStatus, 'ok')
assert.equal(r.rowCount, null)
assert.deepEqual(r.versions, [])
})
test('normaliseRow retains numeric rowCount for datasets', () => {
const r = H.normaliseRow('dataset', { name: 'seed', rowCount: 12000 })
assert.equal(r.rowCount, 12000)
})
test('sortHubRows sorts by kind order then name asc', () => {
const rows = [
{ kind: 'dataset', name: 'zebra' },
{ kind: 'plugin', name: 'bash-local' },
{ kind: 'dataset', name: 'alpha' },
{ kind: 'script', name: 'dedup' },
{ kind: 'plugin', name: 'agent-spine' },
].map((r) => H.normaliseRow(r.kind, r))
const sorted = H.sortHubRows(rows)
assert.deepEqual(
sorted.map((r) => `${r.kind}:${r.name}`),
['plugin:agent-spine', 'plugin:bash-local', 'dataset:alpha', 'dataset:zebra', 'script:dedup'],
)
})
test('sortHubRows leaves the input untouched', () => {
const rows = [
H.normaliseRow('script', { name: 'a' }),
H.normaliseRow('plugin', { name: 'b' }),
]
const snapshot = rows.map((r) => r.name)
H.sortHubRows(rows)
assert.deepEqual(rows.map((r) => r.name), snapshot)
})
test('sectionCounts includes zero-count sections so empty slots render', () => {
const rows = [
H.normaliseRow('plugin', { name: 'p1' }),
H.normaliseRow('plugin', { name: 'p2' }),
H.normaliseRow('script', { name: 's1' }),
]
const counts = H.sectionCounts(rows)
assert.equal(counts.get('plugin'), 2)
assert.equal(counts.get('script'), 1)
assert.equal(counts.get('dataset'), 0)
assert.equal(counts.get('rubric'), 0)
assert.equal(counts.size, H.KIND_ORDER.length)
})
test('parseScriptSummary reads the last JSON line', () => {
const stdout = [
'starting…',
'seen 100 rows',
'{"progress": 0.5}', // no written/dropped → skipped
'{"written": 42, "dropped": 8, "notes": "ok"}',
].join('\n')
const summary = H.parseScriptSummary(stdout)
assert.equal(summary.written, 42)
assert.equal(summary.dropped, 8)
assert.equal(summary.notes, 'ok')
assert.equal(summary.source, 'stdout')
})
test('parseScriptSummary returns null when nothing usable is emitted', () => {
assert.equal(H.parseScriptSummary(''), null)
assert.equal(H.parseScriptSummary('hello\nworld\n'), null)
assert.equal(H.parseScriptSummary('{"unrelated": 1}\n'), null)
})
test('parseScriptSummary tolerates a trailing empty line', () => {
const stdout = '{"written": 1, "dropped": 0}\n\n'
const summary = H.parseScriptSummary(stdout)
assert.equal(summary.written, 1)
})
test('formatDiffSummary composes the row-count delta phrase', () => {
const s = H.formatDiffSummary({
inputRows: 18432,
summary: { written: 12109, dropped: 6323, notes: 'exact-match dedup' },
outputRows: 12109,
})
assert.match(s, /18,432 → 12,109 rows/)
assert.match(s, /6,323 dropped/)
assert.match(s, /exact-match dedup/)
})
test('formatDiffSummary falls back to fs delta when summary is missing', () => {
const s = H.formatDiffSummary({ inputRows: 100, summary: null, outputRows: 80 })
assert.match(s, /100 → 80 rows/)
assert.match(s, /20 dropped/)
})
test('formatDiffSummary handles no input row count gracefully', () => {
const s = H.formatDiffSummary({ inputRows: NaN, summary: { written: 5, dropped: 0 }, outputRows: 5 })
assert.match(s, /5 rows written/)
})
test('previewDatasetRows parses first N JSONL rows', () => {
const jsonl = [
'{"messages": [{"role":"user","content":"hi"}]}',
'{"messages": [{"role":"user","content":"there"}]}',
'garbage line',
'{"messages": [{"role":"user","content":"third"}]}',
'{"messages": [{"role":"user","content":"fourth"}]}',
].join('\n')
const rows = H.previewDatasetRows(jsonl, 3)
assert.equal(rows.length, 3)
assert.equal(rows[0].messages[0].content, 'hi')
assert.equal(rows[2].messages[0].content, 'third')
})
test('chipColumnsFor detects the known chip columns + collects the rest', () => {
const rows = [
{ messages: [], reasoning_content: 'x', task_id: 'a' },
{ messages: [], tool_calls: [] },
]
const c = H.chipColumnsFor(rows)
assert.deepEqual(c.chips, ['messages', 'reasoning_content', 'tool_calls'])
assert.deepEqual(c.rest, ['task_id'])
})
test('countJsonlRows counts non-empty lines only', () => {
assert.equal(H.countJsonlRows(''), 0)
assert.equal(H.countJsonlRows('a\nb\nc\n'), 3)
assert.equal(H.countJsonlRows('a\n\nb\n\n'), 2)
})
test('sdkLegend lists the four seams the Hub touches', () => {
const legend = H.sdkLegend()
const ids = legend.map((l) => l.id)
assert.deepEqual(ids.sort(), ['dataset/list', 'library/list', 'plugins/list', 'script/run'])
const gap = legend.find((l) => l.id === 'script/run')
assert.equal(gap.status, 'file-tier')
assert.equal(gap.gap, 'G12')
})