fix: bastion script waits and keyboard-like sendLine (#1960) (#2055)

Keep only the confirmed product fixes for 奇安信-style auto-login:

1. Seed startup screen from viewport or live buffer so on-screen menus
   stay waitable (never mark the whole buffer consumed at script start).
2. sendLine emits body then CR separately, matching real keyboard input.
3. After sendLine, consume only pre-send buffer length so peer prompts
   that arrive between body and Enter remain matchable for the next step.
This commit is contained in:
陈大猫 authored and GitHub committed 2026-07-09 17:58:18 +08:00
1 parent ca0c59ff0c
commit 4735e9ace0
6 files changed
+244 -56

No files matched your search

+19 -1
View File
@@ -629,7 +629,25 @@ function createScriptRuntime(deps) {
await trackStep(`sendLine: ${truncateActivityLabel(line, 60)}`);
if (deps.isAborted?.()) return;
appendLog(runId, `→ ${line}`);
writeToSession(sessionId, `${line}\r`, { automated: true });
// Bastion menus can ignore a single "line\r" packet even when
// stream.write succeeds. Match xterm: body, then Enter (#1960).
// Consume only pre-send buffer length so prompts that arrive between
// body and CR stay waitable for the next step.
const buffer = getOutputBuffer(sessionId);
const lengthBeforeSend = buffer.getText().length;
if (line.length > 0) {
writeToSession(sessionId, line, {
automated: true,
invalidateStartupSeed: false,
});
await interruptibleSleep(30, deps.isAborted);
if (deps.isAborted?.()) return;
}
writeToSession(sessionId, "\r", {
automated: true,
invalidateStartupSeed: false,
});
buffer.consumeThroughAbsolute(lengthBeforeSend);
}));
},
waitFor(pattern, timeoutMs = 30000) {