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

Refactored metadata linting #1851

Merged
merged 1 commit into from
May 9, 2023
Merged

Refactored metadata linting #1851

merged 1 commit into from
May 9, 2023

Conversation

happz
Copy link
Collaborator

@happz happz commented Feb 14, 2023

The existing user-facing API did not change, we still have the CLI commands we're used to, tmt [test|plan|story] lint and tmt lint. internally, things are not different, with linters split into categories, automagical discovery, formalized internal APIs, and new CLI look (--list-checks, --failed-only, --enable-checks & brand new output).

$ tmt story lint /spec/plans/import
/spec/plans/import
pass C000 fmf node passes schema validation
pass C001 summary key is set
pass C002 summary is reasonably long
pass S001 correct key are used
fail S002 story is required

Fixes #2006

@happz happz force-pushed the lint-checks-refactored branch 3 times, most recently from d1b1ad0 to 9e7e9db Compare February 15, 2023 11:50
@happz happz marked this pull request as ready for review February 15, 2023 11:50
@happz happz added the command | lint tmt lint command label Feb 15, 2023
@happz happz force-pushed the common-base-class-and-call-other-branch branch from 5b15c59 to e00562a Compare February 17, 2023 12:37
@psss psss force-pushed the common-base-class-and-call-other-branch branch from c2b6dfb to 9e112d7 Compare February 20, 2023 17:14
Base automatically changed from common-base-class-and-call-other-branch to main February 20, 2023 18:29
@happz happz added this to the 1.23 milestone Feb 22, 2023
@thrix thrix requested review from thrix and janhavlin March 3, 2023 13:10
@thrix
Copy link
Collaborator

thrix commented Mar 7, 2023

@happz while running it manually, this looks weird:

warn C001 summary key is missing, it is useful for quick inspection
skip C002 summary key is missing, it is useful for quick inspection

@thrix
Copy link
Collaborator

thrix commented Mar 7, 2023

@happz also we will need to add some documentation about this, describing all the available checks?

thrix
thrix previously requested changes Mar 7, 2023
Copy link
Collaborator

@thrix thrix left a comment

Choose a reason for hiding this comment

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

Some small comments, otherwise the code looks clean

tests/lint/test.sh Outdated Show resolved Hide resolved
tmt/lint.py Outdated Show resolved Hide resolved
tmt/lint.py Outdated Show resolved Hide resolved
@happz
Copy link
Collaborator Author

happz commented Mar 11, 2023

@happz also we will need to add some documentation about this, describing all the available checks?

@thrix --list-checks should help:

$ tmt lint --list-checks
Linters available for tests
C000: fmf node should pass the schema validation
C001: summary key should be set, it is very useful for quick inspection
C002: summary should not exceed 50 characters
T001: all keys are known
T002: test script must be defined
T003: test directory path must be absolute
T004: test directory path must exist
T005: relevancy has been obsoleted by adjust
T006: coverage has been obsoleted by link
T007: manual test path is not an actual path
T008: manual test should be valid markdown

Linters available for plans
C000: fmf node should pass the schema validation
C001: summary key should be set, it is very useful for quick inspection
C002: summary should not exceed 50 characters
P001: all keys are known
P002: execute step must be defined with "how"
P003: execute step methods must be known
P004: discover step methods must be known
P005: remote fmf ids must be valid

Linters available for stories
C000: fmf node should pass the schema validation
C001: summary key should be set, it is very useful for quick inspection
C002: summary should not exceed 50 characters
S001: all keys are known
S002: story key must be defined
$ 

tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
tests/test/lint/test.sh Fixed Show fixed Hide fixed
@happz happz mentioned this pull request May 5, 2023
@LecrisUT
Copy link
Contributor

LecrisUT commented May 5, 2023

A note from #2008, should add a test condition for when the fmf root is in a different path. Maybe that should be made a test fixture/conftest.py so that it can be added to all test.

@happz
Copy link
Collaborator Author

happz commented May 5, 2023

A test for #2006 added in fa2520b

@psss
Copy link
Collaborator

psss commented May 5, 2023

What about using a different color for the skip label? Currently it can be easily confused with pass.

@LecrisUT
Copy link
Contributor

LecrisUT commented May 5, 2023

Green/Gray/Red/Yellow for pass/skip/fail/warning? These should be standard

@psss
Copy link
Collaborator

psss commented May 5, 2023

When an invalid key is present, the problem is reported twice:

warn C000 key "requires" not recognized by schema, and does not match "^extra-" pattern
fail T001 unknown key "requires" is used

Is this intentional? When two unknown keys are provided, duplication is gone:

warn C000 fmf node failed schema validation
warn C001 summary key is missing
fail T001 unknown key "hm" is used
fail T001 unknown key "requires" is used

Not sure why.

@psss
Copy link
Collaborator

psss commented May 5, 2023

Green/Gray/Red/Yellow for pass/skip/fail/warning? These should be standard

Sounds good to me. Maybe blue could be also suitable for skip as an "info" color.

@happz
Copy link
Collaborator Author

happz commented May 5, 2023

Green/Gray/Red/Yellow for pass/skip/fail/warning? These should be standard

Sounds good to me. Maybe blue could be also suitable for skip as an "info" color.

Changed to white in 5b356c5 as Click does not offer gray. Let me know whether it should be blue instead...

@happz
Copy link
Collaborator Author

happz commented May 5, 2023

When an invalid key is present, the problem is reported twice:

warn C000 key "requires" not recognized by schema, and does not match "^extra-" pattern
fail T001 unknown key "requires" is used

Is this intentional? When two unknown keys are provided, duplication is gone:

warn C000 fmf node failed schema validation
warn C001 summary key is missing
fail T001 unknown key "hm" is used
fail T001 unknown key "requires" is used

Not sure why.

I do know why, fixed in e2169ff.

tests/usability/main.fmf Outdated Show resolved Hide resolved
@psss
Copy link
Collaborator

psss commented May 5, 2023

Changed to white in 5b356c5 as Click does not offer gray. Let me know whether it should be blue instead...

Thanks. Just tried with my light terminal and the skip tags are hardly readable :( Let's go with blue instead.

@happz
Copy link
Collaborator Author

happz commented May 5, 2023

Changed to white in 5b356c5 as Click does not offer gray. Let me know whether it should be blue instead...

Thanks. Just tried with my light terminal and the skip tags are hardly readable :( Let's go with blue instead.

Changed to blue in 8fc1e89

@psss psss requested a review from thrix May 5, 2023 13:52
@psss psss self-assigned this May 5, 2023
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

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

This is a great enhancement! And will be superuseful. Quite an elegant implementation! Found some minor issues, a couple of questions, nothing serious.

tmt/cli.py Show resolved Hide resolved
tmt/lint.py Show resolved Hide resolved
tmt/lint.py Show resolved Hide resolved
tmt/lint.py Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
tmt/base.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all comments!

The existing user-facing API did not change, we still have the CLI
commands we're used to, `tmt [test|plan|story] lint` and `tmt lint`.
internally, things are not different, with linters split into
categories, automagical discovery, formalized internal APIs, and new CLI
look (`--list-checks`, `--failed-only`, `--enable-checks` & brand new
output).

```
$ tmt story lint /spec/plans/import
/spec/plans/import
pass C000 fmf node passes schema validation
pass C001 summary key is set
pass C002 summary is reasonably long
pass S001 correct key are used
fail S002 story is required
```
@psss psss dismissed thrix’s stale review May 9, 2023 06:15

Should be covered.

@psss
Copy link
Collaborator

psss commented May 9, 2023

/packit test

@psss
Copy link
Collaborator

psss commented May 9, 2023

The only failure is /tests/finish/ansible error on fetching the centos:7 image. Happened multiple time recently. Filed as #2063.

@psss psss merged commit 68276b9 into main May 9, 2023
@psss psss deleted the lint-checks-refactored branch May 9, 2023 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command | lint tmt lint command priority | must high priority, must be included in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tmt lint fails with fmf path not in root
7 participants