feat(extensions): port update-agent-context to Python#3387
Open
marcelsafin wants to merge 2 commits into
Open
Conversation
Ports the agent-context extension updater to a single Python script, per github#3281 and the check-prerequisites PoC pattern from github#3302. The bash version already ran its core logic through embedded Python heredocs, so the port lifts that logic into a standalone script. Parity tests run bash and Python side by side and compare output and resulting context-file bytes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Ports the agent-context extension’s context-file updater to a standalone Python script, alongside a new parity test suite to ensure behavior matches the existing Bash/PowerShell implementations.
Changes:
- Add
extensions/agent-context/scripts/python/update_agent_context.pyimplementing the updater logic in Python. - Add
tests/extensions/test_update_agent_context_python_parity.pyto run Bash vs Python (and some PowerShell vs Python) parity checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| extensions/agent-context/scripts/python/update_agent_context.py | New Python implementation of the agent-context updater (config parsing, plan resolution, section upsert, .mdc frontmatter repair). |
| tests/extensions/test_update_agent_context_python_parity.py | New parity test suite comparing Python behavior/output with Bash and PowerShell variants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+50
| def _collect_context_files(data: dict, project_root: str) -> list[str]: | ||
| """Resolve the managed context files from config, mirroring the bash logic.""" | ||
| context_files: list[str] = [] | ||
| seen: set[str] = set() | ||
| case_insensitive = sys.platform.startswith(("win32", "cygwin")) | ||
|
|
||
| def add(value: object) -> None: |
Contributor
Author
There was a problem hiding this comment.
Fixed in 3c105c7: added msys to the platform tuple, matching the uname gate in the bash script.
Comment on lines
+444
to
+461
| @pytest.mark.skipif(not POWERSHELL, reason="no PowerShell available") | ||
| def test_python_upsert_matches_powershell(tmp_path: Path) -> None: | ||
| repo_a = make_project(tmp_path / "proj-ps", context_file="AGENTS.md") | ||
| repo_b = make_project(tmp_path / "proj-py", context_file="AGENTS.md") | ||
| existing = ( | ||
| "# My project\n\n" | ||
| "<!-- SPECKIT START -->\nstale\n<!-- SPECKIT END -->\n" | ||
| "\ntail\n" | ||
| ) | ||
| for repo in (repo_a, repo_b): | ||
| add_plan(repo) | ||
| (repo / "AGENTS.md").write_text(existing, encoding="utf-8") | ||
|
|
||
| ps = run_powershell(repo_a) | ||
| py = run_python(repo_b) | ||
|
|
||
| assert ps.returncode == py.returncode == 0, ps.stderr + py.stderr | ||
| assert (repo_a / "AGENTS.md").read_bytes() == (repo_b / "AGENTS.md").read_bytes() |
Contributor
Author
There was a problem hiding this comment.
Added in 3c105c7: test_python_unparseable_config_matching_bash locks in exit 0 plus the stderr messages for invalid YAML.
…ble config gate Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ports the agent-context extension updater to Python, per #3281. Follows the pattern from the check-prerequisites PoC (#3302): additive port, no changes to the bash or PowerShell scripts, parity tests that run both implementations side by side.
The bash version already ran its core logic through embedded Python heredocs, so this port mostly lifts that logic into a standalone script:
extensions/agent-context/scripts/python/update_agent_context.py— config parsing (context_files/context_file/markers), self-seeding frominit-options.jsonviaagent-context-defaults.json, path validation (absolute/backslash/../escape rejection), plan-path resolution (feature.jsonfirst, mtime fallback), marker upsert for all four cases (both markers, start only, end only, none), CRLF normalization, and.mdcfrontmatter repair (alwaysApply: true).tests/extensions/test_update_agent_context_python_parity.py— 22 parity tests. Bash tests compare exit code, normalized stdout/stderr, and resulting context-file bytes. PowerShell tests compare resulting file content and skip whenpwshis unavailable.Testing
uv run specify --helpuv sync && uv run pytest(3790 passed, 107 skipped)AI Disclosure
Ported and tested with GitHub Copilot CLI. I reviewed the diff and verified parity behavior manually.
Fixes #3281