@pylonsync/sync 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.1",
6
+ "version": "0.10.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./dist/index.d.ts",
@@ -5,6 +5,7 @@
5
5
  // first answer, anonymous or not, and notifies store subscribers.
6
6
 
7
7
  import { afterEach, expect, test } from "bun:test";
8
+ import { SyncEngine } from "./index";
8
9
  import { createTestEnv, type TestEnv } from "./test-harness";
9
10
 
10
11
  let env: TestEnv | null = null;
@@ -39,3 +40,28 @@ test("resolved with the signed-in identity", async () => {
39
40
  expect(env.engine.sessionResolved()).toBe(true);
40
41
  expect(env.engine.resolvedSession().userId).toBe("u1");
41
42
  });
43
+
44
+ test("an offline start leaves the session unresolved instead of reporting anonymous", async () => {
45
+ // A cold launch with no network: /api/auth/me never answers, so the
46
+ // engine cannot know who the user is. `sessionResolved()` must stay
47
+ // false. A mobile route guard that read the placeholder `userId: null`
48
+ // as "signed out" would send a signed-in user to the sign-in screen
49
+ // every time they open the app on a plane.
50
+ const original = globalThis.fetch;
51
+ globalThis.fetch = (async () => {
52
+ throw new Error("simulated network failure (offline)");
53
+ }) as unknown as typeof fetch;
54
+ const engine = new SyncEngine({
55
+ baseUrl: "http://stub.invalid",
56
+ persist: false,
57
+ multiTab: false,
58
+ });
59
+ try {
60
+ await engine.start();
61
+ expect(engine.sessionResolved()).toBe(false);
62
+ expect(engine.resolvedSession().userId).toBeNull();
63
+ } finally {
64
+ engine.stop();
65
+ globalThis.fetch = original;
66
+ }
67
+ });