diff --git a/glon/cli.py b/glon/cli.py index f1a10e2..eaefde0 100644 --- a/glon/cli.py +++ b/glon/cli.py @@ -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"], @@ -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( @@ -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 ) diff --git a/project/TICKETS.md b/project/TICKETS.md index be8bb99..1374928 100644 --- a/project/TICKETS.md +++ b/project/TICKETS.md @@ -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) | diff --git a/project/ticket-012/README.md b/project/ticket-012/README.md index 87aeb31..e0df5aa 100644 --- a/project/ticket-012/README.md +++ b/project/ticket-012/README.md @@ -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 diff --git a/project/ticket-013/README.md b/project/ticket-013/README.md new file mode 100644 index 0000000..af1a9d9 --- /dev/null +++ b/project/ticket-013/README.md @@ -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//` 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) diff --git a/project/ticket-013/ai-antigravity-logs.txt b/project/ticket-013/ai-antigravity-logs.txt new file mode 100644 index 0000000..5fd1905 --- /dev/null +++ b/project/ticket-013/ai-antigravity-logs.txt @@ -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) diff --git a/project/ticket-013/ai-antigravity.md b/project/ticket-013/ai-antigravity.md new file mode 100644 index 0000000..0472295 --- /dev/null +++ b/project/ticket-013/ai-antigravity.md @@ -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//` 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. diff --git a/project/ticket-013/changelog.md b/project/ticket-013/changelog.md new file mode 100644 index 0000000..72077d0 --- /dev/null +++ b/project/ticket-013/changelog.md @@ -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`. diff --git a/project/ticket-013/intent.json b/project/ticket-013/intent.json new file mode 100644 index 0000000..ac51722 --- /dev/null +++ b/project/ticket-013/intent.json @@ -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// 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." + } + ] + } +} diff --git a/project/ticket-013/preprompt.md b/project/ticket-013/preprompt.md new file mode 100644 index 0000000..3ba83ca --- /dev/null +++ b/project/ticket-013/preprompt.md @@ -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. diff --git a/tests/test_cli.py b/tests/test_cli.py index 385ece4..ca40ea9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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// 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