Skip to content

fix: provenance and syntax highlighting respect --no-color and pipe detection#2281

Merged
aknysh merged 4 commits intomainfrom
osterman/provenance-no-color
Apr 3, 2026
Merged

fix: provenance and syntax highlighting respect --no-color and pipe detection#2281
aknysh merged 4 commits intomainfrom
osterman/provenance-no-color

Conversation

@osterman
Copy link
Copy Markdown
Member

@osterman osterman commented Apr 2, 2026

what

  • Provenance output (describe component --provenance) now strips ANSI color codes when stdout is piped or redirected, and respects --no-color
  • Syntax highlighting via HighlightCodeWithConfig also properly degrades when stdout is piped
  • Provenance output now routes through data.Write() instead of fmt.Print() for proper I/O channel handling

why

  • Provenance rendering used lipgloss.NewStyle() unconditionally without checking stdout TTY status, so ANSI escape codes leaked into piped/redirected output
  • HighlightCodeWithConfig checked IsTTYSupportForStdout() || IsTTYSupportForStderr() — since stderr remains a TTY when piping stdout, this always returned true and defeated pipe detection
  • fmt.Print() bypassed the data channel I/O layer, skipping secret masking

references

  • Follows the same stdout-only TTY check pattern used by list commands (pkg/list/list_values.go)
  • Mirrors HighlightCodeWithConfig's precedence: NoColor wins, then ForceColor, then stdout TTY detection

Summary by CodeRabbit

  • Improvements

    • More precise color handling for provenance and code highlighting: honors NoColor/ForceColor and now detects stdout TTY only for consistent styling.
    • Provenance rendering disables styling when color is off.
    • Provenance stdout output now flows through the shared output path for more consistent display.
  • Bug Fixes

    • Normalized spacing and newline placement around provenance legends and stack headers.
  • Tests

    • Updated/added tests and golden snapshots to reflect whitespace, legend formatting, and color/no-color behaviors.

…hen piping

Provenance output (`describe component --provenance`) emitted ANSI escape codes
when stdout was piped or redirected, and did not respect `--no-color`. Two root
causes: (1) provenance rendering used `lipgloss.NewStyle()` unconditionally
without checking stdout TTY status, and (2) `HighlightCodeWithConfig` checked
`IsTTYSupportForStdout() || IsTTYSupportForStderr()` which always returned true
when piping since stderr remains a TTY.

- Add `isProvenanceColorEnabled()` that checks NoColor, ForceColor, then stdout
  TTY — matching the pattern used by list commands
- Thread `useColor` bool through all provenance rendering functions so lipgloss
  calls are skipped entirely when color is disabled
- Fix `HighlightCodeWithConfig` to check only stdout TTY (data channel output)
- Route provenance output through `data.Write()` instead of `fmt.Print()`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@osterman osterman requested a review from a team as a code owner April 2, 2026 19:56
@github-actions github-actions bot added the size/s Small size PR label Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Dependency Review

✅ No vulnerabilities or license issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA d2fca70.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cec09240-97c7-4c17-9e65-094cafe43570

📥 Commits

Reviewing files that changed from the base of the PR and between fa5c3b4 and d2fca70.

📒 Files selected for processing (1)
  • pkg/provenance/tree_renderer_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/provenance/tree_renderer_test.go

📝 Walkthrough

Walkthrough

Routes provenance stdout through the shared writer, threads a computed color toggle through provenance rendering to honor terminal color settings, restricts syntax-highlight terminal detection to stdout TTY only, normalizes whitespace in provenance snapshot goldens, and adds tests for color/no-color rendering behavior.

Changes

Cohort / File(s) Summary
Output Routing
internal/exec/describe_component.go
Writes provenance stdout via data.Write(output) instead of fmt.Print, preserving file vs stdout branching.
Provenance Rendering & Tests
pkg/provenance/tree_renderer.go, pkg/provenance/tree_renderer_test.go
Introduces useColor determination (honors Terminal.NoColor, Terminal.ForceColor, stdout TTY), threads it through RenderTree/renderFileTree/legend/inline comments, updates color helpers to be conditional, and adds extensive tests for color/no-color paths.
Highlight Terminal Detection
pkg/utils/highlight_utils.go
Changes highlighting detection to check only stdout TTY (IsTTYSupportForStdout()), removing stderr TTY consideration; affects when highlighting is applied.
Snapshot Normalization
tests/snapshots/*describe_component*_*.stdout.golden
Whitespace and blank-line normalization in provenance legend and stack sections across multiple golden snapshots.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • aknysh
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 59.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: enabling provenance and syntax highlighting to respect --no-color flag and pipe detection.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/provenance-no-color

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/exec/describe_component.go (1)

257-265: ⚠️ Potential issue | 🟠 Major

Don't render ANSI before the file branch.

RenderInlineProvenanceWithStackFile() runs before this decides between stdout and writeOutputToFile(), so describe component --provenance --file out.yaml from a TTY will still save ANSI escape sequences. Please pass a destination-aware plain/color override into the renderer and its highlighting path so file output stays plain unless color is explicitly forced.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/exec/describe_component.go` around lines 257 - 265,
RenderInlineProvenanceWithStackFile is being called before we decide whether
output goes to a file, so ANSI escapes are embedded even when
writeOutputToFile(file, ...) is used; change the call site to determine the
destination first and pass a destination-aware color/plain override into
RenderInlineProvenanceWithStackFile (or its internal highlighting helper) so it
renders plain for file output and colored for TTY stdout (unless color is
explicitly forced). Concretely, compute the output target (file != ""), derive a
boolean or enum like useColor based on that target and existing force-color
flags, and pass that flag into p.RenderInlineProvenanceWithStackFile (and any
highlighting functions it calls) instead of rendering first and then choosing
writeOutputToFile or data.Write.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@internal/exec/describe_component.go`:
- Around line 257-265: RenderInlineProvenanceWithStackFile is being called
before we decide whether output goes to a file, so ANSI escapes are embedded
even when writeOutputToFile(file, ...) is used; change the call site to
determine the destination first and pass a destination-aware color/plain
override into RenderInlineProvenanceWithStackFile (or its internal highlighting
helper) so it renders plain for file output and colored for TTY stdout (unless
color is explicitly forced). Concretely, compute the output target (file != ""),
derive a boolean or enum like useColor based on that target and existing
force-color flags, and pass that flag into p.RenderInlineProvenanceWithStackFile
(and any highlighting functions it calls) instead of rendering first and then
choosing writeOutputToFile or data.Write.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29ef25ba-98fb-4824-be87-31bbef514816

📥 Commits

Reviewing files that changed from the base of the PR and between 1c18f61 and f3c4163.

📒 Files selected for processing (3)
  • internal/exec/describe_component.go
  • pkg/provenance/tree_renderer.go
  • pkg/utils/highlight_utils.go

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 2, 2026
@osterman osterman added the patch A minor, backward compatible change label Apr 2, 2026
… removal

The prior commit skips lipgloss styling when color is disabled (non-TTY),
which removes trailing whitespace padding from provenance legend lines.
Update the golden snapshot files to match the new clean output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/m Medium size PR and removed size/s Small size PR labels Apr 2, 2026
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 2, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 71.05263% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.22%. Comparing base (1c18f61) to head (d2fca70).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/provenance/tree_renderer.go 72.22% 6 Missing and 4 partials ⚠️
internal/exec/describe_component.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2281      +/-   ##
==========================================
+ Coverage   77.16%   77.22%   +0.05%     
==========================================
  Files        1045     1045              
  Lines       98367    98388      +21     
==========================================
+ Hits        75909    75981      +72     
+ Misses      18209    18157      -52     
- Partials     4249     4250       +1     
Flag Coverage Δ
unittests 77.22% <71.05%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/utils/highlight_utils.go 8.08% <100.00%> (ø)
internal/exec/describe_component.go 69.23% <0.00%> (+0.23%) ⬆️
pkg/provenance/tree_renderer.go 58.99% <72.22%> (+14.46%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cover the new useColor=false branches in tree_renderer.go:
- isProvenanceColorEnabled (nil, NoColor, ForceColor, default)
- colorize with useColor disabled
- formatProvenanceCommentWithStackFile plain-text output
- renderProvenanceLegend with/without stack file
- renderFileTree with empty/single/multiple file trees
- addProvenanceToLine padding, wrapping, and nil entry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/provenance/tree_renderer_test.go (1)

199-205: Add a compile-time sentinel for schema field references used here.

This test relies on schema.Terminal.NoColor and schema.Terminal.ForceColor; add a sentinel so field renames fail fast at compile time.

Suggested sentinel
+var _ = schema.Terminal{
+	NoColor:    true,
+	ForceColor: true,
+}
+
 func TestBuildYAMLPathMap_MultilineSupport(t *testing.T) {

As per coding guidelines "Add compile-time sentinels for schema field references in tests: when a test uses a specific struct field ..., add ... as a compile guard so a field rename immediately fails the build."

Also applies to: 214-215

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/provenance/tree_renderer_test.go` around lines 199 - 205, Add a
compile-time sentinel that references the schema.Terminal fields used by the
test so renames fail the build: declare a package-level unused variable like var
_ = schema.Terminal{NoColor: false, ForceColor: false} (placed in
pkg/provenance/tree_renderer_test.go near the test) to pin
schema.Terminal.NoColor and schema.Terminal.ForceColor; also add the same
sentinel or extend it to cover the other usage at the lines referenced (214-215)
so both test references are guarded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/provenance/tree_renderer_test.go`:
- Around line 249-253: The test "useColor true returns styled text" currently
only checks that colorize(text, color, true) contains the original text, which
can pass if no styling is applied; update the test to assert the colored branch
actually changes the output by adding a non-equality check (e.g.,
assert.NotEqual(t, text, result)) or assert that the result contains ANSI escape
sequences; target the colorize call and the t.Run block to add this additional
assertion so the true branch is validated.
- Around line 221-229: The test hardcodes expected:false for the "default config
without TTY" case which couples it to the test runner environment; instead set
expected to the actual stdout TTY probe result at test runtime (e.g., compute
expected := term.IsTerminal(int(os.Stdout.Fd())) or use the package's existing
stdout/TTY probe helper) and assert against that value so the test checks
behavior not a fixed environment assumption; update the test case that
constructs schema.AtmosConfiguration / schema.AtmosSettings / Terminal to use
that computed expected value.

---

Nitpick comments:
In `@pkg/provenance/tree_renderer_test.go`:
- Around line 199-205: Add a compile-time sentinel that references the
schema.Terminal fields used by the test so renames fail the build: declare a
package-level unused variable like var _ = schema.Terminal{NoColor: false,
ForceColor: false} (placed in pkg/provenance/tree_renderer_test.go near the
test) to pin schema.Terminal.NoColor and schema.Terminal.ForceColor; also add
the same sentinel or extend it to cover the other usage at the lines referenced
(214-215) so both test references are guarded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b1ad406-74a1-45a8-8a92-3b10e7ab4ff5

📥 Commits

Reviewing files that changed from the base of the PR and between 33deff5 and fa5c3b4.

📒 Files selected for processing (1)
  • pkg/provenance/tree_renderer_test.go

Make TTY test case dynamic instead of hardcoding expected value, and
strengthen colorize assertion to verify ANSI codes are actually produced.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aknysh aknysh merged commit b51717f into main Apr 3, 2026
57 checks passed
@aknysh aknysh deleted the osterman/provenance-no-color branch April 3, 2026 16:24
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

These changes were released in v1.215.0-rc.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants