core: require account attribution for legacy imports

Apply provider and historical account identity checks to the designated hourly import source. Retain previously attributed history when a CLI signs out, while excluding mismatched or unknown accounts.

Refs #19
This commit is contained in:
Florian Schmidt
2026-11-15 11:14:52 +01:00
parent b23b7289c7
commit 583f920307
3 changed files with 27 additions and 3 deletions
@@ -116,6 +116,30 @@ public sealed class FleetTests
var b = Profile([raw]) with { LegacyTokens = [new(cutoff.AddHours(-1), null, new(Total: 200))] };
Assert.Equal(107, Analyze(a,b,cfg).Total.Total);
}
[Theory]
[InlineData("[email protected]", Provider.Claude)]
[InlineData(null, Provider.Claude)]
[InlineData("[email protected]", Provider.Codex)]
public void LegacyHistoryMustBelongToTheConfiguredAccount(string? email, Provider provider)
{
var cutoff = Now.AddDays(-1); var cfg = Config();
cfg = cfg with { Accounts = [cfg.Accounts[0] with { LegacyMachine = "a", LegacyProfile = "main", HistoryBefore = cutoff }] };
var p = Profile(provider: provider) with { DataEmail = email,
LegacyTokens = [new(cutoff.AddHours(-1), "claude-opus-4-6", new(Input: 100, Total: 100))] };
var view = Analyze(p, config: cfg);
Assert.Equal(0, view.Total.Total); Assert.Empty(view.Tokens); Assert.Null(view.ApiValue);
Assert.False(view.HasConsumptionData);
Assert.Contains(view.Warnings, w => w.Contains("legacy", StringComparison.OrdinalIgnoreCase) &&
w.Contains("unverified", StringComparison.OrdinalIgnoreCase));
}
[Fact] public void LoggedOutLegacySourceRetainsPreviouslyVerifiedAttribution()
{
var cutoff = Now.AddDays(-1); var cfg = Config();
cfg = cfg with { Accounts = [cfg.Accounts[0] with { LegacyMachine = "a", LegacyProfile = "main", HistoryBefore = cutoff }] };
var p = Profile() with { Auth = new("Unavailable", null, Now, "Signed out"),
LegacyTokens = [new(cutoff.AddHours(-1), null, new(Total: 100))] };
Assert.Equal(100, Analyze(p, config: cfg).Total.Total);
}
[Fact] public void DashboardJsonRoundTripsWithoutReflection()
{
var view = FleetAnalysis.Build(Config(),new([Machine("a",Profile(limits:[Week()]))]),Now);