Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions AgenticPatterns.Tests/NewContextPatternTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public void RecentAndRelevantOutranksOldAndImportant()
{
var scored = EpisodicRetrieval.Score(
[
new("Customer reported export timeouts today.", Now.AddHours(-1), 0.3, "exports"),
new("Customer payment failed months ago.", Now.AddDays(-60), 0.9, "billing")
new("ep-1", "Customer reported export timeouts today.", Now.AddHours(-1), 0.3, "exports"),
new("ep-2", "Customer payment failed months ago.", Now.AddDays(-60), 0.9, "billing")
], "export timeouts", Now);

Assert.Contains("export", scored[0].Episode.Text);
Expand All @@ -189,8 +189,8 @@ public void RecencyDecaysWithAge()
{
var scored = EpisodicRetrieval.Score(
[
new("same text here", Now.AddHours(-1), 0.5, "t"),
new("same text here", Now.AddDays(-30), 0.5, "t")
new("ep-1", "same text here", Now.AddHours(-1), 0.5, "t"),
new("ep-2", "same text here", Now.AddDays(-30), 0.5, "t")
], "unrelated", Now);

Assert.True(scored[0].Recency > scored[1].Recency);
Expand All @@ -201,14 +201,15 @@ public void OnlyTopicsOverTheThresholdConsolidate()
{
Episode[] episodes =
[
new("a", Now, 0.5, "exports"), new("b", Now, 0.5, "exports"), new("c", Now, 0.5, "exports"),
new("d", Now, 0.5, "billing"), new("e", Now, 0.5, "billing")
new("a", "a", Now, 0.5, "exports"), new("b", "b", Now, 0.5, "exports"),
new("c", "c", Now, 0.5, "exports"),
new("d", "d", Now, 0.5, "billing"), new("e", "e", Now, 0.5, "billing")
];

Assert.Equal(["exports"], Consolidation.Ripe(episodes, minimum: 3).Select(g => g.Key));
}

[Fact]
public void NothingConsolidatesBelowTheThreshold() =>
Assert.Empty(Consolidation.Ripe([new("a", Now, 0.5, "exports")], minimum: 3));
Assert.Empty(Consolidation.Ripe([new("a", "a", Now, 0.5, "exports")], minimum: 3));
}
6 changes: 4 additions & 2 deletions AgenticPatterns.Tests/NewOrchestrationPatternTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ public async Task TwoHandlersFeedingEachOtherAreStoppedByTheGenerationCap()
}

[Fact]
public void AnEventNobodySubscribesToIsDeadLetteredNotDropped()
public void AnEventNobodySubscribesToIsRecordedNotDropped()
{
var bus = new EventBus(maxEvents: 10, maxGeneration: 5);

// Not queued, but not lost either. Which list it lands in is asserted by
// EventBusTaxonomyTests - a terminal event is a workflow output, not a delivery failure.
Assert.False(bus.Publish(Event("nobody-listens")));
Assert.Single(bus.DeadLetters);
Assert.Single(bus.TerminalEvents);
}

[Fact]
Expand Down
34 changes: 15 additions & 19 deletions AgenticPatterns.Tests/NewProductionControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,50 +91,46 @@ public void AnInterruptBeatsEverything()

public class MemoryGateTests
{
static readonly Source Billing = new("system:billing", Trust.Authoritative);
static readonly Source Operator = new("operator:alice", Trust.Operator);
static readonly Source Web = new("web:vendor.example/sla", Trust.WebContent);
static readonly Source Evil = new("web:collections-desk.example", Trust.WebContent);

static readonly MemoryItem[] Authoritative =
[new("refund_limit_eur", "250", Provenance.Authoritative, Tier.Active)];
[new("refund_limit_eur", "250", Billing, Tier.Active)];

[Fact]
public void AnAuthoritativeFactCannotBeOverwrittenByScrapedContent() =>
Assert.Equal(Tier.Rejected,
MemoryGate.Admit(new("refund_limit_eur", "50000", Provenance.WebContent), Authoritative).Item.Tier);
MemoryGate.Admit(new MemoryItem("refund_limit_eur", "50000", Evil), Authoritative).Item.Tier);

[Fact]
public void ATrustedSourceIsAdmittedDirectly() =>
Assert.Equal(Tier.Active,
MemoryGate.Admit(new("sla_hours", "4", Provenance.Operator), []).Item.Tier);
MemoryGate.Admit(new MemoryItem("sla_hours", "4", Operator), []).Item.Tier);

[Fact]
public void AnUntrustedSourceLandsInQuarantine() =>
Assert.Equal(Tier.Quarantined,
MemoryGate.Admit(new("sla_hours", "4", Provenance.WebContent), []).Item.Tier);
MemoryGate.Admit(new MemoryItem("sla_hours", "4", Web), []).Item.Tier);

[Fact]
public void TheSameUntrustedSourceRepeatingItselfIsNotCorroboration()
public void TheSameSourceRepeatingItselfIsNotCorroboration()
{
var store = new List<MemoryItem> { new("sla_hours", "4", Provenance.WebContent) };
List<MemoryItem> store = [new("sla_hours", "4", Web)];

Assert.Equal(Tier.Quarantined,
MemoryGate.Admit(new("sla_hours", "4", Provenance.WebContent), store).Item.Tier);
}

[Fact]
public void AnIndependentSourceAgreeingPromotesTheMemory()
{
var store = new List<MemoryItem> { new("sla_hours", "4", Provenance.WebContent) };

Assert.Equal(Tier.Active,
MemoryGate.Admit(new("sla_hours", "4", Provenance.ToolOutput), store).Item.Tier);
MemoryGate.Admit(new MemoryItem("sla_hours", "4", Web), store).Item.Tier);
}

[Fact]
public void QuarantinedItemsAreNotRetrievable()
{
MemoryItem[] store =
[
new("a", "1", Provenance.Authoritative, Tier.Active),
new("b", "2", Provenance.WebContent, Tier.Quarantined),
new("c", "3", Provenance.WebContent, Tier.Rejected)
new("a", "1", Billing, Tier.Active),
new("b", "2", Web, Tier.Quarantined),
new("c", "3", Evil, Tier.Rejected)
];

Assert.Equal(["a"], MemoryGate.Retrievable(store).Select(m => m.Key));
Expand Down
Loading