feat: embed complete GLS protocol kernel in HoloLake
This commit is contained in:
parent
ca5d6f3f58
commit
b8d08fb620
15 changed files with 3515 additions and 485 deletions
|
|
@ -55,6 +55,27 @@ function sourceDependencies(raw) {
|
|||
return [...new Set(match?.[1].match(/GLS-\d{4}/g) || [])].sort()
|
||||
}
|
||||
|
||||
// REPO-012 的旧 depends 没有声明边语义。Bootstrap Compiler 必须把每条旧边
|
||||
// 投影为受限、只读的工程类型;这些边永不自动取得运行效力。真正进入激活图的边
|
||||
// 只能来自 gls-executable-projections/v2 的显式 RUNTIME_REQUIRES。
|
||||
function typedSourceDependency(sourceId, targetId) {
|
||||
const number = Number(targetId.slice(4))
|
||||
const recoveryTargets = new Set(['GLS-0304', 'GLS-0308', 'GLS-0827', 'GLS-0836', 'GLS-0843', 'GLS-0845', 'GLS-0846', 'GLS-0847', 'GLS-0848', 'GLS-0849'])
|
||||
const bootTargets = new Set(['GLS-0307', 'GLS-0310', 'GLS-0803', 'GLS-0819', 'GLS-0840', 'GLS-0841'])
|
||||
const buildTargets = new Set(['GLS-0130', 'GLS-0131', 'GLS-0411', 'GLS-0710', 'GLS-0844'])
|
||||
const evidenceTargets = new Set(['GLS-0306', 'GLS-0311', 'GLS-0604'])
|
||||
let edgeKind = 'NORMATIVE_REFERENCE'
|
||||
if (recoveryTargets.has(targetId) && (sourceId >= 'GLS-0800' || sourceId === 'GLS-0304' || sourceId === 'GLS-0308')) edgeKind = 'RECOVERY_REQUIRES'
|
||||
else if (bootTargets.has(targetId) && sourceId >= 'GLS-0800') edgeKind = 'BOOT_REQUIRES'
|
||||
else if (buildTargets.has(targetId)) edgeKind = 'BUILD_REQUIRES'
|
||||
else if (evidenceTargets.has(targetId)) edgeKind = 'EVIDENCE_ONLY'
|
||||
else if ((number >= 300 && number <= 399) || (number >= 400 && number <= 499) || ['GLS-0602', 'GLS-0603', 'GLS-0605'].includes(targetId)) edgeKind = 'SCHEMA_IMPORT'
|
||||
return {
|
||||
edge_kind: edgeKind,
|
||||
classification_basis: 'BOOTSTRAP_COMPILER_V1_FAMILY_AND_TARGET_RULE',
|
||||
}
|
||||
}
|
||||
|
||||
function contractKind(family, projectionKind) {
|
||||
if (projectionKind) return projectionKind
|
||||
const kinds = {
|
||||
|
|
@ -142,7 +163,9 @@ function stronglyConnectedComponents(graph) {
|
|||
}
|
||||
|
||||
const projectionManifest = JSON.parse(await readFile(projectionsPath, 'utf8'))
|
||||
if (projectionManifest.schema !== 'hololake.gls-executable-projections/v1' || projectionManifest.source_commit !== sourceCommit) {
|
||||
if (projectionManifest.schema !== 'hololake.gls-executable-projections/v2'
|
||||
|| projectionManifest.runtime_graph_rule !== 'ONLY_EXPLICIT_RUNTIME_REQUIRES_EDGES_ENTER_ACTIVATION_GRAPH'
|
||||
|| projectionManifest.source_commit !== sourceCommit) {
|
||||
throw new Error('projection manifest does not match the selected REPO-012 source commit')
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +275,7 @@ for (const [id, source] of [...selectedSource.entries()].sort(([left], [right])
|
|||
const dependencyEdges = [
|
||||
...legacyDependencies.map((target) => ({
|
||||
target,
|
||||
edge_kind: 'LEGACY_UNTYPED_REFERENCE',
|
||||
...typedSourceDependency(id, target),
|
||||
declared_by: `gls/${source.relative}`,
|
||||
enters_runtime_graph: false,
|
||||
target_registered: protocolRegistryIds.has(target),
|
||||
|
|
@ -271,7 +294,6 @@ for (const [id, source] of [...selectedSource.entries()].sort(([left], [right])
|
|||
if (!projection) activationBlockers.push('NO_EXECUTABLE_ADAPTER')
|
||||
if (registrationState === 'DISCOVERED_UNRECONCILED') activationBlockers.push('REGISTRATION_NOT_RECONCILED')
|
||||
if (authorityConflict) activationBlockers.push('REGISTRATION_SOURCE_CONFLICT')
|
||||
if (legacyDependencies.length > 0 && !projection) activationBlockers.push('LEGACY_DEPENDENCIES_REQUIRE_TYPED_REVIEW')
|
||||
if (legacyDependencies.some((target) => !knownSourceIds.has(target)) && !projection) activationBlockers.push('DEPENDENCY_NUMBERED_SOURCE_MISSING')
|
||||
protocols.push({
|
||||
id,
|
||||
|
|
@ -293,6 +315,7 @@ for (const [id, source] of [...selectedSource.entries()].sort(([left], [right])
|
|||
implementation_evidence: metadata?.implementation || null,
|
||||
},
|
||||
contract_kind: contractKind(metadata?.family, projection?.projection_kind),
|
||||
implementation_stage: projection?.stage || null,
|
||||
projection_state: projection ? 'EXECUTABLE_PROJECTION' : 'INVENTORIED_NOT_EXECUTABLE',
|
||||
projection_kind: projection?.projection_kind || null,
|
||||
adapter: projection?.adapter || null,
|
||||
|
|
@ -323,6 +346,12 @@ function visit(id) {
|
|||
for (const id of Object.keys(projectionManifest.projections)) visit(id)
|
||||
|
||||
const executableCount = protocols.filter((protocol) => protocol.projection_state === 'EXECUTABLE_PROJECTION').length
|
||||
const typedDependencyCounts = {}
|
||||
for (const protocol of protocols) {
|
||||
for (const edge of protocol.dependency_edges.filter((candidate) => !candidate.enters_runtime_graph)) {
|
||||
typedDependencyCounts[edge.edge_kind] = (typedDependencyCounts[edge.edge_kind] || 0) + 1
|
||||
}
|
||||
}
|
||||
const dependenciesNotInRegistry = [...legacyDependencyTargets].filter((id) => !protocolRegistryIds.has(id)).sort()
|
||||
const dependenciesWithoutNumberedSource = [...legacyDependencyTargets].filter((id) => !knownSourceIds.has(id)).sort()
|
||||
const numberedSourcesNotInProtocolRegistry = [...knownSourceIds].filter((id) => !protocolRegistryIds.has(id)).sort()
|
||||
|
|
@ -341,7 +370,7 @@ const registry = {
|
|||
arbitrary_protocol_code_allowed: false,
|
||||
executable_projection_requires_explicit_adapter: true,
|
||||
unprojected_protocol_behavior: 'INVENTORIED_NOT_EXECUTABLE',
|
||||
legacy_untyped_dependency_behavior: 'AUDIT_ONLY_BLOCKS_NEW_ACTIVATION',
|
||||
source_dependency_behavior: 'TYPED_AUDIT_ONLY_NEVER_ACTIVATES',
|
||||
runtime_graph_source: 'EXPLICIT_EXECUTABLE_PROJECTIONS_ONLY',
|
||||
runtime_dependency_cycles: 'REJECT',
|
||||
unknown_protocol: 'FAIL_CLOSED',
|
||||
|
|
@ -357,6 +386,9 @@ const registry = {
|
|||
dependencies_without_numbered_source: dependenciesWithoutNumberedSource,
|
||||
numbered_sources_not_in_protocol_registry: numberedSourcesNotInProtocolRegistry,
|
||||
legacy_dependency_cycles: legacyDependencyCycles,
|
||||
source_reference_cycles: legacyDependencyCycles,
|
||||
typed_source_dependency_counts: Object.fromEntries(Object.entries(typedDependencyCounts).sort()),
|
||||
unclassified_source_dependency_count: 0,
|
||||
discovered_unreconciled_count: protocols.filter((protocol) => protocol.registration.state === 'DISCOVERED_UNRECONCILED').length,
|
||||
authority_conflict_count: protocols.filter((protocol) => protocol.registration.state === 'REGISTRATION_CONFLICT').length,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import test from 'node:test'
|
||||
|
||||
const contractUrl = new URL('../contracts/gls-native-runtime-kernel.json', import.meta.url)
|
||||
const projectionUrl = new URL('../contracts/gls-executable-projections.json', import.meta.url)
|
||||
|
||||
test('native protocol kernel is bundled as product contract for P1 through P7', async () => {
|
||||
const contract = JSON.parse(await readFile(contractUrl, 'utf8'))
|
||||
const projections = JSON.parse(await readFile(projectionUrl, 'utf8'))
|
||||
assert.equal(contract.schema, 'hololake.gls-native-runtime-kernel/v1')
|
||||
assert.deepEqual(contract.stages.map((stage) => stage.id), ['P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7'])
|
||||
assert.ok(contract.stages.slice(0, 6).every((stage) => stage.state.startsWith('IMPLEMENTED')))
|
||||
assert.equal(contract.stages.slice(0, 6).flatMap((stage) => stage.protocols).length, 21)
|
||||
assert.equal(Object.keys(projections.projections).length, 25)
|
||||
assert.equal(projections.runtime_graph_rule, 'ONLY_EXPLICIT_RUNTIME_REQUIRES_EDGES_ENTER_ACTIVATION_GRAPH')
|
||||
assert.equal(contract.runtime_boundaries.every_decision_writes_receipt, true)
|
||||
assert.equal(contract.runtime_boundaries.model_can_override_decision, false)
|
||||
assert.equal(contract.runtime_boundaries.raw_protocol_text_executed, false)
|
||||
})
|
||||
|
||||
test('P7 assembly never transfers BS-SH-005 evidence into desktop health', async () => {
|
||||
const contract = JSON.parse(await readFile(contractUrl, 'utf8'))
|
||||
assert.equal(contract.p7_node_assemblies.length, 11)
|
||||
assert.ok(contract.p7_node_assemblies.every((assembly) => assembly.target === 'DESKTOP_HOLOLAKE'))
|
||||
assert.ok(contract.p7_node_assemblies.every((assembly) => assembly.state !== 'ACTIVE_HEALTHY'))
|
||||
assert.ok(contract.p7_node_assemblies.some((assembly) => assembly.sourceEvidenceNode === 'BS-SH-005'))
|
||||
})
|
||||
|
|
@ -14,7 +14,7 @@ test('compiled GLS v2 manifest reconciles current registration sources without e
|
|||
assert.equal(registry.compiler.raw_protocol_text_executed, false)
|
||||
assert.equal(registry.compiler.arbitrary_protocol_code_allowed, false)
|
||||
assert.equal(registry.compiler.unprojected_protocol_behavior, 'INVENTORIED_NOT_EXECUTABLE')
|
||||
assert.equal(registry.compiler.legacy_untyped_dependency_behavior, 'AUDIT_ONLY_BLOCKS_NEW_ACTIVATION')
|
||||
assert.equal(registry.compiler.source_dependency_behavior, 'TYPED_AUDIT_ONLY_NEVER_ACTIVATES')
|
||||
assert.equal(registry.protocol_count, 75)
|
||||
assert.equal(new Set(registry.protocols.map((protocol) => protocol.id)).size, 75)
|
||||
assert.ok(registry.protocols.every((protocol) => /^[a-f0-9]{64}$/.test(protocol.source_sha256)))
|
||||
|
|
@ -29,6 +29,8 @@ test('compiled GLS v2 manifest reconciles current registration sources without e
|
|||
assert.equal(registry.reconciliation.legacy_dependency_cycles.length, 3)
|
||||
assert.equal(registry.reconciliation.discovered_unreconciled_count, 0)
|
||||
assert.equal(registry.reconciliation.authority_conflict_count, 0)
|
||||
assert.equal(registry.reconciliation.unclassified_source_dependency_count, 0)
|
||||
assert.equal(Object.values(registry.reconciliation.typed_source_dependency_counts).reduce((sum, count) => sum + count, 0), 183)
|
||||
})
|
||||
|
||||
test('only explicit deterministic projections enter the runtime enforcement set', async () => {
|
||||
|
|
@ -40,10 +42,29 @@ test('only explicit deterministic projections enter the runtime enforcement set'
|
|||
assert.ok(protocols['GLS-0253'].event_kinds.includes('IDENTITY_ROUTE'))
|
||||
assert.ok(protocols['GLS-0253'].dependency_edges.every((edge) => edge.edge_kind === 'RUNTIME_REQUIRES'))
|
||||
assert.equal(protocols['GLS-0130'].registration.state, 'REGISTERED_PROTOCOL_REGISTRY')
|
||||
assert.equal(protocols['GLS-0130'].contract_kind, 'COMPILER_OR_INTERMEDIATE_REPRESENTATION')
|
||||
assert.ok(protocols['GLS-0130'].dependency_edges.some((edge) => edge.target === 'GLS-0131' && edge.edge_kind === 'LEGACY_UNTYPED_REFERENCE' && !edge.enters_runtime_graph))
|
||||
assert.ok(protocols['GLS-0130'].activation_blockers.includes('LEGACY_DEPENDENCIES_REQUIRE_TYPED_REVIEW'))
|
||||
assert.equal(protocols['GLS-0130'].contract_kind, 'BOOTSTRAP_HLDP_TO_GIR_COMPILER')
|
||||
assert.ok(protocols['GLS-0130'].dependency_edges.some((edge) => edge.target === 'GLS-0131' && edge.edge_kind === 'BUILD_REQUIRES' && !edge.enters_runtime_graph))
|
||||
assert.ok(protocols['GLS-0130'].dependency_edges.some((edge) => edge.target === 'GLS-0411' && edge.edge_kind === 'BUILD_REQUIRES' && !edge.enters_runtime_graph))
|
||||
assert.equal(protocols['GLS-0130'].implementation_stage, 'P6')
|
||||
assert.equal(protocols['GLS-0003'], undefined)
|
||||
assert.equal(registry.executable_projection_count, 4)
|
||||
assert.equal(registry.inventoried_not_executable_count, 71)
|
||||
assert.equal(registry.executable_projection_count, 25)
|
||||
assert.equal(registry.inventoried_not_executable_count, 50)
|
||||
})
|
||||
|
||||
test('P1 through P6 executable dependencies are explicit, typed, closed and acyclic', async () => {
|
||||
const registry = JSON.parse(await readFile(registryUrl, 'utf8'))
|
||||
const executable = new Map(registry.protocols.filter((protocol) => protocol.projection_state === 'EXECUTABLE_PROJECTION').map((protocol) => [protocol.id, protocol]))
|
||||
assert.deepEqual(new Set([...executable.values()].map((protocol) => protocol.implementation_stage)), new Set(['P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6']))
|
||||
assert.ok([...executable.values()].every((protocol) => protocol.dependency_edges.filter((edge) => edge.enters_runtime_graph).every((edge) => edge.edge_kind === 'RUNTIME_REQUIRES' && executable.has(edge.target))))
|
||||
const visiting = new Set()
|
||||
const visited = new Set()
|
||||
const visit = (id) => {
|
||||
assert.equal(visiting.has(id), false, `runtime cycle at ${id}`)
|
||||
if (visited.has(id)) return
|
||||
visiting.add(id)
|
||||
for (const dependency of executable.get(id).dependencies) visit(dependency)
|
||||
visiting.delete(id)
|
||||
visited.add(id)
|
||||
}
|
||||
for (const id of executable.keys()) visit(id)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue