This repository was archived by the owner on Jan 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_models.py
More file actions
752 lines (640 loc) · 26.6 KB
/
Copy pathtest_models.py
File metadata and controls
752 lines (640 loc) · 26.6 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
"""Tests for git_notes_memory.models module.
Tests all dataclasses, enums, and their behavior including:
- Instantiation with required and optional fields
- Immutability (frozen dataclasses)
- Convenience properties and methods
- Enum values and membership
"""
from __future__ import annotations
from dataclasses import FrozenInstanceError
from datetime import UTC, datetime
import pytest
from git_notes_memory.models import (
# Result Models
CaptureAccumulator,
CaptureResult,
# Core Models
CommitInfo,
HydratedMemory,
# Enums
HydrationLevel,
IndexStats,
Memory,
MemoryResult,
NoteRecord,
# Pattern Models
Pattern,
PatternStatus,
PatternType,
SpecContext,
VerificationResult,
)
# =============================================================================
# Test Fixtures
# =============================================================================
@pytest.fixture
def sample_timestamp() -> datetime:
"""Sample timestamp for tests."""
return datetime(2025, 1, 15, 10, 30, 0, tzinfo=UTC)
@pytest.fixture
def sample_memory(sample_timestamp: datetime) -> Memory:
"""Sample Memory instance for tests."""
return Memory(
id="decisions:abc123:0",
commit_sha="abc123def456",
namespace="decisions",
summary="Chose PostgreSQL for persistence",
content="Evaluated SQLite vs PostgreSQL. PostgreSQL wins for concurrency.",
timestamp=sample_timestamp,
spec="auth-service",
phase="implementation",
tags=("database", "architecture"),
status="active",
relates_to=("blockers:xyz789:0",),
)
@pytest.fixture
def sample_commit_info() -> CommitInfo:
"""Sample CommitInfo instance for tests."""
return CommitInfo(
sha="abc123def456789",
author_name="Test Author",
date="2025-01-15T10:30:00Z",
message="feat: add authentication module",
)
# =============================================================================
# Enum Tests
# =============================================================================
class TestHydrationLevel:
"""Tests for HydrationLevel enum."""
def test_values(self) -> None:
"""Test enum values are correct."""
assert HydrationLevel.SUMMARY.value == 1
assert HydrationLevel.FULL.value == 2
assert HydrationLevel.FILES.value == 3
def test_ordering(self) -> None:
"""Test levels can be compared by value."""
assert HydrationLevel.SUMMARY.value < HydrationLevel.FULL.value
assert HydrationLevel.FULL.value < HydrationLevel.FILES.value
def test_membership(self) -> None:
"""Test all expected members exist."""
members = list(HydrationLevel)
assert len(members) == 3
assert HydrationLevel.SUMMARY in members
assert HydrationLevel.FULL in members
assert HydrationLevel.FILES in members
class TestPatternType:
"""Tests for PatternType enum."""
def test_values(self) -> None:
"""Test enum string values."""
assert PatternType.SUCCESS.value == "success"
assert PatternType.ANTI_PATTERN.value == "anti-pattern"
assert PatternType.WORKFLOW.value == "workflow"
assert PatternType.DECISION.value == "decision"
assert PatternType.TECHNICAL.value == "technical"
def test_membership(self) -> None:
"""Test all expected members exist."""
members = list(PatternType)
assert len(members) == 5
class TestPatternStatus:
"""Tests for PatternStatus enum."""
def test_values(self) -> None:
"""Test enum string values."""
assert PatternStatus.CANDIDATE.value == "candidate"
assert PatternStatus.VALIDATED.value == "validated"
assert PatternStatus.PROMOTED.value == "promoted"
assert PatternStatus.DEPRECATED.value == "deprecated"
def test_membership(self) -> None:
"""Test all expected members exist."""
members = list(PatternStatus)
assert len(members) == 4
# =============================================================================
# Core Model Tests
# =============================================================================
class TestMemory:
"""Tests for Memory dataclass."""
def test_creation_with_required_fields(self, sample_timestamp: datetime) -> None:
"""Test creating Memory with only required fields."""
memory = Memory(
id="test:sha:0",
commit_sha="abc123",
namespace="decisions",
summary="Test summary",
content="Test content",
timestamp=sample_timestamp,
)
assert memory.id == "test:sha:0"
assert memory.commit_sha == "abc123"
assert memory.namespace == "decisions"
assert memory.summary == "Test summary"
assert memory.content == "Test content"
assert memory.timestamp == sample_timestamp
def test_default_values(self, sample_timestamp: datetime) -> None:
"""Test default values for optional fields."""
memory = Memory(
id="test:sha:0",
commit_sha="abc123",
namespace="decisions",
summary="Test summary",
content="Test content",
timestamp=sample_timestamp,
)
assert memory.spec is None
assert memory.phase is None
assert memory.tags == ()
assert memory.status == "active"
assert memory.relates_to == ()
def test_creation_with_all_fields(self, sample_memory: Memory) -> None:
"""Test creating Memory with all fields."""
assert sample_memory.spec == "auth-service"
assert sample_memory.phase == "implementation"
assert sample_memory.tags == ("database", "architecture")
assert sample_memory.relates_to == ("blockers:xyz789:0",)
def test_immutability(self, sample_memory: Memory) -> None:
"""Test that Memory is immutable."""
with pytest.raises(FrozenInstanceError):
sample_memory.summary = "Changed summary" # type: ignore[misc]
def test_equality(self, sample_timestamp: datetime) -> None:
"""Test equality comparison."""
memory1 = Memory(
id="test:sha:0",
commit_sha="abc123",
namespace="decisions",
summary="Test",
content="Content",
timestamp=sample_timestamp,
)
memory2 = Memory(
id="test:sha:0",
commit_sha="abc123",
namespace="decisions",
summary="Test",
content="Content",
timestamp=sample_timestamp,
)
assert memory1 == memory2
class TestMemoryResult:
"""Tests for MemoryResult dataclass."""
def test_creation(self, sample_memory: Memory) -> None:
"""Test creating MemoryResult."""
result = MemoryResult(memory=sample_memory, distance=0.25)
assert result.memory == sample_memory
assert result.distance == 0.25
def test_convenience_properties(self, sample_memory: Memory) -> None:
"""Test convenience properties delegate to memory."""
result = MemoryResult(memory=sample_memory, distance=0.25)
assert result.id == sample_memory.id
assert result.commit_sha == sample_memory.commit_sha
assert result.namespace == sample_memory.namespace
assert result.summary == sample_memory.summary
assert result.content == sample_memory.content
assert result.timestamp == sample_memory.timestamp
assert result.spec == sample_memory.spec
assert result.phase == sample_memory.phase
assert result.tags == sample_memory.tags
assert result.status == sample_memory.status
assert result.relates_to == sample_memory.relates_to
def test_score_alias(self, sample_memory: Memory) -> None:
"""Test score property is alias for distance."""
result = MemoryResult(memory=sample_memory, distance=0.42)
assert result.score == result.distance == 0.42
def test_immutability(self, sample_memory: Memory) -> None:
"""Test that MemoryResult is immutable."""
result = MemoryResult(memory=sample_memory, distance=0.25)
with pytest.raises(FrozenInstanceError):
result.distance = 0.5 # type: ignore[misc]
class TestHydratedMemory:
"""Tests for HydratedMemory dataclass."""
def test_creation_minimal(self, sample_memory: Memory) -> None:
"""Test creating HydratedMemory with minimal fields."""
result = MemoryResult(memory=sample_memory, distance=0.1)
hydrated = HydratedMemory(result=result)
assert hydrated.result == result
assert hydrated.full_content is None
assert hydrated.files == ()
assert hydrated.commit_info is None
def test_creation_with_all_fields(
self, sample_memory: Memory, sample_commit_info: CommitInfo
) -> None:
"""Test creating HydratedMemory with all fields."""
result = MemoryResult(memory=sample_memory, distance=0.1)
hydrated = HydratedMemory(
result=result,
full_content="Full markdown content here",
files=(("src/main.py", "print('hello')"), ("README.md", "# Project")),
commit_info=sample_commit_info,
)
assert hydrated.full_content == "Full markdown content here"
assert len(hydrated.files) == 2
assert hydrated.commit_info == sample_commit_info
def test_files_dict_property(self, sample_memory: Memory) -> None:
"""Test files_dict convenience property."""
result = MemoryResult(memory=sample_memory, distance=0.1)
hydrated = HydratedMemory(
result=result,
files=(("src/main.py", "code"), ("README.md", "docs")),
)
files_dict = hydrated.files_dict
assert files_dict == {"src/main.py": "code", "README.md": "docs"}
def test_immutability(self, sample_memory: Memory) -> None:
"""Test that HydratedMemory is immutable."""
result = MemoryResult(memory=sample_memory, distance=0.1)
hydrated = HydratedMemory(result=result)
with pytest.raises(FrozenInstanceError):
hydrated.full_content = "changed" # type: ignore[misc]
class TestSpecContext:
"""Tests for SpecContext dataclass."""
def test_creation_minimal(self) -> None:
"""Test creating SpecContext with minimal fields."""
ctx = SpecContext(spec="auth-service")
assert ctx.spec == "auth-service"
assert ctx.memories == ()
assert ctx.total_count == 0
assert ctx.token_estimate == 0
def test_creation_with_memories(
self, sample_memory: Memory, sample_timestamp: datetime
) -> None:
"""Test creating SpecContext with memories."""
memory2 = Memory(
id="blockers:xyz:0",
commit_sha="xyz789",
namespace="blockers",
summary="API rate limiting",
content="Third-party API has rate limits.",
timestamp=sample_timestamp,
spec="auth-service",
)
ctx = SpecContext(
spec="auth-service",
memories=(sample_memory, memory2),
total_count=2,
token_estimate=500,
)
assert len(ctx.memories) == 2
assert ctx.total_count == 2
assert ctx.token_estimate == 500
def test_by_namespace_property(
self, sample_memory: Memory, sample_timestamp: datetime
) -> None:
"""Test by_namespace groups memories correctly."""
memory2 = Memory(
id="blockers:xyz:0",
commit_sha="xyz789",
namespace="blockers",
summary="Blocker summary",
content="Content",
timestamp=sample_timestamp,
)
memory3 = Memory(
id="decisions:abc:1",
commit_sha="abc124",
namespace="decisions",
summary="Another decision",
content="Content",
timestamp=sample_timestamp,
)
ctx = SpecContext(
spec="test",
memories=(sample_memory, memory2, memory3),
)
by_ns = ctx.by_namespace
assert "decisions" in by_ns
assert "blockers" in by_ns
assert len(by_ns["decisions"]) == 2
assert len(by_ns["blockers"]) == 1
# =============================================================================
# Result Model Tests
# =============================================================================
class TestCaptureResult:
"""Tests for CaptureResult dataclass."""
def test_successful_capture(self, sample_memory: Memory) -> None:
"""Test successful capture result."""
result = CaptureResult(
success=True,
memory=sample_memory,
indexed=True,
)
assert result.success is True
assert result.memory == sample_memory
assert result.indexed is True
assert result.warning is None
def test_failed_capture_with_warning(self) -> None:
"""Test failed capture result with warning."""
result = CaptureResult(
success=False,
warning="Embedding service unavailable",
)
assert result.success is False
assert result.memory is None
assert result.indexed is False
assert result.warning == "Embedding service unavailable"
def test_immutability(self) -> None:
"""Test that CaptureResult is immutable."""
result = CaptureResult(success=True)
with pytest.raises(FrozenInstanceError):
result.success = False # type: ignore[misc]
class TestCaptureAccumulator:
"""Tests for CaptureAccumulator dataclass."""
def test_creation_empty(self) -> None:
"""Test creating empty accumulator."""
acc = CaptureAccumulator()
assert acc.captures == []
assert acc.count == 0
assert acc.successful_count == 0
def test_add_capture(self, sample_memory: Memory) -> None:
"""Test adding captures."""
acc = CaptureAccumulator()
result = CaptureResult(success=True, memory=sample_memory, indexed=True)
acc.add(result)
assert acc.count == 1
assert acc.successful_count == 1
def test_count_properties(self, sample_memory: Memory) -> None:
"""Test count and successful_count properties."""
acc = CaptureAccumulator()
acc.add(CaptureResult(success=True, memory=sample_memory))
acc.add(CaptureResult(success=False, warning="Failed"))
acc.add(CaptureResult(success=True, memory=sample_memory))
assert acc.count == 3
assert acc.successful_count == 2
def test_by_namespace_property(
self, sample_memory: Memory, sample_timestamp: datetime
) -> None:
"""Test by_namespace groups counts correctly."""
acc = CaptureAccumulator()
blocker = Memory(
id="blockers:x:0",
commit_sha="x",
namespace="blockers",
summary="Test",
content="C",
timestamp=sample_timestamp,
)
acc.add(CaptureResult(success=True, memory=sample_memory))
acc.add(CaptureResult(success=True, memory=blocker))
acc.add(CaptureResult(success=True, memory=sample_memory))
by_ns = acc.by_namespace
assert by_ns["decisions"] == 2
assert by_ns["blockers"] == 1
def test_summary_empty(self) -> None:
"""Test summary for empty accumulator."""
acc = CaptureAccumulator()
assert acc.summary() == "No memories captured this session."
def test_summary_with_captures(self, sample_memory: Memory) -> None:
"""Test summary with captures."""
acc = CaptureAccumulator()
acc.add(CaptureResult(success=True, memory=sample_memory))
summary = acc.summary()
assert "Memory Capture Summary" in summary
assert "Captured: 1 memories" in summary
assert sample_memory.id in summary
def test_summary_with_warning(self) -> None:
"""Test summary includes warnings for failed captures without memory."""
acc = CaptureAccumulator()
acc.add(CaptureResult(success=False, warning="Embedding service failed"))
summary = acc.summary()
assert "Embedding service failed" in summary
assert "⚠" in summary
def test_is_mutable(self) -> None:
"""Test that CaptureAccumulator is NOT frozen (mutable)."""
acc = CaptureAccumulator()
acc.captures = [] # Should not raise
assert acc.captures == []
class TestIndexStats:
"""Tests for IndexStats dataclass."""
def test_creation_minimal(self) -> None:
"""Test creating IndexStats with minimal fields."""
stats = IndexStats(total_memories=100)
assert stats.total_memories == 100
assert stats.by_namespace == ()
assert stats.by_spec == ()
assert stats.last_sync is None
assert stats.index_size_bytes == 0
def test_creation_with_all_fields(self, sample_timestamp: datetime) -> None:
"""Test creating IndexStats with all fields."""
stats = IndexStats(
total_memories=150,
by_namespace=(("decisions", 50), ("blockers", 30), ("learnings", 70)),
by_spec=(("auth-service", 80), ("api-gateway", 70)),
last_sync=sample_timestamp,
index_size_bytes=1024000,
)
assert stats.total_memories == 150
assert len(stats.by_namespace) == 3
assert len(stats.by_spec) == 2
assert stats.last_sync == sample_timestamp
assert stats.index_size_bytes == 1024000
def test_dict_properties(self) -> None:
"""Test dict convenience properties."""
stats = IndexStats(
total_memories=100,
by_namespace=(("decisions", 50), ("blockers", 50)),
by_spec=(("auth", 60), ("api", 40)),
)
assert stats.by_namespace_dict == {"decisions": 50, "blockers": 50}
assert stats.by_spec_dict == {"auth": 60, "api": 40}
def test_immutability(self) -> None:
"""Test that IndexStats is immutable."""
stats = IndexStats(total_memories=100)
with pytest.raises(FrozenInstanceError):
stats.total_memories = 200 # type: ignore[misc]
class TestVerificationResult:
"""Tests for VerificationResult dataclass."""
def test_consistent_index(self) -> None:
"""Test result for consistent index."""
result = VerificationResult(is_consistent=True)
assert result.is_consistent is True
assert result.missing_in_index == ()
assert result.orphaned_in_index == ()
assert result.mismatched == ()
assert result.total_issues == 0
def test_inconsistent_index(self) -> None:
"""Test result for inconsistent index."""
result = VerificationResult(
is_consistent=False,
missing_in_index=("mem1", "mem2"),
orphaned_in_index=("mem3",),
mismatched=("mem4", "mem5", "mem6"),
)
assert result.is_consistent is False
assert len(result.missing_in_index) == 2
assert len(result.orphaned_in_index) == 1
assert len(result.mismatched) == 3
assert result.total_issues == 6
def test_immutability(self) -> None:
"""Test that VerificationResult is immutable."""
result = VerificationResult(is_consistent=True)
with pytest.raises(FrozenInstanceError):
result.is_consistent = False # type: ignore[misc]
# =============================================================================
# Pattern Model Tests
# =============================================================================
class TestPattern:
"""Tests for Pattern dataclass."""
def test_creation_minimal(self) -> None:
"""Test creating Pattern with minimal fields."""
pattern = Pattern(
name="Error Handling Pattern",
pattern_type=PatternType.SUCCESS,
description="Consistent error handling improves debugging.",
)
assert pattern.name == "Error Handling Pattern"
assert pattern.pattern_type == PatternType.SUCCESS
assert pattern.description == "Consistent error handling improves debugging."
def test_default_values(self) -> None:
"""Test default values for optional fields."""
pattern = Pattern(
name="Test",
pattern_type=PatternType.WORKFLOW,
description="Desc",
)
assert pattern.evidence == ()
assert pattern.confidence == 0.0
assert pattern.tags == ()
assert pattern.status == PatternStatus.CANDIDATE
assert pattern.first_seen is None
assert pattern.last_seen is None
assert pattern.occurrence_count == 1
def test_creation_with_all_fields(self, sample_timestamp: datetime) -> None:
"""Test creating Pattern with all fields."""
pattern = Pattern(
name="Code Review Pattern",
pattern_type=PatternType.WORKFLOW,
description="Always review code before merge.",
evidence=("mem1", "mem2", "mem3"),
confidence=0.85,
tags=("quality", "process"),
status=PatternStatus.VALIDATED,
first_seen=sample_timestamp,
last_seen=sample_timestamp,
occurrence_count=5,
)
assert pattern.confidence == 0.85
assert len(pattern.evidence) == 3
assert pattern.status == PatternStatus.VALIDATED
assert pattern.occurrence_count == 5
def test_immutability(self) -> None:
"""Test that Pattern is immutable."""
pattern = Pattern(
name="Test",
pattern_type=PatternType.TECHNICAL,
description="Desc",
)
with pytest.raises(FrozenInstanceError):
pattern.name = "Changed" # type: ignore[misc]
# =============================================================================
# Git Model Tests
# =============================================================================
class TestCommitInfo:
"""Tests for CommitInfo dataclass."""
def test_creation(self, sample_commit_info: CommitInfo) -> None:
"""Test creating CommitInfo."""
assert sample_commit_info.sha == "abc123def456789"
assert sample_commit_info.author_name == "Test Author"
assert sample_commit_info.date == "2025-01-15T10:30:00Z"
assert sample_commit_info.message == "feat: add authentication module"
def test_immutability(self, sample_commit_info: CommitInfo) -> None:
"""Test that CommitInfo is immutable."""
with pytest.raises(FrozenInstanceError):
sample_commit_info.sha = "changed" # type: ignore[misc]
class TestNoteRecord:
"""Tests for NoteRecord dataclass."""
def test_creation_minimal(self) -> None:
"""Test creating NoteRecord with minimal fields."""
record = NoteRecord(
commit_sha="abc123",
namespace="decisions",
)
assert record.commit_sha == "abc123"
assert record.namespace == "decisions"
assert record.index == 0
assert record.front_matter == ()
assert record.body == ""
assert record.raw == ""
def test_creation_with_all_fields(self) -> None:
"""Test creating NoteRecord with all fields."""
record = NoteRecord(
commit_sha="abc123",
namespace="decisions",
index=1,
front_matter=(("summary", "Test decision"), ("spec", "auth-service")),
body="Full markdown body content here.",
raw="---\nsummary: Test decision\n---\nFull markdown body content here.",
)
assert record.index == 1
assert len(record.front_matter) == 2
assert record.body == "Full markdown body content here."
def test_front_matter_dict_property(self) -> None:
"""Test front_matter_dict convenience property."""
record = NoteRecord(
commit_sha="abc123",
namespace="decisions",
front_matter=(
("summary", "Test"),
("spec", "auth"),
("phase", "planning"),
),
)
fm_dict = record.front_matter_dict
assert fm_dict == {"summary": "Test", "spec": "auth", "phase": "planning"}
def test_immutability(self) -> None:
"""Test that NoteRecord is immutable."""
record = NoteRecord(commit_sha="abc", namespace="test")
with pytest.raises(FrozenInstanceError):
record.body = "changed" # type: ignore[misc]
# =============================================================================
# Edge Case Tests
# =============================================================================
class TestEdgeCases:
"""Tests for edge cases and special scenarios."""
def test_empty_tuples_are_independent(self) -> None:
"""Test that default tuple factories create independent instances."""
mem1 = Memory(
id="1",
commit_sha="a",
namespace="test",
summary="s",
content="c",
timestamp=datetime.now(UTC),
)
mem2 = Memory(
id="2",
commit_sha="b",
namespace="test",
summary="s",
content="c",
timestamp=datetime.now(UTC),
)
# Empty tuples are singletons in Python, but this shouldn't cause issues
assert mem1.tags == mem2.tags == ()
def test_memory_result_with_zero_distance(self, sample_memory: Memory) -> None:
"""Test MemoryResult with exact match (distance=0)."""
result = MemoryResult(memory=sample_memory, distance=0.0)
assert result.distance == 0.0
assert result.score == 0.0
def test_capture_accumulator_start_time(self) -> None:
"""Test that start_time is set on creation."""
before = datetime.now(UTC)
acc = CaptureAccumulator()
after = datetime.now(UTC)
assert before <= acc.start_time <= after
def test_verification_result_empty_issues(self) -> None:
"""Test VerificationResult with no issues has zero total."""
result = VerificationResult(is_consistent=True)
assert result.total_issues == 0
def test_pattern_confidence_bounds(self) -> None:
"""Test pattern confidence accepts 0.0 to 1.0 range."""
pattern_low = Pattern(
name="Low",
pattern_type=PatternType.SUCCESS,
description="D",
confidence=0.0,
)
pattern_high = Pattern(
name="High",
pattern_type=PatternType.SUCCESS,
description="D",
confidence=1.0,
)
assert pattern_low.confidence == 0.0
assert pattern_high.confidence == 1.0