Contracts (the shared language): - percept / state / context / utterance / render / audio / capabilities - Capability model instead of vendor schemas (see below) Providers (capability-based abstraction): - LLM + Embedding: OpenAI-compatible shape IS the standard, adopted directly - ASR: internal contract is an event stream (partial -> final), because /v1/audio/transcriptions has no partial and dialogue needs it for endpointing. OpenAI adapter degrades to supports_partial=False. - TTS: internal contract carries tags/emotion/style, because /v1/audio/speech has no paralinguistics and [laughter]/[breath] are the core of feeling alive. Unsupported providers are stripped AND reported via Degradation -- silent degradation is forbidden. - Avatar: no de-facto standard, custom RenderCmd protocol driven by State. Core: - mood: dynamical system, slow variables, negativity bias (grudge), numbing after prolonged negativity - bazi: four pillars -> numeric vector; 'ming' is data, not prose - projection: phi, system event -> in-world statement; uncovered events are counted as projection gaps Storage: - SQLite schema, three memory layers, dyad ledger - accessibility floor 0.03 (not 0): forgettable but still there Config split: - models.yaml is the ONLY place model versions live - character.yaml holds world rules / emotion params, no version numbers 58 tests pass; ruff clean.
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
"""八字编译测试。
|
|
|
|
守的是:**命是数值,不是散文。**
|
|
编译结果必须稳定(同一个四柱永远得到同一个向量),
|
|
而且强弱必须真的影响敏感度。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from cybergril.core.bazi import (
|
|
ELEMENTS,
|
|
Pillars,
|
|
compile_pillars,
|
|
day_master_strength,
|
|
element_scores,
|
|
ten_god,
|
|
ten_god_distribution,
|
|
)
|
|
|
|
PILLARS = Pillars(year="甲子", month="丙寅", day="戊午", time="壬子")
|
|
|
|
|
|
def test_pillars_day_master() -> None:
|
|
assert PILLARS.day_master == "戊"
|
|
|
|
|
|
def test_element_scores_sum_positive() -> None:
|
|
scores = element_scores(PILLARS)
|
|
assert set(scores) == set(ELEMENTS)
|
|
assert sum(scores.values()) > 0
|
|
assert all(v >= 0 for v in scores.values())
|
|
|
|
|
|
def test_element_scores_rejects_bad_format() -> None:
|
|
with pytest.raises(ValueError, match="格式错误"):
|
|
element_scores(Pillars(year="甲", month="丙寅", day="戊午", time="壬子"))
|
|
|
|
|
|
def test_day_master_strength_in_range() -> None:
|
|
scores = element_scores(PILLARS)
|
|
s = day_master_strength(PILLARS, scores)
|
|
assert 0.0 <= s <= 1.0
|
|
|
|
|
|
def test_ten_god_known_relations() -> None:
|
|
# 木克土(克我),同阳 → 七杀
|
|
assert ten_god("戊", "甲") == "七杀"
|
|
# 火生土(生我),同阳 → 偏印
|
|
assert ten_god("戊", "丙") == "偏印"
|
|
# 土克水(我克),同阳 → 偏财
|
|
assert ten_god("戊", "壬") == "偏财"
|
|
# 土同土,同阳 → 比肩
|
|
assert ten_god("戊", "戊") == "比肩"
|
|
|
|
|
|
def test_ten_god_distribution_normalized() -> None:
|
|
dist = ten_god_distribution(PILLARS)
|
|
assert dist
|
|
assert abs(sum(dist.values()) - 1.0) < 1e-6
|
|
assert all(0 <= v <= 1 for v in dist.values())
|
|
|
|
|
|
def test_compile_is_deterministic() -> None:
|
|
a = compile_pillars(PILLARS)
|
|
b = compile_pillars(PILLARS)
|
|
assert a.as_dict() == b.as_dict()
|
|
|
|
|
|
def test_compile_produces_bounded_params() -> None:
|
|
d = compile_pillars(PILLARS)
|
|
for key in (
|
|
"autonomy", "compliance", "expressiveness", "warmth",
|
|
"anxiety", "aggression", "discipline", "correcting",
|
|
"solitude_need", "impulsivity", "sharing", "realism",
|
|
):
|
|
val = getattr(d, key)
|
|
assert 0.0 <= val <= 1.0, f"{key} 越界: {val}"
|
|
|
|
|
|
def test_strength_drives_sensitivity() -> None:
|
|
"""身弱必须更敏感、恢复更慢。这是强弱进入动力学的唯一入口。"""
|
|
weak = compile_pillars(Pillars(year="甲子", month="乙丑", day="丙子", time="丁亥"))
|
|
# 用编译结果自身的 strength 反推关系
|
|
for d in (weak, compile_pillars(PILLARS)):
|
|
expected_sens = 1.35 - 0.70 * d.strength
|
|
assert abs(d.sensitivity - expected_sens) < 1e-9
|
|
expected_rec = 1.60 - 1.20 * d.strength
|
|
assert abs(d.recovery_scale - expected_rec) < 1e-9
|
|
|
|
|
|
def test_traits_text_non_empty() -> None:
|
|
assert compile_pillars(PILLARS).traits_text()
|