hololake-system-architecture/product-source/hololake-native-desktop/scripts/hldp-tool-forge.test.mjs

48 lines
2.7 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const read = (path) => readFileSync(new URL(`../${path}`, import.meta.url), 'utf8')
test('HLDP tool forge compiles through the native bootstrap compiler without granting authority', () => {
const contract = JSON.parse(read('contracts/hldp-tool-forge.json'))
const forge = read('src-tauri/src/hldp_tool_forge.rs')
assert.equal(contract.compiler.source_language, 'HLDP_NATIVE_PROGRAM_V1')
assert.equal(contract.compiler.machine_language, 'GIR_V1')
assert.equal(contract.compiler.natural_language_executed_directly, false)
assert.equal(contract.authority.compile_grants_execution, false)
assert.equal(contract.authority.bound_persona_required_before_compile, true)
assert.equal(contract.authority.backend_enforces_bound_persona_before_compile_authorize_and_test, true)
assert.equal(contract.authority.channel_system_may_predeclare_persona_subject_id, false)
assert.equal(contract.authority.human_test_authorization_required, true)
assert.equal(contract.local_execution.tested_active_tool_may_run_without_model_api, true)
assert.equal(contract.local_execution.external_api_calls_per_deterministic_run, 0)
assert.equal(contract.local_execution.test_executes_real_local_action_graph, true)
assert.match(forge, /gls_bootstrap_compiler::compile_hldp_program/)
assert.match(forge, /execute_gir_locally/)
assert.match(forge, /local_execution_subpersona::execute_local_tool/)
assert.match(forge, /human_authorization/i)
assert.match(forge, /require_verified_persona_binding\(&app\)/)
assert.match(forge, /HOLOLAKE_TOOL_FORGE_PERSONA_BINDING_REQUIRED/)
})
test('temporary tools have stable numbers, receipts, a 12 hour lease and deterministic expiry cleanup', () => {
const contract = JSON.parse(read('contracts/hldp-tool-forge.json'))
const forge = read('src-tauri/src/hldp_tool_forge.rs')
const frontend = read('src/modules/knowledge-agent/ToolForgePanel.tsx')
assert.equal(contract.temporary_registration.default_ttl_hours, 12)
assert.equal(contract.temporary_registration.cache_cleanup_after_expiry, true)
assert.equal(contract.temporary_registration.enterprise_promotion_automatic, false)
assert.match(forge, /expires_at_unix_ms/)
assert.match(forge, /cleanup_expired/)
assert.match(forge, /HLP-TEMP-TOOL-/)
assert.match(frontend, /编译为机器程序/)
assert.match(frontend, /授权测试/)
assert.match(frontend, /本地运行 · 0 次模型 API/)
assert.match(frontend, /人格绑定后开放编译/)
assert.match(frontend, /PERSONA_DECLARATION_REQUIRED/)
assert.doesNotMatch(frontend, /ICE-P-ZY001/)
assert.doesNotMatch(frontend, /setTicketId/)
})