fix: 上游巡检允许已审查暂缓覆盖集合新增子技能 (#230)

## Why

`upstream-health-hold.json` could only cover `upstream-path-change` and
`outdated`. When the upstream head of a held collection adds children
that `children` does not declare, the `new-skill` finding stays
actionable even after maintainers have reviewed those children and
decided not to declare them, so the tracking issue (#213) can never
close. `skills/marketingskills` is in this state today: its two new
upstream children were reviewed in the 2026-10-27 round (#227), but
nothing can hold the finding.

## What changes

- `new-skill` is now a holdable status (`HOLDABLE =
("upstream-path-change", "new-skill", "outdated")`).
- A hold that lists `new-skill` also checks the undeclared children:
- the set of undeclared child paths at branch head must equal the set at
the reviewed `head`; otherwise `stale-hold: undeclared children changed
since <head> (added …; removed …)`;
- the staleness diff adds those undeclared child paths to the installed
scope (declared children plus root `LICENSE*`/`NOTICE*`/`COPYING*`), so
any change inside them gives `stale-hold: upstream changed within the
installed scope or undeclared children since <head>`;
- a network error while listing children at the reviewed head is
`unreachable`, not a stale hold.
- Holds without `new-skill` compare the same scope and keep every
existing message. The only wording change for them is the validation
error for an unholdable status, which now lists `new-skill` among the
holdable statuses.
- The discovery filter moves into `undeclared_children()`, which the
`new-skill` finding and the hold check share, so both always agree on
what is undeclared.
- The checker docstring, the tracking-issue guidance in
`.github/workflows/upstream-health.yml`, `README.md` and
`README.zh-CN.md` describe the extended hold.

## Tests

New cases in `scripts/catalog/test_check_upstream_health.py`:

- a valid `new-skill` hold is reported as `held`, and stays held after
an unrelated upstream change;
- a newly added undeclared child, and later the removal of the reviewed
ones, make the hold stale;
- a content change inside a held undeclared child makes the hold stale;
- an `outdated`-only hold on a collection still ignores changes to
undeclared children (existing behaviour);
- a network error while listing children at the reviewed head stays
`unreachable`.

The validation test now accepts `new-skill` and still rejects broken,
`unreachable`, `unpinned`, `held`, `stale-hold` and `ok`.

## Validation

- `scripts/i18n/test_validate_i18n.py`: 19 tests pass.
- `scripts/catalog/test_validate_catalog_metadata.py`: 51 tests pass.
- `scripts/catalog/test_collection_generator.py`: 10 tests pass.
- `scripts/catalog/test_check_upstream_health.py`: 47 tests pass (5
new).
- `validate_catalog_metadata.py --require-complete` and
`validate-i18n.py`: 0 errors, 103 existing warnings. `translate.py
--check`, `actionlint` and `git diff --check` are clean.
- Live run on `marketingskills` (entry and hold as on `main`, in a
scratch copy, not committed):
- with `new-skill` added to the 2026-10-27 hold, the result is
`stale-hold`, because upstream has since moved from `17772c7` to
`0cd9b3a` and changed declared children. The same hold without
`new-skill` is also stale, so this is not caused by the new check. The
two undeclared children are unchanged between those heads.
- with the reviewed head set to a commit whose tree equals the current
head, `new-skill` and `outdated` are both `held` and the summary reports
`actionable: false`.

## Follow-up

After this lands, the `marketingskills` hold can add `new-skill` to its
`statuses`. Its reviewed head needs a fresh review first, because
upstream has changed declared children since `17772c7`.

The pre-publication sensitive-token scan was run privately by the
maintainer and passed.

Refs #213.
This commit is contained in:
yige authored and GitHub committed 2026-10-28 20:08:36 +08:00
1 parent c8626c758e
commit 1ced701714
5 files changed
+121 -25

No files matched your search

+52 -19
View File
@@ -16,28 +16,32 @@ script looks at each upstream and reports, without rewriting anything:
bad-path source.path, the root SKILL.md, or a declared child path is missing at
the installed snapshot (source.ref, or branch head when unpinned)
unreachable network error other than "not found"; treated as unknown, not broken
stale-hold a reviewed hold no longer applies (invalid file, pin or installed upstream
content changed since review, or nothing left to hold); re-review it
stale-hold a reviewed hold no longer applies (invalid file, pin, installed upstream
content or held undeclared children changed since review, or nothing
left to hold); re-review it
new-skill branch head has collection children that `children` does not declare
(same discovery rules as scripts/gen-collection-children.py)
upstream-path-change a declared path moved at branch head but the pin still works
outdated pinned content differs from branch head; review before updating
unpinned entry follows a moving branch without source.ref
held upstream-path-change / outdated finding covered by a reviewed hold
held upstream-path-change / new-skill / outdated finding covered by a reviewed hold
ok nothing to report
Path checks distinguish the installed snapshot from changes at branch head.
Only skills get path checks; agents and teams are AgentFS repositories.
Maintainers who review an upstream change and deliberately keep the current pin
record that decision next to entry.json in `upstream-health-hold.json`:
Maintainers who review an upstream change and deliberately keep the current pin,
or leave new upstream children undeclared, record that decision next to
entry.json in `upstream-health-hold.json`:
{"statuses": ["upstream-path-change", "outdated"], "ref": "<source.ref>",
"head": "<reviewed upstream commit>", "reviewedAt": "YYYY-MM-DD", "reason": "..."}
The listed findings are reported as `held` while source.ref still equals `ref`
and the installed content at branch head is unchanged since `head`. Broken,
unreachable, new-skill and unpinned findings can never be held.
and the installed content at branch head is unchanged since `head`. A hold that
lists new-skill also needs the same undeclared child paths at branch head as at
`head`, with unchanged content. Broken, unreachable and unpinned findings can
never be held.
Usage:
uv run scripts/catalog/check_upstream_health.py # text table
@@ -77,7 +81,7 @@ ORDER = (*BROKEN, "unreachable", "stale-hold", "upstream-path-change", "new-skil
# A reviewed decision to keep the current pin, next to entry.json.
HOLD_NAME = "upstream-health-hold.json"
HOLD_KEYS = ("statuses", "ref", "head", "reviewedAt", "reason")
HOLDABLE = ("upstream-path-change", "outdated")
HOLDABLE = ("upstream-path-change", "new-skill", "outdated")
SHA = re.compile(r"[0-9a-f]{40}")
# Git asks for credentials when a public repository disappears; never prompt.
@@ -217,17 +221,12 @@ def check_skill_paths(entry: dict, repo: Path, revision: str = "HEAD", *,
children = entry.get("children") or []
if children:
declared = {c["path"].strip("/") for c in children}
for child in children:
if child["path"].strip("/") not in skill_dirs:
issues.append(("bad-path", f"child '{child['id']}' -> '{child['path']}' has no SKILL.md"))
discovered = [c for c in GENERATOR.discover_children(repo, revision)
if c["path"] not in declared] if discover else []
declared_ids = {c["id"] for c in children}
extra = [c["path"] for c in discovered if c["id"] not in declared_ids]
extra = undeclared_children(entry, repo, revision) if discover else []
if extra:
shown = ", ".join(extra[:8]) + (f" (+{len(extra) - 8} more)" if len(extra) > 8 else "")
issues.append(("new-skill", shown))
issues.append(("new-skill", abbreviate(extra)))
else:
path = (entry["source"].get("path") or "").strip("/")
if path not in skill_dirs:
@@ -236,13 +235,30 @@ def check_skill_paths(entry: dict, repo: Path, revision: str = "HEAD", *,
return issues
def undeclared_children(entry: dict, repo: Path, revision: str) -> list[str]:
"""Paths of the collection children at `revision` that `children` does not declare."""
children = entry.get("children") or []
if not children:
return []
declared = {c["path"].strip("/") for c in children}
declared_ids = {c["id"] for c in children}
return [c["path"] for c in GENERATOR.discover_children(repo, revision)
if c["path"] not in declared and c["id"] not in declared_ids]
def abbreviate(paths: list[str]) -> str:
return ", ".join(paths[:8]) + (f" (+{len(paths) - 8} more)" if len(paths) > 8 else "")
def apply_hold(issues: list[tuple[str, str]], hold: dict, entry: dict, kind: str, repo: Path,
head: str) -> list[tuple[str, str]]:
"""Report reviewed findings as `held` while the review still covers them.
A hold covers one pinned ref and the installed scope at the reviewed
upstream head. Once either moves, or nothing it lists is found any more,
the findings are kept as they are and a `stale-hold` explains why.
upstream head; a `new-skill` hold also covers the set and content of the
undeclared children at that head. Once any of these moves, or nothing it
lists is found any more, the findings are kept as they are and a
`stale-hold` explains why.
"""
if any(status == "unreachable" for status, _ in issues):
return issues # unknown state: the review can be neither applied nor judged stale
@@ -256,9 +272,26 @@ def apply_hold(issues: list[tuple[str, str]], hold: dict, entry: dict, kind: str
status = "stale-hold" if MISSING_COMMIT.search(fetched.stderr) else "unreachable"
return [*issues, (status, f"reviewed head {reviewed[:7]} cannot be fetched: "
f"{last_line(fetched.stderr)}")]
difference = git("diff", "--quiet", reviewed, head, *comparison_scope(entry, kind), cwd=repo)
scope, undeclared = comparison_scope(entry, kind), []
if "new-skill" in hold["statuses"]:
# Undeclared children are not installed, so the scope above skips them.
try:
undeclared = undeclared_children(entry, repo, head)
before = undeclared if reviewed == head else undeclared_children(entry, repo, reviewed)
except RuntimeError as err:
return [*issues, ("unreachable", f"cannot compare undeclared children with reviewed head "
f"{reviewed[:7]}: {str(err)[:300]}")]
added, removed = sorted(set(undeclared) - set(before)), sorted(set(before) - set(undeclared))
if added or removed:
change = "; ".join(f"{word} {abbreviate(paths)}"
for word, paths in (("added", added), ("removed", removed)) if paths)
return [*issues, ("stale-hold", f"undeclared children changed since {reviewed[:7]} ({change})")]
if scope: # an empty scope already compares the whole snapshot
scope = [*scope, *undeclared]
difference = git("diff", "--quiet", reviewed, head, *scope, cwd=repo)
if difference.returncode == 1:
return [*issues, ("stale-hold", f"upstream changed within the installed scope since {reviewed[:7]}")]
within = "the installed scope or undeclared children" if undeclared else "the installed scope"
return [*issues, ("stale-hold", f"upstream changed within {within} since {reviewed[:7]}")]
if difference.returncode != 0:
return [*issues, ("unreachable", f"cannot compare with reviewed head {reviewed[:7]}: "
f"{last_line(difference.stderr)}")]
+64 -1
View File
@@ -265,12 +265,75 @@ class UpstreamHealthTests(unittest.TestCase):
issues = CHECKER.check_entry(entry)["issues"]
self.assertEqual([i["status"] for i in issues], ["held", "held"])
def test_hold_covers_undeclared_children_reviewed_at_head(self) -> None:
self.commit({"skills/beta/SKILL.md": "---\nname: beta\ndescription: B.\n---\n"})
entry = self.entry(ref=self.first, children=[{"id": "alpha", "path": "skills/alpha"}])
self.hold(entry, statuses=["new-skill"], reason="Beta is not offered.")
self.assertEqual(self.statuses(entry),
{"held": "new-skill: skills/beta — reviewed 2026-10-01: Beta is not offered."})
self.commit({"README.md": "New website.\n"})
self.assertEqual(set(self.statuses(entry)), {"held"})
def test_changed_undeclared_child_set_makes_a_new_skill_hold_stale(self) -> None:
reviewed = self.commit({"skills/beta/SKILL.md": "---\nname: beta\ndescription: B.\n---\n"})
entry = self.entry(ref=self.first, children=[{"id": "alpha", "path": "skills/alpha"}])
self.hold(entry, statuses=["new-skill"])
self.commit({"skills/gamma/SKILL.md": "---\nname: gamma\ndescription: G.\n---\n"})
result = self.statuses(entry)
self.assertEqual(result["new-skill"], "skills/beta, skills/gamma")
self.assertNotIn("held", result)
self.assertEqual(result["stale-hold"],
f"undeclared children changed since {reviewed[:7]} (added skills/gamma)")
sh("git", "rm", "--quiet", "-r", "skills/beta", "skills/gamma", cwd=self.upstream)
self.commit({})
result = self.statuses(entry)
self.assertEqual(set(result), {"stale-hold"})
self.assertIn("(removed skills/beta)", result["stale-hold"])
def test_held_undeclared_child_change_makes_the_hold_stale(self) -> None:
reviewed = self.commit({"skills/beta/SKILL.md": "---\nname: beta\ndescription: B.\n---\n"})
entry = self.entry(ref=self.first, children=[{"id": "alpha", "path": "skills/alpha"}])
self.hold(entry, statuses=["new-skill"])
self.commit({"skills/beta/references/offer.md": "Sponsored content.\n"})
result = self.statuses(entry)
self.assertEqual(result["new-skill"], "skills/beta")
self.assertNotIn("held", result)
self.assertEqual(result["stale-hold"],
f"upstream changed within the installed scope or undeclared children since {reviewed[:7]}")
def test_outdated_hold_ignores_changes_to_undeclared_children(self) -> None:
self.commit({"skills/alpha/SKILL.md": "---\nname: alpha\ndescription: Updated.\n---\n",
"skills/beta/SKILL.md": "---\nname: beta\ndescription: B.\n---\n"})
entry = self.entry(ref=self.first, children=[{"id": "alpha", "path": "skills/alpha"}])
self.hold(entry)
self.commit({"skills/beta/SKILL.md": "---\nname: beta\ndescription: Changed.\n---\n"})
result = self.statuses(entry)
self.assertEqual(set(result), {"held", "new-skill"})
self.assertTrue(result["held"].startswith("outdated: "))
def test_network_error_listing_reviewed_children_is_unknown_not_stale(self) -> None:
reviewed = self.commit({"skills/beta/SKILL.md": "---\nname: beta\ndescription: B.\n---\n"})
entry = self.entry(ref=self.first, children=[{"id": "alpha", "path": "skills/alpha"}])
self.hold(entry, statuses=["new-skill"])
self.commit({"README.md": "New website.\n"})
real_undeclared = CHECKER.undeclared_children
def failing_listing(entry, repo, revision):
if revision == reviewed:
raise RuntimeError("cannot read skills/beta/SKILL.md: Connection reset by peer")
return real_undeclared(entry, repo, revision)
with patch.object(CHECKER, "undeclared_children", side_effect=failing_listing):
result = self.statuses(entry)
self.assertEqual(set(result), {"new-skill", "unreachable"})
def test_hold_validation_rejects_unholdable_statuses_bad_shas_and_extra_keys(self) -> None:
valid = {"statuses": ["upstream-path-change", "outdated"], "ref": "a" * 40, "head": "b" * 40,
"reviewedAt": "2026-10-01", "reason": "Kept after review."}
self.assertEqual(CHECKER.hold_errors(valid), [])
self.assertEqual(CHECKER.hold_errors({**valid, "statuses": ["new-skill"]}), [])
invalid = [{"statuses": [status]} for status in
(*CHECKER.BROKEN, "unreachable", "new-skill", "unpinned", "held", "stale-hold", "ok")]
(*CHECKER.BROKEN, "unreachable", "unpinned", "held", "stale-hold", "ok")]
invalid += [{"statuses": []}, {"statuses": "outdated"}, {"statuses": ["outdated", "outdated"]},
{"ref": "A" * 40}, {"ref": "a" * 12}, {"head": "g" * 40}, {"head": None},
{"reviewedAt": "2026-13-01"}, {"reviewedAt": "18/10/2026"}, {"reason": " "}, {"reason": 1},