refactor(channels): dedupe transport and gateway test scaffolds

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:15 +00:00
parent f717a13039
commit 93ca0ed54f
95 changed files with 4068 additions and 5221 deletions

View File

@@ -13,6 +13,17 @@ const mockTheme: SearchableSelectListTheme = {
matchHighlight: (t) => `*${t}*`,
};
const ansiHighlightTheme: SearchableSelectListTheme = {
selectedPrefix: (t) => t,
selectedText: (t) => t,
description: (t) => t,
scrollInfo: (t) => t,
noMatch: (t) => t,
searchPrompt: (t) => t,
searchInput: (t) => t,
matchHighlight: (t) => `\u001b[31m${t}\u001b[0m`,
};
const testItems = [
{
value: "anthropic/claude-3-opus",
@@ -74,22 +85,12 @@ describe("SearchableSelectList", () => {
});
it("keeps ANSI-highlighted description rows within terminal width", () => {
const ansiTheme: SearchableSelectListTheme = {
selectedPrefix: (t) => t,
selectedText: (t) => t,
description: (t) => t,
scrollInfo: (t) => t,
noMatch: (t) => t,
searchPrompt: (t) => t,
searchInput: (t) => t,
matchHighlight: (t) => `\u001b[31m${t}\u001b[0m`,
};
const label = `provider/${"x".repeat(80)}`;
const items = [
{ value: label, label, description: "Some description text that should not overflow" },
{ value: "other", label: "other", description: "Other description" },
];
const list = new SearchableSelectList(items, 5, ansiTheme);
const list = new SearchableSelectList(items, 5, ansiHighlightTheme);
list.setSelectedIndex(1); // make first row non-selected so description styling is applied
for (const ch of "provider") {
@@ -119,18 +120,8 @@ describe("SearchableSelectList", () => {
});
it("does not corrupt ANSI sequences when highlighting multiple tokens", () => {
const ansiTheme: SearchableSelectListTheme = {
selectedPrefix: (t) => t,
selectedText: (t) => t,
description: (t) => t,
scrollInfo: (t) => t,
noMatch: (t) => t,
searchPrompt: (t) => t,
searchInput: (t) => t,
matchHighlight: (t) => `\u001b[31m${t}\u001b[0m`,
};
const items = [{ value: "gpt-model", label: "gpt-model" }];
const list = new SearchableSelectList(items, 5, ansiTheme);
const list = new SearchableSelectList(items, 5, ansiHighlightTheme);
for (const ch of "gpt m") {
list.handleInput(ch);

View File

@@ -364,7 +364,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
expect(loadHistory).toHaveBeenCalledTimes(1);
});
it("does not reload history or clear active run when another run final arrives mid-stream", () => {
function createConcurrentRunHarness(localContent = "partial") {
const state = makeState({ activeChatRunId: "run-active" });
const { chatLog, tui, setActivityStatus, loadHistory, isLocalRunId, forgetLocalRunId } =
makeContext(state);
@@ -382,9 +382,16 @@ describe("tui-event-handlers: handleAgentEvent", () => {
runId: "run-active",
sessionKey: state.currentSessionKey,
state: "delta",
message: { content: "partial" },
message: { content: localContent },
});
return { state, chatLog, setActivityStatus, loadHistory, handleChatEvent };
}
it("does not reload history or clear active run when another run final arrives mid-stream", () => {
const { state, chatLog, setActivityStatus, loadHistory, handleChatEvent } =
createConcurrentRunHarness("partial");
loadHistory.mockClear();
setActivityStatus.mockClear();
@@ -410,25 +417,8 @@ describe("tui-event-handlers: handleAgentEvent", () => {
});
it("suppresses non-local empty final placeholders during concurrent runs", () => {
const state = makeState({ activeChatRunId: "run-active" });
const { chatLog, tui, setActivityStatus, loadHistory, isLocalRunId, forgetLocalRunId } =
makeContext(state);
const { handleChatEvent } = createEventHandlers({
chatLog,
tui,
state,
setActivityStatus,
loadHistory,
isLocalRunId,
forgetLocalRunId,
});
handleChatEvent({
runId: "run-active",
sessionKey: state.currentSessionKey,
state: "delta",
message: { content: "local stream" },
});
const { state, chatLog, loadHistory, handleChatEvent } =
createConcurrentRunHarness("local stream");
loadHistory.mockClear();
chatLog.finalizeAssistant.mockClear();