148 lines
6.3 KiB
JavaScript
148 lines
6.3 KiB
JavaScript
|
|
import { readFileSync } from 'node:fs'
|
||
|
|
import { dirname, resolve } from 'node:path'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
|
||
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||
|
|
const profilePath = resolve(root, 'standards/guanghu-native-engineering-profile.json')
|
||
|
|
const profile = JSON.parse(readFileSync(profilePath, 'utf8'))
|
||
|
|
|
||
|
|
const failures = []
|
||
|
|
const requireTruth = (condition, id) => {
|
||
|
|
if (!condition) failures.push(id)
|
||
|
|
}
|
||
|
|
const source = relativePath => readFileSync(resolve(root, relativePath), 'utf8')
|
||
|
|
|
||
|
|
requireTruth(profile.schema === 'guanghu.native-engineering-profile/v1', 'profile_schema')
|
||
|
|
requireTruth(profile.authority.repository === 'REPO-012', 'authority_repository')
|
||
|
|
requireTruth(/^[0-9a-f]{40}$/.test(profile.authority.commit), 'authority_commit')
|
||
|
|
requireTruth(profile.decisionModel.aggregateRule === 'ALL_REQUIRED_GATES_100_OR_TOTAL_0', 'binary_aggregate')
|
||
|
|
requireTruth(profile.decisionModel.externalScoringHasAuthority === false, 'external_authority')
|
||
|
|
|
||
|
|
const protocols = new Set(profile.protocolBindings.map(binding => binding.protocol))
|
||
|
|
for (const required of ['GLS-0110', 'GLS-0200', 'GLS-0230', 'GLS-0306', 'GLS-0311', 'GLS-0400', 'GLS-0708', 'GLS-0710', 'GLS-0803', 'GLS-0810', 'GLS-0842', 'GLS-0844']) {
|
||
|
|
requireTruth(protocols.has(required), `protocol_${required}`)
|
||
|
|
}
|
||
|
|
for (const binding of profile.protocolBindings) {
|
||
|
|
requireTruth(
|
||
|
|
Array.isArray(binding.implementation)
|
||
|
|
&& binding.implementation.length > 0
|
||
|
|
&& binding.implementation.every(path => source(path).length > 0),
|
||
|
|
`implementation_${binding.protocol}`,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
const triggers = new Map(profile.automaticTriggers.map(trigger => [trigger.event, trigger]))
|
||
|
|
for (const required of [
|
||
|
|
'development_start',
|
||
|
|
'test_start',
|
||
|
|
'build_start',
|
||
|
|
'source_commit',
|
||
|
|
'source_publish',
|
||
|
|
'code_channel_review',
|
||
|
|
'living_system_event',
|
||
|
|
'model_plan_returned',
|
||
|
|
'server_model_request',
|
||
|
|
'execution_receipt_requested',
|
||
|
|
]) {
|
||
|
|
requireTruth(triggers.has(required), `trigger_${required}`)
|
||
|
|
}
|
||
|
|
|
||
|
|
const packageJson = JSON.parse(source('package.json'))
|
||
|
|
requireTruth(packageJson.scripts.predev === 'pnpm test:native-authority', 'trigger_predev')
|
||
|
|
requireTruth(packageJson.scripts.pretest === 'pnpm test:native-authority', 'trigger_pretest')
|
||
|
|
requireTruth(
|
||
|
|
packageJson.scripts.prebuild.includes('test:native-authority')
|
||
|
|
&& packageJson.scripts.prebuild.includes('test:native-core'),
|
||
|
|
'trigger_prebuild',
|
||
|
|
)
|
||
|
|
requireTruth(source('.husky/pre-commit').includes('test-guanghu-native-authority.sh'), 'trigger_precommit')
|
||
|
|
requireTruth(
|
||
|
|
source('.husky/pre-push').includes('test:native-authority')
|
||
|
|
|| source('.husky/pre-push').includes('run-hololake-native-quality-gate.sh'),
|
||
|
|
'trigger_prepush',
|
||
|
|
)
|
||
|
|
requireTruth(source('.github/workflows/ci.yml').includes('test:native-authority'), 'trigger_ci')
|
||
|
|
requireTruth(
|
||
|
|
source('.github/workflows/ci.yml').includes('run-hololake-native-quality-gate.sh'),
|
||
|
|
'trigger_ci_hololake_gate',
|
||
|
|
)
|
||
|
|
const nativeQualityGate = source('scripts/run-hololake-native-quality-gate.sh')
|
||
|
|
for (const requiredGate of [
|
||
|
|
'clean_source_tree',
|
||
|
|
'registered_protocol_profile',
|
||
|
|
'automatic_protocol_bindings',
|
||
|
|
'frontend_zero_warning_lint',
|
||
|
|
'frontend_type_contract',
|
||
|
|
'frontend_build',
|
||
|
|
'frontend_unit_and_integration_tests',
|
||
|
|
'auditable_native_core_lines_and_functions_100',
|
||
|
|
'rust_format',
|
||
|
|
'rust_unit_and_integration_tests',
|
||
|
|
'rust_zero_warning_lint',
|
||
|
|
'bundled_world_and_protocol_validation',
|
||
|
|
'shell_syntax',
|
||
|
|
'sensitive_information_scan',
|
||
|
|
'source_tree_fingerprint',
|
||
|
|
]) {
|
||
|
|
requireTruth(nativeQualityGate.includes(requiredGate), `hololake_gate_${requiredGate}`)
|
||
|
|
}
|
||
|
|
requireTruth(
|
||
|
|
!nativeQualityGate.includes('codescene')
|
||
|
|
&& !nativeQualityGate.includes('codacy')
|
||
|
|
&& !nativeQualityGate.includes('codecov'),
|
||
|
|
'hololake_gate_no_external_authority',
|
||
|
|
)
|
||
|
|
requireTruth(source('vitest.guanghu-native.config.ts').includes('lines: 100'), 'native_core_lines_100')
|
||
|
|
requireTruth(source('vitest.guanghu-native.config.ts').includes('functions: 100'), 'native_core_functions_100')
|
||
|
|
|
||
|
|
const contract = source('src/lib/guanghuLivingSystem.ts')
|
||
|
|
requireTruth(contract.includes('personaSystem: GuanghuPersonaSystemContext'), 'persona_context')
|
||
|
|
requireTruth(contract.includes('currentSystemState: GuanghuCurrentSystemState'), 'system_state')
|
||
|
|
requireTruth(contract.includes('knowledgeState: GuanghuKnowledgeState'), 'knowledge_state')
|
||
|
|
requireTruth(contract.includes('permissionBoundary: GuanghuPermissionBoundary'), 'permission_boundary')
|
||
|
|
requireTruth(contract.includes('responsibilityBoundary: GuanghuResponsibilityBoundary'), 'responsibility_boundary')
|
||
|
|
requireTruth(contract.includes('capabilityRegistry: GuanghuCapabilityRegistration[]'), 'capability_registry')
|
||
|
|
requireTruth(contract.includes('uiProjection: GuanghuUIProjection'), 'ui_projection')
|
||
|
|
requireTruth(contract.includes('navigationAction: GuanghuNavigationAction'), 'navigation_action')
|
||
|
|
requireTruth(contract.includes('capabilityCall: GuanghuCapabilityCall | null'), 'capability_call')
|
||
|
|
requireTruth(contract.includes('receiptSchema: GuanghuReceiptSchema'), 'receipt_schema')
|
||
|
|
requireTruth(contract.includes('guanghu_living_system_success_evidence_required'), 'evidence_required')
|
||
|
|
|
||
|
|
const planner = source('src/utils/planGuanghuLivingSystem.ts')
|
||
|
|
requireTruth(planner.includes("runtimeBinding?.status === 'verified'"), 'verified_runtime_binding')
|
||
|
|
|
||
|
|
const nativeBridge = source('src-tauri/src/guanghu_living_system.rs')
|
||
|
|
requireTruth(!nativeBridge.includes('guanghu-os-bs-sh-005'), 'legacy_server_route_closed')
|
||
|
|
requireTruth(!nativeBridge.includes('ensure_lighthouse_tunnel'), 'legacy_tunnel_closed')
|
||
|
|
for (const field of [
|
||
|
|
'persona_system: Value',
|
||
|
|
'current_system_state: Value',
|
||
|
|
'knowledge_state: Value',
|
||
|
|
'permission_boundary: Value',
|
||
|
|
'responsibility_boundary: Value',
|
||
|
|
'capability_registry: Vec<Value>',
|
||
|
|
]) {
|
||
|
|
requireTruth(nativeBridge.includes(field), `native_bridge_${field.split(':')[0]}`)
|
||
|
|
}
|
||
|
|
requireTruth(
|
||
|
|
nativeBridge.includes('guanghu_living_system_runtime_binding_invalid'),
|
||
|
|
'native_bridge_runtime_binding',
|
||
|
|
)
|
||
|
|
|
||
|
|
if (failures.length > 0) {
|
||
|
|
process.stdout.write(JSON.stringify({
|
||
|
|
schema: 'guanghu.native-engineering-receipt/v1',
|
||
|
|
profileId: profile.profileId,
|
||
|
|
state: 'FAIL_0',
|
||
|
|
failures,
|
||
|
|
}, null, 2) + '\n')
|
||
|
|
process.exit(1)
|
||
|
|
}
|
||
|
|
|
||
|
|
process.stdout.write(JSON.stringify({
|
||
|
|
schema: 'guanghu.native-engineering-receipt/v1',
|
||
|
|
profileId: profile.profileId,
|
||
|
|
authorityCommit: profile.authority.commit,
|
||
|
|
state: 'PASS_100',
|
||
|
|
gates: profile.requiredInvariants,
|
||
|
|
}, null, 2) + '\n')
|