femo-plugin 1.0.0 → 1.0.2
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/FEMO_logo.svg +55 -0
- package/FEMO_logo_slogan.svg +29 -0
- package/README.md +10 -2
- package/_tmp/fallback/driver2.py +176 -0
- package/_tmp/fallback/events.jsonl +108 -0
- package/_tmp/fallback/gateway_ui.py +325 -0
- package/_tmp/fallback/outbox/j1553_human_[/347/234/213/347/211/214]_1.done +1 -0
- package/_tmp/fallback/outbox/r1.done +1 -0
- package/_tmp/fallback/outbox/r2.done +1 -0
- package/_tmp/fallback/outbox/r3.done +1 -0
- package/_tmp/fallback/outbox/r4.done +1 -0
- package/_tmp/fallback/outbox/r5.done +1 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +3 -2
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +112 -9
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +17 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +3 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +4 -1
- package/hostAdapter/dshAdapter/host/index.ts +5 -0
- package/hostAdapter/dshAdapter/host/preset-install.ts +59 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +14 -6
- package/hostAdapter/dshAdapter/lib/client.js +124 -5
- package/hostAdapter/dshAdapter/lib/client.js.map +3 -3
- package/hostAdapter/dshAdapter/lib/index.js +58 -18
- package/hostAdapter/dshAdapter/lib/index.js.map +4 -4
- package/hostAdapter/dshAdapter/package.json +1 -5
- package/hostAdapter/dshAdapter/preset/agent.cordis.yml +220 -0
- package/hostAdapter/dshAdapter/preset/preset.yml +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/gateway.port +1 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_52a9_624b.jsonl +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_6211.jsonl +10 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-god.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-stage.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/README.md +61 -0
- package/hostAdapter/zcodeAdapter/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/LICENSE +201 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/README.md +635 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/__init__.py +4 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/chronica.py +156 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_api.py +437 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_gen_api.jsx +77 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/ContextExample.py +555 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/MemoryExample.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir/get_dir.py +56 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir//344/275/240/345/217/257/344/273/245/350/256/276/345/256/232/344/273/273/346/204/217/346/226/207/344/273/266/345/244/271/344/270/272/347/224/250/346/210/267/346/225/260/346/215/256/346/226/207/344/273/266/345/244/271.txt +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmBridge.py +247 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmProviders.py +308 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_config.py +35 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_errors.py +278 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_interpreter.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_normalizer.py +396 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_parser.py +2468 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_runtime.py +3630 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/actor_resolver.py +86 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/block_collector.py +441 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/db_utils.py +485 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/femoAsync.py +401 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/host_manifest.py +68 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/job_manager.py +767 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/protocol.py +126 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/save_dialog.py +402 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/task_world.py +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/__init__.py +19 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/checkpoint.py +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/env.py +686 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/evaluator.py +567 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/join.py +303 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/merge.py +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/model.py +245 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/discussion.femo +70 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/goal-mode.femo +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +348 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +393 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
- package/hostAdapter/zcodeAdapter/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/package.json +1 -1
- package/scripts/diag-find-redblue.mjs +38 -0
- package/scripts/diag-god-log.mjs +31 -0
- package/scripts/diag-god-log2.mjs +39 -0
- package/scripts/diag-god-log3.mjs +35 -0
- package/scripts/diag-god-log4.mjs +59 -0
- package/scripts/diag-god-log4b.mjs +39 -0
- package/scripts/diag-redblue-god.mjs +39 -0
- package/scripts/diag-redblue-log.mjs +37 -0
- package/scripts/diag-redblue-span.mjs +41 -0
- package/scripts/diag-stage-1017.mjs +63 -0
- package/scripts/dump_session.py +36 -0
- package/scripts/link-workspace.ps1 +51 -0
- package/scripts/list_souls.py +18 -0
- package/scripts/probe-composer-refresh.mjs +197 -0
- package/scripts/seed_story_souls.py +86 -0
- package/scripts/sync-zcode-dist.ps1 +55 -0
- package/scripts/theme-tokenize/color-extract.txt +288 -0
- package/scripts/theme-tokenize/round1-quoted.ps1 +149 -0
- package/scripts/theme-tokenize/round2-bare.ps1 +138 -0
- package/scripts/theme-tokenize/round3-shape.ps1 +110 -0
- package/tests/_diag_r4_join.femo +32 -0
- package/tests/conftest.py +95 -0
- package/tests/diag-subagent-dir-3081.mjs +101 -0
- package/tests/femoGenerator.test.mjs +3909 -0
- package/tests/femoParser.test.mjs +4813 -0
- package/tests/femogen_notice.test.mjs +109 -0
- package/tests/femoparser_validation.test.mjs +84 -0
- package/tests/main-delivery-queue.test.mjs +329 -0
- package/tests/pre-step-gate.test.mjs +282 -0
- package/tests/read-subagent-model.mjs +24 -0
- package/tests/run-script-tests.py +97 -0
- package/tests/safe-steer.test.mjs +59 -0
- package/tests/strip_comments.test.mjs +164 -0
- package/tests/test_actor_failed.py +92 -0
- package/tests/test_compile_warnings.py +99 -0
- package/tests/test_debug_log_bus.py +108 -0
- package/tests/test_debugger_module_mode.py +141 -0
- package/tests/test_error_buckets.py +117 -0
- package/tests/test_error_dispatcher.py +261 -0
- package/tests/test_exec_ai_retry.py +155 -0
- package/tests/test_exec_human_retry.py +159 -0
- package/tests/test_file_resolve.py +104 -0
- package/tests/test_flow_events.py +311 -0
- package/tests/test_flow_ref_validation.py +92 -0
- package/tests/test_func_dict_fallback.py +39 -0
- package/tests/test_job_lifecycle.py +236 -0
- package/tests/test_job_manager.py +424 -0
- package/tests/test_mind.py +99 -0
- package/tests/test_module_call_args.py +258 -0
- package/tests/test_module_visibility.py +238 -0
- package/tests/test_notice.py +143 -0
- package/tests/test_out_whitelist.py +83 -0
- package/tests/test_par_if_dispatch.py +64 -0
- package/tests/test_par_nested_for.py +78 -0
- package/tests/test_parser.py +494 -0
- package/tests/test_pause.py +102 -0
- package/tests/test_pause_contract.py +135 -0
- package/tests/test_protocol_transcript.py +158 -0
- package/tests/test_scope_self.py +202 -0
- package/tests/test_source_validate.py +113 -0
- package/tests/test_task_world.py +447 -0
- package/tests/test_town_structure.py +70 -0
- package/tests/test_v2_checkpoint.py +115 -0
- package/tests/test_v2_env.py +383 -0
- package/tests/test_v2_evaluator.py +227 -0
- package/tests/test_v2_join.py +315 -0
- package/tests/test_v2_join_wiring.py +429 -0
- package/tests/test_v2_merge.py +167 -0
- package/tests/test_v2_model.py +143 -0
- package/tests/test_v2_resume_e2e.py +472 -0
- package/tests/test_var_decls.py +271 -0
- package/tests/verify-model-functions.mjs +90 -0
- package/tests/verify-subagent-model-3081.mjs +153 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225/node-notice-/346/226/275/345/267/245/346/270/205/345/215/225.md +395 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//344/270/244/344/270/252/345/276/205/350/247/243/345/206/263/347/232/204/351/227/256/351/242/230.MD +66 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/201/234/346/255/242/351/223/276/344/277/256/345/244/215-/346/226/275/345/267/245/346/270/205/345/215/225.md +475 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/217/230/351/207/217/344/270/216task/347/263/273/347/273/237/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225-v2.md +847 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//350/277/220/350/241/214/347/212/266/346/200/201/351/223/276/350/267/257/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225v4.md +654 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//351/224/231/350/257/257/346/263/250/345/205/245/347/273/255/350/201/212-/346/226/275/345/267/245/346/270/205/345/215/225.md +471 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""ErrorDispatcher 单元测试(2026-09-05 错误链路重构,施工清单 v4 §11)。
|
|
2
|
+
|
|
3
|
+
三桶裁决与信号契约(2026-09-05 猫猫实测修订:报错即通知作者):
|
|
4
|
+
- FATAL → notify_author{severity:'fatal'} + VERDICT_FATAL
|
|
5
|
+
- AGENT 未超限 → ai_retry(显示行)+ node_retry(行为信号)
|
|
6
|
+
+ notify_author{severity:'agent_error'}(报错即通知作者,与重试并行)
|
|
7
|
+
+ VERDICT_RETRY
|
|
8
|
+
- AGENT 超限 → notify_author{severity:'agent_giveup'} + VERDICT_EXHAUSTED
|
|
9
|
+
- TOLERANT → 静默 + VERDICT_TOLERANT
|
|
10
|
+
- WARNING(2026-09-07)→ notify_author{severity:'warning'} + VERDICT_WARN,
|
|
11
|
+
无计数无重试信号(warn() 便捷入口)
|
|
12
|
+
- wait_key 计数隔离(同 node 不同 wait_key 各自计数 = par 语义锁定)
|
|
13
|
+
- reset 每场清零
|
|
14
|
+
- compose_message 两 target 文案
|
|
15
|
+
"""
|
|
16
|
+
import pytest
|
|
17
|
+
|
|
18
|
+
from femoCompiler.FEMO_errors import (
|
|
19
|
+
AGENT_RETRY_EVENT,
|
|
20
|
+
ErrorCategory,
|
|
21
|
+
FEMOConfigError,
|
|
22
|
+
FEMOTransientError,
|
|
23
|
+
FEEDBACK_TARGET_AI,
|
|
24
|
+
FEEDBACK_TARGET_HUMAN,
|
|
25
|
+
NOTIFY_AUTHOR_EVENT,
|
|
26
|
+
NODE_SETTLED_EVENT,
|
|
27
|
+
VERDICT_EXHAUSTED,
|
|
28
|
+
VERDICT_FATAL,
|
|
29
|
+
VERDICT_RETRY,
|
|
30
|
+
VERDICT_TOLERANT,
|
|
31
|
+
ErrorDispatcher,
|
|
32
|
+
build_dispatcher,
|
|
33
|
+
classify_error,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FakeRunner:
|
|
38
|
+
"""假 runner:只实现 dispatcher 依赖的 _emit_event,收事件供断言。"""
|
|
39
|
+
|
|
40
|
+
def __init__(self):
|
|
41
|
+
self.events = []
|
|
42
|
+
|
|
43
|
+
def _emit_event(self, event_type, data):
|
|
44
|
+
self.events.append((event_type, data))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def emitted(runner, event_type):
|
|
48
|
+
return [d for t, d in runner.events if t == event_type]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class TestClassifyUnchanged:
|
|
52
|
+
"""既有 classify 用例原样(v4 §3.1:保留不变)。"""
|
|
53
|
+
|
|
54
|
+
def test_transient_is_agent(self):
|
|
55
|
+
assert classify_error(FEMOTransientError("限流")) == ErrorCategory.AGENT
|
|
56
|
+
|
|
57
|
+
def test_config_is_fatal(self):
|
|
58
|
+
assert classify_error(FEMOConfigError("无 key")) == ErrorCategory.FATAL
|
|
59
|
+
|
|
60
|
+
def test_unknown_is_fatal(self):
|
|
61
|
+
assert classify_error(RuntimeError("未知")) == ErrorCategory.FATAL
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class TestFatalDispatch:
|
|
65
|
+
def test_fatal_emits_notify_author_and_verdict(self):
|
|
66
|
+
r = FakeRunner()
|
|
67
|
+
d = build_dispatcher(r)
|
|
68
|
+
verdict = d.dispatch(FEMOConfigError("无 key"), "[X]", bucket=ErrorCategory.FATAL,
|
|
69
|
+
ai_name="@a", target=FEEDBACK_TARGET_AI)
|
|
70
|
+
assert verdict == VERDICT_FATAL
|
|
71
|
+
notes = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
72
|
+
assert len(notes) == 1
|
|
73
|
+
assert notes[0]["severity"] == "fatal"
|
|
74
|
+
assert "无 key" in notes[0]["message"]
|
|
75
|
+
assert notes[0]["node_name"] == "[X]"
|
|
76
|
+
assert notes[0]["ai_name"] == "@a"
|
|
77
|
+
# FATAL 不发 node_retry
|
|
78
|
+
assert emitted(r, AGENT_RETRY_EVENT) == []
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class TestAgentDispatch:
|
|
82
|
+
def test_within_limit_emits_both_signals(self):
|
|
83
|
+
r = FakeRunner()
|
|
84
|
+
d = build_dispatcher(r)
|
|
85
|
+
verdict = d.dispatch(None, "[X]", errors=["变量 'k' 未声明"], wait_key="ai_[X]_1",
|
|
86
|
+
ai_name="@a", max_retries=2, target=FEEDBACK_TARGET_AI)
|
|
87
|
+
assert verdict == VERDICT_RETRY
|
|
88
|
+
retries = emitted(r, AGENT_RETRY_EVENT)
|
|
89
|
+
assert len(retries) == 1
|
|
90
|
+
payload = retries[0]
|
|
91
|
+
assert payload["node_name"] == "[X]"
|
|
92
|
+
assert payload["wait_key"] == "ai_[X]_1"
|
|
93
|
+
assert payload["ai_name"] == "@a"
|
|
94
|
+
assert payload["target"] == "ai"
|
|
95
|
+
assert payload["attempt"] == 1
|
|
96
|
+
assert payload["max_attempts"] == 2
|
|
97
|
+
assert "未声明" in payload["feedback"]
|
|
98
|
+
assert payload["error"] == ["变量 'k' 未声明"]
|
|
99
|
+
# 显示行 ai_retry 同发(target='ai' 时)
|
|
100
|
+
show = emitted(r, "ai_retry")
|
|
101
|
+
assert len(show) == 1 and show[0]["attempt"] == 1
|
|
102
|
+
# 报错即通知作者(2026-09-05 修订):重试的同时发 agent_error
|
|
103
|
+
notes = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
104
|
+
assert len(notes) == 1
|
|
105
|
+
assert notes[0]["severity"] == "agent_error"
|
|
106
|
+
assert "未声明" in notes[0]["message"]
|
|
107
|
+
assert "第 1/2 次反馈" in notes[0]["message"]
|
|
108
|
+
|
|
109
|
+
def test_human_target_has_no_ai_retry_row(self):
|
|
110
|
+
"""human 的重试只有 node_retry(显示由宿主投影窗提醒承担,无 ai_retry 行)。"""
|
|
111
|
+
r = FakeRunner()
|
|
112
|
+
d = build_dispatcher(r)
|
|
113
|
+
verdict = d.dispatch(None, "[H]", errors=["未声明"], wait_key="human_[H]_1",
|
|
114
|
+
max_retries=2, target=FEEDBACK_TARGET_HUMAN)
|
|
115
|
+
assert verdict == VERDICT_RETRY
|
|
116
|
+
assert emitted(r, "ai_retry") == []
|
|
117
|
+
assert emitted(r, AGENT_RETRY_EVENT)[0]["target"] == "human"
|
|
118
|
+
assert "你的输入未被接受" in emitted(r, AGENT_RETRY_EVENT)[0]["feedback"]
|
|
119
|
+
|
|
120
|
+
def test_exhausted_emits_giveup(self):
|
|
121
|
+
r = FakeRunner()
|
|
122
|
+
d = build_dispatcher(r)
|
|
123
|
+
verdicts = [d.dispatch(None, "[X]", errors=["错"], wait_key="ai_[X]_1",
|
|
124
|
+
max_retries=2, target=FEEDBACK_TARGET_AI) for _ in range(3)]
|
|
125
|
+
assert verdicts == [VERDICT_RETRY, VERDICT_RETRY, VERDICT_EXHAUSTED]
|
|
126
|
+
gives = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
127
|
+
# 报错即通知:前两轮 agent_error(与重试并行)+ 超限轮 agent_giveup
|
|
128
|
+
assert [g["severity"] for g in gives] == ["agent_error", "agent_error", "agent_giveup"]
|
|
129
|
+
assert "重试 2 次仍未通过" in gives[2]["message"]
|
|
130
|
+
assert "第 1/2 次反馈" in gives[0]["message"]
|
|
131
|
+
# 超限轮不再发 ai_retry(现状语义:最后一轮 break 前 emit 只有两轮)
|
|
132
|
+
assert len(emitted(r, "ai_retry")) == 2
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class TestWaitKeyIsolation:
|
|
136
|
+
def test_same_node_different_wait_keys_count_independently(self):
|
|
137
|
+
"""par 语义锁定:循环体各分支 node id 相同、wait_key 不同——计数互不抢占。"""
|
|
138
|
+
r = FakeRunner()
|
|
139
|
+
d = build_dispatcher(r)
|
|
140
|
+
v1 = d.dispatch(None, "[P]", errors=["e1"], wait_key="ai_[P]_1", max_retries=1)
|
|
141
|
+
v2 = d.dispatch(None, "[P]", errors=["e2"], wait_key="ai_[P]_2", max_retries=1)
|
|
142
|
+
v3 = d.dispatch(None, "[P]", errors=["e3"], wait_key="ai_[P]_1", max_retries=1)
|
|
143
|
+
assert (v1, v2, v3) == (VERDICT_RETRY, VERDICT_RETRY, VERDICT_EXHAUSTED)
|
|
144
|
+
|
|
145
|
+
def test_fallback_to_node_id_when_wait_key_empty(self):
|
|
146
|
+
r = FakeRunner()
|
|
147
|
+
d = build_dispatcher(r)
|
|
148
|
+
# wait_key 空 → 计数键回退 node_id(同一节点连续计数)
|
|
149
|
+
assert d.dispatch(None, "[X]", errors=["e"], max_retries=1) == VERDICT_RETRY
|
|
150
|
+
assert d.dispatch(None, "[X]", errors=["e"], max_retries=1) == VERDICT_EXHAUSTED
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class TestReset:
|
|
154
|
+
def test_reset_clears_counts(self):
|
|
155
|
+
r = FakeRunner()
|
|
156
|
+
d = build_dispatcher(r)
|
|
157
|
+
assert d.dispatch(None, "[X]", errors=["e"], wait_key="k", max_retries=1) == VERDICT_RETRY
|
|
158
|
+
d.reset()
|
|
159
|
+
assert d.dispatch(None, "[X]", errors=["e"], wait_key="k", max_retries=1) == VERDICT_RETRY
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class TestTolerant:
|
|
163
|
+
def test_tolerant_is_silent(self):
|
|
164
|
+
r = FakeRunner()
|
|
165
|
+
d = build_dispatcher(r)
|
|
166
|
+
verdict = d.dispatch(None, "[X]", bucket=ErrorCategory.TOLERANT)
|
|
167
|
+
assert verdict == VERDICT_TOLERANT
|
|
168
|
+
assert r.events == []
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class TestWarningBucket:
|
|
172
|
+
"""WARNING 桶(2026-09-07):值得作者知道但不拒绝任何东西——运行照常。
|
|
173
|
+
|
|
174
|
+
与 AGENT 的分界:AGENT 拒绝本轮输出并触发重试;WARNING 什么都不拒绝、
|
|
175
|
+
无计数、无 node_retry/ai_retry,只发 notify_author{severity:'warning'}。"""
|
|
176
|
+
|
|
177
|
+
def test_warn_emits_notify_author_warning(self):
|
|
178
|
+
r = FakeRunner()
|
|
179
|
+
d = build_dispatcher(r)
|
|
180
|
+
d.warn("迭代器不是列表", node_id="[F]", ai_name="@a")
|
|
181
|
+
notes = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
182
|
+
assert len(notes) == 1
|
|
183
|
+
assert notes[0]["severity"] == "warning"
|
|
184
|
+
assert notes[0]["node_name"] == "[F]"
|
|
185
|
+
assert notes[0]["ai_name"] == "@a"
|
|
186
|
+
assert notes[0]["message"] == "剧本警告 @ 节点 [F](@a):迭代器不是列表"
|
|
187
|
+
|
|
188
|
+
def test_warn_without_node_has_no_at_tail(self):
|
|
189
|
+
r = FakeRunner()
|
|
190
|
+
d = build_dispatcher(r)
|
|
191
|
+
d.warn("断点续跑变量补种")
|
|
192
|
+
notes = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
193
|
+
assert notes[0]["message"] == "剧本警告:断点续跑变量补种"
|
|
194
|
+
|
|
195
|
+
def test_warn_does_not_touch_retry_counts(self):
|
|
196
|
+
r = FakeRunner()
|
|
197
|
+
d = build_dispatcher(r)
|
|
198
|
+
d.warn("w1", node_id="[X]")
|
|
199
|
+
d.warn("w2", node_id="[X]")
|
|
200
|
+
# 警告不占 AGENT 桶的 wait_key 计数:之后 AGENT 首次反馈仍是 attempt=1。
|
|
201
|
+
d.dispatch(None, "[X]", errors=["e"], wait_key="k", max_retries=1)
|
|
202
|
+
notes = [n for n in emitted(r, NOTIFY_AUTHOR_EVENT) if n["severity"] == "agent_error"]
|
|
203
|
+
assert len(notes) == 1
|
|
204
|
+
assert "第 1/1 次反馈" in notes[0]["message"]
|
|
205
|
+
|
|
206
|
+
def test_warn_emits_no_retry_signals(self):
|
|
207
|
+
r = FakeRunner()
|
|
208
|
+
d = build_dispatcher(r)
|
|
209
|
+
d.warn("w", node_id="[X]")
|
|
210
|
+
assert emitted(r, AGENT_RETRY_EVENT) == []
|
|
211
|
+
assert [t for t, _ in r.events if t == "node_retry"] == []
|
|
212
|
+
|
|
213
|
+
def test_warn_empty_message_is_noop(self):
|
|
214
|
+
r = FakeRunner()
|
|
215
|
+
d = build_dispatcher(r)
|
|
216
|
+
d.warn(" ")
|
|
217
|
+
assert r.events == []
|
|
218
|
+
|
|
219
|
+
def test_dispatch_warning_bucket_routes_to_warn(self):
|
|
220
|
+
from femoCompiler.FEMO_errors import VERDICT_WARN
|
|
221
|
+
r = FakeRunner()
|
|
222
|
+
d = build_dispatcher(r)
|
|
223
|
+
verdict = d.dispatch(None, "[X]", bucket=ErrorCategory.WARNING,
|
|
224
|
+
errors=["something odd"])
|
|
225
|
+
assert verdict == VERDICT_WARN
|
|
226
|
+
notes = emitted(r, NOTIFY_AUTHOR_EVENT)
|
|
227
|
+
assert notes[0]["severity"] == "warning"
|
|
228
|
+
assert "something odd" in notes[0]["message"]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class TestComposeMessage:
|
|
232
|
+
def test_ai_template(self):
|
|
233
|
+
d = build_dispatcher(FakeRunner())
|
|
234
|
+
msg = d.compose_message(node_id="[X]", errors=["a错", "b错"], bucket=ErrorCategory.AGENT,
|
|
235
|
+
attempt=1, max_attempts=2, ai_name="@a", target=FEEDBACK_TARGET_AI)
|
|
236
|
+
assert msg == "剧本错误(agent桶)@ 节点 [X](@a):a错; b错(第 1/2 次反馈)"
|
|
237
|
+
|
|
238
|
+
def test_human_template(self):
|
|
239
|
+
d = build_dispatcher(FakeRunner())
|
|
240
|
+
msg = d.compose_message(node_id="[H]", errors=["未声明"], bucket=ErrorCategory.AGENT,
|
|
241
|
+
target=FEEDBACK_TARGET_HUMAN)
|
|
242
|
+
assert msg == "你的输入未被接受:未声明。请修正后重新输入。"
|
|
243
|
+
|
|
244
|
+
def test_human_giveup_template(self):
|
|
245
|
+
d = build_dispatcher(FakeRunner())
|
|
246
|
+
msg = d.compose_message(node_id="[H]", errors=["未声明"], bucket=ErrorCategory.AGENT,
|
|
247
|
+
attempt=3, max_attempts=2, target=FEEDBACK_TARGET_HUMAN)
|
|
248
|
+
assert msg == "你的输入未被接受:未声明。已重试 2 次仍未通过,本节点按结束继续。"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class TestConstants:
|
|
252
|
+
"""事件名与 verdict 常量契约(宿主按字符串路由,改名=断链)。"""
|
|
253
|
+
|
|
254
|
+
def test_event_names(self):
|
|
255
|
+
assert AGENT_RETRY_EVENT == "node_retry"
|
|
256
|
+
assert NOTIFY_AUTHOR_EVENT == "notify_author"
|
|
257
|
+
assert NODE_SETTLED_EVENT == "node_settled"
|
|
258
|
+
|
|
259
|
+
def test_targets(self):
|
|
260
|
+
assert FEEDBACK_TARGET_AI == "ai"
|
|
261
|
+
assert FEEDBACK_TARGET_HUMAN == "human"
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""_exec_ai 重试环契约测试(2026-09-05 错误链路重构,施工清单 v4 §11)。
|
|
2
|
+
|
|
3
|
+
进程内构造 FEMORunner,mock _invoke_ai_llm(零 LLM)。AI 调用层首个
|
|
4
|
+
pytest 覆盖(此前 304 用例测的是 parser/vars/join,_invoke_ai_llm 零覆盖)。
|
|
5
|
+
|
|
6
|
+
锁定契约:
|
|
7
|
+
- 两轮非法赋值 + 第三轮合法 → node_retry ×2 + notify_author(agent_error) ×2
|
|
8
|
+
(报错即通知作者,2026-09-05 修订)+ 正常落盘 + node_settled(ok)
|
|
9
|
+
- 用尽 → notify_author ×3(2×agent_error + 1×agent_giveup)+ 落盘最后轮
|
|
10
|
+
output + node_settled(gave_up) + flow_done
|
|
11
|
+
- emit_request 仅首轮 True(ai_request 只发一次——重试轮静默等同一 wait_key)
|
|
12
|
+
- 全部重试轮共用同一 wait_key(宿主 parker 锚点)
|
|
13
|
+
"""
|
|
14
|
+
import asyncio
|
|
15
|
+
|
|
16
|
+
import pytest
|
|
17
|
+
|
|
18
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
19
|
+
from femoCompiler.FEMO_runtime import FEMORunner
|
|
20
|
+
|
|
21
|
+
AI_RETRY_FEMO = """meta:
|
|
22
|
+
name = ai-retry-test
|
|
23
|
+
session = new
|
|
24
|
+
actors:
|
|
25
|
+
ai @a = soul:the1stlittlesoul
|
|
26
|
+
vars:
|
|
27
|
+
score = 0
|
|
28
|
+
action act @ai(@a):
|
|
29
|
+
prompt: 输出赋值
|
|
30
|
+
out: score
|
|
31
|
+
mainflow:
|
|
32
|
+
[START] -> act -> [END]
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build_runner(events):
|
|
37
|
+
"""进程内 FEMORunner:事件回调收集到 events 列表。"""
|
|
38
|
+
script = parse_script(AI_RETRY_FEMO, base_dir=".")
|
|
39
|
+
return FEMORunner(script, base_dir=".", verbose=False,
|
|
40
|
+
event_callback=lambda t, d: events.append({"event": t, "data": d or {}}))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def ev(events, name):
|
|
44
|
+
return [e["data"] for e in events if e["event"] == name]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _ScriptedLlm:
|
|
48
|
+
"""_invoke_ai_llm 替身:依次返回预设输出,记录 (wait_key, emit_request)。
|
|
49
|
+
emit_request=True 时模拟原方法 dsh 分支发一条 ai_request(供事件流断言)——
|
|
50
|
+
替身整体替换了方法体,引擎内真正的 ai_request emit 不会发生。"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, outputs, events=None):
|
|
53
|
+
self.outputs = list(outputs)
|
|
54
|
+
self.calls = []
|
|
55
|
+
self._events = events
|
|
56
|
+
|
|
57
|
+
async def __call__(self, blocks, ad, eparam, actor_info, scope_info,
|
|
58
|
+
node_id, ai_name='', wait_key='', emit_request=True):
|
|
59
|
+
self.calls.append({"wait_key": wait_key, "emit_request": emit_request})
|
|
60
|
+
if emit_request and self._events is not None:
|
|
61
|
+
self._events.append({"event": "ai_request",
|
|
62
|
+
"data": {"wait_key": wait_key, "node_name": node_id}})
|
|
63
|
+
item = self.outputs.pop(0)
|
|
64
|
+
if isinstance(item, Exception):
|
|
65
|
+
raise item
|
|
66
|
+
return item
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def run(runner):
|
|
70
|
+
asyncio.run(runner.run_async())
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TestExecAiRetry:
|
|
74
|
+
|
|
75
|
+
def test_two_bad_then_good(self):
|
|
76
|
+
"""两轮非法赋值 + 第三轮合法:node_retry ×2 + 正常落盘 + node_settled(ok)。"""
|
|
77
|
+
events = []
|
|
78
|
+
runner = build_runner(events)
|
|
79
|
+
llm = _ScriptedLlm([
|
|
80
|
+
"台词一 SET VARIABLE: <<wrong_var = 1>>",
|
|
81
|
+
"台词二 SET VARIABLE: <<wrong_var = 2>>",
|
|
82
|
+
"台词三 SET VARIABLE: <<score = 3>>",
|
|
83
|
+
], events)
|
|
84
|
+
runner._invoke_ai_llm = llm
|
|
85
|
+
run(runner)
|
|
86
|
+
types = [e["event"] for e in events]
|
|
87
|
+
assert "flow_error" not in types, ev(events, "flow_error")
|
|
88
|
+
assert "flow_done" in types
|
|
89
|
+
|
|
90
|
+
retries = ev(events, "node_retry")
|
|
91
|
+
assert len(retries) == 2, f"应恰好两次 node_retry: {retries}"
|
|
92
|
+
assert all(r["target"] == "ai" for r in retries)
|
|
93
|
+
assert [r["attempt"] for r in retries] == [1, 2]
|
|
94
|
+
assert retries[0]["max_attempts"] == 2
|
|
95
|
+
assert "out" in retries[0]["error"][0], f"错误应提到 out 白名单: {retries[0]['error']}"
|
|
96
|
+
# 全部轮共用同一 wait_key(parker 锚点)
|
|
97
|
+
assert len({r["wait_key"] for r in retries}) == 1
|
|
98
|
+
assert retries[0]["wait_key"] == llm.calls[0]["wait_key"]
|
|
99
|
+
|
|
100
|
+
# 报错即通知作者(2026-09-05 修订):两轮重试各一条 agent_error
|
|
101
|
+
notes = ev(events, "notify_author")
|
|
102
|
+
assert len(notes) == 2, f"应恰好两条 agent_error: {notes}"
|
|
103
|
+
assert all(n["severity"] == "agent_error" for n in notes)
|
|
104
|
+
assert [n["node_name"] for n in notes] == ["[act]", "[act]"]
|
|
105
|
+
|
|
106
|
+
settled = ev(events, "node_settled")
|
|
107
|
+
assert len(settled) == 1
|
|
108
|
+
assert settled[0]["outcome"] == "ok"
|
|
109
|
+
assert settled[0]["wait_key"] == llm.calls[0]["wait_key"]
|
|
110
|
+
|
|
111
|
+
def test_exhausted_gives_up_gracefully(self):
|
|
112
|
+
"""三轮全非法:notify_author(agent_giveup) + 落盘最后轮 output + node_settled(gave_up)。"""
|
|
113
|
+
events = []
|
|
114
|
+
runner = build_runner(events)
|
|
115
|
+
llm = _ScriptedLlm([
|
|
116
|
+
"错一 SET VARIABLE: <<wrong_var = 1>>",
|
|
117
|
+
"错二 SET VARIABLE: <<wrong_var = 2>>",
|
|
118
|
+
"错三 SET VARIABLE: <<wrong_var = 3>>",
|
|
119
|
+
])
|
|
120
|
+
runner._invoke_ai_llm = llm
|
|
121
|
+
run(runner)
|
|
122
|
+
types = [e["event"] for e in events]
|
|
123
|
+
assert "flow_error" not in types, ev(events, "flow_error")
|
|
124
|
+
assert "flow_done" in types, "用尽后应宽容继续跑完(现状语义)"
|
|
125
|
+
|
|
126
|
+
gives = ev(events, "notify_author")
|
|
127
|
+
# 报错即通知:前两轮 agent_error + 超限轮 agent_giveup(共 3 条)
|
|
128
|
+
assert [g["severity"] for g in gives] == ["agent_error", "agent_error", "agent_giveup"]
|
|
129
|
+
assert gives[2]["node_name"] == "[act]"
|
|
130
|
+
assert "已重试" in gives[2]["message"] or "重试 2 次仍未通过" in gives[2]["message"]
|
|
131
|
+
|
|
132
|
+
settled = ev(events, "node_settled")
|
|
133
|
+
assert len(settled) == 1 and settled[0]["outcome"] == "gave_up"
|
|
134
|
+
|
|
135
|
+
# 落盘 = 最后轮 output(P6:最后轮 output 照落)
|
|
136
|
+
done = ev(events, "ai_done")
|
|
137
|
+
assert done and done[0]["output"].startswith("错三")
|
|
138
|
+
|
|
139
|
+
def test_emit_request_only_first_attempt(self):
|
|
140
|
+
"""ai_request 只发一次:emit_request 首轮 True、重试轮 False。"""
|
|
141
|
+
events = []
|
|
142
|
+
runner = build_runner(events)
|
|
143
|
+
llm = _ScriptedLlm([
|
|
144
|
+
"一 SET VARIABLE: <<wrong_var = 1>>",
|
|
145
|
+
"二 SET VARIABLE: <<score = 2>>",
|
|
146
|
+
], events)
|
|
147
|
+
runner._invoke_ai_llm = llm
|
|
148
|
+
run(runner)
|
|
149
|
+
# ai_request 只出现一次(替身在 emit_request=True 时模拟发出)
|
|
150
|
+
requests = ev(events, "ai_request")
|
|
151
|
+
assert len(requests) == 1, f"ai_request 应只发一次: {len(requests)}"
|
|
152
|
+
# mock 收到的 emit_request 序列
|
|
153
|
+
assert [c["emit_request"] for c in llm.calls] == [True, False]
|
|
154
|
+
# 两轮 wait_key 一致
|
|
155
|
+
assert llm.calls[0]["wait_key"] == llm.calls[1]["wait_key"]
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""_exec_human 重试环契约测试(2026-09-05 错误链路重构,施工清单 v4 §11,裁决④)。
|
|
2
|
+
|
|
3
|
+
human 与 ai 全节点统一走 ErrorDispatcher:非法输入 → node_retry(target='human')
|
|
4
|
+
→ 同 wait_key 重等(既有重等分支原样);连续非法到上限 → notify_author +
|
|
5
|
+
node_settled(gave_up) + 超时放行同款收尾(空输入只落 show 行)。
|
|
6
|
+
mind=委派语法糖零特判:@mind(human 执行者) 自动继承同一路径。
|
|
7
|
+
"""
|
|
8
|
+
import asyncio
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
13
|
+
from femoCompiler.FEMO_runtime import FEMORunner
|
|
14
|
+
|
|
15
|
+
HUMAN_RETRY_FEMO = """meta:
|
|
16
|
+
name = human-retry-test
|
|
17
|
+
session = new
|
|
18
|
+
actors:
|
|
19
|
+
human @p = soul:human, source:0
|
|
20
|
+
vars:
|
|
21
|
+
player_choice = ""
|
|
22
|
+
action accept @human(@p):
|
|
23
|
+
prompt: "选一个"
|
|
24
|
+
scope: [@p]
|
|
25
|
+
out:
|
|
26
|
+
player_choice(dropdown, choices={["A", "B"]}, label="选择")
|
|
27
|
+
action after @assign:
|
|
28
|
+
out: player_choice += "!"
|
|
29
|
+
mainflow:
|
|
30
|
+
[START] -> accept -> [END]
|
|
31
|
+
[accept]: accept
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
MIND_HUMAN_RETRY_FEMO = """meta:
|
|
35
|
+
name = mind-human-retry-test
|
|
36
|
+
session = new
|
|
37
|
+
actors:
|
|
38
|
+
human @p = soul:human, source:0
|
|
39
|
+
vars:
|
|
40
|
+
player_choice = ""
|
|
41
|
+
@seer = @p
|
|
42
|
+
action seer_check @mind(@seer):
|
|
43
|
+
prompt: "选一个"
|
|
44
|
+
out:
|
|
45
|
+
player_choice(dropdown, choices={["A", "B"]}, label="选择")
|
|
46
|
+
mainflow:
|
|
47
|
+
[START] -> seer_check -> [END]
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_runner(femo_text, events):
|
|
52
|
+
script = parse_script(femo_text, base_dir=".")
|
|
53
|
+
runner = FEMORunner(script, base_dir=".", verbose=False,
|
|
54
|
+
event_callback=lambda t, d: events.append({"event": t, "data": d or {}}))
|
|
55
|
+
# FastAPI 模式桩:_human_input_event 非 None → _exec_human 走前端输入分支
|
|
56
|
+
runner._human_input_event = object()
|
|
57
|
+
return runner
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class _ScriptedInputs:
|
|
61
|
+
"""engine.human_input 替身:wait_for_input 依次弹出预设输入(记录 wait_key)。"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, inputs):
|
|
64
|
+
self.inputs = list(inputs)
|
|
65
|
+
self.keys = []
|
|
66
|
+
|
|
67
|
+
async def wait_for_input(self, key, timeout=None):
|
|
68
|
+
self.keys.append(key)
|
|
69
|
+
item = self.inputs.pop(0)
|
|
70
|
+
if isinstance(item, Exception):
|
|
71
|
+
raise item
|
|
72
|
+
return item
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def ev(events, name):
|
|
76
|
+
return [e["data"] for e in events if e["event"] == name]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def run(runner):
|
|
80
|
+
asyncio.run(runner.run_async())
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class TestExecHumanRetry:
|
|
84
|
+
|
|
85
|
+
def test_bad_input_then_retry(self):
|
|
86
|
+
"""非法输入 → node_retry(target='human') + 同 wait_key 重等 → 第二次合法 → ok。"""
|
|
87
|
+
events = []
|
|
88
|
+
runner = build_runner(HUMAN_RETRY_FEMO, events)
|
|
89
|
+
inputs = _ScriptedInputs([
|
|
90
|
+
{"chat_text": "", "variables": {"nope_undeclared": "x"}},
|
|
91
|
+
{"chat_text": "A", "variables": {"player_choice": "A"}},
|
|
92
|
+
])
|
|
93
|
+
runner.engine.human_input = inputs
|
|
94
|
+
run(runner)
|
|
95
|
+
types = [e["event"] for e in events]
|
|
96
|
+
assert "flow_error" not in types, ev(events, "flow_error")
|
|
97
|
+
assert "flow_done" in types
|
|
98
|
+
|
|
99
|
+
retries = ev(events, "node_retry")
|
|
100
|
+
assert len(retries) == 1, f"应恰好一次 node_retry: {retries}"
|
|
101
|
+
assert retries[0]["target"] == "human"
|
|
102
|
+
assert retries[0]["wait_key"] == inputs.keys[0], "重等必须用同一 wait_key"
|
|
103
|
+
assert "未声明" in retries[0]["error"][0]
|
|
104
|
+
assert "你的输入未被接受" in retries[0]["feedback"]
|
|
105
|
+
|
|
106
|
+
# 报错即通知作者(2026-09-05 修订):human 报错同样发 agent_error
|
|
107
|
+
notes = ev(events, "notify_author")
|
|
108
|
+
assert len(notes) == 1, f"应恰好一条 agent_error: {notes}"
|
|
109
|
+
assert notes[0]["severity"] == "agent_error"
|
|
110
|
+
assert "你的输入未被接受" in notes[0]["message"]
|
|
111
|
+
|
|
112
|
+
settled = ev(events, "node_settled")
|
|
113
|
+
assert len(settled) == 1 and settled[0]["outcome"] == "ok"
|
|
114
|
+
|
|
115
|
+
# human_input_error 已退役(裁决⑥)
|
|
116
|
+
assert ev(events, "human_input_error") == []
|
|
117
|
+
# 合法输入生效(assign 节点追加 "!")
|
|
118
|
+
assert ev(events, "human_done"), "human_done 应出现"
|
|
119
|
+
|
|
120
|
+
def test_exhausted_gives_up_with_timeout_style_finish(self):
|
|
121
|
+
"""连续非法到上限:notify_author + node_settled(gave_up) + 空输入收尾(P7)。"""
|
|
122
|
+
events = []
|
|
123
|
+
runner = build_runner(HUMAN_RETRY_FEMO, events)
|
|
124
|
+
bad = {"chat_text": "", "variables": {"nope_undeclared": "x"}}
|
|
125
|
+
inputs = _ScriptedInputs([bad, bad, bad])
|
|
126
|
+
runner.engine.human_input = inputs
|
|
127
|
+
run(runner)
|
|
128
|
+
types = [e["event"] for e in events]
|
|
129
|
+
assert "flow_error" not in types
|
|
130
|
+
assert "flow_done" in types, "上限后应超时放行同款收尾跑完"
|
|
131
|
+
|
|
132
|
+
gives = ev(events, "notify_author")
|
|
133
|
+
# 报错即通知:前两轮 agent_error + 超限轮 agent_giveup(共 3 条)
|
|
134
|
+
assert [g["severity"] for g in gives] == ["agent_error", "agent_error", "agent_giveup"]
|
|
135
|
+
assert "已重试 2 次仍未通过" in gives[2]["message"]
|
|
136
|
+
|
|
137
|
+
settled = ev(events, "node_settled")
|
|
138
|
+
assert len(settled) == 1 and settled[0]["outcome"] == "gave_up"
|
|
139
|
+
# 三轮都消费了输入(重等同 key ×2 + 首轮)
|
|
140
|
+
assert len(inputs.keys) == 3
|
|
141
|
+
assert len(set(inputs.keys)) == 1
|
|
142
|
+
|
|
143
|
+
def test_mind_human_executor_inherits_path(self):
|
|
144
|
+
"""mind 委派(human 执行者):非法输入走同一条 node_retry(target='human') 路径。"""
|
|
145
|
+
events = []
|
|
146
|
+
runner = build_runner(MIND_HUMAN_RETRY_FEMO, events)
|
|
147
|
+
inputs = _ScriptedInputs([
|
|
148
|
+
{"chat_text": "", "variables": {"nope_undeclared": "x"}},
|
|
149
|
+
{"chat_text": "B", "variables": {"player_choice": "B"}},
|
|
150
|
+
])
|
|
151
|
+
runner.engine.human_input = inputs
|
|
152
|
+
run(runner)
|
|
153
|
+
types = [e["event"] for e in events]
|
|
154
|
+
assert "flow_error" not in types
|
|
155
|
+
assert "flow_done" in types
|
|
156
|
+
retries = ev(events, "node_retry")
|
|
157
|
+
assert len(retries) == 1
|
|
158
|
+
assert retries[0]["target"] == "human"
|
|
159
|
+
assert ev(events, "node_settled")[0]["outcome"] == "ok"
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""todo #2:code/memory/context 的 file: 地址解析规则测试。
|
|
2
|
+
|
|
3
|
+
规则(用户拍板):
|
|
4
|
+
- 绝对路径 → 直接支持(无脑)
|
|
5
|
+
- 相对路径 → 相对剧本文件所在目录(base_dir)解析
|
|
6
|
+
- 未保存(base_dir 为空)→ 相对路径报错
|
|
7
|
+
- func_code 默认位置已取消
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
14
|
+
PYTHON_DIR = os.path.join(ROOT, "femoExamples")
|
|
15
|
+
if ROOT not in __import__("sys").path:
|
|
16
|
+
__import__("sys").path.insert(0, ROOT)
|
|
17
|
+
|
|
18
|
+
from femoCompiler.FEMO_runtime import PythonBridge # noqa: E402
|
|
19
|
+
from femoCompiler.block_collector import _load_file_or_text # noqa: E402
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# ── PythonBridge(code: 区 file: 解析) ────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
def test_bridge_absolute_path_works():
|
|
25
|
+
"""绝对路径:直接加载,与 base_dir 无关。"""
|
|
26
|
+
helper = os.path.join(PYTHON_DIR, "mt_test", "file_a.py")
|
|
27
|
+
bridge = PythonBridge(base_dir="") # 未保存态
|
|
28
|
+
mod = bridge.load("helper", helper)
|
|
29
|
+
assert mod is not None
|
|
30
|
+
assert bridge.has("helper.add")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_bridge_relative_resolves_against_script_dir():
|
|
34
|
+
"""相对路径:相对剧本文件所在目录(base_dir)。"""
|
|
35
|
+
bridge = PythonBridge(base_dir=os.path.join(PYTHON_DIR, "mt_test"))
|
|
36
|
+
mod = bridge.load("helper", "file_a.py")
|
|
37
|
+
assert bridge.has("helper.add")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_bridge_relative_unsaved_raises():
|
|
41
|
+
"""未保存(base_dir 空):相对路径报错,提示导出/绝对路径。"""
|
|
42
|
+
bridge = PythonBridge(base_dir="")
|
|
43
|
+
with pytest.raises(FileNotFoundError, match="剧本未保存"):
|
|
44
|
+
bridge.load("helper", "file_a.py")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_bridge_no_func_code_fallback():
|
|
48
|
+
"""func_code 默认位置已取消:相对路径不再回退 func_code 目录。"""
|
|
49
|
+
bridge = PythonBridge(base_dir=os.path.join(PYTHON_DIR, "mt_test"))
|
|
50
|
+
with pytest.raises(FileNotFoundError, match="文件不存在"):
|
|
51
|
+
bridge.load("nope", "definitely_missing_module.py")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# ── _load_file_or_text(meta 区 file: 解析) ───────────────────────────────
|
|
55
|
+
|
|
56
|
+
def test_load_file_absolute():
|
|
57
|
+
"""绝对路径直接读。"""
|
|
58
|
+
helper = os.path.join(PYTHON_DIR, "mt_test", "file_a.py")
|
|
59
|
+
content = _load_file_or_text(f'file:"{helper}"', base_dir="")
|
|
60
|
+
assert "file_a" in content
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_load_file_relative_script_dir():
|
|
64
|
+
"""相对路径基于剧本目录。"""
|
|
65
|
+
content = _load_file_or_text('file:"file_a.py"', base_dir=os.path.join(PYTHON_DIR, "mt_test"))
|
|
66
|
+
assert "file_a" in content
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_load_file_relative_unsaved_raises():
|
|
70
|
+
"""未保存(base_dir 空):相对路径报错。"""
|
|
71
|
+
with pytest.raises(FileNotFoundError, match="剧本未保存"):
|
|
72
|
+
_load_file_or_text('file:"file_a.py"', base_dir="")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_load_file_literal_untouched():
|
|
76
|
+
"""纯文本/字面量不受影响。"""
|
|
77
|
+
assert _load_file_or_text("hello world", base_dir="") == "hello world"
|
|
78
|
+
assert _load_file_or_text('"quoted"', base_dir="") == "quoted"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ── 端到端:bridge run 传空 base_dir(未保存态) → flow_error ─────────────
|
|
82
|
+
|
|
83
|
+
def test_unsaved_relative_script_fails_via_bridge(run_events):
|
|
84
|
+
"""未保存态(base_dir="")跑含相对 file: 的剧本 → flow_error 且提示。"""
|
|
85
|
+
femo = (
|
|
86
|
+
'meta:\n name = rel-unsaved\n'
|
|
87
|
+
'code:\n helper = file:"mt_test/file_a.py"\n'
|
|
88
|
+
'mainflow:\n [START] -> [END]\n'
|
|
89
|
+
)
|
|
90
|
+
events = run_events(femo, base_dir="")
|
|
91
|
+
errs = [e["data"].get("error", "") for e in events if e["event"] == "flow_error"]
|
|
92
|
+
assert errs, "应产生 flow_error"
|
|
93
|
+
assert "剧本未保存" in errs[0], errs[0]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_saved_relative_script_runs_via_bridge(run_events):
|
|
97
|
+
"""已保存态(base_dir=python 目录)跑相对 file: 剧本 → 正常跑完。"""
|
|
98
|
+
femo = (
|
|
99
|
+
'meta:\n name = rel-saved\n'
|
|
100
|
+
'code:\n helper = file:"mt_test/file_a.py"\n'
|
|
101
|
+
'mainflow:\n [START] -> [END]\n'
|
|
102
|
+
)
|
|
103
|
+
events = run_events(femo, base_dir=PYTHON_DIR)
|
|
104
|
+
assert any(e["event"] == "flow_done" for e in events), [e["event"] for e in events]
|