| 1 | // Run: tsx src/__tests__/recovery-quiet-notifications.test.ts |
| 2 | // |
| 3 | // Recovery copies remain protected by the backend, but the desktop UI should |
| 4 | // not interrupt users with recovery lifecycle banners, toasts, or transcript |
| 5 | // notices. |
| 6 | |
| 7 | import { readFileSync } from "node:fs"; |
| 8 | import { dirname, resolve } from "node:path"; |
| 9 | import { fileURLToPath } from "node:url"; |
| 10 | |
| 11 | import { en } from "../locales/en"; |
| 12 | import { zh } from "../locales/zh"; |
| 13 | import { zhTW } from "../locales/zh-TW"; |
| 14 | |
| 15 | let passed = 0; |
| 16 | let failed = 0; |
| 17 | |
| 18 | function ok(cond: boolean, label: string) { |
| 19 | if (cond) { |
| 20 | process.stdout.write(` PASS ${label}\n`); |
| 21 | passed += 1; |
| 22 | } else { |
| 23 | process.stdout.write(` FAIL ${label}\n`); |
| 24 | failed += 1; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | const here = dirname(fileURLToPath(import.meta.url)); |
| 29 | const appSource = readFileSync(resolve(here, "../App.tsx"), "utf8"); |
| 30 | const controllerSource = readFileSync(resolve(here, "../lib/useController.ts"), "utf8"); |
| 31 | |
| 32 | console.log("\nquiet recovery notifications"); |
| 33 | |
| 34 | ok(!appSource.includes("banner--recovery"), "App does not render a recovery banner"); |
| 35 | ok(!appSource.includes("recovery.toast"), "App does not show a recovery-created toast"); |
| 36 | ok(!appSource.includes("onSessionRecoveryFailed"), "App does not show recovery failure toasts"); |
| 37 | ok(!appSource.includes("AcknowledgeTabRecovery"), "App does not expose recovery acknowledgement controls"); |
| 38 | ok(!appSource.includes("OpenTabRecoveryParent"), "App does not expose recovery compare controls"); |
| 39 | ok(!appSource.includes("recovery.openOriginalFailed"), "App does not carry recovery compare failure text"); |
| 40 | |
| 41 | ok(controllerSource.includes("function quietTranscriptNoticeKey"), "controller centralizes quiet transcript notices"); |
| 42 | ok(controllerSource.includes("if (quietTranscriptNoticeKey(rawText, code))"), "raw quiet notices are skipped before localization"); |
| 43 | ok(controllerSource.includes("if (quietTranscriptNoticeKey(text, code))"), "localized quiet notices are skipped before rendering"); |
| 44 | |
| 45 | const removedPromptKeys = [ |
| 46 | "recovery.open", |
| 47 | "recovery.toast", |
| 48 | "recovery.failedLease", |
| 49 | "recovery.failedUnavailable", |
| 50 | "recovery.banner", |
| 51 | "recovery.bannerCompare", |
| 52 | "recovery.bannerDismiss", |
| 53 | "recovery.openOriginalFailed", |
| 54 | ]; |
| 55 | for (const [name, dict] of [["en", en], ["zh", zh], ["zh-TW", zhTW]] as const) { |
| 56 | for (const key of removedPromptKeys) { |
| 57 | ok(!(key in dict), `${name} locale omits ${key}`); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | console.log(`\n${passed} passed, ${failed} failed`); |
| 62 | if (failed > 0) process.exit(1); |
| 63 |