mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 21:19:28 +08:00
feat(market): 专项复核支持安装范围内附加 Notice 的精确接受 (#330)
为 Class C 专项复核增加 `acceptedScopedNotice`,以便在**不放宽根许可证门禁、也不接受嵌套 LICENSE** 的前提下,审查并接受安装范围内已有 NOTICE 文件的附加变更。这是完成 [#310](https://github.com/desirecore/market/pull/310) 所必需的审核能力,本身不改任何技能 pin。 ## 安全边界 / Security boundaries 默认拒绝仍然成立。只有同时满足以下条件的嵌套 NOTICE 追加才会被接受: - 记录必须包含真实的 `reviewedBy`、`reviewedAt` 和非空 `notes`。 - `fromRef` / `toRef` 必须等于本次审核的旧/新完整 40 位 SHA,过期复核会被拒绝。 - `files` 必须恰好等于实际变更的 NOTICE 路径集合(不能多、不能少、不能重复)。 - 每个文件必须给出旧、新内容的 SHA-256,并与两次快照中的真实字节一致。 - 新文件必须是旧文件的严格前缀保留追加(`new.startswith(old)`)。丢掉原有声明的改写或前置插入即使哈希写对了也会被拒绝。 - 只允许非根路径的 NOTICE(例如 `skills/.../NOTICE`)。根目录 LICENSE/NOTICE/COPYING 仍走既有 `acceptedRootEvidenceSha256`。 - 嵌套 LICENSE/COPYING、删除、重命名、新建 NOTICE、通配符、路径逃逸(`..` / 绝对路径)、符号链接一律拒绝。 - `excludePaths` 仍然不能用来隐藏许可或 Notice 文件。 本变更不执行上游代码,不代表安全认证或运行验收。 ## 验证 / Validation - `uv run --with pytest --with jsonschema --with pyyaml python -m pytest scripts/catalog/test_audit_skill_update.py`:29 passed(含既有根 Notice 用例,以及附加 NOTICE 的正例和哈希/快照不匹配、缺理由、多余或不全路径、通配符、`..`、嵌套 LICENSE、删除、重命名、新建、前置插入、excludePaths、符号链接等反例) - `uv run --with pytest --with jsonschema --with pyyaml python -m pytest scripts/catalog/test_validate_catalog_metadata.py`:62 passed Automated source/license/metadata verification tooling only. No auto-merge of skill snapshot PRs in this change.
This commit is contained in:
1 parent
ff87cdace2
commit
8546cb641a
3 files changed
+340
-3
No files matched your search
@@ -42,6 +42,32 @@
|
|||||||
"description": "Exact set of new collection membership install paths when discovered children differ from the old entry. Must equal the discovered path set. Newly added members also require acceptedFrontmatterSha256 for that path.",
|
"description": "Exact set of new collection membership install paths when discovered children differ from the old entry. Must equal the discovered path set. Newly added members also require acceptedFrontmatterSha256 for that path.",
|
||||||
"items": { "type": "string", "minLength": 1 },
|
"items": { "type": "string", "minLength": 1 },
|
||||||
"uniqueItems": true
|
"uniqueItems": true
|
||||||
|
},
|
||||||
|
"acceptedScopedNotice": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Exact in-place additive NOTICE changes inside the install scope. LICENSE/COPYING, deletions, renames, new files, rewrites that drop existing bytes, globs, and root-level NOTICE (use acceptedRootEvidenceSha256) cannot be accepted here. fromRef/toRef must equal the audit's old and new snapshot SHAs, and files must be exactly the changed NOTICE paths with matching previous and new SHA-256 hashes.",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["fromRef", "toRef", "files"],
|
||||||
|
"properties": {
|
||||||
|
"fromRef": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
|
||||||
|
"toRef": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
|
||||||
|
"files": {
|
||||||
|
"type": "array",
|
||||||
|
"minItems": 1,
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["path", "previousSha256", "sha256"],
|
||||||
|
"properties": {
|
||||||
|
"path": { "type": "string", "minLength": 1 },
|
||||||
|
"previousSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
||||||
|
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"if": { "required": ["acceptedScopedNotice"] },
|
||||||
|
"then": { "required": ["reviewedBy", "reviewedAt", "notes"] }
|
||||||
}
|
}
|
||||||
@@ -134,6 +134,86 @@ def dependency_acceptance_key(identity: tuple) -> str:
|
|||||||
return identity[1]
|
return identity[1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def evidence_filename(path: str) -> str:
|
||||||
|
return PurePosixPath(path).name.upper()
|
||||||
|
|
||||||
|
|
||||||
|
def is_notice_filename(path: str) -> bool:
|
||||||
|
return evidence_filename(path).startswith('NOTICE')
|
||||||
|
|
||||||
|
|
||||||
|
def is_license_or_copying_filename(path: str) -> bool:
|
||||||
|
return evidence_filename(path).startswith(('LICENSE', 'COPYING'))
|
||||||
|
|
||||||
|
|
||||||
|
def _sha256_hex(value: object) -> bool:
|
||||||
|
return isinstance(value, str) and bool(re.fullmatch(r'[a-f0-9]{64}', value))
|
||||||
|
|
||||||
|
|
||||||
|
def accept_scoped_notice_changes(review: dict, repo: Path, old: str, new: str,
|
||||||
|
old_map: dict[str, str], new_map: dict[str, str]) -> None:
|
||||||
|
"""Accept only exact, additive, in-place NOTICE edits bound to this snapshot pair.
|
||||||
|
|
||||||
|
Nested LICENSE/COPYING changes, deletions, renames, new files, rewrites that
|
||||||
|
drop existing text, symlinks, path escape, globs, hash or ref mismatches,
|
||||||
|
and unexpected extra files remain rejected. Root LICENSE/NOTICE/COPYING stay
|
||||||
|
on acceptedRootEvidenceSha256.
|
||||||
|
"""
|
||||||
|
old_paths, new_paths = set(old_map), set(new_map)
|
||||||
|
if any(is_license_or_copying_filename(path) and old_map.get(path) != new_map.get(path)
|
||||||
|
for path in old_paths | new_paths):
|
||||||
|
raise AuditBlocked('安装范围内的许可证或 Notice 有变化,需专项复核')
|
||||||
|
if old_paths - new_paths or new_paths - old_paths:
|
||||||
|
raise AuditBlocked('安装范围内的许可证或 Notice 有变化,需专项复核')
|
||||||
|
changed = sorted(path for path in old_paths & new_paths if old_map[path] != new_map[path])
|
||||||
|
if not changed or any(not is_notice_filename(path) for path in changed):
|
||||||
|
raise AuditBlocked('安装范围内的许可证或 Notice 有变化,需专项复核')
|
||||||
|
|
||||||
|
accepted = review.get('acceptedScopedNotice')
|
||||||
|
if not isinstance(accepted, dict):
|
||||||
|
raise AuditBlocked('安装范围内的许可证或 Notice 有变化,需专项复核')
|
||||||
|
if not all(isinstance(review.get(key), str) and review[key].strip()
|
||||||
|
for key in ('reviewedBy', 'reviewedAt', 'notes')):
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核必须包含审核人、日期和理由')
|
||||||
|
if accepted.get('fromRef') != old or accepted.get('toRef') != new:
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核未绑定当前固定快照')
|
||||||
|
|
||||||
|
files = accepted.get('files')
|
||||||
|
if not isinstance(files, list) or not files:
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核文件列表无效')
|
||||||
|
|
||||||
|
seen: set[str] = set()
|
||||||
|
for item in files:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核文件列表无效')
|
||||||
|
raw_path = item.get('path')
|
||||||
|
if not isinstance(raw_path, str) or any(symbol in raw_path for symbol in '*?[]'):
|
||||||
|
raise AuditBlocked('嵌套 Notice 路径不安全')
|
||||||
|
path = safe_path(raw_path)
|
||||||
|
if path != raw_path or not path or is_license_or_copying_filename(path) or not is_notice_filename(path):
|
||||||
|
raise AuditBlocked('专项复核不能用于接受嵌套许可证变更或根路径 Notice')
|
||||||
|
if '/' not in path:
|
||||||
|
raise AuditBlocked('专项复核不能用于接受嵌套许可证变更或根路径 Notice')
|
||||||
|
if path in seen:
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核路径重复')
|
||||||
|
seen.add(path)
|
||||||
|
previous_digest, digest = item.get('previousSha256'), item.get('sha256')
|
||||||
|
if not _sha256_hex(previous_digest) or not _sha256_hex(digest):
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核哈希无效')
|
||||||
|
if path not in old_map or path not in new_map:
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核与实际变更文件不一致')
|
||||||
|
old_bytes, new_bytes = blob(repo, old, path), blob(repo, new, path)
|
||||||
|
if (old_map[path] != previous_digest or new_map[path] != digest
|
||||||
|
or hashlib.sha256(old_bytes).hexdigest() != previous_digest
|
||||||
|
or hashlib.sha256(new_bytes).hexdigest() != digest):
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核哈希不匹配')
|
||||||
|
if not old_bytes or not new_bytes or new_bytes == old_bytes or not new_bytes.startswith(old_bytes):
|
||||||
|
raise AuditBlocked('嵌套 Notice 变更未保留原有声明,不能作为附加 Notice 接受')
|
||||||
|
if seen != set(changed):
|
||||||
|
raise AuditBlocked('嵌套 Notice 专项复核与实际变更文件不一致')
|
||||||
|
|
||||||
|
|
||||||
def load_special_review(record) -> dict:
|
def load_special_review(record) -> dict:
|
||||||
if not record:
|
if not record:
|
||||||
return {}
|
return {}
|
||||||
@@ -231,9 +311,10 @@ def audit_snapshots(repo: Path, entry: dict, sidecar: dict, result: dict,
|
|||||||
return {path: hashlib.sha256(blob(repo, ref, path)).hexdigest()
|
return {path: hashlib.sha256(blob(repo, ref, path)).hexdigest()
|
||||||
for path in files if PurePosixPath(path).name.upper().startswith(('LICENSE', 'NOTICE', 'COPYING'))}
|
for path in files if PurePosixPath(path).name.upper().startswith(('LICENSE', 'NOTICE', 'COPYING'))}
|
||||||
scoped_licenses = scoped_evidence(old, old_files)
|
scoped_licenses = scoped_evidence(old, old_files)
|
||||||
if scoped_licenses != scoped_evidence(new, new_files):
|
new_scoped = scoped_evidence(new, new_files)
|
||||||
raise AuditBlocked('安装范围内的许可证或 Notice 有变化,需专项复核')
|
if scoped_licenses != new_scoped:
|
||||||
licenses.update(scoped_licenses)
|
accept_scoped_notice_changes(review, repo, old, new, scoped_licenses, new_scoped)
|
||||||
|
licenses.update(new_scoped)
|
||||||
accepted_root = review.get('acceptedRootEvidenceSha256') or {}
|
accepted_root = review.get('acceptedRootEvidenceSha256') or {}
|
||||||
for path in {compliance.get('licenseEvidencePath'), compliance.get('noticePath'),
|
for path in {compliance.get('licenseEvidencePath'), compliance.get('noticePath'),
|
||||||
governance.get('license', {}).get('evidencePath')} - {None}:
|
governance.get('license', {}).get('evidencePath')} - {None}:
|
||||||
@@ -380,6 +461,8 @@ def audit_snapshots(repo: Path, entry: dict, sidecar: dict, result: dict,
|
|||||||
report['limitations'].append('依赖清单或结构化简介如有变化,已按专项复核记录中的接受哈希核对,不代表这些字段与旧快照逐字节相同。')
|
report['limitations'].append('依赖清单或结构化简介如有变化,已按专项复核记录中的接受哈希核对,不代表这些字段与旧快照逐字节相同。')
|
||||||
if review.get('acceptedRootEvidenceSha256') or review.get('acceptedCollectionPaths'):
|
if review.get('acceptedRootEvidenceSha256') or review.get('acceptedCollectionPaths'):
|
||||||
report['limitations'].append('根许可证/Notice 或合集成员如有变化,已按专项复核记录中的接受哈希或路径集合核对,不代表与旧快照逐字节或成员集合相同。')
|
report['limitations'].append('根许可证/Notice 或合集成员如有变化,已按专项复核记录中的接受哈希或路径集合核对,不代表与旧快照逐字节或成员集合相同。')
|
||||||
|
if review.get('acceptedScopedNotice'):
|
||||||
|
report['limitations'].append('安装范围内的 Notice 如有变化,已按专项复核记录中绑定的快照、路径和哈希核对,且新文件必须完整保留旧 Notice 字节;不代表与旧快照逐字节相同,也不接受嵌套许可证变更。')
|
||||||
if exclude_paths:
|
if exclude_paths:
|
||||||
report['limitations'].append('excludePaths 只从本仓库的自动审核树遍历中省略路径;DesireCore 安装器在支持该字段前仍会从上游 pin 安装这些文件。')
|
report['limitations'].append('excludePaths 只从本仓库的自动审核树遍历中省略路径;DesireCore 安装器在支持该字段前仍会从上游 pin 安装这些文件。')
|
||||||
errors = validate_record(metadata, report)
|
errors = validate_record(metadata, report)
|
||||||
|
|||||||
@@ -320,6 +320,234 @@ class AuditTests(unittest.TestCase):
|
|||||||
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
||||||
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z', special_review=review)
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
|
||||||
|
def _scoped_notice_review(self, old, new, path, previous, current, **overrides):
|
||||||
|
review = {
|
||||||
|
'schemaVersion': 1,
|
||||||
|
'reviewedBy': 'mashagua',
|
||||||
|
'reviewedAt': '2026-11-22',
|
||||||
|
'notes': 'Accept an additive nested NOTICE that retains prior attribution.',
|
||||||
|
'acceptedScopedNotice': {
|
||||||
|
'fromRef': old,
|
||||||
|
'toRef': new,
|
||||||
|
'files': [{'path': path, 'previousSha256': previous, 'sha256': current}],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
review.update(overrides)
|
||||||
|
return review
|
||||||
|
|
||||||
|
def test_special_review_accepts_additive_scoped_notice(self):
|
||||||
|
import hashlib
|
||||||
|
path = 'skills/sample/NOTICE'
|
||||||
|
old_text = 'retained vendor attribution\n'
|
||||||
|
new_text = old_text + 'appended Unicode-3.0 notice\n'
|
||||||
|
self.write(path, old_text)
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
self.write(path, new_text)
|
||||||
|
new = self.commit()
|
||||||
|
previous = hashlib.sha256(old_text.encode()).hexdigest()
|
||||||
|
digest = hashlib.sha256(new_text.encode()).hexdigest()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z')
|
||||||
|
_, _, report = audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(self.old, new, path, previous, digest))
|
||||||
|
self.assertEqual(report['licenseEvidenceSha256'][path], digest)
|
||||||
|
self.assertTrue(any('安装范围内的 Notice' in item for item in report['limitations']))
|
||||||
|
|
||||||
|
def test_special_review_rejects_invalid_scoped_notice_changes(self):
|
||||||
|
import hashlib
|
||||||
|
path = 'skills/sample/NOTICE'
|
||||||
|
old_text = 'retained vendor attribution\n'
|
||||||
|
new_text = old_text + 'appended Unicode-3.0 notice\n'
|
||||||
|
rewrite = 'completely replaced notice, attribution dropped\n'
|
||||||
|
self.write(path, old_text)
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
previous = hashlib.sha256(old_text.encode()).hexdigest()
|
||||||
|
|
||||||
|
# Rewrite that drops existing attribution, even with matching hashes.
|
||||||
|
self.write(path, rewrite)
|
||||||
|
rewritten = self.commit()
|
||||||
|
rewrite_digest = hashlib.sha256(rewrite.encode()).hexdigest()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '未保留原有声明'):
|
||||||
|
audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': rewritten}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(self.old, rewritten, path, previous, rewrite_digest))
|
||||||
|
|
||||||
|
self.run_git('reset', '--hard', self.old); self.run_git('clean', '-fd')
|
||||||
|
self.write(path, new_text)
|
||||||
|
new = self.commit()
|
||||||
|
digest = hashlib.sha256(new_text.encode()).hexdigest()
|
||||||
|
valid = self._scoped_notice_review(self.old, new, path, previous, digest)
|
||||||
|
cases = [
|
||||||
|
('哈希不匹配', self._scoped_notice_review(self.old, new, path, previous, 'ab' * 32)),
|
||||||
|
('哈希不匹配', self._scoped_notice_review(self.old, new, path, 'cd' * 32, digest)),
|
||||||
|
('未绑定当前固定快照', self._scoped_notice_review('a' * 40, new, path, previous, digest)),
|
||||||
|
('未绑定当前固定快照', self._scoped_notice_review(self.old, 'b' * 40, path, previous, digest)),
|
||||||
|
('必须包含审核人、日期和理由', {**valid, 'reviewedBy': ' '}),
|
||||||
|
('必须包含审核人、日期和理由', {k: v for k, v in valid.items() if k != 'notes'}),
|
||||||
|
('与实际变更文件不一致', {**valid, 'acceptedScopedNotice': {
|
||||||
|
'fromRef': self.old, 'toRef': new,
|
||||||
|
'files': [
|
||||||
|
{'path': path, 'previousSha256': previous, 'sha256': digest},
|
||||||
|
{'path': 'skills/sample/extra/NOTICE', 'previousSha256': previous, 'sha256': digest},
|
||||||
|
],
|
||||||
|
}}),
|
||||||
|
('路径不安全', {**valid, 'acceptedScopedNotice': {
|
||||||
|
'fromRef': self.old, 'toRef': new,
|
||||||
|
'files': [{'path': 'skills/*/NOTICE', 'previousSha256': previous, 'sha256': digest}],
|
||||||
|
}}),
|
||||||
|
('路径不安全', {**valid, 'acceptedScopedNotice': {
|
||||||
|
'fromRef': self.old, 'toRef': new,
|
||||||
|
'files': [{'path': '../NOTICE', 'previousSha256': previous, 'sha256': digest}],
|
||||||
|
}}),
|
||||||
|
]
|
||||||
|
for pattern, review in cases:
|
||||||
|
with self.subTest(pattern=pattern):
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, pattern):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
|
||||||
|
'2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
def test_special_review_cannot_accept_scoped_license_or_notice_deletion(self):
|
||||||
|
import hashlib
|
||||||
|
license_path = 'skills/sample/vendor/LICENSE'
|
||||||
|
notice_path = 'skills/sample/NOTICE'
|
||||||
|
old_license = 'old vendor terms\n'
|
||||||
|
new_license = 'new vendor terms\n'
|
||||||
|
old_notice = 'retained vendor attribution\n'
|
||||||
|
new_notice = old_notice + 'appended note\n'
|
||||||
|
self.write(license_path, old_license)
|
||||||
|
self.write(notice_path, old_notice)
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
|
||||||
|
self.write(license_path, new_license)
|
||||||
|
new = self.commit()
|
||||||
|
review = self._scoped_notice_review(
|
||||||
|
self.old, new, license_path,
|
||||||
|
hashlib.sha256(old_license.encode()).hexdigest(),
|
||||||
|
hashlib.sha256(new_license.encode()).hexdigest())
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice|不能用于接受嵌套许可证'):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
|
||||||
|
'2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
self.run_git('reset', '--hard', self.old); self.run_git('clean', '-fd')
|
||||||
|
(self.repo / notice_path).unlink()
|
||||||
|
deleted = self.commit()
|
||||||
|
previous = hashlib.sha256(old_notice.encode()).hexdigest()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
||||||
|
audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': deleted}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(self.old, deleted, notice_path, previous, previous))
|
||||||
|
|
||||||
|
self.run_git('reset', '--hard', self.old); self.run_git('clean', '-fd')
|
||||||
|
(self.repo / notice_path).unlink()
|
||||||
|
self.write('skills/sample/docs/NOTICE', new_notice)
|
||||||
|
renamed = self.commit()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
||||||
|
audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': renamed}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(
|
||||||
|
self.old, renamed, 'skills/sample/docs/NOTICE',
|
||||||
|
hashlib.sha256(old_notice.encode()).hexdigest(),
|
||||||
|
hashlib.sha256(new_notice.encode()).hexdigest()))
|
||||||
|
|
||||||
|
def test_exclude_paths_still_cannot_hide_scoped_notice(self):
|
||||||
|
path = 'skills/sample/NOTICE'
|
||||||
|
self.write(path, 'old notice\n')
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
self.write(path, 'old notice\nappended\n')
|
||||||
|
new = self.commit()
|
||||||
|
review = {'schemaVersion': 1, 'excludePaths': [path], 'reviewedBy': 'mashagua',
|
||||||
|
'reviewedAt': '2026-11-22', 'notes': 'should not hide NOTICE'}
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '排除列表'):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
|
||||||
|
'2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
def test_symlink_scoped_notice_is_blocked_even_with_review(self):
|
||||||
|
path = 'skills/sample/NOTICE'
|
||||||
|
self.write(path, 'retained vendor attribution\n')
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
(self.repo / path).unlink()
|
||||||
|
(self.repo / path).symlink_to('SKILL.md')
|
||||||
|
new = self.commit()
|
||||||
|
review = self._scoped_notice_review(self.old, new, path, 'ab' * 32, 'cd' * 32)
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '符号链接'):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
|
||||||
|
'2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
def test_special_review_rejects_partial_or_new_file_scoped_notice(self):
|
||||||
|
import hashlib
|
||||||
|
first = 'skills/sample/NOTICE'
|
||||||
|
second = 'skills/sample/docs/NOTICE'
|
||||||
|
old_first = 'retained first attribution\n'
|
||||||
|
new_first = old_first + 'appended first\n'
|
||||||
|
old_second = 'retained second attribution\n'
|
||||||
|
new_second = old_second + 'appended second\n'
|
||||||
|
self.write(first, old_first)
|
||||||
|
self.write(second, old_second)
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
self.write(first, new_first)
|
||||||
|
self.write(second, new_second)
|
||||||
|
new = self.commit()
|
||||||
|
review = self._scoped_notice_review(
|
||||||
|
self.old, new, first,
|
||||||
|
hashlib.sha256(old_first.encode()).hexdigest(),
|
||||||
|
hashlib.sha256(new_first.encode()).hexdigest())
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '与实际变更文件不一致'):
|
||||||
|
audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new},
|
||||||
|
'2026-10-31T01:02:03Z', special_review=review)
|
||||||
|
|
||||||
|
self.run_git('reset', '--hard', self.old); self.run_git('clean', '-fd')
|
||||||
|
created = 'skills/sample/vendor/NOTICE'
|
||||||
|
created_text = 'brand new notice\n'
|
||||||
|
self.write(created, created_text)
|
||||||
|
created_ref = self.commit()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '许可证|Notice'):
|
||||||
|
audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': created_ref}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(
|
||||||
|
self.old, created_ref, created,
|
||||||
|
hashlib.sha256(b'').hexdigest(),
|
||||||
|
hashlib.sha256(created_text.encode()).hexdigest()))
|
||||||
|
|
||||||
|
def test_special_review_rejects_prepended_scoped_notice(self):
|
||||||
|
import hashlib
|
||||||
|
path = 'skills/sample/NOTICE'
|
||||||
|
old_text = 'retained vendor attribution\n'
|
||||||
|
prepended = 'new preface\n' + old_text
|
||||||
|
self.write(path, old_text)
|
||||||
|
self.old = self.commit()
|
||||||
|
self.entry['source']['ref'] = self.old
|
||||||
|
self.metadata['provenance']['content']['ref'] = self.old
|
||||||
|
self.metadata['governance']['compliance']['reviewedRef'] = self.old
|
||||||
|
self.write(path, prepended)
|
||||||
|
new = self.commit()
|
||||||
|
with self.assertRaisesRegex(AuditBlocked, '未保留原有声明'):
|
||||||
|
audit_snapshots(
|
||||||
|
self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z',
|
||||||
|
special_review=self._scoped_notice_review(
|
||||||
|
self.old, new, path,
|
||||||
|
hashlib.sha256(old_text.encode()).hexdigest(),
|
||||||
|
hashlib.sha256(prepended.encode()).hexdigest()))
|
||||||
|
|
||||||
def test_disallows_non_github_fetch_targets(self):
|
def test_disallows_non_github_fetch_targets(self):
|
||||||
self.entry['source']['repoUrl'] = 'file:///private/source'
|
self.entry['source']['repoUrl'] = 'file:///private/source'
|
||||||
with self.assertRaisesRegex(AuditBlocked, 'HTTPS'): audit_update(self.entry, self.metadata, {})
|
with self.assertRaisesRegex(AuditBlocked, 'HTTPS'): audit_update(self.entry, self.metadata, {})
|
||||||
|
|||||||
Reference in new issue
Block a user