Skip to content

fix(workflows): render gate show_file contents in the interactive prompt#2810

Open
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:fix/2809-gate-show-file
Open

fix(workflows): render gate show_file contents in the interactive prompt#2810
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:fix/2809-gate-show-file

Conversation

@doquanghuy
Copy link
Copy Markdown
Contributor

Description

Closes #2809.

The built-in gate step accepts a show_file config field. The value was read, template-expanded, and stored in output["show_file"], but its contents were never displayed at the interactive prompt — the operator was asked to approve/reject without seeing the referenced file.

This renders show_file inside the interactive gate prompt, before the options. A missing or undecodable file degrades to a short one-line notice instead of raising, so a misconfigured path never breaks the prompt.

What changed

  • GateStep._prompt(...) now accepts show_file and prints its contents (each line within the gate box) before the options.
  • New GateStep._read_show_file(...) helper reads the file as UTF-8 and returns a (could not read file: …) / (file is empty) notice on error/empty instead of raising.

Compatibility

  • Non-interactive (PAUSED) path is unchanged — the file is not read when stdin is not a TTY.
  • Exit codes, on_reject handling, and resume semantics are unchanged.
  • Gates without show_file produce byte-identical output to before.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync --extra test && uv run pytest — 3310 passed, 40 skipped
  • Tested with a sample project (if applicable)

Added three targeted tests in tests/test_workflows.py::TestGateStep:

  • interactive prompt renders show_file contents and returns the chosen option;
  • a missing show_file shows the notice and does not crash;
  • the non-interactive path still PAUSES and preserves output["show_file"] without reading the file.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Used Claude to trace the bug in gate/__init__.py, draft the fix and tests, and write this PR body. The behaviour was reproduced and the diff reviewed locally before submission.

@doquanghuy doquanghuy requested a review from mnriem as a code owner June 2, 2026 10:10
The gate step read and recorded `show_file` but never displayed its
contents at the interactive prompt, so the operator approved/rejected
without seeing the referenced file. Render the file inside the prompt
when stdin is a TTY, with a graceful notice for missing/unreadable
files. Non-interactive PAUSED behaviour, exit codes, resume semantics,
and no-`show_file` output are unchanged.

Closes github#2809.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the built-in workflow gate step so that a configured show_file is actually rendered in the interactive prompt, allowing operators to review the referenced file contents before choosing approve/reject. It adds a bounded, non-throwing file-read helper and extends test coverage around the interactive/non-interactive behaviors.

Changes:

  • Render show_file contents inside the interactive gate prompt (before the options).
  • Add _read_show_file() helper that caps output length and degrades to a one-line notice on read/decode errors.
  • Add targeted tests covering interactive rendering, missing files, non-interactive pause behavior, empty files, and truncation.
Show a summary per file
File Description
src/specify_cli/workflows/steps/gate/__init__.py Passes show_file into the gate prompt and safely renders file contents with truncation/error notices.
tests/test_workflows.py Adds regression tests for interactive rendering and safe behavior across missing/empty/large files and non-interactive runs.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment on lines +85 to +89
if show_file and isinstance(show_file, str):
print(" │")
print(f" │ {show_file}:")
for line in GateStep._read_show_file(show_file):
print(f" │ {line}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gate show_file is recorded but never displayed at the interactive prompt

3 participants