import { afterEach, describe, expect, it } from "vitest"; import { createTestSession, type TestSession } from "../../../test/harness"; import contextSizeExtension, { __test } from "../index"; describe("context-size pi-test-harness", () => { let t: TestSession | undefined; afterEach(() => { t?.dispose(); t = undefined; }); it("loads in real Pi extension runtime", async () => { t = await createTestSession({ extensionFactories: [contextSizeExtension] }); expect(t.session.extensionRunner.extensions).toHaveLength(1); }); it("renders the tui view as a bar alone", () => { expect(__test.renderThinBar(26)).toBe("━━━───────"); expect(__test.renderThinBar(null)).toBe("──────────"); }); it("spells out the non-tui label with human-readable headroom", () => { expect( __test.buildPlainLabel({ tokens: 262_000, contextWindow: 1_000_000, percent: 26.2, }), ).toBe("context 26% used, 738k left"); expect( __test.buildPlainLabel({ tokens: null, contextWindow: 1_000_000, percent: null, }), ).toBe("context unknown"); }); it("scales token counts through k and M", () => { expect(__test.formatTokens(940)).toBe("940"); expect(__test.formatTokens(1_180)).toBe("1.2k"); expect(__test.formatTokens(262_000)).toBe("262k"); expect(__test.formatTokens(1_618_000)).toBe("1.6M"); expect(__test.formatTokens(121_527_000)).toBe("122M"); }); });