Skip to content

Commit 4c4d6fe

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 1528dc7 commit 4c4d6fe

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

0 commit comments

Comments
 (0)