Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
test(computer): prove the window settle wait counts from its candidate
jeffreyf10f41cd13b4
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.goindex d19ae54f..afa9f6a7 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go@@ -431,8 +431,7 @@ func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, u// so a home page that moves to another site, such as a sign-in page, still// finds its window. Windows that stay ambiguous are refused.func (c *cuaSession) everydayChromeWindow(ctx context.Context, b agentBrowser, pid int, before map[float64]bool, site string) (listedWindow, int, error) {- var seen time.Time- var candidate float64+ var wait windowSettlefor deadline := time.Now().Add(sharedBrowserWindowWait); ; {windows, err := c.appWindows(ctx, pid)if err != nil {@@ -448,17 +447,7 @@ func (c *cuaSession) everydayChromeWindow(ctx context.Context, b agentBrowser, pmatching = append(matching, w)}}- // The wait counts from when the lone candidate showed: one that- // left, or another in its place, starts it again.- switch {- case len(fresh) == 0:- seen = time.Time{}- case len(fresh) == 1 && fresh[0].WindowID != candidate:- seen, candidate = time.Now(), fresh[0].WindowID- case seen.IsZero():- seen = time.Now()- }- settled := !seen.IsZero() && time.Since(seen) >= everydayChromeSettle+ settled := wait.settled(fresh, time.Now())switch {case len(matching) == 1:return matching[0], 1, nil@@ -476,6 +465,29 @@ func (c *cuaSession) everydayChromeWindow(ctx context.Context, b agentBrowser, p}}+// windowSettle times how long the new windows of a launch have stood. The+// wait counts from when the lone candidate showed: one that left, or another+// in its place, starts it again, so a window that showed only briefly cannot+// lend its time to the window that follows it.+type windowSettle struct {+ seen time.Time+ candidate float64+}++// settled reports whether fresh, the new windows seen at now, have stood for+// everydayChromeSettle.+func (w *windowSettle) settled(fresh []listedWindow, now time.Time) bool {+ switch {+ case len(fresh) == 0:+ w.seen = time.Time{}+ case len(fresh) == 1 && fresh[0].WindowID != w.candidate:+ w.seen, w.candidate = now, fresh[0].WindowID+ case w.seen.IsZero():+ w.seen = now+ }+ return !w.seen.IsZero() && now.Sub(w.seen) >= everydayChromeSettle+}+// everydayChromeSettle is how long the Computer lets the user's Chrome// settle before it trusts what it sees: the window list must stay the same// that long after a start, since Chrome reopens restored windows one afterdiff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.goindex 7d56ca16..b5da6b0f 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go@@ -3,6 +3,7 @@ package localtoolsimport ("strings""testing"+ "time")func TestCountTabsReadsChromeEdgeAndFirefoxStrips(t *testing.T) {@@ -106,3 +107,23 @@ func TestAgentChromeHoldsEachWindowTheTaskOpened(t *testing.T) {t.Fatal("a window of the earlier browser is still held")}}++// A window that showed briefly lends no time to the one that takes its+// place: the settle wait counts from when the lone candidate showed.+func TestWindowSettleCountsFromTheCandidate(t *testing.T) {+ start := time.Unix(1000, 0)+ a, b := []listedWindow{{WindowID: 21}}, []listedWindow{{WindowID: 22}}+ var wait windowSettle+ if wait.settled(a, start) {+ t.Fatal("window A settled when it showed")+ }+ if wait.settled(b, start.Add(everydayChromeSettle)) {+ t.Fatal("window B took the time window A stood")+ }+ if !wait.settled(b, start.Add(2*everydayChromeSettle)) {+ t.Fatal("window B did not settle after standing the settle time")+ }+ if wait.settled(nil, start.Add(3*everydayChromeSettle)) || wait.settled(b, start.Add(3*everydayChromeSettle)) {+ t.Fatal("window B settled again at once after it left and came back")+ }+}