import { describe, expect, it } from "vitest"; import { browserUserContextLine, coalesceBrowserUserActions, maskBrowserUserDetail, } from "./browser-cowork.js"; describe("browser cowork context", () => { it("masks password-like labels and fields", () => { expect(maskBrowserUserDetail("secret-token-value", true)).toBe("••••••"); expect(maskBrowserUserDetail("Password field", false)).toBe("••••••"); }); it("formats user navigation lines", () => { expect(browserUserContextLine("navigate", "https://example.com")).toBe( "User navigated to https://example.com", ); expect(browserUserContextLine("type", "hello", true)).toBe("User typed in a password field"); }); it("coalesces repeated scrolls, typing bursts, and navigate-to-page_change echoes", () => { const lines = coalesceBrowserUserActions([ { kind: "navigate", detail: "https://example.com/login" }, { kind: "page_change", detail: "https://example.com/login" }, { kind: "scroll", detail: "down" }, { kind: "scroll", detail: "down" }, { kind: "scroll", detail: "down" }, { kind: "type", detail: "al" }, { kind: "type", detail: "ice" }, { kind: "type", detail: "pw1", passwordField: true }, { kind: "type", detail: "pw2", passwordField: true }, ]); expect(lines).toEqual([ "User navigated to https://example.com/login", "User scrolled down (3x)", "User typed alice", "User typed in a password field", ]); }); });