feat: truncate --fields body uniformly (task 0021)
Rule that the `body` extra field truncates at 500 chars like `issue view`, resolving the spec's Principle 3 / Command Surface contradiction. Route the `body` extractor through a new `truncatedBody()` FieldDef so `issue list`, `issue create`, `pr list`, and `search` all present it exactly as the detail views do, and add a `--full` flag to each to suppress truncation, keeping the inline hint's "use --full" promise honest.
This commit was merged in pull request #21.
This commit is contained in:
@@ -323,6 +323,46 @@ describe("search issues --fields", () => {
|
||||
expect(row).toContain("http://gitea.example/testowner/testrepo/issues/42");
|
||||
});
|
||||
|
||||
it("applies the body-truncation ruling to a match body, and --full suppresses it", async () => {
|
||||
// Truncated inline at 500 chars with the hint.
|
||||
server = await startFixtureServer([
|
||||
{
|
||||
method: "GET",
|
||||
path: SEARCH_PATH,
|
||||
body: [searchIssueOf(42, { body: "x".repeat(650) })],
|
||||
},
|
||||
]);
|
||||
const truncated = await runCliTest(
|
||||
["search", "issues", "login", "--fields", "body"],
|
||||
{ env: testModeEnv(server.url) },
|
||||
);
|
||||
|
||||
expect(truncated.exitCode).toBe(0);
|
||||
expect(truncated.stdout).toContain("x".repeat(500));
|
||||
expect(truncated.stdout).toContain(
|
||||
"... (truncated, 650 chars total - use --full to see complete body)",
|
||||
);
|
||||
expect(truncated.stdout).not.toContain("x".repeat(650));
|
||||
|
||||
// --full returns the body raw, with no truncation hint.
|
||||
await server.close();
|
||||
server = await startFixtureServer([
|
||||
{
|
||||
method: "GET",
|
||||
path: SEARCH_PATH,
|
||||
body: [searchIssueOf(42, { body: "x".repeat(650) })],
|
||||
},
|
||||
]);
|
||||
const full = await runCliTest(
|
||||
["search", "issues", "login", "--fields", "body", "--full"],
|
||||
{ env: testModeEnv(server.url) },
|
||||
);
|
||||
|
||||
expect(full.exitCode).toBe(0);
|
||||
expect(full.stdout).toContain("x".repeat(650));
|
||||
expect(full.stdout).not.toContain("truncated");
|
||||
});
|
||||
|
||||
it("rejects an unknown --fields name with VALIDATION_ERROR", async () => {
|
||||
server = await startFixtureServer([]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user