test: version clash w/ diamond deps (#11155)

This PR adds a test replicating Kim's diamond dependency example.

The top-level package, `D`, depends on two intermediate packages, `B`
and `C`, which each require semantically different versions of another
package, `A`. The portion of `A` that `B` and `C` publicly use is
unchanged across the versions, but they both privately make use of
changed API. Currently, this causes a version clash. This will be made
to work without error later this quarter.
This commit is contained in:
Mac Malone 2025-11-13 00:40:56 -05:00 committed by GitHub
parent ceb86b1293
commit 2b85e29cc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 191 additions and 0 deletions

View file

@ -0,0 +1 @@
.lake

View file

@ -0,0 +1,2 @@
import DiamondExampleA.Ring.Defs
import DiamondExampleA.Ring.Lemmas

View file

@ -0,0 +1,9 @@
module
public class Ring (A : Type) extends Add A, Mul A, Neg A, Zero A, One A where
add_assoc : ∀ a b c : A, a + b + c = a + (b + c)
add_comm : ∀ a b : A, a + b = b + a
add_zero : ∀ a : A, a + 0 = a
add_neg : ∀ a : A, a + -a = 0
mul_assoc : ∀ a b c : A, a * b * c = a * (b * c)
mul_comm : ∀ a b : A, a * b = b * a

View file

@ -0,0 +1,13 @@
module
public import DiamondExampleA.Ring.Defs
namespace Ring
public theorem add_left_comm [Ring α] : ∀ a b c : α, a + (b + c) = b + (a + c) := by
intros a b c
rw [← add_assoc a b c]
rw [add_comm a b]
rw [add_assoc b a c]
end Ring

View file

@ -0,0 +1,6 @@
name = "DiamondExample-A"
defaultTargets = ["DiamondExampleA"]
[[lean_lib]]
name = "DiamondExampleA"
leanOptions.experimental.module = true

View file

@ -0,0 +1 @@
.lake

View file

@ -0,0 +1 @@
import DiamondExampleB.MainResult

View file

@ -0,0 +1,11 @@
module
public import DiamondExampleA.Ring.Defs
import DiamondExampleA.Ring.Lemmas
open Ring
public theorem foo [Ring α] (a b c d : α) : a + (b + (c + d)) = b + c + a + d := by
rw [poorly_named_lemma]
rw [poorly_named_lemma a c d]
rw [← add_assoc, ← add_assoc]

View file

@ -0,0 +1,11 @@
name = "DiamondExample-B"
defaultTargets = ["DiamondExampleB"]
[[require]]
name = "DiamondExample-A"
git = "../DiamondExample-A"
rev = "v1"
[[lean_lib]]
name = "DiamondExampleB"
leanOptions.experimental.module = true

View file

@ -0,0 +1 @@
.lake

View file

@ -0,0 +1 @@
import DiamondExampleC.MainResult

View file

@ -0,0 +1,11 @@
module
public import DiamondExampleA.Ring.Defs
import DiamondExampleA.Ring.Lemmas
open Ring
public theorem bar [Ring α] (a b c : α) : a + b + c = b + a + c := by
rw [add_assoc]
rw [add_left_comm]
rw [← add_assoc]

View file

@ -0,0 +1,11 @@
name = "DiamondExample-C"
defaultTargets = ["DiamondExampleC"]
[[require]]
name = "DiamondExample-A"
git = "../DiamondExample-A"
rev = "v2"
[[lean_lib]]
name = "DiamondExampleC"
leanOptions.experimental.module = true

View file

@ -0,0 +1,2 @@
.lake
produced.out

View file

@ -0,0 +1 @@
import DiamondExampleD.MainResult

View file

@ -0,0 +1,11 @@
module
import DiamondExampleB.MainResult
import DiamondExampleC.MainResult
open Ring
-- This uses `foo` from `DiamondExampleB` and `bar` from `DiamondExampleC`
example [Ring α] (a b c d : α) : a + (b + (c + d)) = a + (b + c) + d := by
rw [foo]
rw [bar]

View file

@ -0,0 +1,16 @@
name = "DiamondExample-D"
defaultTargets = ["DiamondExampleD"]
[[require]]
name = "DiamondExample-B"
git = "../DiamondExample-B"
rev = "master"
[[require]]
name = "DiamondExample-C"
git = "../DiamondExample-C"
rev = "v2"
[[lean_lib]]
name = "DiamondExampleD"
leanOptions.experimental.module = true

3
tests/pkg/ver_clash/clean.sh Executable file
View file

@ -0,0 +1,3 @@
rm -rf DiamondExample-*/.git
rm -rf DiamondExample-*/.lake DiamondExample-*/lake-manifest.json
rm -f DiamondExample-D/produced.out

79
tests/pkg/ver_clash/test.sh Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env bash
source ../../lake/tests/common.sh
./clean.sh
# This directory contains a unified version of the "ring example"
# developed by Kim across the following 4 repositories:
#
# * https://github.com/kim-em/DiamondExample-A
# * https://github.com/kim-em/DiamondExample-B
# * https://github.com/kim-em/DiamondExample-C
# * https://github.com/kim-em/DiamondExample-D
#
# The top-level package, `D`, depends on two intermediate packages, `B` and `C`,
# which each require semantically different versions of another package, `A`.
# The portion of `A` that `B` and `C` publicly use (i.e., `Ring`) is unchanged
# across the versions, but they both privately make use of changed API (i.e.,
# `poorly_named_lemma` and its rename, `add_left_comm`).
#
# Currently, this causes a version clash, which is tested here.
# ---
# Setup
# ---
# Since committing a Git repository to a Git repository is not well-supported,
# We reinitialize the repositories on each test.
pushd DiamondExample-A
sed_i s/add_left_comm/poorly_named_lemma/ DiamondExampleA/Ring/Lemmas.lean
$LAKE update
init_git
git tag v1
sed_i s/poorly_named_lemma/add_left_comm/ DiamondExampleA/Ring/Lemmas.lean
git commit -am "rename lemma"
git tag v2
popd
pushd DiamondExample-B
$LAKE update
init_git
popd
pushd DiamondExample-C
sed_i s/v2/v1/ lakefile.toml
sed_i s/add_left_comm/poorly_named_lemma/ DiamondExampleC/MainResult.lean
$LAKE update
init_git
git tag v1
sed_i s/v1/v2/ lakefile.toml
sed_i s/poorly_named_lemma/add_left_comm/ DiamondExampleC/MainResult.lean
$LAKE update
git commit -am "use v2"
git tag v2
popd
pushd DiamondExample-D
sed_i s/v2/v1/ lakefile.toml
$LAKE update
init_git
git tag v1
sed_i s/v1/v2/ lakefile.toml
$LAKE update
git commit -am "use v2"
git tag v2
popd
# ---
# Main tests
# ---
cd DiamondExample-D
# Test build succeeds on v1
git switch v1 --detach
test_run build
# Test build fails on v2
git switch v2 --detach
test_err 'Unknown identifier `poorly_named_lemma`' build