claude-dev-env 8.109.3 → 8.109.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/correction/playbooks/fix.md +1 -1
- package/.agents/skills/sync-dev-env/SKILL.md +6 -6
- package/.agents/skills/sync-dev-env/scripts/link_plugin_skills.py +66 -15
- package/.agents/skills/sync-dev-env/scripts/sync_dev_env_constants/config/constants.py +4 -1
- package/.agents/skills/sync-dev-env/scripts/test_link_plugin_skills.py +167 -27
- package/bin/install-constants.mjs +6 -5
- package/bin/install.agents-home.test.mjs +93 -17
- package/bin/install.mjs +90 -46
- package/bin/install.prune.test.mjs +44 -7
- package/bin/install.test.mjs +12 -5
- package/bin/install.transaction.test.mjs +6 -1
- package/bin/publish-directory-pointer.mjs +125 -7
- package/bin/publish-directory-pointer.test.mjs +160 -0
- package/docs/rule-guides/proof-before-pull-request.md +1 -1
- package/hooks/blocking/pull_request_proof.py +98 -14
- package/hooks/blocking/test_pull_request_proof.py +161 -10
- package/hooks/hooks_constants/pull_request_proof_constants.py +11 -1
- package/package.json +1 -1
- package/scripts/account_broker_support.py +10 -1
- package/scripts/ci/installer-lifecycle.mjs +11 -6
- package/scripts/ci/installer-lifecycle.test.mjs +2 -0
- package/scripts/dev_env_scripts_constants/claude_account_constants.py +14 -0
- package/scripts/test_account_broker_support.py +87 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Behavior tests for the proof-in-practice, existing-work and eval checks on a new pull request."""
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import subprocess
|
|
4
5
|
import sys
|
|
5
6
|
from pathlib import Path
|
|
@@ -13,6 +14,7 @@ if str(HOOKS_DIRECTORY) not in sys.path:
|
|
|
13
14
|
from blocking import pull_request_proof as gate
|
|
14
15
|
from hooks_constants.pull_request_proof_constants import (
|
|
15
16
|
COMPARE_FILE_LIST_LIMIT,
|
|
17
|
+
COMPARE_FILE_STATUS_QUERY,
|
|
16
18
|
DEFERRED_PROOF_REASON,
|
|
17
19
|
MISSING_BODY_REASON,
|
|
18
20
|
MISSING_EVAL_SECTION_REASON,
|
|
@@ -347,7 +349,7 @@ def test_other_pull_request_commands_should_pass_the_existing_work_check() -> No
|
|
|
347
349
|
def _repository_with_change(tmp_path: Path, changed_file_name: str) -> Path:
|
|
348
350
|
origin_path = tmp_path / "origin"
|
|
349
351
|
clone_path = tmp_path / "clone"
|
|
350
|
-
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com"]
|
|
352
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
|
|
351
353
|
subprocess.run(["git", "init", "-q", "-b", "main", str(origin_path)], check=True)
|
|
352
354
|
(origin_path / "readme.md").write_text("base\n", encoding="utf-8")
|
|
353
355
|
subprocess.run(["git", "-C", str(origin_path), "add", "."], check=True)
|
|
@@ -397,6 +399,10 @@ def test_should_deny_when_git_cannot_read_the_branch_and_proof_shows_no_picture(
|
|
|
397
399
|
assert gate.missing_look_reason(payload) == UNREADABLE_CHANGES_REASON
|
|
398
400
|
|
|
399
401
|
|
|
402
|
+
def _compare_line(status: str, old_path: str, path: str) -> str:
|
|
403
|
+
return json.dumps([status, old_path, path], separators=(",", ":"), ensure_ascii=False)
|
|
404
|
+
|
|
405
|
+
|
|
400
406
|
def _fake_gh_api(all_responses: dict[str, list[str] | None], all_endpoints: list[str]):
|
|
401
407
|
def fake_gh_api_lines(endpoint: str, query: str) -> list[str] | None:
|
|
402
408
|
all_endpoints.append(endpoint)
|
|
@@ -416,7 +422,7 @@ def test_should_allow_a_python_only_change_the_compare_api_lists_when_git_cannot
|
|
|
416
422
|
) -> None:
|
|
417
423
|
all_endpoints: list[str] = []
|
|
418
424
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
419
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["tool.py"]}, all_endpoints))
|
|
425
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "tool.py")]}, all_endpoints))
|
|
420
426
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
421
427
|
assert gate.missing_look_reason(payload) is None
|
|
422
428
|
assert all_endpoints == [compare_endpoint]
|
|
@@ -425,7 +431,7 @@ def test_should_allow_a_python_only_change_the_compare_api_lists_when_git_cannot
|
|
|
425
431
|
def test_should_deny_a_page_change_the_compare_api_lists_without_a_picture(
|
|
426
432
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
427
433
|
) -> None:
|
|
428
|
-
all_responses = {"repos/o/r": ["trunk"], "repos/o/r/compare/trunk...feature": ["web/page.html", "tool.py"]}
|
|
434
|
+
all_responses = {"repos/o/r": ["trunk"], "repos/o/r/compare/trunk...feature": [_compare_line("M", "", "web/page.html"), _compare_line("M", "", "tool.py")]}
|
|
429
435
|
all_endpoints: list[str] = []
|
|
430
436
|
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
|
|
431
437
|
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "-R o/r --head=feature"))
|
|
@@ -435,6 +441,151 @@ def test_should_deny_a_page_change_the_compare_api_lists_without_a_picture(
|
|
|
435
441
|
assert all_endpoints == ["repos/o/r", "repos/o/r/compare/trunk...feature"]
|
|
436
442
|
|
|
437
443
|
|
|
444
|
+
def _repository_with_rename(
|
|
445
|
+
tmp_path: Path,
|
|
446
|
+
edited_text: str | None,
|
|
447
|
+
old_name: str = "asset-specs.html",
|
|
448
|
+
new_name: str = "references/asset-specs.html",
|
|
449
|
+
reorder_lines: bool = False,
|
|
450
|
+
) -> Path:
|
|
451
|
+
origin_path = tmp_path / "origin"
|
|
452
|
+
clone_path = tmp_path / "clone"
|
|
453
|
+
git_identity = ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
|
|
454
|
+
all_page_lines = [f"page body line {each_index}\n" for each_index in range(20)]
|
|
455
|
+
page_text = "".join(all_page_lines)
|
|
456
|
+
subprocess.run(["git", "init", "-q", "-b", "main", str(origin_path)], check=True)
|
|
457
|
+
(origin_path / old_name).write_text(page_text, encoding="utf-8")
|
|
458
|
+
subprocess.run(["git", "-C", str(origin_path), "add", "."], check=True)
|
|
459
|
+
subprocess.run(["git", "-C", str(origin_path), *git_identity, "commit", "-q", "-m", "base"], check=True)
|
|
460
|
+
subprocess.run(["git", "clone", "-q", str(origin_path), str(clone_path)], check=True)
|
|
461
|
+
subprocess.run(["git", "-C", str(clone_path), "checkout", "-q", "-b", "feature"], check=True)
|
|
462
|
+
(clone_path / new_name).parent.mkdir(exist_ok=True)
|
|
463
|
+
subprocess.run(["git", "-C", str(clone_path), "mv", old_name, new_name], check=True)
|
|
464
|
+
moved_text = "".join(reversed(all_page_lines)) if reorder_lines else page_text
|
|
465
|
+
if edited_text is not None or reorder_lines:
|
|
466
|
+
(clone_path / new_name).write_text(moved_text + (edited_text or ""), encoding="utf-8")
|
|
467
|
+
subprocess.run(["git", "-C", str(clone_path), "add", "."], check=True)
|
|
468
|
+
subprocess.run(["git", "-C", str(clone_path), *git_identity, "commit", "-q", "-m", "move"], check=True)
|
|
469
|
+
return clone_path
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def test_should_allow_a_pure_html_rename_without_a_picture(tmp_path: Path) -> None:
|
|
473
|
+
clone_path = _repository_with_rename(tmp_path, None)
|
|
474
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == []
|
|
475
|
+
assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is None
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def test_should_deny_an_html_rename_that_also_edits_the_page(tmp_path: Path) -> None:
|
|
479
|
+
clone_path = _repository_with_rename(tmp_path, "<p>new line</p>\n")
|
|
480
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
|
|
481
|
+
reason = gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path))
|
|
482
|
+
assert reason is not None
|
|
483
|
+
assert "references/asset-specs.html" in reason
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _stub_compare(monkeypatch: pytest.MonkeyPatch, all_lines: list[str]) -> None:
|
|
487
|
+
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
488
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: all_lines}, []))
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def test_should_allow_a_compare_page_that_lists_a_pure_html_rename(
|
|
492
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
493
|
+
) -> None:
|
|
494
|
+
_stub_compare(monkeypatch, [_compare_line("R100", "asset-specs.html", "references/asset-specs.html"), _compare_line("added", "", "tool.py")])
|
|
495
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") == []
|
|
496
|
+
assert gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")) is None
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def test_should_keep_a_compare_listed_pure_rename_from_a_hidden_suffix_to_a_page(
|
|
500
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
501
|
+
) -> None:
|
|
502
|
+
_stub_compare(monkeypatch, [_compare_line("R100", "notes.txt", "site/notes.html")])
|
|
503
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") == ["site/notes.html"]
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def test_should_deny_a_compare_page_that_lists_an_html_rename_with_an_edit(
|
|
507
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
508
|
+
) -> None:
|
|
509
|
+
_stub_compare(monkeypatch, [_compare_line("renamed", "asset-specs.html", "references/asset-specs.html")])
|
|
510
|
+
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature"))
|
|
511
|
+
assert reason is not None
|
|
512
|
+
assert "references/asset-specs.html" in reason
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def test_should_deny_as_unreadable_when_a_full_compare_page_lists_only_pure_renames(
|
|
516
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
517
|
+
) -> None:
|
|
518
|
+
all_lines = [
|
|
519
|
+
_compare_line("R100", f"old/skill_{each_index}/page.html", f"skills/skill_{each_index}/page.html")
|
|
520
|
+
for each_index in range(COMPARE_FILE_LIST_LIMIT)
|
|
521
|
+
]
|
|
522
|
+
_stub_compare(monkeypatch, all_lines)
|
|
523
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") is None
|
|
524
|
+
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
525
|
+
assert gate.missing_look_reason(payload) == UNREADABLE_CHANGES_REASON
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def test_compare_query_should_label_each_file_by_whether_a_rename_changed_it() -> None:
|
|
529
|
+
all_files = {
|
|
530
|
+
"files": [
|
|
531
|
+
{"status": "renamed", "changes": 0, "previous_filename": "a/x.html", "filename": "b/x.html"},
|
|
532
|
+
{"status": "renamed", "changes": 3, "previous_filename": "a/y.html", "filename": "b/y.html"},
|
|
533
|
+
{"status": "added", "changes": 5, "filename": "c.py"},
|
|
534
|
+
{"status": "modified", "changes": 2, "filename": "we\tird\nname.html"},
|
|
535
|
+
]
|
|
536
|
+
}
|
|
537
|
+
completed = subprocess.run(
|
|
538
|
+
["jq", "-r", COMPARE_FILE_STATUS_QUERY],
|
|
539
|
+
input=json.dumps(all_files),
|
|
540
|
+
capture_output=True,
|
|
541
|
+
text=True,
|
|
542
|
+
check=True,
|
|
543
|
+
)
|
|
544
|
+
assert completed.stdout.splitlines() == [
|
|
545
|
+
_compare_line("R100", "a/x.html", "b/x.html"),
|
|
546
|
+
_compare_line("renamed", "a/y.html", "b/y.html"),
|
|
547
|
+
_compare_line("added", "", "c.py"),
|
|
548
|
+
_compare_line("modified", "", "we\tird\nname.html"),
|
|
549
|
+
]
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def test_should_report_an_unparseable_compare_line_as_unknown(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
553
|
+
_stub_compare(monkeypatch, ["not json"])
|
|
554
|
+
assert gate.remote_visible_changed_files("o/r", "main", "feature") is None
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def test_should_deny_a_byte_identical_rename_from_a_hidden_suffix_to_a_page(tmp_path: Path) -> None:
|
|
558
|
+
clone_path = _repository_with_rename(tmp_path, None, "notes.txt", "site/notes.html")
|
|
559
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["site/notes.html"]
|
|
560
|
+
assert gate.missing_look_reason(_mcp_create_on_branch(PROVEN_BODY, clone_path)) is not None
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def test_should_deny_a_rename_whose_lines_were_reordered(tmp_path: Path) -> None:
|
|
564
|
+
clone_path = _repository_with_rename(tmp_path, None, reorder_lines=True)
|
|
565
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["references/asset-specs.html"]
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def test_should_deny_a_byte_identical_rename_from_one_page_type_to_another(tmp_path: Path) -> None:
|
|
569
|
+
clone_path = _repository_with_rename(tmp_path, None, "Widget.tsx", "site/widget.html")
|
|
570
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["site/widget.html"]
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def test_should_report_unreadable_git_output_as_unknown() -> None:
|
|
574
|
+
assert gate._git_changes([":100644 100644 abc R100", "a.html", "b.html"]) is None
|
|
575
|
+
assert gate._git_changes([":100644 100644 aaa bbb R100", "a.html"]) is None
|
|
576
|
+
assert gate._git_changes([":100644 100644 aaa bbb M", "a.html", "stray", ""]) is None
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def test_should_keep_a_page_whose_name_holds_a_quote(tmp_path: Path) -> None:
|
|
580
|
+
clone_path = _repository_with_change(tmp_path, 'q"t.html')
|
|
581
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ['q"t.html']
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def test_should_keep_a_page_whose_name_has_non_ascii_letters(tmp_path: Path) -> None:
|
|
585
|
+
clone_path = _repository_with_change(tmp_path, "página.html")
|
|
586
|
+
assert gate.visible_changed_files(str(clone_path), "feature") == ["página.html"]
|
|
587
|
+
|
|
588
|
+
|
|
438
589
|
def test_should_deny_as_unreadable_when_the_compare_api_fails(
|
|
439
590
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
440
591
|
) -> None:
|
|
@@ -451,8 +602,8 @@ def test_should_deny_as_unreadable_when_the_compare_api_fails(
|
|
|
451
602
|
assert "before any change to this gate" in reason
|
|
452
603
|
|
|
453
604
|
|
|
454
|
-
def
|
|
455
|
-
return [f"pkg/module_{each_index}.py" for each_index in range(count)]
|
|
605
|
+
def _python_status_lines(count: int) -> list[str]:
|
|
606
|
+
return [_compare_line("M", "", f"pkg/module_{each_index}.py") for each_index in range(count)]
|
|
456
607
|
|
|
457
608
|
|
|
458
609
|
def test_should_deny_as_unreadable_when_a_full_compare_page_lists_no_visible_file(
|
|
@@ -463,7 +614,7 @@ def test_should_deny_as_unreadable_when_a_full_compare_page_lists_no_visible_fil
|
|
|
463
614
|
monkeypatch.setattr(
|
|
464
615
|
gate,
|
|
465
616
|
"_gh_api_lines",
|
|
466
|
-
_fake_gh_api({compare_endpoint:
|
|
617
|
+
_fake_gh_api({compare_endpoint: _python_status_lines(COMPARE_FILE_LIST_LIMIT)}, all_endpoints),
|
|
467
618
|
)
|
|
468
619
|
assert COMPARE_FILE_LIST_LIMIT == 300
|
|
469
620
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
@@ -480,7 +631,7 @@ def test_should_allow_a_short_compare_page_that_lists_only_python(
|
|
|
480
631
|
monkeypatch.setattr(
|
|
481
632
|
gate,
|
|
482
633
|
"_gh_api_lines",
|
|
483
|
-
_fake_gh_api({compare_endpoint:
|
|
634
|
+
_fake_gh_api({compare_endpoint: _python_status_lines(COMPARE_FILE_LIST_LIMIT - 1)}, all_endpoints),
|
|
484
635
|
)
|
|
485
636
|
payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
|
|
486
637
|
assert gate.remote_visible_changed_files("o/r", "main", "feature") == []
|
|
@@ -492,7 +643,7 @@ def test_should_deny_a_visible_file_on_a_full_compare_page(
|
|
|
492
643
|
) -> None:
|
|
493
644
|
all_endpoints: list[str] = []
|
|
494
645
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
495
|
-
all_paths = [*
|
|
646
|
+
all_paths = [*_python_status_lines(COMPARE_FILE_LIST_LIMIT - 1), _compare_line("M", "", "web/page.html")]
|
|
496
647
|
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: all_paths}, all_endpoints))
|
|
497
648
|
reason = gate.missing_look_reason(_shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature"))
|
|
498
649
|
assert reason is not None
|
|
@@ -505,7 +656,7 @@ def test_should_allow_a_page_the_compare_api_lists_when_the_proof_links_an_artif
|
|
|
505
656
|
) -> None:
|
|
506
657
|
all_endpoints: list[str] = []
|
|
507
658
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
508
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["page.html"]}, all_endpoints))
|
|
659
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "page.html")]}, all_endpoints))
|
|
509
660
|
body_path = tmp_path / "body.md"
|
|
510
661
|
body_path.write_text(PROVEN_BODY + "https://claude.ai/code/artifact/abc-123\n", encoding="utf-8")
|
|
511
662
|
payload = _shell(
|
|
@@ -531,7 +682,7 @@ def test_should_read_owner_and_repo_of_an_mcp_create_for_the_compare_api(
|
|
|
531
682
|
) -> None:
|
|
532
683
|
all_endpoints: list[str] = []
|
|
533
684
|
compare_endpoint = "repos/o/r/compare/main...feature"
|
|
534
|
-
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: ["tool.py"]}, all_endpoints))
|
|
685
|
+
monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({compare_endpoint: [_compare_line("M", "", "tool.py")]}, all_endpoints))
|
|
535
686
|
payload = _mcp_create_on_branch(PROVEN_BODY, tmp_path)
|
|
536
687
|
payload["tool_input"].update(owner="o", repo="r", base="main")
|
|
537
688
|
assert gate.missing_look_reason(payload) is None
|
|
@@ -123,7 +123,17 @@ REPOSITORY_FLAG_ASSIGNMENT_PREFIX = "--repo="
|
|
|
123
123
|
GIT_TIMEOUT_SECONDS = 5
|
|
124
124
|
GH_TIMEOUT_SECONDS = 15
|
|
125
125
|
COMPARE_ENDPOINT_TEMPLATE = "repos/{repository}/compare/{base_branch}...{head_branch}"
|
|
126
|
-
|
|
126
|
+
PURE_RENAME_STATUS = "R100"
|
|
127
|
+
RAW_RECORD_PREFIX = ":"
|
|
128
|
+
RAW_RENAME_PATH_COUNT = 2
|
|
129
|
+
RAW_HEADER_FIELD_COUNT = 5
|
|
130
|
+
RAW_RENAME_STATUS_LETTER = "R"
|
|
131
|
+
ALL_RAW_TWO_PATH_STATUS_LETTERS = (RAW_RENAME_STATUS_LETTER, "C")
|
|
132
|
+
COMPARE_FILE_STATUS_QUERY = (
|
|
133
|
+
'.files[] | [(if .status == "renamed" and .changes == 0 then "'
|
|
134
|
+
+ PURE_RENAME_STATUS
|
|
135
|
+
+ '" else .status end), (.previous_filename // ""), .filename] | @json'
|
|
136
|
+
)
|
|
127
137
|
COMPARE_FILE_LIST_LIMIT = 300
|
|
128
138
|
REPOSITORY_ENDPOINT_TEMPLATE = "repos/{repository}"
|
|
129
139
|
DEFAULT_BRANCH_QUERY = ".default_branch"
|
package/package.json
CHANGED
|
@@ -59,6 +59,7 @@ from dev_env_scripts_constants.account_broker_constants import (
|
|
|
59
59
|
utc_time_text,
|
|
60
60
|
)
|
|
61
61
|
from dev_env_scripts_constants.claude_account_constants import (
|
|
62
|
+
ALL_DEACTIVATED_ACCOUNT_NAMES,
|
|
62
63
|
CLAUDE_ACCOUNT_ORDER_FILE_NAME,
|
|
63
64
|
CLAUDE_LAUNCHER_PROGRAM,
|
|
64
65
|
CREDENTIALS_FILE_NAME,
|
|
@@ -133,9 +134,16 @@ def _extra_homes(main_home: Path) -> tuple[Path, ...]:
|
|
|
133
134
|
raise BrokerConfigurationError(f"invalid account list {extras_path}: {error}") from error
|
|
134
135
|
|
|
135
136
|
|
|
137
|
+
def _is_deactivated(account: Account) -> bool:
|
|
138
|
+
all_names = _order_names(account) | {account.home.name.casefold()}
|
|
139
|
+
return not ALL_DEACTIVATED_ACCOUNT_NAMES.isdisjoint(all_names)
|
|
140
|
+
|
|
141
|
+
|
|
136
142
|
def _append_claude_account(
|
|
137
143
|
all_accounts: list[Account], all_seen: set[str], account: Account, main_home: Path
|
|
138
144
|
) -> None:
|
|
145
|
+
if _is_deactivated(account):
|
|
146
|
+
return
|
|
139
147
|
key = str(account.home).casefold()
|
|
140
148
|
if key == str(main_home).casefold():
|
|
141
149
|
all_accounts[0] = Account(Product.CLAUDE, "main", main_home, True, account.command)
|
|
@@ -182,7 +190,8 @@ def load_claude_accounts() -> tuple[Account, ...]:
|
|
|
182
190
|
|
|
183
191
|
Returns:
|
|
184
192
|
Main and additional accounts in configured order, each with its place in the account order file
|
|
185
|
-
and, for a home under the profiles root, its profile name.
|
|
193
|
+
and, for a home under the profiles root, its profile name. An account named in
|
|
194
|
+
``ALL_DEACTIVATED_ACCOUNT_NAMES`` is left out.
|
|
186
195
|
|
|
187
196
|
Raises:
|
|
188
197
|
BrokerConfigurationError: An account list is unreadable.
|
|
@@ -79,9 +79,9 @@ function main() {
|
|
|
79
79
|
const skillsDirectory = join(claudeHome, 'skills');
|
|
80
80
|
const agentsHomeSkillsDirectory = join(sandboxHome, '.agents', 'skills');
|
|
81
81
|
const installedSkills = existsSync(skillsDirectory)
|
|
82
|
-
? readdirSync(skillsDirectory, { withFileTypes: true }).filter((entry) => entry.
|
|
82
|
+
? readdirSync(skillsDirectory, { withFileTypes: true }).filter((entry) => entry.isSymbolicLink())
|
|
83
83
|
: [];
|
|
84
|
-
record('skills installed', installedSkills.length > 0, `${installedSkills.length} skill
|
|
84
|
+
record('skills installed', installedSkills.length > 0, `${installedSkills.length} skill links`);
|
|
85
85
|
record(
|
|
86
86
|
'skills live under ~/.agents/skills',
|
|
87
87
|
existsSync(agentsHomeSkillsDirectory)
|
|
@@ -89,8 +89,13 @@ function main() {
|
|
|
89
89
|
agentsHomeSkillsDirectory,
|
|
90
90
|
);
|
|
91
91
|
record(
|
|
92
|
-
'~/.claude/skills is a
|
|
93
|
-
existsSync(skillsDirectory)
|
|
92
|
+
'~/.claude/skills is a folder of skill links',
|
|
93
|
+
existsSync(skillsDirectory)
|
|
94
|
+
&& lstatSync(skillsDirectory).isDirectory()
|
|
95
|
+
&& installedSkills.length > 0
|
|
96
|
+
&& installedSkills.every((entry) => existsSync(join(skillsDirectory, entry.name))
|
|
97
|
+
&& existsSync(join(agentsHomeSkillsDirectory, entry.name))
|
|
98
|
+
&& realpathSync(join(skillsDirectory, entry.name)) === realpathSync(join(agentsHomeSkillsDirectory, entry.name))),
|
|
94
99
|
skillsDirectory,
|
|
95
100
|
);
|
|
96
101
|
const sampleSkillName = installedSkills.find((entry) => existsSync(join(skillsDirectory, entry.name, 'SKILL.md')))?.name;
|
|
@@ -98,14 +103,14 @@ function main() {
|
|
|
98
103
|
const lookupSkillPath = join(skillsDirectory, sampleSkillName, 'SKILL.md');
|
|
99
104
|
const canonicalSkillPath = join(agentsHomeSkillsDirectory, sampleSkillName, 'SKILL.md');
|
|
100
105
|
record(
|
|
101
|
-
'skill files match through the lookup
|
|
106
|
+
'skill files match through the lookup link',
|
|
102
107
|
existsSync(lookupSkillPath)
|
|
103
108
|
&& existsSync(canonicalSkillPath)
|
|
104
109
|
&& realpathSync(lookupSkillPath) === realpathSync(canonicalSkillPath),
|
|
105
110
|
sampleSkillName,
|
|
106
111
|
);
|
|
107
112
|
} else {
|
|
108
|
-
record('skill files match through the lookup
|
|
113
|
+
record('skill files match through the lookup link', false, 'no skill links');
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
const agentsLookupDirectory = join(claudeHome, 'agents');
|
|
@@ -16,6 +16,8 @@ const DRIVER_TIMEOUT_MILLISECONDS = 60_000;
|
|
|
16
16
|
});
|
|
17
17
|
assert.equal(lifecycleProcess.status, 0, `${lifecycleProcess.stdout}\n${lifecycleProcess.stderr}`);
|
|
18
18
|
assert.match(lifecycleProcess.stdout, /ALL CHECKS PASSED/);
|
|
19
|
+
assert.match(lifecycleProcess.stdout, /\[PASS\] ~\/\.claude\/skills is a folder of skill links/);
|
|
20
|
+
assert.match(lifecycleProcess.stdout, /\[PASS\] skill files match through the lookup link/);
|
|
19
21
|
assert.match(lifecycleProcess.stdout, /Sandbox removed:/);
|
|
20
22
|
});
|
|
21
23
|
|
|
@@ -9,6 +9,7 @@ main account so its owner never runs out.
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
11
|
from dataclasses import dataclass
|
|
12
|
+
from pathlib import PureWindowsPath
|
|
12
13
|
|
|
13
14
|
from dev_env_scripts_constants.shared_tree_constants import CLAUDE_CONFIG_DIR_ENV_VAR
|
|
14
15
|
|
|
@@ -77,6 +78,19 @@ CLAUDE_LAUNCHER_PROGRAM: LauncherProgram = LauncherProgram(
|
|
|
77
78
|
)
|
|
78
79
|
"""Launcher that runs Claude with ``CLAUDE_CONFIG_DIR`` set to the profile home."""
|
|
79
80
|
|
|
81
|
+
ALL_DEACTIVATED_PROFILE_NAMES: tuple[str, ...] = ("org-mel",)
|
|
82
|
+
"""Lowercase profile names of deactivated Claude accounts the broker never picks."""
|
|
83
|
+
|
|
84
|
+
ALL_DEACTIVATED_ACCOUNT_NAMES: frozenset[str] = frozenset(
|
|
85
|
+
each_name.casefold()
|
|
86
|
+
for each_profile_name in ALL_DEACTIVATED_PROFILE_NAMES
|
|
87
|
+
for each_name in (
|
|
88
|
+
each_profile_name,
|
|
89
|
+
PureWindowsPath(CLAUDE_LAUNCHER_PROGRAM.file_name_template.format(profile_name=each_profile_name)).stem,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
"""Every name a deactivated account answers to: its profile name and its launcher name."""
|
|
93
|
+
|
|
80
94
|
LAUNCHER_REPLACED_SUFFIX: str = ".replaced-"
|
|
81
95
|
"""Suffix, before the run time, of an older launcher the sync moved aside."""
|
|
82
96
|
|
|
@@ -130,6 +130,93 @@ def test_should_assign_claude_priorities_from_the_order_file(
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
|
|
133
|
+
def test_should_leave_a_deactivated_account_out_of_the_claude_roster(
|
|
134
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
135
|
+
) -> None:
|
|
136
|
+
main_home = _claude_home_with_extras(monkeypatch, tmp_path, ["org-mel", "ev"])
|
|
137
|
+
(main_home / "claude-account-order.json").write_text(
|
|
138
|
+
json.dumps(["ev", "claude-org-mel"]), encoding="utf-8"
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
accounts = support.load_claude_accounts()
|
|
142
|
+
|
|
143
|
+
assert [each_account.name for each_account in accounts] == ["main", "ev"]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_should_leave_a_deactivated_chain_account_out_of_the_claude_roster(
|
|
147
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
148
|
+
) -> None:
|
|
149
|
+
main_home = _claude_home_with_extras(monkeypatch, tmp_path, ["ev"])
|
|
150
|
+
(main_home / "claude-chain.json").write_text(
|
|
151
|
+
json.dumps(
|
|
152
|
+
{
|
|
153
|
+
"chain": [
|
|
154
|
+
{"command": "C:\\bin\\claude-ORG-MEL.cmd", "credentials_path": str(tmp_path / "dead" / ".credentials.json")},
|
|
155
|
+
{"command": "C:\\bin\\other.cmd", "credentials_path": str(tmp_path / "other" / ".credentials.json")},
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
encoding="utf-8",
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
accounts = support.load_claude_accounts()
|
|
163
|
+
|
|
164
|
+
assert [each_account.name for each_account in accounts] == ["main", "C:\\bin\\other.cmd", "ev"]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_should_keep_the_account_that_only_shares_a_prefix_with_a_deactivated_one(
|
|
168
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
169
|
+
) -> None:
|
|
170
|
+
_claude_home_with_extras(monkeypatch, tmp_path, ["mel", "org-mel-two"])
|
|
171
|
+
|
|
172
|
+
accounts = support.load_claude_accounts()
|
|
173
|
+
|
|
174
|
+
assert [each_account.name for each_account in accounts] == ["main", "mel", "org-mel-two"]
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def test_should_leave_out_a_chain_account_whose_credentials_sit_in_a_deactivated_home(
|
|
178
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
179
|
+
) -> None:
|
|
180
|
+
main_home = _claude_home_with_extras(monkeypatch, tmp_path, ["ev"])
|
|
181
|
+
(main_home / "claude-chain.json").write_text(
|
|
182
|
+
json.dumps({"chain": [{"command": "C:\\bin\\work.cmd", "credentials_path": str(tmp_path / "org-mel" / ".credentials.json")}]}),
|
|
183
|
+
encoding="utf-8",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
accounts = support.load_claude_accounts()
|
|
187
|
+
|
|
188
|
+
assert [each_account.name for each_account in accounts] == ["main", "ev"]
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_should_keep_a_live_extra_account_when_a_deactivated_chain_entry_points_at_its_home(
|
|
192
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
193
|
+
) -> None:
|
|
194
|
+
main_home = _claude_home_with_extras(monkeypatch, tmp_path, ["ev"])
|
|
195
|
+
(main_home / "claude-chain.json").write_text(
|
|
196
|
+
json.dumps({"chain": [{"command": "claude-org-mel.cmd", "credentials_path": str(tmp_path / "profiles" / "ev" / ".credentials.json")}]}),
|
|
197
|
+
encoding="utf-8",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
accounts = support.load_claude_accounts()
|
|
201
|
+
|
|
202
|
+
assert [each_account.name for each_account in accounts] == ["main", "ev"]
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_should_keep_the_main_command_when_a_deactivated_chain_entry_names_the_main_home(
|
|
206
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
207
|
+
) -> None:
|
|
208
|
+
main_home = _claude_home_with_extras(monkeypatch, tmp_path, ["ev"])
|
|
209
|
+
(main_home / "claude-chain.json").write_text(json.dumps({"chain": [{"command": "claude-org-mel.cmd"}]}), encoding="utf-8")
|
|
210
|
+
|
|
211
|
+
accounts = support.load_claude_accounts()
|
|
212
|
+
|
|
213
|
+
assert [(each_account.name, each_account.command) for each_account in accounts] == [("main", "claude"), ("ev", "ev")]
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_should_name_each_deactivated_account_by_its_profile_and_launcher() -> None:
|
|
217
|
+
assert support.ALL_DEACTIVATED_ACCOUNT_NAMES == {"org-mel", "claude-org-mel"}
|
|
218
|
+
|
|
219
|
+
|
|
133
220
|
def test_should_read_an_order_file_saved_with_a_byte_order_mark(
|
|
134
221
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
135
222
|
) -> None:
|