fix(market): 独立技能许可证回读绑定已验证客户端 / Bind standalone notice evidence (#379)

Market 审计区分独立技能与合集安装。独立 Git 子目录只认客户端 #6429 合入 dev 的精确提交 85fba4abf4c60c5704557b2c76568a3da3323967 和 tree 4e38063a01a6d8b9e7b7fc549bbc2716b7d45a81,回读仍须绑定上游完整 pin、路径、根通知哈希和回读时间。保留合集 #6426 的实现与既有记录;两种路径的实施证明不可混用。

Separate standalone Git-subdirectory evidence from collection-child evidence. Only the verified standalone client commit/tree is eligible for that route. An exact upstream pin, scope, notice hash and readback time remain required; the collection entry and receipts are unchanged.

This is source implementation provenance only, not a release or install acceptance, and does not change catalog state, source pins, or receipts.
This commit is contained in:
mashagua authored and GitHub committed 2026-11-28 09:07:20 +08:00
1 parent a2ccfdda9f
commit f8e69321eb
4 files changed
+58 -16

No files matched your search

+21 -6
View File
@@ -191,10 +191,17 @@ def _sha256_hex(value: object) -> bool:
# root LICENSE/NOTICE/COPYING files after verifying the selected child tree.
# This is not a license exception. A later descendant tip is not accepted
# automatically; add a newly verified implementation commit explicitly.
CLIENT_ATTACHED_NOTICE_IMPLEMENTATIONS = {
CLIENT_COLLECTION_NOTICE_IMPLEMENTATIONS = {
'28128a15b3abd76e1529b983ca8a921bdfe9ff30': 'e8c1321e6a098eb905f4646b2027bc7b2259ca6b',
}
# desirecore/desirecore#6429 (squashed into dev): the standalone Git-subdirectory
# path copies the exact catalog-evidenced notice and records it in the lock.
# This is source-implementation provenance, not a released-package or install receipt.
CLIENT_STANDALONE_NOTICE_IMPLEMENTATIONS = {
'85fba4abf4c60c5704557b2c76568a3da3323967': '4e38063a01a6d8b9e7b7fc549bbc2716b7d45a81',
}
ROOT_NOTICE_NAME_PREFIXES = ('LICENSE', 'LICENCE', 'NOTICE', 'COPYING')
@@ -226,7 +233,7 @@ def root_regular_file_sha256(repo: Path, ref: str, path: str) -> str:
def accept_client_attached_notices(review: dict, repo: Path, new: str, install_scopes: list[str],
grant: bytes, license_value: str | None) -> set[str]:
grant: bytes, license_value: str | None, *, is_collection: bool) -> set[str]:
"""Return install scopes proven by bound client attach + install readback.
Absent field: empty set. Present but invalid: AuditBlocked. The acceptance is
@@ -253,9 +260,16 @@ def accept_client_attached_notices(review: dict, repo: Path, new: str, install_s
raise AuditBlocked('客户端附加通知专项复核未绑定当前固定快照')
if not isinstance(client_commit, str) or not re.fullmatch(r'[0-9a-f]{40}', client_commit):
raise AuditBlocked('客户端附加通知专项复核的客户端提交无效')
if client_commit not in CLIENT_ATTACHED_NOTICE_IMPLEMENTATIONS:
raise AuditBlocked('客户端附加通知专项复核的客户端提交不在已核验实现清单中')
expected_tree = CLIENT_ATTACHED_NOTICE_IMPLEMENTATIONS[client_commit]
implementations = (CLIENT_COLLECTION_NOTICE_IMPLEMENTATIONS if is_collection
else CLIENT_STANDALONE_NOTICE_IMPLEMENTATIONS)
expected_tree = implementations.get(client_commit)
if expected_tree is None:
raise AuditBlocked('客户端附加通知专项复核的客户端提交不在已核验实现清单中(安装类型不匹配或提交未核验)')
if not is_collection:
if len(install_scopes) != 1 or not safe_path(install_scopes[0]):
raise AuditBlocked('独立技能附加通知专项复核必须绑定单个 Git 子目录')
if client_tree is None or observed_at is None:
raise AuditBlocked('独立技能附加通知专项复核需要客户端 tree 和回读时间')
if client_tree is not None and (not isinstance(client_tree, str)
or not re.fullmatch(r'[0-9a-f]{40}', client_tree)
or client_tree != expected_tree):
@@ -644,7 +658,8 @@ def _audit_snapshots(repo: Path, entry: dict, sidecar: dict, result: dict,
grant = blob(repo, new, evidence_path) if evidence_path else b''
accept_client_attached_notices(
review, repo, new, paths, grant,
(sidecar.get('governance', {}).get('license') or {}).get('value'))
(sidecar.get('governance', {}).get('license') or {}).get('value'),
is_collection=bool(entry.get('children')))
if review.get('acceptedDescriptionAndLocales'):
accept_description_and_locales(review, entry, sidecar, repo, old, new, paths)
if old_root != new_root:
+17 -6
View File
@@ -565,7 +565,7 @@ class AuditTests(unittest.TestCase):
self.metadata['provenance']['content']['ref'] = sha
self.metadata['governance']['compliance']['reviewedRef'] = sha
def _client_attach_review(self, new, scopes, notice_sha, **overrides):
def _client_attach_review(self, new, scopes, notice_sha, *, is_collection=False, **overrides):
review = {
'schemaVersion': 1,
'reviewedBy': 'mashagua',
@@ -573,8 +573,10 @@ class AuditTests(unittest.TestCase):
'notes': 'Install-copy readback of verified client root-notice attach for this pin.',
'acceptedClientAttachedNotices': {
'sourceRef': new,
'clientCommit': '28128a15b3abd76e1529b983ca8a921bdfe9ff30',
'clientTree': 'e8c1321e6a098eb905f4646b2027bc7b2259ca6b',
'clientCommit': '28128a15b3abd76e1529b983ca8a921bdfe9ff30' if is_collection
else '85fba4abf4c60c5704557b2c76568a3da3323967',
'clientTree': 'e8c1321e6a098eb905f4646b2027bc7b2259ca6b' if is_collection
else '4e38063a01a6d8b9e7b7fc549bbc2716b7d45a81',
'observedAt': '2026-11-26T16:04:23Z',
'noticeRootPath': 'LICENSE',
'noticeSha256': notice_sha,
@@ -724,15 +726,19 @@ class AuditTests(unittest.TestCase):
self.write('skills/sample/scripts/tool.py', 'print("new fixture")\n')
notice_sha = hashlib.sha256((self.repo / 'LICENSE').read_bytes()).hexdigest()
new = self.commit()
valid = self._client_attach_review(new, ['skills/sample'], notice_sha)
cases = [
('未绑定当前固定快照', {'acceptedClientAttachedNotices': {'sourceRef': self.old}}),
('未绑定当前固定快照', {'acceptedClientAttachedNotices': {'sourceRef': 'a' * 40}}),
('不在已核验实现清单中', {'acceptedClientAttachedNotices': {'clientCommit': 'a' * 40}}),
('安装类型不匹配', self._client_attach_review(
new, ['skills/sample'], notice_sha, is_collection=True)),
('需要客户端 tree 和回读时间', {'acceptedClientAttachedNotices': {'clientTree': None}}),
('需要客户端 tree 和回读时间', {'acceptedClientAttachedNotices': {'observedAt': None}}),
('客户端提交无效', {'acceptedClientAttachedNotices': {'clientCommit': '28128a15'}}),
('客户端 tree 与已核验实现不一致', {'acceptedClientAttachedNotices': {'clientTree': 'a' * 40}}),
('根通知哈希与当前快照不一致', {'acceptedClientAttachedNotices': {'noticeSha256': 'b' * 64}}),
('缺少子项安装回读', {'acceptedClientAttachedNotices': {'scopes': []}}),
('与安装范围不一致', self._client_attach_review(new, ['skills/another'], notice_sha)),
('必须包含审核人、日期和理由', {'notes': ''}),
('必须包含审核人、日期和理由', {'reviewedBy': ''}),
]
@@ -762,10 +768,15 @@ class AuditTests(unittest.TestCase):
self.write('skills/sample/scripts/tool.py', 'print("new fixture")\n')
notice_sha = hashlib.sha256((self.repo / 'LICENSE').read_bytes()).hexdigest()
new = self.commit()
complete = self._client_attach_review(new, ['skills/sample', 'skills/another'], notice_sha)
complete = self._client_attach_review(new, ['skills/sample', 'skills/another'], notice_sha,
is_collection=True)
wrong_mode = self._client_attach_review(new, ['skills/sample', 'skills/another'], notice_sha)
with self.assertRaisesRegex(AuditBlocked, '安装类型不匹配'):
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
'2026-10-31T01:02:03Z', special_review=wrong_mode)
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
'2026-10-31T01:02:03Z', special_review=complete)
partial = self._client_attach_review(new, ['skills/sample'], notice_sha)
partial = self._client_attach_review(new, ['skills/sample'], notice_sha, is_collection=True)
with self.assertRaisesRegex(AuditBlocked, '缺少子项安装回读|与安装范围不一致'):
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
'2026-10-31T01:02:03Z', special_review=partial)
+19 -3
View File
@@ -350,8 +350,8 @@ def _client_attach_review(case, new, scopes, notice_sha):
'notes': 'Install-copy readback of verified client root-notice attach for this pin.',
'acceptedClientAttachedNotices': {
'sourceRef': new,
'clientCommit': '28128a15b3abd76e1529b983ca8a921bdfe9ff30',
'clientTree': 'e8c1321e6a098eb905f4646b2027bc7b2259ca6b',
'clientCommit': '85fba4abf4c60c5704557b2c76568a3da3323967',
'clientTree': '4e38063a01a6d8b9e7b7fc549bbc2716b7d45a81',
'observedAt': '2026-11-26T16:04:23Z',
'noticeRootPath': 'LICENSE',
'noticeSha256': notice_sha,
@@ -376,13 +376,29 @@ def test_client_attached_notice_readback_is_info_not_blocked(case):
rows = inspect_snapshots(case.repo, case.entry, case.metadata, {'ref': case.old, 'head': new}, review)
row = next(r for r in rows if r['gate']=='installed-project-notice')
assert row['state']=='info'
assert row['evidence']['clientCommit']=='28128a15b3abd76e1529b983ca8a921bdfe9ff30'
assert row['evidence']['clientCommit']=='85fba4abf4c60c5704557b2c76568a3da3323967'
assert not any(r['gate']=='installed-project-notice' and r['state']=='blocked' for r in rows)
_,_,receipt = audit_snapshots(case.repo, case.entry, case.metadata, {'ref': case.old, 'head': new},
'2026-10-31T01:02:03Z', special_review=review)
assert receipt['source']['ref']==new
def test_collection_client_cannot_attest_standalone_notice(case):
import hashlib
(case.repo/'skills/sample/LICENSE').unlink()
baseline(case)
case.write('skills/sample/scripts/tool.py', 'new')
new = case.commit()
notice_sha = hashlib.sha256((case.repo/'LICENSE').read_bytes()).hexdigest()
review = _client_attach_review(case, new, ['skills/sample'], notice_sha)
review['acceptedClientAttachedNotices'].update(
clientCommit='28128a15b3abd76e1529b983ca8a921bdfe9ff30',
clientTree='e8c1321e6a098eb905f4646b2027bc7b2259ca6b')
rows = inspect_snapshots(case.repo, case.entry, case.metadata, {'ref': case.old, 'head': new}, review)
assert any(r['gate']=='client-attached-notice' and r['state']=='blocked' for r in rows)
assert any(r['gate']=='installed-project-notice' and r['state']=='blocked' for r in rows)
def test_wrong_pin_client_attach_review_does_not_deliver(case):
import hashlib
(case.repo/'skills/sample/LICENSE').unlink()
+1 -1
View File
@@ -85,7 +85,7 @@ def inspect_snapshots(repo, entry, metadata, result, special_review=None):
if review.get('acceptedClientAttachedNotices'):
try:
attached_scopes = accept_client_attached_notices(
review, repo, new, scopes, grants[new], license_value)
review, repo, new, scopes, grants[new], license_value, is_collection=bool(entry.get('children')))
except AuditBlocked as error:
add('.', 'client-attached-notice', 'blocked', 'introduced',
'专项复核的客户端附加通知证据无效或未绑定当前 pin。 / Client-attached notice special review is invalid or not bound to this pin.',