Skip to content

Commit 65015b1

Browse files
committed
test: add regression tests for BuildProduct::from_db
The existing tests covered RelativeStorePath::from_path (which was already working), but not the from_db path where the actual bug lived. Add tests that exercise from_db directly: - subpath product (/nix/store/hash-name/share/doc/nix/manual) - bare store path (/nix/store/hash-name) - None path (NULL in database)
1 parent 07b1547 commit 65015b1

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

  • subprojects/hydra-queue-runner/src/state

subprojects/hydra-queue-runner/src/state/build.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,69 @@ mod tests {
802802
assert_eq!(rel.print(&dir), original);
803803
}
804804
}
805+
806+
/// Helper to construct an `OwnedBuildProduct` with a given path, leaving
807+
/// other fields at harmless defaults.
808+
fn make_db_product(path: Option<&str>) -> db::models::OwnedBuildProduct {
809+
db::models::OwnedBuildProduct {
810+
r#type: "doc".into(),
811+
subtype: "manual".into(),
812+
filesize: None,
813+
sha256hash: None,
814+
path: path.map(Into::into),
815+
name: "test-product".into(),
816+
defaultpath: Some("index.html".into()),
817+
}
818+
}
819+
820+
// Regression test: `BuildProduct::from_db` used to feed the full
821+
// `buildproducts.path` value (e.g. `/nix/store/…/share/doc/nix/manual`)
822+
// to `StoreDir::parse`, which rejected the trailing `/…` with
823+
// `invalid store path / symbol at 50`. This wedged every cached build
824+
// whose products included a sub-path.
825+
#[test]
826+
fn from_db_parses_subpath_product() {
827+
let dir = test_store_dir();
828+
let bp = BuildProduct::from_db(
829+
&dir,
830+
make_db_product(Some(
831+
"/nix/store/bwqqp42xqn37z31dapi7jrhy8iwc2zsx-nix-manual-2.31.4/share/doc/nix/manual",
832+
)),
833+
)
834+
.expect("subpath product must parse via from_db");
835+
836+
let rel = bp.path.expect("path must be Some");
837+
assert_eq!(
838+
rel.base_path.to_string(),
839+
"bwqqp42xqn37z31dapi7jrhy8iwc2zsx-nix-manual-2.31.4"
840+
);
841+
assert_eq!(&*rel.relative_path, "share/doc/nix/manual");
842+
}
843+
844+
#[test]
845+
fn from_db_parses_bare_store_path() {
846+
let dir = test_store_dir();
847+
let bp = BuildProduct::from_db(
848+
&dir,
849+
make_db_product(Some(
850+
"/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-example-1.0",
851+
)),
852+
)
853+
.expect("bare store path must parse via from_db");
854+
855+
let rel = bp.path.expect("path must be Some");
856+
assert_eq!(
857+
rel.base_path.to_string(),
858+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-example-1.0"
859+
);
860+
assert!(rel.relative_path.is_empty());
861+
}
862+
863+
#[test]
864+
fn from_db_handles_none_path() {
865+
let dir = test_store_dir();
866+
let bp = BuildProduct::from_db(&dir, make_db_product(None))
867+
.expect("None path must not error");
868+
assert!(bp.path.is_none());
869+
}
805870
}

0 commit comments

Comments
 (0)