import AgentDeployPage from './AgentDeployPage.vue';
import type { AgentReq } from './agentDeploy.model';
// 请求æ•获(æµè§ˆå™¨ä¾§ï¼‰ï¼šCT ä¸èƒ½ Node ä¾§ import story(会连带转译 .vue 炸 esbuild),
// 所以 stub 里把请求挂 window.__agentCalls,spec 用 page.evaluate 读å–/清空。
function captureAgent(url: string, body: unknown): void {
const w = window as unknown as { __agentCalls?: Array<{ url: string; body: unknown }> };
w.__agentCalls = w.__agentCalls ?? [];
w.__agentCalls.push({ url, body });
}
// Index é¢„å¡«æ ·ä¾‹ï¼ˆWebApi :34-40 契约:{ serverUrl, downloadUrl })
const INDEX = { serverUrl: 'http://10.0.0.2:6600', downloadUrl: 'http://x.newlifex.com/star/' };
// éƒ¨ç½²ç»“æžœæ ·ä¾‹ï¼ˆWebApi :47-88 契约:List<AgentDeployResult>{host,success,message,output}):
// 1 æˆåŠŸï¼ˆæœ‰è¾“å‡ºï¼‰+ 1 失败(空输出),覆盖结果表åŒè‰²ä¸Žè¾“出弹窗两æ€
const DEPLOY_ROWS = [
{ host: '10.0.0.12', success: true, message: '部署æˆåŠŸ', output: 'StarAgent 安装完æˆ\næœåС已å¯åЍ' },
{ host: '10.0.0.13', success: false, message: 'SSH 连接失败: Connection refused', output: '' },
];
function baseReq(): AgentReq {
return async (opts) => {
if (opts.url === '/Nodes/AgentDeploy/Index') return { code: 0, data: INDEX };
return { code: 0, data: null };
};
}
// Default:Index 预填 + 测试连接æˆåŠŸ + 部署返回 1 æˆåŠŸ 1 失败(CT 在åŒå±é©±åЍ免æµç¨‹ï¼‰
function stubReqDefault(): AgentReq {
const base = baseReq();
return async (opts) => {
if (opts.url === '/Nodes/AgentDeploy/TestConnection') {
captureAgent(String(opts.url), (opts.data ?? {}) as unknown);
return { code: 0, data: { success: true, message: '连接æˆåŠŸï¼ŒStarServer å¯è¾¾' } };
}
if (opts.url === '/Nodes/AgentDeploy/Deploy') {
captureAgent(String(opts.url), opts.data);
return { code: 0, data: DEPLOY_ROWS };
}
return base(opts);
};
}
// TestFail:测试连接失败分支(data.success=false,åŽç«¯ message 原文é€å‡ºï¼‰
function stubReqTestFail(): AgentReq {
const base = baseReq();
return async (opts) => {
if (opts.url === '/Nodes/AgentDeploy/TestConnection') {
captureAgent(String(opts.url), (opts.data ?? {}) as unknown);
return { code: 0, data: { success: false, message: 'SSH 连接失败: Connection refused' } };
}
return base(opts);
};
}
// DeployWebNotImpl:executeOn=web 部署 → code=500 åŽç«¯æœªå®žçŽ°æ–‡æ¡ˆåŽŸæ ·é€å‡ºï¼ˆC09/C10)
function stubReqWebNotImpl(): AgentReq {
const base = baseReq();
return async (opts) => {
if (opts.url === '/Nodes/AgentDeploy/Deploy') {
captureAgent(String(opts.url), opts.data);
return { code: 500, message: 'StarWeb 本地执行暂未实现,请选择 StarServer 执行', data: null };
}
return base(opts);
};
}
export const stories = [
// ç©ºè¡¨å• + Index 预填:「已从æœåŠ¡ç«¯é¢„å¡«ã€æ ‡ + firstHost æç¤ºâ€”—CT 交互全æµç¨‹åœ¨æœ¬å±é©±åЍ
{ id: 'AgentDeployPage/Default', component: AgentDeployPage, props: { deps: { request: stubReqDefault() } } },
// æµ‹è¯•è¿žæŽ¥å¤±è´¥åˆ†æ”¯ï¼šçº¢æ¡ + åŽç«¯ message 原文
{ id: 'AgentDeployPage/TestFail', component: AgentDeployPage, props: { deps: { request: stubReqTestFail() } } },
// 部署 code=500:错误æ¡åŽŸæ–‡é€å‡ºï¼ˆweb 未实现ç‰ï¼‰
{ id: 'AgentDeployPage/DeployWebNotImpl', component: AgentDeployPage, props: { deps: { request: stubReqWebNotImpl() } } },
];
|