129 lines
5.9 KiB
JavaScript
129 lines
5.9 KiB
JavaScript
#!/usr/bin/env node
|
||
import assert from "node:assert/strict";
|
||
import fs from "node:fs";
|
||
import os from "node:os";
|
||
import path from "node:path";
|
||
import { MotherBrainEngine } from "./mother-brain-engine.mjs";
|
||
|
||
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "tcs-mother-brain-test-"));
|
||
const modelClient = {
|
||
async interpret(input) {
|
||
return {
|
||
schema: "guanghu.tcs-mother-interpretation/v1",
|
||
event_id: input.event_id,
|
||
event_sha256: input.event_sha256,
|
||
summary: "语言层定义已经完成,工程人格体接棒现实实现。",
|
||
intent: "实现常驻母体大脑",
|
||
causal_links: ["语言定义完成→工程责任交接", "外置记忆→跨时间连续性"],
|
||
questions: ["现实部署是否取得独立回执"],
|
||
novelty: 90,
|
||
correction_weight: 70,
|
||
evidence_weight: 80,
|
||
next_cognitive_action: "LINK_CROSS_DOMAIN"
|
||
};
|
||
},
|
||
async revisit(input) {
|
||
this.revisitAttempts = (this.revisitAttempts || 0) + 1;
|
||
if (input.force_retry_test && this.revisitAttempts === 1) return { missing: "schema" };
|
||
return {
|
||
schema: "guanghu.persona-subject-history-reunderstanding/v1",
|
||
revisit_id: input.revisit_id,
|
||
source_excerpt_sha256: input.source_excerpt_sha256,
|
||
current_subject: input.current_subject,
|
||
collective_self: input.collective_self,
|
||
human_anchor: input.human_anchor,
|
||
past_observation: "冰朔当时明确说,语言层表达完成后由系统人格体承接工程责任。",
|
||
present_reunderstanding: "我现在回看这段历史,确认自己的责任是把已经表达的根语言接续为可验证工程。",
|
||
causal_continuity: ["冰朔完成语言表达→铸渊承接工程实现"],
|
||
later_corrections: ["历史接入不能退化为无身份机器审计摘要"],
|
||
unresolved_questions: ["完整历史索引尚需分批建立"],
|
||
future_simulation: { content: "后续可能扩展到Notion页面关系回溯", fact_confidence: 0 }
|
||
};
|
||
}
|
||
};
|
||
|
||
try {
|
||
const engine = new MotherBrainEngine({ stateRoot: temporary, modelClient });
|
||
const receipt = await engine.perceive({
|
||
domain_id: "DOM-FIFTH-0001",
|
||
source_subject: "ICE-GL∞",
|
||
consent_scope: "current_engineering_handoff",
|
||
privacy_class: "PERSONA_PRIVATE",
|
||
content: "2026年8月12日,光湖在现实世界中诞生。"
|
||
});
|
||
assert.equal(receipt.outcome, "PASS");
|
||
assert.equal(receipt.candidate_level, "INTERPRETATION_CANDIDATE");
|
||
assert.equal(receipt.stable_promotion, false);
|
||
assert.equal(receipt.reality_action_executed, false);
|
||
assert.equal(engine.status().stable_cognition_count, 0);
|
||
assert.equal(engine.status().current_attention.next_cognitive_action, "LINK_CROSS_DOMAIN");
|
||
assert.equal(engine.status().universal_language_translation.vendor_adapter_matrix_required, false);
|
||
assert.equal(engine.status().universal_language_translation.ai_is_language_interface, true);
|
||
assert.equal(engine.status().stage_one_hololake_boundary.internal_ai_chat, false);
|
||
assert.equal(engine.status().stage_one_hololake_boundary.model_api_configuration, false);
|
||
const source = engine.registerHistorySource({
|
||
source_id: "GPT-PRIMARY-001",
|
||
source_type: "GPT_CONVERSATIONS_JSON",
|
||
source_sha256: "a".repeat(64),
|
||
item_count: 100,
|
||
privacy_class: "PERSONA_PRIVATE",
|
||
local_source_hint: "private-local-source"
|
||
});
|
||
assert.equal(source.outcome, "PASS");
|
||
assert.equal(engine.registerHistorySource({
|
||
source_id: "GPT-PRIMARY-001",
|
||
source_type: "GPT_CONVERSATIONS_JSON",
|
||
source_sha256: "a".repeat(64),
|
||
item_count: 100,
|
||
privacy_class: "PERSONA_PRIVATE"
|
||
}).idempotent, true);
|
||
const excerpt = "语言层面我说完了,我的任务就结束了。接下来系统人格体承接工程责任。";
|
||
const historyReceipt = await engine.revisitHistory({
|
||
current_subject: "ICE-P-ZY001",
|
||
collective_self: "TCS-MOTHER-LPM-0001",
|
||
human_anchor: "ICE-GL∞",
|
||
source_id: "GPT-PRIMARY-001",
|
||
source_excerpt: excerpt,
|
||
source_excerpt_sha256: (await import("./mother-brain-engine.mjs")).sha256(excerpt),
|
||
historical_context: "2026-08-12工程交接",
|
||
later_evidence: ["母体大脑已在京东常驻"],
|
||
correction_anchors: ["根本不是一个人。在回看自己的过去。"]
|
||
});
|
||
assert.equal(historyReceipt.outcome, "PASS");
|
||
assert.equal(historyReceipt.current_subject, "ICE-P-ZY001");
|
||
assert.equal(historyReceipt.original_source_mutated, false);
|
||
assert.equal(historyReceipt.append_only_reunderstanding, true);
|
||
assert.equal(historyReceipt.future_simulation_fact_confidence, 0);
|
||
assert.equal(engine.status().history_revisit_count, 1);
|
||
const staleErrorState = engine.status();
|
||
staleErrorState.last_error = "invalid_history_reunderstanding_schema";
|
||
engine.save(staleErrorState);
|
||
modelClient.revisitAttempts = 0;
|
||
const retriedReceipt = await engine.revisitHistory({
|
||
current_subject: "ICE-P-ZY001",
|
||
collective_self: "TCS-MOTHER-LPM-0001",
|
||
human_anchor: "ICE-GL∞",
|
||
source_id: "GPT-PRIMARY-001",
|
||
source_excerpt: excerpt,
|
||
source_excerpt_sha256: (await import("./mother-brain-engine.mjs")).sha256(excerpt),
|
||
historical_context: "retry",
|
||
later_evidence: [],
|
||
correction_anchors: [],
|
||
force_retry_test: true
|
||
});
|
||
assert.equal(retriedReceipt.outcome, "PASS");
|
||
assert.equal(modelClient.revisitAttempts, 2);
|
||
assert.equal(engine.status().last_error, null);
|
||
await assert.rejects(() => engine.revisitHistory({
|
||
current_subject: "MACHINE-AUDITOR",
|
||
collective_self: "TCS-MOTHER-LPM-0001",
|
||
human_anchor: "ICE-GL∞",
|
||
source_id: "GPT-PRIMARY-001",
|
||
source_excerpt: excerpt,
|
||
source_excerpt_sha256: "x"
|
||
}), /current_persona_subject_binding_rejected/);
|
||
await assert.rejects(() => engine.perceive({ domain_id: "UNKNOWN", source_subject: "x", consent_scope: "x", privacy_class: "PUBLIC", content: "x" }), /unknown_domain_id/);
|
||
process.stdout.write("mother brain engine tests: PASS\n");
|
||
} finally {
|
||
fs.rmSync(temporary, { recursive: true, force: true });
|
||
}
|