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.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* { 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.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('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/) })