Files
deepseek-harness/examples/desktop/test/renderer-qa-seed-session.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

48 lines
2.7 KiB
JavaScript

// Round-visual N2 (2026-07-16): `window.__dshQaSeedSession` seam. See
// docs/walkthrough-round-visual.md tail for the discovery: `dsh.newSession()`
// alone leaves `state.activeSessionId === null`, so any fixture that gates on
// an active session (playTraceFixture / onSessionEvent) renders nothing.
// This test locks the seam's DSH_QA gating rule + the newSession → selectSession
// chain so future walkthroughs don't rediscover the two-step dance.
//
// Gating shape:
// window.dshQa present → __dshQaSeedSession must exist and chain properly
// window.dshQa absent → __dshQaSeedSession must NOT be exposed (prod parity)
'use strict'
const test = require('node:test')
const assert = require('node:assert/strict')
const { loadRenderer } = require('./renderer-harness.js')
test('__dshQaSeedSession: exposed only when window.dshQa is present (DSH_QA=1 parity)', async () => {
// Absent dshQa bridge → seam must not exist. This is the production
// shape — DSH_QA=0 launches never see the seam, matching the same rule
// that gates window:reveal + window.dshQa itself.
const { window: prodWindow } = await loadRenderer()
assert.equal(prodWindow.dshQa, undefined, 'sanity: harness omits dshQa by default')
assert.equal(typeof prodWindow.__dshQaSeedSession, 'undefined',
'__dshQaSeedSession must not leak into production renderer')
})
test('__dshQaSeedSession: chains newSession → selectSession and returns the id', async () => {
// Inject a dshQa bridge before bootUi runs. The harness's default dsh stub
// returns { id: 'test-session' } from newSession; selectSession is the
// renderer's own routine (nothing to stub — we observe its side effect).
const preboot = (windowStub) => { windowStub.dshQa = { revealWindow: async () => ({ ok: true }) } }
const { window: qaWindow, dsh } = await loadRenderer({}, { preboot })
assert.equal(typeof qaWindow.__dshQaSeedSession, 'function',
'seam should be exposed when window.dshQa is present')
const { id } = await qaWindow.__dshQaSeedSession()
assert.equal(id, 'test-session', 'seam returns the freshly minted session id')
// newSession IPC was called exactly once (order-in-calls tolerant so the
// harness's own boot-time calls don't fail the assertion).
const newSessionCalls = dsh.__calls.filter((c) => c[0] === 'newSession')
assert.equal(newSessionCalls.length, 1, 'newSession IPC called exactly once by the seam')
// After the chain resolves, `getActiveSessionId()` must reflect the new id —
// that's the whole point of the seam (state.activeSessionId is what
// playTraceFixture / onSessionEvent gate on).
assert.equal(qaWindow.__dshChat.getActiveSessionId(), 'test-session',
'activeSessionId flipped by selectSession — the chain worked')
})