dsh-biocore 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/lib/core-worker.js +268 -0
- package/lib/index.js +160 -70
- package/lib/modules/autonomy.js +125 -0
- package/lib/modules/cache-stats.js +48 -0
- package/lib/modules/core-turn.js +24 -6
- package/lib/modules/expression-inject.js +0 -10
- package/lib/modules/expression-refresh.js +0 -9
- package/lib/modules/memory-capture.js +2 -1
- package/lib/modules/memory-inject.js +50 -5
- package/lib/modules/memory-tools.js +7 -4
- package/lib/modules/python-env.js +46 -0
- package/lib/modules/safety-gate.js +0 -3
- package/lib/modules/series.js +54 -0
- package/lib/modules/switch.js +16 -0
- package/lib/py-bridge.js +81 -15
- package/package.json +1 -1
- package/python/biocore_memory/core/config.py +138 -127
- package/python/biocore_memory/engine.py +2653 -2476
- package/python/biocore_memory/recall/embedding.py +129 -0
- package/python/biocore_memory/recall/feedback.py +202 -0
- package/python/biocore_model/preference_drift.py +255 -0
- package/python/biocore_model/tests/__init__.py +1 -0
- package/python/biocore_model/tests/core_mode_ui_check.mjs +63 -0
- package/python/biocore_model/tests/core_status_check.mjs +29 -0
- package/python/biocore_model/tests/dom_safe_check.mjs +22 -0
- package/python/biocore_model/tests/leak_samples_run.py +18 -0
- package/python/biocore_model/tests/orb_ring_check.mjs +20 -0
- package/python/biocore_model/tests/panel_html_check.mjs +63 -0
- package/python/biocore_model/tests/persona_flow_check.mjs +17 -0
- package/python/biocore_model/tests/render_guard_check.mjs +19 -0
- package/python/biocore_model/tests/switch_groups_check.mjs +94 -0
- package/python/biocore_model/tests/tabs_state_check.mjs +24 -0
- package/python/biocore_model/tests/test_affective_labor.py +102 -0
- package/python/biocore_model/tests/test_appraisal.py +137 -0
- package/python/biocore_model/tests/test_appraisal_action.py +55 -0
- package/python/biocore_model/tests/test_arch_convergence.py +35 -0
- package/python/biocore_model/tests/test_attachment_behavior.py +95 -0
- package/python/biocore_model/tests/test_attachment_regulation.py +63 -0
- package/python/biocore_model/tests/test_attachment_state.py +29 -0
- package/python/biocore_model/tests/test_attribution.py +56 -0
- package/python/biocore_model/tests/test_attributor.py +108 -0
- package/python/biocore_model/tests/test_autonomic.py +69 -0
- package/python/biocore_model/tests/test_autonomy_accumulator.py +84 -0
- package/python/biocore_model/tests/test_autonomy_affect.py +62 -0
- package/python/biocore_model/tests/test_autonomy_blame.py +44 -0
- package/python/biocore_model/tests/test_autonomy_caps.py +29 -0
- package/python/biocore_model/tests/test_autonomy_check.py +40 -0
- package/python/biocore_model/tests/test_autonomy_clingy.py +41 -0
- package/python/biocore_model/tests/test_autonomy_cooldown_selfcontact.py +138 -0
- package/python/biocore_model/tests/test_autonomy_frustration.py +42 -0
- package/python/biocore_model/tests/test_autonomy_hourly_limit.py +46 -0
- package/python/biocore_model/tests/test_autonomy_loop.py +64 -0
- package/python/biocore_model/tests/test_autonomy_mode.py +37 -0
- package/python/biocore_model/tests/test_autonomy_model.py +60 -0
- package/python/biocore_model/tests/test_autonomy_model_v2.py +68 -0
- package/python/biocore_model/tests/test_autonomy_module_text.py +104 -0
- package/python/biocore_model/tests/test_autonomy_params.py +163 -0
- package/python/biocore_model/tests/test_autonomy_reason.py +34 -0
- package/python/biocore_model/tests/test_autonomy_self.py +153 -0
- package/python/biocore_model/tests/test_autonomy_send_gate.py +38 -0
- package/python/biocore_model/tests/test_autonomy_silence.py +37 -0
- package/python/biocore_model/tests/test_autonomy_status.py +35 -0
- package/python/biocore_model/tests/test_autonomy_test_trigger.py +24 -0
- package/python/biocore_model/tests/test_autonomy_tick.py +148 -0
- package/python/biocore_model/tests/test_autonomy_v4.py +64 -0
- package/python/biocore_model/tests/test_autonomy_v5.py +43 -0
- package/python/biocore_model/tests/test_autonomy_v7.py +48 -0
- package/python/biocore_model/tests/test_autonomy_v_theta.py +85 -0
- package/python/biocore_model/tests/test_batch1_wiring.py +231 -0
- package/python/biocore_model/tests/test_batch2_wiring.py +231 -0
- package/python/biocore_model/tests/test_batch3_wiring.py +223 -0
- package/python/biocore_model/tests/test_bio_tick.py +202 -0
- package/python/biocore_model/tests/test_boundary.py +183 -0
- package/python/biocore_model/tests/test_boundary_gate.py +295 -0
- package/python/biocore_model/tests/test_brain_split.py +99 -0
- package/python/biocore_model/tests/test_co_recall.py +350 -0
- package/python/biocore_model/tests/test_commitment_extractor.py +197 -0
- package/python/biocore_model/tests/test_compassion_fatigue.py +84 -0
- package/python/biocore_model/tests/test_connection_bids.py +69 -0
- package/python/biocore_model/tests/test_core_bridge.py +88 -0
- package/python/biocore_model/tests/test_core_bridge_episode.py +14 -0
- package/python/biocore_model/tests/test_core_bridge_forget.py +17 -0
- package/python/biocore_model/tests/test_core_bridge_identity.py +15 -0
- package/python/biocore_model/tests/test_core_bridge_media.py +17 -0
- package/python/biocore_model/tests/test_core_bridge_relation.py +17 -0
- package/python/biocore_model/tests/test_core_bridge_summary.py +17 -0
- package/python/biocore_model/tests/test_core_client.py +156 -0
- package/python/biocore_model/tests/test_core_commands.py +146 -0
- package/python/biocore_model/tests/test_core_mode.py +161 -0
- package/python/biocore_model/tests/test_core_state.py +240 -0
- package/python/biocore_model/tests/test_criticality.py +61 -0
- package/python/biocore_model/tests/test_cross_session_copy.py +67 -0
- package/python/biocore_model/tests/test_debug_values.py +169 -0
- package/python/biocore_model/tests/test_defense_mechanisms.py +177 -0
- package/python/biocore_model/tests/test_delta_budget.py +157 -0
- package/python/biocore_model/tests/test_diag_trace.py +201 -0
- package/python/biocore_model/tests/test_directives_compat.py +698 -0
- package/python/biocore_model/tests/test_dissonance.py +97 -0
- package/python/biocore_model/tests/test_drift_sign.py +87 -0
- package/python/biocore_model/tests/test_embedding_fallback.py +277 -0
- package/python/biocore_model/tests/test_embedding_local.py +279 -0
- package/python/biocore_model/tests/test_embedding_mode.py +175 -0
- package/python/biocore_model/tests/test_embedding_modes.py +342 -0
- package/python/biocore_model/tests/test_emotion_geometry.py +114 -0
- package/python/biocore_model/tests/test_emotion_probe.py +214 -0
- package/python/biocore_model/tests/test_emotion_probe_concurrency.py +128 -0
- package/python/biocore_model/tests/test_entity_graph.py +198 -0
- package/python/biocore_model/tests/test_entity_resolve.py +446 -0
- package/python/biocore_model/tests/test_envy.py +173 -0
- package/python/biocore_model/tests/test_exit_or_silence.py +209 -0
- package/python/biocore_model/tests/test_expr_guard.py +1 -0
- package/python/biocore_model/tests/test_expr_intent.py +66 -0
- package/python/biocore_model/tests/test_expr_state.py +66 -0
- package/python/biocore_model/tests/test_expr_template.py +71 -0
- package/python/biocore_model/tests/test_expr_tone.py +41 -0
- package/python/biocore_model/tests/test_extreme_scenarios.py +147 -0
- package/python/biocore_model/tests/test_feedback_flow.py +185 -0
- package/python/biocore_model/tests/test_feedback_guard.py +65 -0
- package/python/biocore_model/tests/test_feedback_llm.py +59 -0
- package/python/biocore_model/tests/test_feedback_llm_inferred.py +140 -0
- package/python/biocore_model/tests/test_feedback_memory.py +63 -0
- package/python/biocore_model/tests/test_feedback_user.py +61 -0
- package/python/biocore_model/tests/test_frustration_curve.py +66 -0
- package/python/biocore_model/tests/test_global_bio_state.py +116 -0
- package/python/biocore_model/tests/test_governance.py +181 -0
- package/python/biocore_model/tests/test_granularity.py +133 -0
- package/python/biocore_model/tests/test_graph_extract.py +224 -0
- package/python/biocore_model/tests/test_graph_recall.py +226 -0
- package/python/biocore_model/tests/test_graph_sqlite.py +298 -0
- package/python/biocore_model/tests/test_growth.py +301 -0
- package/python/biocore_model/tests/test_intent_render.py +60 -0
- package/python/biocore_model/tests/test_intero_regulation.py +224 -0
- package/python/biocore_model/tests/test_intero_style.py +146 -0
- package/python/biocore_model/tests/test_item3_numeric.py +105 -0
- package/python/biocore_model/tests/test_item6_numeric.py +116 -0
- package/python/biocore_model/tests/test_layered_memory.py +174 -0
- package/python/biocore_model/tests/test_leak_guard.py +75 -0
- package/python/biocore_model/tests/test_learning_probe.py +93 -0
- package/python/biocore_model/tests/test_life_loop.py +222 -0
- package/python/biocore_model/tests/test_life_loop_10s.py +131 -0
- package/python/biocore_model/tests/test_local_embedding_health.py +258 -0
- package/python/biocore_model/tests/test_memory_affect_encoding.py +79 -0
- package/python/biocore_model/tests/test_memory_backend.py +332 -0
- package/python/biocore_model/tests/test_memory_dedup.py +316 -0
- package/python/biocore_model/tests/test_memory_dual.py +219 -0
- package/python/biocore_model/tests/test_memory_dual_wiring.py +219 -0
- package/python/biocore_model/tests/test_memory_feedback.py +241 -0
- package/python/biocore_model/tests/test_memory_fixes.py +84 -0
- package/python/biocore_model/tests/test_memory_forgetting.py +58 -0
- package/python/biocore_model/tests/test_memory_inject.py +211 -0
- package/python/biocore_model/tests/test_memory_mood_recall.py +118 -0
- package/python/biocore_model/tests/test_memory_store.py +372 -0
- package/python/biocore_model/tests/test_metacog.py +103 -0
- package/python/biocore_model/tests/test_migrate.py +245 -0
- package/python/biocore_model/tests/test_migrate_store.py +194 -0
- package/python/biocore_model/tests/test_mind_wander.py +65 -0
- package/python/biocore_model/tests/test_mood.py +35 -0
- package/python/biocore_model/tests/test_narrative.py +114 -0
- package/python/biocore_model/tests/test_needs_esteem.py +51 -0
- package/python/biocore_model/tests/test_needs_events.py +205 -0
- package/python/biocore_model/tests/test_needs_sleep.py +54 -0
- package/python/biocore_model/tests/test_noise_bank.py +54 -0
- package/python/biocore_model/tests/test_numeric_schema.py +98 -0
- package/python/biocore_model/tests/test_output_protocol.py +65 -0
- package/python/biocore_model/tests/test_page_debug.py +147 -0
- package/python/biocore_model/tests/test_page_status_autonomy.py +215 -0
- package/python/biocore_model/tests/test_pipeline.py +345 -0
- package/python/biocore_model/tests/test_pipeline_api.py +192 -0
- package/python/biocore_model/tests/test_pipeline_mode.py +222 -0
- package/python/biocore_model/tests/test_plugin_config.py +85 -0
- package/python/biocore_model/tests/test_policy_learning.py +116 -0
- package/python/biocore_model/tests/test_possible_selves.py +88 -0
- package/python/biocore_model/tests/test_predictor.py +227 -0
- package/python/biocore_model/tests/test_preference_drift.py +142 -0
- package/python/biocore_model/tests/test_preset.py +142 -0
- package/python/biocore_model/tests/test_proactive_context.py +70 -0
- package/python/biocore_model/tests/test_proactive_history.py +90 -0
- package/python/biocore_model/tests/test_proactive_memory.py +141 -0
- package/python/biocore_model/tests/test_proactive_send_record.py +88 -0
- package/python/biocore_model/tests/test_probe_contract.py +71 -0
- package/python/biocore_model/tests/test_prospective.py +154 -0
- package/python/biocore_model/tests/test_provider_fallback.py +89 -0
- package/python/biocore_model/tests/test_reconstruction.py +111 -0
- package/python/biocore_model/tests/test_regulation_strategies.py +228 -0
- package/python/biocore_model/tests/test_relation_stage.py +114 -0
- package/python/biocore_model/tests/test_relationship_stage.py +59 -0
- package/python/biocore_model/tests/test_release_140.py +55 -0
- package/python/biocore_model/tests/test_repair_after_boundary.py +249 -0
- package/python/biocore_model/tests/test_reply_limit.py +86 -0
- package/python/biocore_model/tests/test_reply_limit_persist.py +48 -0
- package/python/biocore_model/tests/test_reply_split.py +52 -0
- package/python/biocore_model/tests/test_reply_split_astrbot.py +66 -0
- package/python/biocore_model/tests/test_reply_split_inject.py +53 -0
- package/python/biocore_model/tests/test_rerank.py +229 -0
- package/python/biocore_model/tests/test_rollback.py +175 -0
- package/python/biocore_model/tests/test_runtime.py +175 -0
- package/python/biocore_model/tests/test_runtime_active.py +205 -0
- package/python/biocore_model/tests/test_runtime_pipeline.py +1583 -0
- package/python/biocore_model/tests/test_runtime_proactive.py +231 -0
- package/python/biocore_model/tests/test_scheduler.py +79 -0
- package/python/biocore_model/tests/test_secrecy.py +105 -0
- package/python/biocore_model/tests/test_self_esteem.py +45 -0
- package/python/biocore_model/tests/test_self_intent.py +347 -0
- package/python/biocore_model/tests/test_self_interest.py +183 -0
- package/python/biocore_model/tests/test_self_layer_wiring.py +198 -0
- package/python/biocore_model/tests/test_self_verification.py +113 -0
- package/python/biocore_model/tests/test_situation.py +142 -0
- package/python/biocore_model/tests/test_sleep_circadian.py +41 -0
- package/python/biocore_model/tests/test_social_pain.py +49 -0
- package/python/biocore_model/tests/test_social_repair.py +67 -0
- package/python/biocore_model/tests/test_social_theory.py +78 -0
- package/python/biocore_model/tests/test_source_monitoring.py +204 -0
- package/python/biocore_model/tests/test_speak_like_group.py +36 -0
- package/python/biocore_model/tests/test_stages.py +226 -0
- package/python/biocore_model/tests/test_state_tag.py +86 -0
- package/python/biocore_model/tests/test_template_expr.py +65 -0
- package/python/biocore_model/tests/test_text_inference.py +70 -0
- package/python/biocore_model/tests/test_theta_params.py +115 -0
- package/python/biocore_model/tests/test_topic_control.py +200 -0
- package/python/biocore_model/tests/test_turn_memory.py +105 -0
- package/python/biocore_model/tests/test_turn_memory_panel.py +174 -0
- package/python/biocore_model/tests/test_ui_settings.py +84 -0
- package/python/biocore_model/tests/test_ui_settings_authority.py +179 -0
- package/python/biocore_model/tests/test_user_appraisal_async.py +155 -0
- package/python/biocore_model/tests/test_user_classify.py +122 -0
- package/python/biocore_model/tests/test_value_order.py +117 -0
- package/python/biocore_model/tests/test_voice_bank.py +105 -0
- package/python/biocore_model/tests/test_waiting_sense.py +216 -0
- package/python/biocore_model/tests/test_x_directives.py +101 -0
- package/python/biocore_model/tests/ui_compat_check.mjs +22 -0
- package/python/biocore_model/tests/view_mode_check.mjs +17 -0
- package/python/biocore_runtime/autonomy.py +208 -0
- package/python/biocore_runtime/core_state.py +302 -0
- package/python/biocore_runtime/governance.py +495 -0
- package/python/biocore_runtime/growth.py +528 -0
- package/python/biocore_runtime/pipeline.py +850 -23
- package/python/biocore_runtime/relationship_state.py +214 -0
- package/python/biocore_runtime/self_layer.py +103 -0
- package/python/biocore_runtime/service.py +162 -0
- package/python/biocore_runtime/standby.py +472 -0
- package/ui/panel-layout.js +83 -39
- package/ui/panel.css +885 -743
- package/ui/panel.html +356 -296
- package/ui/panel.js +739 -865
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""task-171 只读诊断单测:状态差/提示词差/记录有界/落盘规则/面板投射。
|
|
3
|
+
|
|
4
|
+
纯函数行为 + main.py 接线源码断言;不导入 AstrBot。
|
|
5
|
+
"""
|
|
6
|
+
import ast
|
|
7
|
+
import json
|
|
8
|
+
import unittest
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from biocore_model import diag_trace as dt
|
|
12
|
+
|
|
13
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
14
|
+
MAIN = (ROOT / "main.py").read_text(encoding="utf-8")
|
|
15
|
+
ROUTES = (ROOT / "biocore_model" / "plugin_routes.py").read_text(encoding="utf-8")
|
|
16
|
+
SCHEMA = json.loads((ROOT / "_conf_schema.json").read_text(encoding="utf-8"))
|
|
17
|
+
DASH = ROOT / "pages" / "dashboard"
|
|
18
|
+
SRC_HTML = (DASH / "index.src.html").read_text(encoding="utf-8")
|
|
19
|
+
INDEX_HTML = (DASH / "index.html").read_text(encoding="utf-8")
|
|
20
|
+
APP_JS = (DASH / "app.js").read_text(encoding="utf-8")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SnapshotDiffTest(unittest.TestCase):
|
|
24
|
+
def test_snapshot_keys_and_rounding(self):
|
|
25
|
+
class Core:
|
|
26
|
+
v = 0.123456
|
|
27
|
+
stress = 0.4
|
|
28
|
+
snap = dt.state_snapshot(Core())
|
|
29
|
+
self.assertIn("v", snap)
|
|
30
|
+
self.assertEqual(snap["v"], 0.1235)
|
|
31
|
+
self.assertEqual(set(snap), set(dt.SNAPSHOT_KEYS))
|
|
32
|
+
self.assertTrue(all(isinstance(value, float) for value in snap.values()))
|
|
33
|
+
|
|
34
|
+
def test_snapshot_reads_nested_needs(self):
|
|
35
|
+
snap = dt.state_snapshot({"v": 0.1, "needs": {"belonging": 0.7}})
|
|
36
|
+
self.assertEqual(snap["belonging"], 0.7)
|
|
37
|
+
self.assertEqual(snap["v"], 0.1)
|
|
38
|
+
|
|
39
|
+
def test_diff_only_moved_values(self):
|
|
40
|
+
before = {"v": 0.1, "stress": 0.2, "energy": 0.5}
|
|
41
|
+
after = {"v": 0.15, "stress": 0.2, "energy": 0.44}
|
|
42
|
+
delta = dt.diff_state(before, after)
|
|
43
|
+
self.assertEqual(set(delta), {"v", "energy"})
|
|
44
|
+
self.assertEqual(delta["v"], 0.05)
|
|
45
|
+
self.assertEqual(delta["energy"], -0.06)
|
|
46
|
+
|
|
47
|
+
def test_diff_empty_when_same(self):
|
|
48
|
+
snap = {"v": 0.1, "a": 0.2}
|
|
49
|
+
self.assertEqual(dt.diff_state(snap, dict(snap)), {})
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class PromptDiffTest(unittest.TestCase):
|
|
53
|
+
def test_unchanged(self):
|
|
54
|
+
diff = dt.prompt_diff("a\nb", "a\nb")
|
|
55
|
+
self.assertFalse(diff["changed"])
|
|
56
|
+
self.assertEqual(diff["chars_delta"], 0)
|
|
57
|
+
self.assertEqual(diff["preview"], "")
|
|
58
|
+
|
|
59
|
+
def test_changed_counts(self):
|
|
60
|
+
diff = dt.prompt_diff("a\nb", "a\nb\nc")
|
|
61
|
+
self.assertTrue(diff["changed"])
|
|
62
|
+
self.assertEqual(diff["chars_delta"], 2)
|
|
63
|
+
self.assertEqual(diff["lines_added"], 1)
|
|
64
|
+
self.assertEqual(diff["lines_removed"], 0)
|
|
65
|
+
self.assertTrue(diff["preview"])
|
|
66
|
+
|
|
67
|
+
def test_preview_bounded(self):
|
|
68
|
+
diff = dt.prompt_diff("a", "b" * 500)
|
|
69
|
+
self.assertLessEqual(len(diff["preview"]), dt.PREVIEW_CHARS)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class BuildTest(unittest.TestCase):
|
|
73
|
+
def _record(self, **overrides):
|
|
74
|
+
kwargs = dict(
|
|
75
|
+
before={"v": 0.1, "stress": 0.2}, after={"v": 0.2, "stress": 0.2},
|
|
76
|
+
intent={"top": "要你陪", "intents": [
|
|
77
|
+
{"kind": "要你陪", "weight": 0.7, "reason": "有点空"},
|
|
78
|
+
{"kind": "自己待着", "weight": 0.3, "reason": "累"}],
|
|
79
|
+
"motivation": "想让他陪一会儿", "self_weight": 0.7,
|
|
80
|
+
"drive": 0.5, "urge": 0.35, "satisfaction": -0.1,
|
|
81
|
+
"candidates": [{"kind": "要你陪", "score": 0.8},
|
|
82
|
+
{"kind": "顺着你", "score": 0.2}]},
|
|
83
|
+
metacog={"band": "low", "confidence": 0.3, "converge": False,
|
|
84
|
+
"allow_self_correction": False, "reason": "把握不大"},
|
|
85
|
+
pending_prompts=["该问一句:体检"], voice_phrases=["少来。"],
|
|
86
|
+
length={"scale": 0.8, "brevity": "short", "source": "metacog"},
|
|
87
|
+
hints={"strategy": "hint", "prospective": "p", "voice": "v",
|
|
88
|
+
"metacog": "m"},
|
|
89
|
+
prompt={"changed": True, "chars": 120, "chars_delta": 12,
|
|
90
|
+
"lines_added": 1, "lines_removed": 0, "preview": "x"},
|
|
91
|
+
session="s1", ts=100.0, turn=3, latency_ms=123.4,
|
|
92
|
+
text_chars=8, switches={"diag_trace_enabled": True})
|
|
93
|
+
kwargs.update(overrides)
|
|
94
|
+
return dt.build(**kwargs)
|
|
95
|
+
|
|
96
|
+
def test_record_contract(self):
|
|
97
|
+
rec = self._record()
|
|
98
|
+
for key in ("ts", "session", "turn", "state_delta", "intent",
|
|
99
|
+
"candidates", "metacog", "length", "hints", "prompt",
|
|
100
|
+
"switches", "latency_ms"):
|
|
101
|
+
self.assertIn(key, rec)
|
|
102
|
+
self.assertEqual(rec["turn"], 3)
|
|
103
|
+
self.assertEqual(rec["state_delta"], {"v": 0.1})
|
|
104
|
+
self.assertEqual(rec["intent"]["top"], "要你陪")
|
|
105
|
+
self.assertEqual(rec["intent"]["weight"], 0.7)
|
|
106
|
+
self.assertEqual(rec["intent"]["reason"], "有点空")
|
|
107
|
+
self.assertEqual(rec["length"]["source"], "metacog")
|
|
108
|
+
self.assertEqual(rec["candidates"][0]["kind"], "要你陪")
|
|
109
|
+
|
|
110
|
+
def test_record_bounds(self):
|
|
111
|
+
rec = self._record(session="s" * 500, pending_prompts=["p" * 500] * 9,
|
|
112
|
+
voice_phrases=["v" * 500] * 9,
|
|
113
|
+
hints={"strategy": "h" * 900})
|
|
114
|
+
self.assertEqual(len(rec["session"]), 80)
|
|
115
|
+
self.assertEqual(len(rec["pending_prompts"]), 3)
|
|
116
|
+
self.assertLessEqual(len(rec["pending_prompts"][0]), 60)
|
|
117
|
+
self.assertEqual(len(rec["voice_phrases"]), 2)
|
|
118
|
+
self.assertLessEqual(len(rec["hints"]["strategy"]), 140)
|
|
119
|
+
|
|
120
|
+
def test_record_garbage_safe(self):
|
|
121
|
+
rec = dt.build(before="x", after=3, intent="no", metacog=None,
|
|
122
|
+
pending_prompts="no", length="no", prompt=7)
|
|
123
|
+
self.assertEqual(rec["state_delta"], {})
|
|
124
|
+
self.assertEqual(rec["intent"]["top"], "")
|
|
125
|
+
self.assertEqual(rec["length"]["scale"], 1.0)
|
|
126
|
+
|
|
127
|
+
def test_render_text_bounded(self):
|
|
128
|
+
text = dt.render_text(self._record())
|
|
129
|
+
self.assertLessEqual(len(text), dt.TEXT_CHARS)
|
|
130
|
+
self.assertIn("turn=3", text)
|
|
131
|
+
self.assertIn("intent=要你陪", text)
|
|
132
|
+
self.assertIn("len=0.80", text)
|
|
133
|
+
self.assertIn("prompt=chars120", text)
|
|
134
|
+
self.assertEqual(dt.render_text("nope"), "")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class RowsTest(unittest.TestCase):
|
|
138
|
+
def test_append_keeps_newest_50(self):
|
|
139
|
+
rows = [{"turn": i} for i in range(60)]
|
|
140
|
+
out = dt.append(rows, {"turn": 60}, limit=50)
|
|
141
|
+
self.assertEqual(len(out), 50)
|
|
142
|
+
self.assertEqual(out[-1]["turn"], 60)
|
|
143
|
+
self.assertEqual(out[0]["turn"], 11)
|
|
144
|
+
|
|
145
|
+
def test_view_newest_first(self):
|
|
146
|
+
rows = [{"turn": i} for i in range(1, 6)]
|
|
147
|
+
view = dt.view(rows, limit=3)
|
|
148
|
+
self.assertEqual([row["turn"] for row in view], [5, 4, 3])
|
|
149
|
+
|
|
150
|
+
def test_append_ignores_garbage(self):
|
|
151
|
+
out = dt.append(["x", None, {"turn": 1}], "nope", limit=50)
|
|
152
|
+
self.assertEqual(out, [{"turn": 1}])
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class PurityAndWiringTest(unittest.TestCase):
|
|
156
|
+
def test_pure_module_imports(self):
|
|
157
|
+
tree = ast.parse((ROOT / "biocore_model" / "diag_trace.py")
|
|
158
|
+
.read_text(encoding="utf-8"))
|
|
159
|
+
modules = set()
|
|
160
|
+
for node in ast.walk(tree):
|
|
161
|
+
if isinstance(node, ast.Import):
|
|
162
|
+
modules.update(alias.name.split(".")[0] for alias in node.names)
|
|
163
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
164
|
+
modules.add(node.module.split(".")[0])
|
|
165
|
+
self.assertEqual(modules, {"__future__"})
|
|
166
|
+
|
|
167
|
+
def test_schema_flag_default_off(self):
|
|
168
|
+
entry = SCHEMA.get("diag_trace_enabled")
|
|
169
|
+
self.assertIsInstance(entry, dict)
|
|
170
|
+
self.assertEqual(entry.get("type"), "bool")
|
|
171
|
+
self.assertIs(entry.get("default"), False)
|
|
172
|
+
|
|
173
|
+
def test_main_wiring(self):
|
|
174
|
+
self.assertIn('self.config.get("diag_trace_enabled", False)', MAIN)
|
|
175
|
+
self.assertIn("diag_trace as _diag_mod", MAIN)
|
|
176
|
+
self.assertIn("_diag_mod3.build(", MAIN)
|
|
177
|
+
self.assertIn("_diag_trace_write(", MAIN)
|
|
178
|
+
self.assertIn('DATA_DIR / "trace.jsonl"', MAIN)
|
|
179
|
+
self.assertIn("self._diag_pending", MAIN)
|
|
180
|
+
self.assertIn("[biocore] diag ", MAIN)
|
|
181
|
+
self.assertIn("diag_trace_enabled", MAIN)
|
|
182
|
+
|
|
183
|
+
def test_status_projection(self):
|
|
184
|
+
self.assertIn('"diag_trace": (self._diag_trace_payload()', MAIN)
|
|
185
|
+
self.assertIn('"diag_trace": (self._diag_trace_payload()', ROUTES)
|
|
186
|
+
self.assertIn("self._diag_trace_rows(5)", MAIN)
|
|
187
|
+
|
|
188
|
+
def test_dashboard_page(self):
|
|
189
|
+
for text in (SRC_HTML, INDEX_HTML):
|
|
190
|
+
self.assertIn('data-session-tab="diag"', text)
|
|
191
|
+
self.assertIn('id="sessionPanelDiag"', text)
|
|
192
|
+
self.assertIn('id="diagRows"', text)
|
|
193
|
+
self.assertIn("这一轮为什么", text)
|
|
194
|
+
self.assertIn("function renderDiagTrace()", APP_JS)
|
|
195
|
+
self.assertIn('$("diagRows")', APP_JS)
|
|
196
|
+
self.assertIn("renderDiagTrace();", APP_JS)
|
|
197
|
+
self.assertIn("data.diag_trace", APP_JS)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
if __name__ == "__main__":
|
|
201
|
+
unittest.main()
|