Merge branch 'fix/v14311-settings' into release/v1.43.11

# Conflicts:
#	messages/de.json
#	messages/en.json
#	messages/es.json
#	messages/fr.json
#	messages/it.json
#	messages/ko.json
#	messages/nl.json
#	messages/pl.json
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 14:13:51 +02:00
commit eabfeaef08
74 files changed
+2545 -436

No files matched your search

@@ -0,0 +1,152 @@
/**
* Settings actions say how they went.
*
* Each action below finished in silence on at least one side. Adding or
* removing a passkey or a security key only redrew the list; disconnecting an
* integration and revoking a share link fired from a dialog that had already
* closed, so a refused request left everything as it was and said nothing;
* the injection-site exclusions, the local-OCR switch and the preventive-care
* reminder switches saved, or did not, without a word.
*
* They use the pair the rest of the app reports a write with —
* `toastWrittenOutcome("success", …)`, the outcome module's one door to the
* success toast, and `showErrorToast` (which carries the error id of a server
* failure). The passkey and security-key cards keep their inline error line,
* which also carries the step-up dialog's outcome, and gain the success half.
*
* Mutation callbacks only run after an interaction, so the wiring is read
* from the source: per action, the success callback raises the success
* outcome and, where the card has no inline error line, the error callback raises
* `showErrorToast`.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import ts from "typescript";
import { describe, expect, it } from "vitest";
interface Site {
file: string;
/** `const <name> = useMutation({…})`, or `<name>.mutate(…, {…})`. */
name: string;
shape: "definition" | "call";
needsErrorToast: boolean;
}
const SITES: Site[] = [
{
file: "src/components/settings/security-section/passkey-list-section.tsx",
name: "add",
shape: "definition",
needsErrorToast: false,
},
{
file: "src/components/settings/security-section/passkey-list-section.tsx",
name: "remove",
shape: "definition",
needsErrorToast: false,
},
{
file: "src/components/settings/security-section/security-keys-card.tsx",
name: "add",
shape: "definition",
needsErrorToast: false,
},
{
file: "src/components/settings/security-section/security-keys-card.tsx",
name: "remove",
shape: "definition",
needsErrorToast: false,
},
{
file: "src/components/settings/integrations/oauth-integration-card.tsx",
name: "disconnect",
shape: "definition",
needsErrorToast: true,
},
{
file: "src/components/settings/sharing-section.tsx",
name: "revokeMutation",
shape: "definition",
needsErrorToast: true,
},
{
file: "src/components/settings/injection-sites-card.tsx",
name: "mutation",
shape: "definition",
needsErrorToast: true,
},
{
file: "src/components/labs/labs-settings.tsx",
name: "updateLocalOcr",
shape: "call",
needsErrorToast: true,
},
{
file: "src/components/measurement-reminders/vorsorge-settings.tsx",
name: "update",
shape: "call",
needsErrorToast: true,
},
];
/** The `{ onSuccess, onError, … }` literal for a site, or null. */
function callbacks(site: Site): ts.ObjectLiteralExpression | null {
const text = readFileSync(join(process.cwd(), site.file), "utf8");
const sf = ts.createSourceFile(site.file, text, ts.ScriptTarget.Latest, true);
let found: ts.ObjectLiteralExpression | null = null;
const visit = (node: ts.Node) => {
if (found) return;
if (
site.shape === "definition" &&
ts.isVariableDeclaration(node) &&
node.name.getText(sf) === site.name &&
node.initializer &&
ts.isCallExpression(node.initializer) &&
node.initializer.expression.getText(sf) === "useMutation"
) {
const arg = node.initializer.arguments[0];
if (arg && ts.isObjectLiteralExpression(arg)) found = arg;
}
if (
site.shape === "call" &&
ts.isCallExpression(node) &&
node.expression.getText(sf) === `${site.name}.mutate`
) {
const arg = node.arguments[1];
if (arg && ts.isObjectLiteralExpression(arg)) found = arg;
}
ts.forEachChild(node, visit);
};
visit(sf);
return found;
}
function property(obj: ts.ObjectLiteralExpression, name: string): string {
const prop = obj.properties.find((p) => p.name && p.name.getText() === name);
return prop ? prop.getText() : "";
}
describe("settings actions report their outcome", () => {
for (const site of SITES) {
describe(`${site.file} → ${site.name}`, () => {
const obj = callbacks(site);
it("is found", () => {
expect(obj, "the mutation options were not found").not.toBeNull();
});
it("raises a success toast", () => {
expect(property(obj!, "onSuccess")).toMatch(
/toastWrittenOutcome\(\s*"success"/,
);
});
if (site.needsErrorToast) {
it("raises an error toast through showErrorToast", () => {
expect(property(obj!, "onError")).toContain("showErrorToast(");
});
}
});
}
});
@@ -216,12 +216,25 @@ describe("<AiSection> — dropdown-driven UX (B2)", () => {
expect(html).toContain("ChatGPT-Account (Codex)");
// v1.4.33 — the active-provider heading and the parent section
// both ship without the "KI"/"AI" prefix per the project-voice rule
// ("Aktiver KI-Provider" → "Aktiver Provider"). The heading and the
// chain summary now share the same phrase, so we assert against the
// explicit `activeProviderLabel` slot below it ("Primärer Provider")
// to keep the test pinned to the right surface.
// ("Aktiver KI-Provider" → "Aktiver Provider"). The picker below it is
// labelled for what it does: it chooses the form, not the order.
expect(html).toContain("Aktiver Provider");
expect(html).toContain("Primärer Provider");
expect(html).toContain("Anbieter einrichten");
});
it("labels the picker for what it does, not as the primary provider", () => {
// The select picks which provider's key and model the form below edits.
// It never wrote anything, yet read "Primary provider" under a card
// that said it held "the provider HealthLog asks first": a person who
// picked one expected it to answer first, and the chain order, which is
// what decides that, stayed as it was. The copy now points at the chain.
activeProviderQuery = "codex";
const html = render();
expect(html).not.toContain("Primary provider");
expect(html).toContain("Set up a provider");
expect(html).toContain(
"the order below decides which one HealthLog asks first",
);
});
// v1.18.0 — the Coach preference cards (disable toggle, preferences,
@@ -0,0 +1,57 @@
/**
* Ending a grant from the sessions card asks first.
*
* "Sign out everywhere" leaves accepted grants standing and lists them with a
* one-click end. That end is the same act as the access card's revoke — it
* takes another account's standing access to the record, permanently — but it
* fired on the tap, while the access card asks with a dialog naming who loses
* what. The row is state set after a mutation, out of reach of a static
* render, so the wiring is read from the source: the revoke call may only sit
* inside a `ConfirmButton`'s `onConfirm`.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import ts from "typescript";
import { describe, expect, it } from "vitest";
const FILE = "src/components/settings/security-sessions-card.tsx";
function revokeCallSites(): { attr: string | null; element: string | null }[] {
const text = readFileSync(join(process.cwd(), FILE), "utf8");
const sf = ts.createSourceFile(FILE, text, ts.ScriptTarget.Latest, true);
const sites: { attr: string | null; element: string | null }[] = [];
const visit = (node: ts.Node) => {
if (
ts.isCallExpression(node) &&
node.expression.getText(sf) === "revokeGrant.mutate"
) {
let attr: string | null = null;
let element: string | null = null;
for (let p: ts.Node | undefined = node.parent; p; p = p.parent) {
if (ts.isJsxAttribute(p) && attr === null) attr = p.name.getText(sf);
if (
(ts.isJsxSelfClosingElement(p) || ts.isJsxOpeningElement(p)) &&
attr !== null
) {
element = p.tagName.getText(sf);
break;
}
}
sites.push({ attr, element });
}
ts.forEachChild(node, visit);
};
visit(sf);
return sites;
}
describe("kept-grant revoke on the sessions card", () => {
it("fires only from a ConfirmButton's onConfirm", () => {
const sites = revokeCallSites();
expect(sites.length).toBeGreaterThan(0);
for (const site of sites) {
expect(site).toEqual({ attr: "onConfirm", element: "ConfirmButton" });
}
});
});
@@ -0,0 +1,163 @@
/**
* A settings save that raises its own pending flag lowers it in a `finally`.
*
* The cards that hand-roll a `saving` flag around a raw `fetch` set it, await
* the request, and cleared it on the line after. A request that never reached
* the server (offline, a dropped connection, a timeout) rejects instead of
* returning a response, the line after never ran, and the card stayed in its
* saving state for good: the Telegram form, the mood reminder, the low-stock
* threshold, the lock-screen detail switch, the Coach nudges, the profile
* form. Every one of them disabled its own control while "saving", so the
* only way out was a reload.
*
* `useMutation` owns its `isPending` and cannot get stuck this way; this
* guard covers the hand-rolled ones. For every async function under
* `src/components/settings` that sets one of the pending flags below to
* `true` and then awaits, it requires a `try` whose `finally` sets the same
* flag back to `false` — or, the older shape that is equally safe, every
* await inside a `try` that catches, so nothing can skip the reset after it.
* What it cannot see: a flag under another name, or a function that hands
* the await to a helper it does not await itself.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import ts from "typescript";
import { describe, expect, it } from "vitest";
import { walkSourceFiles } from "@/__tests__/helpers/source-files";
const ROOT = join(process.cwd(), "src/components/settings");
const PENDING_SETTER =
/^set(Saving|Pending|Busy|Loading|Submitting|ActionLoading)$/;
interface Finding {
where: string;
setter: string;
/** The flag is lowered in a `finally`, or no await can throw past the reset. */
safe: boolean;
}
/** Is this await inside the try block of a `try` that has a `catch`? */
function caught(node: ts.Node, fn: ts.Node): boolean {
for (let p = node.parent; p && p !== fn; p = p.parent) {
if (
ts.isBlock(p) &&
ts.isTryStatement(p.parent) &&
p.parent.tryBlock === p &&
p.parent.catchClause
) {
return true;
}
}
return false;
}
type FunctionLike =
| ts.FunctionDeclaration
| ts.FunctionExpression
| ts.ArrowFunction
| ts.MethodDeclaration;
function isFunctionLike(node: ts.Node): node is FunctionLike {
return (
ts.isFunctionDeclaration(node) ||
ts.isFunctionExpression(node) ||
ts.isArrowFunction(node) ||
ts.isMethodDeclaration(node)
);
}
/** Walk a function body without descending into nested functions. */
function ownNodes(body: ts.Node, visit: (node: ts.Node) => void): void {
const step = (node: ts.Node) => {
visit(node);
if (isFunctionLike(node)) return;
ts.forEachChild(node, step);
};
ts.forEachChild(body, step);
}
function setterCall(node: ts.Node, sf: ts.SourceFile, value: string) {
return (
ts.isCallExpression(node) &&
ts.isIdentifier(node.expression) &&
PENDING_SETTER.test(node.expression.text) &&
node.arguments.length === 1 &&
node.arguments[0].getText(sf) === value
);
}
function scan(): Finding[] {
const findings: Finding[] = [];
for (const rel of walkSourceFiles(ROOT, { floor: 150 })) {
if (rel.includes("__tests__/")) continue;
const text = readFileSync(join(ROOT, rel), "utf8");
const sf = ts.createSourceFile(rel, text, ts.ScriptTarget.Latest, true);
const visitFn = (node: ts.Node) => {
if (
isFunctionLike(node) &&
node.body &&
node.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)
) {
const raised = new Set<string>();
const awaits: ts.Node[] = [];
ownNodes(node.body, (n) => {
if (setterCall(n, sf, "true")) {
raised.add(
((n as ts.CallExpression).expression as ts.Identifier).text,
);
}
if (ts.isAwaitExpression(n)) awaits.push(n);
});
const allCaught = awaits.every((a) => caught(a, node));
if (awaits.length > 0) {
for (const setter of raised) {
let resetInFinally = false;
ownNodes(node.body, (n) => {
if (!ts.isTryStatement(n) || !n.finallyBlock) return;
ownNodes(n.finallyBlock, (m) => {
if (
setterCall(m, sf, "false") &&
((m as ts.CallExpression).expression as ts.Identifier)
.text === setter
) {
resetInFinally = true;
}
});
});
const line =
sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
findings.push({
where: `${rel}:${line}`,
setter,
safe: resetInFinally || allCaught,
});
}
}
}
ts.forEachChild(node, visitFn);
};
visitFn(sf);
}
return findings;
}
describe("settings saves cannot stay pending after a failed request", () => {
const findings = scan();
it("finds the hand-rolled saves it is meant to check", () => {
// A matcher that found nothing would pass on any tree.
expect(findings.length).toBeGreaterThan(10);
});
it("every one lowers its flag in a finally", () => {
const stuck = findings
.filter((f) => !f.safe)
.map((f) => `${f.where} (${f.setter})`);
expect(
stuck,
"Move the reset into `finally`, so a request that rejects (offline, timeout) cannot leave the card saving.",
).toEqual([]);
});
});
@@ -0,0 +1,52 @@
/**
* The token revoke confirmation names the act.
*
* Both token lists (API tokens and MCP connections) labelled the dialog's
* confirm button with `settings.tokenRevoked` — "Revoked", the status word the
* admin overview shows for a token that is already gone — so the button that
* performs the revoke read as if it had happened. The phone layout's trigger
* carried the dialog title instead, question mark included.
*
* Read from the source because the dialog content only mounts while open, and
* an SSR render never sees it. What is pinned: every `AlertDialogAction` that
* calls `handleRevoke` is labelled with the action key, and no trigger or
* action on these two surfaces uses the status word.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const FILES = [
"src/components/settings/api-section.tsx",
"src/components/settings/mcp-section.tsx",
];
function read(rel: string): string {
return readFileSync(join(process.cwd(), rel), "utf8");
}
/** The body of every `<AlertDialogAction …>…</AlertDialogAction>` block. */
function actions(source: string): string[] {
return [
...source.matchAll(/<AlertDialogAction\b[\s\S]*?<\/AlertDialogAction>/g),
].map((m) => m[0]);
}
describe("token revoke labels", () => {
for (const rel of FILES) {
it(`${rel}: the revoke confirm says "Revoke token"`, () => {
const revokes = actions(read(rel)).filter((a) =>
a.includes("handleRevoke(tok.id)"),
);
expect(revokes.length).toBeGreaterThan(0);
for (const action of revokes) {
expect(action).toContain('t("settings.tokenRevokeAction")');
}
});
it(`${rel}: never labels a control with the status word`, () => {
expect(read(rel)).not.toContain('t("settings.tokenRevoked")');
});
}
});