diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e9d4f6..60ab5230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,19 @@ All notable user-visible changes are recorded here. Versions follow [Semantic Ve `blog/posts/`, and the build renders the index, each post, an RSS feed and a sitemap as static pages. See blog/README.md. - `/blogs` and `/blogs//` redirect to the same page under `/blog/`. +- A one-screen landing page at `/start/` for paid traffic, to test against + the home page. It says what shell does in one line and gives the three + setup steps: install, start your agent (`shell claude`, or tap Codex, + Hermes, OpenCode or Cursor), and scan the QR code. On a phone, "Send these + steps to my laptop" opens the share sheet. The page gets the home page's + analytics and X pixel, is kept out of search results, and reports as its + own route (`start`, `landing_start` on the statistics dashboard). +- Ad-specific versions of `/start/`, set up in PostHog without a deploy. An ad + links to `/start/?utm_content=`, and the page takes that page's + headline, subline, step 2 agent and button text from the payload of the + `start-landing-pages` feature flag. An unknown page, or PostHog being slow or + blocked, shows the default page. Events from the visit record the page key + as `landing_variant`, so results can be compared page by page. - The installer runs a `shell` command once it has installed, by the new executable's full path, so one pasted line can install and link a machine before its install directory is on PATH: @@ -51,6 +64,25 @@ All notable user-visible changes are recorded here. Versions follow [Semantic Ve - Answers that resume after an idle pause continue in the same chat message. - Blue “Reading … as messages” notices are restored. Summary permission switches reflect a successful save immediately instead of waiting for the next poll. +- `npm run deploy:production` refuses a config that does not set + `POSTHOG_ENABLED` to `"0"` or `"1"`. Since 0.23.1 the relay has been + deployed with a config that left the flag out, and because Wrangler replaces + every Worker variable on deploy, relay analytics (downloads, installs, + sessions, viewers and MCP results) silently stopped on 23 September. The + accounts app was unaffected because its flag is committed. Production needs + `"POSTHOG_ENABLED": "1"` in `wrangler.production.jsonc` and a redeploy to + restore it. +- Starting `claude` (or `opencode`) from the app no longer reopens an old + agent conversation. Any `shell` command starts the background daemon when + none is running, and it passed on its whole environment. Run from inside + Claude Code, that included the conversation's id, so every session the app + then asked for was treated as a handoff and forked that conversation instead + of starting fresh, until the daemon restarted. The daemon and the sessions it + starts no longer carry an agent conversation's identity, and a session the + app asks for never hands off. Typing `shell claude` inside Claude Code still + forks the conversation, as before. Machines already affected are fixed once + the new release's daemon replaces the running one (`shell service install`, + a restart, or signing in again). - Signing in from the header link of the sign-up page returns to the terminal link request that sent you there. It used to land on the sessions list, with the terminal still waiting for a callback that was never coming. @@ -194,7 +226,6 @@ All notable user-visible changes are recorded here. Versions follow [Semantic Ve - Shell Keep's "Gather now" answered "internal error". The database only allowed a command to be a start or a kill, while the rest of the system already accepted the gathering's probe. - ## [0.23.3] — 2026-09-25 ### Fixed diff --git a/cmd/shell/agent_loop.go b/cmd/shell/agent_loop.go index 98091cce..4c3f6bc5 100644 --- a/cmd/shell/agent_loop.go +++ b/cmd/shell/agent_loop.go @@ -247,7 +247,11 @@ func performAgentCommand( // not silently weaken E2EE or widen file sharing on the wrapper itself. arguments := append([]string{"--"}, browserCommandArguments(command.Command)...) launch := exec.CommandContext(ctx, self, arguments...) - launch.Env = passwordHandoffEnvironment(os.Environ(), "") + // Never an agent conversation's identity, even from a daemon an older + // release started with one: the browser asked for a new program. Also + // drop any inherited browser password the parent was handed, as a + // fresh launch reads its own from the pipe or not at all. + launch.Env = passwordHandoffEnvironment(detachedEnvironment(os.Environ()), "") if command.Name != "" { // The launched shell reads this when it publishes the session, so // the name chosen in the browser survives to the session list. diff --git a/cmd/shell/daemon_unix.go b/cmd/shell/daemon_unix.go index 371c4736..956ec9df 100644 --- a/cmd/shell/daemon_unix.go +++ b/cmd/shell/daemon_unix.go @@ -134,7 +134,7 @@ func startDetachedDaemon(self string) { defer null.Close() command := exec.Command(self, "daemon") - command.Env = os.Environ() + command.Env = detachedEnvironment(os.Environ()) command.Stdin = null command.Stdout = null command.Stderr = null diff --git a/cmd/shell/daemon_windows.go b/cmd/shell/daemon_windows.go index 1ae0bb83..85d26e1f 100644 --- a/cmd/shell/daemon_windows.go +++ b/cmd/shell/daemon_windows.go @@ -102,7 +102,7 @@ func startDetachedDaemon(self string) { defer null.Close() command := exec.Command(self, "daemon") - command.Env = os.Environ() + command.Env = detachedEnvironment(os.Environ()) command.Stdin = null command.Stdout = null command.Stderr = null diff --git a/cmd/shell/handoff.go b/cmd/shell/handoff.go index 1ef90ed7..a37a027a 100644 --- a/cmd/shell/handoff.go +++ b/cmd/shell/handoff.go @@ -83,6 +83,43 @@ func prepareCommandLaunch(arguments, environment []string, allowHandoff bool) co return launch } +// harnessIdentityVariables are the variables an agent harness sets to tell a +// tool subprocess which conversation it belongs to. They are right for the one +// command the agent ran, and wrong for anything that outlives it. +// +// The daemon is the case that matters: any shell command starts it when none +// is running, so a first command typed inside Claude Code used to leave a +// daemon carrying that conversation's id. Every session the browser then asked +// for inherited it, read as a handoff, and forked that old conversation instead +// of starting the program that was asked for, until the daemon next restarted. +// +// Keep this a superset of every adapter's detection and strip lists; +// TestHarnessIdentityVariablesCoverEveryAdapter checks. +var harnessIdentityVariables = []string{ + "CLAUDECODE", + "CLAUDE_CODE_CHILD_SESSION", + "CLAUDE_CODE_SESSION_ID", + "CLAUDE_CODE_BRIDGE_SESSION_ID", + "CLAUDE_CODE_REMOTE_SESSION_ID", + "OPENCODE", + "OPENCODE_PID", + "OPENCODE_SESSION_ID", + "AGENT", +} + +// detachedEnvironment is the environment for a process that outlives the +// command that started it: this one, minus any agent conversation's identity. +func detachedEnvironment(environment []string) []string { + return removeEnvironmentVariables(environment, harnessIdentityVariables...) +} + +// handoffAllowed reports whether a launch may fork the agent conversation it +// was started from. Only a background launch someone typed may. A session the +// browser asked for never does: it asked for the program, started fresh. +func handoffAllowed(foreground bool, environment []string) bool { + return !foreground && environmentValue(environment, sessionOriginEnvironment) == "" +} + func environmentValue(environment []string, name string) string { prefix := name + "=" for _, entry := range environment { diff --git a/cmd/shell/handoff_test.go b/cmd/shell/handoff_test.go index f6b3ebaa..c255ceab 100644 --- a/cmd/shell/handoff_test.go +++ b/cmd/shell/handoff_test.go @@ -233,3 +233,70 @@ func TestOpencodeAdapterFallsBackToContinueWhenUnresolvable(t *testing.T) { t.Fatalf("arguments = %#v, want %#v", launch.Arguments, wantArguments) } } + +func TestHarnessIdentityVariablesCoverEveryAdapter(t *testing.T) { + listed := map[string]bool{} + for _, name := range harnessIdentityVariables { + listed[name] = true + } + for _, adapter := range harnessAdapters { + // With a session id, every adapter rewrites without touching disk. + _, stripped, _ := adapter.Rewrite(adapter.Binary, testClaudeSessionID) + for _, name := range stripped { + if !listed[name] { + t.Errorf("%s strips %s, which harnessIdentityVariables does not list", adapter.Binary, name) + } + } + } + for _, name := range []string{"CLAUDE_CODE_CHILD_SESSION", "CLAUDE_CODE_SESSION_ID", "OPENCODE", "OPENCODE_SESSION_ID"} { + if !listed[name] { + t.Errorf("harnessIdentityVariables does not list detection variable %s", name) + } + } +} + +func TestDetachedEnvironmentDropsAgentConversationIdentity(t *testing.T) { + got := detachedEnvironment([]string{ + "PATH=/usr/bin", + "CLAUDECODE=1", + "CLAUDE_CODE_CHILD_SESSION=1", + "CLAUDE_CODE_SESSION_ID=" + testClaudeSessionID, + "OPENCODE=1", + "OPENCODE_SESSION_ID=" + testOpencodeSessionID, + "HOME=/home/someone", + "SHELL_ONLINE_CONFIG=/tmp/config.json", + }) + want := []string{"PATH=/usr/bin", "HOME=/home/someone", "SHELL_ONLINE_CONFIG=/tmp/config.json"} + if !reflect.DeepEqual(got, want) { + t.Fatalf("detachedEnvironment = %#v, want %#v", got, want) + } +} + +// Regression: a daemon first started from inside a Claude Code conversation +// passed that conversation's id to every browser-started session, so starting +// `claude` from the app forked that old conversation again, every time. +func TestBrowserStartedSessionNeverForksAnAgentConversation(t *testing.T) { + inherited := []string{ + "CLAUDECODE=1", + "CLAUDE_CODE_CHILD_SESSION=1", + "CLAUDE_CODE_SESSION_ID=" + testClaudeSessionID, + sessionOriginEnvironment + "=cmd_123", + } + // Even if the variables reach the session, the browser's request is not a handoff. + launch := prepareCommandLaunch([]string{"claude"}, inherited, handoffAllowed(false, inherited)) + if launch.Handoff != "" || !reflect.DeepEqual(launch.Arguments, []string{"claude"}) { + t.Fatalf("browser-started claude handed off: %#v", launch) + } + // And they no longer reach it: the daemon and its sessions start without them. + if value := environmentValue(detachedEnvironment(inherited), "CLAUDE_CODE_SESSION_ID"); value != "" { + t.Fatalf("detached environment kept the conversation id %q", value) + } + // Typed inside Claude Code, `shell claude` still forks the conversation, as before. + typed := inherited[:3] + if launch := prepareCommandLaunch([]string{"claude"}, typed, handoffAllowed(false, typed)); launch.Handoff != claudeConversationHandoff { + t.Fatalf("typed shell claude no longer hands off: %#v", launch) + } + if handoffAllowed(true, typed) { + t.Fatal("a foreground launch must not hand off") + } +} diff --git a/cmd/shell/main.go b/cmd/shell/main.go index 7d6297b7..8bdc2e7a 100644 --- a/cmd/shell/main.go +++ b/cmd/shell/main.go @@ -164,7 +164,7 @@ func run(arguments []string, stdout, stderr io.Writer) int { if len(command) == 0 { command = []string{defaultShellCommand()} } - launch := prepareCommandLaunch(command, os.Environ(), !*foreground) + launch := prepareCommandLaunch(command, os.Environ(), handoffAllowed(*foreground, os.Environ())) command = launch.Arguments fileService, err := openSharedFileService(*shareFiles, *filesRoot) if err != nil { diff --git a/docs/self-hosting.md b/docs/self-hosting.md index ee30ad38..e4bc3bad 100644 --- a/docs/self-hosting.md +++ b/docs/self-hosting.md @@ -70,7 +70,10 @@ Objects, Rate Limiting, Analytics Engine, and static assets. Keep every documentation path in `run_worker_first`: a page served straight from the assets binding is never counted. `npm run deploy:production` refuses a production config that routes fewer of these paths through the Worker than -`wrangler.example.jsonc` does. +`wrangler.example.jsonc` does, or one that does not set `POSTHOG_ENABLED` to +`"0"` or `"1"`. Wrangler replaces every Worker variable on deploy, so a config +that leaves the flag out turns relay analytics off without any error. The +example keeps it `"0"`; a self-hosted relay sends nothing to PostHog. The private statistics dashboard is optional and configured with Worker secrets (`npx wrangler secret put `): diff --git a/scripts/deploy-production.mjs b/scripts/deploy-production.mjs index 6e4b2e09..343ae67d 100644 --- a/scripts/deploy-production.mjs +++ b/scripts/deploy-production.mjs @@ -25,6 +25,12 @@ export function validateProductionConfig(config) { !["0", "1"].includes(config.vars?.MCP_CONTROL_ENABLED)) { throw new Error("production target, pinned account, or explicit control gate is invalid"); } + // Wrangler replaces every Worker var on deploy. A config that omits the flag + // silently turns relay analytics off (installs, sessions, viewers, MCP), so + // the choice must be written down, the same way as the control gate. + if (!["0", "1"].includes(config.vars?.POSTHOG_ENABLED)) { + throw new Error("production config must set vars.POSTHOG_ENABLED to \"0\" or \"1\""); + } } export function deployProduction({ argv = [], configPath = resolve("wrangler.production.jsonc"), executor } = {}) { diff --git a/scripts/test-install-windows.ps1 b/scripts/test-install-windows.ps1 index ac590fbf..8a655bca 100644 --- a/scripts/test-install-windows.ps1 +++ b/scripts/test-install-windows.ps1 @@ -14,8 +14,10 @@ try { Set-Content -NoNewline -Path (Join-Path $downloads "SHA256SUMS") -Value "$digest $artifact`n" $server = Start-Process python -ArgumentList "-m", "http.server", "18787", "--bind", "127.0.0.1", "--directory", $root -PassThru -WindowStyle Hidden - $deadline = [DateTime]::UtcNow.AddSeconds(10) + # A cold hosted runner can take well over ten seconds to start Python. + $deadline = [DateTime]::UtcNow.AddSeconds(60) do { + if ($server.HasExited) { throw "The test download server (python -m http.server) exited with code $($server.ExitCode)" } try { Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:18787/downloads/SHA256SUMS" | Out-Null break diff --git a/scripts/test-terminal-live-browser.mjs b/scripts/test-terminal-live-browser.mjs index 2258f962..072552c0 100644 --- a/scripts/test-terminal-live-browser.mjs +++ b/scripts/test-terminal-live-browser.mjs @@ -731,7 +731,9 @@ try { if (runtime) { try { process.kill(-runtime.pid, "SIGTERM"); } catch {} await delay(300); } try { await transport?.close(); } catch {} try { await vite?.close(); } catch {} - rmSync(temp, { recursive: true, force: true }); + // Chrome may still be writing its profile here as it exits, which made this + // throw ENOTEMPTY after every check had passed. Node retries exactly that. + rmSync(temp, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 }); } process.exitCode = failed ? 1 : 0; diff --git a/shared/landing-paths.ts b/shared/landing-paths.ts new file mode 100644 index 00000000..e70beb04 --- /dev/null +++ b/shared/landing-paths.ts @@ -0,0 +1,10 @@ +/** + * The public landing pages. "/" is the home page; "/start/" is a one-screen + * page for paid traffic, tested against it. Both get the landing page's + * analytics, X pixel and Content-Security-Policy, and nothing else does. + */ +export const START_PATH = "/start/"; + +export function isLandingPath(pathname: string): boolean { + return pathname === "/" || pathname === "" || pathname === START_PATH; +} diff --git a/shared/posthog.ts b/shared/posthog.ts index 84e1887a..f5fe01da 100644 --- a/shared/posthog.ts +++ b/shared/posthog.ts @@ -18,8 +18,8 @@ const EVENTS = new Set([ ]); const VALUES: Record> = { surface: new Set(["landing", "docs", "terminal", "app", "game", "relay"]), - route: new Set(["landing", "docs", "terminal", "login", "signup", "reset", "feedback", "account", "sessions", "session", "audit", "team", "join", "terms", "privacy", "machines", "game", "cli_authorize"]), - target: new Set(["install", "brew_install", "source_build", "run", "docs_command", "share", "skill", "start_nav", "start_hero", "start_footer", "start_bottom", "demo", "github_star", "signup_nav", "signup_hero", "signup_team", "signup_footer", "github", "signup", "signin", "docs", "app", "feedback", "session", "machine", "team", "vault", "automation", "account", "command", "invite", "cli", "unknown"]), + route: new Set(["landing", "start", "docs", "terminal", "login", "signup", "reset", "feedback", "account", "sessions", "session", "audit", "team", "join", "terms", "privacy", "machines", "game", "cli_authorize"]), + target: new Set(["install", "brew_install", "source_build", "run", "docs_command", "share", "skill", "start_nav", "start_hero", "start_footer", "start_bottom", "start_share", "demo", "github_star", "signup_nav", "signup_hero", "signup_team", "signup_footer", "github", "signup", "signin", "docs", "app", "feedback", "session", "machine", "team", "vault", "automation", "account", "command", "invite", "cli", "unknown"]), source: new Set(["x", "google", "github", "reddit", "hacker_news", "bing", "youtube", "linkedin", "facebook", "instagram", "direct", "internal", "other", "app", "newsletter", "product_hunt", "discord", "slack", "mastodon", "bluesky", "podcast"]), device: new Set(["mobile", "tablet", "desktop", "bot", "cli", "unknown"]), outcome: new Set([...OPERATION_OUTCOMES, "unsupported_os", "unsupported_arch", "download_failed", "checksum_mismatch", "unknown", "matched", "limit", "reset", "revoked", "error", "busy", "too_large", "conflict", "in_flight", "delivered", "delivery_uncertain"]), @@ -96,6 +96,10 @@ export function posthogPayload(event: string, id: string, input: Record): Array> } const settle = () => new Promise((resolve) => setTimeout(resolve, 40)); +/* Wait for what a test expects to arrive, not a fixed time a busy runner can overrun. */ +async function until(condition: () => boolean, timeout = 2000): Promise { + const end = Date.now() + timeout; + while (!condition() && Date.now() < end) await new Promise((resolve) => setTimeout(resolve, 10)); +} describe("standalone relay with a host that owns its grid", () => { test("passes the host's grid on once per change and never resizes for a viewer", async () => { @@ -216,6 +221,7 @@ describe("standalone relay with a host that owns its grid", () => { host.socket.send(JSON.stringify({ type: "terminal_grid", cols: 173, rows: 51 })); await settle(); phone.socket.close(); + await until(() => sizes(desk.received).length > 0); await settle(); expect(sizes(desk.received)).toEqual([{ type: "terminal_size", cols: 173, rows: 51, dynamic: true }]); diff --git a/start/index.html b/start/index.html new file mode 100644 index 00000000..67da9809 --- /dev/null +++ b/start/index.html @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Use any coding agent from your phone | shell.online + + +
+
+ shell.online +
+ +
+
+

Use any coding agent from your phone.

+

Free and open source. No account needed.

+
+ +
+

How it works

+
    +
  1. +
    + + On your laptop, install shellInstall shell +
    + + +
    +
    +
    + curl -fsSL https://shell.online/install | sh + +
    +
  2. +
  3. +
    + + Start your agent through shell +
    +
    + shell claude + +
    +

    or + + + + +

    +
  4. +
  5. +
    + + Scan the QR code it prints with this phoneyour phone +
    +
  6. +
+
+
+ +
+ +

+
+
+ + + diff --git a/tests/analytics.test.ts b/tests/analytics.test.ts index 231cc88c..81f2c628 100644 --- a/tests/analytics.test.ts +++ b/tests/analytics.test.ts @@ -157,6 +157,8 @@ describe("analytics", () => { it("names every documentation page, and keeps unknown paths apart from 404s", () => { expect(documentTarget("/", 200, "0.15.1")).toBe("landing"); + expect(documentTarget("/start/", 200, "0.15.1")).toBe("landing_start"); + expect(documentTarget("/start/", 404, "0.15.1")).toBe("not_found"); expect(documentTarget("/docs/", 200, "0.15.1")).toBe("docs"); expect(documentTarget("/app/", 200, "0.15.1")).toBe("docs_app"); expect(documentTarget("/cli/", 200, "0.15.1")).toBe("docs_cli"); diff --git a/tests/csp-ga.test.ts b/tests/csp-ga.test.ts index d7e70108..92dd54b4 100644 --- a/tests/csp-ga.test.ts +++ b/tests/csp-ga.test.ts @@ -41,6 +41,15 @@ describe("secureAssetResponse CSP Google Analytics endpoints", () => { expect(privatePolicy).not.toMatch(/twitter|t\.co|ads-twitter/); } }); + it("gives the /start/ landing page the home page's analytics and X origins, and keeps it out of search", () => { + const home = csp(secureAssetResponse(htmlResponse(), "/", "shell.online")); + const start = secureAssetResponse(htmlResponse(), "/start/", "shell.online"); + expect(csp(start)).toBe(home); + expect(start.headers.get("X-Robots-Tag")).toBe("noindex, nofollow, noarchive"); + for (const [path, host] of [["/start", "shell.online"], ["/start/x", "shell.online"], ["/start/", "app.shell.online"]]) { + expect(csp(secureAssetResponse(htmlResponse(), path, host))).not.toMatch(/twitter|googletagmanager/); + } + }); it("allows GA on public landing page (/) HTML on shell.online", () => { const res = secureAssetResponse(htmlResponse(), "/", "shell.online"); const policy = csp(res); diff --git a/tests/posthog.test.ts b/tests/posthog.test.ts index 1ea56c53..cb1d0c11 100644 --- a/tests/posthog.test.ts +++ b/tests/posthog.test.ts @@ -165,6 +165,9 @@ describe("PostHog explicit capture boundary", () => { const payload = posthogPayload("$pageview", ID, { surface: "terminal", route: "terminal", target: SECRET, source: SECRET, url: SECRET, content: SECRET, token: SECRET, $current_url: SECRET, $set: { email: SECRET } }); expect(JSON.stringify(payload)).not.toContain(SECRET); expect(payload?.properties.$current_url).toBe("https://shell.online/s/:session"); + const start = posthogPayload("$pageview", ID, { surface: "landing", route: "start" }); + expect(start?.properties).toMatchObject({ $current_url: "https://shell.online/start/", $pathname: "/start/", $host: "shell.online", route: "start" }); + expect(posthogPayload("landing_cta", ID, { target: "start_share" })?.properties.target).toBe("start_share"); expect(payload?.properties.$process_person_profile).toBe(false); expect(payload?.properties.$geoip_disable).toBe(true); expect(posthogPayload(SECRET, ID)).toBeNull(); @@ -174,6 +177,8 @@ describe("PostHog explicit capture boundary", () => { for (const url of ["http://shell.online/", "https://evil.shell.online/", "https://stats.shell.online/", "https://app.shell.online/auth/callback?code=SECRET", "https://shell.online:444/", "https://shell.online/unknown"]) expect(analyticsRoute(new URL(url))).toBeNull(); expect(analyticsRoute(new URL(`https://app.shell.online/sessions/${SECRET}?token=${SECRET}`))).toEqual({ surface: "app", route: "session" }); expect(analyticsRoute(new URL("https://app.shell.online/game"))).toEqual({ surface: "game", route: "game" }); + expect(analyticsRoute(new URL("https://shell.online/start/?utm_source=x&utm_medium=paid_social"))).toEqual({ surface: "landing", route: "start" }); + expect(analyticsRoute(new URL("https://shell.online/start/other"))).toBeNull(); }); it("uses a finite acquisition source, never a raw URL/campaign/click ID", () => { expect(analyticsSource(new URL(`https://shell.online/?twclid=${SECRET}`), "")).toBe("x"); diff --git a/tests/production-deploy.test.ts b/tests/production-deploy.test.ts index 7565e2fd..1f29d113 100644 --- a/tests/production-deploy.test.ts +++ b/tests/production-deploy.test.ts @@ -9,7 +9,7 @@ const valid = () => ({ name: "shell-online", account_id: "a".repeat(32), compatibility_flags: ["enable_request_signal"], routes: [{ pattern: "shell.online" }, { pattern: "stats.shell.online" }], - vars: { MCP_CONTROL_ENABLED: "0" }, + vars: { MCP_CONTROL_ENABLED: "0", POSTHOG_ENABLED: "1" }, }); describe("production deploy guard", () => { it("refuses an older or unknown release identity", () => { @@ -21,7 +21,17 @@ describe("production deploy guard", () => { }); it("accepts the explicit production target with either control state", () => { expect(() => validateProductionConfig(valid())).not.toThrow(); - expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "1" } })).not.toThrow(); + expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "1", POSTHOG_ENABLED: "1" } })).not.toThrow(); + }); + it("accepts relay analytics explicitly on or off", () => { + expect(() => validateProductionConfig({ ...valid(), vars: { MCP_CONTROL_ENABLED: "0", POSTHOG_ENABLED: "0" } })).not.toThrow(); + }); + // Regression: 0.23.1 deployed with a config that omitted the flag, and every + // relay event stopped reaching PostHog while the accounts app kept reporting. + it.each([undefined, "", "true", "yes", 1])("refuses a config whose relay analytics flag is %s", (value) => { + const vars: Record = { MCP_CONTROL_ENABLED: "0" }; + if (value !== undefined) vars.POSTHOG_ENABLED = value; + expect(() => validateProductionConfig({ ...valid(), vars })).toThrow("POSTHOG_ENABLED"); }); it.each([ { name: "shell-online-staging" }, { account_id: undefined }, { routes: [] }, diff --git a/tests/start-pages.test.ts b/tests/start-pages.test.ts new file mode 100644 index 00000000..32e06260 --- /dev/null +++ b/tests/start-pages.test.ts @@ -0,0 +1,95 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { loadPage, pageFromPayload, payloadFromFlags, requestedPage, START_PAGES_FLAG } from "../web/start-pages"; +import { POSTHOG_ORIGIN, POSTHOG_TOKEN, posthogPayload } from "../shared/posthog"; + +const payload = { + pages: { + pocket: { headline: "Your coding agent, in your pocket.", subline: "Free. No account needed.", agent: "codex", send: "Send to my laptop" }, + partial: { headline: "Just a headline." }, + }, +}; +const flags = (body: unknown, enabled = true) => ({ flags: { [START_PAGES_FLAG]: { key: START_PAGES_FLAG, enabled, metadata: { payload: body } } } }); + +afterEach(() => vi.unstubAllGlobals()); + +describe("which /start/ page an ad asked for", () => { + it("reads a short page key from utm_content", () => { + expect(requestedPage(new URL("https://shell.online/start/?utm_source=x&utm_content=Pocket"))).toBe("pocket"); + expect(requestedPage(new URL("https://shell.online/start/?utm_content=v2_codex-a"))).toBe("v2_codex-a"); + }); + it.each(["", "a b", "