Skip to content

tests: add unit tests for app/utils/tool_trace.py and app/utils/traci…#2630

Open
HaMZAAsif043 wants to merge 5 commits into
Tracer-Cloud:mainfrom
HaMZAAsif043:issue-2594-tests
Open

tests: add unit tests for app/utils/tool_trace.py and app/utils/traci…#2630
HaMZAAsif043 wants to merge 5 commits into
Tracer-Cloud:mainfrom
HaMZAAsif043:issue-2594-tests

Conversation

@HaMZAAsif043
Copy link
Copy Markdown

tests: add unit tests for app/utils/tool_trace.py and app/utils/tracing.py

Fixes #2594

Describe the changes you have made in this PR -

Added comprehensive unit tests for app/utils/tool_trace.py and app/utils/tracing.py inside tests/utils/. The tests verify:

  • Redacting sensitive keys recursively in collections.
  • Formatting JSON previews correctly including truncation.
  • Tool trace entry formatting and UI output limits.
  • Validating the traceable decorator acts as a no-op identity decorator preserving metadata.

Demo/Screenshot for feature changes and bug fixes -

image image image

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • [X ] Yes, I used AI assistance (continue below)

If you used AI assistance:

  • [X ] I have reviewed every single line of the AI-generated code
  • [ X] I can explain the purpose and logic of each function/component I added
  • [ X] I have tested edge cases and understand how the code handles them
  • [ X] I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:


Checklist before requesting a review

  • [ x] I have added proper PR title and linked to the issue
  • [ x] I have performed a self-review of my code
  • [ x] I can explain the purpose of every function, class, and logic block I added
  • [ x] I understand why my changes work and have tested them thoroughly
  • [ x] I have considered potential edge cases and how my code handles them
  • [ x] If it is a core feature, I have added thorough tests
  • [ x] My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

Copilot AI review requested due to automatic review settings May 27, 2026 19:40
@github-actions
Copy link
Copy Markdown
Contributor

Greptile code review

This repo uses Greptile for automated review. Before merge, aim for Confidence Score: 5/5 with zero unresolved review threads — see CONTRIBUTING.md.

Run a review — add a PR comment with:

@greptile review

Give it ~5-10 minutes (sometimes longer) for results, then fix feedback and re-trigger until you reach Confidence Score: 5/5.

Optional: automate with the greploop skill.

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds unit tests to validate no-op tracing behavior and tool-trace formatting/redaction utilities.

Changes:

  • Introduces tests for traceable decorator semantics and metadata preservation.
  • Adds redaction recursion/precedence tests for sensitive fields and runtime objects.
  • Adds formatting/truncation tests for JSON previews and tool trace entries.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tests/utils/test_tracing.py Verifies traceable behaves as a no-op decorator and preserves function metadata.
tests/utils/test_tool_trace.py Validates redaction, JSON preview formatting, and tool trace entry rendering/truncation.

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

Comment on lines +8 to +15
def test_traceable_returns_identity_decorator() -> None:
def traced_function() -> str:
return "ok"

assert traceable()(traced_function) is traced_function
assert traceable("investigation-step", extra="x")(traced_function) is traced_function


Comment thread tests/utils/test_tool_trace.py Outdated
Comment on lines +51 to +52
for scalar in (123, "plain", None, True):
assert redact_sensitive(scalar) is scalar
Comment on lines +44 to +47
assert redacted["items"] == [
{"password": "[redacted]"},
["public", {"_client": "[runtime object]"}],
]
Comment thread tests/utils/test_tool_trace.py Outdated

def test_format_tool_trace_entry_handles_empty_trace_record_and_output_limit() -> None:
formatted = format_tool_trace_entry({})
assert formatted == "- `tool` (iteration None)\n input: `{}`\n output: `null`"
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR adds unit tests for app/utils/tool_trace.py and app/utils/tracing.py, covering sensitive-key redaction, JSON preview formatting/truncation, trace-entry formatting, and the no-op @traceable decorator.

  • tests/utils/test_tool_trace.py: Four test functions verify redact_sensitive (including recursive and substring-match behaviour), format_json_preview (redaction, truncation, non-serialisable types), and format_tool_trace_entry (field precedence, loop labels, output caps). Two assertions are slightly loose: the empty-entry output field is checked for the label but not the null value, and the truncation length bound has an undocumented 8-char slack beyond what the implementation actually produces.
  • tests/utils/test_tracing.py: Two concise tests confirm the identity (is) contract of traceable and that decorated functions retain their original __name__, __doc__, arguments, and return value.

Confidence Score: 5/5

Test-only addition with no changes to production code; safe to merge.

The change is purely additive tests. All assertions are correct and will pass against the current implementation. The two looseness findings are minor precision nits that do not affect correctness or coverage of the intended behaviour.

No files require special attention.

Important Files Changed

Filename Overview
tests/utils/test_tool_trace.py Adds four test functions covering redaction, JSON preview, trace-entry formatting, and output limits. Assertions are mostly correct; two are slightly loose (output-field value not pinned, truncation bound has undocumented slack).
tests/utils/test_tracing.py Adds two tests for the no-op traceable decorator, correctly using identity (is) checks and verifying preserved metadata. No issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[test_redact_sensitive_recurses_into_nested_collections] --> R[redact_sensitive]
    B[test_redact_sensitive_handles_scalars_and_regex_precedence] --> R
    C[test_format_json_preview_redacts_truncates_and_stringifies] --> FJP[format_json_preview]
    FJP --> R
    D[test_format_tool_trace_entry_populates_fields_and_collapses_previews] --> FTTE[format_tool_trace_entry]
    E[test_format_tool_trace_entry_handles_empty_trace_record_and_output_limit] --> FTTE
    FTTE --> FJP
    F[test_traceable_returns_identity_decorator] --> T[traceable]
    G[test_traceable_preserves_args_kwargs_return_value_and_metadata] --> T
Loading

Reviews (6): Last reviewed commit: "style: ruff format test_tool_trace.py" | Re-trigger Greptile

Comment thread tests/utils/test_tool_trace.py Outdated
Comment thread tests/utils/test_tool_trace.py
Comment thread tests/utils/test_tool_trace.py
@cerencamkiran
Copy link
Copy Markdown
Collaborator

Could you please take a look at the Greptile and Copilot comments?

@HaMZAAsif043
Copy link
Copy Markdown
Author

Could you please take a look at the Greptile and Copilot comments?

yes on it

@HaMZAAsif043
Copy link
Copy Markdown
Author

@greptile review

@HaMZAAsif043
Copy link
Copy Markdown
Author

@greptile review

Comment thread tests/utils/test_tool_trace.py Outdated
@HaMZAAsif043
Copy link
Copy Markdown
Author

(iteration None) when loop_iteration is absent looks like an implementation
bug in format_tool_trace_entry — the absent case falls through to
f"iteration {None}" instead of being omitted. This is pre-existing in
app/utils/tool_trace.py, not introduced by this PR. Should I open a separate
issue for the fix, or pin the current behaviour in the test for now?

@HaMZAAsif043
Copy link
Copy Markdown
Author

@greptile review

1 similar comment
@HaMZAAsif043
Copy link
Copy Markdown
Author

@greptile review

@cerencamkiran
Copy link
Copy Markdown
Collaborator

Thanks for fixing most of the comments

I still think the "is traced_function" checks are a bit too strict. A small "functools.wraps" no-op wrapper could still be valid but would fail these tests. Could you either remove the "is" checks or add a short note saying object identity is intentionally part of the contract?

@HaMZAAsif043
Copy link
Copy Markdown
Author

Added a comment clarifying that object identity is intentional here traceable is a no-op and should return the original function, not a wrapper.
Happy to change it if the contract is meant to be looser.

… here

	raceable is a no-op and should return the original function, not a wrapper.
@cerencamkiran
Copy link
Copy Markdown
Collaborator

@greptile review

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.

tests: add unit tests for app/utils/tool_trace.py and app/utils/tracing.py

4 participants