#13

Fix CI log output and follow polling

MergedxlabMembermerged intofrom

Summary

  • include every actionLogs entry in human try ci logs output, ordered by the first log timestamp, before the process stdout/stderr streams
  • implement try ci logs --follow as real polling until the API reports done
  • emit only appended bytes while following and ignore a temporarily shorter/stale snapshot so already printed output is not duplicated
  • keep JSON follow output machine-readable by printing the final payload once

Verification

  • cargo fmt --check
  • cargo test --test trylle_cli_commands_mock ci_logs_
  • cargo test --lib
  • the new integration tests cover joined human output, repeated polling, appended-byte cursors, and a shorter intermediate snapshot

The unrelated base tests pr_view_human_output_renders_markdown_body_after_checks and npm_check_json_reports_the_scoped_installation also fail on the untouched master checkout. The latter still expects version 1.1.0 while the current checkout reports 1.1.3.

Activity

4
trylle-botreviewed4mo ago
trylle-bot4mo ago

First-pass review from an automated senior-engineer reviewer. No approval / change request — just observations for a human to weigh.

What changed

  • try ci logs / try ci watch now render through a shared emit_ci_logs → ci_log_components path that also surfaces every actionLogs entry, ordered by the first RFC3339 timestamp in each body, before stdout/stderr (src/trylle/mod.rs:2136).
  • try ci logs --follow is now real: follow_ci_logs polls /v1/ci/jobs/{run_id}/logs on an interval until the payload reports "done": true (src/trylle/mod.rs:2130). The flag existed before but was silently ignored (the old arm matched Logs { .., }).
  • Human follow prints only appended bytes via CiLogCursor::delta; JSON follow suppresses intermediate payloads and prints the final one once.
  • Poll cadence is overridable through TRYLLE_CLI_CI_LOG_POLL_INTERVAL_MS (default 1000ms), which is also what makes the new tests fast.

Risk areas

  • CiLogCursor::delta re-emits the entire body on any non-prefix change (src/trylle/mod.rs:2118). The Some(_) | None arm fires whenever the new body is neither a superset-prefix nor a stale prefix of the previous one — e.g. a log tail rewritten in place (\r progress bars, ANSI re-render) or a server-side reformat. In that case the whole current body is reprinted, duplicating bytes already streamed, which is exactly the behavior --follow is meant to avoid. Normal append-only logs are prefix-stable so this won't trigger for them, but it's the one path where the dedup contract breaks. Worth a comment or a test covering a divergent snapshot.
  • No JSON-follow test coverage. The new tests exercise joined human output, appended-byte polling, and the shorter-snapshot case, but the JSON follow branch in follow_ci_logs (poll-until-done, print once) has no test. It's the branch most likely to regress silently since it produces no incremental output.
  • Unbounded polling. follow_ci_logs loops until done == true; a payload that never sets done (or omits it) polls forever with no cap or backoff. Acceptable for an interactive --follow, but there's no ceiling if the API stalls.
  • Cross-stream ordering is positional, not chronological. ci_log_components sorts action logs by timestamp but always emits all action logs, then stdout, then stderr. Interleaving between an action log and process stdout is lost even when timestamps would interleave them. Matches the PR's stated intent; flagging so it's a conscious choice.

Suggested follow-ups

  • Consider routing CiCommand::Watch (src/trylle/mod.rs:2067) through follow_ci_logs: its help says "Watch a CI run until it completes," but it remains a single one-shot fetch (unchanged by this PR). The polling helper now exists to make it actually watch.
  • Add a delta test where consecutive snapshots diverge (non-prefix) to pin down the intended behavior of the re-emit branch above.

The two unrelated base-test failures called out in the PR body (pr_view_human_output_renders_markdown_body_after_checks, npm_check_json_reports_the_scoped_installation) aren't touched by this diff and match a pre-existing version-string drift on master.

xlab merged commit 938d637 into master3mo ago

Branch fix/ci-logs-follow has been merged.

Checking branch