Market import: fill entries in from their websites

A list of just websites and relationships (url:, website:, or a bare
address) can be imported with "Fill in the empty boxes from each
website": each entry is filled in as on New entry, in the background a
few at a time, and saved straight into the Market. Entries already there,
by name or website, are skipped before their site is read; the plan's
limit is kept. The import page shows the progress and each entry's result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 06:41:54 -07:00
co-authored by Claude Opus 5.5
parent 185522c0c3
commit 4692d72d58
10 changed files with 659 additions and 9 deletions
+43
View File
@@ -47,3 +47,46 @@ func TestMarketMoved(t *testing.T) {
t.Errorf("post: %d %s", rec.Code, rec.Header().Get("Location"))
}
}
func TestMarketImportFill(t *testing.T) {
s, h := newTestServer(t, nil)
list := "- url: https://rival.example\n relationship: competitor\n"
// Without AI: the box can't be ticked, and says why if it is.
body := do(h, http.MethodGet, "/market/import", nil, nil).Body.String()
if !strings.Contains(body, `name="fill" disabled`) || !strings.Contains(body, `<a href="/settings/ai">Set up the AI</a>`) {
t.Errorf("import page without AI:\n%s", body)
}
body = postForm(h, "/market/import", url.Values{"yaml": {list}, "fill": {"on"}}).Body.String()
if !strings.Contains(body, "set up the AI to fill entries in") || !strings.Contains(body, "rival.example") {
t.Errorf("fill without AI:\n%s", body)
}
// Websites only, without the box ticked: says to tick it.
body = postForm(h, "/market/import", url.Values{"yaml": {list}}).Body.String()
if !strings.Contains(body, "Some entries have only a website") {
t.Errorf("websites only, not filled:\n%s", body)
}
// The last list's progress, from the setting.
st := marketFillState{Running: false, Total: 2, Lines: []inventory.FillLine{
{Site: "https://rival.example", Name: "Rival", ID: 7, Outcome: inventory.FillAdded, Filled: []string{"X handle", "description"}},
{Site: "https://gone.example", Outcome: inventory.FillFailed, Note: "no such host"},
}}
if err := s.DB.PutJSON(marketFillKey, st); err != nil {
t.Fatal(err)
}
body = do(h, http.MethodGet, "/market/import", nil, nil).Body.String()
for _, want := range []string{"1 added, 0 updated, 0 skipped, 1 failed", `<a href="/market/7">Rival</a>`, "filled: X handle, description", "no such host"} {
if !strings.Contains(body, want) {
t.Errorf("progress lacks %q", want)
}
}
// One left running with nothing doing it was stopped with the app;
// the card stops polling.
st.Running = true
_ = s.DB.PutJSON(marketFillKey, st)
body = do(h, http.MethodGet, "/market/import/status", nil, nil).Body.String()
if !strings.Contains(body, "Stopped with the app after 2 of 2") || strings.Contains(body, "hx-trigger") {
t.Errorf("status:\n%s", body)
}
}