fix: stabilize pty send-keys tests
This commit is contained in:
@@ -15,7 +15,7 @@ test("process send-keys encodes Enter for pty sessions", async () => {
|
||||
const processTool = createProcessTool();
|
||||
const result = await execTool.execute("toolcall", {
|
||||
command:
|
||||
"node -e \"process.stdin.on('data', d => { process.stdout.write(d); if (d.includes(13)) process.exit(0); });\"",
|
||||
"node -e \"process.stdin.on('data', d => { process.stdout.write(d); if (d.includes(10) || d.includes(13)) process.exit(0); });\"",
|
||||
pty: true,
|
||||
background: true,
|
||||
});
|
||||
@@ -30,7 +30,8 @@ test("process send-keys encodes Enter for pty sessions", async () => {
|
||||
keys: ["h", "i", "Enter"],
|
||||
});
|
||||
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
const deadline = Date.now() + (process.platform === "win32" ? 4000 : 2000);
|
||||
while (Date.now() < deadline) {
|
||||
await wait(50);
|
||||
const poll = await processTool.execute("toolcall", { action: "poll", sessionId });
|
||||
const details = poll.details as { status?: string; aggregated?: string };
|
||||
|
||||
@@ -12,6 +12,10 @@ type Modifiers = {
|
||||
shift: boolean;
|
||||
};
|
||||
|
||||
function escapeRegExp(value: string) {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
const namedKeyMap = new Map<string, string>([
|
||||
["enter", CR],
|
||||
["return", CR],
|
||||
@@ -231,8 +235,9 @@ function xtermModifier(mods: Modifiers): number {
|
||||
}
|
||||
|
||||
function applyXtermModifier(sequence: string, modifier: number): string | null {
|
||||
const csiNumber = /^\x1b\[(\d+)([~A-Z])$/;
|
||||
const csiArrow = /^\x1b\[(A|B|C|D|H|F)$/;
|
||||
const escPattern = escapeRegExp(ESC);
|
||||
const csiNumber = new RegExp(`^${escPattern}\\[(\\d+)([~A-Z])$`);
|
||||
const csiArrow = new RegExp(`^${escPattern}\\[(A|B|C|D|H|F)$`);
|
||||
|
||||
const numberMatch = sequence.match(csiNumber);
|
||||
if (numberMatch) {
|
||||
|
||||
@@ -20,7 +20,7 @@ describe("session slug", () => {
|
||||
|
||||
it("falls back to three words when collisions persist", () => {
|
||||
vi.spyOn(Math, "random").mockReturnValue(0);
|
||||
const slug = createSessionSlug((id) => id === "amber-atlas" || id === "amber-atlas-2");
|
||||
const slug = createSessionSlug((id) => /^amber-atlas(-\d+)?$/.test(id));
|
||||
expect(slug).toBe("amber-atlas-atlas");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user