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

Make sat reproducible #86

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Make sat reproducible #86

merged 4 commits into from
Jan 14, 2025

Conversation

manuelnaranjo
Copy link
Collaborator

This PR will make the output of the sat resolver deterministic

@manuelnaranjo manuelnaranjo added the enhancement New feature or request label Jan 13, 2025
@manuelnaranjo manuelnaranjo self-assigned this Jan 13, 2025
@manuelnaranjo manuelnaranjo force-pushed the mnaranjo/make-sat-reproducible branch from 16fba88 to 73c4e4a Compare January 13, 2025 14:25
@manuelnaranjo
Copy link
Collaborator Author

manuelnaranjo commented Jan 13, 2025

This run shows the test failing before we sort the inputs to the SAT resolver

--- FAIL: TestDeterministicOutput (8.41s)
    --- FAIL: TestDeterministicOutput/iteration:_0 (0.83s)
        sat_determinsitic_test.go:74: 
            Expected
                <[]string | len:26, cap:32>: [
                    "glibc-0:2.28-161.el8",
                    "bash-0:4.4.20-1.el8_4",
                    "libattr-0:2.4.48-3.el8",
                    "coreutils-single-0:8.30-10.el8",
                    "ncurses-libs-0:6.1-9.20180224.el8",
                    "shadow-utils-2:4.6-13.el8",
                    "libcap-ng-0:0.7.11-1.el8",
                    "libselinux-0:2.9-5.el8",
                    "libxcrypt-0:4.1.1-6.el8",
                    "libacl-0:2.2.53-1.el8",
                    "centos-stream-release-0:8.5-3.el8",
                    "setup-0:2.12.2-6.el8",
                    "audit-libs-0:3.0-0.17.20191104git1c2f876.el8",
                    "tzdata-0:2021a-1.el8",
                    "glibc-langpack-yue-0:2.28-161.el8",
                    "bzip2-libs-0:1.0.6-26.el8",
                    "basesystem-0:11-5.el8",
                    "centos-stream-repos-0:8-2.el8",
                    "ncurses-base-0:6.1-9.20180224.el8",
                    "glibc-common-0:2.28-161.el8",
                    "libsepol-0:2.9-2.el8",
                    "filesystem-0:3.8-6.el8",
                    "libcap-0:2.26-4.el8",
                    "centos-gpg-keys-1:8-2.el8",
                    "pcre2-0:10.32-2.el8",
                    "libsemanage-0:2.9-6.el8",
                ]
            to consist of
                <[]string | len:26, cap:26>: [
                    "glibc-all-langpacks-0:2.28-161.el8",
                    "libsepol-0:2.9-2.el8",
                    "ncurses-base-0:6.1-9.20180224.el8",
                    "libacl-0:2.2.53-1.el8",
                    "libattr-0:2.4.48-3.el8",
                    "basesystem-0:11-5.el8",
                    "bash-0:4.4.20-1.el8_4",
                    "filesystem-0:3.8-6.el8",
                    "centos-gpg-keys-1:8-2.el8",
                    "libsemanage-0:2.9-6.el8",
                    "libxcrypt-0:4.1.1-6.el8",
                    "libcap-0:2.26-4.el8",
                    "libselinux-0:2.9-5.el8",
                    "ncurses-libs-0:6.1-9.20180224.el8",
                    "bzip2-libs-0:1.0.6-26.el8",
                    "coreutils-single-0:8.30-10.el8",
                    "tzdata-0:2021a-1.el8",
                    "shadow-utils-2:4.6-13.el8",
                    "glibc-0:2.28-161.el8",
                    "glibc-common-0:2.28-161.el8",
                    "libcap-ng-0:0.7.11-1.el8",
                    "pcre2-0:10.32-2.el8",
                    "audit-libs-0:3.0-0.17.20191104git1c2f876.el8",
                    "setup-0:2.12.2-6.el8",
                    "centos-stream-release-0:8.5-3.el8",
                    "centos-stream-repos-0:8-2.el8",
                ]
            the missing elements were
                <[]string | len:1, cap:1>: [
                    "glibc-all-langpacks-0:2.28-161.el8",
                ]
            the extra elements were
                <[]string | len:1, cap:1>: [
                    "glibc-langpack-yue-0:2.28-161.el8",
                ]
    --- FAIL: TestDeterministicOutput/iteration:_1 (0.83s)
        sat_determinsitic_test.go:74: 
            Expected
                <[]string | len:26, cap:32>: [
                    "pcre2-0:10.32-2.el8",
                    "ncurses-libs-0:6.1-9.20180224.el8",
                    "audit-libs-0:3.0-0.17.20191104git1c2f876.el8",
                    "bzip2-libs-0:1.0.6-26.el8",
                    "libattr-0:2.4.48-3.el8",
                    "glibc-langpack-es-0:2.28-161.el8",
                    "libacl-0:2.2.53-1.el8",
                    "centos-stream-repos-0:8-2.el8",
                    "glibc-0:2.28-161.el8",
                    "tzdata-0:2021a-1.el8",
                    "centos-gpg-keys-1:8-2.el8",
                    "libselinux-0:2.9-5.el8",
                    "shadow-utils-2:4.6-13.el8",
                    "filesystem-0:3.8-6.el8",
                    "setup-0:2.12.2-6.el8",
                    "glibc-common-0:2.28-161.el8",
                    "libsemanage-0:2.9-6.el8",
                    "basesystem-0:11-5.el8",
                    "libcap-ng-0:0.7.11-1.el8",
                    "centos-stream-release-0:8.5-3.el8",
                    "bash-0:4.4.20-1.el8_4",
                    "coreutils-single-0:8.30-10.el8",
                    "ncurses-base-0:6.1-9.20180224.el8",
                    "libxcrypt-0:4.1.1-6.el8",
                    "libsepol-0:2.9-2.el8",
                    "libcap-0:2.26-4.el8",
                ]
            to consist of
                <[]string | len:26, cap:26>: [
                    "glibc-all-langpacks-0:2.28-161.el8",
                    "libsepol-0:2.9-2.el8",
                    "ncurses-base-0:6.1-9.20180224.el8",
                    "libacl-0:2.2.53-1.el8",
                    "libattr-0:2.4.48-3.el8",
                    "basesystem-0:11-5.el8",
                    "bash-0:4.4.20-1.el8_4",
                    "filesystem-0:3.8-6.el8",
                    "centos-gpg-keys-1:8-2.el8",
                    "libsemanage-0:2.9-6.el8",
                    "libxcrypt-0:4.1.1-6.el8",
                    "libcap-0:2.26-4.el8",
                    "libselinux-0:2.9-5.el8",
                    "ncurses-libs-0:6.1-9.20180224.el8",
                    "bzip2-libs-0:1.0.6-26.el8",
                    "coreutils-single-0:8.30-10.el8",
                    "tzdata-0:2021a-1.el8",
                    "shadow-utils-2:4.6-13.el8",
                    "glibc-0:2.28-161.el8",
                    "glibc-common-0:2.28-161.el8",
                    "libcap-ng-0:0.7.11-1.el8",
                    "pcre2-0:10.32-2.el8",
                    "audit-libs-0:3.0-0.17.20191104git1c2f876.el8",
                    "setup-0:2.12.2-6.el8",
                    "centos-stream-release-0:8.5-3.el8",
                    "centos-stream-repos-0:8-2.el8",
                ]
            the missing elements were
                <[]string | len:1, cap:1>: [
                    "glibc-all-langpacks-0:2.28-161.el8",
                ]
            the extra elements were
                <[]string | len:1, cap:1>: [
                    "glibc-langpack-es-0:2.28-161.el8",
                ]

go.mod Outdated Show resolved Hide resolved
pkg/sat/sat.go Outdated
@@ -146,8 +162,13 @@ func (r *Resolver) LoadInvolvedPackages(packages []*api.Package, ignoreRegex []s

if !r.nobest {
packages = nil
for _, v := range r.bestPackages {
packages = append(packages, v)
bestPackagesKeys := make([]string, 0, len(r.bestPackages))
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe use maps.Keys for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not a go expert, so TIL about it, I'll make the change, it looks way cleaner

Reduce some tech debt by using cmp.Or instead of multi level ifs.
Will make use of slices.Sort and slices.SortFunc so we can sort
dictionary keys before we send them to the sat resolver
Check if by making the input to sat stable the output is also stable
@manuelnaranjo manuelnaranjo force-pushed the mnaranjo/make-sat-reproducible branch from ed0a589 to 0b90edb Compare January 14, 2025 12:56
Make sure the sat solver output is deterministic and reproducible by
making the input order stable
@manuelnaranjo manuelnaranjo force-pushed the mnaranjo/make-sat-reproducible branch from 0b90edb to e9f6570 Compare January 14, 2025 13:07
@kellyma2
Copy link
Collaborator

Looks good to me

@manuelnaranjo manuelnaranjo merged commit b5efd4c into main Jan 14, 2025
13 checks passed
@manuelnaranjo manuelnaranjo deleted the mnaranjo/make-sat-reproducible branch January 14, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants