-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportFormatterTests.cs
More file actions
135 lines (110 loc) · 5.09 KB
/
ReportFormatterTests.cs
File metadata and controls
135 lines (110 loc) · 5.09 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
using CodexSessionSync.Core;
namespace CodexSessionSync.Tests;
public class ReportFormatterTests
{
[Fact]
public void FormatCounts_Dictionary_ReturnsSortedByCount()
{
var counts = new Dictionary<string, int> { ["openai"] = 5, ["anthropic"] = 3 };
var result = ReportFormatter.FormatCounts(counts);
Assert.Equal(2, result.Count);
Assert.Contains("openai: 5", result[0]);
Assert.Contains("anthropic: 3", result[1]);
}
[Fact]
public void FormatCounts_Dictionary_Empty_ReturnsNone()
{
var counts = new Dictionary<string, int>();
var result = ReportFormatter.FormatCounts(counts);
Assert.Single(result);
Assert.Equal("- none", result[0]);
}
[Fact]
public void FormatCounts_TupleList_MergesNullAsMissing()
{
var counts = new List<(string?, int)> { ("openai", 5), (null, 2) };
var result = ReportFormatter.FormatCounts(counts);
Assert.Equal(2, result.Count);
Assert.Contains("openai: 5", result[0]);
Assert.Contains("<missing>: 2", result[1]);
}
[Fact]
public void RenderMutual_ContainsModeAndProviders()
{
var config = new ConfigStatus("config.toml", "openai", new List<string> { "openai" }, true, null);
var report = new SyncReport { SourceProvider = "*", TargetProviders = new List<string> { "openai" } };
var sqlite = new SqliteReport { Path = null };
var result = ReportFormatter.RenderMutual("/home/user/.codex", null, config, new List<string> { "openai" }, report, sqlite, false);
Assert.Contains("mutual provider session sync", result);
Assert.Contains("/home/user/.codex", result);
Assert.Contains("Preview only", result);
}
[Fact]
public void RenderMutual_ApplyMode_NoPreviewMessage()
{
var config = new ConfigStatus("config.toml", "openai", new List<string> { "openai" }, true, null);
var report = new SyncReport { SourceProvider = "*", TargetProviders = new List<string> { "openai" } };
var sqlite = new SqliteReport { Path = null };
var result = ReportFormatter.RenderMutual("/home/user/.codex", null, config, new List<string> { "openai" }, report, sqlite, true);
Assert.Contains("apply", result);
Assert.DoesNotContain("Preview only", result);
}
[Fact]
public void RenderOpenAi_ContainsSourceAndTarget()
{
var report = new SyncReport { SourceProvider = "openai", TargetProviders = new List<string> { "anthropic" } };
var sqlite = new SqliteReport { Path = null };
var result = ReportFormatter.RenderOpenAi("/home/user/.codex", null, "openai", new List<string> { "anthropic" }, report, sqlite, false);
Assert.Contains("openai sync to all", result);
Assert.Contains("Source provider: openai", result);
Assert.Contains("anthropic", result);
}
[Fact]
public void RenderMigrate_ContainsMigrationInfo()
{
var result_model = new MigrateResult
{
FilesScanned = 10,
FilesNeedingUpdate = 3,
FilesUpdated = 3,
SessionMetaRewritten = 5,
ProviderCountsBefore = new Dictionary<string, int> { ["openai"] = 8, ["anthropic"] = 2 },
ProviderCountsAfter = new Dictionary<string, int> { ["openai"] = 10 },
Sqlite = new SqliteReport { Path = "/path/to/state.sqlite", RowsNeedingUpdate = 2, RowsUpdated = 2 }
};
var result = ReportFormatter.RenderMigrate("/home/user/.codex", "/backup", "openai", result_model, true);
Assert.Contains("single-target migration", result);
Assert.Contains("files scanned: 10", result);
Assert.Contains("session_meta rewritten: 5", result);
Assert.Contains("state.sqlite", result);
Assert.DoesNotContain("Preview only", result);
}
[Fact]
public void RenderMigrate_PreviewMode_ShowsPreviewMessage()
{
var result_model = new MigrateResult
{
Sqlite = new SqliteReport { Path = null }
};
var result = ReportFormatter.RenderMigrate("/home/user/.codex", null, "openai", result_model, false);
Assert.Contains("Preview only", result);
}
[Fact]
public void RenderMutual_WithBackupDir_ShowsBackupPath()
{
var config = new ConfigStatus("config.toml", "openai", new List<string>(), false, null);
var report = new SyncReport();
var sqlite = new SqliteReport();
var result = ReportFormatter.RenderMutual("/home/user/.codex", "/tmp/backup", config, new List<string>(), report, sqlite, false);
Assert.Contains("Backup dir: /tmp/backup", result);
}
[Fact]
public void RenderMutual_NoProviders_ShowsWarning()
{
var config = new ConfigStatus("config.toml", null, new List<string>(), false, null);
var report = new SyncReport { TargetProviders = new List<string>() };
var sqlite = new SqliteReport();
var result = ReportFormatter.RenderMutual("/home/user/.codex", null, config, new List<string>(), report, sqlite, false);
Assert.Contains("No configured providers found", result);
}
}