ReMe/reme_studio/desktop/tests/stream-presentation.test.ts
jinliyl 524b1b6908
feat(studio): unify the workbench and proactive runtime (#764)
* fix(proactive): simplify round files and restore failed summaries

* fix(proactive): validate document-relative Markdown links

* feat(proactive_agent): implement v2 daily record workflow with single-file decision

- Add ProactiveAgentStepV2 class to support single daily note decision and reminder
- Introduce RoundOutputs for v2 round file tracking, and keep RoundArtifacts for v1 summary backup
- Refactor AgentOutbox to support both v1 standalone reminder files and v2 daily reminder records
- Add proactive_record utilities to parse and validate v2 daily record frontmatter and metadata
- Enhance proactive_agent to prepare, read, and manage artifacts for both v1 and v2 flows
- Add configuration profile proactive_v2 to enable new workflow with backward compatibility
- Update proactive.yaml and reactive proactive_agent_step configuration comment for easy switching
- Provide extensive schema validation for v2 reminders ensuring priority and message consistency
- Document v2 workflow and usage in English and Chinese runtime docs
- Add unit tests for v2 step verifying single file output and proper decision handling

* refactor(agent/runtime): replace ReminderRef with string keys and simplify reminder handling

- Remove ReminderRef model and switch to using workspace-relative string keys for reminders
- Simplify AgentOutbox to read, write, and manage reminders keyed by strings
- Change file locking and version checking to protect concurrent edits on daily record files
- Replace legacy and v2 reminder file handling with unified ReminderFiles storage
- Adjust ChatNotifications to operate with the new key scheme and update pending/read sets
- Refactor RoundOutputs to RoundRecord for safer round record tracking and rollback
- Remove unused ProactiveRunResult and related references from imports and exports
- Update InboxWakeRequest, AgentReminder, and related models for consistent ID and path validation
- Adjust proactive agent runtime and local runtime to check reminder versions before commit
- Correct language and docs to describe reminders as daily records instead of separate files
- Clean up roles of inbox and outbox for reminder ownership, delivery, and acknowledgments

* fix(proactive): serialize round commits and align desktop reminders

* refactor(proactive): unify task triggers in Proactive Runtime

* fix(proactive): bound reminder payloads and simplify receipts

* refactor(studio): share workbench and simplify proactive delivery

* fix(studio): update and centralize build dependencies

* fix(proactive): guard draft repair and verify Studio deployments

* chore(docs): update source-map-js

* feat(release): support publishing selected artifacts from a tag

* chore(studio): remove the public playground

* refactor: simplify reminders and release workflows

* fix: preserve proactive records and align release provenance

* test(proactive): remove brittle prompt and preset assertions

* fix(proactive): register reminders after input acknowledgement

* feat(notebook): list projects across todos and ideas

* feat(studio): connect mobile apps to configurable ReMe services

* fix(proactive): reserve registered reminder paths

* fix(studio): request Android local network access

* fix(proactive): reserve reminder paths referenced by receipts
2026-11-23 17:19:21 +08:00

133 lines
4.8 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
DesktopUpdates,
mergeState,
STREAM_RENDER_MS,
} from "../src/renderer/state.ts";
import type { StudioState, DisplayMessage } from "../../client/src/protocol.ts";
const message = (text: string, completed = false): DisplayMessage => ({
id: "reply",
turnId: "turn",
role: "assistant",
source: "chat",
content: text,
items: [
{ id: "intro", type: "text", text: "Checking", status: "completed" },
{
id: "answer",
type: "text",
text,
status: completed ? "completed" : "running",
},
],
completed,
streaming: !completed,
status: null,
});
const state = (messages = [message("First")]): StudioState =>
({
revision: 0,
sessionId: "session",
selectedAgentName: "Remy",
messages,
pending: null,
}) as StudioState;
test("IPC replacements retain unchanged messages and timeline items, including after history insertion", () => {
const history = { ...message("Saved", true), id: "saved", turnId: "saved" };
const initial = state([history, message("First")]);
const next = mergeState(initial, {
revision: 1,
messages: structuredClone([history, message("First second")]),
});
assert.equal(next.messages[0], initial.messages[0]);
assert.notEqual(next.messages[1], initial.messages[1]);
assert.equal(next.messages[1].items![0], initial.messages[1].items![0]);
const replay = mergeState(next, {
revision: 2,
messages: structuredClone(next.messages),
});
assert.equal(replay.messages, next.messages);
const prepended = mergeState(replay, {
revision: 3,
messages: [
{ ...history, id: "earlier", turnId: "earlier" },
...structuredClone(replay.messages),
],
});
assert.equal(prepended.messages[1], history);
assert.equal(prepended.messages[2], next.messages[1]);
assert.equal(mergeState(prepended, { revision: 2, messages: [] }), prepended);
});
test("burst deltas publish the latest complete snapshot on a timer without needing animation frames", (t) => {
t.mock.timers.enable({ apis: ["setTimeout"] });
const published: StudioState[] = [];
const updates = new DesktopUpdates(state(), (value) => published.push(value));
updates.push({ revision: 1, messages: [message("First second")] });
updates.push({ revision: 2, messages: [message("First second third")] });
assert.equal(published.length, 0);
t.mock.timers.tick(STREAM_RENDER_MS);
assert.equal(published.length, 1);
assert.equal(published[0].revision, 2);
assert.equal(published[0].messages[0].content, "First second third");
updates.push({ revision: 3, messages: [message("Last token")] });
updates.flush();
assert.equal(published.at(-1)!.messages[0].content, "Last token");
t.mock.timers.tick(STREAM_RENDER_MS);
assert.equal(published.length, 2);
});
test("tools and final snapshots flush queued prose in order and never leave delayed terminal updates", (t) => {
t.mock.timers.enable({ apis: ["setTimeout"] });
const published: StudioState[] = [];
const updates = new DesktopUpdates(state(), (value) => published.push(value));
updates.push({ revision: 1, messages: [message("Before tool")] });
const toolMessage = message("Before tool");
toolMessage.items!.push({
id: "read",
type: "tool",
name: "read",
input: "file.md",
output: "",
status: "running",
actions: [],
});
updates.push({ revision: 2, messages: [toolMessage] });
assert.equal(published.length, 1);
assert.deepEqual(
published[0].messages[0].items!.map((item) => item.id),
["intro", "answer", "read"],
);
updates.push({ revision: 3, messages: [message("Corrected final", true)] });
assert.equal(published.length, 2);
assert.equal(published[1].messages[0].content, "Corrected final");
assert.equal(published[1].messages[0].streaming, false);
t.mock.timers.tick(STREAM_RENDER_MS * 2);
assert.equal(published.length, 2);
});
test("context changes, connection failures and disposal cannot publish a queued old view", (t) => {
t.mock.timers.enable({ apis: ["setTimeout"] });
const published: StudioState[] = [];
const updates = new DesktopUpdates(state(), (value) => published.push(value));
updates.push({ revision: 1, messages: [message("Queued")] });
updates.push({
revision: 2,
selectedAgentName: "monitor",
sessionId: "other",
messages: [message("Other")],
});
assert.equal(published[0].selectedAgentName, "monitor");
updates.push({ revision: 3, messages: [message("Other delta")] });
updates.push({ revision: 4, connection: "reconnecting" });
assert.equal(published[1].messages[0].content, "Other delta");
assert.equal(published[1].connection, "reconnecting");
updates.push({ revision: 5, messages: [message("Disposed")] });
updates.close();
t.mock.timers.tick(STREAM_RENDER_MS * 2);
updates.flush();
assert.equal(published.length, 2);
});