Files
deepseek-harness/examples/desktop/test/window-reveal-qa-seam.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

100 lines
4.9 KiB
JavaScript

// The QA-only `window:reveal` handler is extracted into window-reveal.js so
// we can drive its handshake without booting Electron. The channel itself
// is registered by src/main/main.js only when process.env.DSH_QA === '1' —
// that gate is asserted here by a smaller check that reads the source, so
// the production preload never leaks the reveal seam.
'use strict'
const test = require('node:test')
const assert = require('node:assert')
const fs = require('node:fs')
const path = require('node:path')
const { revealWindow } = require('../src/main/window-reveal.js')
function fakeWindow(overrides = {}) {
const state = { shown: false, workspaceCalls: [], destroyed: false }
const win = {
isDestroyed: () => state.destroyed,
isVisibleOnAllWorkspaces: () => false,
setVisibleOnAllWorkspaces: (flag, opts) => state.workspaceCalls.push({ flag, opts }),
showInactive: () => { state.shown = true },
...overrides,
}
win._state = state
return win
}
test('reveal returns no-window when handle is missing', async () => {
const res1 = await revealWindow(null)
assert.deepStrictEqual(res1, { ok: false, reason: 'no-window' })
const dead = fakeWindow()
dead._state.destroyed = true
const res2 = await revealWindow(dead)
assert.deepStrictEqual(res2, { ok: false, reason: 'no-window' })
})
test('reveal calls showInactive on a healthy window', async () => {
const w = fakeWindow()
const res = await revealWindow(w, { platform: 'linux', sleep: () => Promise.resolve() })
assert.deepStrictEqual(res, { ok: true })
assert.strictEqual(w._state.shown, true, 'showInactive must fire — the whole point of the seam')
})
test('darwin path flips workspace flag on then restores off', async () => {
const w = fakeWindow()
await revealWindow(w, { platform: 'darwin', sleep: () => Promise.resolve() })
assert.ok(w._state.workspaceCalls.length >= 2,
`expected at least two workspace-flag calls on darwin (got ${w._state.workspaceCalls.length})`)
assert.strictEqual(w._state.workspaceCalls[0].flag, true)
assert.deepStrictEqual(w._state.workspaceCalls[0].opts, { visibleOnFullScreen: false })
const last = w._state.workspaceCalls[w._state.workspaceCalls.length - 1]
assert.strictEqual(last.flag, false,
'must restore to false — otherwise the window follows the user across every Space')
})
test('non-darwin platforms skip the workspace flip entirely', async () => {
const w = fakeWindow()
await revealWindow(w, { platform: 'linux', sleep: () => Promise.resolve() })
assert.strictEqual(w._state.workspaceCalls.length, 0,
'workspace-flag is a macOS Space quirk; other platforms should never touch it')
})
test('darwin: if window already visibleOnAllWorkspaces, do NOT force it back to false', async () => {
// Some users legitimately keep DSH on all workspaces themselves. Our
// reveal must not override that preference on exit.
const w = fakeWindow({ isVisibleOnAllWorkspaces: () => true })
await revealWindow(w, { platform: 'darwin', sleep: () => Promise.resolve() })
// We may have called setVisibleOnAllWorkspaces(true, …) again (redundant but harmless),
// but must NOT have called false on the way out.
const restoredFalse = w._state.workspaceCalls.some((c) => c.flag === false)
assert.strictEqual(restoredFalse, false,
'we should not clobber a user-set all-workspaces preference')
})
test('main.js gates window:reveal registration on DSH_QA=1', () => {
// Source-level assertion — the seam must be behind an explicit env flag
// so the production preload surface has zero reveal channel. Reading
// the source keeps the test cheap and honest about main.js's structure
// (we don't boot Electron just to sniff a handler registration).
const src = fs.readFileSync(path.resolve(__dirname, '..', 'src', 'main', 'main.js'), 'utf8')
const registerIdx = src.indexOf("ipcMain.handle('window:reveal'")
assert.notStrictEqual(registerIdx, -1, 'window:reveal handler registration missing from main.js')
// The NEAREST gate before the handler must be the DSH_QA=1 check — other
// earlier DSH_QA gates (qa hash, console mirror) are unrelated to this seam.
const gateIdx = src.lastIndexOf("process.env.DSH_QA === '1'", registerIdx)
assert.notStrictEqual(gateIdx, -1, 'DSH_QA gate string missing before window:reveal in main.js')
assert.ok(registerIdx < gateIdx + 400,
'window:reveal handler must be inside the DSH_QA=1 gate block')
})
test('preload.js exposes dshQa.revealWindow only when DSH_QA=1', () => {
const src = fs.readFileSync(path.resolve(__dirname, '..', 'src', 'preload', 'preload.js'), 'utf8')
const gateIdx = src.indexOf("process.env.DSH_QA === '1'")
const bridgeIdx = src.indexOf("exposeInMainWorld('dshQa'")
assert.notStrictEqual(gateIdx, -1, 'DSH_QA gate missing from preload.js')
assert.notStrictEqual(bridgeIdx, -1, 'dshQa contextBridge missing from preload.js')
assert.ok(bridgeIdx > gateIdx,
'dshQa bridge must sit inside the DSH_QA=1 gate block')
})