refactor(context): support copy attributes on root tag into snapshot element

This commit is contained in:
2026-03-29 17:28:41 +08:00
parent 247052e318
commit 1c995923a1
2 changed files with 54 additions and 4 deletions

View File

@@ -109,6 +109,41 @@ class ContextWorkspaceTest {
assertTrue(aggregatedXml.contains("<content>older</content>"))
}
@Test
fun `aggregated snapshots preserve rendered block root attributes`() {
val manager = ContextWorkspace()
manager.register(
ContextBlock(
blockContent = AttributedTestBlockContent("memory", "main", "older", "historic"),
compactBlock = AttributedTestBlockContent("memory", "main", "older-compact", "historic"),
abstractBlock = AttributedTestBlockContent("memory", "main", "older-abstract", "historic"),
visibleTo = setOf(ContextBlock.VisibleDomain.MEMORY),
replaceFadeFactor = 20.0,
timeFadeFactor = 0.0,
activateFactor = 0.0
)
)
manager.register(
ContextBlock(
blockContent = AttributedTestBlockContent("memory", "main", "newer", "latest"),
compactBlock = AttributedTestBlockContent("memory", "main", "newer-compact", "latest"),
abstractBlock = AttributedTestBlockContent("memory", "main", "newer-abstract", "latest"),
visibleTo = setOf(ContextBlock.VisibleDomain.MEMORY),
replaceFadeFactor = 20.0,
timeFadeFactor = 0.0,
activateFactor = 0.0
)
)
val resolved = manager.resolve(listOf(ContextBlock.VisibleDomain.MEMORY))
val aggregatedXml = resolved.blocks.single().encodeToXmlString()
assertTrue(aggregatedXml.contains("<snapshot category=\"latest\" source=\"main\" urgency=\"normal\">"))
assertTrue(aggregatedXml.contains("<history_snapshot category=\"historic\" source=\"main\" urgency=\"normal\">"))
assertTrue(aggregatedXml.contains("<content>newer</content>"))
assertTrue(aggregatedXml.contains("<content>older</content>"))
}
@Test
fun `register fades matching source blocks and removes zero score ones`() {
val manager = ContextWorkspace()
@@ -420,7 +455,7 @@ class ContextWorkspaceTest {
)
}
private class TestBlockContent(
private open class TestBlockContent(
blockName: String,
source: String,
val content: String,
@@ -430,4 +465,16 @@ class ContextWorkspaceTest {
appendTextElement(document, root, "content", content)
}
}
private class AttributedTestBlockContent(
blockName: String,
source: String,
content: String,
private val category: String,
urgency: Urgency = Urgency.NORMAL
) : TestBlockContent(blockName, source, content, urgency) {
override fun appendRootAttributes(): Map<String, String> {
return super.appendRootAttributes() + ("category" to category)
}
}
}