diff --git a/apps/mobile/src/app/delete.tsx b/apps/mobile/src/app/delete.tsx index 148a2d1..e761627 100644 --- a/apps/mobile/src/app/delete.tsx +++ b/apps/mobile/src/app/delete.tsx @@ -7,12 +7,13 @@ import { reloadAppAsync } from "expo"; import { Stack } from "expo-router"; import { useCallback, useEffect, useReducer, useRef, useState } from "react"; -import { BackHandler, View } from "react-native"; +import { BackHandler, Platform, View } from "react-native"; import { eraseReducer, initialErase, confirmationMatches, type EraseScreen } from "@hermit/runtime"; import { notificationAccessEnabled, openNotificationAccessSettings } from "../adapters"; import { confirmErase, eraseEverything, phoneHasLock, walletBalance } from "../adapters/erase"; import { Icon } from "../components/Icon"; import { Btn, Card, Empty, Failed, Input, Note as NoteLine, Notice, Page, T } from "../components/kit"; +import { eraseLines } from "../delete-view"; import { useHermit } from "../hermit-context"; import { t } from "../i18n"; import { radius, s } from "../theme"; @@ -20,7 +21,6 @@ import { usePalette } from "../use-palette"; // Read at use, not at import: the word follows the app language (HM-SET-05). const word = () => t("HM-SET-03.confirmWord"); -const LIST = ["listData", "listMessages", "listKeys", "listCache", "listModel"] as const; interface Facts { initial: EraseScreen; @@ -103,6 +103,7 @@ function Flow({ initial, hasLock, notifAccess }: Facts) { function Body(props: { screen: EraseScreen; hasLock: boolean; notifAccess: boolean; onType(text: string): void; onSubmit(): void; onWalletAck(): void; onRetry(): void }) { const p = usePalette(); + const lines = eraseLines(Platform.OS); const { screen } = props; switch (screen.kind) { case "wallet_warning": @@ -126,11 +127,12 @@ function Body(props: { screen: EraseScreen; hasLock: boolean; notifAccess: boole return ( {t("HM-SET-03.body")} - {/* What goes, on the page color with coral marks. */} + {/* What goes, on the page color with coral marks. On iOS the captured-messages line is not there: + capture is Android-only, and so is the permissions note under the list. */} - {LIST.map((k) => )} + {lines.list.map((k) => )} - + {lines.permissionsStay ? : null} {props.notifAccess ? : null} { + const lines = eraseLines("android"); + assert.deepEqual(lines.list, ["listData", "listMessages", "listKeys", "listCache", "listModel"]); + assert.equal(lines.permissionsStay, true); +}); + +test("on iOS the list leaves out the captured messages line and the permissions note is gone", () => { + const lines = eraseLines("ios"); + assert.deepEqual(lines.list, ["listData", "listKeys", "listCache", "listModel"]); + assert.equal(lines.permissionsStay, false); +}); + +test("only Android gets the Android lines", () => { + for (const os of ["web", "macos", "windows"]) { + const lines = eraseLines(os); + assert.ok(!lines.list.includes("listMessages"), os); + assert.equal(lines.permissionsStay, false, os); + } +}); diff --git a/apps/mobile/src/delete-view.ts b/apps/mobile/src/delete-view.ts new file mode 100644 index 0000000..6c3af99 --- /dev/null +++ b/apps/mobile/src/delete-view.ts @@ -0,0 +1,16 @@ +// HM-SET-03: which of the erase screen's lines apply on this OS. Pure: tested under Node with node --test +// (delete-view.test.ts). WhatsApp capture reads Android notifications, so its line and the Android permissions +// note only apply on Android; iOS has no capture and no such permissions to mention. + +export const ERASE_LIST = ["listData", "listMessages", "listKeys", "listCache", "listModel"] as const; + +export type EraseListKey = (typeof ERASE_LIST)[number]; + +/** The "what goes" list keys and whether the permissions note shows, for React Native's `Platform.OS` (or any OS string). */ +export function eraseLines(os: string): { list: readonly EraseListKey[]; permissionsStay: boolean } { + const android = os === "android"; + return { + list: android ? ERASE_LIST : ERASE_LIST.filter((k) => k !== "listMessages"), + permissionsStay: android, + }; +} diff --git a/packages/connectors/test/mcp-url.test.ts b/packages/connectors/test/mcp-url.test.ts index a6d0373..95e97d2 100644 --- a/packages/connectors/test/mcp-url.test.ts +++ b/packages/connectors/test/mcp-url.test.ts @@ -1,5 +1,7 @@ import { describe, expect, it } from "vitest"; import { getChecked, parseHttpsUrl, parseJsonObject, postChecked, resolveRedirect } from "../src/index.ts"; +import { bool, str, strArr } from "../src/mcp/json.ts"; +import { withoutTrailingSlash } from "../src/mcp/url.ts"; import { fakeNet, json } from "./mcp-fixtures.ts"; describe("parseHttpsUrl: every URL the MCP client touches (FR-CONN-02)", () => { @@ -133,3 +135,48 @@ describe("getChecked and postChecked: the URL check runs before every hop", () = expect(net.sent[0]!.maxResponseBytes).toBe(10); }); }); + +describe("MCP JSON field readers (str, strArr, bool)", () => { + it("str returns non-empty own string fields and undefined otherwise", () => { + expect(str({ name: "hermit" }, "name")).toBe("hermit"); + expect(str({ name: "" }, "name")).toBeUndefined(); + expect(str({ name: 123 }, "name")).toBeUndefined(); + expect(str({ name: null }, "name")).toBeUndefined(); + expect(str({ name: ["hermit"] }, "name")).toBeUndefined(); + expect(str({}, "name")).toBeUndefined(); + expect(str(Object.create({ name: "x" }) as Record, "name")).toBeUndefined(); + }); + + it("strArr keeps only string items from own array fields and returns undefined otherwise", () => { + expect(strArr({ items: ["a", 1, null, "b"] }, "items")).toEqual(["a", "b"]); + expect(strArr({ items: [] }, "items")).toEqual([]); + expect(strArr({ items: "abc" }, "items")).toBeUndefined(); + expect(strArr({ items: { a: "1" } }, "items")).toBeUndefined(); + expect(strArr({}, "items")).toBeUndefined(); + expect(strArr(Object.create({ items: ["x"] }) as Record, "items")).toBeUndefined(); + }); + + it("bool returns own boolean fields and undefined otherwise", () => { + expect(bool({ enabled: true }, "enabled")).toBe(true); + expect(bool({ enabled: false }, "enabled")).toBe(false); + expect(bool({ enabled: "true" }, "enabled")).toBeUndefined(); + expect(bool({ enabled: 1 }, "enabled")).toBeUndefined(); + expect(bool({}, "enabled")).toBeUndefined(); + expect(bool(Object.create({ enabled: true }) as Record, "enabled")).toBeUndefined(); + }); +}); + +describe("withoutTrailingSlash", () => { + it("strips at most one trailing path slash while preserving query strings", () => { + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/")!)).toBe("https://mcp.example.com"); + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/mcp/")!)).toBe("https://mcp.example.com/mcp"); + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/mcp")!)).toBe("https://mcp.example.com/mcp"); + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/mcp/?a=1")!)).toBe( + "https://mcp.example.com/mcp?a=1", + ); + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/?a=1")!)).toBe( + "https://mcp.example.com?a=1", + ); + expect(withoutTrailingSlash(parseHttpsUrl("https://mcp.example.com/mcp//")!)).toBe("https://mcp.example.com/mcp/"); + }); +});