Files
deepseek-harness/examples/desktop/test/interrupt-normalize.test.js
T
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

125 lines
4.7 KiB
JavaScript

// Locks the canonical protocol-v2 `session/interrupt` normalization shape.
// The bridge (packages/ui/jsonrpc/src/interactions.ts) only emits requests
// with the discriminant at `payload.kind`; a legacy flat shape at
// `spec.kind` was considered during protocol design but never made it to
// the wire. This test locks that in place — if the wire ever moves back to
// flat, this test flips to the new expectation deliberately.
'use strict'
const test = require('node:test')
const assert = require('node:assert')
const { normalizeInterruptRequest } = require('../src/main/interrupt-normalize.js')
function makePending() { return new Map() }
function makeSender() {
const calls = []
return { fn: (channel, payload) => calls.push({ channel, payload }), calls }
}
test('accepts canonical nested payload (approval)', () => {
const pending = makePending()
const sender = makeSender()
const req = {
sessionId: 'S1',
interruptId: 'I-1',
payload: {
kind: 'approval',
spec: {
toolCallId: 'call-a',
options: [
{ optionId: 'allow-once', name: 'Allow once', kind: 'allow_once' },
{ optionId: 'reject-once', name: 'Reject', kind: 'reject_once' },
],
},
},
}
const p = normalizeInterruptRequest(req, pending, sender.fn)
assert.ok(typeof p.then === 'function', 'returns a pending promise')
assert.strictEqual(sender.calls.length, 1, 'dispatched once to renderer')
const { channel, payload } = sender.calls[0]
assert.strictEqual(channel, 'interrupt:incoming')
assert.strictEqual(payload.sessionId, 'S1')
assert.strictEqual(payload.interruptId, 'I-1')
assert.strictEqual(payload.kind, 'approval')
assert.strictEqual(payload.spec.toolCallId, 'call-a')
assert.strictEqual(payload.spec.options.length, 2)
assert.ok(pending.has('I-1'), 'resolver stored under interruptId')
// Resolve so the promise settles cleanly for the test runner.
pending.get('I-1').resolve({ outcome: 'cancelled' })
})
test('accepts canonical nested payload (form)', () => {
const pending = makePending()
const sender = makeSender()
const req = {
sessionId: 'S2',
interruptId: 'I-2',
payload: { kind: 'form', spec: { fields: [{ id: 'name', label: 'Name' }] } },
}
const p = normalizeInterruptRequest(req, pending, sender.fn)
assert.ok(typeof p.then === 'function')
const { payload } = sender.calls[0]
assert.strictEqual(payload.kind, 'form')
assert.deepStrictEqual(payload.spec.fields, [{ id: 'name', label: 'Name' }])
pending.get('I-2').resolve({ outcome: 'cancelled' })
})
test('rejects flat legacy shape (spec.kind without payload)', () => {
// Legacy draft shape. Bridge no longer emits this; fail-closed protects the
// shell from ambient garbage or a mistyped test bridge.
const pending = makePending()
const sender = makeSender()
const req = {
sessionId: 'S3',
interruptId: 'I-3',
spec: { kind: 'approval', toolCallId: 'x' },
}
const out = normalizeInterruptRequest(req, pending, sender.fn)
assert.deepStrictEqual(out, { outcome: 'cancelled' })
assert.strictEqual(sender.calls.length, 0, 'no dispatch when shape is unknown')
assert.strictEqual(pending.size, 0, 'no resolver registered')
})
test('rejects when payload has unknown kind', () => {
const pending = makePending()
const sender = makeSender()
const req = {
sessionId: 'S4',
interruptId: 'I-4',
payload: { kind: 'unknown-thing', spec: {} },
}
const out = normalizeInterruptRequest(req, pending, sender.fn)
assert.deepStrictEqual(out, { outcome: 'cancelled' })
assert.strictEqual(sender.calls.length, 0)
assert.strictEqual(pending.size, 0)
})
test('synthesizes an interruptId when the runtime omits one', () => {
const pending = makePending()
const sender = makeSender()
const req = {
sessionId: 'S5',
// interruptId absent — normalizer must synthesize `int-<uuid>` so the
// resolver map still has a stable key.
payload: { kind: 'approval', spec: { toolCallId: 'x', options: [] } },
}
const p = normalizeInterruptRequest(req, pending, sender.fn)
assert.ok(typeof p.then === 'function')
assert.strictEqual(sender.calls.length, 1)
const id = sender.calls[0].payload.interruptId
assert.match(id, /^int-/, 'synthesized id has the expected prefix')
assert.ok(pending.has(id))
pending.get(id).resolve({ outcome: 'cancelled' })
})
test('rejects when payload is missing or malformed', () => {
const pending = makePending()
const sender = makeSender()
for (const bad of [null, undefined, {}, { sessionId: 'x' }, { payload: null }, { payload: 'no' }]) {
const out = normalizeInterruptRequest(bad, pending, sender.fn)
assert.deepStrictEqual(out, { outcome: 'cancelled' }, `bad shape ${JSON.stringify(bad)} is cancelled`)
}
assert.strictEqual(sender.calls.length, 0)
})