fix: coverage

This commit is contained in:
imccyu
2026-08-09 18:56:29 +08:00
parent 1b1e170c1f
commit 924cfcef95
12 changed files with 46 additions and 28 deletions

View File

@@ -7,7 +7,7 @@ import type {
export interface ChatNodeDataMap {}
/** Renderer kinds contributed by the currently installed Chat business modules. */
export type ChatNodeKind = keyof ChatNodeDataMap & string
export type ChatNodeKind = Extract<keyof ChatNodeDataMap, string>
/** Final Chat Node narrowed to one registered renderer kind and payload. */
export type ChatNode<Kind extends ChatNodeKind = ChatNodeKind> = {

View File

@@ -210,7 +210,7 @@ export interface TurnTailOwnerProps {
}
/** Hook constrained to business data published on the current Chat Node's Turn. */
export type UseChatNodeTurnData = <Key extends keyof ConversationTurnDataMap & string>(
export type UseChatNodeTurnData = <Key extends Extract<keyof ConversationTurnDataMap, string>>(
key: Key,
) => Readonly<ConversationTurnDataMap[Key]> | undefined

View File

@@ -78,13 +78,16 @@ class FixtureLocationIndex implements ChatLocationNodeIndex {
class FixtureTurnDataStore implements ConversationLocationDataStore<ConversationTurnDataMap> {
private readonly values = new Map<string, unknown>()
get<Key extends keyof ConversationTurnDataMap & string>(
get<Key extends Extract<keyof ConversationTurnDataMap, string>>(
key: Key,
): Readonly<ConversationTurnDataMap[Key]> | undefined {
return this.values.get(key) as Readonly<ConversationTurnDataMap[Key]> | undefined
}
set<Key extends keyof ConversationTurnDataMap & string>(key: Key, value: ConversationTurnDataMap[Key]): void {
set<Key extends Extract<keyof ConversationTurnDataMap, string>>(
key: Key,
value: ConversationTurnDataMap[Key],
): void {
this.values.set(key, value)
}
}

View File

@@ -181,12 +181,14 @@ function makeHarness(init?: Partial<ConversationSnapshot>) {
if (key !== 'conversation.chat.node') return opts?.fallback ?? null
const nodeOwner = owner as RoutedChatNodeOwner
const nodeKey = opts?.hookContext as string | undefined
const useTurnData = ((dataKey: string) => props.useSession((snapshot) => {
const location = nodeKey === undefined ? undefined : snapshot.chat.nodes.get(nodeKey)?.location
return location?.kind === 'turn' || location?.kind === 'step'
? location.turn.data.get(dataKey as never)
: undefined
})) as UseChatNodeTurnData
const useTurnData = ((dataKey: string) => {
return props.useSession((snapshot) => {
const location = nodeKey === undefined ? undefined : snapshot.chat.nodes.get(nodeKey)?.location
return location?.kind === 'turn' || location?.kind === 'step'
? location.turn.data.get(dataKey as never)
: undefined
})
}) as UseChatNodeTurnData
const nodeProps = <Kind extends ChatNode['kind']>(): ChatNodeViewProps<Kind> => (
{ ...props, ...nodeOwner, useTurnData } as unknown as ChatNodeViewProps<Kind>
)
@@ -226,7 +228,7 @@ function makeHarness(init?: Partial<ConversationSnapshot>) {
case 'unknown':
return <UnknownNodeView {...nodeProps<'unknown'>()} />
case 'tool-call': {
const block = (nodeOwner.node.data as { readonly root: ToolCallBlock }).root
const block = nodeOwner.node.data.root
const toolName = 'kind' in block ? block.call?.name ?? '' : block.name
const tool = {
callId: block.callId,
@@ -843,7 +845,7 @@ describe('ChatView', () => {
mounted()
return () => { unmounted() }
}, [])
const root = (node.data as { readonly root: ToolCallBlock }).root
const root = node.data.root
return (
<div data-testid="stateful-tool" data-state={'kind' in root ? 'settled' : 'running'}>
{root.callId}