feat: 上架视频剪辑固定材料与作者契约

This commit is contained in:
yige committed 2026-11-02 21:52:36 +08:00
1 parent 9577e9a411
commit eef65008eb
18 files changed
+5658 -198

No files matched your search

+32 -1
View File
@@ -1,7 +1,32 @@
import { isApplicationEntry, isAuthoredRegistryEntry } from './entry-schema.mjs'
/** 发布者关系声明的跨字段检查;不推导安装、权限或运行时健康。 */
export function validateApplicationContract(manifest) {
if (!['docker-app', 'native-app', 'artifact'].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')
}
const ids = new Set()
for (const entrypoint of Array.isArray(manifest.entrypoints) ? manifest.entrypoints : []) {
if (!entrypoint || typeof entrypoint !== 'object') continue
@@ -18,3 +43,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 !== '..')
}
+10
View File
@@ -0,0 +1,10 @@
/** 作者 release 使用受审的新契约;普通条目仍由已发布 global Schema 校验。 */
export const AUTHORED_ENTRY_SCHEMA_FILENAME = 'registry-entry.v4.3.schema.json'
export function isAuthoredRegistryEntry(entry) {
return entry?.type === 'web-bundle' || (entry !== null && typeof entry === 'object' && Object.hasOwn(entry, 'appRelease'))
}
export function isApplicationEntry(entry) {
return ['docker-app', 'native-app', 'artifact', 'web-bundle'].includes(entry?.type)
}
+7
View File
@@ -141,6 +141,13 @@ function validateNode(value, schema, rootSchema, path, errors) {
if (schema.items) {
value.forEach((item, index) => validateNode(item, schema.items, rootSchema, joinPath(path, index), errors))
}
if (schema.contains !== undefined && !value.some((item, index) => {
const candidateErrors = []
validateNode(item, schema.contains, rootSchema, joinPath(path, index), candidateErrors)
return candidateErrors.length === 0
})) {
errors.push({ path, message: '数组必须包含符合 contains 的元素' })
}
}
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
+22 -10
View File
@@ -4,6 +4,7 @@ import { basename, join, relative, resolve, sep } from 'node:path'
import { validateJsonSchema } from './json-schema.mjs'
import { findStaticMetrics } from './static-metadata.mjs'
import { validateApplicationContract } from './application-contract.mjs'
import { AUTHORED_ENTRY_SCHEMA_FILENAME, isApplicationEntry, isAuthoredRegistryEntry } from './entry-schema.mjs'
export const CATALOG_SIDECAR_FILENAME = 'catalog-metadata.v1.json'
@@ -33,6 +34,15 @@ function schemaDiagnostics(value, schema, file) {
)
}
function readSchema(file, diagnostics) {
const schema = readJson(file, diagnostics)
if (schema === null || Array.isArray(schema) || !['object', 'boolean'].includes(typeof schema)) {
diagnostics.push(diagnostic('error', 'invalid-schema', file, '$', 'Schema 根必须是对象或 boolean'))
return null
}
return schema
}
function safeRelativePath(value) {
return (
typeof value === 'string' &&
@@ -77,7 +87,7 @@ function timestampShapeIsConsistent(timestamp) {
function validateSidecarSemantics(manifest, sidecar, file) {
const errors = []
const add = (code, path, message) => errors.push(diagnostic('error', code, file, path, message))
const expectedKind = ['docker-app', 'native-app', 'artifact'].includes(manifest.type) ? 'app' : 'service'
const expectedKind = isApplicationEntry(manifest) ? 'app' : 'service'
if (sidecar.identity?.id !== manifest.id) add('identity-mismatch', '$.identity.id', 'sidecar identity.id 必须与 legacy manifest.id 一致')
if (sidecar.identity?.kind !== expectedKind) add('kind-mismatch', '$.identity.kind', `legacy ${manifest.type} 必须映射为 ${expectedKind}`)
@@ -140,7 +150,7 @@ function validateSidecarSemantics(manifest, sidecar, file) {
if (manifest.toolCount !== undefined && sidecar.spec?.toolCount !== manifest.toolCount) add('spec-mismatch', '$.spec.toolCount', 'toolCount 必须与 legacy 一致')
}
if (['native-app', 'artifact'].includes(manifest.type)) {
if (['native-app', 'artifact', 'web-bundle'].includes(manifest.type) || isAuthoredRegistryEntry(manifest)) {
for (const field of ['stewardship', 'availability', 'redistribution', 'listingMaintainer', 'upstreamMaintainer', 'branding', 'compliance']) {
if (!isDeepStrictEqual(manifest[field], sidecar.governance?.[field])) add('native-governance-mismatch', '$.governance.' + field, '原生应用 manifest 与 sidecar 的治理事实必须一致')
}
@@ -205,15 +215,16 @@ export function validateRegistry(repoRoot, options = {}) {
const diagnostics = []
const manifestFile = join(root, 'manifest.json')
const schemaVersionFile = join(root, 'SCHEMA_VERSION')
const rootSchema = readJson(join(root, 'schemas', 'registry-manifest.v3.schema.json'), diagnostics)
const legacyEntrySchema = readJson(join(root, 'schemas', 'registry-entry.v3.schema.json'), diagnostics)
const externalEntrySchema = readJson(join(root, 'schemas', 'registry-entry.schema.json'), diagnostics)
const sidecarSchema = readJson(join(root, 'schemas', 'catalog-metadata.v1.schema.json'), diagnostics)
const rootSchema = readSchema(join(root, 'schemas', 'registry-manifest.v3.schema.json'), diagnostics)
const legacyEntrySchema = readSchema(join(root, 'schemas', 'registry-entry.v3.schema.json'), diagnostics)
const externalEntrySchema = readSchema(join(root, 'schemas', 'registry-entry.schema.json'), diagnostics)
const authoredEntrySchema = readSchema(join(root, 'schemas', AUTHORED_ENTRY_SCHEMA_FILENAME), diagnostics)
const sidecarSchema = readSchema(join(root, 'schemas', 'catalog-metadata.v1.schema.json'), diagnostics)
const rootManifest = readJson(manifestFile, diagnostics)
const entryDirs = findEntryDirs(join(root, 'entries'))
const counts = { totalEntries: 0, dockerApps: 0, mcpServices: 0, httpApis: 0, externalIntegrations: 0, sidecars: 0, legacyOnly: 0 }
if (rootManifest && rootSchema) diagnostics.push(...schemaDiagnostics(rootManifest, rootSchema, relativeFile(root, manifestFile)))
if (rootManifest && rootSchema !== null) diagnostics.push(...schemaDiagnostics(rootManifest, rootSchema, relativeFile(root, manifestFile)))
const schemaVersion = existsSync(schemaVersionFile) ? readFileSync(schemaVersionFile, 'utf8').trim() : ''
const currentEntrySchema = /^4\./.test(schemaVersion) ? externalEntrySchema : legacyEntrySchema
if (!schemaVersion) diagnostics.push(diagnostic('error', 'missing-schema-version', 'SCHEMA_VERSION', '$', 'SCHEMA_VERSION 不能为空'))
@@ -240,8 +251,9 @@ export function validateRegistry(repoRoot, options = {}) {
if (entry.type === 'mcp') counts.mcpServices += 1
if (entry.type === 'http-api') counts.httpApis += 1
if (entry.type === 'external-integration') counts.externalIntegrations += 1
const effectiveEntrySchema = ['external-integration', 'native-app', 'artifact'].includes(entry.type) ? externalEntrySchema : currentEntrySchema
if (effectiveEntrySchema) diagnostics.push(...schemaDiagnostics(entry, effectiveEntrySchema, manifestRelative))
const effectiveEntrySchema = isAuthoredRegistryEntry(entry) ? authoredEntrySchema
: ['external-integration', 'native-app', 'artifact'].includes(entry.type) ? externalEntrySchema : currentEntrySchema
if (effectiveEntrySchema !== null && effectiveEntrySchema !== undefined) diagnostics.push(...schemaDiagnostics(entry, effectiveEntrySchema, manifestRelative))
for (const message of validateApplicationContract(entry)) diagnostics.push(diagnostic('error', 'application-contract', manifestRelative, '$', message))
if (entry.id !== basename(entryDir)) diagnostics.push(diagnostic('error', 'directory-id-mismatch', manifestRelative, '$.id', 'manifest.id 必须与 entries/<id> 目录名一致'))
if (seenIds.has(entry.id)) diagnostics.push(diagnostic('error', 'duplicate-id', manifestRelative, '$.id', 'Registry 条目 ID 重复'))
@@ -259,7 +271,7 @@ export function validateRegistry(repoRoot, options = {}) {
const sidecar = readJson(sidecarPath, diagnostics)
if (!sidecar) continue
const sidecarRelative = relativeFile(root, sidecarPath)
if (sidecarSchema) diagnostics.push(...schemaDiagnostics(sidecar, sidecarSchema, sidecarRelative))
if (sidecarSchema !== null) diagnostics.push(...schemaDiagnostics(sidecar, sidecarSchema, sidecarRelative))
diagnostics.push(...validateSidecarSemantics(entry, sidecar, sidecarRelative))
}