Skip to content

Commit fca8ff4

Browse files
authored
Merge pull request #403 from xylar/fix-copilot-instructions
Update agent instructions
2 parents f6d55d2 + 3d0d674 commit fca8ff4

10 files changed

Lines changed: 264 additions & 34 deletions

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Follow the repository's automated style configuration in
66
- Keep changes consistent with existing Polaris patterns.
77
- For Python, follow the path-specific instructions in
88
`.github/instructions/python.instructions.md`.
9+
- Use the repository's Pixi environment before considering any other Python
10+
environment. Prefer `pixi run -e py314 <command>` for `python`, `pytest`,
11+
`pre-commit`, `ruff`, and `mypy`, and check `.pixi/` plus `pixi.toml`
12+
before concluding a tool is missing.
913
- pre-commit on changed files is required before finishing; if sandboxed
1014
execution fails, request escalation and do not close the task until it has
1115
run or the user declines.

.github/workflows/copilot-setup-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ jobs:
3838
- name: Verify the agent environment
3939
run: |
4040
pixi run -e py314 python --version
41+
pixi run -e py314 pytest --version
42+
pixi run -e py314 pre-commit --version
4143
pixi run -e py314 mache --help

AGENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ These instructions apply to the whole repository unless a deeper
1010
- If an instruction here conflicts with automated tooling, follow the
1111
automated tooling.
1212

13+
## Python environment
14+
15+
- This repository uses Pixi as the primary development environment manager.
16+
- Check the root `.pixi/` and `pixi.toml` before creating or selecting any
17+
other Python environment.
18+
- Prefer `pixi run -e py314 <command>` for Python tools such as `python`,
19+
`pytest`, `pre-commit`, `ruff`, and `mypy`.
20+
- If you need an interactive shell, use `pixi shell -e py314` from the repo
21+
root instead of creating a new virtual environment.
22+
- Do not treat `pytest: command not found` in a plain shell as a missing
23+
dependency until you have tried the command through Pixi.
24+
1325
## Python style
1426

1527
- Keep Python lines at 79 characters or fewer whenever possible.
@@ -28,7 +40,12 @@ These instructions apply to the whole repository unless a deeper
2840

2941
## Validation
3042

43+
- Run tests and linting through Pixi unless the task explicitly requires a
44+
different environment.
45+
- Prefer `pixi run -e py314 pytest` for tests.
3146
- pre-commit on changed files is required before finishing; if sandboxed
3247
execution fails, request escalation and do not close the task until it has
3348
run or the user declines.
49+
- Prefer `pixi run -e py314 pre-commit run --files ...` for required
50+
validation.
3451
- Prefer fixing lint and formatting issues rather than suppressing them.

docs/developers_guide/config_machines_updates.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ The update path is:
8989
2. The workflow creates or refreshes a GitHub issue.
9090
3. Copilot is assigned to that issue.
9191
4. Copilot opens a pull request against `main`.
92-
5. That PR updates `mache/cime_machine_config/config_machines.xml` first, then
93-
any related Spack templates or version strings that the report indicates
94-
should be reviewed.
92+
5. That PR replaces `mache/cime_machine_config/config_machines.xml` with the
93+
latest version from `E3SM-Project/E3SM`, then updates any related Spack
94+
templates or version strings that the report indicates should be reviewed.
9595
6. A maintainer reviews and merges the PR.
9696
7. The next daily run compares the merged repository state against upstream
9797
again.
@@ -112,8 +112,16 @@ Copilot receives instructions from two places.
112112
`agent_assignment` payload:
113113

114114
- Use the issue body as the task definition.
115-
- Update `config_machines.xml` first.
116-
- Then update related Spack templates and version strings.
115+
- Run `pixi run -e py314 python utils/update_cime_machine_config.py
116+
--work-dir .`.
117+
- Replace `mache/cime_machine_config/config_machines.xml` with the generated
118+
`upstream_config_machines.xml`, then remove that temporary file before
119+
committing.
120+
- State the upstream E3SM commit hash in the PR summary.
121+
- Then update related Spack templates and version strings under
122+
`mache/spack/templates/<machine>*.yaml`,
123+
`mache/spack/templates/<machine>*.sh`, and
124+
`mache/spack/templates/<machine>*.csh`.
117125
- Add TODO comments in the PR when prefix or path changes need reviewer
118126
confirmation.
119127

@@ -123,6 +131,7 @@ Copilot receives instructions from two places.
123131
drift and includes:
124132

125133
- the timestamp and upstream source URL,
134+
- the upstream revision when it could be resolved from GitHub,
126135
- the workflow run URL,
127136
- the list of affected supported machines,
128137
- the required work list,
@@ -131,9 +140,16 @@ drift and includes:
131140

132141
The required work section tells Copilot to:
133142

134-
- update `mache/cime_machine_config/config_machines.xml` for the affected
135-
supported machines,
136-
- update Spack templates and version strings when module or environment drift
143+
- run `pixi run -e py314 python utils/update_cime_machine_config.py
144+
--work-dir .`,
145+
- replace `mache/cime_machine_config/config_machines.xml` with the generated
146+
`upstream_config_machines.xml`,
147+
- remove `upstream_config_machines.xml` before committing,
148+
- state the upstream E3SM commit hash in the PR summary,
149+
- update Spack templates and version strings in
150+
`mache/spack/templates/<machine>*.yaml`,
151+
`mache/spack/templates/<machine>*.sh`, and
152+
`mache/spack/templates/<machine>*.csh` when module or environment drift
137153
implies different package versions,
138154
- keep the PR focused when the change is only version or module drift,
139155
- add a TODO in the PR instead of guessing when a new prefix or path is not
@@ -173,13 +189,17 @@ in this order.
173189

174190
### 1. `config_machines.xml` changes
175191

176-
Verify that the PR updates
177-
`mache/cime_machine_config/config_machines.xml` only for supported machines
178-
reported by the workflow, and that those changes match the current upstream
179-
E3SM machine definitions.
192+
Verify that the PR replaces
193+
`mache/cime_machine_config/config_machines.xml` with the current upstream file
194+
from `E3SM-Project/E3SM`, rather than hand-editing only selected machine
195+
blocks.
196+
197+
The supported-machine report from the workflow tells you which machine entries
198+
caused the drift and which sections deserve the closest review.
180199

181200
In practice, the easiest cross-check is to compare the PR against the report
182-
artifact from the workflow run that opened or refreshed the issue.
201+
artifact and the upstream XML source from the workflow run that opened or
202+
refreshed the issue.
183203

184204
### 2. Related Spack updates
185205

mache/cime_machine_config/report.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def has_updates(self) -> bool:
5151
class UpdateReport:
5252
generated_at: str
5353
upstream_url: str
54+
upstream_revision: str | None
5455
supported_machines: list[str]
5556
machines: list[MachineUpdate]
5657

@@ -64,7 +65,13 @@ def to_dict(self) -> dict[str, object]:
6465
return data
6566

6667

67-
def build_update_report(old_xml, new_xml, supported_machines, upstream_url):
68+
def build_update_report(
69+
old_xml,
70+
new_xml,
71+
supported_machines,
72+
upstream_url,
73+
upstream_revision=None,
74+
):
6875
"""Build a structured report for supported machine config changes."""
6976

7077
old_root = etree.parse(old_xml).getroot()
@@ -87,6 +94,7 @@ def build_update_report(old_xml, new_xml, supported_machines, upstream_url):
8794
return UpdateReport(
8895
generated_at=datetime.now(timezone.utc).isoformat(),
8996
upstream_url=upstream_url,
97+
upstream_revision=upstream_revision,
9098
supported_machines=list(supported_machines),
9199
machines=machines,
92100
)
@@ -113,6 +121,9 @@ def render_update_issue(report, run_url=None):
113121
f'- Upstream source: {report.upstream_url}',
114122
]
115123

124+
if report.upstream_revision is not None:
125+
lines.append(f'- Upstream revision: {report.upstream_revision}')
126+
116127
if run_url:
117128
lines.append(f'- Workflow run: {run_url}')
118129

@@ -121,14 +132,24 @@ def render_update_issue(report, run_url=None):
121132
'',
122133
'Required work:',
123134
'',
124-
'- Update mache/cime_machine_config/config_machines.xml for the',
125-
' affected supported machines.',
135+
'- Run `pixi run -e py314 python '
136+
'utils/update_cime_machine_config.py --work-dir .` from the',
137+
' repository root.',
138+
'- Replace mache/cime_machine_config/config_machines.xml with',
139+
' upstream_config_machines.xml generated by that command, then',
140+
' remove upstream_config_machines.xml before committing.',
126141
'- If module or environment changes imply different',
127142
' system-package',
128143
' versions, update the corresponding mache Spack templates and',
129144
' version strings for the affected toolchains.',
145+
'- Look for related Spack template files under',
146+
' mache/spack/templates/<machine>*.yaml,',
147+
' mache/spack/templates/<machine>*.sh, and',
148+
' mache/spack/templates/<machine>*.csh.',
130149
'- If the only follow-up is module or version drift, keep the PR',
131150
' focused on those updates.',
151+
'- In the PR summary, state which upstream E3SM commit hash was',
152+
' used for the config_machines.xml replacement.',
132153
'- If any prefix or path values changed and the correct',
133154
' replacement',
134155
' is not obvious, add a TODO comment in the PR for the reviewer',
@@ -350,6 +371,12 @@ def _render_machine_section(machine):
350371
'- Spack templates to review: '
351372
f'{", ".join(machine.spack_templates_to_review)}'
352373
)
374+
lines.append(
375+
'- Spack template globs: '
376+
f'mache/spack/templates/{machine.machine}*.yaml, '
377+
f'mache/spack/templates/{machine.machine}*.sh, '
378+
f'mache/spack/templates/{machine.machine}*.csh'
379+
)
353380
else:
354381
lines.append('- Spack templates to review: none matched')
355382

tests/test_cime_machine_config_report.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_build_update_report_detects_spack_related_drift(
5050
new_xml=new_xml,
5151
supported_machines=['test-machine'],
5252
upstream_url='https://example.invalid/config_machines.xml',
53+
upstream_revision='deadbeef1234',
5354
)
5455

5556
assert report.has_updates is True
@@ -97,13 +98,22 @@ def test_render_update_issue_includes_required_instructions(
9798
new_xml=new_xml,
9899
supported_machines=['test-machine'],
99100
upstream_url='https://example.invalid/config_machines.xml',
101+
upstream_revision='deadbeef1234',
100102
)
101103
markdown = render_update_issue(
102104
report,
103105
run_url='https://github.example/actions/runs/1',
104106
)
105107

106-
assert 'Update mache/cime_machine_config/config_machines.xml' in markdown
108+
assert (
109+
'pixi run -e py314 python utils/update_cime_machine_config.py'
110+
in markdown
111+
)
112+
assert 'upstream_config_machines.xml' in markdown
113+
assert 'deadbeef1234' in markdown
114+
assert 'state which upstream E3SM commit hash was' in markdown
115+
assert 'mache/spack/templates/<machine>*.yaml' in markdown
116+
assert 'mache/spack/templates/test-machine*.sh' in markdown
107117
assert 'TODO comment in the PR for the reviewer' in markdown
108118
assert 'test-machine_gnu_mpich.yaml' in markdown
109119
assert 'https://github.example/actions/runs/1' in markdown
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from importlib.util import module_from_spec, spec_from_file_location
2+
from pathlib import Path
3+
4+
5+
def _load_update_module():
6+
module_path = (
7+
Path(__file__).resolve().parents[1]
8+
/ 'utils'
9+
/ 'update_cime_machine_config.py'
10+
)
11+
spec = spec_from_file_location('update_cime_machine_config', module_path)
12+
assert spec is not None
13+
assert spec.loader is not None
14+
15+
module = module_from_spec(spec)
16+
spec.loader.exec_module(module)
17+
return module
18+
19+
20+
def test_parse_github_raw_url_supports_default_e3sm_url():
21+
update_module = _load_update_module()
22+
23+
source = update_module._parse_github_raw_url(
24+
'https://raw.githubusercontent.com/E3SM-Project/E3SM/'
25+
'refs/heads/master/cime_config/machines/config_machines.xml'
26+
)
27+
28+
assert source == (
29+
'E3SM-Project',
30+
'E3SM',
31+
'master',
32+
'cime_config/machines/config_machines.xml',
33+
)
34+
35+
36+
def test_get_latest_commit_sha_uses_github_commits_api(monkeypatch):
37+
update_module = _load_update_module()
38+
captured = {}
39+
40+
class FakeResponse:
41+
def raise_for_status(self):
42+
return None
43+
44+
def json(self):
45+
return [{'sha': 'abc123'}]
46+
47+
def fake_get(url, *, params, timeout):
48+
captured['url'] = url
49+
captured['params'] = params
50+
captured['timeout'] = timeout
51+
return FakeResponse()
52+
53+
monkeypatch.setattr(update_module.requests, 'get', fake_get)
54+
55+
sha = update_module._get_latest_commit_sha(
56+
owner='E3SM-Project',
57+
repo='E3SM',
58+
ref='master',
59+
path='cime_config/machines/config_machines.xml',
60+
)
61+
62+
assert sha == 'abc123'
63+
assert captured['url'].endswith('/repos/E3SM-Project/E3SM/commits')
64+
assert captured['params'] == {
65+
'sha': 'master',
66+
'path': 'cime_config/machines/config_machines.xml',
67+
'per_page': 1,
68+
}
69+
assert captured['timeout'] == 60

utils/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ mache package.
66
## update CIME machine config
77

88
The `update_cime_machine_config.py` script can be used to download the latest
9-
version of the `config_machines.xml` file from E3SM's `master` branch, then
10-
compare it from the previous version stored in `mache` and show changes related
11-
to supported machines.
12-
13-
A developer can then copy `new_config_machines.xml` into
14-
`mache/cime_machine_config/config_machines.xml` as part of a PR that makes
15-
relevant updates. They should also make the changes associated with the
16-
differences that this utility displays in the appropriate `mache/spack/templates` files.
9+
version of the `config_machines.xml` file from `E3SM-Project/E3SM`, compare it
10+
with the copy stored in `mache`, and show changes related to supported
11+
machines.
12+
13+
When drift is detected, the follow-up PR should replace
14+
`mache/cime_machine_config/config_machines.xml` with the latest upstream file
15+
from `E3SM-Project/E3SM`. This utility helps confirm the drift and review the
16+
affected supported machines; it does not rewrite the repository copy in place.
17+
18+
The PR should also make the changes associated with the differences that this
19+
utility displays in the appropriate `mache/spack/templates` files.
1720

1821
## extract spack shell scripts from CIME machine config
1922

utils/manage_cime_machine_config_issue.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,19 @@ def build_issue_payload(
197197
'target_repo': f'{owner}/{repo}',
198198
'base_branch': base_branch,
199199
'custom_instructions': (
200-
'Use the issue body as the task definition. Update '
201-
'config_machines.xml first, then the related Spack '
202-
'templates and version strings. Add TODO comments in the '
203-
'PR when prefix or path changes need reviewer confirmation.'
200+
'Use the issue body as the task definition. Run `pixi run '
201+
'-e py314 python utils/update_cime_machine_config.py '
202+
'--work-dir .`, replace '
203+
'mache/cime_machine_config/config_machines.xml with '
204+
'upstream_config_machines.xml, remove '
205+
'upstream_config_machines.xml before committing, and state '
206+
'the upstream E3SM commit hash in the PR summary. Then '
207+
'update the related Spack templates and version strings in '
208+
'mache/spack/templates/<machine>*.yaml, '
209+
'mache/spack/templates/<machine>*.sh, and '
210+
'mache/spack/templates/<machine>*.csh. '
211+
'Add TODO comments in the PR when prefix or path changes '
212+
'need reviewer confirmation.'
204213
),
205214
'custom_agent': '',
206215
'model': '',

0 commit comments

Comments
 (0)