Skip to content

Commit 40fb123

Browse files
authored
fix(test): unbreak the observation store suite and main's test build (#11941)
Seven tests in homeboy-core, plus two initializers that stopped "cargo check --workspace --tests" from compiling at all. schema::tests (3) -- seed_owned_and_orphaned_children inserts rows that reference a run which does not exist, because that is precisely what migration 13 exists to reap; one of the tests is literally named migration_13_reaps_rows_orphaned_while_enforcement_was_off. enforce_foreign_keys now turns enforcement on at open, so the seed could no longer create the orphans under test. Relax the pragma for the seed and restore it after. store_init_tests (2) -- test_status and test_database_path asserted the XDG layout while with_isolated_home sets HOMEBOY_DATA_DIR, which homeboy_data() checks first. Add EnvGuard::unset and clear it. test_database_path also set XDG_DATA_HOME, which can never take effect: the registered home-root override outranks XDG deliberately, and the harness always registers one. It now pins the resolution order that actually exists. store_artifact_tests (1) -- test_record_directory_artifact had two fields swapped. record_directory_artifact_with_id_and_metadata writes the tree digest to sha256, which is also what the idempotent-reuse check compares; the test asserted it in url and expected sha256 to be None. tests/self_checks_test.rs -- release_readiness_source was added to both TestArgs and LintArgs without updating these initializers, so main did not compile. Same E0063 class as #11767, and the second time this session. Verified by diffing full homeboy-core --lib failure lists against origin/main: 30 -> 23, zero new.
1 parent 010df5d commit 40fb123

3 files changed

Lines changed: 52 additions & 11 deletions

File tree

crates/homeboy-core/src/observation/store/schema.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,15 @@ mod tests {
899899
}
900900

901901
fn seed_owned_and_orphaned_children(connection: &Connection) {
902+
// These rows model state written *while FK enforcement was off* -- the
903+
// exact scenario migration 13 exists to clean up, and what
904+
// `migration_13_reaps_rows_orphaned_while_enforcement_was_off` is named
905+
// for. `enforce_foreign_keys` now turns enforcement on at open, so the
906+
// seed must turn it off to create the orphans whose reaping is under
907+
// test. (It also lets `trace_spans` be inserted before `trace_runs`.)
908+
connection
909+
.pragma_update(None, "foreign_keys", false)
910+
.expect("relax foreign keys to seed orphaned children");
902911
connection
903912
.execute_batch(
904913
r#"
@@ -931,6 +940,9 @@ mod tests {
931940
"#,
932941
)
933942
.unwrap();
943+
connection
944+
.pragma_update(None, "foreign_keys", true)
945+
.expect("restore foreign key enforcement after seeding");
934946
}
935947

936948
fn surviving_run_ids(connection: &Connection, table: &str) -> Vec<String> {

tests/core/observation/store_test.rs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ impl XdgGuard {
2929
std::env::remove_var("XDG_DATA_HOME");
3030
Self { prior }
3131
}
32-
33-
fn set(value: &std::path::Path) -> Self {
34-
let prior = std::env::var("XDG_DATA_HOME").ok();
35-
std::env::set_var("XDG_DATA_HOME", value);
36-
Self { prior }
37-
}
3832
}
3933

4034
impl Drop for XdgGuard {
@@ -52,6 +46,18 @@ impl EnvGuard {
5246
std::env::set_var(key, value);
5347
Self { key, prior }
5448
}
49+
50+
/// Clear a variable for the guard's lifetime.
51+
///
52+
/// Needed for the XDG-layout assertions below: `with_isolated_home` sets
53+
/// `HOMEBOY_DATA_DIR`, and `homeboy_data()` checks it *before* consulting
54+
/// `XDG_DATA_HOME` -- so an `XdgGuard` alone cannot reach the path it is
55+
/// setting up. Same drift documented in #11919.
56+
fn unset(key: &'static str) -> Self {
57+
let prior = std::env::var(key).ok();
58+
std::env::remove_var(key);
59+
Self { key, prior }
60+
}
5561
}
5662

5763
impl Drop for EnvGuard {
@@ -70,6 +76,7 @@ mod store_init_tests {
7076
fn test_status() {
7177
with_isolated_home(|home| {
7278
let _xdg = XdgGuard::unset();
79+
let _data_dir = EnvGuard::unset(crate::paths::HOMEBOY_DATA_DIR_ENV);
7380

7481
let status = store::status().expect("status");
7582

@@ -90,15 +97,29 @@ mod store_init_tests {
9097
});
9198
}
9299

100+
/// Pins the resolved database path under an isolated home.
101+
///
102+
/// This deliberately does **not** set `XDG_DATA_HOME`. `homeboy_data()`
103+
/// consults the registered home-root override *before* XDG -- the override
104+
/// "outranks `XDG_DATA_HOME` deliberately" per its own comment -- and
105+
/// `with_isolated_home` always registers one. So an `XdgGuard::set` here
106+
/// could never take effect, and asserting an XDG-derived path was pinning
107+
/// a resolution order that does not exist. It failed for that reason.
108+
///
109+
/// `HOMEBOY_DATA_DIR` is cleared because the harness sets it and it
110+
/// short-circuits ahead of everything; clearing it is what makes this the
111+
/// production default rather than a test artifact (#11919).
93112
#[test]
94113
fn test_database_path() {
95114
with_isolated_home(|home| {
96-
let data_home = home.path().join("xdg-data");
97-
let _xdg = XdgGuard::set(&data_home);
115+
let _data_dir = EnvGuard::unset(crate::paths::HOMEBOY_DATA_DIR_ENV);
98116

99117
let path = store::database_path().expect("db path");
100118

101-
assert_eq!(path, data_home.join("homeboy/homeboy.sqlite"));
119+
assert_eq!(
120+
path,
121+
home.path().join(".local/share/homeboy/homeboy.sqlite")
122+
);
102123
});
103124
}
104125

@@ -1099,16 +1120,22 @@ mod store_artifact_tests {
10991120
std::fs::read_to_string(persisted.join("nested/detail.txt")).expect("read nested"),
11001121
"detail"
11011122
);
1123+
// The immutable tree digest lives in `sha256`, not `url`.
1124+
// `record_directory_artifact_with_id_and_metadata` computes
1125+
// `directory_tree_sha256` and stores it there -- it is also what the
1126+
// idempotent-reuse check compares (`existing.sha256.as_deref()`).
1127+
// This assertion had the two fields swapped and failed for that
1128+
// reason.
11021129
assert_eq!(
1103-
artifact.url,
1130+
artifact.sha256,
11041131
Some(
11051132
crate::observation::directory_tree_sha256(&persisted)
11061133
.expect("directory digest")
11071134
)
11081135
);
11091136
assert_eq!(artifact.size_bytes, None);
11101137
assert_eq!(artifact.mime, None);
1111-
assert_eq!(artifact.sha256, None);
1138+
assert_eq!(artifact.url, None);
11121139
});
11131140
}
11141141

tests/self_checks_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn lint_args(root: &Path) -> LintArgs {
3838
LintArgs {
3939
comp: component_args(root),
4040
extension_override: ExtensionOverrideArgs::default(),
41+
release_readiness_source: None,
4142
summary: false,
4243
file: None,
4344
glob: None,
@@ -59,6 +60,7 @@ fn test_args(root: &Path) -> TestArgs {
5960
comp: component_args(root),
6061
extension_override: ExtensionOverrideArgs::default(),
6162
skip_lint: false,
63+
release_readiness_source: None,
6264
coverage: false,
6365
coverage_min: None,
6466
baseline_args: BaselineArgs::default(),

0 commit comments

Comments
 (0)