Files
oh-my-pi/packages/coding-agent/test/status-line-model.test.ts
T
can1357 2f54e760c1 feat(coding-agent): added async compaction and in-place handoff
- Added compaction.asyncEnabled (Async Compaction, default on): when
  context enters the pre-threshold band [threshold - lead, threshold)
  with lead = clamp(threshold * 0.125, 8192, 32000), maintenance
  speculatively summarizes in the background off a branch snapshot
  (first configured LLM-backed method: remote, handoff, or soft) using
  a side session id isolated from the live turn. Crossing the threshold
  splices the armed result in instantly instead of blocking on a
  summarization round-trip. Armed results are invalidated by branch
  changes, reset boundaries, model switches that strand provider-native
  replay payloads, and context growth past keepRecentTokens (which
  re-speculates); extensions registering session_before_compact keep
  exact blocking semantics (speculation disabled).
- Reworked handoff to commit in place: /handoff and the auto handoff
  method now write the generated document as a regular compaction entry
  on the current session (summary = document + <files> tag, cut from
  prepareCompaction) instead of starting a new session. SessionHandoff
  shrank to a document generator; session_before_switch/session_switch
  no longer fire with reason "handoff"; mid-turn maintenance no longer
  suppresses the handoff preference; overflow recovery can apply an
  armed handoff result.
- Extracted the shared auto-compaction commit tail
  (#commitAutoCompactionResult / #commitCompactionEntry) used by the
  blocking production path, the armed speculative apply, manual
  compaction, and manual handoff.
- Status line pulses the auto-compact icon while a speculation runs and
  holds it in accent once a result is armed.
- Exported remotePreserveReusable from pi-agent-core/compaction for
  apply-time validation of speculative remote results.
2026-08-20 03:46:34 +02:00

129 lines
4.2 KiB
TypeScript

import { beforeAll, describe, expect, it } from "bun:test";
import { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
import type { SegmentContext } from "@oh-my-pi/pi-coding-agent/modes/components/status-line/segments";
import { renderSegment } from "@oh-my-pi/pi-coding-agent/modes/components/status-line/segments";
import { initTheme, theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
beforeAll(async () => {
await initTheme();
});
function createModelContext(advisorActive: boolean): SegmentContext {
return {
session: {
state: { model: { id: "test-model", name: "Test Model" } },
isFastModeActive: () => false,
isAutoThinking: false,
autoResolvedThinkingLevel: () => undefined,
isAdvisorActive: () => advisorActive,
getAdvisorStatusOverview: () => ({
configured: advisorActive,
advisors: advisorActive ? [{ name: "default", status: "running" }] : [],
}),
} as unknown as SegmentContext["session"],
width: 120,
compactThinkingLevel: false,
options: {},
planMode: null,
loopMode: null,
prewalk: null,
goalMode: null,
vibeMode: null,
collab: null,
usageStats: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
orchestrationInput: 0,
orchestrationOutput: 0,
orchestrationCacheRead: 0,
premiumRequests: 0,
cost: 0,
tokensPerSecond: null,
},
contextPercent: 0,
contextTokens: 0,
contextWindow: 0,
autoCompactEnabled: false,
compactionSpeculation: "idle",
speculationBlinkOn: true,
subagentCount: 0,
activeMs: 0,
activeRepo: null,
worktree: null,
git: { branch: null, status: null, pr: null },
usage: null,
};
}
describe("status line model segment advisor badge", () => {
it("appends a success-colored ++ badge when all advisors run", () => {
const rendered = renderSegment("model", createModelContext(true));
expect(rendered.content).toContain("Test Model");
expect(rendered.content).toContain(theme.fg("success", "++"));
});
it("colors the badge by the worst roster status", () => {
const ctx = createModelContext(true);
ctx.session.getAdvisorStatusOverview = () => ({
configured: true,
advisors: [
{ name: "a", status: "running" },
{ name: "b", status: "quota_exhausted" },
],
});
expect(renderSegment("model", ctx).content).toContain(theme.fg("warning", "++"));
ctx.session.getAdvisorStatusOverview = () => ({
configured: true,
advisors: [
{ name: "a", status: "error" },
{ name: "b", status: "quota_exhausted" },
],
});
expect(renderSegment("model", ctx).content).toContain(theme.fg("error", "++"));
});
it("omits the badge when the advisor is inactive", () => {
const rendered = renderSegment("model", createModelContext(false));
expect(rendered.content).toContain("Test Model");
expect(rendered.content).not.toContain("++");
});
});
describe("status line model segment compact thinking level", () => {
function createThinkingContext(compactThinkingLevel: boolean): SegmentContext {
return {
...createModelContext(false),
compactThinkingLevel,
session: {
state: {
model: { id: "test-model", name: "Test Model", thinking: true },
thinkingLevel: ThinkingLevel.High,
},
isFastModeActive: () => false,
isAutoThinking: false,
autoResolvedThinkingLevel: () => undefined,
isAdvisorActive: () => false,
getAdvisorStatusOverview: () => ({ configured: false, advisors: [] }),
} as unknown as SegmentContext["session"],
};
}
it("trails the level as a ` · <level>` suffix when compact mode is off", () => {
const display = theme.thinking.high;
const modelPrefix = theme.icon.model ? `${theme.icon.model} ` : "";
const rendered = renderSegment("model", createThinkingContext(false));
expect(Bun.stripANSI(rendered.content)).toBe(`${modelPrefix}Test Model${theme.sep.dot}${display}`);
});
it("swaps the model icon for the level glyph and drops the suffix when compact", () => {
const display = theme.thinking.high;
const glyph = display.includes(" ") ? display.slice(0, display.indexOf(" ")) : display;
const rendered = renderSegment("model", createThinkingContext(true));
expect(Bun.stripANSI(rendered.content)).toBe(`${glyph} Test Model`);
expect(Bun.stripANSI(rendered.content)).not.toContain(theme.sep.dot);
});
});