|
1 | | -import { describe, expect } from "bun:test" |
| 1 | +import { describe, expect, test } from "bun:test" |
2 | 2 | import { Cause, Effect, Exit, Layer } from "effect" |
3 | 3 | import type * as Scope from "effect/Scope" |
4 | 4 | import os from "os" |
5 | 5 | import path from "path" |
6 | 6 | import { Config } from "@/config/config" |
7 | 7 | import { Shell } from "../../src/shell/shell" |
8 | | -import { ShellTool } from "../../src/tool/shell" |
| 8 | +import { ShellTool, previewMetadata } from "../../src/tool/shell" |
9 | 9 | import { Filesystem } from "@/util/filesystem" |
10 | 10 | import { provideInstance, tmpdirScoped } from "../fixture/fixture" |
11 | 11 | import type { Permission } from "../../src/permission" |
@@ -1205,42 +1205,22 @@ describe("tool.shell truncation", () => { |
1205 | 1205 | ), |
1206 | 1206 | ) |
1207 | 1207 |
|
1208 | | - it.live("truncates metadata output by utf8 byte length", () => |
1209 | | - runIn( |
1210 | | - projectRoot, |
1211 | | - Effect.gen(function* () { |
1212 | | - const result = yield* run({ |
1213 | | - command: `${bin} -e ${evalarg("process.stdout.write(String.fromCodePoint(0x4e00).repeat(10001))")}`, |
1214 | | - description: "Generate CJK output exceeding metadata byte limit", |
1215 | | - }) |
1216 | | - const output = result.metadata.output |
1217 | | - if (typeof output !== "string") throw new Error("expected metadata output") |
| 1208 | + test("truncates metadata output by utf8 byte length", () => { |
| 1209 | + const output = previewMetadata(String.fromCodePoint(0x4e00).repeat(10001)) |
1218 | 1210 |
|
1219 | | - expect(output.startsWith("...\n\n")).toBe(true) |
1220 | | - expect(Buffer.byteLength(output.slice("...\n\n".length), "utf-8")).toBeLessThanOrEqual(30_000) |
1221 | | - }), |
1222 | | - ), |
1223 | | - ) |
| 1211 | + expect(output.startsWith("...\n\n")).toBe(true) |
| 1212 | + expect(Buffer.byteLength(output.slice("...\n\n".length), "utf-8")).toBeLessThanOrEqual(30_000) |
| 1213 | + }) |
1224 | 1214 |
|
1225 | | - it.live("does not split surrogate pairs when truncating metadata output", () => |
1226 | | - runIn( |
1227 | | - projectRoot, |
1228 | | - Effect.gen(function* () { |
1229 | | - const result = yield* run({ |
1230 | | - command: `${bin} -e ${evalarg( |
1231 | | - "process.stdout.write(String.fromCharCode(97)+String.fromCodePoint(0x1f642).repeat(15000)+String.fromCharCode(98))", |
1232 | | - )}`, |
1233 | | - description: "Generate emoji output exceeding metadata byte limit", |
1234 | | - }) |
1235 | | - const output = result.metadata.output |
1236 | | - if (typeof output !== "string") throw new Error("expected metadata output") |
| 1215 | + test("does not split surrogate pairs when truncating metadata output", () => { |
| 1216 | + const output = previewMetadata( |
| 1217 | + String.fromCharCode(97) + String.fromCodePoint(0x1f642).repeat(15000) + String.fromCharCode(98), |
| 1218 | + ) |
| 1219 | + const first = output.charCodeAt("...\n\n".length) |
1237 | 1220 |
|
1238 | | - const first = output.charCodeAt("...\n\n".length) |
1239 | | - expect(output.startsWith("...\n\n")).toBe(true) |
1240 | | - expect(first < 0xdc00 || first > 0xdfff).toBe(true) |
1241 | | - }), |
1242 | | - ), |
1243 | | - ) |
| 1221 | + expect(output.startsWith("...\n\n")).toBe(true) |
| 1222 | + expect(first < 0xdc00 || first > 0xdfff).toBe(true) |
| 1223 | + }) |
1244 | 1224 |
|
1245 | 1225 | it.live("full output is saved to file when truncated", () => |
1246 | 1226 | runIn( |
|
0 commit comments