Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fill_login: treat whitespace usernames as blank; only ask for a username when one exists
AdityaUmale57717bea732b
diff --git a/server/login-fill.test.ts b/server/login-fill.test.tsindex fbd4f28fc0..64888b0dd5 100644--- a/server/login-fill.test.ts+++ b/server/login-fill.test.ts@@ -361,6 +361,27 @@ describe("one-time codes and fields", () => {expect(page.typed).toEqual([]);});+ it("counts whitespace-only usernames as blank", async () => {+ const saved = [{ host: "example.com", username: " " }, { host: "example.com", username: "alice" }];+ const { fill } = setup("https://example.com/login", LOGIN_FORM, saved, { submit: false });+ expect((await fill()).text).toMatch(/^There are 2 saved logins for example\.com: alice, 1 with no username saved\. /);+ });++ it("asks for no username when every saved login has none", async () => {+ const saved = [{ host: "example.com", username: "" }, { host: "example.com", username: "" }];+ const { page, fill } = setup("https://example.com/login", LOGIN_FORM, saved, { submit: false });+ const text = (await fill()).text;+ expect(text).toMatch(/^There are 2 saved logins for example\.com: 2 with no username saved\. /);+ expect(text).not.toContain("Call fill_login again with the username");+ expect(page.typed).toEqual([]);+ });++ it("offers a retry without a username when the only saved login has none", async () => {+ const { fill } = setup("https://example.com/login", LOGIN_FORM, [{ host: "example.com", username: "" }], { submit: false });+ expect((await fill("carol")).text).toMatch(/1 with no username saved\. .* Or call fill_login again without a username to use that one login\.$/);+ expect(await fill()).toMatchObject({ ok: true });+ });+it("says when the page has no login fields", async () => {const { page, fill } = setup("https://example.com/", `<main><input type="search" name="q"><input type="hidden" name="x"></main>`, [{ host: "example.com", username: "alice" }]);const outcome = await fill();diff --git a/server/login-fill.ts b/server/login-fill.tsindex c4b96978d7..f1b6994776 100644--- a/server/login-fill.ts+++ b/server/login-fill.ts@@ -305,8 +305,12 @@ function listed(logins: Array<LoginPlace & { username: string }>): string {return `Your saved logins: ${shown.join(", ")}${logins.length > shown.length ? ` and ${logins.length - shown.length} more` : ""}.`;}+function hasUsername(login: FillCandidate): boolean {+ return login.username.trim() !== "";+}+function usernames(logins: FillCandidate[]): string {- const named = logins.map((login) => login.username).filter(Boolean);+ const named = logins.filter(hasUsername).map((login) => login.username);const blank = logins.length - named.length;if (!blank) return `${named.join(", ")}.`;return `${[...named, `${blank} with no username saved`].join(", ")}. A login with no username can't be chosen by name: ask the person to add its username where it is saved (Settings → Vault, or the password manager it comes from), or call request_sign_in so the person signs in.`;@@ -392,11 +396,13 @@ export async function fillLogin(input: FillLoginInput, deps: FillLoginDeps): Proif (wanted) {chosen = all.filter((login) => login.username.toLowerCase() === wanted.toLowerCase());if (!chosen.length) {- return { ok: false, host: pageHost, text: `No saved login for ${pageHost} has the username ${JSON.stringify(wanted)}. The usernames saved there: ${usernames(all)}` };+ const onlyBlank = all.length === 1 && !hasUsername(all[0]!) ? " Or call fill_login again without a username to use that one login." : "";+ return { ok: false, host: pageHost, text: `No saved login for ${pageHost} has the username ${JSON.stringify(wanted)}. The usernames saved there: ${usernames(all)}${onlyBlank}` };}}if (chosen.length > 1) {- return { ok: false, host: pageHost, text: `There are ${chosen.length} saved logins for ${pageHost}: ${usernames(chosen)} Call fill_login again with the username to use.` };+ const byName = chosen.some(hasUsername) ? " Call fill_login again with the username to use." : "";+ return { ok: false, host: pageHost, text: `There are ${chosen.length} saved logins for ${pageHost}: ${usernames(chosen)}${byName}` };}const login = chosen[0]!;if (!loginOriginCheck(pageUrl, login).ok) {