From f084c9957a459f46c85e5468718c6e1d21c9f8d8 Mon Sep 17 00:00:00 2001 From: "takemi.ohama" Date: Sun, 22 Nov 2026 00:21:17 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20=E7=89=88=E4=B8=8A=E3=81=92=E3=81=AE?= =?UTF-8?q?=E7=B5=84=E3=81=BF=E7=AB=8B=E3=81=A6=E3=81=A7=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=AE=20plugin.json=20=E3=81=AE=20version=20?= =?UTF-8?q?=E3=82=82=E3=81=9D=E3=82=8D=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 11.0.14 の assemble(run 44965920730)が、依存を更新した playwright-kit の Claude 版の plugin.json だけを 4.0.5 へ上げ、ルートの plugin.json(Agent Plugins package)が 4.0.4 のまま 残って validate_manifests で落ちた。手順「版数の記載をそろえる」がルートの version と description を Claude 版にそろえ、assemble が書き換えを受け入れるよう writes に足す。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KYHP7xPKEHnLPsZtLawhvj --- .ndf/release.json | 2 +- scripts/sync-version-mentions.py | 20 +++++++++++++++++++- scripts/tests/test_sync_version_mentions.py | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.ndf/release.json b/.ndf/release.json index 34ab2e197..f8a0f99ca 100644 --- a/.ndf/release.json +++ b/.ndf/release.json @@ -6,7 +6,7 @@ "name": "版数の記載をそろえる", "stage": "production", "command": ["python3", "scripts/sync-version-mentions.py", "--root", "."], - "writes": ["README.md", "docs/versioning-and-distribution.md", "plugins/ndf/README.md", ".claude-plugin/marketplace.json"], + "writes": ["README.md", "docs/versioning-and-distribution.md", "plugins/ndf/README.md", ".claude-plugin/marketplace.json", "plugins/playwright-kit/plugin.json"], "timeout_seconds": 300 }, { diff --git a/scripts/sync-version-mentions.py b/scripts/sync-version-mentions.py index 6a6cfe3ce..bfd31eb12 100644 --- a/scripts/sync-version-mentions.py +++ b/scripts/sync-version-mentions.py @@ -4,7 +4,7 @@ リリースの設定(`.ndf/release.json`)の手順として、版上げの PR の組み立て(`ndf release-steps assemble`)が `plugin.json` の `version` を上げた後に打つ。 -- 各プラグインの `.claude-plugin/plugin.json`・`.codex-plugin/plugin.json` と、`.claude-plugin/marketplace.json` の +- 各プラグインの `.claude-plugin/plugin.json`・`.codex-plugin/plugin.json`・ルートの `plugin.json`(`version` も)と、`.claude-plugin/marketplace.json` の そのプラグインの description の `(vX.Y.Z)` を、Claude 版の `plugin.json` の `version` にそろえる (`scripts/lib/validate_manifests.py` が確かめる規則) - `scripts/check-doc-staleness.py` が「記載: <古い版>(L<行>) / <正本>: <新しい版>」と報告した行の版数だけを置き換える。 @@ -44,6 +44,9 @@ def sync_descriptions(root: Path) -> list[str]: for path in (claude, claude.parent.parent / ".codex-plugin" / "plugin.json"): if path.is_file() and replace_description_version(path, version, json.loads(path.read_text(encoding="utf-8"))): changed.add(path.relative_to(root).as_posix()) + package = claude.parent.parent / "plugin.json" # Agent Plugins package(ルートの plugin.json)は version も追う + if package.is_file() and sync_package(package, version): + changed.add(package.relative_to(root).as_posix()) market = root / ".claude-plugin" / "marketplace.json" if market.is_file(): for entry in json.loads(market.read_text(encoding="utf-8")).get("plugins", []): @@ -53,6 +56,21 @@ def sync_descriptions(root: Path) -> list[str]: return sorted(changed) +def sync_package(path: Path, version: str) -> bool: + """ルートの plugin.json の `version` と description の版数を `version` にそろえる(整形はそのまま保つ)。""" + manifest = json.loads(path.read_text(encoding="utf-8")) + old = manifest.get("version") + bumped = False + if isinstance(old, str) and old != version: + text = path.read_text(encoding="utf-8") + literal = f'"version": {json.dumps(old)}' + if literal not in text: + raise SystemExit(f"{path}: version の値を本文から見つけられない(整形の形が違う)") + path.write_text(text.replace(literal, f'"version": {json.dumps(version)}', 1), encoding="utf-8") + bumped = True + return replace_description_version(path, version, json.loads(path.read_text(encoding="utf-8"))) or bumped + + def replace_description_version(path: Path, version: str, owner: dict) -> bool: """`owner`(`path` の中のオブジェクト)の `description` の `(vX.Y.Z)` だけを置き換える(ファイルの整形はそのまま保つ)。""" text = path.read_text(encoding="utf-8") diff --git a/scripts/tests/test_sync_version_mentions.py b/scripts/tests/test_sync_version_mentions.py index efe98a3b0..eccb419a7 100644 --- a/scripts/tests/test_sync_version_mentions.py +++ b/scripts/tests/test_sync_version_mentions.py @@ -65,6 +65,19 @@ def test_bumped_tree_becomes_consistent(tmp_path: Path) -> None: assert "そろえた: README.md" in got.stdout +def test_root_plugin_manifest_follows_the_claude_version(tmp_path: Path) -> None: + # 2026-11-22 の 11.0.14 の組み立て: 依存を更新した playwright-kit の Claude 版だけが 4.0.5 へ上がり、 + # ルートの plugin.json(Agent Plugins package)が 4.0.4 のまま残って validate_manifests が落ちた + tree = _export(tmp_path) + new = _bump(tree, "playwright-kit") + got = _run(tree) + assert got.returncode == 0, got.stderr + root = json.loads((tree / "plugins/playwright-kit/plugin.json").read_text(encoding="utf-8")) + assert root["version"] == new + assert f"(v{new})" in root["description"] + assert "そろえた: plugins/playwright-kit/plugin.json" in got.stdout + + def test_consistent_tree_is_left_alone(tmp_path: Path) -> None: tree = _export(tmp_path) got = _run(tree) From 248541a8eb6209da8e4858a535eaf77d5f657fc9 Mon Sep 17 00:00:00 2001 From: "takemi.ohama" Date: Sun, 22 Nov 2026 00:37:58 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20=E3=83=AB=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=20plugin.json=20=E3=81=AE=E5=90=8C=E6=9C=9F=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=82=92=E5=AE=A3=E8=A8=80=E3=81=AE=20writes=20=E3=81=8B?= =?UTF-8?q?=E3=82=89=E8=AA=AD=E3=81=BF=E3=80=811=20=E5=9B=9E=E3=81=AE?= =?UTF-8?q?=E8=AA=AD=E3=81=BF=E6=9B=B8=E3=81=8D=E3=81=A7=E3=81=9D=E3=82=8D?= =?UTF-8?q?=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 同期するルートの plugin.json を .ndf/release.json のこの手順の writes から読む。 宣言に無いものがあれば書く前に止める(組み立てが writes の外として止まるのと同じパスを使う)(r1-1) - マニフェストは 1 回読んで解析し、version と description の更新をまとめて 1 回だけ書く。 marketplace.json も複数の項目をまとめて 1 回で書く(r1-2) Co-Authored-By: Claude Opus 5.5 --- scripts/sync-version-mentions.py | 87 +++++++++++++++------ scripts/tests/test_sync_version_mentions.py | 17 ++++ 2 files changed, 79 insertions(+), 25 deletions(-) diff --git a/scripts/sync-version-mentions.py b/scripts/sync-version-mentions.py index bfd31eb12..9da92e526 100644 --- a/scripts/sync-version-mentions.py +++ b/scripts/sync-version-mentions.py @@ -4,7 +4,8 @@ リリースの設定(`.ndf/release.json`)の手順として、版上げの PR の組み立て(`ndf release-steps assemble`)が `plugin.json` の `version` を上げた後に打つ。 -- 各プラグインの `.claude-plugin/plugin.json`・`.codex-plugin/plugin.json`・ルートの `plugin.json`(`version` も)と、`.claude-plugin/marketplace.json` の +- 各プラグインの `.claude-plugin/plugin.json`・`.codex-plugin/plugin.json`・ルートの `plugin.json`(`version` も。 + リリースの設定のこの手順の `writes` に書いたものだけ。無いものがあれば書く前に止める)と、`.claude-plugin/marketplace.json` の そのプラグインの description の `(vX.Y.Z)` を、Claude 版の `plugin.json` の `version` にそろえる (`scripts/lib/validate_manifests.py` が確かめる規則) - `scripts/check-doc-staleness.py` が「記載: <古い版>(L<行>) / <正本>: <新しい版>」と報告した行の版数だけを置き換える。 @@ -28,13 +29,22 @@ r"(?P\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?))" ) MAX_ROUNDS = 3 +RELEASE_CONFIG = ".ndf/release.json" +SCRIPT_NAME = "sync-version-mentions.py" def sync_descriptions(root: Path) -> list[str]: """description の版数を Claude 版の plugin.json の version にそろえ、書き換えたファイルを返す。""" changed = set() versions = {} - for claude in sorted(root.glob("plugins/**/.claude-plugin/plugin.json")): + claudes = sorted(root.glob("plugins/**/.claude-plugin/plugin.json")) + packages = declared_packages(root) + undeclared = sorted( + rel for rel in (package_of(c).relative_to(root).as_posix() for c in claudes if package_of(c).is_file()) if rel not in packages + ) + if undeclared: # 書き換えた後に組み立てが writes の外として止まる前に、書く前に止める + raise SystemExit(f"ルートの plugin.json が {RELEASE_CONFIG} のこの手順の writes に無い: {', '.join(undeclared)}") + for claude in claudes: manifest = json.loads(claude.read_text(encoding="utf-8")) version = manifest.get("version") if not isinstance(version, str): @@ -42,50 +52,77 @@ def sync_descriptions(root: Path) -> list[str]: if isinstance(manifest.get("name"), str): versions[manifest["name"]] = version for path in (claude, claude.parent.parent / ".codex-plugin" / "plugin.json"): - if path.is_file() and replace_description_version(path, version, json.loads(path.read_text(encoding="utf-8"))): + if path.is_file() and sync_manifest(path, version, follow_version=False): changed.add(path.relative_to(root).as_posix()) - package = claude.parent.parent / "plugin.json" # Agent Plugins package(ルートの plugin.json)は version も追う - if package.is_file() and sync_package(package, version): + package = package_of(claude) # Agent Plugins package(ルートの plugin.json)は version も追う + if package.is_file() and sync_manifest(package, version, follow_version=True): changed.add(package.relative_to(root).as_posix()) market = root / ".claude-plugin" / "marketplace.json" if market.is_file(): - for entry in json.loads(market.read_text(encoding="utf-8")).get("plugins", []): + text = market.read_text(encoding="utf-8") + fixed = text + for entry in json.loads(text).get("plugins", []): version = versions.get(entry.get("name")) if isinstance(entry, dict) else None - if version is not None and replace_description_version(market, version, entry): - changed.add(market.relative_to(root).as_posix()) + if version is not None: + fixed = replace_description_version(market, fixed, version, entry) + if fixed != text: + market.write_text(fixed, encoding="utf-8") + changed.add(market.relative_to(root).as_posix()) return sorted(changed) -def sync_package(path: Path, version: str) -> bool: - """ルートの plugin.json の `version` と description の版数を `version` にそろえる(整形はそのまま保つ)。""" - manifest = json.loads(path.read_text(encoding="utf-8")) +def package_of(claude: Path) -> Path: + return claude.parent.parent / "plugin.json" + + +def declared_packages(root: Path) -> set[str]: + """リリースの設定のうちこのスクリプトを打つ手順の `writes` から、ルートの plugin.json のパスを読む。 + + 組み立て(`assemble`)が書き換えてよいパスとして照らすのと同じ宣言を使う(同期の対象をここで別に持たない)。""" + path = root / RELEASE_CONFIG + if not path.is_file(): + return set() + steps = json.loads(path.read_text(encoding="utf-8")).get("steps", []) + mine = [s for s in steps if isinstance(s, dict) and any(str(a).endswith(SCRIPT_NAME) for a in s.get("command", []))] + writes = {Path(str(w)).as_posix().removeprefix("./") for s in mine for w in s.get("writes", [])} + return { + w + for w in writes + if w.startswith("plugins/") and w.endswith("/plugin.json") and "/.claude-plugin/" not in w and "/.codex-plugin/" not in w + } + + +def sync_manifest(path: Path, version: str, *, follow_version: bool) -> bool: + """1 回読んで、description の版数(`follow_version` なら `version` も)をそろえ、変われば 1 回だけ書く(整形はそのまま保つ)。""" + text = path.read_text(encoding="utf-8") + manifest = json.loads(text) + fixed = text old = manifest.get("version") - bumped = False - if isinstance(old, str) and old != version: - text = path.read_text(encoding="utf-8") + if follow_version and isinstance(old, str) and old != version: literal = f'"version": {json.dumps(old)}' - if literal not in text: + if literal not in fixed: raise SystemExit(f"{path}: version の値を本文から見つけられない(整形の形が違う)") - path.write_text(text.replace(literal, f'"version": {json.dumps(version)}', 1), encoding="utf-8") - bumped = True - return replace_description_version(path, version, json.loads(path.read_text(encoding="utf-8"))) or bumped + fixed = fixed.replace(literal, f'"version": {json.dumps(version)}', 1) + fixed = replace_description_version(path, fixed, version, manifest) + if fixed == text: + return False + path.write_text(fixed, encoding="utf-8") + return True -def replace_description_version(path: Path, version: str, owner: dict) -> bool: - """`owner`(`path` の中のオブジェクト)の `description` の `(vX.Y.Z)` だけを置き換える(ファイルの整形はそのまま保つ)。""" - text = path.read_text(encoding="utf-8") +def replace_description_version(path: Path, text: str, version: str, owner: dict) -> str: + """`owner`(`text` の中のオブジェクト)の `description` の `(vX.Y.Z)` だけを置き換えた本文を返す(整形はそのまま保つ)。""" description = owner.get("description") if not isinstance(description, str): - return False + return text found = DESCRIPTION_VERSION.search(description) if found is None or found.group(1) == version: - return False + return text fixed = description.replace(found.group(0), f"(v{version})", 1) old_literal = json.dumps(description, ensure_ascii=False) if old_literal not in text: raise SystemExit(f"{path}: description の値を本文から見つけられない(エスケープの形が違う)") - path.write_text(text.replace(old_literal, json.dumps(fixed, ensure_ascii=False), 1), encoding="utf-8") - return True + return text.replace(old_literal, json.dumps(fixed, ensure_ascii=False), 1) def stale_lines(output: str) -> list[tuple[str, int, str, str]]: diff --git a/scripts/tests/test_sync_version_mentions.py b/scripts/tests/test_sync_version_mentions.py index eccb419a7..ce5570df4 100644 --- a/scripts/tests/test_sync_version_mentions.py +++ b/scripts/tests/test_sync_version_mentions.py @@ -78,6 +78,23 @@ def test_root_plugin_manifest_follows_the_claude_version(tmp_path: Path) -> None assert "そろえた: plugins/playwright-kit/plugin.json" in got.stdout +def test_undeclared_root_plugin_manifest_stops_before_writing(tmp_path: Path) -> None: + # 同期の対象はリリースの設定の writes から読む。宣言に無いルートの plugin.json を書けば組み立てが writes の外として止まるので、書く前に止める + tree = _export(tmp_path) + config = tree / ".ndf" / "release.json" + settings = json.loads(config.read_text(encoding="utf-8")) + for step in settings["steps"]: + step["writes"] = [w for w in step["writes"] if w != "plugins/playwright-kit/plugin.json"] + config.write_text(json.dumps(settings), encoding="utf-8") + package = tree / "plugins/playwright-kit/plugin.json" + before = package.read_text(encoding="utf-8") + _bump(tree, "playwright-kit") + got = _run(tree) + assert got.returncode != 0 + assert "plugins/playwright-kit/plugin.json" in got.stderr + assert package.read_text(encoding="utf-8") == before + + def test_consistent_tree_is_left_alone(tmp_path: Path) -> None: tree = _export(tmp_path) got = _run(tree) From b479c7bd40588df9fc7b7ae148795cf21e0db889 Mon Sep 17 00:00:00 2001 From: "takemi.ohama" Date: Sun, 22 Nov 2026 00:40:26 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20=E3=83=AB=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=20plugin.json=20=E3=81=AE=E4=BA=8B=E5=89=8D=E6=A4=9C=E6=9F=BB?= =?UTF-8?q?=E3=82=92=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=82=8F=E3=82=8B=E3=83=91?= =?UTF-8?q?=E3=82=B9=E3=81=A0=E3=81=91=E3=81=AB=E7=B5=9E=E3=82=8A=E3=80=81?= =?UTF-8?q?assemble=20=E3=81=A8=E5=90=8C=E3=81=98=E6=AD=A3=E8=A6=8F?= =?UTF-8?q?=E5=8C=96=E3=81=A8=E9=85=8D=E4=B8=8B=E5=88=A4=E5=AE=9A=E3=81=A7?= =?UTF-8?q?=E7=85=A7=E3=82=89=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 書き換え後の本文をすべて作ってから検査し、通ったときだけ書く - ディレクトリの宣言(plugins/playwright-kit/ など)と ./ 付きの表記を受ける - 同期済みで書き換わらないルートの plugin.json には宣言を求めない - 宣言漏れのテストは設定とマニフェストだけの一時ツリーで sync_descriptions を直接呼ぶ(git archive と子プロセスを使わない) Co-Authored-By: Claude Opus 5.5 --- scripts/sync-version-mentions.py | 69 +++++++++++---------- scripts/tests/test_sync_version_mentions.py | 53 +++++++++++----- 2 files changed, 75 insertions(+), 47 deletions(-) diff --git a/scripts/sync-version-mentions.py b/scripts/sync-version-mentions.py index 9da92e526..6e6672677 100644 --- a/scripts/sync-version-mentions.py +++ b/scripts/sync-version-mentions.py @@ -5,7 +5,7 @@ `plugin.json` の `version` を上げた後に打つ。 - 各プラグインの `.claude-plugin/plugin.json`・`.codex-plugin/plugin.json`・ルートの `plugin.json`(`version` も。 - リリースの設定のこの手順の `writes` に書いたものだけ。無いものがあれば書く前に止める)と、`.claude-plugin/marketplace.json` の + 書き換わるものがリリースの設定のこの手順の `writes` の外なら、何も書く前に止める)と、`.claude-plugin/marketplace.json` の そのプラグインの description の `(vX.Y.Z)` を、Claude 版の `plugin.json` の `version` にそろえる (`scripts/lib/validate_manifests.py` が確かめる規則) - `scripts/check-doc-staleness.py` が「記載: <古い版>(L<行>) / <正本>: <新しい版>」と報告した行の版数だけを置き換える。 @@ -18,6 +18,7 @@ import argparse import json +import posixpath import re import subprocess import sys @@ -34,17 +35,13 @@ def sync_descriptions(root: Path) -> list[str]: - """description の版数を Claude 版の plugin.json の version にそろえ、書き換えたファイルを返す。""" - changed = set() + """description の版数を Claude 版の plugin.json の version にそろえ、書き換えたファイルを返す。 + + 書き換え後の本文をすべて作ってから、書き換わるルートの plugin.json が `writes` に入るかを確かめ、入らなければ何も書かずに止める + (書いた後に組み立てが writes の外として止まる前に止める)。""" + planned: dict[Path, str] = {} versions = {} - claudes = sorted(root.glob("plugins/**/.claude-plugin/plugin.json")) - packages = declared_packages(root) - undeclared = sorted( - rel for rel in (package_of(c).relative_to(root).as_posix() for c in claudes if package_of(c).is_file()) if rel not in packages - ) - if undeclared: # 書き換えた後に組み立てが writes の外として止まる前に、書く前に止める - raise SystemExit(f"ルートの plugin.json が {RELEASE_CONFIG} のこの手順の writes に無い: {', '.join(undeclared)}") - for claude in claudes: + for claude in sorted(root.glob("plugins/**/.claude-plugin/plugin.json")): manifest = json.loads(claude.read_text(encoding="utf-8")) version = manifest.get("version") if not isinstance(version, str): @@ -52,11 +49,11 @@ def sync_descriptions(root: Path) -> list[str]: if isinstance(manifest.get("name"), str): versions[manifest["name"]] = version for path in (claude, claude.parent.parent / ".codex-plugin" / "plugin.json"): - if path.is_file() and sync_manifest(path, version, follow_version=False): - changed.add(path.relative_to(root).as_posix()) + if path.is_file(): + plan_manifest(planned, path, version, follow_version=False) package = package_of(claude) # Agent Plugins package(ルートの plugin.json)は version も追う - if package.is_file() and sync_manifest(package, version, follow_version=True): - changed.add(package.relative_to(root).as_posix()) + if package.is_file(): + plan_manifest(planned, package, version, follow_version=True) market = root / ".claude-plugin" / "marketplace.json" if market.is_file(): text = market.read_text(encoding="utf-8") @@ -66,8 +63,15 @@ def sync_descriptions(root: Path) -> list[str]: if version is not None: fixed = replace_description_version(market, fixed, version, entry) if fixed != text: - market.write_text(fixed, encoding="utf-8") - changed.add(market.relative_to(root).as_posix()) + planned[market] = fixed + changed = {path.relative_to(root).as_posix(): text for path, text in planned.items()} + packages = {package_of(c).relative_to(root).as_posix() for c in root.glob("plugins/**/.claude-plugin/plugin.json")} + writes = declared_writes(root) + undeclared = sorted(rel for rel in changed if rel in packages and not covered(rel, writes)) + if undeclared: + raise SystemExit(f"ルートの plugin.json が {RELEASE_CONFIG} のこの手順の writes に無い: {', '.join(undeclared)}") + for path, text in planned.items(): + path.write_text(text, encoding="utf-8") return sorted(changed) @@ -75,25 +79,26 @@ def package_of(claude: Path) -> Path: return claude.parent.parent / "plugin.json" -def declared_packages(root: Path) -> set[str]: - """リリースの設定のうちこのスクリプトを打つ手順の `writes` から、ルートの plugin.json のパスを読む。 +def declared_writes(root: Path) -> list[str]: + """リリースの設定のうちこのスクリプトを打つ手順の `writes` を、組み立て(`assemble`)と同じ表記(`posixpath.normpath`)で返す。 - 組み立て(`assemble`)が書き換えてよいパスとして照らすのと同じ宣言を使う(同期の対象をここで別に持たない)。""" + 組み立てが書き換えてよいパスとして照らすのと同じ宣言を使う(同期の対象をここで別に持たない)。""" path = root / RELEASE_CONFIG if not path.is_file(): - return set() + return [] steps = json.loads(path.read_text(encoding="utf-8")).get("steps", []) mine = [s for s in steps if isinstance(s, dict) and any(str(a).endswith(SCRIPT_NAME) for a in s.get("command", []))] - writes = {Path(str(w)).as_posix().removeprefix("./") for s in mine for w in s.get("writes", [])} - return { - w - for w in writes - if w.startswith("plugins/") and w.endswith("/plugin.json") and "/.claude-plugin/" not in w and "/.codex-plugin/" not in w - } + return [posixpath.normpath(str(w)) for s in mine for w in s.get("writes", [])] + +def covered(rel: str, writes: list[str]) -> bool: + """組み立ての `_outside` と同じく、宣言のパスそのものか、その下のパスなら真(ディレクトリの宣言も受ける)。""" + return any(rel == w or rel.startswith(f"{w.rstrip('/')}/") for w in writes) -def sync_manifest(path: Path, version: str, *, follow_version: bool) -> bool: - """1 回読んで、description の版数(`follow_version` なら `version` も)をそろえ、変われば 1 回だけ書く(整形はそのまま保つ)。""" + +def plan_manifest(planned: dict[Path, str], path: Path, version: str, *, follow_version: bool) -> None: + """1 回読んで、description の版数(`follow_version` なら `version` も)をそろえた本文を、変わるときだけ `planned` へ入れる + (整形はそのまま保つ。書くのは検査の後)。""" text = path.read_text(encoding="utf-8") manifest = json.loads(text) fixed = text @@ -104,10 +109,8 @@ def sync_manifest(path: Path, version: str, *, follow_version: bool) -> bool: raise SystemExit(f"{path}: version の値を本文から見つけられない(整形の形が違う)") fixed = fixed.replace(literal, f'"version": {json.dumps(version)}', 1) fixed = replace_description_version(path, fixed, version, manifest) - if fixed == text: - return False - path.write_text(fixed, encoding="utf-8") - return True + if fixed != text: + planned[path] = fixed def replace_description_version(path: Path, text: str, version: str, owner: dict) -> str: diff --git a/scripts/tests/test_sync_version_mentions.py b/scripts/tests/test_sync_version_mentions.py index ce5570df4..c849aa1df 100644 --- a/scripts/tests/test_sync_version_mentions.py +++ b/scripts/tests/test_sync_version_mentions.py @@ -78,21 +78,46 @@ def test_root_plugin_manifest_follows_the_claude_version(tmp_path: Path) -> None assert "そろえた: plugins/playwright-kit/plugin.json" in got.stdout +def _mini_tree(tmp_path: Path, writes: list[str], *, root_version: str = "1.0.0") -> Path: + """設定と 1 つのプラグインのマニフェストだけの木(Claude 版は 1.0.1 へ上がった後、ルートの plugin.json は `root_version`)。""" + tree = tmp_path / "repo" + command = ["python3", "scripts/sync-version-mentions.py", "--root", "."] + files = { + ".ndf/release.json": {"steps": [{"name": "s", "stage": "production", "command": command, "writes": writes}]}, + "plugins/kit/.claude-plugin/plugin.json": {"name": "kit", "version": "1.0.1", "description": "説明 (v1.0.0)"}, + "plugins/kit/plugin.json": {"name": "kit", "version": root_version, "description": f"説明 (v{root_version})"}, + } + for rel, body in files.items(): + (tree / rel).parent.mkdir(parents=True, exist_ok=True) + (tree / rel).write_text(json.dumps(body, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") + return tree + + +def _texts(tree: Path) -> dict[str, str]: + return {p.relative_to(tree).as_posix(): p.read_text(encoding="utf-8") for p in sorted(tree.rglob("*.json"))} + + def test_undeclared_root_plugin_manifest_stops_before_writing(tmp_path: Path) -> None: - # 同期の対象はリリースの設定の writes から読む。宣言に無いルートの plugin.json を書けば組み立てが writes の外として止まるので、書く前に止める - tree = _export(tmp_path) - config = tree / ".ndf" / "release.json" - settings = json.loads(config.read_text(encoding="utf-8")) - for step in settings["steps"]: - step["writes"] = [w for w in step["writes"] if w != "plugins/playwright-kit/plugin.json"] - config.write_text(json.dumps(settings), encoding="utf-8") - package = tree / "plugins/playwright-kit/plugin.json" - before = package.read_text(encoding="utf-8") - _bump(tree, "playwright-kit") - got = _run(tree) - assert got.returncode != 0 - assert "plugins/playwright-kit/plugin.json" in got.stderr - assert package.read_text(encoding="utf-8") == before + # 同期の対象はリリースの設定の writes から読む。宣言に無いルートの plugin.json を書けば組み立てが writes の外として止まるので、 + # どのファイルも書く前に止める + tree = _mini_tree(tmp_path, ["README.md"]) + before = _texts(tree) + with pytest.raises(SystemExit, match="plugins/kit/plugin.json"): + _load().sync_descriptions(tree) + assert _texts(tree) == before + + +@pytest.mark.parametrize("writes", [["./plugins/kit/plugin.json"], ["plugins/kit/"], ["plugins"]]) +def test_root_plugin_manifest_declared_as_path_or_directory_is_synced(tmp_path: Path, writes: list[str]) -> None: + # 組み立てと同じく、表記を畳んだパスそのものか、宣言したディレクトリの下なら書いてよい + tree = _mini_tree(tmp_path, writes) + assert _load().sync_descriptions(tree) == ["plugins/kit/.claude-plugin/plugin.json", "plugins/kit/plugin.json"] + assert json.loads((tree / "plugins/kit/plugin.json").read_text(encoding="utf-8"))["version"] == "1.0.1" + + +def test_root_plugin_manifest_already_in_sync_needs_no_declaration(tmp_path: Path) -> None: + tree = _mini_tree(tmp_path, [], root_version="1.0.1") + assert _load().sync_descriptions(tree) == ["plugins/kit/.claude-plugin/plugin.json"] def test_consistent_tree_is_left_alone(tmp_path: Path) -> None: