Skip to content

Commit 54d561b

Browse files
author
PartMe
committed
fix: preserve Windows snapshot bytes and align plugin versions
1 parent 1d285f5 commit 54d561b

8 files changed

Lines changed: 122 additions & 5 deletions

‎.gitattributes‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Frozen snapshot identities are byte hashes; never rewrite checkout newlines.
2+
skills/** -text
3+
profiles/** -text
4+
sources.json -text

‎docs/xml-native-guard-acceptance.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ No remote protection or universal local merge guarantee is claimed. Native hooks
7676
Candidate plugin 229f3d2 / engine 0641d67 ran remotely after explicit approval: Linux and macOS passed; Windows exposed strict-default-encoding fixture/package errors and CPython 3.12 path/descriptor ctime disagreement. These failures are retained, not reclassified as skips.
7777

7878
The compatibility repair normalizes only Windows path-versus-descriptor comparison (device/inode/size/mtime/birthtime); full descriptor-before/after and pathname-before/after signatures retain ctime. Reparse/type/link-count/resource checks remain. Strict UTF-8 package reads and native diagnostic captures remove dependence on the Windows ANSI locale. Semantic-mismatch regression failed before the fix. Local complete regression after the fix: **242 tests, 225 passed, 17 existing Windows skips**. Independent review passed XML15 + encoding/diagnostics9 + native hooks12. Native candidate CI on the new paired commits is required; simulations are not native Windows evidence.
79+
80+
### Packaging and registry consistency
81+
Native Windows additionally exposed snapshot path separators and checkout newline conversion. Snapshot keys now use POSIX spelling, and narrowly scoped Git attributes preserve the original frozen bytes; hashes and the 90-file lock are unchanged. A real autocrlf=true checkout with an unprotected CRLF control verifies every frozen byte/hash. All local plugin manifests, DSH metadata, local marketplace entry and runtime version are 0.4.0; the validator rejects drift, including nested local marketplace entries. No tag or release was created. Latest workflow conclusions are recorded separately against immutable paired SHAs.

‎dsh/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitflow",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "按项目约定治理 Git 分支、提交与流转,九技能加确定性门禁",
55
"type": "module",
66
"main": "lib/index.js",

‎marketplace.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "gitflow",
99
"source": "./",
1010
"description": "按项目约定治理 Git 分支、提交与流转,九技能加确定性门禁",
11-
"version": "0.3.0"
11+
"version": "0.4.0"
1212
}
1313
]
1414
}

‎scripts/validate_package.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,35 @@
1111
from gitflow.policy import validate
1212
from vendor_skills import files
1313

14+
VERSION_MANIFESTS = ('package.json', 'dsh/package.json', 'kimi.plugin.json',
15+
'.claude-plugin/plugin.json', '.codex-plugin/plugin.json',
16+
'.zcode-plugin/plugin.json')
17+
18+
19+
def version_errors(root, expected):
20+
errors = []
21+
for relative in VERSION_MANIFESTS:
22+
data = json.loads((root / relative).read_text(encoding='utf-8'))
23+
if data.get('version') != expected:
24+
errors.append('Plugin version mismatch: ' + relative)
25+
marketplace = json.loads((root / 'marketplace.json').read_text(encoding='utf-8'))
26+
for entry in marketplace.get('plugins', []):
27+
if entry.get('source') in ('.', './') and entry.get('version') != expected:
28+
errors.append('Plugin version mismatch: marketplace.json local entry')
29+
module = ast.parse((root / 'scripts/gitflow/git.py').read_text(encoding='utf-8'))
30+
versions = [ast.literal_eval(node.value) for node in module.body
31+
if isinstance(node, ast.Assign) and any(isinstance(t, ast.Name) and t.id == 'VERSION' for t in node.targets)]
32+
if versions != [expected]:
33+
errors.append('Plugin version mismatch: runtime')
34+
return errors
35+
36+
1437
def validate_package():
1538
errors=[]
1639
for file in ROOT.rglob('*'):
1740
if file.is_symlink() and not file.resolve().is_relative_to(ROOT):errors.append('路径越界 '+str(file))
1841
manifest=json.loads((ROOT/'plugin.json').read_text(encoding='utf-8'))
42+
errors.extend(version_errors(ROOT, manifest['version']))
1943
allowed={'$schema','name','version','description','author','homepage','repository','license','keywords','extensions'}
2044
if set(manifest)-allowed or manifest['$schema']!='https://agent-plugins.org/schemas/1.0.0/plugin.schema.json':errors.append('manifest 字段/版本')
2145
if not re.fullmatch(r'(?!.*(--|\.\.))[a-z0-9][a-z0-9.-]{0,62}[a-z0-9]|[a-z0-9]',manifest['name']):errors.append('manifest 名称')

‎scripts/vendor_skills.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def files(root):
1414
for file in sorted((root/directory).rglob('*')):
1515
if '__pycache__' in file.parts:continue
1616
if file.is_symlink():raise ValueError('snapshot symlink')
17-
if file.is_file():result[str(file.relative_to(root))]=hashlib.sha256(file.read_bytes()).hexdigest()
17+
if file.is_file():result[file.relative_to(root).as_posix()]=hashlib.sha256(file.read_bytes()).hexdigest()
1818
result['sources.json']=hashlib.sha256((root/'sources.json').read_bytes()).hexdigest()
1919
return result
2020

@@ -25,7 +25,7 @@ def files(root):
2525
args=parser.parse_args()
2626
lock=ROOT/'skills.lock.json'
2727
if args.check:
28-
expected=json.loads(lock.read_text())
28+
expected=json.loads(lock.read_text(encoding='utf-8'))
2929
if files(ROOT)!=expected['files']:raise SystemExit('技能或模板快照被修改,请重新审阅和锁定。')
3030
if args.source and files(args.source)!=expected['files']:raise SystemExit('上游技能发生漂移,不能冒充当前快照。')
3131
print(json.dumps({'decision':'allow','files':len(expected['files'])}))
@@ -36,5 +36,5 @@ def files(root):
3636
if (ROOT/directory).exists():shutil.rmtree(ROOT/directory)
3737
shutil.copytree(source/directory,ROOT/directory,ignore=shutil.ignore_patterns('__pycache__','*.pyc'))
3838
shutil.copyfile(source/'sources.json',ROOT/'sources.json')
39-
lock.write_text(json.dumps({'schema_version':'1.0.0','source_package':'full-stack-skills/git-skills','source_version':json.loads((source/'.claude-plugin/plugin.json').read_text())['version'],'files':files(ROOT)},ensure_ascii=False,sort_keys=True,indent=2)+'\n')
39+
lock.write_text(json.dumps({'schema_version':'1.0.0','source_package':'full-stack-skills/git-skills','source_version':json.loads((source/'.claude-plugin/plugin.json').read_text(encoding='utf-8'))['version'],'files':files(ROOT)},ensure_ascii=False,sort_keys=True,indent=2)+'\n',encoding='utf-8')
4040
print(json.dumps({'decision':'applied','files':len(files(ROOT))}))

‎tests/test_xml_diagnostics.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,29 @@ def test_validator_reads_real_package_with_cp1252_default(self):
8484
from validate_package import validate_package
8585
with cp1252_default_text_files():
8686
self.assertEqual(validate_package(), [])
87+
88+
class PackageVersionTests(unittest.TestCase):
89+
def test_every_wrapper_and_runtime_share_version(self):
90+
import json
91+
from validate_package import version_errors
92+
expected=json.loads((ROOT/'plugin.json').read_text(encoding='utf-8'))['version']
93+
self.assertEqual(version_errors(ROOT,expected),[])
94+
95+
def test_stale_manifest_version_is_rejected(self):
96+
import json
97+
import tempfile
98+
from pathlib import Path
99+
from validate_package import VERSION_MANIFESTS,version_errors
100+
with tempfile.TemporaryDirectory() as tmp:
101+
root=Path(tmp)
102+
for name in VERSION_MANIFESTS:
103+
target=root/name;target.parent.mkdir(parents=True,exist_ok=True)
104+
target.write_text(json.dumps({'version':'0.4.0'}),encoding='utf-8')
105+
(root/'marketplace.json').write_text(json.dumps({'plugins':[{'source':'./','version':'0.4.0'}]}),encoding='utf-8')
106+
runtime=root/'scripts/gitflow/git.py';runtime.parent.mkdir(parents=True)
107+
runtime.write_text("VERSION = '0.4.0'\n",encoding='utf-8')
108+
(root/'dsh/package.json').write_text('{"version":"0.3.0"}',encoding='utf-8')
109+
self.assertEqual(version_errors(root,'0.4.0'),['Plugin version mismatch: dsh/package.json'])
110+
(root/'dsh/package.json').write_text('{"version":"0.4.0"}',encoding='utf-8')
111+
(root/'marketplace.json').write_text(json.dumps({'plugins':[{'source':'./','version':'0.3.0'},{'source':'elsewhere','version':'unrelated'}]}),encoding='utf-8')
112+
self.assertEqual(version_errors(root,'0.4.0'),['Plugin version mismatch: marketplace.json local entry'])

‎tests/test_xml_snapshot.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Frozen snapshots retain byte identities and POSIX lock keys across checkouts."""
2+
import hashlib
3+
import json
4+
import os
5+
from pathlib import Path, PureWindowsPath
6+
import shutil
7+
import subprocess
8+
import sys
9+
import tempfile
10+
import unittest
11+
from unittest.mock import patch
12+
13+
ROOT = Path(__file__).resolve().parents[1]
14+
sys.path.insert(0, str(ROOT / 'scripts'))
15+
from vendor_skills import files
16+
17+
18+
class SnapshotPortabilityTests(unittest.TestCase):
19+
def test_windows_relative_paths_use_posix_lock_keys(self):
20+
# Keep actual enumeration and hashing; simulate only Windows path spelling
21+
# so this platform-dependent failure is reproducible on Linux as well.
22+
relative_to = Path.relative_to
23+
def windows_relative(path, *other, **kwargs):
24+
relative = relative_to(path, *other, **kwargs)
25+
return PureWindowsPath(*relative.parts)
26+
expected = json.loads((ROOT / 'skills.lock.json').read_text(encoding='utf-8'))['files']
27+
with patch.object(Path, 'relative_to', new=windows_relative):
28+
observed = files(ROOT)
29+
self.assertEqual(observed, expected)
30+
self.assertTrue(all('\\' not in key for key in observed))
31+
32+
def test_autocrlf_checkout_preserves_exact_frozen_bytes(self):
33+
env = {**os.environ, 'GIT_CONFIG_NOSYSTEM': '1', 'GIT_CONFIG_GLOBAL': os.devnull}
34+
with tempfile.TemporaryDirectory(prefix='snapshot-checkout-') as temp:
35+
source = Path(temp) / 'source';source.mkdir()
36+
checkout = Path(temp) / 'checkout'
37+
for directory in ('skills', 'profiles'):
38+
shutil.copytree(ROOT / directory, source / directory, ignore=shutil.ignore_patterns('__pycache__', '*.pyc'))
39+
for name in ('sources.json', 'skills.lock.json'):
40+
shutil.copyfile(ROOT / name, source / name)
41+
if (ROOT / '.gitattributes').exists():
42+
shutil.copyfile(ROOT / '.gitattributes', source / '.gitattributes')
43+
(source / 'unprotected.txt').write_bytes(b'one\ntwo\n')
44+
def git(*args, cwd=source):
45+
result = subprocess.run(['git', '-C', str(cwd), *map(str, args)], env=env, capture_output=True, timeout=30)
46+
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
47+
return result.stdout
48+
git('init', '-b', 'main')
49+
git('config', 'core.autocrlf', 'false')
50+
git('add', '.')
51+
git('-c', 'user.name=Fixture', '-c', '[email protected]', 'commit', '-m', 'snapshot fixture')
52+
git('-c', 'core.autocrlf=true', 'clone', '--no-local', source, checkout)
53+
# Control confirms the checkout actually converted ordinary text.
54+
self.assertEqual((checkout / 'unprotected.txt').read_bytes(), b'one\r\ntwo\r\n')
55+
expected = json.loads((source / 'skills.lock.json').read_text(encoding='utf-8'))['files']
56+
self.assertEqual(files(checkout), expected)
57+
for relative, digest in expected.items():
58+
with self.subTest(path=relative):
59+
self.assertEqual((checkout / relative).read_bytes(), (source / relative).read_bytes())
60+
self.assertEqual(hashlib.sha256((checkout / relative).read_bytes()).hexdigest(), digest)

0 commit comments

Comments
 (0)