merge: 同步 main 并改用已合入的作者契约

main 已在 #16 合入受主仓固定的 4.3 作者 Schema(95afcff…)和校验逻辑,因此保留其字节,不再引入本分支的候选 Schema(29ece0b…)。

- 删除 application-release-contract.mjs:它要求所有条目声明 definitionPath,会拒绝已上架的 definitionSource: manifest 条目;其余检查 main 已覆盖,仅把 definitionPath 规范路径检查移入 application-contract.mjs。
- 保留 webBundles 统计,并在 authored-release 测试样本中声明,与客户端 checkout 校验一致。
- 测试不再写死条目数,并增加 CLI 校验入口与作者 Schema 摘要断言。
- README 合并到现有作者契约章节,移除已过时的候选说明。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yigeandClaude Opus 5.5 committed 2026-11-03 09:52:40 +08:00
commit 80e0ff0355
38 files changed
+2240 -82

No files matched your search

+35 -1
View File
@@ -1,7 +1,35 @@
import { isApplicationEntry, isAuthoredRegistryEntry } from './entry-schema.mjs'
/** 发布者关系声明的跨字段检查;不推导安装、权限或运行时健康。 */
export function validateApplicationContract(manifest) {
if (!['docker-app', 'native-app', 'artifact', 'web-bundle'].includes(manifest.type)) return []
if (!isApplicationEntry(manifest) && !isAuthoredRegistryEntry(manifest)) return []
const errors = []
if (isAuthoredRegistryEntry(manifest)) {
if (!['web-bundle', 'native-app', 'docker-app'].includes(manifest.type)) errors.push('appRelease: unsupported delivery type')
const required = manifest.appRelease?.requiredCapabilities
if (!Array.isArray(required) || !required.includes('release') || (manifest.type === 'web-bundle' && !required.includes('web-bundle'))) {
errors.push('appRelease: delivery capability handshake required')
}
const images = manifest.appRelease?.imageRefs
// 镜像语法由严格 Schema 校验;端口范围属于同一跨字段合同。
if (manifest.type === 'docker-app' && (!Array.isArray(images) || images.length === 0 || images.some(image =>
typeof image !== 'string' || Number(image.split('/')[0].split(':')[1] ?? 0) > 65535))) errors.push('appRelease: Docker images must be pinned by digest')
if (manifest.type !== 'docker-app' && images !== undefined) errors.push('appRelease: imageRefs belongs only to Docker release')
const source = manifest.source
if (!source || !['git', 'release'].includes(source.kind) ||
typeof source.ref !== 'string' || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(source.ref) ||
typeof source.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(source.sha256)) {
errors.push('source: authored release requires immutable commit and archive sha256')
}
try {
const url = new URL(String(source?.url))
if (url.protocol !== 'https:' || url.username || url.password || url.hash || url.search) errors.push('source: credential-free fixed HTTPS URL required')
} catch { errors.push('source: invalid URL') }
if (source?.kind === 'git' && (typeof source.path !== 'string' || !isPortablePath(source.path))) errors.push('source: git archive path must be canonical and relative')
// 内联定义不声明 definitionPath;声明时才要求规范相对路径。
const definitionPath = manifest.appRelease?.definitionPath
if (definitionPath !== undefined && (typeof definitionPath !== 'string' || !isPortablePath(definitionPath))) errors.push('appRelease: definitionPath must be canonical and relative')
}
const ids = new Set()
for (const entrypoint of Array.isArray(manifest.entrypoints) ? manifest.entrypoints : []) {
if (!entrypoint || typeof entrypoint !== 'object') continue
@@ -18,3 +46,9 @@ export function validateApplicationContract(manifest) {
}
return errors
}
function isPortablePath(value) {
return value.length > 0 && value.length <= 512 &&
!/[\\\x00-\x1f?#:]/.test(value) && !value.startsWith('/') &&
value.split('/').every(part => part.length > 0 && part !== '.' && part !== '..')
}