Skip to content

Characterize user-facing log messages #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025

Conversation

blairconrad
Copy link
Contributor

Contributes to #172, implementing

  1. Capture INFO and worse log output in the lib.rs tests, to characterize the state of things now
  2. Add additional tests at this level, to cover the various situations that can cause a change to not be absorbed

src/lib.rs Outdated

let mut revwalk = ctx.repo.revwalk().unwrap();
revwalk.push_head().unwrap();
assert_eq!(revwalk.count(), 2); // git rebase wasn't called so both commits persist
let is_something_in_index = !nothing_left_in_index(&ctx.repo).unwrap();
assert!(is_something_in_index);

log_utils::assert_log_messages_match(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably overkill. When I wrote it, I thought I'd be using it more. If we restrict ourselves to just checking the level and msg, this could go away.

Copy link
Owner

Choose a reason for hiding this comment

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

yeah i think this is too fussy for my tastes. let's not make future test writers jump through this hoop - the message alone is good enough

src/lib.rs Outdated
log_utils::assert_log_messages_are(
capturing_logger.visible_logs(),
vec![
&json!({"level": "WARN", "msg": "Could not find a commit to fix up, use --base to increase the search range."}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops. Some of the lines exceed the 100 char limit that the repo seems to aim for. Later commits for my grand plan end up fixing this (often the messages are different anyhow). Can reformat if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since no comment from you yet, pushing shortened log lines. I hope it doesn't cause confusion.

@blairconrad blairconrad force-pushed the characterize-logging branch 2 times, most recently from 6294a8e to 65cf27a Compare April 6, 2025 19:59
@blairconrad
Copy link
Contributor Author

I see some log-affecting PRs coming in. I don't think they'll conflict with this, but if they get merged, I'll assess and rebase.

Copy link
Owner

@tummychow tummychow left a comment

Choose a reason for hiding this comment

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

this works for me. i'd like to see a refactor to use SlogValue, but it doesn't have to be in this pr, maybe you even have a draft of that coming up. unfortunately it looks like the clippy lint fixes conflicted with this one, so it'll require a small rebase

src/lib.rs Outdated

let mut revwalk = ctx.repo.revwalk().unwrap();
revwalk.push_head().unwrap();
assert_eq!(revwalk.count(), 2); // git rebase wasn't called so both commits persist
let is_something_in_index = !nothing_left_in_index(&ctx.repo).unwrap();
assert!(is_something_in_index);

log_utils::assert_log_messages_match(
Copy link
Owner

Choose a reason for hiding this comment

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

yeah i think this is too fussy for my tastes. let's not make future test writers jump through this hoop - the message alone is good enough

We're about to make some changes to log messages,
so let's first see what we're logging to ensure
we don't break anything.
@blairconrad blairconrad force-pushed the characterize-logging branch from 65cf27a to 9a2e693 Compare April 12, 2025 21:07
@tummychow tummychow merged commit a8fb298 into tummychow:master Apr 12, 2025
6 checks passed
@blairconrad
Copy link
Contributor Author

blairconrad commented Apr 12, 2025

Thanks, @tummychow.

  • rebased to resolve clippy changes
  • removed assert_log_messages_match
  • added log-checking for the two new tests that appeared around the "message" option

i'd like to see a refactor to use SlogValue

Was not aware of SlogValue until your comment.
Will investigate.

Meanwhile, I'm pushing in case you want to merge (but I don't mind being stuck behind #177; whatever's easier for you).

@blairconrad
Copy link
Contributor Author

blairconrad commented Apr 12, 2025

haha, oops. I'd pushed without the log-checking in the extra test methods, then got called away. Came back, added them, and was about to push the updates. But I'm too late. Sorry.

(In this case the extra log-checking doesn't really add anything; all the "all hunks turned into commits" emit about the same log messages, unless the stack is bounded by another author or a merge.)

@blairconrad blairconrad deleted the characterize-logging branch April 12, 2025 23:30
@blairconrad
Copy link
Contributor Author

i'd like to see a refactor to use SlogValue

I've investigated and am not sure what you're looking for.

What are you hoping will use SlogValue?
Do you want the messages to become formalized and use a LogDetails and StatisticsLogger?

I experimented with a future message like

#[derive(Clone, ExtLoggable, Serialize)]
#[LogDetails(
    Id = "101",
    Text = "No changes staged, even after auto-staging. Try adding something to the index.",
    Level = "WARN"
)]
struct NoChangesStaged;

...

    if nothing_left_in_index(repo)? {
        xlog!(ui_logger, NoChangesStaged);
        return Ok(());
    }

And it may be something that will work, but I'm coming up with a panic when it runs.

@tummychow
Copy link
Owner

i don't really care about the statistics, but having typed logging objects would make the user-facing logs more consistent and testable. eg right now you have to write out the log message once at the callsite where it's logged, and again at the place where you're testing it. it would be better to get those things into a single place. if you can't get it working, that's fine, but i think it's worth an attempt

@blairconrad
Copy link
Contributor Author

I'll see what I can do.

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.

2 participants