Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions glon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ def _ensure_git_repo_and_commit(
return False


def _has_origin_remote(repo_dir: Path) -> bool:
"""Return True when ``origin`` remote is configured in ``repo_dir``."""
def _get_origin_remote_url(repo_dir: Path) -> Optional[str]:
"""Return configured ``origin`` remote URL in ``repo_dir``, or ``None``."""
if not (repo_dir / ".git").exists():
return False
return None
try:
result = subprocess.run(
["git", "remote", "get-url", "origin"],
Expand All @@ -889,8 +889,28 @@ def _has_origin_remote(repo_dir: Path) -> bool:
check=False,
)
except FileNotFoundError:
return None
if result.returncode != 0:
return None
url = (result.stdout or "").strip()
return url or None


def _has_origin_remote(repo_dir: Path) -> bool:
"""Return True when ``origin`` remote is configured in ``repo_dir``."""
return _get_origin_remote_url(repo_dir) is not None


def _origin_matches_repository(origin_url: str, owner: str, repo: str) -> bool:
"""Return True when ``origin_url`` targets the expected ``owner/repo``."""
parsed = parse_git_url(origin_url)
if parsed is None:
return False
return result.returncode == 0 and bool((result.stdout or "").strip())
remote_owner, remote_repo = parsed
return (
remote_owner.lower() == owner.lower()
and remote_repo.lower() == repo.lower()
)


def _set_github_visibility(
Expand Down Expand Up @@ -1001,7 +1021,15 @@ def _publish_to_github(
) -> bool:
"""Create or update the GitHub repository via ``gh`` and push."""
full_name = f"{owner}/{repo}"
if _has_origin_remote(repo_dir):
origin_url = _get_origin_remote_url(repo_dir)
if origin_url is not None:
if not _origin_matches_repository(origin_url, owner, repo):
print(
f"Error: Existing origin remote '{origin_url}' does not match "
f"expected repository '{full_name}'. Refusing to change "
"visibility or push."
)
return False
return _attach_origin_and_push(
repo_dir, full_name, visibility, dry_run=dry_run, verbose=verbose
)
Expand Down
1 change: 1 addition & 0 deletions project/TICKETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ This file indexes governance tickets without taking ownership of
| **ticket-010** | [`README.md`](./ticket-010/README.md) | [`preprompt.md`](./ticket-010/preprompt.md) | - | [`ai-antigravity.md`](./ticket-010/ai-antigravity.md) | [`ai-antigravity-logs.txt`](./ticket-010/ai-antigravity-logs.txt) | [`changelog.md`](./ticket-010/changelog.md) |
| **ticket-011** | [`README.md`](./ticket-011/README.md) | [`preprompt.md`](./ticket-011/preprompt.md) | - | [`ai-antigravity.md`](./ticket-011/ai-antigravity.md) | [`ai-antigravity-logs.txt`](./ticket-011/ai-antigravity-logs.txt) | [`changelog.md`](./ticket-011/changelog.md) |
| **ticket-012** | [`README.md`](./ticket-012/README.md) | [`preprompt.md`](./ticket-012/preprompt.md) | - | [`ai-antigravity.md`](./ticket-012/ai-antigravity.md) | [`ai-antigravity-logs.txt`](./ticket-012/ai-antigravity-logs.txt) | [`changelog.md`](./ticket-012/changelog.md) |
| **ticket-013** | [`README.md`](./ticket-013/README.md) | [`preprompt.md`](./ticket-013/preprompt.md) | - | [`ai-antigravity.md`](./ticket-013/ai-antigravity.md) | [`ai-antigravity-logs.txt`](./ticket-013/ai-antigravity-logs.txt) | [`changelog.md`](./ticket-013/changelog.md) |
<!-- AUTO:TICKET_INDEX:END -->
4 changes: 2 additions & 2 deletions project/ticket-012/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

- **ID**: ticket-012
- **Owner**: agent:antigravity
- **Status**: IN_PROGRESS
- **Workflow state**: PUBLICATION
- **Status**: DONE
- **Workflow state**: DONE
- **Created**: 2026-11-23

## Goal and scope
Expand Down
21 changes: 21 additions & 0 deletions project/ticket-013/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ticket 013: Validate existing origin matches owner/repo before publish

- **ID**: ticket-013
- **Owner**: agent:antigravity
- **Status**: IN_PROGRESS
- **Workflow state**: PUBLICATION
- **Created**: 2026-11-23

## Goal and scope

SESSION_EXECUTION_AUTHORIZATION: Remediate the advisory security finding from Validator App PR #12 review by verifying that any existing `origin` remote URL targets the expected `owner/repo` derived from `github/<owner>/<repo>` before modifying repository visibility or pushing.

## Acceptance criteria

- [x] AC-01: `_publish_to_github` fails closed when an existing `origin` URL does not match `owner/repo` (no `gh repo edit`, `git push`, or `goal -a` executed).
- [x] AC-02: Unit tests in `tests/test_cli.py`, `mypy`, and `./project/governance-check.sh` pass.

## Participants

- Human participant: unresolved; no user-* file was created by this script.
- Agent participant: [ai-antigravity.md](ai-antigravity.md)
4 changes: 4 additions & 0 deletions project/ticket-013/ai-antigravity-logs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2026-11-23T12:28:00+01:00 ticket-013 verification log
- pytest -q: 70 passed
- mypy --python-version 3.10 glon: 0 issues
- ./project/governance-check.sh: GOV-PASS (0 errors, 0 warnings)
27 changes: 27 additions & 0 deletions project/ticket-013/ai-antigravity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
participant-id: agent:antigravity
participant: antigravity
role: agent
ticket: ticket-013
---
# Participant: antigravity (AI agent)

## Understanding

Address the Validator App advisory finding on PR #12: verify that any existing `origin` remote URL matches the `owner/repo` inferred from `github/<owner>/<repo>` before changing visibility or pushing.

## Execution plan

1. Add `_get_origin_remote_url` and `_origin_matches_repository` in `glon/cli.py` and fail closed on mismatch in `_publish_to_github`.
2. Add unit tests in `tests/test_cli.py`.
3. Verify with `pytest -q`, `mypy --python-version 3.10 glon`, and `./project/governance-check.sh`.

## Actual changes

- Recorded `SESSION_EXECUTION_AUTHORIZATION`.
- Added origin remote validation in `glon/cli.py` and unit tests in `tests/test_cli.py`.
- Closed merged `ticket-012` in `project/ticket-012/README.md`.

## Blockers

- None.
5 changes: 5 additions & 0 deletions project/ticket-013/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog for ticket-013

- Validated existing `origin` remote URL against path-derived `owner/repo` in `glon/cli.py` before calling `gh repo edit` or `git push`.
- Added unit tests for mismatched and case-insensitive matching origins in `tests/test_cli.py`.
- Closed already-merged `ticket-012` in `project/ticket-012/README.md`.
77 changes: 77 additions & 0 deletions project/ticket-013/intent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"schema": "new-project.intent/v3",
"ticket": "ticket-013",
"summary": "Validate existing origin matches owner/repo before publish",
"workstream": "application",
"classification": {
"kind": "BUG",
"priority": "P1",
"origin": "health"
},
"allowedPaths": [
"project/ticket-013/**",
"project/ticket-012/README.md",
"TODO.md",
"project/TICKETS.md",
"glon/cli.py",
"tests/test_cli.py"
],
"forbiddenPaths": [
"project/ticket-*/user-*.md"
],
"stacks": [],
"dependsOn": [],
"conflictsWith": [],
"integrationTicket": null,
"delivery": {
"acceptedBaseSha": "dee75db022ac1ead832c67c87c1e74e342abdd8e",
"targetBranch": "main",
"outcome": "Fail closed in glon publish when an existing origin remote does not match the github/<owner>/<repo> path.",
"nonGoals": [
"Add runtime dependencies",
"Auto-rewrite foreign origin URLs"
],
"complexity": "XS",
"estimatedMinutes": 10,
"budgets": {
"maxImplementationFiles": 2,
"maxAffectedComponents": 1,
"maxPublicInterfaceChanges": 0,
"maxRuntimeDependencies": 0
},
"architecture": {
"status": "accepted",
"decision": "Validate existing origin URL via parse_git_url in glon/cli.py before calling gh repo edit or git push.",
"components": [
{
"name": "glon-cli",
"paths": [
"glon/cli.py",
"tests/test_cli.py"
]
}
],
"responsibilityChanges": false,
"interfaceChanges": [],
"dataChanges": [],
"ui": {
"impact": "none",
"states": [],
"evidence": []
},
"rollback": "Revert commit on ticket/013-validate-origin-before-publish."
},
"runtimeDependencies": [],
"validation": [
{
"criterion": "AC-01",
"commands": [
"pytest -q",
"mypy --python-version 3.10 glon",
"./project/governance-check.sh"
],
"evidence": "All 70 tests, mypy, and governance checks pass."
}
]
}
}
12 changes: 12 additions & 0 deletions project/ticket-013/preprompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ticket preprompt

- **Task ID**: ticket-013
- **Task title**: Validate existing origin matches owner/repo before publish
- **Created**: 2026-11-23T11:27:21Z

Keep executable implementation outside this governance/evidence directory.
Read a human-owned user-*.md file only when one exists.
The request to execute this work creates SESSION_EXECUTION_AUTHORIZATION;
proceed within the recorded intent without a redundant confirmation prompt.
Require new authority for destructive action, secrets, external coordination,
material objective expansion and trusted merge approval.
60 changes: 60 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,63 @@ def test_main_private_outside_github_folder_prints_error(
mock_print.assert_any_call(
"Error: Current directory is not inside a github/<owner>/<repo> folder."
)

@patch("subprocess.run")
def test_publish_rejects_mismatched_origin_remote(self, mock_run) -> None:
"""Refuse to change visibility or push when origin targets another repo."""
with tempfile.TemporaryDirectory() as temp_dir:
repo_dir = Path(temp_dir) / "github" / "kvmouse" / "pi2w"
(repo_dir / ".git").mkdir(parents=True)

def fake_run(cmd, **kwargs):
if cmd[:3] == ["git", "remote", "get-url"]:
return MagicMock(
returncode=0,
stdout="git@github.com:other-owner/other-repo.git\n",
stderr="",
)
return MagicMock(returncode=0, stdout="", stderr="")

mock_run.side_effect = fake_run

result = publish_repository(repo_dir, "kvmouse", "pi2w", visibility="private")

assert result is False
commands = [call.args[0] for call in mock_run.call_args_list]
assert not any(cmd[0] == "gh" for cmd in commands)
assert not any(cmd[:2] == ["git", "push"] for cmd in commands)
assert not any(cmd[0] == "goal" for cmd in commands)

@patch("subprocess.run")
def test_publish_accepts_case_insensitive_matching_ssh_origin(
self, mock_run
) -> None:
"""Accept SSH origin matching owner/repo regardless of letter case."""
with tempfile.TemporaryDirectory() as temp_dir:
repo_dir = Path(temp_dir) / "github" / "semcod" / "glon"
(repo_dir / ".git").mkdir(parents=True)

def fake_run(cmd, **kwargs):
if cmd[:3] == ["git", "remote", "get-url"]:
return MagicMock(
returncode=0,
stdout="git@github.com:Semcod/Glon.git\n",
stderr="",
)
return MagicMock(returncode=0, stdout="", stderr="")

mock_run.side_effect = fake_run

result = publish_repository(repo_dir, "semcod", "glon", visibility="private")

assert result is True
commands = [call.args[0] for call in mock_run.call_args_list]
assert [
"gh",
"repo",
"edit",
"semcod/glon",
"--visibility",
"private",
] in commands
assert ["goal", "-a"] in commands