ReMe/reme_studio/client/tests/browser-storage.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

87 lines
2.9 KiB
TypeScript

import assert from "node:assert/strict";
import test, { type TestContext } from "node:test";
import { BrowserStorage } from "../src/browser-host.ts";
function useLocalStorage(t: TestContext): Map<string, string> {
const original = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
const storage = new Map<string, string>();
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
},
});
t.after(() => {
if (original) Object.defineProperty(globalThis, "localStorage", original);
else Reflect.deleteProperty(globalThis, "localStorage");
});
return storage;
}
test("browser tabs save only their own settings and receipt changes", async (t) => {
const storage = useLocalStorage(t);
const endpoint = "http://127.0.0.1:2333";
const scope = "test-session";
const initial = new BrowserStorage(endpoint);
initial.presentation(scope).receipts.first = {
userRead: false,
presented: false,
snoozeUntil: 123,
};
initial.changed();
await initial.flush();
const reader = new BrowserStorage(endpoint);
const other = new BrowserStorage(endpoint);
reader.presentation(scope).receipts.first.userRead = true;
reader.changed();
await reader.flush();
const readerSnapshot = storage.get("reme:presentations");
assert.equal(storage.has("reme:settings"), false);
other.settings.theme = "dark";
other.changed();
await other.flush();
assert.equal(storage.get("reme:presentations"), readerSnapshot);
const receipts = other.presentation(scope).receipts;
receipts.first.presented = true;
delete receipts.first.snoozeUntil;
receipts.second = { userRead: true, presented: true };
other.changed();
await other.flush();
reader.settings.voiceEnabled = false;
reader.changed();
await reader.flush();
const reloaded = new BrowserStorage(endpoint);
assert.equal(reloaded.settings.theme, "dark");
assert.equal(reloaded.settings.voiceEnabled, false);
assert.deepEqual(reloaded.presentation(scope).receipts, {
first: { userRead: true, presented: true },
second: { userRead: true, presented: true },
});
});
test("mobile saves a custom service address and web stays on its configured address", async (t) => {
useLocalStorage(t);
const initial = "http://127.0.0.1:2333";
const remote = "http://192.0.2.10:2444";
const mobile = new BrowserStorage();
assert.equal(mobile.settings.endpoint, initial);
mobile.settings.endpoint = remote;
mobile.changed();
await mobile.flush();
const web = new BrowserStorage("https://studio.example.test");
assert.equal(web.settings.endpoint, "https://studio.example.test");
web.settings.theme = "dark";
web.changed();
await web.flush();
const restarted = new BrowserStorage();
assert.equal(restarted.settings.endpoint, remote);
assert.equal(restarted.settings.theme, "dark");
});