Files
deepseek-harness/packages/client/runtime/tests/context-provenance.spec.ts
creatixchu de96087923 feat(web): name context sources and mark steering in the transcript
Every logged non-user user/message collapsed into one identical
「上下文注入」 row, and mid-turn steering rendered in exactly the bubble a
turn-opening prompt uses, so the transcript could not say what had been
added or which message interrupted a running turn.

TranscriptAdapter and the history fold now attach a provenance view to
each context node, computed by contextProvenance() from the durable
source alone: a role (inject, or recall for a cross-session snapshot)
and a producer name read out of the log — instruction paths for
workspace-instructions, session titles for session-reference, the plugin
id for a plugin source, and the bare kind for any other. No client-side
table of producer names, so a renamed or newly mounted producer stays
identifiable without a client release and a foreign log projects like a
live one. ContextInjectionRow titles itself from the role and shows the
name beside it; MessageItem captions durable and pending steering
bubbles.

The caption reverses one clause of the no-interjection-chrome decision,
which removed it because the composer could not steer; composer steering
shipped afterwards without amending that note, so this change supplies
the product decision its reintroduction clause required and corrects the
stale facts left in it.

Fixes #1291
2026-08-04 17:44:18 +08:00

66 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Context provenance projection: the role and producer name a transcript row
* shows for one logged non-user message, read from the durable source alone.
*/
import { describe, expect, it } from 'vitest'
import { contextProvenance } from '../src/client/sessions/context-provenance.ts'
describe('contextProvenance', () => {
it('names a plugin producer by its logged plugin id', () => {
expect(contextProvenance({ kind: 'plugin', plugin: 'dsh-tool-skill' }))
.toEqual({ role: 'inject', label: 'dsh-tool-skill' })
})
it('names workspace instructions by the files they reconciled, deduplicated in first-seen order', () => {
expect(contextProvenance({
kind: 'workspace-instructions',
baseline: true,
changes: [
{ action: 'set', scope: '.AGENTS.md', path: 'AGENTS.md' },
{ action: 'set', scope: 'subAGENTS.md', path: 'sub/AGENTS.md' },
{ action: 'replace', scope: '.AGENTS.md', path: 'AGENTS.md' },
],
})).toEqual({ role: 'inject', label: 'AGENTS.md, sub/AGENTS.md' })
})
it('marks a cross-session snapshot as recall and names the sessions it read', () => {
expect(contextProvenance({
kind: 'session-reference',
version: 1,
references: [{ sessionId: 's1', label: 'Refactor the loader' }, { sessionId: 's2', label: 'Fix CI' }],
})).toEqual({ role: 'recall', label: 'Refactor the loader, Fix CI' })
})
it('identifies a producer this UI version does not know by its own durable kind', () => {
expect(contextProvenance({ kind: 'subagent-report', senderSessionId: 'child' }))
.toEqual({ role: 'inject', label: 'subagent-report' })
})
it('falls back to the source kind when the expected name field is unusable', () => {
// Every arm keeps the kind as its last readable name: a missing, empty, or
// wrongly-typed name field must not blank the row header.
expect(contextProvenance({ kind: 'plugin' }).label).toBe('plugin')
expect(contextProvenance({ kind: 'plugin', plugin: '' }).label).toBe('plugin')
expect(contextProvenance({ kind: 'plugin', plugin: 7 }).label).toBe('plugin')
expect(contextProvenance({ kind: 'workspace-instructions', changes: [] }).label)
.toBe('workspace-instructions')
expect(contextProvenance({ kind: 'workspace-instructions', changes: 'AGENTS.md' }).label)
.toBe('workspace-instructions')
expect(contextProvenance({ kind: 'workspace-instructions', changes: [{ action: 'set' }, null] }).label)
.toBe('workspace-instructions')
expect(contextProvenance({ kind: 'session-reference', references: [] }))
.toEqual({ role: 'recall', label: 'session-reference' })
})
it('degrades to an unnamed injection for a source that carries no readable kind', () => {
const unnamed = { role: 'inject', label: null }
expect(contextProvenance(null)).toEqual(unnamed)
expect(contextProvenance(undefined)).toEqual(unnamed)
expect(contextProvenance('plugin')).toEqual(unnamed)
expect(contextProvenance([{ kind: 'plugin' }])).toEqual(unnamed)
expect(contextProvenance({ plugin: 'dsh-tool-skill' })).toEqual(unnamed)
expect(contextProvenance({ kind: 42 })).toEqual(unnamed)
})
})