Files
deepseek-harness/examples/desktop/test/renderer-compact-now.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

115 lines
4.7 KiB
JavaScript

// Tests for renderer.js `compactNow()` — statusbar Compact button.
//
// Locks the discriminated result the JSON-RPC `session/compact` wire returns:
// the shell must render distinct system lines for compacted/not-compacted/
// unsupported/streaming, and disable the button after a MethodNotFound so a
// second click can't retrigger the rejection. See renderer.js §compactNow and
// packages/ui/jsonrpc/src/protocol.ts SessionCompactResult (both landed in the
// same integration branch).
'use strict'
const test = require('node:test')
const assert = require('node:assert/strict')
const { loadRenderer } = require('./renderer-harness.js')
async function bootWithSession(dshOverride) {
const { renderer, dsh } = await loadRenderer(dshOverride)
renderer.ensureSession('s1', { title: 'a', header: {} })
await renderer.selectSession('s1')
return { renderer, dsh }
}
test('compactNow renders a "nothing to compact" system line on { compacted: false }', async () => {
const { renderer } = await bootWithSession({
async compactSession(_sid) {
return { supported: true, result: { compacted: false, reason: 'nothing-to-compact' } }
},
})
await renderer.compactNow()
const text = renderer.getStreamText()
assert.match(text, /nothing to compact/i,
`expected "nothing to compact" system line, got: ${text.slice(-200)}`)
// The compact/summary card is drawn from the session.event stream on the
// { compacted: true } path; a false result must never draw one.
assert.doesNotMatch(text, /Context compacted/i)
})
test('compactNow stays quiet on { compacted: true } — the session.event stream carries the card', async () => {
const { renderer } = await bootWithSession({
async compactSession(_sid) {
return {
supported: true,
result: { compacted: true, startSeq: 42, summarySeq: 43, endSeq: 44, shadowedCount: 6 },
}
},
})
const before = renderer.getStreamText().length
await renderer.compactNow()
// No "compact requested" line — the daemon emits compact/start →
// compact/summary → compact/end as session events; the compact card lives
// there, not on this branch.
assert.doesNotMatch(renderer.getStreamText().slice(before), /compact requested/i)
assert.doesNotMatch(renderer.getStreamText().slice(before), /nothing to compact/i)
assert.doesNotMatch(renderer.getStreamText().slice(before), /compact skipped/i)
})
test('compactNow reports "unsupported" and remembers it on { supported: false }', async () => {
let calls = 0
const { renderer } = await bootWithSession({
async compactSession(_sid) {
calls += 1
return { supported: false, reason: 'MethodNotFound' }
},
})
await renderer.compactNow()
assert.equal(renderer.getCompactSupported(), false)
assert.match(renderer.getStreamText(), /runtime does not support session\/compact/i)
// A second click must not re-issue the RPC — updateCompactButton keeps the
// button disabled from state.compactSupported === false.
await renderer.compactNow()
// compactNow still runs the RPC in the current implementation (the guard
// lives on the button, not the function), but the state stays sticky at
// false. Verify at least the state contract; the button-disabled guard is
// covered by updateCompactButton tests.
assert.equal(renderer.getCompactSupported(), false)
assert.equal(calls, 2, 'compactNow re-issues the RPC on repeated calls; the button guard is what stops the user')
})
test('compactNow reports the streaming rejection with a compact-friendly message', async () => {
const { renderer } = await bootWithSession({
async compactSession(_sid) {
const err = new Error('session is streaming; compact after turn ends')
throw err
},
})
await renderer.compactNow()
assert.match(renderer.getStreamText(), /compact after this turn ends/i,
'streaming rejection should surface with the "compact after this turn ends" hint')
})
test('compactNow surfaces other RPC failures verbatim', async () => {
const { renderer } = await bootWithSession({
async compactSession(_sid) { throw new Error('summarize boom') },
})
await renderer.compactNow()
assert.match(renderer.getStreamText(), /compact failed: summarize boom/,
'unexpected error should render with the raw message')
})
test('compactNow accepts a legacy untagged ok result (backward compatibility)', async () => {
const { renderer } = await bootWithSession({
async compactSession(_sid) { return { supported: true, result: {} } },
})
await renderer.compactNow()
// Legacy runtime with no `compacted` discriminator falls into the "compact
// requested" branch — better than a silent click.
assert.match(renderer.getStreamText(), /compact requested/i)
})