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): scope pool name-conflict copy to RBAC denials (#7355)

r33drichards042d04ceeaa0
diff --git a/libs/fleet/src/error-message.ts b/libs/fleet/src/error-message.ts
index 34c1e5ffa2..a06b944124 100644
--- a/libs/fleet/src/error-message.ts
+++ b/libs/fleet/src/error-message.ts
@@ -41,15 +41,25 @@ function uniffiErrorDetail(error: UniffiErrorLike): string | undefined {
return undefined
}
+// A pool-create PoolAccessDenied is ambiguous. The name-conflict case reaches
+// us as a Kubernetes RBAC refusal — the namespace cannot create the resource
+// because another account already claimed the (globally unique, DNS-like)
+// name — and its raw text explains nothing to the user. But the same variant
+// also carries deliberate policy denials, like the card-admission gate, whose
+// own message is the actionable one. Only rewrite the RBAC shape.
+const RBAC_CREATE_DENIAL = /is forbidden:[\s\S]*cannot create resource/i
+
export function poolCreateErrorMessage(error: unknown, poolName: string): string {
+ const detail = errorMessage(error)
if (
error &&
typeof error === "object" &&
- (error as UniffiErrorLike).tag === "PoolAccessDenied"
+ (error as UniffiErrorLike).tag === "PoolAccessDenied" &&
+ RBAC_CREATE_DENIAL.test(detail)
) {
return `Pool names must be globally unique across all accounts, similar to DNS names. "${poolName}" may already be in use. Try a different name.`
}
- return errorMessage(error)
+ return detail
}
export function errorMessage(error: unknown): string {
diff --git a/libs/fleet/tests/error-message.test.ts b/libs/fleet/tests/error-message.test.ts
index a880689a12..e58abe676d 100644
--- a/libs/fleet/tests/error-message.test.ts
+++ b/libs/fleet/tests/error-message.test.ts
@@ -92,6 +92,21 @@ test("keeps unrelated pool create errors unchanged", () => {
)
})
+// The card-admission gate denies pool creation through the same
+// PoolAccessDenied variant, but its message is the actionable one — telling
+// the user to pick a different name would send them down the wrong path.
+test("preserves policy denials that are not name conflicts", () => {
+ const denial =
+ "A payment method is required to create this resource. Add one in Billing and try again."
+ const error = uniffiError("PoolAccessDenied", {
+ operation: "create pool",
+ namespace: "demo",
+ status: 403,
+ body: JSON.stringify({ error: denial }),
+ })
+ assert.equal(poolCreateErrorMessage(error, "demo"), denial)
+})
+
test("surfaces reason-only variants like Transport", () => {
const error = uniffiError("Transport", { reason: "dns lookup failed" })
assert.equal(errorMessage(error), "dns lookup failed")