Skip to content

Commit d8d546c

Browse files
redsun82Copilot
andcommitted
Rust: Test dbscheme downgrade preservation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e04aacc commit d8d546c

4 files changed

Lines changed: 110 additions & 2 deletions

File tree

rust/ql/upgrade-tests/66a489863649185f4a9770f894505803059a1312/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Upgrade Regression Test for rust-analyzer 0.0.301 → 0.0.328
22

3-
This test verifies that the dbscheme upgrade script correctly preserves data when migrating databases from the old schema to the new schema.
3+
This test verifies that the dbscheme upgrade and downgrade scripts correctly preserve data when migrating databases between the old and new schemas.
44

55
## Running the test
66

@@ -16,10 +16,13 @@ This will:
1616
5. Restore your branch
1717
6. Upgrade the database to the new schema
1818
7. Verify that the old properties are still accessible via the new schema
19+
8. Downgrade the database back to the old schema
20+
9. Verify that the recovered old-schema properties still match
1921

2022
## Files
2123

22-
- `old.ql` / `old.expected`: Query for the old schema (validates extraction)
24+
- `old.ql` / `old.expected`: Query for the old schema (validates extraction and downgrade)
2325
- `new.ql` / `new.expected`: Query for the new schema (validates upgrade preserved data)
26+
- `downgraded.ql` / `downgraded.expected`: Query for the downgraded old schema
2427
- `upgrade_shapes.rs`: Rust source containing test shapes for all affected schema elements
2528
- `run-test.sh`: Test runner script
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
formatArgsArgName
2+
| 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 |
3+
| 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 |
4+
tryBlock
5+
| upgrade_shapes.rs:21:13:21:21 | { ... } |
6+
structFieldDefault
7+
| upgrade_shapes.rs:9:5:9:17 | field: u8 | upgrade_shapes.rs:9:17:9:17 | 1 |
8+
variantDiscriminant
9+
| upgrade_shapes.rs:13:5:13:9 | V | upgrade_shapes.rs:13:9:13:9 | 2 |
10+
metaPath
11+
| upgrade_shapes.rs:1:4:1:19 | Meta | allow |
12+
| upgrade_shapes.rs:2:4:2:32 | Meta | feature |
13+
| upgrade_shapes.rs:4:3:4:11 | Meta | path_meta |
14+
| upgrade_shapes.rs:5:3:5:15 | Meta | key_value |
15+
| upgrade_shapes.rs:6:3:6:18 | Meta | token_tree |
16+
| upgrade_shapes.rs:7:3:7:19 | Meta | path_meta |
17+
metaExpr
18+
| upgrade_shapes.rs:5:3:5:15 | Meta | upgrade_shapes.rs:5:15:5:15 | 1 |
19+
metaTokenTree
20+
| upgrade_shapes.rs:1:4:1:19 | Meta | upgrade_shapes.rs:1:9:1:19 | TokenTree |
21+
| upgrade_shapes.rs:2:4:2:32 | Meta | upgrade_shapes.rs:2:11:2:32 | TokenTree |
22+
| upgrade_shapes.rs:6:3:6:18 | Meta | upgrade_shapes.rs:6:13:6:18 | TokenTree |
23+
metaIsUnsafe
24+
| upgrade_shapes.rs:7:3:7:19 | Meta |
25+
traitAlias
26+
| 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 |
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import codeql.rust.elements
2+
3+
private predicate inUpgradeShapesFile(Locatable loc) {
4+
loc.getFile().getBaseName() = "upgrade_shapes.rs"
5+
}
6+
7+
query predicate formatArgsArgName(FormatArgsArg arg, Name argName, Expr expr, int argNameColumn) {
8+
inUpgradeShapesFile(arg) and
9+
argName = arg.getName() and
10+
expr = arg.getExpr() and
11+
argNameColumn = argName.getLocation().getStartColumn()
12+
}
13+
14+
query predicate tryBlock(BlockExpr block) {
15+
inUpgradeShapesFile(block) and
16+
block.isTry()
17+
}
18+
19+
query predicate structFieldDefault(StructField field, Expr defaultVal) {
20+
inUpgradeShapesFile(field) and
21+
defaultVal = field.getDefault()
22+
}
23+
24+
query predicate variantDiscriminant(Variant variant, Expr discriminant) {
25+
inUpgradeShapesFile(variant) and
26+
discriminant = variant.getDiscriminant()
27+
}
28+
29+
query predicate metaPath(Meta meta, string pathText) {
30+
inUpgradeShapesFile(meta) and
31+
pathText = meta.getPath().getText()
32+
}
33+
34+
query predicate metaExpr(Meta meta, Expr expr) {
35+
inUpgradeShapesFile(meta) and
36+
expr = meta.getExpr()
37+
}
38+
39+
query predicate metaTokenTree(Meta meta, TokenTree tokenTree) {
40+
inUpgradeShapesFile(meta) and
41+
tokenTree = meta.getTokenTree()
42+
}
43+
44+
query predicate metaIsUnsafe(Meta meta) {
45+
inUpgradeShapesFile(meta) and
46+
meta.isUnsafe()
47+
}
48+
49+
query predicate traitAlias(
50+
TraitAlias alias, Name name, TypeBoundList bounds, WhereClause whereClause
51+
) {
52+
inUpgradeShapesFile(alias) and
53+
name = alias.getName() and
54+
bounds = alias.getTypeBoundList() and
55+
whereClause = alias.getWhereClause()
56+
}

rust/ql/upgrade-tests/66a489863649185f4a9770f894505803059a1312/run-test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -euo pipefail
77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
88
REPO_ROOT="$(git rev-parse --show-toplevel)"
99
OLD_COMMIT="${OLD_COMMIT:-491c373e076}" # origin/main at time of this upgrade
10+
OLD_DBSCHEME="rust/downgrades/109496fd2f20f28a35e50b110859e74882ee80d6/rust.dbscheme"
1011

1112
cd "$REPO_ROOT"
1213

@@ -64,4 +65,26 @@ codeql test run \
6465
--check-databases \
6566
"$SCRIPT_DIR/new.ql" "$@"
6667

68+
echo "==> Downgrading dataset back to old schema..."
69+
codeql dataset upgrade "${DATASET_DIR[0]}" \
70+
--allow-downgrades \
71+
--search-path rust \
72+
--target-dbscheme "$OLD_DBSCHEME"
73+
74+
trap 'restore_ref' EXIT
75+
76+
echo "==> Checking out old commit ($OLD_COMMIT) for downgrade verification..."
77+
git checkout --quiet "$OLD_COMMIT"
78+
git checkout --quiet "$ORIGINAL_REF" -- rust/ql/upgrade-tests codeql-workspace.yml
79+
80+
echo "==> Running preservation test on downgraded dataset..."
81+
codeql test run \
82+
--search-path . \
83+
--dataset "${DATASET_DIR[0]}" \
84+
--check-databases \
85+
"$SCRIPT_DIR/downgraded.ql" "$@"
86+
87+
restore_ref
88+
trap '' EXIT
89+
6790
echo "==> All tests passed!"

0 commit comments

Comments
 (0)