mystack-rig 1.7.2__tar.gz → 1.7.3__tar.gz

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.
Files changed (128) hide show
  1. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/PKG-INFO +4 -2
  2. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/README.md +3 -1
  3. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/remote_dev.py +53 -1
  4. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/PKG-INFO +4 -2
  5. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/scm_version.json +2 -2
  6. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_git_credentials_and_author.py +67 -3
  7. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.coveragerc +0 -0
  8. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.git-blame-ignore-revs +0 -0
  9. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.github/workflows/release.yml +0 -0
  10. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.github/workflows/tests.yml +0 -0
  11. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.gitignore +0 -0
  12. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.rig/playbooks/README.md +0 -0
  13. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/.rig/playbooks/vpn-gateway.yml +0 -0
  14. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/CLAUDE.md +0 -0
  15. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/CLI_STORAGE_SUMMARY.md +0 -0
  16. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/Dockerfile +0 -0
  17. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/GIT_CLONE_FEATURE.md +0 -0
  18. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/GLOSSARY.md +0 -0
  19. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/HETZNER_STORAGE_GUIDE.md +0 -0
  20. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/HETZNER_STORAGE_SECURITY_GUIDE.md +0 -0
  21. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/LICENSE +0 -0
  22. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/Makefile +0 -0
  23. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/README_REAL_E2E.md +0 -0
  24. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/STORAGE_CLI_GUIDE.md +0 -0
  25. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0001-per-profile-generated-state-bucket.md +0 -0
  26. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0002-outputs-as-separate-object-via-file-handoff.md +0 -0
  27. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0003-mcp-servers-declared-once-rendered-at-authorize.md +0 -0
  28. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0004-agents-run-as-live-agents-in-tmux.md +0 -0
  29. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0005-docker-in-configure-for-devcontainers.md +0 -0
  30. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/adr/0006-workspace-user-instead-of-root.md +0 -0
  31. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/architecture.md +0 -0
  32. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/architecture.png +0 -0
  33. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/docs/architecture.svg +0 -0
  34. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/forged-idea.md +0 -0
  35. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/pyproject.toml +0 -0
  36. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/pytest.ini +0 -0
  37. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/requirements.txt +0 -0
  38. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/sample.env +0 -0
  39. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/scripts/coverage_badge.py +0 -0
  40. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/scripts/pypi_version.py +0 -0
  41. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/setup.cfg +0 -0
  42. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/__init__.py +0 -0
  43. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/__init__.py +0 -0
  44. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/__main__.py +0 -0
  45. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/agents.py +0 -0
  46. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/ansible_filters/__init__.py +0 -0
  47. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/ansible_filters/rig_live.py +0 -0
  48. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/ansible_filters/rig_mcp.py +0 -0
  49. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/assets/rig-agent-queue +0 -0
  50. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/assets/rig-agent-state +0 -0
  51. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/assets/tmux.conf +0 -0
  52. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/config.py +0 -0
  53. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/devcontainers.py +0 -0
  54. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/encrypt.py +0 -0
  55. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/git.py +0 -0
  56. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/git_author.py +0 -0
  57. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/last_env.py +0 -0
  58. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/last_session.py +0 -0
  59. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/last_target.py +0 -0
  60. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/live_agent.py +0 -0
  61. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/log.py +0 -0
  62. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/main.py +0 -0
  63. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/mcp.py +0 -0
  64. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/outputs.py +0 -0
  65. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/requirements.txt +0 -0
  66. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/snapshots.py +0 -0
  67. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/state_bucket.py +0 -0
  68. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/storage.py +0 -0
  69. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/vault_keys.py +0 -0
  70. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/vpn.py +0 -0
  71. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/cli/workspace_user.py +0 -0
  72. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/SOURCES.txt +0 -0
  73. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/dependency_links.txt +0 -0
  74. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/entry_points.txt +0 -0
  75. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/requires.txt +0 -0
  76. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/scm_file_list.json +0 -0
  77. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/src/mystack_rig.egg-info/top_level.txt +0 -0
  78. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/test_hetzner_integration.py +0 -0
  79. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/conftest.py +0 -0
  80. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_agents.py +0 -0
  81. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_ansible_galaxy.py +0 -0
  82. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_attach_command.py +0 -0
  83. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_credential_security.py +0 -0
  84. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_destroy_command.py +0 -0
  85. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_dev_command.py +0 -0
  86. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_devcontainers.py +0 -0
  87. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_encrypt_command.py +0 -0
  88. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_encrypt_coverage.py +0 -0
  89. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_firewall_client_ip.py +0 -0
  90. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_git_clone_unit.py +0 -0
  91. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_git_manager.py +0 -0
  92. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_gitignore_init.py +0 -0
  93. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_hetzner_storage.py +0 -0
  94. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_init_command.py +0 -0
  95. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_inspect_describe.py +0 -0
  96. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_last_env.py +0 -0
  97. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_last_session.py +0 -0
  98. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_last_target.py +0 -0
  99. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_live_agent.py +0 -0
  100. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_live_agent_cli.py +0 -0
  101. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_log.py +0 -0
  102. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_main_coverage.py +0 -0
  103. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_mcp_command.py +0 -0
  104. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_mcp_render.py +0 -0
  105. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_outputs.py +0 -0
  106. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_outputs_storage.py +0 -0
  107. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_pypi_version.py +0 -0
  108. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_python_floor.py +0 -0
  109. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_r2_storage.py +0 -0
  110. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_real_e2e_integration.py +0 -0
  111. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_real_e2e_storage.py +0 -0
  112. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_real_e2e_vpn.py +0 -0
  113. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_real_e2e_vpn_tunnel.py +0 -0
  114. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_remote_dev.py +0 -0
  115. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_remote_dev_coverage_extensions.py +0 -0
  116. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_rig_ansible_vars.py +0 -0
  117. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_rig_config.py +0 -0
  118. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_secret_prompt_hidden.py +0 -0
  119. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_setup_provision.py +0 -0
  120. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_simulation_storage.py +0 -0
  121. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_small_module_coverage.py +0 -0
  122. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_snapshots.py +0 -0
  123. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_state_bucket.py +0 -0
  124. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_storage_basic.py +0 -0
  125. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_vault_keys.py +0 -0
  126. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_vpn_optional.py +0 -0
  127. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_vpn_unit.py +0 -0
  128. {mystack_rig-1.7.2 → mystack_rig-1.7.3}/tests/test_workspace_git_clone.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.7.2
3
+ Version: 1.7.3
4
4
  Summary: Ephemeral remotes with full local parity for coding agents
5
5
  Author: mystack-cloud
6
6
  License-Expression: MIT
@@ -481,7 +481,9 @@ MIT
481
481
  shell, which never reads `/etc/profile.d`), so `gh` and `glab` work out of the
482
482
  box in both;
483
483
  - a system-wide git credential helper (`/usr/local/bin/rig-git-credential`)
484
- answers `github.com` / `gitlab.com` HTTPS requests from that same file, so
484
+ answers `github.com` / `gitlab.com` HTTPS requests from that same file (and, for a
485
+ Repo with its own `password_var` such as `<project>_git_pat`, requests to that
486
+ Repo's host from `~/.config/rig/git-hosts`), so
485
487
  `git clone`, `git push` and the `materialize.yml` clone task all use plain
486
488
  URLs (`https://github.com/org/repo.git`) and nothing sits in `.git/config`
487
489
  or `git remote -v`. Other users on the VM (besides root) can't read the file and get no
@@ -459,7 +459,9 @@ MIT
459
459
  shell, which never reads `/etc/profile.d`), so `gh` and `glab` work out of the
460
460
  box in both;
461
461
  - a system-wide git credential helper (`/usr/local/bin/rig-git-credential`)
462
- answers `github.com` / `gitlab.com` HTTPS requests from that same file, so
462
+ answers `github.com` / `gitlab.com` HTTPS requests from that same file (and, for a
463
+ Repo with its own `password_var` such as `<project>_git_pat`, requests to that
464
+ Repo's host from `~/.config/rig/git-hosts`), so
463
465
  `git clone`, `git push` and the `materialize.yml` clone task all use plain
464
466
  URLs (`https://github.com/org/repo.git`) and nothing sits in `.git/config`
465
467
  or `git remote -v`. Other users on the VM (besides root) can't read the file and get no
@@ -698,6 +698,7 @@ def build_rig_ansible_vars(
698
698
  except Exception:
699
699
  identity = ""
700
700
  author = {"name": "", "email": ""}
701
+ vars_out["rig_git_repo_tokens"] = git_repo_token_vars(project)
701
702
  vars_out["rig_identity"] = identity
702
703
  vars_out["rig_git_author_name"] = author["name"]
703
704
  vars_out["rig_git_author_email"] = author["email"]
@@ -706,6 +707,32 @@ def build_rig_ansible_vars(
706
707
  return vars_out
707
708
 
708
709
 
710
+ def git_repo_token_vars(project: Any) -> list[dict[str, str]]:
711
+ """``{host, user, var}`` for each HTTPS clone Repo that has its own ``password_var``.
712
+
713
+ Only the variable *name* is passed on; authorize resolves the secret, so a
714
+ PAT stored per Repo (``<project>_git_pat``) reaches the VM's git credential
715
+ helper like ``github_pat`` / ``gitlab_pat`` do.
716
+ """
717
+ if project is None:
718
+ return []
719
+ from cli.encrypt import _git_host, detect_git_provider
720
+
721
+ found: list[dict[str, str]] = []
722
+ for item in (project.get_vars("git") or {}).get("clone_repos") or []:
723
+ if not isinstance(item, dict):
724
+ continue
725
+ repo, var = str(item.get("repo") or ""), str(item.get("password_var") or "")
726
+ host = _git_host(repo)
727
+ if not (repo.startswith("https://") and var and host):
728
+ continue
729
+ user = "x-access-token" if detect_git_provider(repo) == "github" else "oauth2"
730
+ entry = {"host": host, "user": user, "var": var}
731
+ if entry not in found:
732
+ found.append(entry)
733
+ return found
734
+
735
+
709
736
  def remote_workspace_path(*parts: str) -> str:
710
737
  """Build an absolute path under the remote workspace root."""
711
738
  cleaned = [part.strip("/") for part in parts if part and str(part).strip("/")]
@@ -4514,7 +4541,7 @@ AUTHORIZE_PLAYBOOK = r"""---
4514
4541
  vars:
4515
4542
  _rig_gh_token: "{{ github_pat | default('') }}"
4516
4543
  _rig_gl_token: "{{ gitlab_pat | default('') }}"
4517
- when: (_rig_gh_token | length > 0) or (_rig_gl_token | length > 0)
4544
+ when: (_rig_gh_token | length > 0) or (_rig_gl_token | length > 0) or (rig_git_repo_tokens | default([]) | length > 0)
4518
4545
  block:
4519
4546
  - name: Ensure the rig config directory exists
4520
4547
  file:
@@ -4535,6 +4562,21 @@ AUTHORIZE_PLAYBOOK = r"""---
4535
4562
  {% endif %}
4536
4563
  no_log: true
4537
4564
 
4565
+ # PATs stored per Repo (password_var, e.g. <project>_git_pat): one
4566
+ # "host user token" line each, for the credential helper below.
4567
+ - name: Write the per-repo token file (workspace user only)
4568
+ copy:
4569
+ dest: /home/{{ rig_user }}/.config/rig/git-hosts
4570
+ mode: "0600"
4571
+ content: |
4572
+ {% for t in rig_git_repo_tokens | default([]) %}
4573
+ {% set _tok = lookup('vars', t.var, default='') %}
4574
+ {% if _tok | length > 0 %}
4575
+ {{ t.host }} {{ t.user }} {{ _tok }}
4576
+ {% endif %}
4577
+ {% endfor %}
4578
+ no_log: true
4579
+
4538
4580
  - name: Export the tokens in login shells (gh and glab work out of the box)
4539
4581
  copy:
4540
4582
  dest: /etc/profile.d/rig-git-provider.sh
@@ -4561,6 +4603,16 @@ AUTHORIZE_PLAYBOOK = r"""---
4561
4603
  [ -z "$key" ] && break
4562
4604
  [ "$key" = host ] && host="$value"
4563
4605
  done
4606
+ # A token stored for this exact host (per-Repo password_var) wins.
4607
+ hosts=/home/{{ rig_user }}/.config/rig/git-hosts
4608
+ if [ -r "$hosts" ]; then
4609
+ while read -r h u p; do
4610
+ if [ "$h" = "$host" ] && [ -n "$p" ]; then
4611
+ printf 'username=%s\npassword=%s\n' "$u" "$p"
4612
+ exit 0
4613
+ fi
4614
+ done < "$hosts"
4615
+ fi
4564
4616
  [ -r /home/{{ rig_user }}/.config/rig/git-provider.env ] || exit 0
4565
4617
  . /home/{{ rig_user }}/.config/rig/git-provider.env
4566
4618
  case "$host" in
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.7.2
3
+ Version: 1.7.3
4
4
  Summary: Ephemeral remotes with full local parity for coding agents
5
5
  Author: mystack-cloud
6
6
  License-Expression: MIT
@@ -481,7 +481,9 @@ MIT
481
481
  shell, which never reads `/etc/profile.d`), so `gh` and `glab` work out of the
482
482
  box in both;
483
483
  - a system-wide git credential helper (`/usr/local/bin/rig-git-credential`)
484
- answers `github.com` / `gitlab.com` HTTPS requests from that same file, so
484
+ answers `github.com` / `gitlab.com` HTTPS requests from that same file (and, for a
485
+ Repo with its own `password_var` such as `<project>_git_pat`, requests to that
486
+ Repo's host from `~/.config/rig/git-hosts`), so
485
487
  `git clone`, `git push` and the `materialize.yml` clone task all use plain
486
488
  URLs (`https://github.com/org/repo.git`) and nothing sits in `.git/config`
487
489
  or `git remote -v`. Other users on the VM (besides root) can't read the file and get no
@@ -1,7 +1,7 @@
1
1
  {
2
- "tag": "1.7.2",
2
+ "tag": "1.7.3",
3
3
  "distance": 0,
4
- "node": "g38e76953b1c24d8ab22c3bad8130888076500a63",
4
+ "node": "g2225e2ef4f75670af0950c25b440ccee3a3f9e55",
5
5
  "dirty": false,
6
6
  "branch": "HEAD",
7
7
  "node_date": "2026-11-27"
@@ -209,9 +209,8 @@ def _helper_script(tmp_path):
209
209
  assert helper["copy"]["mode"] == "0755"
210
210
  token_file = tmp_path / "git-provider.env"
211
211
  script = tmp_path / "rig-git-credential"
212
- script.write_text(
213
- helper["copy"]["content"].replace("/home/{{ rig_user }}/.config/rig/git-provider.env", str(token_file))
214
- )
212
+ content = helper["copy"]["content"].replace("/home/{{ rig_user }}/.config/rig/git-provider.env", str(token_file))
213
+ script.write_text(content.replace("/home/{{ rig_user }}/.config/rig/git-hosts", str(tmp_path / "git-hosts")))
215
214
  script.chmod(script.stat().st_mode | stat.S_IXUSR)
216
215
  return script, token_file
217
216
 
@@ -245,6 +244,71 @@ def test_helper_stays_silent_when_it_has_nothing_to_say(tmp_path):
245
244
  assert _ask(script, "erase", "github.com") == ""
246
245
 
247
246
 
247
+ def test_helper_serves_a_per_repo_token_for_its_host(tmp_path):
248
+ """A PAT stored per Repo (password_var) answers git pull, even on a host rig can't classify."""
249
+ script, token_file = _helper_script(tmp_path)
250
+ (tmp_path / "git-hosts").write_text("git.corp.example oauth2 glpat-repo\ngitlab.com oauth2 glpat-own\n")
251
+ token_file.write_text("GITLAB_TOKEN=glpat-default\n")
252
+
253
+ assert _ask(script, "get", "git.corp.example") == "username=oauth2\npassword=glpat-repo\n"
254
+ assert _ask(script, "get", "gitlab.com") == "username=oauth2\npassword=glpat-own\n" # per-repo wins
255
+ assert _ask(script, "get", "other.example") == ""
256
+
257
+
258
+ def test_helper_without_provider_file_still_serves_per_repo_token(tmp_path):
259
+ script, _token_file = _helper_script(tmp_path)
260
+ (tmp_path / "git-hosts").write_text("gitlab.com oauth2 glpat-own\n")
261
+
262
+ assert _ask(script, "get", "gitlab.com") == "username=oauth2\npassword=glpat-own\n"
263
+
264
+
265
+ def test_authorize_writes_per_repo_tokens_from_their_vars():
266
+ import jinja2
267
+
268
+ block = _provider_block()
269
+ task = next(t for t in block if t["name"].startswith("Write the per-repo token file"))
270
+ assert task["copy"]["mode"] == "0600" and task["no_log"] is True
271
+ secrets = {"p_git_pat": "glpat-1", "unset": ""}
272
+ template = jinja2.Environment().from_string(task["copy"]["content"])
273
+ rendered = template.render(
274
+ lookup=lambda _kind, name, default="": secrets.get(name, default),
275
+ rig_git_repo_tokens=[
276
+ {"host": "gitlab.com", "user": "oauth2", "var": "p_git_pat"},
277
+ {"host": "x.example", "user": "oauth2", "var": "unset"},
278
+ ],
279
+ )
280
+ assert rendered.strip() == "gitlab.com oauth2 glpat-1"
281
+ assert next(t for t in _authorize_tasks() if t["name"] == "Provider tokens for git, gh and glab")["when"].count(
282
+ "rig_git_repo_tokens"
283
+ )
284
+
285
+
286
+ def test_git_repo_token_vars_lists_https_repos_with_their_own_password_var():
287
+ from cli.remote_dev import git_repo_token_vars
288
+
289
+ class Project:
290
+ def get_vars(self, key):
291
+ assert key == "git"
292
+ return {
293
+ "clone_repos": [
294
+ {"repo": "https://gitlab.com/o/a.git", "password_var": "a_git_pat"},
295
+ {"repo": "https://gitlab.com/o/a2.git", "password_var": "a_git_pat"},
296
+ {"repo": "https://github.com/o/b.git", "password_var": "b_git_pat"},
297
+ {"repo": "https://git.corp.example/o/c.git", "password_var": "c_git_pat"},
298
+ {"repo": "git@gitlab.com:o/d.git", "password_var": "d_git_pat"},
299
+ {"repo": "https://gitlab.com/o/e.git"},
300
+ "junk",
301
+ ]
302
+ }
303
+
304
+ assert git_repo_token_vars(Project()) == [
305
+ {"host": "gitlab.com", "user": "oauth2", "var": "a_git_pat"},
306
+ {"host": "github.com", "user": "x-access-token", "var": "b_git_pat"},
307
+ {"host": "git.corp.example", "user": "oauth2", "var": "c_git_pat"},
308
+ ]
309
+ assert git_repo_token_vars(None) == []
310
+
311
+
248
312
  def test_helper_works_through_real_git(tmp_path):
249
313
  script, token_file = _helper_script(tmp_path)
250
314
  token_file.write_text("GH_TOKEN=ghp_abc\n")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes