Skip to content
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

Fix #9151 (cabal init logs at loglevel "Log") #9346

Merged
merged 9 commits into from
Dec 5, 2023

Conversation

aleeusgr
Copy link
Contributor

@aleeusgr aleeusgr commented Oct 17, 2023

The actual ADT for severity should change because "Log" is useless as a datatype, arguably it shouldn't even be an entry in the ADT and the severity should be at Info for everything that's not a Warn.

QA notes:

when calling cabal init the user sees log entries categorized as Info, while entries categorized as Log should not appear.

@aleeusgr aleeusgr changed the title draft: Fix9151 Fix #9151 Oct 17, 2023
changelog.d/pr-9346 Outdated Show resolved Hide resolved
Copy link
Collaborator

@andreabedini andreabedini left a comment

Choose a reason for hiding this comment

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

I am in with this change. I left a couple of comments.

@fgaz fgaz linked an issue Oct 17, 2023 that may be closed by this pull request
@fgaz fgaz changed the title Fix #9151 Fix #9151 (cabal init logs at loglevel "Log") Oct 17, 2023
Copy link
Collaborator

@geekosaur geekosaur left a comment

Choose a reason for hiding this comment

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

Not repeating the points that have already been raised.

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Oct 18, 2023

Validation test is broken.

Todo:

  • what's a validation test?
    Validation testing is a process of evaluating software during or at the end of the development process to ensure that it meets specified business requirements.
  • does it have to do with where I placed the function?
  • is it something that will resolve itself?

@emilypi
Copy link
Member

emilypi commented Oct 18, 2023

@aleeusgr Re: validation tests - i'll take a look in a bit to remind myself.

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Oct 18, 2023

OK. Meanwhile I'll try to run the failing test locally in 9.2.8

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Oct 19, 2023

All checks pass. Maybe guard expression caused validate test to fail.

@emilypi please check QA note I added at the top of this PR.
I will add the change suggested by @ulysses4ever unless there are objections.

I need to

  • rebase the PR to the latest of master branch.
  • Think about testing strategy
  • wait for second approval
  • add squash and merge label.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 22, 2023

@aleeusgr: don't hesitate to mark the PR with help_needed and ping the Matrix channel if you feel blocked.

@aleeusgr
Copy link
Contributor Author

Hi @Mikolaj
I think we did everything that was planned here and checks pass.

I was waiting for the second approval, I don't know how things work here: I assumed someone would ping me if any actions are needed.

@emilypi could you confirm we achieved our goals for this PR?

Thanks.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 22, 2023

I was looking at your checklist in the comment above. Any ideas for an automated test?

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Nov 22, 2023

Maybe we could parse the log output line by line and fail if [Log] shows up?
@Mikolaj is this a sound thing to do?

@Mikolaj
Copy link
Member

Mikolaj commented Nov 23, 2023

Sounds good to me. Perhaps also check the test output is not empty (and make sure the cabal-install commands issued in the test really should log something). Alternatively, there are golden tests somewhere (see the READMEs in the test folders and also CONTRIBUTING) so, if they apply to this situation, you can ensure the log output is always exactly the same as you record and accept initially. I suppose cabal init logs are deterministic, so that may work.

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Nov 23, 2023

  • write/find a test that interacts with log output of cabal-install
  • look at suites:
    • unit tests
    • integration tests
    • long tests

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Nov 24, 2023

what is a golden test ?
Golden test is like a unit test but its output is stored in a file.

Golden tests define 6 test groups which correspond(?) to this comment:

-- * Empty flags, non-simple target gen, no special options
-- * Empty flags, simple target gen, no special options
-- * Empty flags, non-simple target gen, with generated comments (no minimal setting)
-- * Empty flags, non-simple target gen, with minimal setting (no generated comments)
-- * Empty flags, non-simple target gen, minimal and generated comments set.

five lines vs 6 test groups. The first group is one ring to rule them all:

"golden"
[ goldenLibTests v pkgIx pkgDir pkgName
, goldenExeTests v pkgIx pkgDir pkgName
, goldenTestTests v pkgIx pkgDir pkgName
, goldenPkgDescTests v srcDb pkgDir pkgName
, goldenCabalTests v pkgIx srcDb
]

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Nov 24, 2023

https://github.com/haskell/cabal/tree/master/cabal-install/tests#integration-tests

each test is a shell script.
🤔
But I don't see any .sh files, for example cabal-install/tests contains no shell scripts.

Looking at the file, it contains only test trees but no test code.

The list of unit tests can be found in cabal-install.cabal

The functionality I added relates to Init command, so I should look at

import qualified UnitTests.Distribution.Client.Init

There are five test trees(?) imported in init: FileCreators, Interactive, Non-interactive, Golden, Simple.

@aleeusgr
Copy link
Contributor Author

aleeusgr commented Nov 26, 2023

to run tests:
nix develop github:yvan-sraka/cabal.nix

Parsing log outputs:
https://stackoverflow.com/questions/42702618/parsing-a-log-file-in-haskell
https://dev.to/anaynayak/haskell-parsing-a-log-message-1290
https://hackage.haskell.org/package/attoparsec

@emilypi
Copy link
Member

emilypi commented Nov 26, 2023

What you could do is probably add a parameter to add a log queue accumulator in the prompt state. I.e.

newtype PurePrompt a = PurePrompt
  { _runPrompt
      :: NonEmpty String
      -> Either BreakException (a, NonEmpty String)
  }
  deriving (Functor)

Should turn into the following:

type LogQueue = [Text]

newtype PurePrompt a = PurePrompt
{ _runPrompt
    :: NonEmpty String
    -> Either BreakException (a, NonEmpty (LogQueue, String))
}
deriving (Functor)

Then the instances will need to be adjusted so that dedicated log functions are used which pipe to the correct behaviors in the IO case and the PurePrompt case. This is extracurricular. I think if you establish that the log output is doing the correct thing in a screenshot and raise an issue to track logging in PurePrompt state, I'll accept the PR.

@aleeusgr
Copy link
Contributor Author

image

Copy link
Member

@emilypi emilypi left a comment

Choose a reason for hiding this comment

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

Great job @aleeusgr :)

Congrats on contributing to Cabal!

@emilypi emilypi added the squash+merge me Tell Mergify Bot to squash-merge label Nov 29, 2023
@aleeusgr
Copy link
Contributor Author

Thank you @emilypi
It's a pleasure 😀

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Dec 1, 2023
@aleeusgr
Copy link
Contributor Author

aleeusgr commented Dec 5, 2023

dear @geekosaur or @emilypi

I regret to inform you that there is a problem with merging this PR:
image

I wonder what I could do to make it go through but it looks I am powerless in this situation.

Thank you for your attention

@Mikolaj
Copy link
Member

Mikolaj commented Dec 5, 2023

Strange. Let me rebase.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 5, 2023

@mergify rebase

Copy link
Contributor

mergify bot commented Dec 5, 2023

rebase

✅ Branch has been successfully rebased

@mergify mergify bot merged commit d9af0dc into haskell:master Dec 5, 2023
51 checks passed
@Mikolaj
Copy link
Member

Mikolaj commented Dec 5, 2023

Success! It must have been a mergify hiccup (and then a GHA random hangup, which I restarted).

@aleeusgr: congrats again! :)

erikd pushed a commit to erikd/cabal that referenced this pull request Apr 22, 2024
* rm Log from Severity loglevels

* replace Log with Info

* add changelog

* fix typo

* fix changelog entry

* add displaySeverity

* fix changelog

* run fourmolu

* implement case expression in displaySeverity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cabal init logs at loglevel "Log"?
6 participants