GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): queue offline settle and snooze on plain HTTP too · pingdotgg/t3code@83d9f4d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • mobile/src/state
      • thread-triage-outbox-storage.ts
    • web
      • src/connection
        • threadTriageOutboxStore.browser.test.ts
        • threadTriageOutboxStore.test.ts
        • threadTriageOutboxStore.ts
      • vite.config.ts
  • docs/user
    • thread-sidebar.md
  • packages/client-runtime/src
    • platform
      • threadTriageOutboxStore.ts
    • state
      • threadCommands.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/state/thread-triage-outbox-storage.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/state/thread-triage-outbox-storage.ts
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ async function getStorageFile() {
1111
return new File(Paths.document, "thread-triage-outbox.json");
1212
}
1313

14+
async function readStorageFile() {
15+
const file = await getStorageFile();
16+
return file.exists ? await file.text() : null;
17+
}
18+
1419
/** Lives outside the client cache so clearing cached data keeps unsynced settles and snoozes. */
1520
export const mobileThreadTriageOutboxStore = makeThreadTriageOutboxStore({
1621
read: Effect.tryPromise({
17-
try: async () => {
18-
const file = await getStorageFile();
19-
return file.exists ? await file.text() : null;
20-
},
22+
try: readStorageFile,
2123
catch: (cause) => new ThreadTriageOutboxStorageError({ cause }),
2224
}),
23-
write: (value) =>
25+
// One process owns this file, and the store already serializes its own changes.
26+
modify: (next) =>
2427
Effect.tryPromise({
25-
try: async () => writeFileAtomically(await getStorageFile(), value),
28+
try: async () => {
29+
const value = next(await readStorageFile());
30+
if (value !== null) await writeFileAtomically(await getStorageFile(), value);
31+
},
2632
catch: (cause) => new ThreadTriageOutboxStorageError({ cause }),
2733
}),
2834
});
Collapse file

‎apps/web/src/connection/threadTriageOutboxStore.browser.test.ts‎

Copy file name to clipboard
+88Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { describe, expect, it } from "@effect/vitest";
2+
import { CommandId, EnvironmentId, ThreadId } from "@t3tools/contracts";
3+
import {
4+
makeThreadTriageOutboxStore,
5+
ThreadTriageOutboxStorageError,
6+
} from "@t3tools/client-runtime/platform";
7+
import * as Cause from "effect/Cause";
8+
import * as DateTime from "effect/DateTime";
9+
import * as Effect from "effect/Effect";
10+
import * as Logger from "effect/Logger";
11+
import { vi } from "vite-plus/test";
12+
13+
import {
14+
browserThreadTriageOutboxStorage,
15+
browserThreadTriageOutboxStore,
16+
} from "./threadTriageOutboxStore";
17+
18+
const settle = (threadId: string) => ({
19+
environmentId: EnvironmentId.make("remote"),
20+
threadId: ThreadId.make(threadId),
21+
commandId: CommandId.make(`settle-${threadId}`),
22+
action: { type: "settle" as const },
23+
queuedAt: DateTime.makeUnsafe("2026-09-12T10:00:00.000Z"),
24+
snapshotSequence: 1,
25+
});
26+
27+
const replaceStored = (raw: string) => browserThreadTriageOutboxStorage.modify(() => raw);
28+
29+
describe("browser thread triage storage", () => {
30+
it.effect("keeps every tab's change when tabs save at the same time", () =>
31+
Effect.gen(function* () {
32+
yield* replaceStored(JSON.stringify({ entries: [], operableEnvironmentIds: [] }));
33+
const tab = () => makeThreadTriageOutboxStore(browserThreadTriageOutboxStorage);
34+
35+
yield* Effect.all([tab().put(settle("first")), tab().put(settle("second"))], {
36+
concurrency: "unbounded",
37+
});
38+
39+
const { entries } = yield* tab().load;
40+
expect(entries.map((entry) => entry.threadId).toSorted()).toEqual(["first", "second"]);
41+
}),
42+
);
43+
44+
it.effect("discards an unreadable document on the caller's logger, then saves", () =>
45+
Effect.gen(function* () {
46+
yield* replaceStored("{invalid");
47+
const warnings: unknown[] = [];
48+
49+
yield* browserThreadTriageOutboxStore
50+
.put(settle("thread"))
51+
.pipe(
52+
Effect.provideService(
53+
Logger.CurrentLoggers,
54+
new Set([Logger.make(({ message }) => warnings.push(message))]),
55+
),
56+
);
57+
58+
expect(warnings).toHaveLength(1);
59+
expect((yield* browserThreadTriageOutboxStore.load).entries).toEqual([settle("thread")]);
60+
}),
61+
);
62+
63+
it.effect("clears retained environment state even when storage is unavailable", () =>
64+
Effect.gen(function* () {
65+
yield* Effect.acquireRelease(
66+
Effect.sync(() => vi.stubGlobal("indexedDB", undefined)),
67+
() => Effect.sync(() => vi.unstubAllGlobals()),
68+
);
69+
const environmentId = EnvironmentId.make("removed");
70+
const retained = new Set([environmentId]);
71+
yield* Effect.acquireRelease(
72+
Effect.sync(() =>
73+
browserThreadTriageOutboxStore.subscribeCleared((removed) => retained.delete(removed)),
74+
),
75+
(unsubscribe) => Effect.sync(unsubscribe),
76+
);
77+
78+
const result = yield* Effect.exit(
79+
browserThreadTriageOutboxStore.clearEnvironment(environmentId),
80+
);
81+
82+
expect(result._tag === "Failure" && Cause.squash(result.cause)).toBeInstanceOf(
83+
ThreadTriageOutboxStorageError,
84+
);
85+
expect(retained.size).toBe(0);
86+
}),
87+
);
88+
});
Collapse file

‎apps/web/src/connection/threadTriageOutboxStore.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/connection/threadTriageOutboxStore.test.ts
-186Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.