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

Validate triagebot.toml in tidy/CI #106104

Closed
compiler-errors opened this issue Dec 23, 2022 · 22 comments · Fixed by rust-lang/triagebot#1730
Closed

Validate triagebot.toml in tidy/CI #106104

compiler-errors opened this issue Dec 23, 2022 · 22 comments · Fixed by rust-lang/triagebot#1730
Assignees
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Dec 23, 2022

Would've prevented #106102, which broke in #105661.

We should at least validate the toml file is valid syntax, but ideally we'd validate more context-specific stuff.

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-testsuite Area: The testsuite used to check the correctness of rustc labels Dec 24, 2022
@jyn514
Copy link
Member

jyn514 commented Dec 24, 2022

Mentoring instructions: Add a new check to tidy around here that parses triagebot.toml to make sure it's valid toml:

pub mod alphabetical;
pub mod bins;
pub mod debug_artifacts;
pub mod deps;
pub mod edition;
pub mod error_codes_check;
pub mod errors;
pub mod extdeps;
pub mod features;
pub mod mir_opt_tests;
pub mod pal;
pub mod primitive_docs;
pub mod style;
pub mod target_specific_tests;
pub mod ui_tests;
pub mod unit_tests;
pub mod unstable_book;
pub mod walk;

See the existing tidy files for an example of how to write a tidy check.

@jyn514 jyn514 added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Dec 24, 2022
@aadityadhruv
Copy link

Hi, I'm a new contributor here and thought of picking this as my first issue. From what I understand, a new crate (something like triagebot.rs) needs to be made for this issue right? Where we can parse the toml and see if it is valid.

@jyn514
Copy link
Member

jyn514 commented Dec 24, 2022

@aadityadhruv a new module, not a new crate. The module should be part of tidy so check runs on x test tidy.

@aadityadhruv
Copy link

Right, that makes sense. Thank you!

@aadityadhruv
Copy link

Hi, sorry for the late response, I was out traveling. I'm currently confused about a certain thing. Currently what I am trying to do is manually check the file for valid syntax, by going over it line by line. Is this the correct method to do this, or should I be using an already existing crate like toml? I would assume that extra crate dependencies aren't probably wanted.

Also, I was wondering something about Path in the check function. For this module, would I need to check/filter any paths like some other modules do? I was assuming that I will simply open path + 'tiragebot.toml' and read that file.

Any help is appreciated!

@jyn514
Copy link
Member

jyn514 commented Dec 28, 2022

should I be using an already existing crate like toml?

Yes, please use toml, don't use regex or anything like that.

@ehuss
Copy link
Contributor

ehuss commented Dec 29, 2022

I personally would prefer to see this implemented in triagebot itself instead of tidy. That would make it work for all repositories. It should be fairly trivial to add a handler that checks for a PR that modifies triagebot.toml and to validate it, and post a comment if it is not correct. It can even use the Config type to verify that the actual structure matches. Bonus points would to also use serde-ignored to enforce that unknown fields aren't included.

@dotdot0
Copy link
Contributor

dotdot0 commented Jan 2, 2023

@aadityadhruv are you still working on this?

@aadityadhruv
Copy link

Hi, yeah I'm sorry, I'm still working on it. I've been pretty busy the last couple of days, I'll get it done this week itself. Hope that's ok!

@dotdot0
Copy link
Contributor

dotdot0 commented Jan 2, 2023

Hi, yeah I'm sorry, I'm still working on it. I've been pretty busy the last couple of days, I'll get it done this week itself. Hope that's ok!

Yeah! it's alright

@aadityadhruv
Copy link

I personally would prefer to see this implemented in triagebot itself instead of tidy. That would make it work for all repositories. It should be fairly trivial to add a handler that checks for a PR that modifies triagebot.toml and to validate it, and post a comment if it is not correct. It can even use the Config type to verify that the actual structure matches. Bonus points would to also use serde-ignored to enforce that unknown fields aren't included.

Sorry for being slow with the issue, but along with being busy, I've been kinda stuck, and was unsure if I should ask for help. I am currently unsure if I should be doing work in tidy or the triagebot repository. Should I first try to get the tidy check working and then maybe open an issue on the triagebot repo?

@aadityadhruv
Copy link

aadityadhruv commented Jan 5, 2023

Here is the code I had written (it does not work since I do not know what the configuration of the toml is):

use crate::walk::{filter_dirs, walk};
use serde::Deserialize;
use std::path::Path;

#[derive(Deserialize)]
struct Config {}

pub fn check(path: &Path, bad: &mut bool) {
    walk(path, &mut |path| filter_dirs(path), &mut |entry, contents| {
        let file = entry.path();
        let filename = file.file_name().unwrap();
        if filename != "triagebot.toml" {
            return;
        }
        let conf: Result<Config, toml::de::Error> = toml::from_str(contents);
        match conf {
            Ok(_) => {}
            Err(_err) => {
                tidy_error!(bad, "{} is an invalid toml file", file.display())
            }
        }
    });
}

I am unsure what would be the right next step here.

@madsravn
Copy link
Contributor

madsravn commented Jan 6, 2023

Hi @aadityadhruv . I am new here and just looking through for an issue I can get started with. So keeping that in mind, here is my idea.

If you look at the documentation for the toml crate there is a method where you can just parse an entire string into a toml::Value. This Value is an enum for the entire toml structure. My idea is that if you can parse the triagebot.toml it is correct toml and you have validated the file.

My very short code is here:

use toml::Value;

fn main() {
    let input = std::fs::read_to_string("triagebot.toml").unwrap();
    let value = input.parse::<Value>().unwrap();
    println!("{value}");
}

I hope it helps.

@aadityadhruv
Copy link

This looks great! Thank you!

@aadityadhruv
Copy link

Here is a PR for the same: #106559

@jyn514
Copy link
Member

jyn514 commented Jan 10, 2023

I personally would prefer to see this implemented in triagebot itself instead of tidy. That would make it work for all repositories. It should be fairly trivial to add a handler that checks for a PR that modifies triagebot.toml and to validate it, and post a comment if it is not correct. It can even use the Config type to verify that the actual structure matches. Bonus points would to also use serde-ignored to enforce that unknown fields aren't included.

👍 #106559 (comment)

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 14, 2023

Just thought I'd drop by and say that this would have been nice to avoid #106848 😅

@jyn514
Copy link
Member

jyn514 commented Jan 14, 2023

Ah, that wouldn't have been caught actually - the toml syntax was valid, the file just didn't exist in the repository. Checking if the glob has at least one match seems possible.

@0xJepsen
Copy link

I see the PR up but not sure if anyone is still working on the requested changes?

@aadityadhruv
Copy link

Yeah I'm currently working on it in the triagebot repo, I haven't opened a PR/Issue yet for it.

@meysam81
Copy link
Contributor

meysam81 commented Oct 7, 2023

@rustbot claim

@meysam81
Copy link
Contributor

meysam81 commented Oct 8, 2023

Can someone please review this change: rust-lang/triagebot#1730

meysam81 added a commit to meysam81/triagebot that referenced this issue Nov 12, 2023
ehuss pushed a commit to meysam81/triagebot that referenced this issue Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
9 participants