diff --git a/README.md b/README.md
index bb59a93e..b03eb17b 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,7 @@ npm run dev:e2e
npm run auth:e2e:save
```
-Reset with `npm run e2e:local:reset` before a full run, then save auth again because reset replaces the local user. See [`docs/agents/local-e2e.md`](./docs/agents/local-e2e.md) for fixture IDs, safety rules, lifecycle commands, and verification.
+Reset with `npm run e2e:local:reset` before a full run, then save auth again because reset replaces the local user. To test on a phone, open the Wi-Fi address that `dev:e2e` prints and paste the code from `npm run auth:e2e:copy-code`. Claude has its own local account, which **Sign in as Claude** selects and `npm run auth:e2e:save:claude` saves. See [`docs/agents/local-e2e.md`](./docs/agents/local-e2e.md) for fixture IDs, safety rules, lifecycle commands, and verification.
The existing-account flow below remains available for non-destructive local checks against a configured development project. Do not use it for the resettable browser suite.
diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx
index 72f92f24..29cc3e6c 100644
--- a/app/(auth)/login/page.tsx
+++ b/app/(auth)/login/page.tsx
@@ -9,7 +9,7 @@ import { ClearPrivateBrowserCache } from "@/components/ui/ClearPrivateBrowserCac
import { PageHeader } from "@/components/ui/PageHeader";
import { getCurrentUser } from "@/lib/auth";
import { getLoginAuthError } from "@/lib/server/login-error";
-import { getLocalLoginPageState } from "@/lib/server/local-test-login";
+import { CLAUDE_LOCAL_LOGIN_ACCOUNT, getLocalLoginPageState } from "@/lib/server/local-test-login";
type LoginPageProps = {
searchParams: Promise<{
@@ -24,7 +24,7 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
const user = await getCurrentUser();
const requestHeaders = await headers();
const host = requestHeaders.get("host") || "";
- const { requiresPairingCode, showLocalLogin } = getLocalLoginPageState(host);
+ const { requiresPairingCode, showClaudeLogin, showLocalLogin } = getLocalLoginPageState(host);
const localError =
params.localError === "pairing-code"
? "That local pairing code was not accepted. Copy the current code from your Mac and try again."
@@ -92,13 +92,27 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
type="password"
/>
- On your Mac, run npm run auth:local:copy-code, then paste the code here.
+ On your Mac, run npm run{" "}
+ {process.env.POKENOTES_E2E_LOCAL === "1"
+ ? "auth:e2e:copy-code"
+ : "auth:local:copy-code"}
+ , then paste the code here.
) : null}
+ {showClaudeLogin ? (
+
+ ) : null}
{showLocalLogin ? (
diff --git a/app/auth/dev-login/route.ts b/app/auth/dev-login/route.ts
index b3a0aeb1..a42f5bd1 100644
--- a/app/auth/dev-login/route.ts
+++ b/app/auth/dev-login/route.ts
@@ -40,6 +40,7 @@ export async function POST(request: NextRequest) {
}
const pairingCode = String(formData.get("pairingCode") || "");
const validation = validateLocalLoginAttempt({
+ account: String(formData.get("account") || "") || null,
host: request.headers.get("host"),
origin: request.headers.get("origin"),
pairingCode,
diff --git a/docs/agents/local-e2e.md b/docs/agents/local-e2e.md
index 99cec8ea..5b918aa0 100644
--- a/docs/agents/local-e2e.md
+++ b/docs/agents/local-e2e.md
@@ -31,6 +31,21 @@ The isolated app runs at `http://localhost:3010`, alongside the normal watchdog-
The setup command writes ignored, mode-`0600` credentials to `.env.e2e.local`. Do not print, copy into documentation, or commit that file.
+## Phone, iOS Simulator, and Claude's account
+
+`npm run dev:e2e` listens on every interface and prints the Wi-Fi addresses a phone can use, such as `http://.local:3010` or `http://192.168.x.y:3010`. It discovers those addresses each time it starts, adds them to the pairing-login host list and to Next.js `allowedDevOrigins`, and stores nothing, so a new network needs only a restart. The phone must be on the same Wi-Fi as the Mac. On the Mac, run `npm run auth:e2e:copy-code`, then paste into the phone's pairing-code field with Universal Clipboard.
+
+The iOS Simulator shares the Mac's network, so `http://localhost:3010` works in its Safari. Agents drive it with the T3 device tools (`device_list`, `device_open`, then the returned `agent-device` command) and should use the Wi-Fi address when the check is meant to stand in for a phone.
+
+The reset seeds two accounts:
+
+| Account | Use |
+| --- | --- |
+| `e2e@pokenotes.local` (E2E Trainer) | The fixture account below. Browser journeys assert on it; **Sign in locally** selects it. |
+| `claude@pokenotes.local` (Claude Tester) | Claude's own account. It starts empty, so agent checks create their own state through the UI. **Sign in as Claude** selects it. |
+
+Save Claude's agent-browser state with `npm run auth:e2e:save:claude`; it is written to `.agent-browser/pokenotes-e2e-claude-auth.json`. Both accounts share the pairing code, and a reset recreates both, so save both states again after every reset. Uploaded profile photos load from `127.0.0.1:54321` and do not appear on a physical phone; preset avatars do.
+
## Routine use
For the complete Battle Log import check, run:
@@ -116,7 +131,7 @@ npm run e2e:local:stop
## Fixture contract
-Each reset creates one confirmed synthetic account, `e2e@pokenotes.local`, with stable application IDs:
+Each reset creates one confirmed synthetic fixture account, `e2e@pokenotes.local`, with stable application IDs, plus Claude's empty account described above:
| Area | Stable fixtures |
| --- | --- |
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 9e723f34..3a69790b 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -11,6 +11,13 @@ export default [
"react-hooks/set-state-in-effect": "off"
}
},
+ {
+ // CommonJS files can only load their dependencies with require().
+ files: ["**/*.cjs", "next.config.js"],
+ rules: {
+ "@typescript-eslint/no-require-imports": "off"
+ }
+ },
{
ignores: [
"node_modules/**",
diff --git a/lib/server/local-test-login.ts b/lib/server/local-test-login.ts
index 698ca35b..8b80e758 100644
--- a/lib/server/local-test-login.ts
+++ b/lib/server/local-test-login.ts
@@ -7,8 +7,13 @@ type LocalLoginEnvironment = {
POKE_NOTES_LOCAL_LOGIN_HOSTS?: string;
POKE_NOTES_TEST_LOGIN_EMAIL?: string;
POKE_NOTES_TEST_LOGIN_PASSWORD?: string;
+ POKE_NOTES_CLAUDE_LOGIN_EMAIL?: string;
+ POKE_NOTES_CLAUDE_LOGIN_PASSWORD?: string;
};
+/** Form value that selects Claude's own local test account instead of the default one. */
+export const CLAUDE_LOCAL_LOGIN_ACCOUNT = "claude";
+
const LOOPBACK_HOSTS = new Set(["localhost:3000", "127.0.0.1:3000", "[::1]:3000"]);
function normalizeHost(value: string | null | undefined) {
@@ -31,12 +36,23 @@ export function isAllowedLocalLoginHost(
return getAllowedLocalLoginHosts(environment).has(normalizeHost(host));
}
-function getLocalLoginConfig(environment: LocalLoginEnvironment = process.env) {
+function getLocalLoginConfig(
+ environment: LocalLoginEnvironment = process.env,
+ account?: string | null
+) {
const enabled =
environment.NODE_ENV === "development" &&
environment.POKE_NOTES_ENABLE_TEST_LOGIN === "1";
- const email = String(environment.POKE_NOTES_TEST_LOGIN_EMAIL || "");
- const password = String(environment.POKE_NOTES_TEST_LOGIN_PASSWORD || "");
+ const claude = account === CLAUDE_LOCAL_LOGIN_ACCOUNT;
+ const email = String(
+ (claude ? environment.POKE_NOTES_CLAUDE_LOGIN_EMAIL : environment.POKE_NOTES_TEST_LOGIN_EMAIL) ||
+ ""
+ );
+ const password = String(
+ (claude
+ ? environment.POKE_NOTES_CLAUDE_LOGIN_PASSWORD
+ : environment.POKE_NOTES_TEST_LOGIN_PASSWORD) || ""
+ );
const pairingCode = String(environment.POKE_NOTES_LOCAL_LOGIN_CODE || "");
return {
@@ -55,21 +71,26 @@ export function getLocalLoginPageState(
const allowedHost = isAllowedLocalLoginHost(host, environment);
const requiresPairingCode = allowedHost;
+ const showLocalLogin = Boolean(config.configured && allowedHost);
+
return {
- showLocalLogin: Boolean(config.configured && allowedHost),
+ showLocalLogin,
+ showClaudeLogin:
+ showLocalLogin && getLocalLoginConfig(environment, CLAUDE_LOCAL_LOGIN_ACCOUNT).configured,
requiresPairingCode
};
}
export function validateLocalLoginRequest(
input: {
+ account?: string | null | undefined;
host: string | null | undefined;
origin: string | null | undefined;
secFetchSite?: string | null | undefined;
},
environment: LocalLoginEnvironment = process.env
) {
- const config = getLocalLoginConfig(environment);
+ const config = getLocalLoginConfig(environment, input.account);
const host = normalizeHost(input.host);
if (!config.configured || !isAllowedLocalLoginHost(host, environment)) {
@@ -100,6 +121,7 @@ export function validateLocalLoginRequest(
export function validateLocalLoginAttempt(
input: {
+ account?: string | null | undefined;
host: string | null | undefined;
origin: string | null | undefined;
pairingCode: string;
diff --git a/next.config.js b/next.config.js
index e739a5cc..23b3d9be 100644
--- a/next.config.js
+++ b/next.config.js
@@ -1,3 +1,5 @@
+const { localNetworkHostnames } = require("./scripts/local-network-hosts.cjs");
+
const baselineSecurityHeaders = [
{
key: "Permissions-Policy",
@@ -20,7 +22,8 @@ const baselineSecurityHeaders = [
/** @type {import('next').NextConfig} */
const nextConfig = {
distDir: process.env.POKENOTES_E2E_LOCAL === "1" ? ".next-e2e" : ".next",
- allowedDevOrigins: ["192.168.1.195", "Jamess-MacBook-Pro-2.local"],
+ // Lets a phone on the same Wi-Fi load dev assets from whatever address this Mac has today.
+ allowedDevOrigins: process.env.NODE_ENV === "production" ? [] : localNetworkHostnames(),
async headers() {
return [
{
diff --git a/package.json b/package.json
index 50937fe0..cc7adfe2 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,8 @@
"auth:local:setup": "node scripts/setup-local-test-login.mjs",
"auth:local:save": "node scripts/save-local-auth-state.mjs",
"auth:e2e:save": "node scripts/local-e2e.mjs save-auth",
+ "auth:e2e:save:claude": "node scripts/local-e2e.mjs save-auth --account=claude",
+ "auth:e2e:copy-code": "node scripts/local-e2e.mjs copy-code",
"e2e:local:setup": "node scripts/local-e2e.mjs setup",
"e2e:local:reset": "node scripts/local-e2e.mjs reset",
"e2e:local:start": "node scripts/local-e2e.mjs start",
diff --git a/scripts/local-e2e.mjs b/scripts/local-e2e.mjs
index 3ffcacf1..b63b0d1c 100644
--- a/scripts/local-e2e.mjs
+++ b/scripts/local-e2e.mjs
@@ -15,6 +15,7 @@ import { delimiter, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { config as loadDotenv, parse as parseDotenv } from "dotenv";
import { waitForLocalSchema } from "./local-e2e-readiness.mjs";
+import localNetworkHosts from "./local-network-hosts.cjs";
const rootDir = resolve(fileURLToPath(new URL("..", import.meta.url)));
const e2eDir = resolve(rootDir, "tests/e2e");
@@ -26,6 +27,8 @@ const tsxBin = resolve(rootDir, "node_modules/.bin/tsx");
const nextBin = resolve(rootDir, "node_modules/.bin/next");
const dockerBinDir = "/Applications/Docker.app/Contents/Resources/bin";
const command = process.argv[2] || "status";
+const appPort = 3010;
+const claudeEmail = "claude@pokenotes.local";
const localSupabaseArgs = ["--workdir", "tests/e2e"];
const excludedServices = [
"realtime",
@@ -73,11 +76,12 @@ const commands = {
stop,
status,
dev,
- "save-auth": saveAuth
+ "save-auth": saveAuth,
+ "copy-code": copyCode
};
if (!commands[command]) {
- throw new Error(`Unknown command ${JSON.stringify(command)}. Use setup, reset, start, stop, status, dev, or save-auth.`);
+ throw new Error(`Unknown command ${JSON.stringify(command)}. Use setup, reset, start, stop, status, dev, save-auth, or copy-code.`);
}
await commands[command]();
@@ -277,6 +281,8 @@ async function reset() {
const previousEnvironment = readExistingE2eEnvironment();
const password = previousEnvironment.POKE_NOTES_TEST_LOGIN_PASSWORD
|| `Local-${randomBytes(18).toString("base64url")}!9`;
+ const claudePassword = previousEnvironment.POKE_NOTES_CLAUDE_LOGIN_PASSWORD
+ || `Local-${randomBytes(18).toString("base64url")}!9`;
const pairingCode = previousEnvironment.POKE_NOTES_LOCAL_LOGIN_CODE
|| randomBytes(18).toString("base64url");
const authClaimsSecret = previousEnvironment.POKENOTES_AUTH_CLAIMS_SECRET
@@ -286,7 +292,9 @@ async function reset() {
NEXT_PUBLIC_SUPABASE_URL: apiUrl,
SUPABASE_SERVICE_ROLE_KEY: serviceRoleKey,
POKE_NOTES_TEST_LOGIN_EMAIL: "e2e@pokenotes.local",
- POKE_NOTES_TEST_LOGIN_PASSWORD: password
+ POKE_NOTES_TEST_LOGIN_PASSWORD: password,
+ POKE_NOTES_CLAUDE_LOGIN_EMAIL: claudeEmail,
+ POKE_NOTES_CLAUDE_LOGIN_PASSWORD: claudePassword
});
console.log("Waiting for the recreated local schema to become readable through PostgREST.");
@@ -309,6 +317,8 @@ async function reset() {
"POKE_NOTES_LOCAL_LOGIN_HOSTS=localhost:3010,127.0.0.1:3010,[::1]:3010",
"POKE_NOTES_TEST_LOGIN_EMAIL=e2e@pokenotes.local",
`POKE_NOTES_TEST_LOGIN_PASSWORD=${password}`,
+ `POKE_NOTES_CLAUDE_LOGIN_EMAIL=${claudeEmail}`,
+ `POKE_NOTES_CLAUDE_LOGIN_PASSWORD=${claudePassword}`,
""
].join("\n");
@@ -351,19 +361,45 @@ async function dev() {
throw new Error("Refusing to start: the E2E local-only marker is missing.");
}
assertLocalUrl(String(process.env.NEXT_PUBLIC_SUPABASE_URL || ""));
- await spawnAndForward(nextBin, ["dev", "-H", "0.0.0.0", "--port", "3010"], localEnvironment());
+ // Discovered at start, not stored, because the Mac's Wi-Fi address changes between networks.
+ const lanHosts = localNetworkHosts.localNetworkHostnames();
+ const loginHosts = new Set([
+ ...String(process.env.POKE_NOTES_LOCAL_LOGIN_HOSTS || "").split(",").filter(Boolean),
+ ...lanHosts.map((hostname) => `${hostname}:${appPort}`)
+ ]);
+ if (lanHosts.length > 0) {
+ console.log(`On a phone on the same Wi-Fi, open ${lanHosts.map((hostname) => `http://${hostname}:${appPort}`).join(" or ")}.`);
+ console.log("Run npm run auth:e2e:copy-code on this Mac and paste the code on the phone (Universal Clipboard).");
+ }
+ await spawnAndForward(
+ nextBin,
+ ["dev", "-H", "0.0.0.0", "--port", String(appPort)],
+ localEnvironment({ POKE_NOTES_LOCAL_LOGIN_HOSTS: Array.from(loginHosts).join(",") })
+ );
+}
+
+async function copyCode() {
+ const pairingCode = readExistingE2eEnvironment().POKE_NOTES_LOCAL_LOGIN_CODE;
+ if (!pairingCode) {
+ throw new Error("Missing .env.e2e.local. Run npm run e2e:local:setup first.");
+ }
+ run("pbcopy", [], { capture: true, input: pairingCode });
+ console.log("Local E2E pairing code copied to the macOS clipboard; its value was not printed.");
}
async function saveAuth() {
if (!existsSync(envFile)) {
throw new Error("Missing .env.e2e.local. Run npm run e2e:local:setup first.");
}
+ const claude = process.argv.slice(3).includes("--account=claude");
await spawnAndForward(
process.execPath,
[
"scripts/save-local-auth-state.mjs",
- "--base-url=http://localhost:3010",
- "--state=.agent-browser/pokenotes-e2e-auth.json"
+ `--base-url=http://localhost:${appPort}`,
+ ...(claude
+ ? ["--account=claude", "--state=.agent-browser/pokenotes-e2e-claude-auth.json"]
+ : ["--state=.agent-browser/pokenotes-e2e-auth.json"])
],
localEnvironment({ POKENOTES_ENV_FILE: ".env.e2e.local" })
);
diff --git a/scripts/local-network-hosts.cjs b/scripts/local-network-hosts.cjs
new file mode 100644
index 00000000..cd2180df
--- /dev/null
+++ b/scripts/local-network-hosts.cjs
@@ -0,0 +1,50 @@
+// Hostnames a phone on the same Wi-Fi can use to reach this Mac's dev server.
+// CommonJS so next.config.js can require it as well as the .mjs scripts.
+
+const { execFileSync } = require("node:child_process");
+const { networkInterfaces } = require("node:os");
+
+function isPrivateIpv4(address) {
+ const octets = address.split(".").map(Number);
+ if (octets.length !== 4 || octets.some((octet) => !Number.isInteger(octet))) {
+ return false;
+ }
+
+ return (
+ octets[0] === 10 ||
+ (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) ||
+ (octets[0] === 192 && octets[1] === 168) ||
+ (octets[0] === 169 && octets[1] === 254)
+ );
+}
+
+/** Private IPv4 addresses plus the macOS Bonjour name (`.local`), without ports. */
+function localNetworkHostnames() {
+ const hosts = new Set();
+
+ for (const addresses of Object.values(networkInterfaces())) {
+ for (const address of addresses ?? []) {
+ if (address.family === "IPv4" && !address.internal && isPrivateIpv4(address.address)) {
+ hosts.add(address.address);
+ }
+ }
+ }
+
+ if (process.platform === "darwin") {
+ try {
+ const localHostName = execFileSync("scutil", ["--get", "LocalHostName"], {
+ encoding: "utf8",
+ stdio: ["ignore", "pipe", "ignore"]
+ }).trim();
+ if (localHostName) {
+ hosts.add(`${localHostName}.local`);
+ }
+ } catch {
+ // The private IP remains available when the Bonjour name cannot be read.
+ }
+ }
+
+ return Array.from(hosts);
+}
+
+module.exports = { localNetworkHostnames };
diff --git a/scripts/save-local-auth-state.mjs b/scripts/save-local-auth-state.mjs
index bf2d7ad9..d34eb34b 100644
--- a/scripts/save-local-auth-state.mjs
+++ b/scripts/save-local-auth-state.mjs
@@ -41,6 +41,14 @@ const baseUrlParts = new URL(baseUrl);
const statePath = resolve(String(args.get("--state") || ".agent-browser/pokenotes-local-auth.json"));
const session = String(args.get("--session") || `pokenotes-local-auth-${Date.now()}`);
const pairingCode = String(process.env.POKE_NOTES_LOCAL_LOGIN_CODE || "");
+const account = String(args.get("--account") || "");
+
+if (account && account !== "claude") {
+ throw new Error(`Unknown local account "${account}". Use --account=claude or omit it.`);
+}
+if (account === "claude" && !process.env.POKE_NOTES_CLAUDE_LOGIN_EMAIL) {
+ throw new Error("Claude's local account is not configured. Run npm run e2e:local:reset first.");
+}
if (!existsSync(agentBrowserBin)) {
throw new Error("agent-browser is not installed. Run npm install first.");
@@ -67,7 +75,9 @@ if (currentUrl.pathname === "/login") {
]);
runAgentBrowser([
"click",
- 'form[action="/auth/dev-login"] button[type="submit"]'
+ account
+ ? `form[action="/auth/dev-login"] button[name="account"][value="${account}"]`
+ : 'form[action="/auth/dev-login"] button[type="submit"]:not([name])'
]);
}
runAgentBrowser([
diff --git a/scripts/seed-local-e2e.ts b/scripts/seed-local-e2e.ts
index f4cad07e..db9d4db8 100644
--- a/scripts/seed-local-e2e.ts
+++ b/scripts/seed-local-e2e.ts
@@ -12,6 +12,10 @@ const apiUrl = String(process.env.NEXT_PUBLIC_SUPABASE_URL || "");
const serviceRoleKey = String(process.env.SUPABASE_SERVICE_ROLE_KEY || "");
const email = String(process.env.POKE_NOTES_TEST_LOGIN_EMAIL || "");
const password = String(process.env.POKE_NOTES_TEST_LOGIN_PASSWORD || "");
+const claudeEmail = String(process.env.POKE_NOTES_CLAUDE_LOGIN_EMAIL || "");
+const claudePassword = String(
+ process.env.POKE_NOTES_CLAUDE_LOGIN_PASSWORD || "",
+);
assertLocalOnly();
@@ -278,6 +282,47 @@ async function main() {
console.log(
"Seeded one synthetic account with 2 decks, 2 lists, 1 matchup, 1 tournament, 1 round, and 3 logs.",
);
+
+ if (claudeEmail && claudePassword) {
+ await seedClaudeAccount();
+ console.log(
+ `Seeded Claude's own empty account, ${claudeEmail}, for agent checks.`,
+ );
+ }
+}
+
+// Claude's account starts empty so agent checks create their own state through the UI
+// without touching the fixture account the browser journeys assert on.
+async function seedClaudeAccount() {
+ const { data, error } = await client.auth.admin.createUser({
+ email: claudeEmail,
+ password: claudePassword,
+ email_confirm: true,
+ user_metadata: {
+ full_name: "Claude Tester",
+ given_name: "Claude",
+ family_name: "Tester",
+ },
+ });
+ if (error || !data.user) {
+ throw new Error(
+ `Could not create Claude's local account: ${error?.message || "missing user"}`,
+ );
+ }
+
+ await insert("profiles", {
+ id: data.user.id,
+ display_name: "Claude Tester",
+ first_name: "Claude",
+ last_name: "Tester",
+ email: claudeEmail,
+ ptcgl_username: "ClaudeTester",
+ role: "user",
+ avatar_color: "blue",
+ auth_account_created_at: now,
+ created_at: now,
+ updated_at: now,
+ });
}
main().catch((error) => {
diff --git a/scripts/setup-local-test-login.mjs b/scripts/setup-local-test-login.mjs
index 4ca0b3ee..855847ef 100644
--- a/scripts/setup-local-test-login.mjs
+++ b/scripts/setup-local-test-login.mjs
@@ -1,13 +1,12 @@
#!/usr/bin/env node
-import { execFileSync } from "node:child_process";
import { randomBytes } from "node:crypto";
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
-import { networkInterfaces } from "node:os";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { createClient } from "@supabase/supabase-js";
import { config as loadDotenv } from "dotenv";
+import localNetworkHosts from "./local-network-hosts.cjs";
const rootDir = resolve(fileURLToPath(new URL("..", import.meta.url)));
const envPath = resolve(rootDir, ".env");
@@ -135,28 +134,8 @@ function discoverLocalLoginHosts() {
`[::1]:${port}`
]);
- for (const addresses of Object.values(networkInterfaces())) {
- for (const address of addresses ?? []) {
- if (address.family === "IPv4" && !address.internal) {
- if (isPrivateIpv4(address.address)) {
- hosts.add(`${address.address}:${port}`);
- }
- }
- }
- }
-
- if (process.platform === "darwin") {
- try {
- const localHostName = execFileSync("scutil", ["--get", "LocalHostName"], {
- encoding: "utf8",
- stdio: ["ignore", "pipe", "ignore"]
- }).trim();
- if (localHostName) {
- hosts.add(`${localHostName}.local:${port}`);
- }
- } catch {
- // The discovered private IP remains available when mDNS lookup is unavailable.
- }
+ for (const hostname of localNetworkHosts.localNetworkHostnames()) {
+ hosts.add(`${hostname}:${port}`);
}
for (const configuredHost of String(process.env.POKE_NOTES_LOCAL_LOGIN_HOSTS || "").split(",")) {
@@ -169,20 +148,6 @@ function discoverLocalLoginHosts() {
return Array.from(hosts).join(",");
}
-function isPrivateIpv4(address) {
- const octets = address.split(".").map(Number);
- if (octets.length !== 4 || octets.some((octet) => !Number.isInteger(octet))) {
- return false;
- }
-
- return (
- octets[0] === 10 ||
- (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) ||
- (octets[0] === 192 && octets[1] === 168) ||
- (octets[0] === 169 && octets[1] === 254)
- );
-}
-
async function listAllAuthUsers() {
const users = [];
let page = 1;
diff --git a/scripts/verify-local-import.mjs b/scripts/verify-local-import.mjs
index 9eb710a1..7bc0e6e9 100644
--- a/scripts/verify-local-import.mjs
+++ b/scripts/verify-local-import.mjs
@@ -102,7 +102,7 @@ try {
await page.locator('form[action="/auth/dev-login"] input[name="pairingCode"]').fill(environment.POKE_NOTES_LOCAL_LOGIN_CODE);
await Promise.all([
page.waitForURL(`${baseUrl}/dashboard`),
- page.locator('form[action="/auth/dev-login"] button[type="submit"]').click()
+ page.locator('form[action="/auth/dev-login"] button[type="submit"]:not([name])').click()
]);
await verifyLogsBootstrap();
await page.getByRole("button", { name: "E2E Trainer e2e@pokenotes.local", exact: true }).waitFor();
@@ -830,7 +830,7 @@ async function verifyLogsBootstrap() {
await page.locator('form[action="/auth/dev-login"] input[name="pairingCode"]').fill(environment.POKE_NOTES_LOCAL_LOGIN_CODE);
await Promise.all([
page.waitForURL(`${baseUrl}/dashboard`),
- page.locator('form[action="/auth/dev-login"] button[type="submit"]').click()
+ page.locator('form[action="/auth/dev-login"] button[type="submit"]:not([name])').click()
]);
await page.goto(`${baseUrl}/logs`);
await page.locator('[data-route-client-timing="route-data-visible"]').waitFor({ state: "attached" });
diff --git a/tests/local-test-login.test.ts b/tests/local-test-login.test.ts
index 102511c5..cdd4b506 100644
--- a/tests/local-test-login.test.ts
+++ b/tests/local-test-login.test.ts
@@ -31,6 +31,7 @@ test("local login is disabled in production even when every variable is populate
assert.deepEqual(getLocalLoginPageState("phone-mac.local:3000", environment), {
requiresPairingCode: true,
+ showClaudeLogin: false,
showLocalLogin: false
});
assert.deepEqual(
@@ -50,6 +51,7 @@ test("local login is disabled in production even when every variable is populate
test("loopback login requires the pairing code without putting it in a URL", () => {
assert.deepEqual(getLocalLoginPageState("localhost:3000", developmentEnvironment), {
requiresPairingCode: true,
+ showClaudeLogin: false,
showLocalLogin: true
});
@@ -86,6 +88,7 @@ test("loopback login requires the pairing code without putting it in a URL", ()
test("an explicitly allowed LAN host requires the local pairing code", () => {
assert.deepEqual(getLocalLoginPageState("phone-mac.local:3000", developmentEnvironment), {
requiresPairingCode: true,
+ showClaudeLogin: false,
showLocalLogin: true
});
@@ -156,7 +159,33 @@ test("LAN login stays hidden until a pairing code is configured", () => {
}),
{
requiresPairingCode: true,
+ showClaudeLogin: false,
showLocalLogin: false
}
);
});
+
+test("the Claude account signs in with its own credentials only when configured", () => {
+ const attempt = {
+ account: "claude",
+ host: "localhost:3000",
+ origin: "http://localhost:3000",
+ pairingCode: "correct-local-pairing-code",
+ secFetchSite: "same-origin"
+ };
+ const claudeEnvironment = {
+ ...developmentEnvironment,
+ POKE_NOTES_CLAUDE_LOGIN_EMAIL: "claude@example.invalid",
+ POKE_NOTES_CLAUDE_LOGIN_PASSWORD: "claude-password"
+ };
+
+ assert.equal(getLocalLoginPageState("localhost:3000", claudeEnvironment).showClaudeLogin, true);
+ const claude = validateLocalLoginAttempt(attempt, claudeEnvironment);
+ assert.equal(claude.allowed && claude.config.email, "claude@example.invalid");
+ const fallback = validateLocalLoginAttempt({ ...attempt, account: "" }, claudeEnvironment);
+ assert.equal(fallback.allowed && fallback.config.email, "test@example.invalid");
+ assert.deepEqual(validateLocalLoginAttempt(attempt, developmentEnvironment), {
+ allowed: false,
+ reason: "request"
+ });
+});