mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(context): support copy attributes on root tag into snapshot element
This commit is contained in:
@@ -299,11 +299,14 @@ private class AggregatedBlockContent(
|
||||
val tagName = if (index == snapshotIndex) "snapshot" else "history_snapshot"
|
||||
val wrapper = document.createElement(tagName)
|
||||
val renderedBlock = groupedBlock.renderedBlock
|
||||
wrapper.setAttribute("source", renderedBlock.source)
|
||||
wrapper.setAttribute("urgency", renderedBlock.urgency.name.lowercase(Locale.ROOT))
|
||||
val encoded = renderedBlock.encodeToXml()
|
||||
val attributes = encoded.attributes
|
||||
for (attributeIndex in 0 until attributes.length) {
|
||||
val attribute = attributes.item(attributeIndex)
|
||||
wrapper.setAttribute(attribute.nodeName, attribute.nodeValue)
|
||||
}
|
||||
root.appendChild(wrapper)
|
||||
|
||||
val encoded = renderedBlock.encodeToXml()
|
||||
val childNodes = encoded.childNodes
|
||||
for (childIndex in 0 until childNodes.length) {
|
||||
wrapper.appendChild(document.importNode(childNodes.item(childIndex), true))
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user