Spaces:
Running
Running
File size: 27,592 Bytes
a9e27c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | import json
import tomllib
from itertools import groupby, pairwise
import pytest
from playwright.sync_api import expect
from free_claude_code.harnesses import claude_integration, claude_onboarding
@pytest.mark.parametrize(
"integration,button_id",
[
("claude-vscode", "openClaudeIntegration"),
("codex", "openCodexIntegration"),
("claude-desktop", "openClaudeDesktopIntegration"),
("jetbrains-acp", "openJetBrainsIntegration"),
],
)
@pytest.mark.parametrize("connected", [False, True])
def test_connection_check_uses_disabled_loading_button(
page, admin_base_url, integration, button_id, connected
):
pending = []
def hold_check(route):
pending.append(route)
page.evaluate("window.integrationChecks = (window.integrationChecks || 0) + 1")
page.route(f"**/admin/api/integrations/{integration}", hold_check)
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator(f"#{button_id}")
for visit in range(2):
if visit:
page.get_by_role("button", name="Providers", exact=True).click()
page.get_by_role("button", name="Integrations", exact=True).click()
expect(button).to_be_disabled()
expect(button).to_have_text("Loading…")
expect(button).to_have_attribute("aria-busy", "true")
expect(button).to_have_css("background-color", "rgb(23, 27, 38)")
assert (
button.evaluate(
"element => getComputedStyle(element, '::before').animationName"
)
== "integration-spinner"
)
expect(page.locator("#view-integrations .status-pill")).to_have_count(0)
page.wait_for_function(
"count => window.integrationChecks >= count", arg=visit + 1
)
assert len(pending) == 1
pending.pop().fulfill(
json={
"connected": connected,
"paths": None,
"update": {"state": "ready", "changed": False, "message": None},
}
)
expect(button).to_be_enabled()
expect(button).to_have_text("Disconnect" if connected else "Connect")
expect(button).to_have_attribute("aria-busy", "false")
@pytest.mark.parametrize("width", [1280, 1200, 390])
def test_codex_connect_disconnect_and_modal_paths(
page, admin_base_url, tmp_path, width
):
page.set_viewport_size({"width": width, "height": 900})
page.goto(f"{admin_base_url}/admin/integrations")
expect(page.locator("#openClaudeIntegration")).to_be_enabled()
expect(page.locator("#messageArea")).to_have_text("")
cards = page.locator("#view-integrations > article")
expect(cards.first).to_be_visible()
expect(page.locator("#claudeIntegrationStatus")).to_have_count(0)
expect(page.locator("#openCodexIntegration")).to_be_enabled()
expect(page.locator("#codexIntegrationStatus")).to_have_count(0)
bounds = [card.bounding_box() for card in cards.all()]
if width >= 1200:
descriptions = [
card.locator(".section-heading p").bounding_box() for card in cards.all()
]
for _, row in groupby(range(len(bounds)), key=lambda index: bounds[index]["y"]):
indices = list(row)
assert all(
bounds[right]["x"] > bounds[left]["x"]
for left, right in pairwise(indices)
)
assert len({descriptions[index]["y"] for index in indices}) == 1
assert bounds[1]["y"] == bounds[0]["y"]
else:
assert all(right["y"] > left["y"] for left, right in pairwise(bounds))
assert page.locator("body").evaluate(
"element => element.scrollWidth <= window.innerWidth"
)
opener = page.locator("#openCodexIntegration")
dialog = page.get_by_role("dialog", name="Codex in VS Code and App", exact=True)
opener.click()
expect(dialog).to_be_visible()
expect(page.locator("#claudeIntegrationDialog")).not_to_be_visible()
expect(dialog.get_by_role("button", name="Close", exact=True)).to_be_focused()
expect(dialog).to_contain_text(
"Configure Codex to use FCC. Your selected model stays unchanged."
)
assert dialog.evaluate("element => element.scrollWidth <= element.clientWidth")
path = tmp_path / ".codex" / "config.toml"
expect(dialog.locator("#codexIntegrationFiles li")).to_have_text(
[str(path.resolve())]
)
page.locator("#codexIntegrationDescription").click()
expect(dialog).to_be_visible()
dialog.get_by_role("button", name="Close", exact=True).click()
expect(dialog).not_to_be_visible()
expect(opener).to_be_focused()
opener.click()
page.keyboard.press("Escape")
expect(dialog).not_to_be_visible()
opener.click()
page.mouse.click(1, 1)
expect(dialog).not_to_be_visible()
assert not path.exists()
path.parent.mkdir()
path.write_text('model = "my-choice" # Keep this\n')
opener.click()
page.locator("#confirmCodexIntegration").click()
expect(dialog).not_to_be_visible()
expect(opener).to_have_text("Disconnect")
expect(page.locator("#codexIntegrationStatus")).to_have_count(0)
expect(opener).to_have_css("color", "rgb(239, 68, 68)")
if width >= 1200:
buttons = [
card.get_by_role("button").first.bounding_box() for card in cards.all()
]
for _, row in groupby(range(len(bounds)), key=lambda index: bounds[index]["y"]):
assert len({buttons[index]["y"] for index in row}) == 1
assert len({button["height"] for button in buttons}) == 1
expect(page.locator("#codexIntegrationMessage")).to_have_text(
"Settings saved. Restart Codex and select an FCC model."
)
assert tomllib.loads(path.read_text())["model"] == "my-choice"
assert "# Keep this" in path.read_text()
page.reload()
expect(opener).to_have_text("Disconnect")
opener.click()
expect(page.locator("#confirmCodexIntegration")).to_have_text("Disconnect")
expect(page.locator("#confirmCodexIntegration")).to_have_css(
"color", "rgb(239, 68, 68)"
)
expect(dialog.locator("#codexIntegrationFiles li")).to_have_text(
[str(path.resolve())]
)
page.locator("#confirmCodexIntegration").click()
expect(opener).to_have_text("Connect")
expect(opener).to_have_css("color", "rgb(6, 16, 11)")
expect(page.locator("#codexIntegrationStatus")).to_have_count(0)
assert tomllib.loads(path.read_text()) == {"model": "my-choice"}
assert not (tmp_path / "vscode" / "settings.json").exists()
assert not (tmp_path / ".claude.json").exists()
@pytest.mark.parametrize("width", [1280, 390])
def test_modal_shows_files_for_the_selected_action(
page, admin_base_url, tmp_path, width
):
page.set_viewport_size({"width": width, "height": 900})
page.goto(f"{admin_base_url}/admin/integrations")
page.locator("#openClaudeIntegration").click()
dialog = page.locator("#claudeIntegrationDialog")
paths = dialog.locator("#claudeIntegrationFiles li")
expect(paths).to_have_text(
[
str((tmp_path / "vscode" / "settings.json").resolve()),
str((tmp_path / ".claude.json").resolve()),
]
)
assert dialog.evaluate("element => element.scrollWidth <= element.clientWidth")
page.locator("#confirmClaudeIntegration").click()
expect(dialog).not_to_be_visible()
page.locator("#openClaudeIntegration").click()
expect(paths).to_have_text([str((tmp_path / "vscode" / "settings.json").resolve())])
page.keyboard.press("Escape")
expect(dialog).not_to_be_visible()
def test_connect_disconnect_and_modal_dismissal(page, admin_base_url, tmp_path):
path = tmp_path / "vscode" / "settings.json"
page.goto(f"{admin_base_url}/admin/integrations")
card_button = page.locator("#openClaudeIntegration")
dialog = page.locator("#claudeIntegrationDialog")
action = page.locator("#confirmClaudeIntegration")
expect(card_button).to_be_enabled()
expect(card_button).to_have_text("Connect")
for dismiss in ("close", "escape", "outside"):
card_button.click()
expect(dialog).to_be_visible()
if dismiss == "close":
dialog.get_by_role("button", name="Close", exact=True).click()
elif dismiss == "escape":
page.keyboard.press("Escape")
else:
page.mouse.click(1, 1)
expect(dialog).not_to_be_visible()
assert not path.exists()
card_button.click()
action.click()
expect(dialog).not_to_be_visible()
expect(card_button).to_have_text("Disconnect")
expect(page.locator("#claudeIntegrationStatus")).to_have_count(0)
expect(card_button).to_have_css("color", "rgb(239, 68, 68)")
expect(page.locator("#claudeIntegrationMessage")).to_contain_text("Reload VS Code")
assert json.loads(path.read_text())["claudeCode.disableLoginPrompt"] is True
state_path = tmp_path / ".claude.json"
assert json.loads(state_path.read_text())["hasCompletedOnboarding"] is True
expect(page.locator("#openClaudeOnboarding")).to_have_text("Completed")
page.reload()
expect(card_button).to_have_text("Disconnect")
card_button.click()
expect(action).to_have_text("Disconnect")
expect(action).to_have_css("color", "rgb(239, 68, 68)")
expect(page.locator("#claudeIntegrationDescription")).to_contain_text("Remove")
page.keyboard.press("Escape")
assert json.loads(path.read_text())["claudeCode.disableLoginPrompt"] is True
card_button.click()
action.click()
expect(card_button).to_have_text("Connect")
expect(card_button).to_have_css("color", "rgb(6, 16, 11)")
expect(page.locator("#claudeIntegrationStatus")).to_have_count(0)
assert json.loads(path.read_text()) == {}
assert json.loads(state_path.read_text())["hasCompletedOnboarding"] is True
def test_manual_setup_and_revisit_read_the_file(page, admin_base_url, tmp_path):
path = tmp_path / "vscode" / "settings.json"
status = page.request.get(f"{admin_base_url}/admin/api/status").json()
claude_integration.configure(
path,
f"http://localhost:{status['port']}/",
"e2e-proxy-token",
True,
)
claude_onboarding.complete(tmp_path / ".claude.json")
page.goto(f"{admin_base_url}/admin/integrations")
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
(tmp_path / ".claude.json").unlink()
page.reload()
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
page.locator("#openClaudeOnboarding").click()
page.locator("#confirmClaudeOnboarding").click()
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
page.get_by_role("button", name="Providers", exact=True).click()
path.write_text("{}")
page.get_by_role("button", name="Integrations", exact=True).click()
expect(page.locator("#openClaudeIntegration")).to_have_text("Connect")
def test_invalid_settings_error_can_be_retried_and_does_not_break_admin(
page, admin_base_url, tmp_path
):
path = tmp_path / "vscode" / "settings.json"
path.parent.mkdir()
path.write_text("{invalid}")
page.goto(f"{admin_base_url}/admin/integrations")
expect(page.locator("#claudeIntegrationMessage")).to_contain_text("Check the JSON")
expect(page.locator("#openClaudeIntegration")).to_have_text("Retry")
expect(page.locator("#openClaudeIntegration")).to_have_attribute(
"aria-busy", "false"
)
expect(page.locator("#view-integrations .status-pill")).to_have_count(0)
page.get_by_role("button", name="Providers", exact=True).click()
expect(page.locator('[data-provider="nvidia_nim"]')).to_be_visible()
page.get_by_role("button", name="Integrations", exact=True).click()
path.write_text("{}")
page.locator("#openClaudeIntegration").click()
expect(page.locator("#openClaudeIntegration")).to_have_text("Connect")
def test_save_pending_and_failure_stay_in_modal(page, admin_base_url):
page.goto(f"{admin_base_url}/admin/integrations")
page.locator("#openClaudeIntegration").click()
requests = []
def hold_save(route):
requests.append(route)
page.evaluate("window.integrationSaveIntercepted = true")
page.route(
"**/admin/api/integrations/claude-vscode/connect",
hold_save,
)
action = page.locator("#confirmClaudeIntegration")
action.click()
expect(action).to_be_disabled()
expect(action).to_have_text("Saving…")
page.wait_for_function("window.integrationSaveIntercepted === true")
requests[0].fulfill(status=503, json={"detail": "Could not save settings."})
expect(action).to_be_enabled()
expect(page.locator("#claudeIntegrationDialog")).to_be_visible()
expect(page.locator("#claudeIntegrationDialogMessage")).to_have_text(
"Could not save settings."
)
def test_codex_existing_setup_revisit_and_invalid_config_retry(
page, admin_base_url, tmp_path
):
path = tmp_path / ".codex" / "config.toml"
assert page.request.post(
f"{admin_base_url}/admin/api/integrations/codex/connect"
).ok
page.goto(f"{admin_base_url}/admin/integrations")
opener = page.locator("#openCodexIntegration")
expect(opener).to_have_text("Disconnect")
page.get_by_role("button", name="Providers", exact=True).click()
path.write_text("[invalid")
page.get_by_role("button", name="Integrations", exact=True).click()
expect(page.locator("#codexIntegrationMessage")).to_contain_text("Check the TOML")
expect(opener).to_have_text("Retry")
path.write_text("")
opener.click()
expect(opener).to_have_text("Connect")
def test_codex_save_pending_and_failure_stay_in_modal(page, admin_base_url, tmp_path):
page.goto(f"{admin_base_url}/admin/integrations")
page.locator("#openCodexIntegration").click()
action = page.locator("#confirmCodexIntegration")
def reject_save(route):
expect(action).to_be_disabled()
expect(action).to_have_text("Saving…")
expect(page.locator("#openCodexIntegration")).to_be_disabled()
route.fulfill(status=503, json={"detail": "Could not save settings."})
page.route("**/admin/api/integrations/codex/connect", reject_save)
action.click()
expect(page.locator("#codexIntegrationDialogMessage")).to_have_text(
"Could not save settings."
)
expect(action).to_be_enabled()
expect(page.locator("#codexIntegrationDialog")).to_be_visible()
assert not (tmp_path / ".codex" / "config.toml").exists()
@pytest.mark.parametrize(
"integration,prefix", [("claude-vscode", "Claude"), ("codex", "Codex")]
)
def test_background_update_spinner_failure_retry_and_completion(
page, admin_base_url, integration, prefix
):
progress = {"state": "starting", "changed": False, "message": None}
retries = []
def startup(route):
response = route.fetch()
payload = response.json()
payload["startup"]["integrations"][integration] = dict(progress)
route.fulfill(response=response, json=payload)
def status(route):
route.fulfill(
json={
"connected": True if progress["state"] == "ready" else None,
"paths": None,
"update": dict(progress),
}
)
def retry(route):
retries.append(route.request.method)
progress.update(state="starting", changed=False, message=None)
route.fulfill(json={"update": dict(progress)})
page.route("**/admin/api/status", startup)
page.route(f"**/admin/api/integrations/{integration}", status)
page.route(f"**/admin/api/integrations/{integration}/refresh", retry)
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator(f"#open{prefix}Integration")
confirm = page.locator(f"#confirm{prefix}Integration")
message = page.locator(f"#{prefix.lower()}IntegrationMessage")
expect(button).to_be_disabled()
expect(confirm).to_be_disabled()
expect(button).to_have_attribute("aria-busy", "true")
progress.update(
state="failed", message="Could not update settings. Check permissions."
)
expect(button).to_have_text("Retry")
expect(button).to_be_enabled()
expect(message).to_have_text(progress["message"])
with page.expect_response(
f"{admin_base_url}/admin/api/integrations/{integration}/refresh"
):
button.click()
expect(button).to_be_disabled()
assert retries == ["POST"]
page.wait_for_function(
"id => state.startup?.startup?.integrations[id]?.state === 'starting'",
arg=integration,
)
progress.update(state="ready", changed=True)
expect(button).to_have_text("Disconnect")
expect(button).to_be_enabled()
expect(button).to_have_css("color", "rgb(239, 68, 68)")
expect(message).to_have_text(
"Settings updated. Reload VS Code."
if prefix == "Claude"
else "Settings updated. Restart Codex."
)
@pytest.fixture
def admin_client_files(request, tmp_path):
if not getattr(request, "param", False):
return None
path = tmp_path / "vscode/settings.json"
path.parent.mkdir()
path.write_text(
json.dumps(
{
"editor.fontSize": 15,
"claudeCode.disableLoginPrompt": True,
"claudeCode.environmentVariables": [
{"name": "ANTHROPIC_BASE_URL", "value": "http://localhost:8082"},
{"name": "ANTHROPIC_AUTH_TOKEN", "value": "e2e-proxy-token"},
{
"name": "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY",
"value": "1",
},
],
}
)
)
return path
@pytest.mark.parametrize("admin_client_files", [True], indirect=True)
def test_startup_updates_before_opening_integrations(
admin_client_files, admin_base_url, page, tmp_path
):
page.goto(f"{admin_base_url}/admin")
page.wait_for_function(
"state.startup?.startup?.integrations['claude-vscode']?.state === 'ready'"
)
page.get_by_role("button", name="Integrations", exact=True).click()
button = page.locator("#openClaudeIntegration")
expect(button).to_have_text("Disconnect")
expect(page.locator("#claudeIntegrationMessage")).to_be_hidden()
saved = json.loads(admin_client_files.read_text())
assert saved["editor.fontSize"] == 15
assert any(
entry == {"name": "CLAUDE_CODE_DISABLE_ADVISOR_TOOL", "value": "1"}
for entry in saved["claudeCode.environmentVariables"]
)
assert not (tmp_path / ".claude.json").exists()
expect(page.locator("#openClaudeOnboarding")).to_have_text("Complete onboarding")
page.screenshot(path=str(tmp_path / "integration-updated.png"), full_page=True)
button.click()
page.locator("#confirmClaudeIntegration").click()
expect(button).to_have_text("Connect")
page.reload()
expect(button).to_have_text("Connect")
expect(page.locator("#claudeIntegrationMessage")).to_be_hidden()
def test_independent_onboarding_modal_and_completion(page, admin_base_url, tmp_path):
state = tmp_path / ".claude.json"
settings = tmp_path / "vscode" / "settings.json"
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator("#openClaudeOnboarding")
dialog = page.locator("#claudeOnboardingDialog")
expect(button).to_have_text("Complete onboarding")
for dismiss in ("close", "escape", "outside"):
button.click()
expect(dialog).to_be_visible()
expect(page.locator("#claudeOnboardingFiles li")).to_have_text(
[str(state.resolve())]
)
if dismiss == "close":
dialog.get_by_role("button", name="Close", exact=True).click()
elif dismiss == "escape":
page.keyboard.press("Escape")
else:
page.mouse.click(1, 1)
expect(dialog).not_to_be_visible()
assert not state.exists() and not settings.exists()
button.click()
page.locator("#confirmClaudeOnboarding").click()
expect(dialog).not_to_be_visible()
expect(button).to_have_text("Completed")
expect(button).to_be_disabled()
expect(page.locator("#openClaudeIntegration")).to_have_text("Connect")
assert json.loads(state.read_text())["hasCompletedOnboarding"] is True
assert not settings.exists()
state.write_text('{"hasCompletedOnboarding":false}')
page.get_by_role("button", name="Providers", exact=True).click()
page.get_by_role("button", name="Integrations", exact=True).click()
expect(button).to_have_text("Complete onboarding")
assert state.read_text() == '{"hasCompletedOnboarding":false}'
@pytest.mark.parametrize("completed", [False, True])
def test_onboarding_status_uses_loading_and_completed_button(
page, admin_base_url, tmp_path, completed
):
pending = []
def hold(route):
pending.append(route)
page.evaluate("window.onboardingStatusIntercepted = true")
page.route("**/admin/api/integrations/claude-onboarding", hold)
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator("#openClaudeOnboarding")
expect(button).to_have_text("Loading…")
expect(button).to_be_disabled()
expect(button).to_have_attribute("aria-busy", "true")
expect(button).to_have_css("background-color", "rgb(23, 27, 38)")
assert (
button.evaluate(
"element => getComputedStyle(element, '::before').animationName"
)
== "integration-spinner"
)
page.wait_for_function("window.onboardingStatusIntercepted === true")
pending.pop().fulfill(
json={
"completed": completed,
"paths": {"claude_state": str(tmp_path / ".claude.json")},
}
)
expect(button).to_have_text("Completed" if completed else "Complete onboarding")
expect(button).to_have_attribute("aria-busy", "false")
if completed:
expect(button).to_be_disabled()
expect(button).to_have_css("background-color", "rgb(23, 27, 38)")
else:
expect(button).to_be_enabled()
def test_onboarding_errors_retry_independently(page, admin_base_url, tmp_path):
assert page.request.post(
f"{admin_base_url}/admin/api/integrations/claude-vscode/connect"
).ok
state = tmp_path / ".claude.json"
state.write_text('{"secret-state":invalid}')
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator("#openClaudeOnboarding")
expect(button).to_have_text("Retry")
expect(page.locator("#claudeOnboardingMessage")).to_contain_text(".claude.json")
expect(page.locator("#claudeOnboardingMessage")).not_to_contain_text("secret-state")
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
state.write_text('{"hasCompletedOnboarding":false}')
button.click()
expect(button).to_have_text("Complete onboarding")
assert state.read_text() == '{"hasCompletedOnboarding":false}'
def reject(route):
route.fulfill(status=503, json={"detail": "Could not access .claude.json."})
endpoint = "**/admin/api/integrations/claude-onboarding/complete"
page.route(endpoint, reject)
button.click()
action = page.locator("#confirmClaudeOnboarding")
action.click()
expect(page.locator("#claudeOnboardingDialogMessage")).to_contain_text(
"Could not access"
)
expect(action).to_be_enabled()
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
page.unroute(endpoint, reject)
action.click()
expect(button).to_have_text("Completed")
def test_failed_connect_updates_independent_onboarding_card(
page, admin_base_url, tmp_path, monkeypatch
):
settings = tmp_path / "vscode" / "settings.json"
write = claude_integration.atomic_write_text
def fail_settings(path, content):
if path == settings:
raise PermissionError("denied")
write(path, content)
monkeypatch.setattr(claude_integration, "atomic_write_text", fail_settings)
page.goto(f"{admin_base_url}/admin/integrations")
expect(page.locator("#openClaudeOnboarding")).to_have_text("Complete onboarding")
page.locator("#openClaudeIntegration").click()
page.locator("#confirmClaudeIntegration").click()
expect(page.locator("#claudeIntegrationDialogMessage")).to_contain_text(
"Could not access"
)
expect(page.locator("#openClaudeOnboarding")).to_have_text("Completed")
expect(page.locator("#openClaudeIntegration")).to_have_text("Connect")
assert not settings.exists()
assert (
json.loads((tmp_path / ".claude.json").read_text())["hasCompletedOnboarding"]
is True
)
def test_late_onboarding_status_cannot_undo_connect_result(
page, admin_base_url, tmp_path
):
pending = []
checks = 0
def hold_first(route):
nonlocal checks
checks += 1
if checks == 1:
pending.append(route)
else:
route.continue_()
endpoint = "**/admin/api/integrations/claude-onboarding"
page.route(endpoint, hold_first)
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator("#openClaudeOnboarding")
expect(button).to_have_text("Loading…")
page.locator("#openClaudeIntegration").click()
page.locator("#confirmClaudeIntegration").click()
expect(button).to_have_text("Completed")
assert checks == 2
with page.expect_response(
lambda response: response.url.endswith("/claude-onboarding")
):
pending.pop().fulfill(
json={
"completed": False,
"paths": {"claude_state": str(tmp_path / ".claude.json")},
}
)
page.evaluate(
"() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))"
)
expect(button).to_have_text("Completed")
expect(button).to_be_disabled()
@pytest.mark.parametrize("save_failed", [False, True])
def test_connect_reconciles_after_pending_onboarding_save(
page, admin_base_url, tmp_path, save_failed
):
pending = []
def hold(route):
pending.append(route)
endpoint = "**/admin/api/integrations/claude-onboarding/complete"
page.route(endpoint, hold)
page.goto(f"{admin_base_url}/admin/integrations")
button = page.locator("#openClaudeOnboarding")
expect(button).to_have_text("Complete onboarding")
button.click()
page.locator("#confirmClaudeOnboarding").click()
expect(button).to_have_text("Saving…")
page.keyboard.press("Escape")
expect(page.locator("#claudeOnboardingDialog")).not_to_be_visible()
page.locator("#openClaudeIntegration").click()
page.locator("#confirmClaudeIntegration").click()
expect(page.locator("#openClaudeIntegration")).to_have_text("Disconnect")
assert (
json.loads((tmp_path / ".claude.json").read_text())["hasCompletedOnboarding"]
is True
)
assert len(pending) == 1
with page.expect_response(
lambda response: response.url.endswith("/claude-onboarding")
):
pending.pop().fulfill(
status=503 if save_failed else 200,
json=(
{"detail": "Temporary completion error"}
if save_failed
else {"completed": True, "changed": False}
),
)
expect(button).to_have_text("Completed")
expect(button).to_be_disabled()
expect(page.locator("#claudeOnboardingMessage")).to_be_hidden()
|