feat: initial Lam Agent extension (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { errorMessage, formatRelativeTime, titleFromPrompt, truncate } from "../lib/utils";
|
||||
|
||||
describe("truncate", () => {
|
||||
it("collapses whitespace so list rows never wrap unexpectedly", () => {
|
||||
expect(truncate("hello\n\n world", 40)).toBe("hello world");
|
||||
});
|
||||
|
||||
it("leaves short text alone", () => {
|
||||
expect(truncate("short", 40)).toBe("short");
|
||||
});
|
||||
|
||||
it("clips with an ellipsis at the requested width", () => {
|
||||
const result = truncate("a".repeat(100), 10);
|
||||
expect(result).toBe(`${"a".repeat(9)}…`);
|
||||
expect(result).toHaveLength(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatRelativeTime", () => {
|
||||
const now = 1_700_000_000_000;
|
||||
|
||||
it("reports very recent timestamps as just now", () => {
|
||||
expect(formatRelativeTime(now - 5_000, now)).toBe("just now");
|
||||
});
|
||||
|
||||
it("reports minutes and hours", () => {
|
||||
expect(formatRelativeTime(now - 12 * 60_000, now)).toBe("12m ago");
|
||||
expect(formatRelativeTime(now - 3 * 3_600_000, now)).toBe("3h ago");
|
||||
});
|
||||
|
||||
it("reports days within the last week", () => {
|
||||
expect(formatRelativeTime(now - 2 * 86_400_000, now)).toBe("2d ago");
|
||||
});
|
||||
|
||||
it("treats clock skew as just now rather than a negative age", () => {
|
||||
expect(formatRelativeTime(now + 60_000, now)).toBe("just now");
|
||||
});
|
||||
});
|
||||
|
||||
describe("titleFromPrompt", () => {
|
||||
it("uses the first non-empty line, stripped of markdown decoration", () => {
|
||||
expect(titleFromPrompt("\n\n## How do I deploy?\nmore text", 60)).toBe("How do I deploy?");
|
||||
});
|
||||
|
||||
it("falls back to a placeholder for an empty prompt", () => {
|
||||
expect(titleFromPrompt(" \n ", 60)).toBe("New chat");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errorMessage", () => {
|
||||
it("unwraps Error instances", () => {
|
||||
expect(errorMessage(new Error("boom"))).toBe("boom");
|
||||
});
|
||||
|
||||
it("passes strings through", () => {
|
||||
expect(errorMessage("plain failure")).toBe("plain failure");
|
||||
});
|
||||
|
||||
it("survives values that cannot be serialised", () => {
|
||||
const circular: Record<string, unknown> = {};
|
||||
circular.self = circular;
|
||||
expect(typeof errorMessage(circular)).toBe("string");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user