"""The web page's chat history: saved chats in the browser (#1787), edit / regenerate / rewind with an Undo (#2615), the rewind choice between "here" and a branch (#3823), and sending while an answer is written (#4004). One design, opt-in, off by default. The logic runs in Node (serve/test_web_history.js); what the page does in a real browser is in tools/webtest/browser_test.mjs (run here when WEBTEST_MODULES is set). These checks read the sources for what must hold whatever the code looks like: off is the page from before, and nothing about a chat goes to the server.""" from __future__ import annotations import os import re import shutil import subprocess import unittest import urllib.error import urllib.request from pathlib import Path from serve.frontend import ChatTemplate from serve.server import ByteTokenizer, MockEngine, Service, serve ROOT = Path(__file__).resolve().parents[1] WEB = Path(__file__).parent / "web" @unittest.skipUnless(shutil.which("node"), "node is not installed") class HistoryInNode(unittest.TestCase): def test_messages_titles_branches_and_the_browser_store(self): r = subprocess.run([shutil.which("node"), str(Path(__file__).with_name("test_web_history.js"))], capture_output=True, text=True, timeout=60) self.assertEqual(r.returncode, 0, r.stdout + r.stderr) class OffIsThePageFromBefore(unittest.TestCase): @classmethod def setUpClass(cls): cls.html = (WEB / "index.html").read_text(encoding="utf-8") cls.app = (WEB / "app.js").read_text(encoding="utf-8") cls.ui = (WEB / "chats-ui.js").read_text(encoding="utf-8") cls.store = (WEB / "chatstore.js").read_text(encoding="utf-8") def test_the_three_switches_start_off(self): self.assertIn('chatList: false, chatEdit: false, whileBusy: "wait"', self.app) for el in ("s-list", "s-edit"): self.assertIn('aria-checked="false"', re.search(rf']*id="{el}"[^>]*>', self.html).group(0)) self.assertIn('data-v="wait"', self.html) self.assertRegex(self.html, r'