oficina / equipo Public

web: draft keys are scoped by task, so Needs you notes stay apart

Task 8 review, fix round 2.

equipoKeepDrafts keyed a field by its form's data-draft-key and name
only. The Needs you page renders several decisions in one live region,
each with a More options form keyed "more" holding name="note", so on a
refresh the last decision's note overwrote the others and was then
restored into every one: a note could be erased or sent with another
task's card.

The key is now whose form it is, the form's key and the field's name.
Whose is the enclosing decision's task (data-decision), else the form's
action (Design's Add a note, /team/{id}/taste). team-panel.js still
applies drafts only to the same specialist's panel. No template changes
(work_needs.html and work_pages.go are untouched).

TDD evidence
- New browser regression TestBrowserNeedsDrafts (-tags browser): the
  real work_needs.html content template with two decisions (tasks tk1
  and tk2, each with More options) served at 127.0.0.1 with
  work-stream.js. Type "fewer colours" in tk1's note and "bigger type"
  in tk2's, move focus away, refresh through equipo:work.
  Red with b8a3dbd6's work-stream.js: tk1's note held "bigger type".
  Green: each note stays in its own decision.
- Mutations (each broke, test failed, restored):
  - key without the task or action scope: TestBrowserNeedsDrafts
  - key by field name only: TestBrowserNeedsDrafts, TestBrowserTasteDrafts
  - task scope without the task id: TestBrowserNeedsDrafts
- Also passing: -tags browser TestBrowserTasteDrafts and
  TestBrowserDirection*; thintest TestBrowserTeamPanel,
  TestBrowserTaskRows, TestBrowserTrackPulse; go vet -tags browser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 16d815d8141f0d80876628ef018d5a67384bdf75 parent b8a3dbd
2 files changed, +86 −3
  • internal/equipo/static/work-stream.js +8 −3
  • internal/equipo/team_taste_browser_test.go +78 −0
diff --git a/internal/equipo/static/work-stream.js b/internal/equipo/static/work-stream.js
index 432a1534..62ad9d61 100644
--- a/internal/equipo/static/work-stream.js
+++ b/internal/equipo/static/work-stream.js
@@ -21,12 +21,17 @@
// forms that carry a stable data-draft-key (Design's Add a note), and
// which of those fields has the focus; the function it returns puts
// both back into the same fields of the fresh copy that replaces old.
- // A field is known by its form's key and its own name. team-panel.js
- // uses it for the drawer.
+ // A field is known by whose form it is, its form's key and its own
+ // name. Whose: the enclosing decision's task (the Needs you page holds
+ // several decisions, each with a More options form keyed "more"), else
+ // the form's action, so one task's note never lands in another's.
+ // team-panel.js uses it for the drawer.
window.equipoKeepDrafts = function (old) {
function key(el) {
var f = el.closest("form[data-draft-key]");
- return f && el.name ? f.dataset.draftKey + " " + el.name : "";
+ if (!f || !el.name) return "";
+ var d = f.closest("[data-decision]");
+ return [d ? "task " + d.dataset.decision : "action " + (f.getAttribute("action") || ""), f.dataset.draftKey, el.name].join("\n");
}
function fields(root) {
return root.querySelectorAll("form[data-draft-key] textarea, form[data-draft-key] select, form[data-draft-key] input:not([type=hidden])");
diff --git a/internal/equipo/team_taste_browser_test.go b/internal/equipo/team_taste_browser_test.go
index 8da4e381..134ef64a 100644
--- a/internal/equipo/team_taste_browser_test.go
+++ b/internal/equipo/team_taste_browser_test.go
@@ -134,3 +134,81 @@ func TestBrowserTasteDrafts(t *testing.T) {
t.Errorf("script errors: %s", got)
}
}
+
+// TestBrowserNeedsDrafts (Task 8 review, fix round 2): the Needs you page
+// renders several decisions in one live region, each with a More options
+// form keyed "more" and a field named note. A refresh keeps each
+// decision's note in its own form: the key is scoped by the decision's
+// task, so one note never overwrites or joins another task's.
+func TestBrowserNeedsDrafts(t *testing.T) {
+ var lines []taskLine
+ for _, id := range []string{"tk1", "tk2"} {
+ c := feedbackTask(feedbackRounds())
+ c.task.ID, c.card.ID, c.card.TaskID = id, "c"+id, id
+ line := taskLine{Task: c.task, Card: c.card}
+ line.Decision = decisionOf(c.task, line)
+ if line.Decision == nil || !line.Decision.More {
+ t.Fatalf("%s: no decision with More options", id)
+ }
+ lines = append(lines, line)
+ }
+ var content bytes.Buffer
+ if err := pages["work_needs"].ExecuteTemplate(&content, "content", pageData{Thin: workView{Decisions: lines}}); err != nil {
+ t.Fatal(err)
+ }
+ head := fmt.Sprintf(`<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="%s"><link rel="stylesheet" href="%s"><link rel="stylesheet" href="%s">`+
+ `<script>window.errors = []; addEventListener("error", e => errors.push(String(e.message)));</script><script defer src="%s"></script></head><body>`,
+ assets.Path("static/tokens.css"), assets.Path("static/theme.css"), assets.Path("static/equipo.css"), assets.Path("static/work-stream.js"))
+ mux := http.NewServeMux()
+ mux.Handle("GET /static/", assets.Handler())
+ mux.HandleFunc("GET /needs-you", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ fmt.Fprint(w, head+content.String()+`</body></html>`)
+ })
+ mux.HandleFunc("GET /tasks/{task}/files/{id}", func(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) })
+ server := httptest.NewServer(mux) // 127.0.0.1
+ defer server.Close()
+
+ opts := append(chromedp.DefaultExecAllocatorOptions[:], chromedp.ExecPath(harness.ChromePath(t)), chromedp.NoSandbox, chromedp.UserDataDir(t.TempDir()))
+ alloc, stop := chromedp.NewExecAllocator(context.Background(), opts...)
+ defer stop()
+ ctx, cancel := chromedp.NewContext(alloc)
+ defer cancel()
+ ctx, timeout := context.WithTimeout(ctx, 60*time.Second)
+ defer timeout()
+ run := func(a chromedp.Action[chromedp.Void]) {
+ t.Helper()
+ if _, err := chromedp.Run(ctx, a); err != nil {
+ t.Fatal(err)
+ }
+ }
+ eval := func(js string) string {
+ t.Helper()
+ out, err := chromedp.Run(ctx, chromedp.Evaluate[string](js, chromedp.EvalAwaitPromise))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return out
+ }
+ note := func(task string) string {
+ return `document.querySelector('[data-decision="` + task + `"] form[data-draft-key="more"] [name=note]')`
+ }
+ run(chromedp.Navigate(server.URL + "/needs-you"))
+ if got := eval(`new Promise(r => setTimeout(() => r(document.querySelectorAll('form[data-draft-key="more"] [name=note]').length + " " + errors.join(";")), 300))`); got != "2 " {
+ t.Fatalf("More options notes on the page: %s", got)
+ }
+ // A swap waits while a form has the focus: type each, then move on.
+ for task, text := range map[string]string{"tk1": "fewer colours", "tk2": "bigger type"} {
+ eval(`(` + note(task) + `.focus(), "")`)
+ run(chromedp.KeyEvent(text))
+ }
+ eval(`(document.activeElement.blur(), document.querySelector("#work-needs").dataset.old = "1", document.dispatchEvent(new Event("equipo:work")), "")`)
+ if got := eval(`new Promise(r => { const t0 = Date.now(); (function wait() { const s = document.querySelector("#work-needs"); if (s && !s.dataset.old) return r("ok"); if (Date.now() - t0 > 5000) return r("no refresh " + errors.join(";")); setTimeout(wait, 50); })(); })`); got != "ok" {
+ t.Fatal(got)
+ }
+ for task, want := range map[string]string{"tk1": "fewer colours", "tk2": "bigger type"} {
+ if got := eval(note(task) + `.value`); got != want {
+ t.Errorf("after the refresh %s's More options note holds %q, want %q", task, got, want)
+ }
+ }
+}