The composer draft, the pending attachment list and the error banner
were single values shared by both slots. Uploading on companion and
then switching to operations routed the companion instance's
attachment ids into the operations instance, the operations error
banner stayed visible on the companion tab, and a half-typed message
followed the user across tabs.
Make all three Record<ChatSlot, ...>, mirroring the sending,
unreadCounts and storedSessions state that was already per slot. Every
asynchronous action now pins its slot at the start, so an upload or a
send that resolves after the user switched tabs still lands on the slot
it belonged to.
Splitting the error state is required rather than incidental. refresh()
runs every 500ms and wrote the shared error on failure and cleared it on
success, so any send or upload error was silently wiped within half a
second. The polling failure describes the IPC channel rather than a
slot, so it keeps its own runtimeError; slotError is owned solely by
user actions and takes precedence when both are present.
All three new tests were checked against a mutation that reads the
companion slot regardless of selection, and all three fail under it.
Refs: F-16 (audit P1-11).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
All four listen() call sites assigned the resolved unregister function
unconditionally. When the effect was cleaned up before the promise
settled, that assignment landed on a dead closure and the listener was
never unregistered. React StrictMode mounts, cleans up and mounts again,
so the first listener leaked on every development mount. In ChatPanel
that meant applyRuntimeEvents ran twice per event and, because a delta
is appended to the existing content, every character of a streamed reply
was doubled.
Track whether the effect is still live and unregister immediately when
the promise settles late. Each site also gains a catch, since these were
all bare void listen(...).then(...) chains — a rejected listen, such as
the missing desktop-pet capability, became an unhandled rejection rather
than anything observable.
The listener mock in src/test/setup.ts resolved eagerly, which made the
race impossible to express. Replace it with a controllable double in
src/test/tauriEvent.ts that defers resolution until the test asks for
it, tracks each registration separately, and only dispatches to handlers
that have not been unregistered. The registry is plain module state, so
setup.ts resets it after each test.
ChatPanel had no test file; this adds one. Both new tests were checked
against a mutation restoring the old assignment, and both fail under it.
Refs: F-15 (audit P1-10).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Commit 41592e2 shortened the localized fallback string but left the
ternary wrapped across three lines, which prettier now collapses. This
file passed `prettier --check` at 785f125 and failed afterwards, so it
is the only formatting regression introduced by the R1/R2 batch.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Historical UTF-8 corruption left question-mark runs in user-visible copy and in
one accessible name: the sprite load failure message, the canvas context
failure message, the pet window's `aria-label`, and the page loading state.
A separate spot had the "desktop floating" option label hard-coded as numeric
HTML entities.
Refs P1-17 / F-09.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Rust serializes `Option<String>` without `skip_serializing_if`, so absent
fields arrive as `null`. Zod's `.optional()` accepts only `undefined`, so
`safeParse` failed and three chains silently died:
- `boundRuntimeEventSchema.sessionId/messageId`: desktop-v1 and mock events
carry no session id, so every one of them was discarded; AstrBot error and
heartbeat frames were discarded too.
- `remoteChatSessionSchema.displayName/updatedAt`: one null field threw for
the whole array, leaving the remote session list permanently empty.
- `astrbotModelOptionSchema.name`: a null name failed capability parsing,
which permanently disabled the file upload button.
The sibling `slotRuntimeSnapshotSchema` in the same file already used
`.nullish()` throughout, which is what makes this look like a miss during the
de-enveloping change rather than a deliberate choice.
`formatSessionTime` widens with it: `updatedAt` is now `string | null` and the
existing falsy guard already handled null.
Refs P1-7a / F-06.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tauri rejects `invoke` with the deserialized Rust error value, which for
`RuntimeCommandError { code, message }` is a plain object rather than an
`Error`. Nine call sites used `reason instanceof Error ? reason.message :
String(reason)`, so every send, reconnect, stop, and settings failure showed
the user `[object Object]`.
`ProfileManager` already had a correct implementation; this lifts it into
`src/lib/errorMessage.ts` and routes the other call sites through it. The
module also exports `isCancelledError`, which a later batch needs to tell a
deliberate stop apart from a real failure.
Refs P1-16 / F-08.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Assistant messages come from a remote AstrBot instance and are untrusted, but
the markdown renderer passed the href through verbatim, so `javascript:` and
`data:` URLs reached an anchor. Inside this webview, script execution has
access to the full Tauri IPC surface.
Links are now resolved with `new URL()` and only http/https/mailto survive;
anything else renders as the original plain text. Relative hrefs are rejected
too rather than being presented as absolute links against the placeholder base.
`rel` gains `noopener`.
The helper lives in `src/lib/` rather than beside the component because a
non-component export in a component module fails `react-refresh` under the
repository's `--max-warnings 0` lint gate.
Refs P1-15 / F-05.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The manifest filename pattern used `\.` inside a regex literal, which matches
a literal backslash followed by any character, while the surrounding character
class already excludes backslashes. Every valid pack was rejected, including
the one bundled in this repository, so pack import was entirely unusable.
Adds a test that parses the bundled manifest so the pattern cannot regress.
Refs P1-12 / F-02.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Add configuration-only auto-connect rules, runtime operations slot lock
while tasks are active, and duplicate server-instance warnings without
silent Profile merge. Surface policy status to the settings UI and cover
the new boundaries with Rust and Vitest checks.