@microvac/plugin-daytona 0.0.0-stage → 0.1.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -2
- package/dist/archive-stream-window.test.d.ts +2 -0
- package/dist/archive-stream-window.test.d.ts.map +1 -0
- package/dist/archive-stream-window.test.js +93 -0
- package/dist/archive-stream-window.test.js.map +1 -0
- package/dist/archive-stream.d.ts +10 -0
- package/dist/archive-stream.d.ts.map +1 -0
- package/dist/archive-stream.js +159 -0
- package/dist/archive-stream.js.map +1 -0
- package/dist/archive-stream.test.d.ts +2 -0
- package/dist/archive-stream.test.d.ts.map +1 -0
- package/dist/archive-stream.test.js +121 -0
- package/dist/archive-stream.test.js.map +1 -0
- package/dist/duplex-close-deadline.test.d.ts +2 -0
- package/dist/duplex-close-deadline.test.d.ts.map +1 -0
- package/dist/duplex-close-deadline.test.js +106 -0
- package/dist/duplex-close-deadline.test.js.map +1 -0
- package/dist/duplex-command-stream.d.ts +98 -0
- package/dist/duplex-command-stream.d.ts.map +1 -0
- package/dist/duplex-command-stream.js +218 -0
- package/dist/duplex-command-stream.js.map +1 -0
- package/dist/duplex-command-stream.live.test.d.ts +2 -0
- package/dist/duplex-command-stream.live.test.d.ts.map +1 -0
- package/dist/duplex-command-stream.live.test.js +324 -0
- package/dist/duplex-command-stream.live.test.js.map +1 -0
- package/dist/duplex-command-stream.test.d.ts +2 -0
- package/dist/duplex-command-stream.test.d.ts.map +1 -0
- package/dist/duplex-command-stream.test.js +519 -0
- package/dist/duplex-command-stream.test.js.map +1 -0
- package/dist/file-sync-capacity.live.test.d.ts +2 -0
- package/dist/file-sync-capacity.live.test.d.ts.map +1 -0
- package/dist/file-sync-capacity.live.test.js +122 -0
- package/dist/file-sync-capacity.live.test.js.map +1 -0
- package/dist/file-sync-capacity.test.d.ts +2 -0
- package/dist/file-sync-capacity.test.d.ts.map +1 -0
- package/dist/file-sync-capacity.test.js +337 -0
- package/dist/file-sync-capacity.test.js.map +1 -0
- package/dist/file-sync-diagnostics.test.d.ts +2 -0
- package/dist/file-sync-diagnostics.test.d.ts.map +1 -0
- package/dist/file-sync-diagnostics.test.js +165 -0
- package/dist/file-sync-diagnostics.test.js.map +1 -0
- package/dist/file-sync.d.ts +80 -0
- package/dist/file-sync.d.ts.map +1 -0
- package/dist/file-sync.js +1362 -0
- package/dist/file-sync.js.map +1 -0
- package/dist/file-sync.test.d.ts +2 -0
- package/dist/file-sync.test.d.ts.map +1 -0
- package/dist/file-sync.test.js +1214 -0
- package/dist/file-sync.test.js.map +1 -0
- package/dist/idle-activity.d.ts +40 -0
- package/dist/idle-activity.d.ts.map +1 -0
- package/dist/idle-activity.js +145 -0
- package/dist/idle-activity.js.map +1 -0
- package/dist/idle-activity.test.d.ts +2 -0
- package/dist/idle-activity.test.d.ts.map +1 -0
- package/dist/idle-activity.test.js +159 -0
- package/dist/idle-activity.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lease-tracing.d.ts +7 -0
- package/dist/lease-tracing.d.ts.map +1 -0
- package/dist/lease-tracing.js +31 -0
- package/dist/lease-tracing.js.map +1 -0
- package/dist/lease-tracing.test.d.ts +2 -0
- package/dist/lease-tracing.test.d.ts.map +1 -0
- package/dist/lease-tracing.test.js +298 -0
- package/dist/lease-tracing.test.js.map +1 -0
- package/dist/login-pty.d.ts +162 -0
- package/dist/login-pty.d.ts.map +1 -0
- package/dist/login-pty.js +258 -0
- package/dist/login-pty.js.map +1 -0
- package/dist/login-pty.test.d.ts +2 -0
- package/dist/login-pty.test.d.ts.map +1 -0
- package/dist/login-pty.test.js +319 -0
- package/dist/login-pty.test.js.map +1 -0
- package/dist/manifest.d.ts +5 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +189 -0
- package/dist/manifest.js.map +1 -0
- package/dist/one-shot-exec-deadline.test.d.ts +2 -0
- package/dist/one-shot-exec-deadline.test.d.ts.map +1 -0
- package/dist/one-shot-exec-deadline.test.js +73 -0
- package/dist/one-shot-exec-deadline.test.js.map +1 -0
- package/dist/plugin.d.ts +103 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +3572 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.test.d.ts +2 -0
- package/dist/plugin.test.d.ts.map +1 -0
- package/dist/plugin.test.js +7276 -0
- package/dist/plugin.test.js.map +1 -0
- package/dist/pty-chunked-input.d.ts +48 -0
- package/dist/pty-chunked-input.d.ts.map +1 -0
- package/dist/pty-chunked-input.js +74 -0
- package/dist/pty-chunked-input.js.map +1 -0
- package/dist/pty-chunked-input.test.d.ts +2 -0
- package/dist/pty-chunked-input.test.d.ts.map +1 -0
- package/dist/pty-chunked-input.test.js +115 -0
- package/dist/pty-chunked-input.test.js.map +1 -0
- package/dist/runner-ingress.sdk-integration.d.ts +2 -0
- package/dist/runner-ingress.sdk-integration.d.ts.map +1 -0
- package/dist/runner-ingress.sdk-integration.js +87 -0
- package/dist/runner-ingress.sdk-integration.js.map +1 -0
- package/dist/session-command-completion.test.d.ts +2 -0
- package/dist/session-command-completion.test.d.ts.map +1 -0
- package/dist/session-command-completion.test.js +251 -0
- package/dist/session-command-completion.test.js.map +1 -0
- package/dist/session-stream-exit.d.ts +13 -0
- package/dist/session-stream-exit.d.ts.map +1 -0
- package/dist/session-stream-exit.js +48 -0
- package/dist/session-stream-exit.js.map +1 -0
- package/dist/tar-listing.test.d.ts +2 -0
- package/dist/tar-listing.test.d.ts.map +1 -0
- package/dist/tar-listing.test.js +220 -0
- package/dist/tar-listing.test.js.map +1 -0
- package/dist/worker.d.ts +3 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +5 -0
- package/dist/worker.js.map +1 -0
- package/package.json +42 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider PTY WebSocket message cap, in bytes. The provider rejects a single
|
|
3
|
+
* PTY message over this size with WebSocket close code 1009 and closes the
|
|
4
|
+
* connection.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PTY_MESSAGE_CAP_BYTES = 65536;
|
|
7
|
+
/**
|
|
8
|
+
* The maximum byte length of one host-to-sandbox chunk. It holds about 5 KiB of
|
|
9
|
+
* headroom under {@link PTY_MESSAGE_CAP_BYTES}, so a chunk never sits on the cap
|
|
10
|
+
* boundary. A later change in how the provider counts message overhead does not
|
|
11
|
+
* push one chunk over the cap and back into the close-code-1009 failure. The
|
|
12
|
+
* headroom costs about nine percent more messages for a large payload.
|
|
13
|
+
*
|
|
14
|
+
* The chunker slices bytes, not string characters, so a chunk boundary can split
|
|
15
|
+
* a multi-byte UTF-8 sequence. The read-side streaming `TextDecoder` rejoins a
|
|
16
|
+
* split sequence, so a byte slice is safe. A string-index slice could split a
|
|
17
|
+
* surrogate pair, so the chunker never slices by character.
|
|
18
|
+
*/
|
|
19
|
+
export declare const PTY_INPUT_CHUNK_BYTES: number;
|
|
20
|
+
/**
|
|
21
|
+
* Send one host-to-sandbox payload as byte-bounded chunks under the provider
|
|
22
|
+
* message cap. The function encodes a string payload to UTF-8 bytes, slices the
|
|
23
|
+
* byte array into chunks of at most {@link PTY_INPUT_CHUNK_BYTES}, and calls
|
|
24
|
+
* `sendInput` for each chunk in order.
|
|
25
|
+
*
|
|
26
|
+
* The loop awaits each chunk before it sends the next chunk. The `await` keeps
|
|
27
|
+
* the wire order equal to the slice order, and it makes the chunk send fail-fast:
|
|
28
|
+
* after a chunk rejects, the function sends no further chunk of this payload. A
|
|
29
|
+
* synchronous loop could not fail-fast, because `sendInput` reaches `ws.send`
|
|
30
|
+
* before its first `await`, so a synchronous loop puts every chunk on the wire
|
|
31
|
+
* before the first rejection settles. The awaited loop learns the rejection
|
|
32
|
+
* before it sends the next chunk, so it stops.
|
|
33
|
+
*
|
|
34
|
+
* The function does not overlap two calls for the same channel. The caller
|
|
35
|
+
* serializes its writes (for example, through a promise chain), so the awaited
|
|
36
|
+
* loop of one payload never interleaves its chunks with the chunks of the next
|
|
37
|
+
* payload.
|
|
38
|
+
*
|
|
39
|
+
* `onError` runs at most one time. The function reports the first rejected chunk
|
|
40
|
+
* and returns. A rejected send never throws out of this function, so the caller's
|
|
41
|
+
* stream stays the single result path.
|
|
42
|
+
*
|
|
43
|
+
* @param sendInput - Sends one raw byte chunk to the pseudo-terminal.
|
|
44
|
+
* @param payload - The host-to-sandbox payload, as a string or raw bytes.
|
|
45
|
+
* @param onError - Optional. The function calls it one time on the first rejected chunk.
|
|
46
|
+
*/
|
|
47
|
+
export declare function sendPtyInputInChunks(sendInput: (chunk: Uint8Array) => Promise<void>, payload: string | Uint8Array, onError?: () => void): Promise<void>;
|
|
48
|
+
//# sourceMappingURL=pty-chunked-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pty-chunked-input.d.ts","sourceRoot":"","sources":["../src/pty-chunked-input.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAK/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/C,OAAO,EAAE,MAAM,GAAG,UAAU,EAC5B,OAAO,CAAC,EAAE,MAAM,IAAI,GACnB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// The shared host-to-sandbox write chunker for the Daytona pseudo-terminal (PTY)
|
|
2
|
+
// sessions. The provider PTY WebSocket rejects any single message over 65536
|
|
3
|
+
// bytes with WebSocket close code 1009 and closes the connection. `sendInput`
|
|
4
|
+
// sends a whole payload in one message, so a payload above the cap takes the
|
|
5
|
+
// channel down. Real duplex frames cross the cap (single frames of 127582 and
|
|
6
|
+
// 150416 bytes are observed). This module slices each payload into byte-bounded
|
|
7
|
+
// chunks under the cap and sends each chunk in order.
|
|
8
|
+
/**
|
|
9
|
+
* The provider PTY WebSocket message cap, in bytes. The provider rejects a single
|
|
10
|
+
* PTY message over this size with WebSocket close code 1009 and closes the
|
|
11
|
+
* connection.
|
|
12
|
+
*/
|
|
13
|
+
export const PTY_MESSAGE_CAP_BYTES = 65536;
|
|
14
|
+
/**
|
|
15
|
+
* The maximum byte length of one host-to-sandbox chunk. It holds about 5 KiB of
|
|
16
|
+
* headroom under {@link PTY_MESSAGE_CAP_BYTES}, so a chunk never sits on the cap
|
|
17
|
+
* boundary. A later change in how the provider counts message overhead does not
|
|
18
|
+
* push one chunk over the cap and back into the close-code-1009 failure. The
|
|
19
|
+
* headroom costs about nine percent more messages for a large payload.
|
|
20
|
+
*
|
|
21
|
+
* The chunker slices bytes, not string characters, so a chunk boundary can split
|
|
22
|
+
* a multi-byte UTF-8 sequence. The read-side streaming `TextDecoder` rejoins a
|
|
23
|
+
* split sequence, so a byte slice is safe. A string-index slice could split a
|
|
24
|
+
* surrogate pair, so the chunker never slices by character.
|
|
25
|
+
*/
|
|
26
|
+
export const PTY_INPUT_CHUNK_BYTES = 60 * 1024;
|
|
27
|
+
/** The single UTF-8 encoder the chunker reuses for every string payload. */
|
|
28
|
+
const PTY_INPUT_TEXT_ENCODER = new TextEncoder();
|
|
29
|
+
/**
|
|
30
|
+
* Send one host-to-sandbox payload as byte-bounded chunks under the provider
|
|
31
|
+
* message cap. The function encodes a string payload to UTF-8 bytes, slices the
|
|
32
|
+
* byte array into chunks of at most {@link PTY_INPUT_CHUNK_BYTES}, and calls
|
|
33
|
+
* `sendInput` for each chunk in order.
|
|
34
|
+
*
|
|
35
|
+
* The loop awaits each chunk before it sends the next chunk. The `await` keeps
|
|
36
|
+
* the wire order equal to the slice order, and it makes the chunk send fail-fast:
|
|
37
|
+
* after a chunk rejects, the function sends no further chunk of this payload. A
|
|
38
|
+
* synchronous loop could not fail-fast, because `sendInput` reaches `ws.send`
|
|
39
|
+
* before its first `await`, so a synchronous loop puts every chunk on the wire
|
|
40
|
+
* before the first rejection settles. The awaited loop learns the rejection
|
|
41
|
+
* before it sends the next chunk, so it stops.
|
|
42
|
+
*
|
|
43
|
+
* The function does not overlap two calls for the same channel. The caller
|
|
44
|
+
* serializes its writes (for example, through a promise chain), so the awaited
|
|
45
|
+
* loop of one payload never interleaves its chunks with the chunks of the next
|
|
46
|
+
* payload.
|
|
47
|
+
*
|
|
48
|
+
* `onError` runs at most one time. The function reports the first rejected chunk
|
|
49
|
+
* and returns. A rejected send never throws out of this function, so the caller's
|
|
50
|
+
* stream stays the single result path.
|
|
51
|
+
*
|
|
52
|
+
* @param sendInput - Sends one raw byte chunk to the pseudo-terminal.
|
|
53
|
+
* @param payload - The host-to-sandbox payload, as a string or raw bytes.
|
|
54
|
+
* @param onError - Optional. The function calls it one time on the first rejected chunk.
|
|
55
|
+
*/
|
|
56
|
+
export async function sendPtyInputInChunks(sendInput, payload, onError) {
|
|
57
|
+
const bytes = typeof payload === "string" ? PTY_INPUT_TEXT_ENCODER.encode(payload) : payload;
|
|
58
|
+
for (let offset = 0; offset < bytes.length; offset += PTY_INPUT_CHUNK_BYTES) {
|
|
59
|
+
const chunk = bytes.subarray(offset, offset + PTY_INPUT_CHUNK_BYTES);
|
|
60
|
+
try {
|
|
61
|
+
// Await the send before the next chunk. The await keeps the wire order and
|
|
62
|
+
// lets the loop learn a rejection before it starts a later send.
|
|
63
|
+
await sendInput(chunk);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Report the first rejected chunk one time and stop. The function starts no
|
|
67
|
+
// later send for this payload, so the wire keeps the ordered, fail-fast
|
|
68
|
+
// behavior. The raw provider error never leaves this function.
|
|
69
|
+
onError?.();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=pty-chunked-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pty-chunked-input.js","sourceRoot":"","sources":["../src/pty-chunked-input.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,sDAAsD;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,sBAAsB,GAAG,IAAI,WAAW,EAAE,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,SAA+C,EAC/C,OAA4B,EAC5B,OAAoB;IAEpB,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7F,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,qBAAqB,EAAE,CAAC;QAC5E,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAAC,CAAC;QACrE,IAAI,CAAC;YACH,2EAA2E;YAC3E,iEAAiE;YACjE,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;YAC5E,wEAAwE;YACxE,+DAA+D;YAC/D,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pty-chunked-input.test.d.ts","sourceRoot":"","sources":["../src/pty-chunked-input.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { PTY_INPUT_CHUNK_BYTES, PTY_MESSAGE_CAP_BYTES, sendPtyInputInChunks, } from "./pty-chunked-input.js";
|
|
3
|
+
/**
|
|
4
|
+
* A fake `sendInput`. It records each raw byte chunk, so a test asserts the chunk
|
|
5
|
+
* count, the chunk sizes, and the rejoined bytes. It copies each chunk, because
|
|
6
|
+
* the chunker passes a `subarray` view of one shared byte array.
|
|
7
|
+
*/
|
|
8
|
+
function createByteRecorder() {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
return {
|
|
11
|
+
chunks,
|
|
12
|
+
async sendInput(chunk) {
|
|
13
|
+
chunks.push(Uint8Array.from(chunk));
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Concatenate the recorded chunks into one byte array. */
|
|
18
|
+
function concatChunks(chunks) {
|
|
19
|
+
const total = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
20
|
+
const joined = new Uint8Array(total);
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const chunk of chunks) {
|
|
23
|
+
joined.set(chunk, offset);
|
|
24
|
+
offset += chunk.length;
|
|
25
|
+
}
|
|
26
|
+
return joined;
|
|
27
|
+
}
|
|
28
|
+
describe("sendPtyInputInChunks", () => {
|
|
29
|
+
it("sends a payload below the cap as exactly one send", async () => {
|
|
30
|
+
const recorder = createByteRecorder();
|
|
31
|
+
await sendPtyInputInChunks(recorder.sendInput, "a small frame\n");
|
|
32
|
+
expect(recorder.chunks).toHaveLength(1);
|
|
33
|
+
expect(recorder.chunks[0]?.length).toBeLessThanOrEqual(PTY_MESSAGE_CAP_BYTES);
|
|
34
|
+
});
|
|
35
|
+
it("splits a payload above the cap into more than one send, each at or below the cap", async () => {
|
|
36
|
+
const recorder = createByteRecorder();
|
|
37
|
+
// A fixed payload well above the provider message cap. It stays fixed, so a
|
|
38
|
+
// raised chunk size above this size makes the payload one send and fails this
|
|
39
|
+
// test.
|
|
40
|
+
const payload = new Uint8Array(150_416).fill(65);
|
|
41
|
+
await sendPtyInputInChunks(recorder.sendInput, payload);
|
|
42
|
+
expect(recorder.chunks.length).toBeGreaterThan(1);
|
|
43
|
+
for (const chunk of recorder.chunks) {
|
|
44
|
+
expect(chunk.length).toBeLessThanOrEqual(PTY_INPUT_CHUNK_BYTES);
|
|
45
|
+
expect(chunk.length).toBeLessThanOrEqual(PTY_MESSAGE_CAP_BYTES);
|
|
46
|
+
}
|
|
47
|
+
expect(concatChunks(recorder.chunks)).toEqual(payload);
|
|
48
|
+
});
|
|
49
|
+
it("slices a multi-byte character across a boundary by bytes and rejoins it", async () => {
|
|
50
|
+
const recorder = createByteRecorder();
|
|
51
|
+
// A fixed payload: one 1-byte "x", then the 3-byte character "€" repeated. It
|
|
52
|
+
// stays fixed, so a raised chunk size above this size makes the payload one
|
|
53
|
+
// send and fails this test. The chunk size is a multiple of 3, so a pure "€"
|
|
54
|
+
// run would put every boundary on a character edge. The 1-byte prefix shifts
|
|
55
|
+
// the "€" run by one byte, so the first chunk boundary lands inside one "€"
|
|
56
|
+
// sequence.
|
|
57
|
+
const text = `x${"€".repeat(30_000)}`;
|
|
58
|
+
const inputBytes = new TextEncoder().encode(text);
|
|
59
|
+
expect(inputBytes.length).toBe(90_001);
|
|
60
|
+
await sendPtyInputInChunks(recorder.sendInput, text);
|
|
61
|
+
expect(recorder.chunks.length).toBeGreaterThan(1);
|
|
62
|
+
// The first chunk holds exactly the byte cap and ends inside a "€" sequence,
|
|
63
|
+
// because the 1-byte prefix shifts the 3-byte run off the cap boundary. A
|
|
64
|
+
// character-index slice could never end mid-sequence, so the slice is by bytes.
|
|
65
|
+
expect(recorder.chunks[0]?.length).toBe(PTY_INPUT_CHUNK_BYTES);
|
|
66
|
+
// The rejoined bytes equal the input bytes, so a split multi-byte sequence is
|
|
67
|
+
// whole again. A streaming decoder on the read side then decodes it.
|
|
68
|
+
const joined = concatChunks(recorder.chunks);
|
|
69
|
+
expect(joined).toEqual(inputBytes);
|
|
70
|
+
expect(new TextDecoder("utf-8").decode(joined)).toBe(text);
|
|
71
|
+
});
|
|
72
|
+
it("resolves each send before it starts the next send", async () => {
|
|
73
|
+
let active = 0;
|
|
74
|
+
let maxActive = 0;
|
|
75
|
+
const sendCount = { value: 0 };
|
|
76
|
+
// A `sendInput` that stays active across a microtask. The awaited loop starts
|
|
77
|
+
// the next send only after the previous send resolves, so at most one send is
|
|
78
|
+
// active at a time. A synchronous burst would start every send at once.
|
|
79
|
+
const sendInput = async () => {
|
|
80
|
+
active += 1;
|
|
81
|
+
maxActive = Math.max(maxActive, active);
|
|
82
|
+
await Promise.resolve();
|
|
83
|
+
sendCount.value += 1;
|
|
84
|
+
active -= 1;
|
|
85
|
+
};
|
|
86
|
+
// Three chunks of the byte cap plus a short tail.
|
|
87
|
+
const payload = new Uint8Array(PTY_INPUT_CHUNK_BYTES * 3 + 10).fill(65);
|
|
88
|
+
await sendPtyInputInChunks(sendInput, payload);
|
|
89
|
+
expect(sendCount.value).toBe(4);
|
|
90
|
+
expect(maxActive).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
it("stops sending later chunks after a chunk rejects", async () => {
|
|
93
|
+
const chunks = [];
|
|
94
|
+
let errorCount = 0;
|
|
95
|
+
// A `sendInput` that records the chunk, then rejects on a later microtask. The
|
|
96
|
+
// rejection is asynchronous, so a synchronous burst could not stop the later
|
|
97
|
+
// sends. The awaited loop learns the rejection before the next send, so it
|
|
98
|
+
// sends one chunk only.
|
|
99
|
+
const sendInput = async (chunk) => {
|
|
100
|
+
chunks.push(chunk);
|
|
101
|
+
await Promise.resolve();
|
|
102
|
+
throw new Error("RAW-PROVIDER-BROKEN-PIPE");
|
|
103
|
+
};
|
|
104
|
+
// A payload above the cap, so the chunker would fire more than one chunk with
|
|
105
|
+
// no fail-fast. The loop stops after the first rejected chunk.
|
|
106
|
+
await sendPtyInputInChunks(sendInput, new Uint8Array(150_416).fill(65), () => {
|
|
107
|
+
errorCount += 1;
|
|
108
|
+
});
|
|
109
|
+
// The loop sent one chunk, learned the rejection, and started no later send.
|
|
110
|
+
expect(chunks).toHaveLength(1);
|
|
111
|
+
// The error handler ran one time for the whole payload.
|
|
112
|
+
expect(errorCount).toBe(1);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=pty-chunked-input.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pty-chunked-input.test.js","sourceRoot":"","sources":["../src/pty-chunked-input.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,SAAS,kBAAkB;IAIzB,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,OAAO;QACL,MAAM;QACN,KAAK,CAAC,SAAS,CAAC,KAAiB;YAC/B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,YAAY,CAAC,MAA6B;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,K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,CAAC,EAAE,GAAG,EAAE;YAC3E,UAAU,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,6EAA6E;QAC7E,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/B,wDAAwD;QACxD,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-ingress.sdk-integration.d.ts","sourceRoot":"","sources":["../src/runner-ingress.sdk-integration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
3
|
+
import { PassThrough } from "node:stream";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { createRequest, definePlugin, isJsonRpcResponse, JsonRpcCallError, parseMessage, readEnvironmentRunnerIngressFailure, serializeMessage, startWorkerRpcHost } from "@paperclipai/plugin-sdk";
|
|
6
|
+
import plugin, { __resetDaytonaSandboxHandleCacheForTest } from "./plugin.js";
|
|
7
|
+
describe("Daytona ingress SDK failure over worker RPC", () => {
|
|
8
|
+
it("keeps a missing API credential as a configuration failure", async () => {
|
|
9
|
+
vi.stubEnv("DAYTONA_API_KEY", "");
|
|
10
|
+
try {
|
|
11
|
+
const error = await plugin.definition.onEnvironmentRunnerIngressEndpoint({
|
|
12
|
+
companyId: "fixture-company", environmentId: "fixture-environment", driverKey: "daytona",
|
|
13
|
+
runId: "fixture-run", port: 43127, path: "/api/runner/v1/connect/fixture-run",
|
|
14
|
+
lease: { providerLeaseId: "fixture-sandbox" }, config: {},
|
|
15
|
+
}).catch(error => error);
|
|
16
|
+
expect(error).toBeInstanceOf(Error);
|
|
17
|
+
expect(error.message).toContain("require an API key");
|
|
18
|
+
expect(readEnvironmentRunnerIngressFailure(error)).toBeNull();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
vi.unstubAllEnvs();
|
|
22
|
+
__resetDaytonaSandboxHandleCacheForTest();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
it.each([
|
|
26
|
+
{ status: 502, phase: "sandbox_lookup" }, { status: 401, phase: "sandbox_lookup" },
|
|
27
|
+
{ status: 403, phase: "sandbox_lookup" }, { status: 400, phase: "sandbox_lookup" },
|
|
28
|
+
{ status: 502, phase: "private_preview" },
|
|
29
|
+
])("retains the pinned SDK's HTTP $status at $phase without provider response data", async ({ status, phase }) => {
|
|
30
|
+
let requests = 0;
|
|
31
|
+
let apiUrl = "";
|
|
32
|
+
const server = createServer((request, response) => {
|
|
33
|
+
requests++;
|
|
34
|
+
if (phase === "private_preview" && !request.url?.includes("43127")) {
|
|
35
|
+
response.writeHead(200, { "content-type": "application/json" });
|
|
36
|
+
response.end(JSON.stringify({ id: "fixture-sandbox", name: "fixture-sandbox", organizationId: "fixture-org",
|
|
37
|
+
state: "started", toolboxProxyUrl: apiUrl, labels: {}, autoStopInterval: 0 }));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
response.writeHead(status, { "content-type": "text/html", "x-private-token": "fixture-private-header" });
|
|
41
|
+
response.end(`<html><title>${status} Bad Gateway</title>fixture-private-url fixture-private-token</html>`);
|
|
42
|
+
});
|
|
43
|
+
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
|
44
|
+
const address = server.address();
|
|
45
|
+
if (!address || typeof address === "string")
|
|
46
|
+
throw new Error("Missing fixture address");
|
|
47
|
+
apiUrl = `http://127.0.0.1:${address.port}`;
|
|
48
|
+
const stdin = new PassThrough(), stdout = new PassThrough();
|
|
49
|
+
const lines = createInterface({ input: stdout });
|
|
50
|
+
const worker = startWorkerRpcHost({ stdin, stdout, plugin: definePlugin({ async setup() { },
|
|
51
|
+
onEnvironmentRunnerIngressEndpoint: plugin.definition.onEnvironmentRunnerIngressEndpoint,
|
|
52
|
+
}) });
|
|
53
|
+
try {
|
|
54
|
+
const response = new Promise(resolve => lines.on("line", line => {
|
|
55
|
+
const message = parseMessage(line);
|
|
56
|
+
if (isJsonRpcResponse(message))
|
|
57
|
+
resolve(message);
|
|
58
|
+
}));
|
|
59
|
+
stdin.write(serializeMessage(createRequest("environmentRunnerIngressEndpoint", {
|
|
60
|
+
companyId: "fixture-company", environmentId: "fixture-environment", driverKey: "daytona",
|
|
61
|
+
runId: "fixture-run", port: 43127, path: "/api/runner/v1/connect/fixture-run",
|
|
62
|
+
lease: { providerLeaseId: "fixture-sandbox" },
|
|
63
|
+
config: { apiKey: "fixture-private-key", apiUrl, timeoutMs: 2000 },
|
|
64
|
+
}, "ingress")));
|
|
65
|
+
const result = await response;
|
|
66
|
+
expect(requests).toBeGreaterThan(0);
|
|
67
|
+
if (!("error" in result) || !result.error)
|
|
68
|
+
throw new Error("Expected SDK rejection");
|
|
69
|
+
expect(readEnvironmentRunnerIngressFailure(new JsonRpcCallError(result.error)))
|
|
70
|
+
.toEqual({ phase, httpStatus: status });
|
|
71
|
+
expect(result.error.message).toContain(String(status));
|
|
72
|
+
expect(JSON.stringify(result)).not.toContain("fixture-private");
|
|
73
|
+
expect(result.error.data).toEqual({ schema: "paperclip/environment-runner-ingress-error/v1",
|
|
74
|
+
failure: { phase, httpStatus: status } });
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
worker.stop();
|
|
78
|
+
lines.close();
|
|
79
|
+
stdin.destroy();
|
|
80
|
+
stdout.destroy();
|
|
81
|
+
server.closeAllConnections();
|
|
82
|
+
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
|
|
83
|
+
__resetDaytonaSandboxHandleCacheForTest();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=runner-ingress.sdk-integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-ingress.sdk-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AC;gBAAS,CAAC;YACT,MAAM,CAAC,IAAI,EAAE,CAAC;YAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAChE,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAC7B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACvG,uCAAuC,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-command-completion.test.d.ts","sourceRoot":"","sources":["../src/session-command-completion.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
const getSandbox = vi.hoisted(() => vi.fn());
|
|
3
|
+
vi.mock("@daytonaio/sdk", () => ({
|
|
4
|
+
Daytona: class {
|
|
5
|
+
get = getSandbox;
|
|
6
|
+
},
|
|
7
|
+
DaytonaNotFoundError: class extends Error {
|
|
8
|
+
},
|
|
9
|
+
DaytonaTimeoutError: class extends Error {
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
import plugin, { __resetDaytonaSandboxHandleCacheForTest, __setDaytonaPluginContextForTest } from "./plugin.js";
|
|
13
|
+
function fixture() {
|
|
14
|
+
const process = {
|
|
15
|
+
createSession: vi.fn().mockResolvedValue(undefined),
|
|
16
|
+
executeSessionCommand: vi.fn().mockResolvedValue({ cmdId: "fixture-command" }),
|
|
17
|
+
getSessionCommand: vi.fn().mockResolvedValue({ exitCode: 0 }),
|
|
18
|
+
getSessionCommandLogs: vi.fn().mockImplementation(async (_session, _command, stdout) => {
|
|
19
|
+
if (stdout)
|
|
20
|
+
return new Promise(() => { });
|
|
21
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
getSandbox.mockResolvedValue({ id: "fixture-sandbox", state: "started", process });
|
|
25
|
+
const execute = (commandTimeoutMs = 2_000) => plugin.definition.onEnvironmentExecute({
|
|
26
|
+
driverKey: "daytona", companyId: "fixture-company", environmentId: "fixture-environment",
|
|
27
|
+
config: { apiKey: "fixture-not-a-key", timeoutMs: 30_000 },
|
|
28
|
+
lease: { providerLeaseId: "fixture-sandbox" }, command: "printf", args: ["fixture"],
|
|
29
|
+
commandTimeoutMs,
|
|
30
|
+
});
|
|
31
|
+
return { process, execute };
|
|
32
|
+
}
|
|
33
|
+
describe("Daytona completed session commands", () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
__resetDaytonaSandboxHandleCacheForTest();
|
|
36
|
+
getSandbox.mockReset();
|
|
37
|
+
vi.useFakeTimers();
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.useRealTimers();
|
|
41
|
+
__resetDaytonaSandboxHandleCacheForTest();
|
|
42
|
+
});
|
|
43
|
+
it("returns a finished command's final separated logs without opening a follow socket", async () => {
|
|
44
|
+
const { process, execute } = fixture();
|
|
45
|
+
let settled = false;
|
|
46
|
+
const pending = execute().then(result => { settled = true; return result; });
|
|
47
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
48
|
+
expect(settled).toBe(true);
|
|
49
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
50
|
+
expect(process.getSessionCommandLogs).toHaveBeenCalledExactlyOnceWith(expect.any(String), "fixture-command");
|
|
51
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
it("streams a still-running command and reconciles its final snapshot", async () => {
|
|
54
|
+
const { process, execute } = fixture();
|
|
55
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined });
|
|
56
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
57
|
+
if (stdout) {
|
|
58
|
+
stdout("prefix ");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
return { stdout: "prefix complete\n", stderr: "error\n" };
|
|
62
|
+
});
|
|
63
|
+
expect(await execute()).toMatchObject({ exitCode: 0, timedOut: false, stdout: "prefix complete\n", stderr: "error\n" });
|
|
64
|
+
expect(process.getSessionCommandLogs.mock.calls.filter(call => call[2])).toHaveLength(1);
|
|
65
|
+
});
|
|
66
|
+
it("retains a completed status response that takes 300ms without opening a follow socket", async () => {
|
|
67
|
+
const { process, execute } = fixture();
|
|
68
|
+
process.getSessionCommand.mockImplementationOnce(() => new Promise(resolve => setTimeout(() => resolve({ exitCode: 0 }), 300)));
|
|
69
|
+
let settled = false;
|
|
70
|
+
const pending = execute().then(result => { settled = true; return result; });
|
|
71
|
+
await vi.advanceTimersByTimeAsync(600);
|
|
72
|
+
const settledWithinObservation = settled;
|
|
73
|
+
if (!settled)
|
|
74
|
+
await vi.advanceTimersByTimeAsync(1_500);
|
|
75
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
76
|
+
expect(settledWithinObservation).toBe(true);
|
|
77
|
+
expect(process.getSessionCommandLogs.mock.calls.filter(call => call[2])).toHaveLength(0);
|
|
78
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
79
|
+
});
|
|
80
|
+
it("bounds an unavailable initial status read and retains the working stream", async () => {
|
|
81
|
+
const { process, execute } = fixture();
|
|
82
|
+
process.getSessionCommand.mockImplementationOnce(() => new Promise(() => { }));
|
|
83
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
84
|
+
if (stdout) {
|
|
85
|
+
stdout("complete stdout\n");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
89
|
+
});
|
|
90
|
+
const pending = execute();
|
|
91
|
+
await vi.advanceTimersByTimeAsync(499);
|
|
92
|
+
expect(process.getSessionCommandLogs).not.toHaveBeenCalled();
|
|
93
|
+
await vi.advanceTimersByTimeAsync(2);
|
|
94
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
95
|
+
expect(process.getSessionCommandLogs.mock.calls.filter(call => call[2])).toHaveLength(1);
|
|
96
|
+
});
|
|
97
|
+
it("retains stream recovery after the initial status request rejects", async () => {
|
|
98
|
+
const { process, execute } = fixture();
|
|
99
|
+
process.getSessionCommand.mockRejectedValueOnce(new Error("status transport unavailable"));
|
|
100
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
101
|
+
if (stdout) {
|
|
102
|
+
stdout("complete stdout\n");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
106
|
+
});
|
|
107
|
+
expect(await execute()).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
108
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
109
|
+
});
|
|
110
|
+
it("does not treat a visible exit as proof that final logs were read", async () => {
|
|
111
|
+
const { process, execute } = fixture();
|
|
112
|
+
process.getSessionCommandLogs.mockImplementation(() => new Promise(() => { }));
|
|
113
|
+
const pending = execute(100);
|
|
114
|
+
await vi.advanceTimersByTimeAsync(101);
|
|
115
|
+
expect(await pending).toMatchObject({ exitCode: null, timedOut: true,
|
|
116
|
+
metadata: { timeoutScope: "session_log_observation", commandExitConfirmed: true, observedExitCode: 0 } });
|
|
117
|
+
});
|
|
118
|
+
it("keeps the total command deadline while the initial status is unavailable", async () => {
|
|
119
|
+
const { process, execute } = fixture();
|
|
120
|
+
process.getSessionCommand.mockImplementation(() => new Promise(() => { }));
|
|
121
|
+
const pending = execute(100);
|
|
122
|
+
await vi.advanceTimersByTimeAsync(101);
|
|
123
|
+
expect(await pending).toMatchObject({ exitCode: null, timedOut: true });
|
|
124
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
125
|
+
expect(process.getSessionCommandLogs).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
it.each([0, 7])("settles exit %s from its final snapshot before the follow socket closes", async (exitCode) => {
|
|
128
|
+
const { process, execute } = fixture();
|
|
129
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined }).mockResolvedValue({ exitCode });
|
|
130
|
+
let lateOutput;
|
|
131
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
132
|
+
if (stdout) {
|
|
133
|
+
lateOutput = stdout;
|
|
134
|
+
stdout("complete ");
|
|
135
|
+
return new Promise(() => { });
|
|
136
|
+
}
|
|
137
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
138
|
+
});
|
|
139
|
+
let settled = false;
|
|
140
|
+
const pending = execute(10_000).then(result => { settled = true; return result; });
|
|
141
|
+
await vi.advanceTimersByTimeAsync(250);
|
|
142
|
+
const settledBeforeSocketClose = settled;
|
|
143
|
+
if (!settled)
|
|
144
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
145
|
+
const result = await pending;
|
|
146
|
+
expect(settledBeforeSocketClose).toBe(true);
|
|
147
|
+
expect(result).toMatchObject({ exitCode, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
148
|
+
lateOutput?.("late bytes must be ignored");
|
|
149
|
+
expect(result.stdout).toBe("complete stdout\n");
|
|
150
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
151
|
+
});
|
|
152
|
+
it("bounds the early status reads while a longer command keeps streaming", async () => {
|
|
153
|
+
const { process, execute } = fixture();
|
|
154
|
+
process.getSessionCommand.mockResolvedValue({ exitCode: undefined });
|
|
155
|
+
let closeStream;
|
|
156
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
157
|
+
if (stdout) {
|
|
158
|
+
stdout("complete ");
|
|
159
|
+
return new Promise(resolve => { closeStream = resolve; });
|
|
160
|
+
}
|
|
161
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
162
|
+
});
|
|
163
|
+
let settled = false;
|
|
164
|
+
const pending = execute(10_000).then(result => { settled = true; return result; });
|
|
165
|
+
await vi.advanceTimersByTimeAsync(2_500);
|
|
166
|
+
expect(settled).toBe(false);
|
|
167
|
+
expect(process.getSessionCommand).toHaveBeenCalledTimes(5);
|
|
168
|
+
process.getSessionCommand.mockResolvedValue({ exitCode: 0 });
|
|
169
|
+
closeStream();
|
|
170
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n" });
|
|
171
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
172
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
173
|
+
});
|
|
174
|
+
it.each(["rejected", "unavailable"])("retains the healthy stream after a %s early exit read", async (failure) => {
|
|
175
|
+
const { process, execute } = fixture();
|
|
176
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined });
|
|
177
|
+
if (failure === "rejected")
|
|
178
|
+
process.getSessionCommand.mockRejectedValueOnce(new Error("early status unavailable"));
|
|
179
|
+
else
|
|
180
|
+
process.getSessionCommand.mockImplementationOnce(() => new Promise(() => { }));
|
|
181
|
+
let closeStream;
|
|
182
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout) => {
|
|
183
|
+
if (stdout)
|
|
184
|
+
return new Promise(resolve => { closeStream = resolve; });
|
|
185
|
+
return { stdout: "complete stdout\n", stderr: "complete stderr\n" };
|
|
186
|
+
});
|
|
187
|
+
let settled = false;
|
|
188
|
+
const pending = execute(10_000).then(result => { settled = true; return result; });
|
|
189
|
+
await vi.advanceTimersByTimeAsync(600);
|
|
190
|
+
expect(settled).toBe(false);
|
|
191
|
+
expect(process.getSessionCommand).toHaveBeenCalledTimes(2);
|
|
192
|
+
closeStream();
|
|
193
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "complete stdout\n", stderr: "complete stderr\n" });
|
|
194
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
195
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
196
|
+
});
|
|
197
|
+
it("keeps the final snapshot deadline after observing an early exit", async () => {
|
|
198
|
+
const { process, execute } = fixture();
|
|
199
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined });
|
|
200
|
+
process.getSessionCommandLogs.mockImplementation(() => new Promise(() => { }));
|
|
201
|
+
const pending = execute(100);
|
|
202
|
+
await vi.advanceTimersByTimeAsync(101);
|
|
203
|
+
expect(await pending).toMatchObject({ exitCode: null, timedOut: true,
|
|
204
|
+
metadata: { timeoutScope: "session_log_observation", commandExitConfirmed: true, observedExitCode: 0 } });
|
|
205
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
206
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
207
|
+
});
|
|
208
|
+
it("stops early exit reads at the original command deadline", async () => {
|
|
209
|
+
const { process, execute } = fixture();
|
|
210
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined }).mockImplementation(() => new Promise(() => { }));
|
|
211
|
+
const pending = execute(100);
|
|
212
|
+
await vi.advanceTimersByTimeAsync(101);
|
|
213
|
+
expect(await pending).toMatchObject({ exitCode: null, timedOut: true });
|
|
214
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
215
|
+
expect(process.getSessionCommand).toHaveBeenCalledTimes(2);
|
|
216
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
217
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
218
|
+
});
|
|
219
|
+
it("reconciles UTF-8 output and fences late follow callbacks after an early exit", async () => {
|
|
220
|
+
const { process, execute } = fixture();
|
|
221
|
+
const log = vi.fn();
|
|
222
|
+
const restore = __setDaytonaPluginContextForTest({ execution: { log } });
|
|
223
|
+
process.getSessionCommand.mockResolvedValueOnce({ exitCode: undefined });
|
|
224
|
+
let lateStdout;
|
|
225
|
+
let lateStderr;
|
|
226
|
+
process.getSessionCommandLogs.mockImplementation(async (_session, _command, stdout, stderr) => {
|
|
227
|
+
if (stdout) {
|
|
228
|
+
lateStdout = stdout;
|
|
229
|
+
lateStderr = stderr;
|
|
230
|
+
stdout("α");
|
|
231
|
+
return new Promise(() => { });
|
|
232
|
+
}
|
|
233
|
+
return { stdout: "αβ🚀\n", stderr: "γδ\n" };
|
|
234
|
+
});
|
|
235
|
+
try {
|
|
236
|
+
const pending = execute();
|
|
237
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
238
|
+
expect(await pending).toMatchObject({ exitCode: 0, timedOut: false, stdout: "αβ🚀\n", stderr: "γδ\n" });
|
|
239
|
+
const deliveredCount = log.mock.calls.length;
|
|
240
|
+
lateStdout("late stdout");
|
|
241
|
+
lateStderr("late stderr");
|
|
242
|
+
expect(log).toHaveBeenCalledTimes(deliveredCount);
|
|
243
|
+
expect(process.executeSessionCommand).toHaveBeenCalledTimes(1);
|
|
244
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
restore();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
//# sourceMappingURL=session-command-completion.test.js.map
|