#!/usr/bin/env python3 """E2E 分步执行:第1步创建+验证,第2步清理""" import json, httpx, uuid, sys, os, time sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from tests.conftest_auth import _get_token_from_auth_state STATE_FILE = os.path.join(os.path.dirname(__file__), '..', '.e2e_state.json') def load_state(): if os.path.exists(STATE_FILE): return json.load(open(STATE_FILE)) return {} def save_state(state): json.dump(state, open(STATE_FILE, 'w')) def get_client(): token = _get_token_from_auth_state() return httpx.Client(base_url='https://cloud-fat.d-robotics.cc', headers={'Authorization': token}, timeout=10) def step1_system_prompt(client): name = f'E2E_SPLIT_{uuid.uuid4().hex[:6]}' resp = client.post('/api/generationApi/systemPrompt/create', json={ 'name': name, 'description': 'E2E分步测试', 'prompt': 'test', 'permission': 'public' }) sp_id = resp.json().get('data', {}).get('id') print(f'[创建] 系统提示词: {name} (id={sp_id})') # 验证 detail = client.get(f'/api/generationApi/systemPrompt/{sp_id}').json() assert detail['status'] == 0 print(f'[验证] 详情: name={detail["data"]["name"]}') updated = client.put(f'/api/generationApi/systemPrompt/{sp_id}', json={ 'name': name + '_updated', 'description': 'updated', 'prompt': 'updated' }).json() assert updated['status'] == 0 print(f'[更新] OK') print(f'\n去平台验证: https://cloud-fat.d-robotics.cc/d-cloud/data-create/list') print(f'搜索: {name}_updated') return {'sp_id': sp_id} def step2_system_prompt(client, state): sp_id = state.get('sp_id') if sp_id: client.delete(f'/api/generationApi/systemPrompt/{sp_id}') print(f'[清理] 系统提示词 id={sp_id} 已删除') def step1_task(client): resp = client.post('/api/generationApi/comfyWorkflow/list', json={}) wf_id = resp.json()['data']['list'][0]['id'] name = f'E2E_SPLIT_{uuid.uuid4().hex[:6]}' resp2 = client.post('/api/generationApi/imgGeneration/task', json={ 'name': name, 'workflow_id': int(wf_id), 'batch_size': 1, 'instance_count': 1, 'cache_path': f'fattest/e2e_split_{uuid.uuid4().hex[:6]}', 'prompt_list': ['e2e split test'], 'expansion_param': {'prompt': 'test', 'system_prompt': ''}, 'resource_param': {'sku_id': 'a10690ab-816a-e350-0f00-b6f318ee86ee', 'queue_name': 'fattest-elastic', 'queue_type': 'elastic'} }) task_id = resp2.json().get('data', {}).get('task_id') or resp2.json().get('taskId') print(f'[创建] 任务: {name} (id={task_id})') detail = client.post(f'/api/generationApi/imgGeneration/task/{task_id}/detail', json={}).json() print(f'[验证] 详情获取成功') print(f'\n去平台验证: https://cloud-fat.d-robotics.cc/d-cloud/data-create/list') print(f'搜索: {name}') return {'task_id': task_id, 'wf_id': wf_id} def step2_task(client, state): task_id = state.get('task_id') if task_id: client.post(f'/api/generationApi/imgGeneration/task/{task_id}/stop', json={}) client.post(f'/api/generationApi/imgGeneration/task/{task_id}/delete', json={}) print(f'[清理] 任务 id={task_id} 已删除') def step1_dataspace(client): name = f'E2E_SPLIT_{uuid.uuid4().hex[:6]}' resp = client.post('/api/cloudDiskApi/spaces', json={'name': name, 'type': 'private'}) space_id = resp.json().get('data', {}).get('id') print(f'[创建] 数据空间: {name} (id={space_id})') client.post(f'/api/cloudDiskApi/files/{space_id}/folder', json={'name': 'e2e_test_folder'}) print(f'[验证] 已创建文件夹') print(f'\n去平台验证: https://cloud-fat.d-robotics.cc/d-cloud/data-space') print(f'搜索: {name}') return {'space_id': space_id} def step2_dataspace(client, state): space_id = state.get('space_id') if space_id: client.delete(f'/api/cloudDiskApi/spaces/{space_id}') print(f'[清理] 数据空间 id={space_id} 已删除') STEPS = { 'system_prompt': (step1_system_prompt, step2_system_prompt), 'task': (step1_task, step2_task), 'dataspace': (step1_dataspace, step2_dataspace), } if __name__ == '__main__': name = sys.argv[2] if len(sys.argv) > 2 else 'system_prompt' step = sys.argv[4] if len(sys.argv) > 4 else '1' client = get_client() if name not in STEPS: print(f'未知的 E2E: {name}') print(f'可用: {list(STEPS.keys())}') sys.exit(1) step1_fn, step2_fn = STEPS[name] if step == '1': state = step1_fn(client) save_state(state) print(f'\n第1步完成。数据已创建,去平台验证后运行第2步。') print(f'运行: python scripts/run_e2e_split.py --name {name} --step 2') elif step == '2': state = load_state() if not state: print('没有找到第1步的状态,请先运行第1步') sys.exit(1) step2_fn(client, state) save_state({}) print(f'\n第2步完成。数据已清理。')