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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user