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
2 changes: 1 addition & 1 deletion apps/mobile/preview/shots.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const shots = [
other({ id: "HM-SET-03", name: "Delete everything, the wallet still holds money", route: "delete" }),
other({ id: "HM-SET-03", name: "Delete everything, type the word", route: "delete", variant: "confirm", act: tap(/^(Entiendo, continuar|I understand, continue)$/) }),
other({ id: "HM-SET-06", name: "Appearance", route: "appearance" }),
other({ id: "HM-SET-08", name: "About", route: "about" }),
core({ id: "HM-SET-08", name: "About", route: "about" }),

// Activity, messages, memory, reminders, calendar
other({ id: "HM-ACT-01", name: "Activity", route: "activity", mockup: "settings-activity" }),
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/preview/src/stubs/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ export const clearSiteData = ok(true);
export const copyAddress = ok(true);
export const copyLogValue = ok(true);
export const walletBundleAvailable = () => false;
export const appVersion = () => "0.1.0-preview.1";
export const startWalletWorklet = () => ({});
19 changes: 19 additions & 0 deletions apps/mobile/src/about-version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="node" />
// Issue #31: the bug form asks for the version on About, so About shows it, read through the adapters.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const screen = readFileSync(new URL("./app/about.tsx", import.meta.url), "utf8");

test("About shows the app's version from the adapters, in a line people can select and copy", () => {
assert.match(screen, /import \{[^}]*\bappVersion\b[^}]*\} from "\.\.\/adapters\/device-lab";/);
const at = screen.indexOf('t("HM-SET-08.version", { version: appVersion() })');
assert.ok(at > 0, "the version line fills HM-SET-08.version with appVersion()");
const tag = screen.slice(screen.lastIndexOf("<T", at), at);
assert.match(tag, /\bselectable\b/, "the version line is selectable");
});

test("About reads no phone facts itself", () => {
assert.doesNotMatch(screen, /expo-constants/);
});
2 changes: 2 additions & 0 deletions apps/mobile/src/app/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// them, Delete everything in coral outline, and the licenses as a grouped list of links.
import { useRouter } from "expo-router";
import { Image, Linking, Pressable, View } from "react-native";
import { appVersion } from "../adapters/device-lab";
import { Btn, Card, Group, Label, Page, Row, T } from "../components/kit";
import { logos } from "../brand";
import { t } from "../i18n";
Expand All @@ -27,6 +28,7 @@ export default function About() {
<T v="title" style={{ flex: 1 }}>{"Does everything.\nTells no one."}</T>
</View>
<T v="body" color="soft">{t("HM-SET-08.body")}</T>
<T v="small" color="soft" selectable>{t("HM-SET-08.version", { version: appVersion() })}</T>

<Card>
<View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap", gap: s.xl }} accessibilityRole="summary">
Expand Down
7 changes: 3 additions & 4 deletions apps/mobile/src/app/bot-new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { useLocalSearchParams, useRouter } from "expo-router";
import { useEffect, useMemo, useState } from "react";
import { View } from "react-native";
import type { PermissionMode } from "@hermit/core";
import { MAX_BOT_NAME_CHARS } from "@hermit/core/bots";
import type { BotProposalView } from "@hermit/runtime";
import { BOT_TEMPLATES, fromProposal, fromTemplate, formNeedsFingerprint, formProblems, toNewBot, type BotForm, type BotTemplateId } from "../bot-form-view";
import { BOT_TEMPLATES, capBotName, fromProposal, fromTemplate, formNeedsFingerprint, formProblems, toNewBot, type BotForm, type BotTemplateId } from "../bot-form-view";
import { BLANK_LOOK, TEMPLATE_LOOKS } from "../bot-templates";
import { BotAvatar } from "../components/BotAvatar";
import { ModeSheet } from "../components/ModeSheet";
Expand Down Expand Up @@ -136,10 +135,10 @@ export default function BotNew() {
<Input
label={t("HM-BOT-03.name")}
value={f.name}
onChange={(name) => edit({ name })}
onChange={(name) => edit({ name: capBotName(name) })}
invalid={problems.includes("name_too_long")}
style={{ flex: 1 }}
field={{ autoCapitalize: "words", maxLength: MAX_BOT_NAME_CHARS }}
field={{ autoCapitalize: "words" }}
/>
</View>
{problems.includes("name_too_long") ? <Refusal reason="name_too_long" name={f.name.trim()} /> : null}
Expand Down
5 changes: 2 additions & 3 deletions apps/mobile/src/app/bot-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import { useLocalSearchParams, useRouter } from "expo-router";
import { useCallback, useEffect, useState } from "react";
import { AccessibilityInfo, View } from "react-native";
import { MAX_BOT_NAME_CHARS } from "@hermit/core/bots";
import { HERMIT_BOT_ID, type Bot, type MemoryCursor, type Note as Fact, type PermissionMode } from "@hermit/core";
import { formNeedsFingerprint, formPatch, formProblems, fromBot, noteActions, settingsResult, type BotForm } from "../bot-form-view";
import { capBotName, formNeedsFingerprint, formPatch, formProblems, fromBot, noteActions, settingsResult, type BotForm } from "../bot-form-view";
import { forgetBotCaches } from "../adapters";
import { BotAvatar } from "../components/BotAvatar";
import { ConfirmSheet, ConnectorsList, GroupsList, LookPicker, Refusal, modeLine, useSourceChoices } from "../components/BotFormParts";
Expand Down Expand Up @@ -230,7 +229,7 @@ export default function BotSettings() {
{hermitBot ? (
<T v="body" color="soft" style={{ flex: 1 }}>{t("HM-BOT-04.hermitRole")}</T>
) : (
<Input label={t("HM-BOT-03.name")} value={form.name} onChange={(name) => edit({ name })} invalid={problems.includes("name_too_long") || problems.includes("name_empty")} style={{ flex: 1 }} field={{ autoCapitalize: "words", maxLength: MAX_BOT_NAME_CHARS }} />
<Input label={t("HM-BOT-03.name")} value={form.name} onChange={(name) => edit({ name: capBotName(name) })} invalid={problems.includes("name_too_long") || problems.includes("name_empty")} style={{ flex: 1 }} field={{ autoCapitalize: "words" }} />
)}
</View>
{problems.includes("name_empty") ? <Refusal reason="name_empty" name={bot.name} /> : null}
Expand Down
14 changes: 13 additions & 1 deletion apps/mobile/src/bot-form-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync } from "node:fs";
import { RESERVED_GROUPS, SKILL_GROUPS, type BotLook } from "@hermit/core/bots";
import type { BotProposalView } from "../../../packages/runtime/src/bot-api.ts";
import { BOT_REFUSALS } from "../../../packages/runtime/src/bot-api.ts";
import { BOT_TEMPLATES, formPatch, fromBot, fromProposal, fromTemplate, formNeedsFingerprint, formProblems, noteActions, proposalCard, refusalLine, settingsResult, shownGroups, toNewBot, type BotForm } from "./bot-form-view.ts";
import { BOT_TEMPLATES, capBotName, formPatch, fromBot, fromProposal, fromTemplate, formNeedsFingerprint, formProblems, noteActions, proposalCard, refusalLine, settingsResult, shownGroups, toNewBot, type BotForm } from "./bot-form-view.ts";

const LOOK: BotLook = { shape: "whelk", color: "sand" };
const form = (over: Partial<BotForm> = {}): BotForm => ({ name: "Viajes", role: "Planeas los viajes de la familia Prueba.", look: LOOK, grants: ["web_read", "notes"], sites: "wikivoyage.org", connectors: [], mode: null, ...over });
Expand All @@ -18,6 +18,18 @@ test("HM-BOT-03: the form's problems match the runtime's limits", () => {
assert.deepEqual(formProblems(form({ name: "n".repeat(41), role: "r".repeat(801), sites: "wikivoyage.org, 192.168.0.1" })), ["name_too_long", "role_too_long", "bad_site"]);
assert.deepEqual(formProblems(form()), []);
});
test("HM-BOT-03: a bot name is capped at 40 code points, keeping emoji whole", () => {
assert.equal(capBotName("😀".repeat(40)), "😀".repeat(40));
assert.equal(capBotName("😀".repeat(41)), "😀".repeat(40));
assert.equal(capBotName("n".repeat(41)), "n".repeat(40));
assert.equal(capBotName("Viajes"), "Viajes");
});

test("HM-BOT-03: a role of 800 emoji passes, 801 does not", () => {
assert.deepEqual(formProblems(form({ role: "😀".repeat(800) })), []);
assert.deepEqual(formProblems(form({ role: "😀".repeat(801) })), ["role_too_long"]);
});

test("HM-BOT-03: the fingerprint for mail send, logins, pay or Don't ask, and only when newly granted", () => {
assert.equal(formNeedsFingerprint(form({ grants: ["mail_read"] })), false);
assert.equal(formNeedsFingerprint(form({ grants: ["mail_send"] })), true);
Expand Down
7 changes: 6 additions & 1 deletion apps/mobile/src/bot-form-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ export function formProblems(f: BotForm): Array<"name_empty" | "name_too_long" |
const name = f.name.trim();
if (!name) out.push("name_empty");
else if ([...name].length > MAX_BOT_NAME_CHARS) out.push("name_too_long");
if (f.role.trim().length > MAX_ROLE_CHARS) out.push("role_too_long");
if ([...f.role.trim()].length > MAX_ROLE_CHARS) out.push("role_too_long");
if (siteWords(f.sites).some((w) => normalizeSite(w) === undefined)) out.push("bad_site");
return out;
}

/** Cap a typed bot name at MAX_BOT_NAME_CHARS code points, keeping emoji whole. React Native's `maxLength` counts UTF-16 units, so it stops a name of 40 emoji at 20; this caps by code point instead, like the store does. */
export function capBotName(text: string): string {
return [...text].slice(0, MAX_BOT_NAME_CHARS).join("");
}

/**
* Task 1's one rule as the runtime applies it: on the bot's own mode only. A null mode ("Como el resto") brings no Don't
* ask of its own, whatever the global mode is (the global took the word and the fingerprint when it was set), so
Expand Down
10 changes: 5 additions & 5 deletions apps/site/locales/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@
"HM-SITE-01.sourceBody": "Hermit es de código abierto bajo Apache 2.0. La jaula que revisa cada acción, los controles de privacidad que hacen fallar la compilación, las evaluaciones y este sitio viven en un solo repositorio público.",
"HM-SITE-01.sourceContribute": "Contribuir",
"HM-SITE-01.sourceCodeLabel": "Descarga el código y corre los controles de privacidad",
"HM-SITE-01.labKicker": "Laboratorio de dispositivos",
"HM-SITE-01.labKicker": "Laboratorio del teléfono",
"HM-SITE-01.labTitle": "Ayúdanos a que Hermit sea rápido en cada teléfono.",
"HM-SITE-01.labBody": "Hermit corre un modelo pequeño en el propio teléfono, y cada teléfono es distinto. Corre la prueba de rendimiento en el tuyo y comparte el reporte. Cada uno muestra dónde le falta trabajo a Hermit.",
"HM-SITE-01.labBody": "Hermit corre un modelo pequeño en el propio teléfono, y cada teléfono es distinto. Corre la prueba de rendimiento en el tuyo y comparte el informe. Cada uno muestra dónde le falta trabajo a Hermit.",
"HM-SITE-01.labStep1Title": "Corre la prueba",
"HM-SITE-01.labStep1Body": "Mide al modelo en tu teléfono y revisa sus respuestas.",
"HM-SITE-01.labStep2Title": "Lee el reporte",
"HM-SITE-01.labStep2Body": "Nada sale de tu teléfono por su cuenta. Tú ves el reporte antes que nadie.",
"HM-SITE-01.labStep2Title": "Lee el informe",
"HM-SITE-01.labStep2Body": "Nada sale de tu teléfono por su cuenta. Tú ves el informe antes que nadie.",
"HM-SITE-01.labStep3Title": "Compártelo",
"HM-SITE-01.labStep3Body": "Súbelo al repositorio, como explica la guía.",
"HM-SITE-01.labCta": "Leer la guía de dispositivos",
Expand All @@ -155,7 +155,7 @@
"HM-SITE-01.getKicker": "Consigue Hermit",
"HM-SITE-01.getTitleA": "Hecho a la vista de todos.",
"HM-SITE-01.getTitleB": "Rumbo a las tiendas.",
"HM-SITE-01.getBody": "Hermit está en pre-alfa y todavía no está en las tiendas. Los APK de vista previa para Android están en GitHub Releases: instala uno, corre el Laboratorio del teléfono y envía su reporte. Dale una estrella al repositorio para seguirlo, o compílalo desde el código.",
"HM-SITE-01.getBody": "Hermit está en pre-alfa y todavía no está en las tiendas. Los APK de vista previa para Android están en GitHub Releases: instala uno, corre el Laboratorio del teléfono y envía su informe. Dale una estrella al repositorio para seguirlo, o compílalo desde el código.",
"HM-SITE-01.getSource": "Compilarlo desde el código",
"HM-SITE-01.getApk": "Descargar el APK de vista previa",
"HM-SITE-01.peekAlt": "Hermit asomándose desde adentro de su concha",
Expand Down
13 changes: 13 additions & 0 deletions apps/site/test/locales.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, test } from "vitest";
import en from "../locales/en.json";
import es from "../locales/es-419.json";
import appEn from "../../../packages/copy/locales/en.json";
import appEs from "../../../packages/copy/locales/es-419.json";
import { translator } from "../lib/i18n";

const KEY_PATTERN = /^(HM-SITE-\d{2}|common)\.[a-z][a-zA-Z0-9]*$/;
Expand Down Expand Up @@ -53,6 +55,17 @@ describe("site copy", () => {
}
});

test("the lab's kicker is the name the app gives the Device lab, in both languages", () => {
expect(en["HM-SITE-01.labKicker"]).toBe(appEn["HM-SET-10.title"]);
expect(es["HM-SITE-01.labKicker"]).toBe(appEs["HM-SET-10.title"]);
});

test("in Spanish the lab's report is an informe, as in the app, and the lab is never a laboratorio de dispositivos", () => {
for (const k of ["HM-SITE-01.labBody", "HM-SITE-01.labStep2Title", "HM-SITE-01.labStep2Body", "HM-SITE-01.getBody"] as const) {
expect(es[k], k).not.toMatch(/reporte|laboratorio de dispositivos/i);
}
});

test("USD₮ is the only money the copy names", () => {
for (const [k, v] of all) expect(v, k).not.toMatch(/\bUSDC\b|\bUSDT\b|stablecoin|\bETH\b|bitcoin/i);
});
Expand Down
1 change: 1 addition & 0 deletions packages/copy/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
"HM-SET-08.licensesTitle": "Open-source licenses",
"HM-SET-08.trademarks": "Hermit's code is Apache 2.0 and the crab's art is CC BY 4.0. The Hermit name, logo and wordmark are trademarks and are not covered by those licenses. Hermit is built with:",
"HM-SET-08.licenseA11y": "{name}, {license} license",
"HM-SET-08.version": "Version {version}",
"HM-REM-01.title": "Reminders",
"HM-REM-01.loading": "Loading reminders…",
"HM-REM-01.emptyTitle": "No reminders yet",
Expand Down
1 change: 1 addition & 0 deletions packages/copy/locales/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
"HM-SET-08.licensesTitle": "Licencias de código abierto",
"HM-SET-08.trademarks": "El código de Hermit es Apache 2.0 y el arte del cangrejo es CC BY 4.0. El nombre Hermit, su símbolo y su logotipo son marcas y no están cubiertos por esas licencias. Hermit está hecho con:",
"HM-SET-08.licenseA11y": "{name}, licencia {license}",
"HM-SET-08.version": "Versión {version}",
"HM-REM-01.title": "Recordatorios",
"HM-REM-01.loading": "Cargando recordatorios…",
"HM-REM-01.emptyTitle": "Aún no tienes recordatorios",
Expand Down
39 changes: 39 additions & 0 deletions packages/copy/test/copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,45 @@ describe("locale files (CT-10)", () => {
});
});

// AGENTS.md rule 9: the app's Spanish uses tú. Only voseo forms that can't be read another way are listed, so
// "elegí" or "escribí" (also the first person past tense) stay out. \b doesn't count accented letters as letters,
// so the edges are (?<!\p{L}) and (?!\p{L}).
const VOSEO_FORMS = [
"podés", "tenés", "querés", "sabés", "hacés", "decís", "necesitás", "preferís", "tocá", "mirá", "probá", "activá", "revisá",
"volvé", "poné", "usá", "agregá", "cambiá", "guardá", "confirmá", "dejá", "buscá", "esperá", "fijate", "acordate", "decime",
"avisame", "mandale", "contame",
];
const VOSEO = new RegExp(`(?<!\\p{L})(?:${VOSEO_FORMS.join("|")})(?!\\p{L})`, "iu");

describe("tú, not vos (AGENTS.md rule 9)", () => {
test("the matcher flags voseo", () => {
for (const s of [
"Tocá el botón", "Si querés, te aviso", "¿Podés esperar?", "Ya tenés todo.", "Si sabés la hora, dime.", "¿Qué hacés?",
"Decís que sí.", "Si necesitás algo, escribe.", "Si preferís, después.", "Mirá esto.", "Probá de nuevo.", "Activá las notificaciones.",
"Revisá el correo.", "Volvé a la lista.", "Poné tu huella.", "Usá la otra cuenta.", "Agregá un recordatorio.", "Cambiá la hora.",
"Guardá el cambio.", "Confirmá el pago.", "Dejá un mensaje.", "Buscá el archivo.", "Esperá un momento.", "Fijate en la fecha.",
"Acordate del lunes.", "Decime cuándo.", "Avisame mañana.", "Mandale un saludo a Ana.", "Contame más.",
]) expect(s, s).toMatch(VOSEO);
});

test("the matcher ignores case, accented capitals included", () => {
expect("TOCÁ EL BOTÓN").toMatch(VOSEO);
expect("Querés").toMatch(VOSEO);
});

test("the matcher leaves tú and other words alone", () => {
for (const s of ["Toca el botón", "Si quieres, te aviso", "No abrí nada", "Elegí la primera.", "Le escribí a Luis."]) expect(s, s).not.toMatch(VOSEO);
});

test("the matcher counts accented letters as letters at both edges", () => {
for (const s of ["Antes tocábamos el timbre.", "Siempre dejábamos la llave.", "ñtocá", "étocá"]) expect(s, s).not.toMatch(VOSEO);
});

test("no value in es-419 uses voseo", () => {
for (const [k, v] of Object.entries(es)) expect(v, k).not.toMatch(VOSEO);
});
});

describe("translator", () => {
test("fills placeholders", () => {
expect(createTranslator(es)("HM-ACT-03.title", { index: 7 })).toBe("Cadena rota en la entrada 7");
Expand Down
Loading
Loading