From f4a876da46bfc6359f99553ebfdad4c4a00d7baf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 03:35:53 +0000 Subject: [PATCH 1/2] test: add comprehensive tests for summarizeToolInput Adds test coverage for `summarizeToolInput` covering: - Empty and invalid inputs - String truncations at limits - Specialized extraction for symbols, intervals, criteria, and limits - General fallback representation of JSON Objects Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com> --- tests/toolSummary.test.ts | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/toolSummary.test.ts diff --git a/tests/toolSummary.test.ts b/tests/toolSummary.test.ts new file mode 100644 index 0000000..2970f4d --- /dev/null +++ b/tests/toolSummary.test.ts @@ -0,0 +1,64 @@ +import { describe, it, expect } from "vitest"; +import { summarizeToolInput } from "../src/tui/lib/toolSummary"; + +describe("summarizeToolInput", () => { + it("returns empty string for undefined or empty input", () => { + expect(summarizeToolInput(undefined)).toBe(""); + expect(summarizeToolInput("")).toBe(""); + }); + + it("truncates invalid JSON or non-object JSON", () => { + expect(summarizeToolInput("just a string")).toBe("just a string"); + expect(summarizeToolInput("123")).toBe("123"); + expect(summarizeToolInput("true")).toBe("true"); + + const longString = "this is a very long string that should eventually be truncated because it exceeds the sixty character limit"; + expect(summarizeToolInput(longString)).toBe("this is a very long string that should eventually be trunca…"); + }); + + it("extracts single ticker/symbol", () => { + expect(summarizeToolInput(JSON.stringify({ ticker: "VND" }))).toBe("VND"); + expect(summarizeToolInput(JSON.stringify({ symbol: "SSI" }))).toBe("SSI"); + expect(summarizeToolInput(JSON.stringify({ tickers: "FPT" }))).toBe("FPT"); + expect(summarizeToolInput(JSON.stringify({ symbols: "HPG" }))).toBe("HPG"); + }); + + it("truncates array of tickers/symbols to max 3", () => { + expect(summarizeToolInput(JSON.stringify({ symbols: ["VND", "SSI", "FPT", "HPG"] }))).toBe("VND,SSI,FPT"); + expect(summarizeToolInput(JSON.stringify({ tickers: ["VND", "SSI"] }))).toBe("VND,SSI"); + }); + + it("extracts timeframe or interval", () => { + expect(summarizeToolInput(JSON.stringify({ interval: "1D" }))).toBe("1D"); + expect(summarizeToolInput(JSON.stringify({ ticker: "VND", timeframe: "1W" }))).toBe("VND 1W"); + }); + + it("extracts criterion and limit", () => { + expect(summarizeToolInput(JSON.stringify({ criterion: "volume", limit: 10 }))).toBe("volume n=10"); + }); + + it("combines multiple extracted fields", () => { + expect( + summarizeToolInput(JSON.stringify({ ticker: "VND", interval: "1D", criterion: "rsi", limit: 5 })) + ).toBe("VND 1D rsi n=5"); + }); + + it("falls back to first 3 keys for unhandled objects", () => { + expect( + summarizeToolInput(JSON.stringify({ foo: "bar", baz: 123, qux: true })) + ).toBe('foo="bar" baz=123 qux=true'); + expect( + summarizeToolInput(JSON.stringify({ a: 1, b: 2, c: 3, d: 4 })) + ).toBe("a=1 b=2 c=3"); + }); + + it("truncates fallback string if it exceeds 60 characters", () => { + const obj = { + veryLongKeyNameThatWillTakeUpSpace: "some equally long value that pushes it over the limit", + anotherKey: "value" + }; + expect(summarizeToolInput(JSON.stringify(obj))).toBe( + 'veryLongKeyNameThatWillTakeUpSpace="some equally long value…' + ); + }); +}); From b392a10b8b71b17096481bd679dfeca5273dbd29 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 03:41:05 +0000 Subject: [PATCH 2/2] fix: use correct esm import extension in tests Updates the import path in `tests/toolSummary.test.ts` to use `.js` extension to comply with ESM module resolution. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com> --- tests/toolSummary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/toolSummary.test.ts b/tests/toolSummary.test.ts index 2970f4d..d1d5f3c 100644 --- a/tests/toolSummary.test.ts +++ b/tests/toolSummary.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest"; -import { summarizeToolInput } from "../src/tui/lib/toolSummary"; +import { summarizeToolInput } from "../src/tui/lib/toolSummary.js"; describe("summarizeToolInput", () => { it("returns empty string for undefined or empty input", () => {