package thintest
import (
"bytes"
"net/http"
"net/url"
"regexp"
"strings"
"testing"
"time"
"amadan.net/oficina/equipo/internal/equipo"
"amadan.net/oficina/equipo/internal/wire"
)
// Research on the pages (Research spec §3.6 and §5, slice R5): the
// sources and inventory cards in the conversation, the Research step's
// waiting states on the task page, its findings, kept images served by
// the instance only, and its fetch log as escaped text. Nothing on a
// page loads a remote resource.
// cardOf is one card's markup on a conversation page.
func cardOf(t *testing.T, page, id string) string {
t.Helper()
card := regexp.MustCompile(`(?s)
]* data-card="` + regexp.QuoteMeta(id) + `".*?\n`).FindString(page)
if card == "" {
t.Fatalf("no card %s in:\n%s", id, page)
}
return card
}
// researchItem is the task page's timeline entry for a Research step.
func researchItem(t *testing.T, page string) string {
t.Helper()
item := regexp.MustCompile(`(?s)]*>.*?`).FindString(page)
if item == "" {
t.Fatalf("no Research entry in:\n%s", page)
}
return item
}
// noRemoteLoads fails when markup would load anything from another
// origin: an image, frame, embed, object, script or stylesheet whose
// address is absolute.
func noRemoteLoads(t *testing.T, what, markup string) {
t.Helper()
if m := regexp.MustCompile(`(?i)<(img|iframe|embed|object|script|link|source|video|audio)\b[^>]*\b(src|href|data|srcset)="(https?:)?//`).FindString(markup); m != "" {
t.Fatalf("%s loads a remote resource: %s", what, m)
}
for _, tag := range []string{"