mirror of
https://github.com/github/codeql.git
synced 2026-05-29 18:41:27 +02:00
Rust: Test dbscheme downgrade preservation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Upgrade Regression Test for rust-analyzer 0.0.301 → 0.0.328
|
||||
|
||||
This test verifies that the dbscheme upgrade script correctly preserves data when migrating databases from the old schema to the new schema.
|
||||
This test verifies that the dbscheme upgrade and downgrade scripts correctly preserve data when migrating databases between the old and new schemas.
|
||||
|
||||
## Running the test
|
||||
|
||||
@@ -16,10 +16,13 @@ This will:
|
||||
5. Restore your branch
|
||||
6. Upgrade the database to the new schema
|
||||
7. Verify that the old properties are still accessible via the new schema
|
||||
8. Downgrade the database back to the old schema
|
||||
9. Verify that the recovered old-schema properties still match
|
||||
|
||||
## Files
|
||||
|
||||
- `old.ql` / `old.expected`: Query for the old schema (validates extraction)
|
||||
- `old.ql` / `old.expected`: Query for the old schema (validates extraction and downgrade)
|
||||
- `new.ql` / `new.expected`: Query for the new schema (validates upgrade preserved data)
|
||||
- `downgraded.ql` / `downgraded.expected`: Query for the downgraded old schema
|
||||
- `upgrade_shapes.rs`: Rust source containing test shapes for all affected schema elements
|
||||
- `run-test.sh`: Test runner script
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
formatArgsArgName
|
||||
| upgrade_shapes.rs:22:37:22:41 | FormatArgsArg | upgrade_shapes.rs:22:37:22:37 | (no string representation) | upgrade_shapes.rs:22:41:22:41 | 1 | 37 |
|
||||
| upgrade_shapes.rs:22:44:22:48 | FormatArgsArg | upgrade_shapes.rs:22:44:22:44 | (no string representation) | upgrade_shapes.rs:22:48:22:48 | 2 | 44 |
|
||||
tryBlock
|
||||
| upgrade_shapes.rs:21:13:21:21 | { ... } |
|
||||
structFieldDefault
|
||||
| upgrade_shapes.rs:9:5:9:17 | field: u8 | upgrade_shapes.rs:9:17:9:17 | 1 |
|
||||
variantDiscriminant
|
||||
| upgrade_shapes.rs:13:5:13:9 | V | upgrade_shapes.rs:13:9:13:9 | 2 |
|
||||
metaPath
|
||||
| upgrade_shapes.rs:1:4:1:19 | Meta | allow |
|
||||
| upgrade_shapes.rs:2:4:2:32 | Meta | feature |
|
||||
| upgrade_shapes.rs:4:3:4:11 | Meta | path_meta |
|
||||
| upgrade_shapes.rs:5:3:5:15 | Meta | key_value |
|
||||
| upgrade_shapes.rs:6:3:6:18 | Meta | token_tree |
|
||||
| upgrade_shapes.rs:7:3:7:19 | Meta | path_meta |
|
||||
metaExpr
|
||||
| upgrade_shapes.rs:5:3:5:15 | Meta | upgrade_shapes.rs:5:15:5:15 | 1 |
|
||||
metaTokenTree
|
||||
| upgrade_shapes.rs:1:4:1:19 | Meta | upgrade_shapes.rs:1:9:1:19 | TokenTree |
|
||||
| upgrade_shapes.rs:2:4:2:32 | Meta | upgrade_shapes.rs:2:11:2:32 | TokenTree |
|
||||
| upgrade_shapes.rs:6:3:6:18 | Meta | upgrade_shapes.rs:6:13:6:18 | TokenTree |
|
||||
metaIsUnsafe
|
||||
| upgrade_shapes.rs:7:3:7:19 | Meta |
|
||||
traitAlias
|
||||
| upgrade_shapes.rs:16:1:18:12 | TraitAlias | upgrade_shapes.rs:16:7:16:11 | Alias | upgrade_shapes.rs:16:18:16:22 | ... | upgrade_shapes.rs:17:1:18:11 | WhereClause |
|
||||
@@ -0,0 +1,56 @@
|
||||
import codeql.rust.elements
|
||||
|
||||
private predicate inUpgradeShapesFile(Locatable loc) {
|
||||
loc.getFile().getBaseName() = "upgrade_shapes.rs"
|
||||
}
|
||||
|
||||
query predicate formatArgsArgName(FormatArgsArg arg, Name argName, Expr expr, int argNameColumn) {
|
||||
inUpgradeShapesFile(arg) and
|
||||
argName = arg.getName() and
|
||||
expr = arg.getExpr() and
|
||||
argNameColumn = argName.getLocation().getStartColumn()
|
||||
}
|
||||
|
||||
query predicate tryBlock(BlockExpr block) {
|
||||
inUpgradeShapesFile(block) and
|
||||
block.isTry()
|
||||
}
|
||||
|
||||
query predicate structFieldDefault(StructField field, Expr defaultVal) {
|
||||
inUpgradeShapesFile(field) and
|
||||
defaultVal = field.getDefault()
|
||||
}
|
||||
|
||||
query predicate variantDiscriminant(Variant variant, Expr discriminant) {
|
||||
inUpgradeShapesFile(variant) and
|
||||
discriminant = variant.getDiscriminant()
|
||||
}
|
||||
|
||||
query predicate metaPath(Meta meta, string pathText) {
|
||||
inUpgradeShapesFile(meta) and
|
||||
pathText = meta.getPath().getText()
|
||||
}
|
||||
|
||||
query predicate metaExpr(Meta meta, Expr expr) {
|
||||
inUpgradeShapesFile(meta) and
|
||||
expr = meta.getExpr()
|
||||
}
|
||||
|
||||
query predicate metaTokenTree(Meta meta, TokenTree tokenTree) {
|
||||
inUpgradeShapesFile(meta) and
|
||||
tokenTree = meta.getTokenTree()
|
||||
}
|
||||
|
||||
query predicate metaIsUnsafe(Meta meta) {
|
||||
inUpgradeShapesFile(meta) and
|
||||
meta.isUnsafe()
|
||||
}
|
||||
|
||||
query predicate traitAlias(
|
||||
TraitAlias alias, Name name, TypeBoundList bounds, WhereClause whereClause
|
||||
) {
|
||||
inUpgradeShapesFile(alias) and
|
||||
name = alias.getName() and
|
||||
bounds = alias.getTypeBoundList() and
|
||||
whereClause = alias.getWhereClause()
|
||||
}
|
||||
@@ -7,6 +7,7 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||
OLD_COMMIT="${OLD_COMMIT:-491c373e076}" # origin/main at time of this upgrade
|
||||
OLD_DBSCHEME="rust/downgrades/109496fd2f20f28a35e50b110859e74882ee80d6/rust.dbscheme"
|
||||
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
@@ -64,4 +65,26 @@ codeql test run \
|
||||
--check-databases \
|
||||
"$SCRIPT_DIR/new.ql" "$@"
|
||||
|
||||
echo "==> Downgrading dataset back to old schema..."
|
||||
codeql dataset upgrade "${DATASET_DIR[0]}" \
|
||||
--allow-downgrades \
|
||||
--search-path rust \
|
||||
--target-dbscheme "$OLD_DBSCHEME"
|
||||
|
||||
trap 'restore_ref' EXIT
|
||||
|
||||
echo "==> Checking out old commit ($OLD_COMMIT) for downgrade verification..."
|
||||
git checkout --quiet "$OLD_COMMIT"
|
||||
git checkout --quiet "$ORIGINAL_REF" -- rust/ql/upgrade-tests codeql-workspace.yml
|
||||
|
||||
echo "==> Running preservation test on downgraded dataset..."
|
||||
codeql test run \
|
||||
--search-path . \
|
||||
--dataset "${DATASET_DIR[0]}" \
|
||||
--check-databases \
|
||||
"$SCRIPT_DIR/downgraded.ql" "$@"
|
||||
|
||||
restore_ref
|
||||
trap '' EXIT
|
||||
|
||||
echo "==> All tests passed!"
|
||||
|
||||
Reference in New Issue
Block a user