Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions apps/mobile/src/app/delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
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";
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;
Expand Down Expand Up @@ -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":
Expand All @@ -126,11 +127,12 @@ function Body(props: { screen: EraseScreen; hasLock: boolean; notifAccess: boole
return (
<View style={{ gap: s.lg }}>
<T v="body">{t("HM-SET-03.body")}</T>
{/* 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. */}
<View style={{ gap: s.sm }}>
{LIST.map((k) => <NoteLine key={k} icon="trash-2" tone="coral" text={t(`HM-SET-03.${k}`)} textColor="text" v="body" />)}
{lines.list.map((k) => <NoteLine key={k} icon="trash-2" tone="coral" text={t(`HM-SET-03.${k}`)} textColor="text" v="body" />)}
</View>
<NoteLine icon="info" text={t("HM-SET-03.permissionsStay")} />
{lines.permissionsStay ? <NoteLine icon="info" text={t("HM-SET-03.permissionsStay")} /> : null}
{props.notifAccess ? <Btn label={t("HM-SET-03.openNotificationAccess")} kind="secondary" icon="settings" small onPress={openNotificationAccessSettings} /> : null}
<Input
label={t("HM-SET-03.typePrompt", { word: word() })}
Expand Down
25 changes: 25 additions & 0 deletions apps/mobile/src/delete-view.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// HM-SET-03 (#212): the erase screen's list and notes on each OS. The WhatsApp capture line and the Android
// permissions note only apply where capture exists, which is Android; iOS has no capture.
import { test } from "node:test";
import assert from "node:assert/strict";
import { eraseLines } from "./delete-view.ts";

test("on Android the list keeps every line and the permissions note shows", () => {
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);
}
});
16 changes: 16 additions & 0 deletions apps/mobile/src/delete-view.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
47 changes: 47 additions & 0 deletions packages/connectors/test/mcp-url.test.ts
Original file line number Diff line number Diff line change
@@ -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)", () => {
Expand Down Expand Up @@ -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<string, unknown>, "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<string, unknown>, "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<string, unknown>, "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/");
});
});
Loading