evOo-local/packages/adapters/src/user-progress.test.ts
cynarAI ca869561ac
Voice-first streaming, non-blocking follow-ups and chat UX (#205)
* media: check ffmpeg filter support before subtitle operations

* sandbox: handle synchronous spawn errors safely in desktop sandbox

* Voice-first streaming, non-blocking follow-ups, quiet routines and chat UX

Why: questions blocked the chat, follow-up messages had no acknowledgement, message actions sat beside the bubble, and voice turn-taking added latency.

What: waiting runs accept steering messages and the bot marks each claimed follow-up as seen; unclaimed follow-ups show as queued. Reaction, copy and reply controls sit under each message. Streaming voice (VAD endpointing, barge-in that stops the run, clause-based TTS), an optimistic input queue, procedural earcons and delta-based quiet routines were added. Onboarding can be skipped straight to the main conversation. Dual-surface layout and project pickers are included. Status colors use semantic tokens.

Tested: unit suites for core, adapters, api and web pass, typecheck and Biome are clean. Browser end-to-end tests were not run locally.

* Update translation catalogs

Re-extracted catalogs for the new and moved strings; the catalog sync test passes.

* Add project plan and test readiness notes

Notes from the milestone work: feature inventory, test infrastructure and test readiness. No code changes.

* fix(ci): align scale guards, space deletion, computer toggle, and mobile expo deps

* fix(ci): restore space deletion guard, browser toggle, and run-steps contracts

* fix(ci): restore model resolution errors, group stage, and onboarding flow

* fix(ci): restore in-app-browser close button, disable stop button while sending, and sync lingui catalogs

* fix(ci): address web e2e failures for bot-crud, choice cards, message quote, and voice onboarding

* test(web): wait for avatar and rig visibility in oo-avatar motion spec

* test(web): wait for persisted message IDs in message-hover-actions pagination spec

* Onboarding: always drop the local voice when the voice step is skipped

Skipping waited only for the latest voice load and disconnected only
when the client saw the connect succeed. An earlier or client-failed
connect could still persist the local credential, so a user who
skipped voice was left with one. Wait for every load and always
disconnect.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wy1md9QE1ayJbDCwJ4vAQs

* Shell: hide the optimistic copy once the transcript shows the send

A message sent while the bot works streamed into the transcript before
its send request resolved, so the same text showed twice until the
optimistic bubble was removed. Drop an optimistic message as soon as a
persisted user message with the same text appears.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wy1md9QE1ayJbDCwJ4vAQs

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 14:08:31 +02:00

113 lines
4.2 KiB
TypeScript

import type { MessageBlock } from "@rakazo/contracts";
import { isToolActivityBlock } from "@rakazo/core";
import { describe, expect, it } from "vitest";
import {
botMessageOutcomeFromMidTurn,
clampUserProgressMessage,
extractNarrationText,
finalBlocksAfterMidTurnProgress,
isProgressMessageTruncated,
isUserProgressClientNonce,
USER_PROGRESS_MESSAGE_MAX_LENGTH,
userProgressClientNonce,
} from "./user-progress.js";
describe("clampUserProgressMessage", () => {
it("trims and rejects empty text", () => {
expect(clampUserProgressMessage(" hello ")).toBe("hello");
expect(clampUserProgressMessage(" ")).toBe("");
});
it("clamps long progress beats", () => {
const clamped = clampUserProgressMessage("x".repeat(USER_PROGRESS_MESSAGE_MAX_LENGTH + 40));
expect(clamped).toHaveLength(USER_PROGRESS_MESSAGE_MAX_LENGTH);
expect(clamped.endsWith("…")).toBe(true);
});
});
describe("isProgressMessageTruncated", () => {
it("is false for text that fits", () => {
expect(isProgressMessageTruncated("short update")).toBe(false);
expect(isProgressMessageTruncated("x".repeat(USER_PROGRESS_MESSAGE_MAX_LENGTH))).toBe(false);
});
it("is true for text that would be cut off by clampUserProgressMessage", () => {
const long = "x".repeat(USER_PROGRESS_MESSAGE_MAX_LENGTH + 1);
expect(isProgressMessageTruncated(long)).toBe(true);
expect(clampUserProgressMessage(long).endsWith("…")).toBe(true);
});
});
describe("extractNarrationText", () => {
it("pulls text blocks and current text while keeping tool activity", () => {
const { text, remaining } = extractNarrationText(
[
{ kind: "text", text: "Checking calendars. " },
{ kind: "steps", steps: [{ label: "Web search", count: 1 }] },
{ kind: "text", text: "Found three options." },
],
" Still looking.",
);
expect(text).toBe("Checking calendars. Found three options. Still looking.");
expect(remaining).toEqual([{ kind: "steps", steps: [{ label: "Web search", count: 1 }] }]);
});
});
describe("finalBlocksAfterMidTurnProgress", () => {
it("drops a hollow final message that is only hidden tool activity", () => {
const steps: MessageBlock = { kind: "steps", steps: [{ label: "Shell", count: 2 }] };
expect(finalBlocksAfterMidTurnProgress([steps], true)).toEqual([]);
expect(finalBlocksAfterMidTurnProgress([steps], false)).toEqual([steps]);
});
it("keeps a final answer alongside tool activity", () => {
const blocks: MessageBlock[] = [
{ kind: "steps", steps: [{ label: "Web search", count: 1 }] },
{ kind: "text", text: "You are free Tuesday afternoon." },
];
expect(finalBlocksAfterMidTurnProgress(blocks, true)).toEqual(blocks);
expect(isToolActivityBlock(blocks[0]!)).toBe(true);
});
it("drops meaningless text stubs alongside tool activity when mid-turn was published", () => {
const blocks: MessageBlock[] = [
{ kind: "steps", steps: [{ label: "Shell", count: 1 }] },
{ kind: "text", text: "L" },
];
expect(finalBlocksAfterMidTurnProgress(blocks, true)).toEqual([]);
});
});
describe("botMessageOutcomeFromMidTurn", () => {
it("prefers the final reply as a result", () => {
expect(botMessageOutcomeFromMidTurn("All set.", ["Checking calendars…"])).toEqual({
text: "All set.",
intent: "result",
});
});
it("returns mid-turn progress as status when there is no final reply", () => {
expect(
botMessageOutcomeFromMidTurn("", ["Checking calendars…", "Found three free slots."]),
).toEqual({
text: "Checking calendars…\n\nFound three free slots.",
intent: "status",
});
});
it("returns null when nothing was posted", () => {
expect(botMessageOutcomeFromMidTurn(" ", [])).toBeNull();
});
});
describe("userProgressClientNonce", () => {
it("tags mid-turn progress messages for reconciler detection", () => {
const nonce = userProgressClientNonce("run-1", 0);
expect(nonce.startsWith("user-progress:run-1:0:")).toBe(true);
expect(isUserProgressClientNonce(nonce)).toBe(true);
expect(userProgressClientNonce("run-1", 0)).not.toBe(nonce);
expect(isUserProgressClientNonce(null)).toBe(false);
expect(isUserProgressClientNonce("other")).toBe(false);
});
});