Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/app/src/components/session-context-usage.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, test } from "bun:test"
import * as fs from "node:fs/promises"
import * as path from "node:path"
import { contextUsageRingPercent, contextUsageTone } from "./session-context-usage-state"

const SOURCE_PATH = path.join(__dirname, "session-context-usage.tsx")
Comment thread
Astro-Han marked this conversation as resolved.
Resolved

describe("session context usage indicator helpers", () => {
test("uses normal tone for unknown usage and usage below warning", () => {
expect(contextUsageTone(null)).toBe("normal")
Expand All @@ -20,3 +24,12 @@ describe("session context usage indicator helpers", () => {
expect(contextUsageRingPercent(120)).toBe(100)
})
})

describe("SessionContextUsage render contract", () => {
test("does not pass volatile context accessors through non-keyed Show children", async () => {
const source = await fs.readFile(SOURCE_PATH, "utf8")

expect(source).not.toContain("<Show when={context()}>")
expect(source).not.toContain("<Show when={compactStatus()}>{(status)")
})
})
26 changes: 14 additions & 12 deletions packages/app/src/components/session-context-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,23 @@ export function SessionContextUsage(props: SessionContextUsageProps) {
limit: limit.toLocaleString(language.intl()),
})
}
const contextUsedLabel = createMemo(() => {
const ctx = context()
return ctx ? contextUsedText(ctx) : undefined
})

const tooltipValue = () => (
<div>
<Show when={context()}>
{(ctx) => (
<>
<div class="flex items-center gap-2">
<span>{language.t("context.usage.title")}</span>
</div>
<div class="flex items-center gap-2">
<span>{contextUsedText(ctx())}</span>
</div>
<Show when={compactStatus()}>{(status) => <div>{status()}</div>}</Show>
</>
)}
<Show when={contextUsedLabel()}>
<div class="flex items-center gap-2">
<span>{language.t("context.usage.title")}</span>
</div>
<div class="flex items-center gap-2">
<span>{contextUsedLabel()}</span>
</div>
<Show when={compactStatus()}>
<div>{compactStatus()}</div>
</Show>
</Show>
<div class="flex items-center gap-2">
<span>{cost()}</span>
Expand Down
Loading