Files
shiro-neko/test/helpers.ts
T
asepharyana 76043aeb38 Implement background command support for bash tool
- Added `background` option to `bash` tool to allow long-lived commands to run without blocking the turn.
- Introduced `bash_status` tool to check the status and output of background commands.
- Added `bash_stop` tool to explicitly stop running background commands.
- Updated command parsing to handle `/bash` commands for listing, stopping individual, and stopping all background commands.
- Enhanced session management to reap stale background commands on agent shutdown.
- Updated UI to reflect background command status and allow user interruption via ctrl-c.
- Added tests for background command functionality and command parsing.
- Documented new features and usage in background-bash.md.
2026-09-11 18:52:50 +07:00

69 lines
2.4 KiB
TypeScript

import type { LanguageModelV4Usage } from '@ai-sdk/provider';
import type { AppHooks } from '../src/ui/App';
/**
* A `usage` chunk for `simulateReadableStream`, typed so the cast goes away.
*
* The same object was copied verbatim into 17 test files with `as any`, one per
* stream finish. This builds the real `LanguageModelV4Usage` shape with the
* numbers a test cares about and the cache fields zeroed.
*/
export function usageOf(input: number, output = 1): LanguageModelV4Usage {
return {
inputTokens: { total: input, noCache: input, cacheRead: 0, cacheWrite: 0 },
outputTokens: { total: output, text: output, reasoning: 0 },
};
}
/** Default AppHooks for UI tests; override only what a test cares about. */
export function testHooks(over: Partial<AppHooks> = {}): AppHooks {
return {
sessionId: 'test1234',
config: () => ({ provider: 'openai', model: 'gpt-5' }),
switchModel: (id) => `model is now ${id}`,
switchAgent: (name) => `agent is now ${name}`,
switchThinking: (level) => `thinking is now ${level}`,
agentName: () => 'default',
thinkingLevel: () => 'medium',
applyProvider: async () => 'configured',
listModels: async () => ({ models: [] }),
listSessions: async () => 'no saved sessions',
searchSessions: async () => '',
forkSession: async () => 'forked',
listSkills: () => 'no skills loaded',
listPlugins: () => 'no plugins active',
listMemory: async () => 'nothing remembered yet',
summarizeMemory: async () => 'nothing to compact',
resumeSession: async () => 'resumed',
saveSession: async () => 'saved',
instructionFiles: () => [],
listPaths: async () => [],
fileChangeSeq: () => 0,
registry: {
list: async () => [],
installed: async () => [],
stage: async () => {
throw new Error('no registry in tests unless a test provides one');
},
install: async () => 'installed',
remove: async () => 'removed',
},
mcp: {
names: () => [],
list: () => 'no mcp servers configured',
add: async (result) => `added ${result.name}`,
remove: async (name) => `removed ${name}`,
},
initPrompt: 'write AGENTS.md',
scaffoldWorkflow: () => [],
backgroundCommands: {
list: () => 'no background commands',
stop: async (handle) => `stopped ${handle}`,
stopAll: async () => 'stopped all',
},
history: [],
recordPrompt: () => {},
...over,
};
}