The lab's phone shows an HTML message as Telegram does, so a tap carries back the words shown (issue 692)
mesh/merge-gate head dcaf843b8a6e merged into trunk 1316a405a630 — pass: the change touches no module of the mesh's graph
mesh/repo-check head dcaf843b8a6e merged into trunk 1316a405a630 — pass: THE CHANGE ALTERS ITS OWN CHECK (asks/merge-check.sh): main's version judged it; t…
mesh/delivery delivered

Since mesh-catalog #278 the channel sends every message in HTML (issues 383, 639). The fake Bot API kept
the text as sent, tags and entities included, and gave that back on a tap; the channel compares a tap by
the plain words it showed, so the proof's tap was refused as "this message does not show what the mesh put
there". Telegram reads the markup and gives the plain words back; the fake now does too.
This commit is contained in:
jochen
2026-10-14 02:37:06 +02:00
parent 1316a405a6
commit dcaf843b8a
2 changed files with 26 additions and 1 deletions
+25
View File
@@ -3,8 +3,10 @@ package asks
import (
"encoding/json"
"fmt"
"html"
"net/http"
"net/http/httptest"
"regexp"
"strings"
"sync"
"testing"
@@ -100,6 +102,11 @@ func (f *fakeTelegram) serve(w http.ResponseWriter, r *http.Request) {
case "sendMessage", "editMessageText":
chat := int64(num(body["chat_id"]))
text, _ := body["text"].(string)
if mode, _ := body["parse_mode"].(string); mode == "HTML" {
// What a message shows, and what a tap on it carries back, is its text with the markup read: tags gone,
// entities unescaped — as the service gives it (novox/hq issue 692).
text = shownOfHTML(text)
}
m := tgMessage{Chat: chat, Text: text, Buttons: buttonsOf(body["reply_markup"]), At: time.Now()}
f.mu.Lock()
if method == "sendMessage" {
@@ -324,3 +331,21 @@ func firstLine(s string) string {
}
return s
}
var htmlTag = regexp.MustCompile(`</?[a-zA-Z][^>]*>`)
// shownOfHTML is a text sent in Telegram's HTML as the service shows it and gives it back: its tags read and taken
// out, its entities written as the characters they stand for.
func shownOfHTML(text string) string {
return html.UnescapeString(htmlTag.ReplaceAllString(text, ""))
}
// The fake phone shows a message sent in HTML as Telegram does (novox/hq issue 692): the words without their
// markup, so a tap carries back what the channel digests, as on the real service.
func TestTheFakePhoneShowsHTMLAsTelegramDoes(t *testing.T) {
in := "<b>Flip the lab&#39;s switch?</b>\nA &lt;b&gt; &amp; c\n<code>+ k: v</code>\n\n<blockquote expandable>Asked by lab-asker.</blockquote>"
want := "Flip the lab's switch?\nA <b> & c\n+ k: v\n\nAsked by lab-asker."
if got := shownOfHTML(in); got != want {
t.Errorf("%q, want %q", got, want)
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ sh -n live-acceptance.sh
go vet ./...
out=$(mktemp)
status=0
go test -count=1 -timeout 25m -v -run '^TestTheOperatorsAnswerEndToEnd$' . >"$out" 2>&1 || status=$?
go test -count=1 -timeout 25m -v -run '^(TestTheOperatorsAnswerEndToEnd|TestTheFakePhoneShowsHTMLAsTelegramDoes)$' . >"$out" 2>&1 || status=$?
grep -E '^(--- | --- |ok|FAIL|PASS)' "$out" || true
if grep -q 'NOT RUN' "$out"; then
echo "NOT RUN: THE PROOF OF THE OPERATOR'S ANSWERS DID NOT RUN HERE:"