fix: file路由readFile改promise版 + 终端客户端自动聚焦(实机pwd已验证服务端通)

This commit is contained in:
Aisland
2026-08-17 20:45:29 +08:00
parent 825730c54c
commit f83aa1d589
5 changed files with 43 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
const WebSocket = require('ws');
const ws = new WebSocket('ws://127.0.0.1:3080/api/worktable/term?cwd=' + encodeURIComponent('E:/AI_Workspace') + '&cols=80&rows=24');
const received = [];
const timer = setTimeout(() => { console.log('RESULT: FAIL 15s 无任何输出'); process.exit(1); }, 15000);
ws.on('open', () => { console.log('WS_OPEN'); setTimeout(() => { console.log('SEND pwd'); ws.send('pwd\r'); }, 1500); });
ws.on('message', (d) => {
const t = String(d);
received.push(t);
console.log('FRAME[' + received.length + ']:', JSON.stringify(t.slice(0, 100)));
if (t.includes('E:\\AI_Workspace') || /[A-Za-z]:[\\/]/.test(t)) {
clearTimeout(timer);
console.log('RESULT: PASS pwd 真实回显 OK');
ws.close(); process.exit(0);
}
});
ws.on('close', (code) => { console.log('WS_CLOSE code=' + code); clearTimeout(timer); process.exit(0); });
ws.on('error', (e) => { console.log('WS_ERROR:', String(e)); clearTimeout(timer); process.exit(1); });
+7
View File
@@ -22,6 +22,13 @@ const WebSocket = require('ws');
const fakeReq = { [Symbol.asyncIterator]() { let done = false; return { next: () => (done ? Promise.resolve({ done: true }) : (done = true, Promise.resolve({ done: false, value: Buffer.from('{"path":"E:/AI_Workspace"}') }))) }; } };
await fsRoute.handler(fakeReq, fakeRes);
console.log('fs direct:', captured && captured.status, captured && captured.body ? captured.body.slice(0, 160) : '');
// file 路由直调(真实 README.md)
const fileRoute = routes.find((r) => r.path === '/api/worktable/file');
let fc = null;
const fRes = { writeHead: (s) => { fc = { status: s }; }, end: (b) => { fc.body = String(b); } };
const fReq = { url: '/api/worktable/file?path=' + encodeURIComponent('E:/AI_Workspace/DeepseekHarness/Projects/dsh-worktable/README.md') };
await fileRoute.handler(fReq, fRes);
console.log('file direct:', fc && fc.status, fc && fc.body ? fc.body.slice(0, 60) : '');
if (upgrades.length === 0) { console.log('RESULT: NO_TERMINAL_ROUTE'); process.exit(1); }
const server = http.createServer((req, res) => { res.writeHead(404); res.end(); });
server.on('upgrade', (req, socket, head) => {