refactor: 重构执行引擎为上下文驱动架构
- 优化 WorkflowExecutor 与 Exchange支持 ExecutionEnv 资源注入。 - 实现 Session 级别连接复用与变量池内存镜像化,消除重复 I/O 开销。 - 引入 ChainMap 实现动态上下文切换,解决参数化变量与全局提取变量的优先级覆盖。 - 完善变量提取与断言逻辑,确保跨用例变量流转的可靠性。
This commit is contained in:
40
core/context.py
Normal file
40
core/context.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei,ChenWei
|
||||
@Software: PyCharm
|
||||
@contact: t6g888@163.com
|
||||
@file: context
|
||||
@date: 2026/3/14 09:07
|
||||
@desc:
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Any
|
||||
from pathlib import Path
|
||||
|
||||
from core.exchange import Exchange
|
||||
from core.session import Session
|
||||
from commons.file_processors.yaml_processor import YamlProcessor
|
||||
|
||||
|
||||
class VariableStore:
|
||||
"""内存变量仓库:负责 L2 缓存与磁盘的唯一交互"""
|
||||
|
||||
def __init__(self, seed_file: Path):
|
||||
self.seed_file = seed_file
|
||||
self.processor = YamlProcessor(seed_file)
|
||||
# 启动时仅加载一次
|
||||
self.store: Dict[str, Any] = self.processor.load() or {}
|
||||
|
||||
def persist(self):
|
||||
"""测试结束时统一写盘"""
|
||||
self.processor.save(self.store)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExecutionEnv:
|
||||
"""环境上下文:持有共享资源"""
|
||||
session: Session
|
||||
store: VariableStore
|
||||
exchanger: "Exchange"
|
||||
Reference in New Issue
Block a user