Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cyclops-cs): disable payment gate in previews (#7315)

r33drichardse1fe5e44b471
diff --git a/libs/fleet/src/local-visual-preview.ts b/libs/fleet/src/local-visual-preview.ts
index d9d5c9ecfe..1dcfb12ef0 100644
--- a/libs/fleet/src/local-visual-preview.ts
+++ b/libs/fleet/src/local-visual-preview.ts
@@ -10,16 +10,13 @@ import type {
Conversation,
ConversationSummary,
} from "./api/chat"
+import { isReviewPreviewEnvironment } from "./preview-environment"
export function isLocalVisualPreview(): boolean {
const localPreview =
import.meta.env.DEV &&
import.meta.env.VITE_CUA_LOCAL_VISUAL_PREVIEW === "true"
- const pullRequestPreview =
- import.meta.env.VITE_CUA_REVIEW_VISUAL_PREVIEW === "true" &&
- /^cyclops-cs-pr-\d+\.tail204509\.ts\.net$/.test(
- window.location.hostname,
- )
+ const pullRequestPreview = isReviewPreviewEnvironment()
if (!localPreview && !pullRequestPreview) return false
return new URLSearchParams(window.location.search).has("cua-visual-preview")
}
diff --git a/libs/fleet/src/pages/PoolNew.tsx b/libs/fleet/src/pages/PoolNew.tsx
index 764af3bd8e..4a0bb4929d 100644
--- a/libs/fleet/src/pages/PoolNew.tsx
+++ b/libs/fleet/src/pages/PoolNew.tsx
@@ -20,6 +20,7 @@ import { createPool } from "../fleet/pools"
import type { PoolTemplateConfig } from "../fleet/models"
import { CuaButton } from "../components/CuaButton"
import { PageShell } from "../components/PageShell"
+import { isReviewPreviewEnvironment } from "../preview-environment"
const NAME_PATTERN = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/
@@ -80,6 +81,7 @@ export function PoolNew() {
const location = useLocation()
const flash = useFlash()
const { billing: billingEnabled } = useFeatureFlags()
+ const paymentMethodGateEnabled = !isReviewPreviewEnvironment()
const navState = location.state as PoolNewState | null
const source = navState?.source ?? null
@@ -124,7 +126,7 @@ export function PoolNew() {
const nameRef = useRef<InputProps.Ref>(null)
useEffect(() => {
- if (!billingEnabled) return
+ if (!billingEnabled || !paymentMethodGateEnabled) return
let cancelled = false
billingApi
.summary()
@@ -140,7 +142,7 @@ export function PoolNew() {
return () => {
cancelled = true
}
- }, [billingEnabled])
+ }, [billingEnabled, paymentMethodGateEnabled])
useBeforeUnload(event => {
if (!dirty || submitting) return
diff --git a/libs/fleet/src/preview-environment.ts b/libs/fleet/src/preview-environment.ts
new file mode 100644
index 0000000000..5ead079a24
--- /dev/null
+++ b/libs/fleet/src/preview-environment.ts
@@ -0,0 +1,12 @@
+const REVIEW_PREVIEW_HOSTNAME = /^cyclops-cs-pr-\d+\.tail204509\.ts\.net$/
+
+export function isReviewPreviewHostname(hostname: string): boolean {
+ return REVIEW_PREVIEW_HOSTNAME.test(hostname)
+}
+
+export function isReviewPreviewEnvironment(): boolean {
+ return (
+ import.meta.env.VITE_CUA_REVIEW_VISUAL_PREVIEW === "true" &&
+ isReviewPreviewHostname(window.location.hostname)
+ )
+}
diff --git a/libs/fleet/tests/preview-environment.test.ts b/libs/fleet/tests/preview-environment.test.ts
new file mode 100644
index 0000000000..e8060d27cb
--- /dev/null
+++ b/libs/fleet/tests/preview-environment.test.ts
@@ -0,0 +1,22 @@
+import assert from "node:assert/strict"
+import test from "node:test"
+import { isReviewPreviewHostname } from "../src/preview-environment"
+
+test("recognizes Cyclops CS pull request preview hostnames", () => {
+ assert.equal(
+ isReviewPreviewHostname("cyclops-cs-pr-123.tail204509.ts.net"),
+ true,
+ )
+})
+
+test("rejects production and lookalike hostnames", () => {
+ assert.equal(isReviewPreviewHostname("cyclops.cua.ai"), false)
+ assert.equal(
+ isReviewPreviewHostname("cyclops-cs-pr-123.example.com"),
+ false,
+ )
+ assert.equal(
+ isReviewPreviewHostname("evil-cyclops-cs-pr-123.tail204509.ts.net"),
+ false,
+ )
+})