Skip to content

ci: limit auto-fix agent to Kotlin sources and scope its credentials - #1087

Merged
dkhawk merged 2 commits into
mainfrom
ci/harden-auto-fix
Nov 16, 2026
Merged

dkhawk merged 2 commits into
mainfrom
ci/harden-auto-fix

Conversation

@kikoso

@kikoso kikoso commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

The auto-fix workflow writes whatever file paths the model returns and then compiles the tree, with the checkout token still in `.git/config`. This tightens what the agent can touch and where credentials are available.

`create_pr.py`

  • Only `.kt` files under `maps-app/src/`, `maps-compose/src/`, `maps-compose-utils/src/` and `maps-compose-widgets/src/` can be modified or created. Paths are resolved first (so `..` and symlinks cannot escape), and every path is checked before anything is written: one bad entry aborts the run with the tree untouched.
  • The branch name is always `auto-fix/issue-` instead of a model-chosen name, and `ISSUE_NUMBER` must be numeric.
  • `pr_metadata.json` now lists the files that were actually written.

`auto-fix.yml`

  • Checkout uses `persist-credentials: false`, so the compile step runs without a token on disk.
  • The push step commits only the files from `pr_metadata.json` instead of `git add .`, authenticates with `gh auth setup-git` and no longer force-pushes.

Testing

  • `actionlint` passes on the workflow.
  • Ran `create_pr.py` locally with a mocked Gemini: a valid response still writes the files and produces `auto-fix/issue-42`. Build scripts, `.github/`, `..` traversal, a symlinked `.kt`, absolute paths and non-list values are all refused, with no file written.
  • The workflow itself has not run end to end, since the `agent: create-pr` label does not currently exist on the repo.

create_pr.py now only writes .kt files under the library and demo source
directories, derives the branch name from the issue number and records the
files it changed. The workflow checks out without persisted credentials,
commits only those files and authenticates just for the push.
@kikoso
kikoso requested a review from a team as a code owner November 12, 2026 19:40
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 1fc2bbb on main (#1083).

Module Line % Change Branch % Change
maps-compose 15.27% no change 3.75% no change
maps-compose-utils 26.29% no change 12.70% no change
maps-compose-widgets 3.87% no change 0.00% no change
TOTAL 17.35% no change 5.46% no change

Line and branch coverage from unit test reports. History is recorded on the coverage-history branch after each merge to main.

@googlemaps-bot

googlemaps-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 45.83% 🍏

There is no coverage information present for the Files changed

@dkhawk
dkhawk merged commit c6ea1f0 into main Nov 16, 2026
14 checks passed
@dkhawk
dkhawk deleted the ci/harden-auto-fix branch November 16, 2026 17:20
dkhawk added a commit that referenced this pull request Nov 17, 2026
…cope (#1088)

* ci: limit auto-fix agent to Kotlin sources and scope its credentials

create_pr.py now only writes .kt files under the library and demo source
directories, derives the branch name from the issue number and records the
files it changed. The workflow checks out without persisted credentials,
commits only those files and authenticates just for the push.

* ci: harden auto-fix path validation, prompt isolation, and PR token scope

- Restrict EDITABLE_SOURCE_DIRS to src/main/ (excluding test source sets and generated baseline profiles) and enforce a strict character allowlist regex on relative paths so embedded newlines cannot split mapfile in auto-fix.yml.
- Scope list_project_files() to editable .kt files, cap modified/created files per run (MAX_FILES_PER_RUN = 10), add HTTP request timeouts, and abort if no files were changed.
- Separate system_instruction from <issue_content>-delimited user input across all Gemini API calls and sanitize PR metadata (single-line commit/title, approved link domains, code-wrapped @mentions, and same-issue closing keywords).
- Use GITHUB_TOKEN instead of SYNCED_GITHUB_TOKEN_REPO and create auto-fix PRs as drafts so downstream pull_request workflows do not execute unreviewed AI-generated code with repository secrets.
- Remove committed create_pr.cpython-315.pyc bytecode file and block __pycache__/ and *.py[cod] in .gitignore and check_agent_leftovers.py.

* chore: untrack the Python bytecode cache committed in #1087

* ci: address review feedback on delimiter escaping and branch guards

- Use a case-insensitive regex in sanitize_content() to neutralize mixed-case, spaced, attributed, or unclosed <issue_content> delimiter tags.
- Bail out if auto-fix/issue-<N> already exists on origin (both right after checkout and before git push) instead of force-pushing over potential maintainer commits.
- Include the draft PR URL and instructions to close/reopen (or push a commit) and mark ready for review to trigger the full CI suite.

---------

Co-authored-by: Enrique López Mañas <eenriquelopez@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants