Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Jan 13, 2025
1 parent a0fd132 commit 6e7cf38
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 53 deletions.
14 changes: 3 additions & 11 deletions node/chat/chat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("tea/chat.spec.ts", () => {
expect(
await buffer.getLines({ start: 0, end: -1 }),
"initial render of chat works",
).toEqual(["Stopped (end_turn) [input: 0, output: 0]"] as Line[]);
).toEqual(Chat.LOGO.split("\n") as Line[]);

app.dispatch({
type: "add-message",
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("tea/chat.spec.ts", () => {
expect(
await buffer.getLines({ start: 0, end: -1 }),
"initial render of chat works",
).toEqual(["Stopped (end_turn) [input: 0, output: 0]"] as Line[]);
).toEqual(Chat.LOGO.split("\n") as Line[]);

app.dispatch({
type: "add-message",
Expand Down Expand Up @@ -172,10 +172,6 @@ describe("tea/chat.spec.ts", () => {
"Stopped (end_turn) [input: 0, output: 0]",
] as Line[]);

// expect(
// await extractMountTree(mountedApp.getMountedNode()),
// ).toMatchSnapshot();

app.dispatch({
type: "clear",
});
Expand All @@ -184,11 +180,7 @@ describe("tea/chat.spec.ts", () => {
expect(
await buffer.getLines({ start: 0, end: -1 }),
"finished render is as expected",
).toEqual(["Stopped (end_turn) [input: 0, output: 0]"] as Line[]);

// expect(
// await extractMountTree(mountedApp.getMountedNode()),
// ).toMatchSnapshot();
).toEqual(Chat.LOGO.split("\n") as Line[]);
});
});
});
77 changes: 38 additions & 39 deletions node/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,46 +545,45 @@ ${msg.error.stack}`,
model,
dispatch,
}) => {
return d`${
model.messages.length
? model.messages.map(
(m, idx) =>
d`${messageModel.view({
model: m,
toolManager: model.toolManager,
dispatch: (msg) => {
dispatch({ type: "message-msg", msg, idx });
},
})}\n`,
if (
model.messages.length == 0 &&
Object.keys(model.contextManager.files).length == 0
) {
return d`${LOGO}`;
}

return d`${model.messages.map(
(m, idx) =>
d`${messageModel.view({
model: m,
toolManager: model.toolManager,
dispatch: (msg) => {
dispatch({ type: "message-msg", msg, idx });
},
})}\n`,
)}${
model.conversation.state == "message-in-flight"
? d`Awaiting response ${
MESSAGE_ANIMATION[
Math.floor(
(new Date().getTime() - model.conversation.sendDate.getTime()) /
333,
) % MESSAGE_ANIMATION.length
]
}`
: withBindings(
d`Stopped (${model.conversation.stopReason}) [input: ${model.conversation.usage.inputTokens.toString()}, output: ${model.conversation.usage.outputTokens.toString()}${
model.conversation.usage.cacheHits !== undefined &&
model.conversation.usage.cacheMisses !== undefined
? d`, cache hits: ${model.conversation.usage.cacheHits.toString()}, cache misses: ${model.conversation.usage.cacheMisses.toString()}`
: ""
}]`,
{
"<CR>": () => dispatch({ type: "show-message-debug-info" }),
},
)
: LOGO
}${
model.messages.length
? model.conversation.state == "message-in-flight"
? d`Awaiting response ${
MESSAGE_ANIMATION[
Math.floor(
(new Date().getTime() -
model.conversation.sendDate.getTime()) /
333,
) % MESSAGE_ANIMATION.length
]
}`
: withBindings(
d`Stopped (${model.conversation.stopReason}) [input: ${model.conversation.usage.inputTokens.toString()}, output: ${model.conversation.usage.outputTokens.toString()}${
model.conversation.usage.cacheHits !== undefined &&
model.conversation.usage.cacheMisses !== undefined
? d`, cache hits: ${model.conversation.usage.cacheHits.toString()}, cache misses: ${model.conversation.usage.cacheMisses.toString()}`
: ""
}]`,
{
"<CR>": () => dispatch({ type: "show-message-debug-info" }),
},
)
: ""
}${
model.conversation.state == "stopped" &&
model.messages.length &&
!contextManagerModel.isContextEmpty(model.contextManager)
? d`\n${contextManagerModel.view({
model: model.contextManager,
Expand Down Expand Up @@ -701,12 +700,12 @@ ${msg.error.stack}`,
};
}

const LOGO = d`\
export const LOGO = `\
________
╱ ╲
╱ ╱
╱ ╱
╲__╱__╱__╱
`;
# magenta.nvim`;
5 changes: 2 additions & 3 deletions node/magenta.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { withDriver } from "./test/preamble";
import { pollUntil } from "./utils/async";
import type { Position0Indexed } from "./nvim/window";
import { LOGO } from "./chat/chat";

describe("node/magenta.spec.ts", () => {
it("clear command should work", async () => {
Expand All @@ -25,9 +26,7 @@ sup?
Stopped (end_turn) [input: 0, output: 0]`);

await driver.clear();
await driver.assertDisplayBufferContent(
`Stopped (end_turn) [input: 0, output: 0]`,
);
await driver.assertDisplayBufferContent(LOGO);
await driver.inputMagentaText(`hello again`);
await driver.send();
await driver.mockAnthropic.respond({
Expand Down

0 comments on commit 6e7cf38

Please sign in to comment.