mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 17:30:43 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1520ee3242 |
No files matched your search
@@ -11,6 +11,7 @@ remains unsupported.
|
||||
|
||||
### Added
|
||||
|
||||
- Added a dry-run legacy issue migration inventory (`scripts/agent_queue/migrate.py` and `python3 -m agent_queue migrate-inventory`) with unit tests (`tests/agent_queue/test_migrate.py`) and coordination docs (`docs/coordination/issue-migration.md`). Compares legacy `##` headings against the parser's `###` headings across area, owned files, acceptance command, and dependencies, preserves existing issue history in `### Context`, refuses to fabricate file ownership, and requires explicit maintainer approval before any issue edit or `agent:ready` label.
|
||||
- Added explicit claim-before-work rules for contributors and coding agents to `AGENTS.md`, `CONTRIBUTING.md` and the pull request template: check for existing claims, claim with `/claim`, keep a 24-hour lease alive with `/progress`, `/release` when stopping, and link the claimed issue. Without the claim workflow, the earliest valid claim comment wins.
|
||||
- Added native Metal upload and readback of BC2 and BC3 textures: `xenora-texture` gains a
|
||||
pitched `BcAlphaUpload` for 16-byte blocks, and `NativeCompute::read_bc_alpha_upload` sends
|
||||
|
||||
@@ -49,3 +49,4 @@ either path. The [changelog](../CHANGELOG.md) records notable changes.
|
||||
- [Legal scope](legal.md), [dependency licensing](licenses.md), and [third-party notices](../THIRD_PARTY_NOTICES.md) — Input policy, attribution, and redistribution findings.
|
||||
- [Contribution guidelines](../CONTRIBUTING.md) — Original authorship, Developer Certificate of Origin sign-off, and evidence requirements.
|
||||
- [Agent task queue](coordination/agent-tasks.md) — Areas, claiming, leases, upstream sync, verification and the security model for parallel contributors and coding agents.
|
||||
- [Legacy issue migration inventory](coordination/issue-migration.md) — Dry-run inventory for migrating legacy `##` issue headings to the `###` agent-task form with explicit maintainer review.
|
||||
@@ -0,0 +1,50 @@
|
||||
# Legacy Issue Migration Inventory
|
||||
|
||||
The agent task queue parser (`scripts/agent_queue/tasks.py`) reads GitHub issue-form fields from
|
||||
level-3 Markdown headings (`### Area`, `### Priority`, `### Files`, `### Acceptance command`,
|
||||
`### Depends on`, `### Interface`). Earlier backlog issues in Xenora use level-2 headings (`## Area`,
|
||||
`## Files`, `## Acceptance command`, `## Depends on`, `## Objective and acceptance criteria`), so the
|
||||
parser sees empty `area`, `files`, `acceptance`, and `depends` fields until those issues are
|
||||
migrated to the agent task form.
|
||||
|
||||
## Safety rules
|
||||
|
||||
1. **Dry-run by default:** `migrate-inventory` is read-only. It never edits GitHub issues and never
|
||||
adds `agent:ready` labels.
|
||||
2. **Explicit maintainer review required:** Every non-compliant issue is flagged with
|
||||
`requires_maintainer_review: true` and `safe_to_apply_without_review: false`. Maintainers must
|
||||
review each proposed body before applying edits or adding `agent:ready`.
|
||||
3. **Never fabricate file ownership:** Issues without an explicit `Files` section are classified as
|
||||
`incomplete` with `missing_fields: ["files"]`. `plan_apply` refuses to generate an edit or
|
||||
`agent:ready` label for any incomplete issue until a maintainer explicitly supplies owned paths.
|
||||
4. **Preserve issue history:** Proposed migrated bodies map recognized legacy `##` sections to the
|
||||
canonical `###` headings and preserve any original preamble text and unrecognized `##` sections
|
||||
verbatim under `### Context`.
|
||||
5. **Text is data only:** Issue text is parsed with fixed string and regular-expression rules and is
|
||||
never executed. Code fences inside `Files` sections are stripped so fence markers (such as
|
||||
`text`) are never treated as owned paths.
|
||||
|
||||
## Running the dry-run inventory
|
||||
|
||||
Gather open issues into a local state snapshot, then inspect the inventory as JSON or a review table:
|
||||
|
||||
```sh
|
||||
PYTHONPATH=scripts python3 -m agent_queue gather --repo ranveersoni98/Xenora --no-prs > state.json
|
||||
PYTHONPATH=scripts python3 -m agent_queue migrate-inventory --state state.json --text
|
||||
PYTHONPATH=scripts python3 -m agent_queue migrate-inventory --state state.json > migration-inventory.json
|
||||
```
|
||||
|
||||
Each issue in the inventory is classified into one of three states:
|
||||
|
||||
- `compliant` — already uses `###` headings with a valid `Area`, explicit `Files`, and a non-empty
|
||||
`Acceptance command`.
|
||||
- `legacy_migratable` — uses `##` or mixed `##`/`###` headings and already declares explicit `Area`,
|
||||
`Files`, and `Acceptance command`; includes a non-destructive `proposed_body` for maintainer review.
|
||||
- `incomplete` — missing one or more required fields (`area`, `files`, or `acceptance command`);
|
||||
blocked from automated edits and `agent:ready` labeling until completed by a maintainer.
|
||||
|
||||
## Tests
|
||||
|
||||
```sh
|
||||
PYTHONPATH=scripts python3 -m unittest discover -s tests/agent_queue -v
|
||||
```
|
||||
@@ -8,7 +8,7 @@ from datetime import datetime, timezone
|
||||
from . import config as cfgmod
|
||||
from . import ghio
|
||||
from . import lease as L
|
||||
from . import prcheck, queue
|
||||
from . import migrate, prcheck, queue
|
||||
from . import tasks as T
|
||||
from . import decide as decide_mod
|
||||
from .decide import decide
|
||||
@@ -48,6 +48,7 @@ def main(argv):
|
||||
s = sub.add_parser("list"); s.add_argument("--state", required=True); s.add_argument("--area", default=""); s.add_argument("--json", action="store_true")
|
||||
s = sub.add_parser("next"); s.add_argument("--state", required=True); s.add_argument("--area", required=True); s.add_argument("--login", required=True)
|
||||
s = sub.add_parser("check-body"); s.add_argument("--file", required=True)
|
||||
s = sub.add_parser("migrate-inventory"); s.add_argument("--state", required=True); s.add_argument("--text", action="store_true"); s.add_argument("--include-closed", action="store_true")
|
||||
s = sub.add_parser("event"); s.add_argument("--path", required=True)
|
||||
s = sub.add_parser("config-get"); s.add_argument("key")
|
||||
a = p.parse_args(argv)
|
||||
@@ -139,6 +140,12 @@ def main(argv):
|
||||
return 1
|
||||
print("area:" + t["area"])
|
||||
print("priority:" + t["priority"])
|
||||
elif a.cmd == "migrate-inventory":
|
||||
res = migrate.inventory(_load(a.state), include_closed=a.include_closed)
|
||||
if a.text:
|
||||
sys.stdout.write(migrate.format_report(res))
|
||||
else:
|
||||
_out(res)
|
||||
elif a.cmd == "touch":
|
||||
# stdin lines "<sha>\t<path>"; report those touching patterns of tasks held by login
|
||||
state, hits = _load(a.state), []
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Dry-run migration inventory for legacy ## issue bodies versus ### agent-task headings.
|
||||
|
||||
Text is data only: nothing parsed from issue bodies is ever executed.
|
||||
Never fabricates file ownership or edits issues without explicit maintainer approval.
|
||||
"""
|
||||
import re
|
||||
|
||||
from . import config as cfgmod
|
||||
from . import tasks as T
|
||||
|
||||
HEADING = re.compile(r"^(#{2,3})\s+(.+?)\s*$")
|
||||
PLACEHOLDER = "_no response_"
|
||||
|
||||
ALIASES = {
|
||||
"area": "area",
|
||||
"priority": "priority",
|
||||
"interface": "interface",
|
||||
"goal": "goal",
|
||||
"objective": "goal",
|
||||
"objective and acceptance criteria": "goal",
|
||||
"files": "files",
|
||||
"owned files": "files",
|
||||
"acceptance command": "acceptance command",
|
||||
"acceptance": "acceptance command",
|
||||
"depends on": "depends on",
|
||||
"dependencies": "depends on",
|
||||
"context": "context",
|
||||
}
|
||||
|
||||
CANONICAL_ORDER = (
|
||||
("area", "Area"),
|
||||
("priority", "Priority"),
|
||||
("interface", "Interface"),
|
||||
("goal", "Goal"),
|
||||
("files", "Files"),
|
||||
("acceptance command", "Acceptance command"),
|
||||
("depends on", "Depends on"),
|
||||
("context", "Context"),
|
||||
)
|
||||
|
||||
|
||||
def parse_sections_with_levels(body):
|
||||
"""Parse ## and ### headings while ignoring headings inside fenced code blocks.
|
||||
|
||||
Returns (preamble, entries) where each entry is (level, raw_heading, text).
|
||||
"""
|
||||
text = (body or "").replace("\r\n", "\n")
|
||||
lines = text.split("\n")
|
||||
in_fence = False
|
||||
preamble_lines = []
|
||||
entries = []
|
||||
cur = None
|
||||
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith("```"):
|
||||
in_fence = not in_fence
|
||||
if cur is None:
|
||||
preamble_lines.append(line)
|
||||
else:
|
||||
cur[2].append(line)
|
||||
continue
|
||||
if not in_fence:
|
||||
m = HEADING.match(line)
|
||||
if m:
|
||||
if cur is not None:
|
||||
entries.append((cur[0], cur[1], "\n".join(cur[2]).strip()))
|
||||
cur = (len(m.group(1)), m.group(2).strip(), [])
|
||||
continue
|
||||
if cur is None:
|
||||
preamble_lines.append(line)
|
||||
else:
|
||||
cur[2].append(line)
|
||||
|
||||
if cur is not None:
|
||||
entries.append((cur[0], cur[1], "\n".join(cur[2]).strip()))
|
||||
|
||||
preamble = "\n".join(preamble_lines).strip()
|
||||
return preamble, entries
|
||||
|
||||
|
||||
def _clean_text(text):
|
||||
t = (text or "").strip()
|
||||
return "" if t.lower() == PLACEHOLDER else t
|
||||
|
||||
|
||||
def _parse_files(text):
|
||||
"""Extract owned file patterns without leaking code fence markers or fabricating paths."""
|
||||
out = []
|
||||
for raw in (text or "").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("```"):
|
||||
continue
|
||||
if line.startswith(("- ", "* ")):
|
||||
line = line[2:].strip()
|
||||
line = line.strip("`").strip()
|
||||
if not line or line.lower() == PLACEHOLDER:
|
||||
continue
|
||||
out.append(line)
|
||||
return out
|
||||
|
||||
|
||||
def _heading_style(entries):
|
||||
levels = {lvl for lvl, _, _ in entries}
|
||||
if not levels:
|
||||
return "none"
|
||||
if levels == {3}:
|
||||
return "h3"
|
||||
if levels == {2}:
|
||||
return "h2_legacy"
|
||||
return "mixed"
|
||||
|
||||
|
||||
def render_migrated_body(preamble, canonical, extra_sections, parsed):
|
||||
"""Render a ### agent-task body while preserving preamble and extra legacy sections."""
|
||||
blocks = []
|
||||
|
||||
def add(heading, value):
|
||||
blocks.append("### %s\n\n%s" % (heading, value if value else "_No response_"))
|
||||
|
||||
add("Area", parsed["area"])
|
||||
add("Priority", parsed["priority"])
|
||||
add("Interface", canonical.get("interface", ""))
|
||||
add("Goal", canonical.get("goal", ""))
|
||||
|
||||
if parsed["files"]:
|
||||
files_text = "\n".join("- %s" % p for p in parsed["files"])
|
||||
else:
|
||||
files_text = ""
|
||||
add("Files", files_text)
|
||||
|
||||
acc = T.normalise_acceptance(parsed["acceptance"])
|
||||
add("Acceptance command", acc)
|
||||
|
||||
deps_raw = canonical.get("depends on", "")
|
||||
if not deps_raw and parsed["depends"]:
|
||||
deps_raw = ", ".join("#%d" % n for n in parsed["depends"])
|
||||
add("Depends on", deps_raw)
|
||||
|
||||
context_parts = []
|
||||
if canonical.get("context"):
|
||||
context_parts.append(canonical["context"])
|
||||
if preamble:
|
||||
context_parts.append("Preserved issue preamble:\n\n" + preamble)
|
||||
for lvl, raw_heading, raw_text in extra_sections:
|
||||
if raw_text:
|
||||
context_parts.append("%s %s\n\n%s" % ("#" * lvl, raw_heading, raw_text))
|
||||
else:
|
||||
context_parts.append("%s %s" % ("#" * lvl, raw_heading))
|
||||
add("Context", "\n\n".join(context_parts))
|
||||
|
||||
return "\n\n".join(blocks) + "\n"
|
||||
|
||||
|
||||
def classify_issue(issue):
|
||||
"""Inspect one issue dict and build a dry-run migration inventory record."""
|
||||
body = issue.get("body") or ""
|
||||
labels = T.label_names(issue)
|
||||
current = T.parse_task(issue)
|
||||
preamble, entries = parse_sections_with_levels(body)
|
||||
style = _heading_style(entries)
|
||||
|
||||
canonical = {}
|
||||
extra_sections = []
|
||||
warnings = []
|
||||
raw_area_text = ""
|
||||
|
||||
for lvl, raw_heading, raw_text in entries:
|
||||
cleaned = _clean_text(raw_text)
|
||||
key = ALIASES.get(raw_heading.lower())
|
||||
if key is None:
|
||||
extra_sections.append((lvl, raw_heading, cleaned))
|
||||
continue
|
||||
if key == "area":
|
||||
raw_area_text = cleaned.strip().lower()
|
||||
if key in canonical and cleaned:
|
||||
if canonical[key]:
|
||||
canonical[key] = canonical[key] + "\n\n" + cleaned
|
||||
else:
|
||||
canonical[key] = cleaned
|
||||
else:
|
||||
canonical[key] = cleaned
|
||||
|
||||
area_candidate = raw_area_text or T.label_value(labels, "area:")
|
||||
area = area_candidate if area_candidate in cfgmod.AREAS else ""
|
||||
if raw_area_text and raw_area_text not in cfgmod.AREAS:
|
||||
warnings.append("unrecognized_area")
|
||||
|
||||
prio_candidate = canonical.get("priority", "").strip().lower() or T.label_value(labels, "priority:")
|
||||
priority = prio_candidate if prio_candidate in cfgmod.PRIORITIES else "medium"
|
||||
if canonical.get("priority", "").strip() and prio_candidate not in cfgmod.PRIORITIES:
|
||||
warnings.append("unrecognized_priority")
|
||||
|
||||
files = _parse_files(canonical.get("files", ""))
|
||||
acceptance = canonical.get("acceptance command", "")
|
||||
depends = sorted({int(n) for n in re.findall(r"#(\d+)", canonical.get("depends on", ""))})
|
||||
interface = canonical.get("interface", "")
|
||||
|
||||
parsed_legacy = {
|
||||
"area": area,
|
||||
"priority": priority,
|
||||
"files": files,
|
||||
"depends": depends,
|
||||
"acceptance": T.normalise_acceptance(acceptance),
|
||||
"interface": interface,
|
||||
}
|
||||
|
||||
missing = []
|
||||
if not area:
|
||||
missing.append("area")
|
||||
if not files:
|
||||
missing.append("files")
|
||||
warnings.append("no_explicit_file_ownership")
|
||||
if not parsed_legacy["acceptance"]:
|
||||
missing.append("acceptance command")
|
||||
|
||||
if style in ("h2_legacy", "mixed"):
|
||||
warnings.append("legacy_h2_headings")
|
||||
if preamble or extra_sections:
|
||||
warnings.append("extra_content_preserved_in_context")
|
||||
|
||||
current_ok = (
|
||||
style == "h3"
|
||||
and bool(current["area"])
|
||||
and bool(current["files"])
|
||||
and bool(T.normalise_acceptance(current["acceptance"]))
|
||||
and not any(f.startswith("```") or f in ("text", "sh") for f in current["files"])
|
||||
)
|
||||
|
||||
if current_ok:
|
||||
status = "compliant"
|
||||
proposed_body = None
|
||||
elif not missing:
|
||||
status = "legacy_migratable"
|
||||
proposed_body = render_migrated_body(preamble, canonical, extra_sections, parsed_legacy)
|
||||
else:
|
||||
status = "incomplete"
|
||||
proposed_body = render_migrated_body(preamble, canonical, extra_sections, parsed_legacy)
|
||||
|
||||
parser_gap = {
|
||||
"area_missed": bool(area) and current["area"] != area,
|
||||
"files_missed": bool(files) and current["files"] != files,
|
||||
"acceptance_missed": bool(parsed_legacy["acceptance"])
|
||||
and T.normalise_acceptance(current["acceptance"]) != parsed_legacy["acceptance"],
|
||||
"depends_missed": bool(depends) and current["depends"] != depends,
|
||||
}
|
||||
|
||||
return {
|
||||
"number": int(issue["number"]),
|
||||
"title": issue.get("title", ""),
|
||||
"state": str(issue.get("state", "OPEN")).upper(),
|
||||
"labels": labels,
|
||||
"status": status,
|
||||
"heading_style": style,
|
||||
"current_parsed": {
|
||||
"area": current["area"],
|
||||
"priority": current["priority"],
|
||||
"files": current["files"],
|
||||
"depends": current["depends"],
|
||||
"acceptance": T.normalise_acceptance(current["acceptance"]),
|
||||
"interface": current["interface"],
|
||||
},
|
||||
"legacy_parsed": parsed_legacy,
|
||||
"parser_gap": parser_gap,
|
||||
"missing_fields": missing,
|
||||
"warnings": warnings,
|
||||
"requires_maintainer_review": status != "compliant",
|
||||
"safe_to_apply_without_review": False,
|
||||
"proposed_body": proposed_body,
|
||||
}
|
||||
|
||||
|
||||
def inventory(state, include_closed=False):
|
||||
"""Build a dry-run migration inventory across issues in a gathered state dict."""
|
||||
items = []
|
||||
for issue in state.get("issues") or []:
|
||||
st = str(issue.get("state", "OPEN")).upper()
|
||||
if not include_closed and st != "OPEN":
|
||||
continue
|
||||
items.append(classify_issue(issue))
|
||||
items.sort(key=lambda r: r["number"])
|
||||
counts = {"compliant": 0, "legacy_migratable": 0, "incomplete": 0}
|
||||
for r in items:
|
||||
counts[r["status"]] += 1
|
||||
return {
|
||||
"dry_run": True,
|
||||
"total": len(items),
|
||||
"counts": counts,
|
||||
"issues": items,
|
||||
}
|
||||
|
||||
|
||||
def format_report(report):
|
||||
"""Format a dry-run inventory as a concise human-readable review table."""
|
||||
c = report["counts"]
|
||||
lines = [
|
||||
"Dry-run issue migration inventory (no issues edited, no labels changed)",
|
||||
"Total: %d | compliant: %d | legacy_migratable: %d | incomplete: %d"
|
||||
% (report["total"], c["compliant"], c["legacy_migratable"], c["incomplete"]),
|
||||
"",
|
||||
"number\tstatus\theading_style\tarea\tfiles\tdepends\tmissing\ttitle",
|
||||
]
|
||||
for r in report["issues"]:
|
||||
lp = r["legacy_parsed"]
|
||||
lines.append(
|
||||
"#%d\t%s\t%s\t%s\t%d\t%s\t%s\t%s"
|
||||
% (
|
||||
r["number"],
|
||||
r["status"],
|
||||
r["heading_style"],
|
||||
lp["area"] or "-",
|
||||
len(lp["files"]),
|
||||
",".join("#%d" % d for d in lp["depends"]) or "-",
|
||||
",".join(r["missing_fields"]) or "-",
|
||||
r["title"],
|
||||
)
|
||||
)
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def plan_apply(report, approved_issues, actor, cfg, add_ready=False):
|
||||
"""Produce guarded edit plans only for maintainer-approved, complete legacy issues.
|
||||
|
||||
Never fabricates missing fields or file ownership, and never adds agent:ready unless
|
||||
explicitly requested by a maintainer for a complete issue.
|
||||
"""
|
||||
if not cfgmod.is_maintainer(cfg, actor):
|
||||
return {
|
||||
"ok": False,
|
||||
"error": "only a maintainer may approve issue body migrations or ready labels",
|
||||
"actions": [],
|
||||
"skipped": [],
|
||||
}
|
||||
|
||||
approved = {int(n) for n in approved_issues}
|
||||
actions = []
|
||||
skipped = []
|
||||
for r in report.get("issues") or []:
|
||||
n = r["number"]
|
||||
if n not in approved:
|
||||
continue
|
||||
if r["status"] == "compliant":
|
||||
skipped.append({"issue": n, "reason": "already compliant"})
|
||||
continue
|
||||
if r["status"] != "legacy_migratable" or r["missing_fields"]:
|
||||
skipped.append(
|
||||
{
|
||||
"issue": n,
|
||||
"reason": "incomplete (missing: %s); maintainer must supply explicit fields without fabricating ownership"
|
||||
% ", ".join(r["missing_fields"]),
|
||||
}
|
||||
)
|
||||
continue
|
||||
actions.append(
|
||||
{
|
||||
"issue": n,
|
||||
"edit_body": r["proposed_body"],
|
||||
"add_labels": ["agent:ready"] if add_ready else [],
|
||||
"preserved_history": True,
|
||||
"approved_by": actor,
|
||||
}
|
||||
)
|
||||
return {"ok": True, "actions": actions, "skipped": skipped}
|
||||
@@ -0,0 +1,244 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
|
||||
|
||||
from agent_queue import migrate as M
|
||||
from agent_queue import tasks as T
|
||||
from helpers import CFG, ROOT, issue
|
||||
|
||||
|
||||
LEGACY_H2_BODY = """## Area
|
||||
|
||||
shared
|
||||
|
||||
## Priority
|
||||
|
||||
high
|
||||
|
||||
## Files
|
||||
|
||||
- `scripts/agent_queue/`
|
||||
- `tests/agent_queue/`
|
||||
- `docs/coordination/`
|
||||
|
||||
## Acceptance command
|
||||
|
||||
```sh
|
||||
PYTHONPATH=scripts python3 -m unittest discover -s tests/agent_queue
|
||||
```
|
||||
|
||||
## Depends on
|
||||
|
||||
#165
|
||||
|
||||
## Interface
|
||||
|
||||
Existing public interfaces; coordinate changes before editing.
|
||||
|
||||
## Objective and acceptance criteria
|
||||
|
||||
Build a dry-run migration inventory for legacy ## headings versus ### headings.
|
||||
|
||||
Baseline: 951189c; preserve existing issue history.
|
||||
"""
|
||||
|
||||
INCOMPLETE_LEGACY_BODY = """## Area
|
||||
|
||||
runtime
|
||||
|
||||
## Priority
|
||||
|
||||
medium
|
||||
|
||||
## Acceptance command
|
||||
|
||||
cargo test --workspace
|
||||
|
||||
## Objective and acceptance criteria
|
||||
|
||||
Add missing runtime checks without guessing owned paths.
|
||||
"""
|
||||
|
||||
COMPLIANT_H3_BODY = """### Area
|
||||
|
||||
gpu
|
||||
|
||||
### Priority
|
||||
|
||||
high
|
||||
|
||||
### Files
|
||||
|
||||
crates/xenora-metal/
|
||||
|
||||
### Acceptance command
|
||||
|
||||
cargo test -p xenora-metal
|
||||
|
||||
### Depends on
|
||||
|
||||
#165
|
||||
"""
|
||||
|
||||
|
||||
class MigrationInventory(unittest.TestCase):
|
||||
def test_reproducible_gap_and_round_trip(self):
|
||||
i = {"number": 179, "title": "[SHARED] Migrate legacy issues", "state": "OPEN", "labels": ["p2"], "body": LEGACY_H2_BODY}
|
||||
|
||||
# Reproducible gap: current ### parser misses every legacy ## section.
|
||||
current = T.parse_task(i)
|
||||
self.assertEqual(current["area"], "")
|
||||
self.assertEqual(current["files"], [])
|
||||
self.assertEqual(current["depends"], [])
|
||||
self.assertEqual(current["acceptance"], "")
|
||||
|
||||
rec = M.classify_issue(i)
|
||||
self.assertEqual(rec["status"], "legacy_migratable")
|
||||
self.assertEqual(rec["heading_style"], "h2_legacy")
|
||||
self.assertTrue(rec["requires_maintainer_review"])
|
||||
self.assertFalse(rec["safe_to_apply_without_review"])
|
||||
self.assertEqual(rec["missing_fields"], [])
|
||||
self.assertEqual(rec["legacy_parsed"]["area"], "shared")
|
||||
self.assertEqual(rec["legacy_parsed"]["priority"], "high")
|
||||
self.assertEqual(
|
||||
rec["legacy_parsed"]["files"],
|
||||
["scripts/agent_queue/", "tests/agent_queue/", "docs/coordination/"],
|
||||
)
|
||||
self.assertEqual(rec["legacy_parsed"]["depends"], [165])
|
||||
self.assertEqual(
|
||||
rec["legacy_parsed"]["acceptance"],
|
||||
"PYTHONPATH=scripts python3 -m unittest discover -s tests/agent_queue",
|
||||
)
|
||||
self.assertTrue(all(rec["parser_gap"].values()))
|
||||
|
||||
# Round-trip: proposed ### body parses cleanly under tasks.parse_task.
|
||||
reparsed = T.parse_task({"number": 179, "title": i["title"], "state": "OPEN", "labels": [], "body": rec["proposed_body"]})
|
||||
self.assertEqual(reparsed["area"], "shared")
|
||||
self.assertEqual(reparsed["priority"], "high")
|
||||
self.assertEqual(
|
||||
reparsed["files"],
|
||||
["scripts/agent_queue/", "tests/agent_queue/", "docs/coordination/"],
|
||||
)
|
||||
self.assertEqual(reparsed["depends"], [165])
|
||||
self.assertEqual(
|
||||
T.normalise_acceptance(reparsed["acceptance"]),
|
||||
"PYTHONPATH=scripts python3 -m unittest discover -s tests/agent_queue",
|
||||
)
|
||||
self.assertIn("Baseline: 951189c; preserve existing issue history.", rec["proposed_body"])
|
||||
|
||||
def test_never_fabricates_file_ownership(self):
|
||||
i = {"number": 201, "title": "[RUNTIME] Missing files", "state": "OPEN", "labels": [], "body": INCOMPLETE_LEGACY_BODY}
|
||||
rec = M.classify_issue(i)
|
||||
self.assertEqual(rec["status"], "incomplete")
|
||||
self.assertEqual(rec["legacy_parsed"]["files"], [])
|
||||
self.assertIn("files", rec["missing_fields"])
|
||||
self.assertIn("no_explicit_file_ownership", rec["warnings"])
|
||||
self.assertTrue(rec["requires_maintainer_review"])
|
||||
|
||||
def test_preserves_preamble_and_extra_sections(self):
|
||||
body = (
|
||||
"Original triage note from 2026-11-20.\n\n"
|
||||
+ LEGACY_H2_BODY
|
||||
+ "\n## Historical notes\n\nObserved on Apple M5; keep this record.\n"
|
||||
)
|
||||
rec = M.classify_issue({"number": 180, "title": "History check", "state": "OPEN", "labels": [], "body": body})
|
||||
self.assertIn("Original triage note from 2026-11-20.", rec["proposed_body"])
|
||||
self.assertIn("## Historical notes", rec["proposed_body"])
|
||||
self.assertIn("Observed on Apple M5; keep this record.", rec["proposed_body"])
|
||||
self.assertIn("extra_content_preserved_in_context", rec["warnings"])
|
||||
|
||||
def test_code_fences_in_files_not_treated_as_paths(self):
|
||||
body = (
|
||||
"## Area\n\nshared\n\n## Files\n\n```text\nscripts/agent_queue/\n```\n\n"
|
||||
"## Acceptance command\n\n```sh\npython3 -m unittest\n```\n"
|
||||
)
|
||||
rec = M.classify_issue({"number": 182, "title": "Fenced files", "state": "OPEN", "labels": [], "body": body})
|
||||
self.assertEqual(rec["legacy_parsed"]["files"], ["scripts/agent_queue/"])
|
||||
reparsed = T.parse_task({"number": 182, "body": rec["proposed_body"]})
|
||||
self.assertEqual(reparsed["files"], ["scripts/agent_queue/"])
|
||||
|
||||
def test_compliant_h3_issue_is_not_rewritten(self):
|
||||
rec = M.classify_issue({"number": 183, "title": "Compliant", "state": "OPEN", "labels": ["agent:ready"], "body": COMPLIANT_H3_BODY})
|
||||
self.assertEqual(rec["status"], "compliant")
|
||||
self.assertEqual(rec["heading_style"], "h3")
|
||||
self.assertFalse(rec["requires_maintainer_review"])
|
||||
self.assertIsNone(rec["proposed_body"])
|
||||
|
||||
def test_mixed_headings_detected(self):
|
||||
body = "### Area\n\nqa\n\n## Files\n\ntests/agent_queue/\n\n### Acceptance command\n\npython3 -m unittest\n"
|
||||
rec = M.classify_issue({"number": 184, "title": "Mixed", "state": "OPEN", "labels": [], "body": body})
|
||||
self.assertEqual(rec["heading_style"], "mixed")
|
||||
self.assertEqual(rec["status"], "legacy_migratable")
|
||||
self.assertTrue(rec["parser_gap"]["files_missed"])
|
||||
|
||||
def test_plan_apply_requires_maintainer_and_blocks_incomplete(self):
|
||||
state = {
|
||||
"issues": [
|
||||
{"number": 179, "title": "Legacy ok", "state": "OPEN", "labels": [], "body": LEGACY_H2_BODY},
|
||||
{"number": 201, "title": "Incomplete", "state": "OPEN", "labels": [], "body": INCOMPLETE_LEGACY_BODY},
|
||||
{"number": 183, "title": "Compliant", "state": "OPEN", "labels": [], "body": COMPLIANT_H3_BODY},
|
||||
issue(999, state="CLOSED"),
|
||||
]
|
||||
}
|
||||
rep = M.inventory(state)
|
||||
self.assertTrue(rep["dry_run"])
|
||||
self.assertEqual(rep["total"], 3)
|
||||
self.assertEqual(rep["counts"], {"compliant": 1, "legacy_migratable": 1, "incomplete": 1})
|
||||
|
||||
# Non-maintainer refused.
|
||||
refused = M.plan_apply(rep, [179], actor="gpu-dev", cfg=CFG, add_ready=True)
|
||||
self.assertFalse(refused["ok"])
|
||||
self.assertEqual(refused["actions"], [])
|
||||
|
||||
# Maintainer approving all three: only #179 gets an edit plan; #201 is blocked; #183 skipped.
|
||||
plan = M.plan_apply(rep, [179, 201, 183], actor="maint", cfg=CFG, add_ready=False)
|
||||
self.assertTrue(plan["ok"])
|
||||
self.assertEqual([a["issue"] for a in plan["actions"]], [179])
|
||||
self.assertEqual(plan["actions"][0]["add_labels"], [])
|
||||
self.assertEqual(len(plan["skipped"]), 2)
|
||||
|
||||
# Explicit opt-in required to add agent:ready.
|
||||
plan_ready = M.plan_apply(rep, [179], actor="maint", cfg=CFG, add_ready=True)
|
||||
self.assertEqual(plan_ready["actions"][0]["add_labels"], ["agent:ready"])
|
||||
|
||||
|
||||
class MigrationCli(unittest.TestCase):
|
||||
def test_cli_migrate_inventory_json_and_text(self):
|
||||
state = {
|
||||
"issues": [
|
||||
{"number": 179, "title": "Legacy ok", "state": "OPEN", "labels": [], "body": LEGACY_H2_BODY},
|
||||
{"number": 201, "title": "Incomplete", "state": "OPEN", "labels": [], "body": INCOMPLETE_LEGACY_BODY},
|
||||
]
|
||||
}
|
||||
env = dict(os.environ, PYTHONPATH=os.path.join(ROOT, "scripts"))
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
sp = os.path.join(td, "state.json")
|
||||
with open(sp, "w", encoding="utf-8") as fh:
|
||||
json.dump(state, fh)
|
||||
|
||||
r_json = subprocess.run(
|
||||
[sys.executable, "-m", "agent_queue", "migrate-inventory", "--state", sp],
|
||||
cwd=ROOT, env=env, capture_output=True, text=True, check=True,
|
||||
)
|
||||
out = json.loads(r_json.stdout)
|
||||
self.assertTrue(out["dry_run"])
|
||||
self.assertEqual(out["counts"]["legacy_migratable"], 1)
|
||||
self.assertEqual(out["counts"]["incomplete"], 1)
|
||||
|
||||
r_text = subprocess.run(
|
||||
[sys.executable, "-m", "agent_queue", "migrate-inventory", "--state", sp, "--text"],
|
||||
cwd=ROOT, env=env, capture_output=True, text=True, check=True,
|
||||
)
|
||||
self.assertIn("Dry-run issue migration inventory", r_text.stdout)
|
||||
self.assertIn("#179\tlegacy_migratable\th2_legacy", r_text.stdout)
|
||||
self.assertIn("#201\tincomplete\th2_legacy", r_text.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user