1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Unit tests for the `session` command helpers.
//!
//! Why: extracted from `session.rs` to keep that production file under the
//! 500-SLOC cap while retaining full test coverage for the private helpers.
//! What: tests for `derive_source_id_from_path` and `matches_session`.
//! Test: this file (budget: 1500 SLOC as a `_tests.rs` file).
use super::{derive_source_id_from_path, matches_session};
#[test]
fn derive_source_id_from_cwd_returns_none_without_git() {
// A fresh TempDir has no git repo, so get_origin_url will return None
// and derive_source_id_from_path must return None (not panic).
let dir = tempfile::TempDir::new().expect("tempdir");
assert!(
derive_source_id_from_path(dir.path()).is_none(),
"non-git directory must yield None"
);
}
#[test]
fn ls_source_id_filter_selects_correct_slug() {
// When source_id = Some("owner/repo") and current = false, the slug
// comes straight from the --source-id flag (no git lookup needed).
// We verify the slug is correctly passed by asserting it would be used
// as-is in the query param (no transformation needed for a valid slug).
let slug = "myorg/myrepo";
// A valid slug contains exactly one '/' and no whitespace.
assert!(slug.contains('/'), "slug must be owner/repo form");
assert_eq!(
slug.split('/').count(),
2,
"slug must have exactly two parts"
);
// derive_source_id_from_path returns the same owner/repo format.
// This test guards the format invariant that the daemon expects.
let (owner, repo) = slug.split_once('/').unwrap();
assert!(!owner.is_empty());
assert!(!repo.is_empty());
}
#[test]
fn info_managed_fallback_matches_by_id_and_name() {
let session = serde_json::json!({
"id": "abc-1234-uuid",
"name": "tmpm-red-owl",
"state": "active"
});
assert!(
matches_session(&session, "abc-1234-uuid"),
"must match by exact id"
);
assert!(
matches_session(&session, "tmpm-red-owl"),
"must match by exact name"
);
assert!(
!matches_session(&session, "tmpm-blue-fox"),
"must not match a different name"
);
assert!(
!matches_session(&session, "xyz-9999"),
"must not match a different id"
);
// Partial matches are not accepted — the lookup is exact.
assert!(
!matches_session(&session, "abc-1234"),
"partial id must not match"
);
}