Files
openchamber/packages/ui/src/sync/last-session-cache.test.ts
T
Bohdan Triapitsyn 86ef96302d feat(mobile): mobile app navigation rework and beta-feedback closeout (#2561)
Navigation model rebuilt around two full-width drawers and a minimal
header (sessions / title-switcher / usage ring / workspace):

- Left sessions drawer: cross-project tree with live status indicators,
  swipe actions on sessions (rename/archive/delete) and on group headers
  (project edit / two-step close, worktree delete), reorder-only edit
  mode with collapsible project cards and draggable worktrees, app-level
  footer (connected instance, settings, pending web update).
- Right workspace drawer: Changes / Files / Terminal / Notes / MCP as
  pill tabs (inactive tabs icon-only); panes stay mounted once visited.
  The full desktop file editor serves the Files tab; read/skill tool taps
  in chat open the file there at the requested line.
- Header session switcher on title tap: 10 cross-project recents with
  live busy/attention indicators and project · branch metadata; the
  usage ring opens a metadata overlay with an explicit loading state.
- The overflow menu is gone on phones (its destinations moved into the
  drawers); iPad keeps it until its dedicated layout pass.

Correctness and continuity:

- /auth/session answers bearer-first, so a stale WebView cookie can no
  longer mask a revoked device token; cold launches classify failures
  fast and land on an explicit connect screen.
- Authoritative session snapshots raise frozen ordering baselines and
  stale live ranks — recents stay truthful after the app slept.
- Cold launches reopen the last active session per instance (persisted
  pointer, confirmed against a sessions snapshot; a user-opened draft
  clears it), with a logo hold instead of a draft flash.

Also: collapsed pill composer gains the stop control; chat tool rows
share one 36px rhythm; Task subtool rows truncate; larger bottom safe
area so the composer clears big-screen corner radii; Capacitor build
hides About/Update (store updates apply there); widgets link to the
sessions drawer with a list icon; MobileApp split into focused modules;
five mobile-surface detectors unified; translucent borders normalized to
70%; all new strings translated across the 10 locales.

iPad and foldable layouts are intentionally untouched - separate next version PR.
2026-08-01 21:16:36 +03:00

66 lines
2.9 KiB
TypeScript

import { beforeEach, describe, expect, test } from "bun:test"
import { clearLastActiveSession, persistLastActiveSession, readLastActiveSession } from "./last-session-cache"
class TestStorage implements Storage {
readonly values = new Map<string, string>()
get length() { return this.values.size }
clear() { this.values.clear() }
getItem(key: string) { return this.values.get(key) ?? null }
key(index: number) { return [...this.values.keys()][index] ?? null }
removeItem(key: string) { this.values.delete(key) }
setItem(key: string, value: string) { this.values.set(key, value) }
}
let storage: TestStorage
beforeEach(() => {
storage = new TestStorage()
})
describe("last active session persistence", () => {
test("keeps independent entries per runtime", () => {
persistLastActiveSession("runtime-a", { sessionId: "ses-a", directory: "/repo/a" }, storage)
persistLastActiveSession("runtime-b", { sessionId: "ses-b", directory: null }, storage)
expect(readLastActiveSession("runtime-a", storage)).toEqual({ sessionId: "ses-a", directory: "/repo/a" })
expect(readLastActiveSession("runtime-b", storage)).toEqual({ sessionId: "ses-b", directory: null })
})
test("overwrites the entry for the same runtime", () => {
persistLastActiveSession("runtime-a", { sessionId: "ses-1", directory: "/repo" }, storage)
persistLastActiveSession("runtime-a", { sessionId: "ses-2", directory: null }, storage)
expect(readLastActiveSession("runtime-a", storage)).toEqual({ sessionId: "ses-2", directory: null })
})
test("clear removes only the targeted runtime", () => {
persistLastActiveSession("runtime-a", { sessionId: "ses-a", directory: null }, storage)
persistLastActiveSession("runtime-b", { sessionId: "ses-b", directory: null }, storage)
clearLastActiveSession("runtime-a", storage)
expect(readLastActiveSession("runtime-a", storage)).toBeNull()
expect(readLastActiveSession("runtime-b", storage)).toEqual({ sessionId: "ses-b", directory: null })
})
test("malformed persisted payload reads as empty, not a crash", () => {
storage.setItem("oc.lastSession.v1", "{not json")
expect(readLastActiveSession("runtime-a", storage)).toBeNull()
storage.setItem("oc.lastSession.v1", JSON.stringify({ version: 99, runtimes: { "runtime-a": { sessionId: "x" } } }))
expect(readLastActiveSession("runtime-a", storage)).toBeNull()
})
test("bounds retained runtime namespaces", () => {
for (let index = 0; index < 10; index += 1) {
persistLastActiveSession(`runtime-${index}`, { sessionId: `ses-${index}`, directory: null }, storage)
}
const retained = Array.from({ length: 10 }, (_, index) => readLastActiveSession(`runtime-${index}`, storage))
.filter(Boolean)
expect(retained.length).toBe(8)
// Newest entries survive.
expect(readLastActiveSession("runtime-9", storage)).not.toBeNull()
expect(readLastActiveSession("runtime-0", storage)).toBeNull()
})
})