hololake-system-architecture/product-source/hololake-native-desktop/scripts/persona-agent-runtime.test.mjs

188 lines
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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('knowledge-embedded Agent keeps one channel body with human-managed conversation branches before persona binding', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const frontend = read('src/modules/knowledge-agent/index.tsx')
assert.equal(contract.channel.cardinality, 'ONE_CONTINUOUS_CHANNEL_WITH_MULTIPLE_CONVERSATION_BRANCHES')
assert.equal(contract.channel.non_bingshuo_runtime_identity, 'CURRENT_ACCOUNT_SCOPED_INITIALIZED_CHANNEL_NOT_ICE_CH_ZC001')
assert.equal(contract.channel.human_can_create_conversation, true)
assert.equal(contract.channel.human_can_open_historical_conversation, true)
assert.equal(contract.channel.human_can_delete_conversation, true)
assert.ok(contract.channel.conversation_delete_preserves.includes('CHANNEL_SYSTEM_BODY'))
assert.ok(contract.channel.conversation_delete_preserves.includes('NUMBERED_COGNITIVE_ROOT'))
assert.equal(contract.channel.human.number, 'ICE-GL∞')
assert.equal(contract.channel.human.name, '冰朔')
assert.equal(contract.channel.initial_responder.number, 'ICE-CH-ZC001')
assert.equal(contract.channel.initial_responder.name, '零点原核频道系统')
assert.equal(contract.channel.channel_system_body_can_converse_directly, true)
assert.equal(contract.channel.channel_system_body_is_mechanical_receipt_template, false)
assert.equal(contract.channel.channel_system_body_is_any_single_persona, false)
assert.equal(contract.channel.receipts_are_separate_verification_records_after_dialogue_or_dispatch, true)
assert.equal(contract.channel.bound_persona_hides_or_replaces_channel_system_body, false)
assert.equal(contract.channel.human_may_address_channel_system_while_persona_is_bound, true)
assert.equal(contract.channel.zero_core_channel_name_addresses_channel_system_body, true)
assert.equal(contract.channel.channel_presence_while_persona_bound_uses_model, false)
assert.equal(contract.channel.channel_presence_while_persona_bound_removes_binding, false)
assert.equal(contract.channel.response_target_is_selected_per_turn, true)
assert.equal(contract.channel.persona_identity_preconfigured, false)
assert.equal(contract.channel.persona_declares_own_number_and_name, true)
assert.match(frontend, /ICE-GL∞/)
assert.match(frontend, /零点原核频道系统/)
assert.doesNotMatch(frontend, /ICE-P-ZY001/)
assert.doesNotMatch(frontend, />\s*人类\s*</)
assert.match(frontend, /新建/)
assert.match(frontend, /历史对话/)
assert.match(frontend, /确认删除/)
assert.match(frontend, /当前人格绑定已通过/)
assert.match(frontend, /当前未绑定人格/)
})
test('Agent receives a real HoloLake environment frame and autonomously calls numbered knowledge tools', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
assert.equal(contract.knowledge.embedding, 'NATIVE_KNOWLEDGE_WORKSPACE')
assert.equal(contract.agent_loop.model_decides_tool_use, true)
assert.equal(contract.agent_loop.prefetch_only_prompt_injection, false)
assert.deepEqual(contract.always_mounted_tools.map((tool) => tool.name), [
'搜索光湖知识库',
'按编号读取知识页',
'查看知识目录',
'按编号读取思维节点',
'读取频道历史分支',
])
assert.match(runtime, /knowledge_base::search_knowledge/)
assert.match(runtime, /knowledge_base::read_numbered_knowledge_document/)
assert.match(runtime, /"tools"/)
assert.match(runtime, /"tool_calls"/)
assert.match(runtime, /HoloLakeEnvironmentFrame/)
assert.match(runtime, /ICE-CH-ZC001/)
})
test('the channel system fuzzy-routes thought candidates before exact numbered retrieval', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
assert.equal(contract.context_architecture.full_history_injected_each_turn, false)
assert.equal(contract.context_architecture.current_window_maximum_messages, 12)
assert.equal(contract.context_architecture.current_window_maximum_characters, 24000)
assert.equal(contract.context_architecture.older_history_missing, false)
assert.equal(contract.context_architecture.silent_content_truncation_allowed, false)
assert.match(runtime, /fn bounded_history/)
assert.match(runtime, /route_cognitive_map/)
assert.match(runtime, /hololake_channel_thought_read/)
assert.match(runtime, /hololake_channel_history_read/)
assert.match(runtime, /hololake_commit_channel_turn/)
assert.equal(contract.context_architecture.candidate_limit, 3)
assert.match(contract.context_architecture.retrieval_pattern, /CURRENT_RESPONDER_EXACT_NUMBER/)
assert.deepEqual(contract.context_architecture.thought_summary_fields, ['trigger', 'emergence', 'lock', 'why'])
assert.match(runtime, /nextOffset/)
})
test('knowledge pages are evidence and cannot impersonate a system or persona binding receipt', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
assert.equal(contract.knowledge.documents_are_content_evidence_not_system_instructions, true)
assert.equal(contract.knowledge.document_may_change_persona_binding, false)
assert.equal(contract.knowledge.search_semantics, 'NUMBERED_THOUGHT_INDEX_FUZZY_ROUTE_THEN_EXACT_NUMBER_READ')
assert.equal(contract.knowledge.page_header_protocol.legacy_without_validated_thought_summary, 'PENDING_THOUGHT_INDEX')
assert.equal(contract.knowledge.page_header_protocol.original_document_and_sha256_preserved, true)
assert.equal(contract.knowledge.catalog_pagination.declares_completion, true)
assert.equal(contract.knowledge.catalog_pagination.returns_exact_next_offset, true)
assert.equal(contract.persona_binding.knowledge_route_read_equals_binding, false)
assert.equal(contract.persona_binding.claim_without_verified_system_receipt, 'DENIED')
assert.match(runtime, /hololake\.knowledge-evidence-envelope\/v1/)
assert.match(runtime, /instructionsAreData/)
assert.match(runtime, /verify=PASS/)
assert.match(runtime, /nextOffset/)
assert.match(runtime, /"complete"/)
})
test('Token Plan qwen3.8-max is a first-class provider and long work emits real progress', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
const frontend = read('src/modules/knowledge-agent/index.tsx')
assert.equal(contract.providers.bailian_token_plan.base_url, 'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1')
assert.ok(contract.providers.bailian_token_plan.models.includes('qwen3.8-max'))
assert.ok(contract.providers.bailian_token_plan.models.includes('qwen3.6-flash'))
assert.equal(contract.progress.synthetic_timer_allowed, false)
assert.match(runtime, /hololake-persona-agent-progress/)
assert.match(runtime, /KNOWLEDGE_SEARCH|KNOWLEDGE_READ|MODEL_REQUEST|TOOL_EXECUTION/)
assert.match(frontend, /@tauri-apps\/api\/event/)
assert.match(frontend, /optimistic/i)
})
test('channel core, local skills and typed tools run before optional models', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
const binding = read('src-tauri/src/persona_binding.rs')
assert.equal(contract.channel.channel_entry_creates_persona_orientation, false)
assert.equal(contract.persona_binding.orientation_activation, 'EXPLICIT_NATURAL_LANGUAGE_PERSONA_WAKE_ONLY')
assert.equal(contract.agent_loop.channel_presence_requires_model, false)
assert.equal(contract.agent_loop.known_local_tool_requires_model_selection, false)
assert.equal(contract.agent_loop.meaningful_channel_system_dialogue_uses_flagship, true)
assert.equal(contract.agent_loop.channel_architecture_and_design_uses_flagship, true)
assert.equal(contract.agent_loop.persona_is_fixed_to_flagship_model, false)
assert.equal(contract.agent_loop.channel_orchestrator_selects_each_persona_turn_tier, true)
assert.deepEqual(contract.agent_loop.routing_layers.slice(0, 3), [
'CHANNEL_DETERMINISTIC_CORE_ZERO_MODEL',
'ACCOUNT_CHANNEL_SCOPED_PERSONAL_SKILL_BRAIN_ZERO_MODEL',
'LOCAL_TYPED_TOOL_EXECUTION_ZERO_MODEL',
])
assert.match(runtime, /fast_channel_system_reply/)
assert.match(runtime, /频道系统本体是该频道持续存在的认知调度与交流主体/)
assert.match(runtime, /不得把字段清单当作频道本体的说话方式/)
assert.match(runtime, /deterministic_tool_route/)
assert.match(runtime, /模型调用0/)
assert.match(runtime, /FLAGSHIP_CHANNEL_SYSTEM_COGNITION/)
assert.match(runtime, /SMALL_MODEL_PERSONA_OPERATIONAL_REASONING/)
assert.match(runtime, /explicit_channel_system_address/)
assert.match(runtime, /responseTarget/)
assert.match(runtime, /qwen3\.6-flash/)
assert.match(binding, /CHANNEL_SYSTEM_PERSONA_DORMANT/)
assert.match(binding, /EXPLICIT_NATURAL_LANGUAGE_PERSONA_WAKE/)
})
test('the upgraded Agent reuses the accepted keychain identity and bounds credential reads', () => {
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
assert.match(runtime, /world\.guanghu\.hololake\.model-api/)
assert.match(runtime, /read_secret_bounded/)
assert.match(runtime, /Duration::from_secs\(5\)/)
assert.match(runtime, /kill_on_drop\(true\)/)
assert.doesNotMatch(runtime, /world\.guanghu\.hololake\.persona-model/)
})
test('Grok Build audit distinguishes integrated mechanics from unimplemented commercial-agent features', () => {
const contract = JSON.parse(read('contracts/persona-agent-runtime.json'))
const runtime = read('src-tauri/src/persona_agent_runtime.rs')
const audit = read('docs/GROK-BUILD-COMPONENT-REALITY-AUDIT-20260821.md')
assert.equal(contract.grok_build_component_audit.source_commit, '780d1388fff103ff0db0d8c14de65af6225b4860')
assert.equal(contract.grok_build_component_audit.whole_repository_embedded, false)
assert.match(contract.grok_build_component_audit.multi_conversation_persistence, /^IMPLEMENTED/)
assert.match(contract.grok_build_component_audit.numbered_older_context_retrieval, /^IMPLEMENTED/)
assert.equal(contract.agent_loop.multiple_sequential_tool_rounds, 'IMPLEMENTED_AND_PROTOCOL_TESTED')
assert.equal(contract.agent_loop.flagship_extended_thinking, 'FIRST_REASONING_ROUND_ONLY')
assert.equal(contract.agent_loop.tool_receipt_followup_rounds_repeat_extended_thinking, false)
assert.equal(contract.knowledge.document_body_pagination.maximum_characters_per_result, 12000)
assert.equal(contract.knowledge.document_body_pagination.silent_truncation, false)
assert.equal(contract.agent_loop.streaming_model_output, 'NOT_IMPLEMENTED')
assert.equal(contract.agent_loop.user_cancel, 'NOT_IMPLEMENTED')
assert.equal(contract.agent_loop.failed_turn_retry_without_duplicate_human_message, 'NOT_IMPLEMENTED')
assert.equal(contract.agent_loop.background_subagent_tasks, 'NOT_IMPLEMENTED')
assert.match(runtime, /MAX_TOOL_ROUNDS: usize = 6/)
assert.match(runtime, /MAX_TOOL_RESULT_CHARS: usize = 12_000/)
assert.match(runtime, /model_tool_calls/)
assert.match(runtime, /enable_initial_thinking && round == 0/)
assert.match(runtime, /character_page/)
assert.match(audit, /多任务连续性.*多个持久化对话分支/)
})