Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
/**
* Unit tests for the reasoning-trace reducer: WS events in, human-readable
* thinking steps out. Pure function — no store, no React.
*/
import { describe, expect, it } from "vitest";
import {
finalizeThinkingSteps,
MAX_THINKING_STEPS,
reduceThinkingSteps,
replayTrace,
traceModel,
type ThinkingStep,
} from "@/lib/thinkingSteps";
const T0 = 1_000_000;
function run(
events: Array<[string, unknown, number?]>,
initial: ThinkingStep[] = [],
): ThinkingStep[] {
let steps = initial;
for (const [name, payload, ts] of events) {
steps = reduceThinkingSteps(steps, name, payload, ts ?? T0) ?? steps;
}
return steps;
}
describe("reduceThinkingSteps", () => {
it("ignores irrelevant events (returns null, not a new array)", () => {
expect(reduceThinkingSteps([], "SystemStateChanged", {}, T0)).toBeNull();
expect(reduceThinkingSteps([], "MessageSent", { role: "user" }, T0)).toBeNull();
});
it("opens a brain step with provider · model detail", () => {
const steps = run([
["BrainTurnStarted", { provider: "gemini", model: "gemini-3-flash" }],
]);
expect(steps).toHaveLength(1);
expect(steps[0]).toMatchObject({
kind: "brain",
labelKey: "thinking.step_brain",
detail: "gemini · gemini-3-flash",
status: "active",
});
});
it("closes the previous brain attempt when the fallback chain restarts", () => {
const steps = run([
["BrainTurnStarted", { provider: "openai" }, T0],
["BrainTurnStarted", { provider: "claude-api" }, T0 + 500],
]);
expect(steps).toHaveLength(2);
expect(steps[0].status).toBe("done");
expect(steps[0].durationMs).toBe(500);
expect(steps[1].status).toBe("active");
});
it("completes the brain step on BrainTurnCompleted with wall-clock duration", () => {
const steps = run([
["BrainTurnStarted", { provider: "gemini" }, T0],
["BrainTurnCompleted", { tokens_out: 42 }, T0 + 1200],
]);
expect(steps[0].status).toBe("done");
expect(steps[0].durationMs).toBe(1200);
});
it("pairs ToolCallCompleted with the most recent active tool step", () => {
const steps = run([
["ToolCallStarted", { tool_name: "wiki-recall" }],
["ToolCallCompleted", { success: true, duration_ms: 340 }],
]);
expect(steps).toHaveLength(1);
expect(steps[0]).toMatchObject({
kind: "tool",
detail: "wiki-recall",
status: "done",
durationMs: 340,
});
});
it("marks a failed tool call as error", () => {
const steps = run([
["ToolCallStarted", { tool_name: "open-app" }],
["ToolCallCompleted", { success: false, duration_ms: 90, error: "boom" }],
]);
expect(steps[0].status).toBe("error");
});
it("maps the ToolExecutor's ActionProposed/ActionExecuted pair by tool name", () => {
const steps = run([
["ActionProposed", { tool_name: "wiki-recall", risk_tier: "safe" }],
["ActionProposed", { tool_name: "open-app", risk_tier: "monitor" }],
["ActionExecuted", { tool_name: "wiki-recall", success: true, duration_ms: 210 }],
]);
expect(steps).toHaveLength(2);
expect(steps[0]).toMatchObject({ detail: "wiki-recall", status: "done", durationMs: 210 });
expect(steps[1]).toMatchObject({ detail: "open-app", status: "active" });
});
it("dedupes when both event families fire for the same call", () => {
const steps = run([
["ToolCallStarted", { tool_name: "wiki-recall" }],
["ActionProposed", { tool_name: "wiki-recall" }],
]);
expect(steps).toHaveLength(1);
});
it("surfaces an ActionExecuted without a Proposed as a finished row", () => {
const steps = run([
["ActionExecuted", { tool_name: "open-app", success: false, duration_ms: 5000 }],
]);
expect(steps).toHaveLength(1);
expect(steps[0]).toMatchObject({ detail: "open-app", status: "error" });
});
it("marks a denied tool call as error", () => {
const steps = run([
["ActionProposed", { tool_name: "delete-files" }],
["ActionDenied", { tool_name: "delete-files", reason: "blacklist" }],
]);
expect(steps[0].status).toBe("error");
});
it("upserts computer-use phases into ONE row instead of appending", () => {
const steps = run([
["ObservationCaptured", { window_title: "Chrome" }],
["CUStepProfiled", { phase: "plan", step_idx: 0 }],
["ActionPlanned", { action_kind: "click", target_hint: "{Button}" }],
["CUStepProfiled", { phase: "verify", step_idx: 1 }],
]);
const cu = steps.filter((s) => s.kind === "computer");
expect(cu).toHaveLength(1);
expect(cu[0].labelKey).toBe("thinking.step_cu_verify");
expect(cu[0].status).toBe("active");
});
it("pairs Jarvis-Agent worker start/completion and converts duration_s to ms", () => {
const steps = run([
["JarvisAgentTaskStarted", { utterance: "build a flask app" }],
["JarvisAgentTaskCompleted", { success: true, duration_s: 44.8 }],
]);
expect(steps).toHaveLength(1);
expect(steps[0]).toMatchObject({
kind: "worker",
status: "done",
durationMs: 44_800,
});
});
it("adds progress as a note and a preamble as a thought, skips other kinds", () => {
const steps = run([
["AnnouncementRequested", { kind: "progress", text: "Halfway there" }],
["AnnouncementRequested", { kind: "preamble", text: "I'll check the computers you set up." }],
["AnnouncementRequested", { kind: "completion", text: "Done" }],
]);
expect(steps).toHaveLength(2);
expect(steps[0]).toMatchObject({ kind: "note", detail: "Halfway there", status: "done" });
expect(steps[1]).toMatchObject({ kind: "thought", detail: "I'll check the computers you set up.", status: "done" });
});
it("keeps a refused call as a denied step, even with no proposal before it", () => {
const proposed = run([
["ActionProposed", { tool_name: "run-app-action" }],
["ActionDenied", { tool_name: "run-app-action", reason: "blacklist: <tool-declared-block>" }],
]);
expect(proposed).toHaveLength(1);
expect(proposed[0]).toMatchObject({ kind: "tool", status: "error", denied: true, error: "blacklist: <tool-declared-block>" });
const guarded = run([["ActionDenied", { tool_name: "run-app-action", reason: "Plan mode permits reads only" }]]);
expect(guarded).toHaveLength(1);
expect(guarded[0]).toMatchObject({ kind: "tool", detail: "run-app-action", status: "error", denied: true });
});
it("caps the list and evicts finished steps before active ones", () => {
let steps: ThinkingStep[] = [];
for (let i = 0; i < MAX_THINKING_STEPS + 5; i++) {
steps = run(
[
["ToolCallStarted", { tool_name: `tool-${i}` }],
["ToolCallCompleted", { success: true, duration_ms: 1 }],
],
steps,
);
}
steps = run([["ToolCallStarted", { tool_name: "still-running" }]], steps);
expect(steps.length).toBeLessThanOrEqual(MAX_THINKING_STEPS);
expect(steps.some((s) => s.detail === "still-running")).toBe(true);
});
});
describe("finalizeThinkingSteps", () => {
it("closes active steps with a computed duration and keeps finished ones", () => {
const steps = run([
["ToolCallStarted", { tool_name: "a" }, T0],
["ToolCallCompleted", { success: true, duration_ms: 10 }, T0 + 10],
["ToolCallStarted", { tool_name: "b" }, T0 + 20],
]);
const finalized = finalizeThinkingSteps(steps, T0 + 100);
expect(finalized[0]).toMatchObject({ status: "done", durationMs: 10 });
expect(finalized[1]).toMatchObject({ status: "done", durationMs: 80 });
});
});
describe("rationale, arguments and results", () => {
it("puts the model's rationale as a thought row in front of the tool row", () => {
const steps = run([
[
"ActionProposed",
{
tool_name: "wiki-recall",
args: { query: "Urlaub" },
rationale: "I'll look that up in the wiki.",
},
],
["ActionExecuted", { tool_name: "wiki-recall", success: true, duration_ms: 40, output_preview: "2 pages" }],
]);
expect(steps).toHaveLength(2);
expect(steps[0]).toMatchObject({
kind: "thought",
detail: "I'll look that up in the wiki.",
status: "done",
});
expect(steps[1]).toMatchObject({
kind: "tool",
detail: "wiki-recall",
args: { query: "Urlaub" },
result: "2 pages",
status: "done",
});
});
it("keeps the error text of a failed or denied call", () => {
const failed = run([
["ActionProposed", { tool_name: "open_app", args: { app: "Foo" } }],
["ActionExecuted", { tool_name: "open_app", success: false, error: "not installed" }],
]);
expect(failed[0]).toMatchObject({ status: "error", error: "not installed" });
const denied = run([
["ActionProposed", { tool_name: "run_shell" }],
["ActionDenied", { tool_name: "run_shell", reason: "blocked by policy" }],
]);
expect(denied[0]).toMatchObject({ status: "error", error: "blocked by policy" });
});
it("names the provider that actually answered on the brain row", () => {
const steps = run([
["BrainTurnStarted", { provider: "openai", model: "gpt-5" }],
["BrainTurnStarted", { provider: "anthropic", model: "claude" }],
["BrainTurnCompleted", { provider: "anthropic", model: "claude" }],
]);
expect(traceModel(steps)).toBe("anthropic · claude");
});
});
describe("replayTrace", () => {
it("rebuilds a stored trace through the same reducer", () => {
const snapshot = replayTrace({
started_ms: T0,
ended_ms: T0 + 3_000,
events: [
{ name: "ActionProposed", ts_ms: T0 + 100, payload: { tool_name: "search_web", args: { query: "x" } } },
{ name: "ActionExecuted", ts_ms: T0 + 900, payload: { tool_name: "search_web", success: true } },
{ name: "BrainTurnStarted", ts_ms: T0 + 1_000, payload: { provider: "p", model: "m" } },
{ name: "BrainTurnCompleted", ts_ms: T0 + 2_900, payload: { provider: "p", model: "m" } },
],
});
expect(snapshot).not.toBeNull();
expect(snapshot!.durationMs).toBe(3_000);
expect(snapshot!.model).toBe("p · m");
expect(snapshot!.steps.map((s) => s.kind)).toEqual(["tool", "brain"]);
expect(snapshot!.steps[0]).toMatchObject({ detail: "search_web", status: "done", durationMs: 800 });
expect(snapshot!.steps.every((s) => s.status !== "active")).toBe(true);
});
it("is null for nothing, and closes steps a stored turn never finished", () => {
expect(replayTrace(null)).toBeNull();
expect(replayTrace({ events: [] })).toBeNull();
expect(replayTrace({ events: [{ name: "MessageSent", ts_ms: 1, payload: {} }] })).toBeNull();
const open = replayTrace({
events: [{ name: "ActionProposed", ts_ms: T0, payload: { tool_name: "a" } }],
});
expect(open!.steps[0].status).toBe("done");
});
});