oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build e2elive && browser
2
3package e2elivetest
4
5import (
6 "context"
7 "net/http"
8 "net/url"
9 "testing"
10 "time"
11
12 "amadan.net/oficina/equipo/internal/browsertest"
13 "amadan.net/rastrillo/rastrillo/db"
14 "amadan.net/rastrillo/rastrillo/harness"
15 "github.com/chromedp/cdproto/cdp"
16 "github.com/chromedp/cdproto/network"
17 "github.com/chromedp/chromedp"
18)
19
20func liveSelfHeal(t *testing.T, c *http.Client, origin string, d *db.DB, startRunner func()) {
21 t.Helper()
22 rig := harness.New(t, func(string) http.Handler { return http.NotFoundHandler() })
23 u, _ := url.Parse(origin)
24 rig.Run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
25 cookies := []*network.CookieParam{}
26 for _, cookie := range c.Jar.Cookies(u) {
27 cookies = append(cookies, &network.CookieParam{Name: cookie.Name, Value: cookie.Value, URL: origin})
28 }
29 _, err := cdp.Call(ctx, target, network.SetCookies, network.SetCookiesParams{Cookies: cookies})
30 return err
31 }), chromedp.Navigate(origin+"/settings/coordinator"), browsertest.Wait(`!!document.querySelector('h1')`))
32 if !harness.Evaluate[bool](rig, `!document.querySelector('[name="connection_id"], [value="bind"], [value="reset"]')`) {
33 t.Fatal("coordinator picker remains")
34 }
35 rig.Run(chromedp.Navigate(origin+"/conversation"), browsertest.Wait(`!!document.querySelector('#composer')`))
36 if !harness.Evaluate[bool](rig, `(()=>{const f=document.querySelector('#composer');f.querySelector('textarea').value='Please set up amadan.net/oficina/e2e-unknown-repo. Use propose_project, then post_message asking me to use the setup card. After I accept the card, first call equipo_status, then call post_message with body exactly: Project ready with an inherited team budget. Deliver that reply through post_message, never a direct assistant response. Do not propose a plan or start specialist work.';f.requestSubmit();return !!document.querySelector('[equipo-thinking]')})()`) {
37 t.Fatal("thinking bubble missing")
38 }
39 startRunner()
40 delivered := func(n int) {
41 liveWait(t, "self-heal coordinator reply", 150*time.Second, func() bool {
42 var uncertain int
43 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM coordinator_turns WHERE state='uncertain'").Scan(&uncertain))
44 if uncertain > 0 {
45 t.Fatal("coordinator turn became uncertain")
46 }
47 var count int
48 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM coordinator_turns WHERE state='delivered'").Scan(&count))
49 return count == n
50 })
51 }
52 delivered(1)
53 liveWait(t, "first turn contained", 30*time.Second, func() bool {
54 var count int
55 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM coordinator_turns t JOIN attempts a ON a.id=t.attempt_id WHERE t.state='delivered' AND a.containment='contained'").Scan(&count))
56 return count == 1
57 })
58 rig.Run(chromedp.Navigate(origin + "/conversation"))
59 rig.Run(browsertest.Wait(`!!document.querySelector('form[action^="/conversation/projects/"]') && !document.querySelector('ol [equipo-thinking]')`))
60 rig.Run(browsertest.Click(`form[action^="/conversation/projects/"] button[value="setup"]`))
61 t.Log("project setup card submitted")
62 delivered(2)
63 var projects, denied, defaults, statusCalls int
64 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM project_proposals WHERE state='created' AND project_id>0").Scan(&projects))
65 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM coordinator_turns WHERE state='admission_denied'").Scan(&denied))
66 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM budget_records WHERE json_extract(config,'$.Projects') IS NULL").Scan(&defaults))
67 executionMust(t, d.Writer().QueryRow("SELECT count(*) FROM conversation_requests WHERE operation='coordinator.tool' AND input_hash<>'' AND result LIKE '%coordinator_limits%'").Scan(&statusCalls))
68 if projects != 1 || denied != 0 || defaults != 1 || statusCalls < 1 {
69 t.Fatalf("self heal: projects=%d denied=%d inherited=%d status=%d", projects, denied, defaults, statusCalls)
70 }
71 t.Log("no picker; project created by card; subsequent turn admitted with inherited budget; equipo_status used")
72}
73