Skip to content

CLI: --tail-bytes 0 keeps the entire command output #195

Closed

Description

@FredApps

What went wrong?

The output or a command was wrong: --tail-bytes 0 keeps the entire command output instead of none.

DiffCI version

0.3.54 (main at 40aa308)

Command you ran

diffci verify --changed --tail-bytes 0 --out receipt.json (also check, gate and verify-savings, which take the same flag)

Environment

Ubuntu, Node.js 24.22.1, terminal.

What happens

tail in packages/diffci-cli/src/client/verify-savings.ts is:

function tail(value: string, bytes: number): string {
  if (Buffer.byteLength(value, "utf8") <= bytes) return value;
  return value.slice(-bytes);
}

With bytes 0, value.slice(-0) is value.slice(0), the whole string. measureCommand uses it for stdoutTail and stderrTail, and a selection that runs as a single command goes straight through measureCommand, so the receipt (and the outcome log) gets the complete output of the test run, up to the 256 MiB maxBuffer, where --tail-bytes 0 asks for none. A selection split into several parts already handles 0 correctly in measureCommands (options.tailBytes > 0 ? ... : ""), so the result depends on how the selection was batched.

measureCommand(`node -e "process.stdout.write('hello')"`, { cwd: tmpdir(), timeoutMs: 60000, tailBytes: 0 }).stdoutTail
// "hello", expected ""

A second, smaller problem in the same function: the length check counts bytes but the cut counts UTF-16 characters, so output with multi-byte characters keeps more than tailBytes bytes. "abcééé" with tailBytes: 3 keeps "ééé" (6 bytes).

What you expected

--tail-bytes 0 keeps no output, and a tail is at most tailBytes bytes, cut at a character boundary.

Regression test

packages/diffci-cli/tests/client/command-tail.test.ts in the linked pull request fails on main and passes with the fix.

Activity

  1. added a commit that references this issue on Nov 18, 2026
    d65b3ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions