fix(core): preserve shell output tail (#39403)
This commit is contained in:
parent
37a1b80d5a
commit
754ea99d86
2 changed files with 13 additions and 5 deletions
|
|
@ -205,8 +205,12 @@ export const Plugin = {
|
||||||
yield* context.progress({ shellID: info.id })
|
yield* context.progress({ shellID: info.id })
|
||||||
|
|
||||||
const captureShell = Effect.fn("ShellTool.captureShell")(function* () {
|
const captureShell = Effect.fn("ShellTool.captureShell")(function* () {
|
||||||
const page = yield* shell.output(info.id, { limit: MAX_CAPTURE_BYTES })
|
const latest = yield* shell.output(info.id, { cursor: Number.MAX_SAFE_INTEGER })
|
||||||
const truncated = page.size > page.cursor
|
const truncated = latest.size > MAX_CAPTURE_BYTES
|
||||||
|
const page = yield* shell.output(info.id, {
|
||||||
|
cursor: Math.max(0, latest.size - MAX_CAPTURE_BYTES),
|
||||||
|
limit: MAX_CAPTURE_BYTES,
|
||||||
|
})
|
||||||
const notice = truncated ? `\n\n[output truncated; full output saved to: ${info.file}]` : ""
|
const notice = truncated ? `\n\n[output truncated; full output saved to: ${info.file}]` : ""
|
||||||
return {
|
return {
|
||||||
output: `${page.output || "(no output)"}${notice}`,
|
output: `${page.output || "(no output)"}${notice}`,
|
||||||
|
|
|
||||||
|
|
@ -165,8 +165,8 @@ const bodyExitCommand = isWindows
|
||||||
: "printf body && exit 7"
|
: "printf body && exit 7"
|
||||||
const overflowCommand = (bytes: number) =>
|
const overflowCommand = (bytes: number) =>
|
||||||
isWindows
|
isWindows
|
||||||
? `[Console]::Out.Write(('x' * ${bytes})); Start-Sleep -Milliseconds 100`
|
? `[Console]::Out.Write('output-start' + ('x' * ${bytes}) + 'output-end'); Start-Sleep -Milliseconds 100`
|
||||||
: `head -c ${bytes} /dev/zero | tr '\\0' 'x'`
|
: `printf output-start; head -c ${bytes} /dev/zero | tr '\\0' 'x'; printf output-end`
|
||||||
const progressOverflowCommand = (bytes: number, release: string) =>
|
const progressOverflowCommand = (bytes: number, release: string) =>
|
||||||
isWindows
|
isWindows
|
||||||
? `[Console]::Out.Write(('x' * ${bytes})); while (!(Test-Path -LiteralPath '${release}')) { Start-Sleep -Milliseconds 50 }`
|
? `[Console]::Out.Write(('x' * ${bytes})); while (!(Test-Path -LiteralPath '${release}')) { Start-Sleep -Milliseconds 50 }`
|
||||||
|
|
@ -410,7 +410,11 @@ describe("ShellTool", () => {
|
||||||
Effect.andThen((settled) =>
|
Effect.andThen((settled) =>
|
||||||
Effect.sync(() => {
|
Effect.sync(() => {
|
||||||
expect(settled.metadata).toMatchObject({ exit: 0, truncated: true })
|
expect(settled.metadata).toMatchObject({ exit: 0, truncated: true })
|
||||||
expect(settled.content?.[0]).toMatchObject({
|
const content = settled.content?.[0]
|
||||||
|
if (!content || content.type !== "text") throw new Error("Expected text content")
|
||||||
|
expect(content.text.includes("output-start")).toBe(false)
|
||||||
|
expect(content.text.includes("output-end")).toBe(true)
|
||||||
|
expect(content).toMatchObject({
|
||||||
type: "text",
|
type: "text",
|
||||||
text: expect.stringContaining("output truncated; full output saved to:"),
|
text: expect.stringContaining("output truncated; full output saved to:"),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue