add backward compatibility test with older ver.

This commit is contained in:
elianddb
2026-02-12 15:51:08 -08:00
parent b2bc73274f
commit 62c9addfd2
4 changed files with 53 additions and 7 deletions

View File

@@ -4556,13 +4556,14 @@ var MergeArtifactsScripts = []queries.ScriptTest{
Query: "SELECT COUNT(*) FROM dolt_constraint_violations_t;",
Expected: []sql.Row{{4}},
},
// Omit violation_info from select so test passes under Doltgres (in-process returns Columns as []string, wire/protocol returns []interface{}).
{
Query: "SELECT * FROM dolt_constraint_violations_t ORDER BY pk, CAST(violation_info AS CHAR);",
Query: "SELECT from_root_ish, violation_type, pk, a, b FROM dolt_constraint_violations_t ORDER BY pk, CAST(violation_info AS CHAR);",
Expected: []sql.Row{
{doltCommit, "unique index", 1, 0, 0, merge.UniqCVMeta{Name: "ua", Columns: []string{"a"}}},
{doltCommit, "unique index", 1, 0, 0, merge.UniqCVMeta{Name: "ub", Columns: []string{"b"}}},
{doltCommit, "unique index", 2, 0, 0, merge.UniqCVMeta{Name: "ua", Columns: []string{"a"}}},
{doltCommit, "unique index", 2, 0, 0, merge.UniqCVMeta{Name: "ub", Columns: []string{"b"}}},
{doltCommit, "unique index", 1, 0, 0},
{doltCommit, "unique index", 1, 0, 0},
{doltCommit, "unique index", 2, 0, 0},
{doltCommit, "unique index", 2, 0, 0},
},
},
{

View File

@@ -65,7 +65,7 @@ function test_backward_compatibility() {
PATH="`pwd`"/"$bin":"$PATH" setup_repo "$ver"
echo "Run the bats tests with current Dolt version hitting repositories from older Dolt version $ver"
DEFAULT_BRANCH="$DEFAULT_BRANCH" REPO_DIR="`pwd`"/repos/"$ver" DOLT_VERSION="$ver" bats ./test_files/bats
DOLT_LEGACY_BIN="$(pwd)/$bin/dolt" DEFAULT_BRANCH="$DEFAULT_BRANCH" REPO_DIR="$(pwd)/repos/$ver" DOLT_VERSION="$ver" bats ./test_files/bats
}
function list_forward_compatible_versions() {
@@ -146,7 +146,7 @@ _main() {
# sanity check: run tests against current version
echo "Run the bats tests using current Dolt version hitting repositories from the current Dolt version"
DEFAULT_BRANCH="$DEFAULT_BRANCH" REPO_DIR="`pwd`"/repos/HEAD bats ./test_files/bats
DEFAULT_BRANCH="$DEFAULT_BRANCH" REPO_DIR="$(pwd)/repos/HEAD" bats ./test_files/bats
}
_main

View File

@@ -211,3 +211,39 @@ EOF
run dolt merge check_merge
[ "$status" -eq 0 ]
}
@test "constraint violation readable and resolvable by current build" {
[[ "$DOLT_VERSION" =~ 0\.50 ]] && skip "constraint violation test not run for Dolt version 0.50"
repo="$BATS_TEST_TMPDIR/cv_test_repo_$$"
mkdir -p "$repo" && cd "$repo"
old_dolt init
old_dolt sql <<SQL
CREATE TABLE cv_test (pk INT PRIMARY KEY, u INT UNIQUE);
INSERT INTO cv_test VALUES (3, 20);
SQL
old_dolt add .
old_dolt commit -m "cv_test base"
old_dolt checkout -b cv_branch
old_dolt sql -q "INSERT INTO cv_test VALUES (2, 10);" -r csv
old_dolt add .
old_dolt commit -m "cv_branch: add row (2,10)"
old_dolt checkout main
old_dolt sql -q "INSERT INTO cv_test VALUES (1, 10);" -r csv
old_dolt add .
old_dolt commit -m "main: add row (1,10)"
run old_dolt merge --no-ff cv_branch
cd "$repo"
run dolt sql -q "SELECT from_root_ish, violation_type, pk, u, violation_info FROM dolt_constraint_violations_cv_test ORDER BY pk;" -r csv
[ "$status" -eq 0 ]
[[ "${#lines[@]}" -eq 3 ]] || false
[[ "${lines[0]}" == "from_root_ish,violation_type,pk,u,violation_info" ]] || false
[[ "${lines[1]}" =~ ,unique\ index,1,10, ]] || false
[[ "${lines[2]}" =~ ,unique\ index,2,10, ]] || false
from_root_ish="${lines[1]%%,*}"
[ -n "$from_root_ish" ] || false
[[ "${lines[2]}" == "$from_root_ish"* ]] || false
run dolt sql -q "DELETE FROM dolt_constraint_violations_cv_test;" -r csv
[ "$status" -eq 0 ]
}

View File

@@ -1,5 +1,14 @@
load helper/windows-compat
# When DOLT_LEGACY_BIN is set (backward-compat run), old_dolt runs that binary; otherwise runs current dolt.
old_dolt() {
if [ -n "$DOLT_LEGACY_BIN" ]; then
"$DOLT_LEGACY_BIN" "$@"
else
dolt "$@"
fi
}
if [ -z "$BATS_TMPDIR" ]; then
export BATS_TMPDIR=$HOME/batstmp/
mkdir $BATS_TMPDIR