-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix "Always expand running logs" behavior on subsequent updates #34964
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
Conversation
Sorry I am not able to review the code written by AI, it looks more complex than it should be and really difficult to understand. To be simple, why not just remove the I would suggest you to use AI as reference and rewrite the code to make sure every line is clear and maintainable. |
this.currentJobStepsStates[i] = {cursor: null, expanded: shouldExpand}; | ||
} else if (this.optionAlwaysExpandRunning && isRunning && !this.currentJobStepsStates[i].expanded) { | ||
// auto-expand running steps on subsequent loads (handles step transitions) | ||
this.currentJobStepsStates[i].expanded = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract the loop's body to a separate function, then we only need to test that function's behavior.
For example:
for (let i = 0; i < this.currentJob.steps.length; i++) {
syncCurrentJobStepsStates(i);
}
Then we only need to mock some related variables to test syncCurrentJobStepsStates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
So, we can, sort of, but look at how many internal references the body of the loop has ... currentJob, currentJobStepsStates, optionAlwaysExpandRunning, etc. It's not impossible to set that up and mock it, but it's also not as trivial as it seems? The question is also - what's the goal of the test? You're looking at this after-the-fact, I wrote the test before I fixed the bug, so I wanted a test that reproduced the bug behavior itself as a failing test. Doing what you suggest requires knowing in advance what the fix is, which also means that it's impossible to write a test before you know what the fix is. It's a different approach, that's all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not impossible to set that up and mock it, but it's also not as trivial as it seems?
IMO it should be easier than the vue mock. And we have clear data definition for various cases.
what's the goal of the test?
Make the logic correct.
You're looking at this after-the-fact .... it's impossible to write a test before you know what the fix is. It's a different approach
I also wrote a lot of code to test something, and if the test code is not necessary, I won't leave them in the code base. We can only keep the necessary tests to test what we want. We can still make the tests fail with old approach, and pass with new approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so you want just logic tests, not behavior tests. That's fine - I didn't realize that was the project's convention. I can try to do that. When I test, I tend to test behavior, not logic - logic, once written, doesn't usually "break" - but behavior often does, so in my experience it's been a better safety net to test behaviors. Apologies for the misstep, I will match your conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are always good and welcome, and I agree that many components lack tests (well, crowd-contributed open-source project, I am not able to convince everyone to write tests properly, not everyone has that much time).
IMO:
- The best: we can have proper tests, including behavior tests.
- Good: cover most core logic.
- Acceptable: fully manually tested.
Meanwhile, the most important: the code should be overall right and maintainable, that's the first rule.
Disclaimer: that's just my personal opinion, I am not native speaker so sometimes my expression might not be accurate. Thank you for understanding.
@wxiaoguang are you referring to the test code? I don't think the fix code itself is that difficult to understand. The test code has to setup a bunch of stuff because of the Vue component, otherwise mounting the view just fails and makes any test impossible. Edit: had AI generate a code review below for you. |
Code ReviewThis PR successfully addresses the "Always expand running logs" bug by fixing the auto-expansion behavior on subsequent job updates. Here's my analysis: ✅ Strengths
|
Please post the understanding from you but not from an AI robot .........
AbortController: it is necessary to avoid duplicate requests, and cancel the previous request before sending a new one.
What's the difference? |
To be clear - I'm trying as much as possible to fix a behavior I'm seeing without disrupting what's there ... I can try removing the Re: the abort controller - I spent a disproportionate amount of time around that code - the AI couldn't make heads or tails of it. I hadn't used AbortController in the past, so I looked at the docs on MDN to familiarize myself with what it's supposed to be doing. As near as I could tell, the way that it's being used in this code wasn't necessary, but similar question as before - what's the current purpose of the abortcontroller check that I removed -- it doesn't seem to match what you wrote -- " to avoid duplicate requests, and cancel the previous request before sending a new one"? No tests were written, so it's nearly impossible for an outsider to understand the intent of the current code, especially when it seems like it isn't working correctly. This is why I try to leave things as they are as much as possible, since I can't know what might break if I make changes without understanding the intent. I'll see what I can do to simplify this and maybe just remove any testing since that seems to be problematic since the frontend hasn't been developed with this in mind. |
If you don't understand how the current code works, why you fully trust the AI's code? I believe the developers themselves should fully understand the code when making changes, right? |
Why it doesn't match? Could you show a real example? |
There's a few examples in the previously linked MDN docs, is that what you mean? |
I also read MDN docs. I don't see any problem. If you think there is a problem, please show the details, based on our code: what are the steps to prove that the problem exists? For example, you can show the real example: do step1, then step2, then step3, expect to see A, but we get B, then mismatch. Otherwise, I am not able to know what is the "mismatch" mentioned by your review. |
What's your impression of what this line of code is intended to do?
|
I checked if just removing the |
So we must make sure that after There won't cause difference in current code base, but to make the whole design stable, it's good to keep. At least, it isn't wrong and doesn't cause any problem. |
It makes it impossible to test for some reason - even using I'll close this for now and maybe try again without any tests. Sorry for the bother. |
Summary
Fixes the "Always expand running logs" setting behavior so that it properly auto-expands running log steps on subsequent job updates, not just on the initial page load.
Problem
Currently, the "Always expand running logs" setting only works when the Actions page is first loaded (
isFirstLoad = true
). If a a running step is collapsed, or if a step transitions from "waiting" to "running" status during subsequent job updates, the logs do not auto-expand even though the setting is enabled.Solution
Modified
RepoActionView.vue
to:Test Coverage
Added basic tests (☹️ .
RepoActionView.autoExpand.test.ts
) to reproduce buggy behavior. This was challenging because of how the Vue component is currently written - introduced a (hopefully) minor refactoring to simplify mocking theloadJobData
function by optionally allowing injection of it. Also removed a check of theabortController
that I think is unnecessary -if (this.loadingAbortController !== abortController) return
-- this was really making the testing difficult and I'm not 100% sure what was going on behind the scenes to make it so, but according to the MDN docs, this line shouldn't be necessary - the line to read from the response,await resp.json()
will fail with an AbortError if the request was aborted at any point before the response is read. There's already try/catch handling of the AbortError further down, so this should still be handled. Apologies if I'm parsing this wrong, it just seems impossible to get a component test past this line otherwiseChanges Made
web_src/js/components/RepoActionView.vue
: Enhanced theloadJob
method to handle auto-expansion on all updatesweb_src/js/components/RepoActionView.autoExpand.test.ts
: Added focused tests for the auto-expand functionalitypackage.json
/package-lock.json
: Added@vue/test-utils
dependency for testingp.s. interestingly when I was testing this "live", I found that with the auto-expand behavior working, the current auto-scroll logs (see #34957) worked better ... until it got to a long step that was updating a lot ... then it broke again, so I think #34957 is still needed.