Index tier history sources lazily
This commit is contained in:
@@ -1006,6 +1006,13 @@ mapping for each of S contributions. Use existing wide/sparse fixtures, not timi
|
|||||||
thresholds or another explanation-replay implementation.
|
thresholds or another explanation-replay implementation.
|
||||||
Focused check: `go test ./internal/engine -run 'Tier|Projection|Sequence|History'`.
|
Focused check: `go test ./internal/engine -run 'Tier|Projection|Sequence|History'`.
|
||||||
|
|
||||||
|
Status: **complete** (E04). Prior completed commits include `3a1b6ff`,
|
||||||
|
`d172a5e`, and `1dd94a3`. Validation passed:
|
||||||
|
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -run 'Tier|Projection|Sequence|History' -count=1`,
|
||||||
|
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -count=1`,
|
||||||
|
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./... -count=1`,
|
||||||
|
and `git diff --check`.
|
||||||
|
|
||||||
## Stage 31 — Index Compound Identity Restoration
|
## Stage 31 — Index Compound Identity Restoration
|
||||||
|
|
||||||
Finding: **E05**.
|
Finding: **E05**.
|
||||||
|
|||||||
@@ -11,17 +11,18 @@ import (
|
|||||||
|
|
||||||
func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
||||||
policy := mustCompileSequenceIdentityPolicy(t, []sequenceIdentityRegistration{
|
policy := mustCompileSequenceIdentityPolicy(t, []sequenceIdentityRegistration{
|
||||||
{selector: sequenceIdentitySelector{literalSequenceSelector("records")}, identityFields: []string{"id"}},
|
{selector: sequenceIdentitySelector{
|
||||||
{selector: sequenceIdentitySelector{literalSequenceSelector("other")}, identityFields: []string{"id"}},
|
literalSequenceSelector("collections"), anyMappingSequenceSelector(), literalSequenceSelector("records"),
|
||||||
|
}, identityFields: []string{"id"}},
|
||||||
})
|
})
|
||||||
first := parseCompositionDocument(t, "source-1", "records: [{id: a, value: first}]\nother: [{id: x}]\n")
|
first := parseCompositionDocument(t, "source-1", "collections: {north: {records: [{id: a, value: first}]}, south: {records: [{id: x}]}}\n")
|
||||||
second := parseCompositionDocument(t, "source-2", "records: [{id: b, value: second}]\nother: [{id: y}]\n")
|
second := parseCompositionDocument(t, "source-2", "collections: {north: {records: [{id: b, value: second}]}, south: {records: [{id: y}]}}\n")
|
||||||
composed, diagnostics := composeDocumentsWithPolicy(policy, first, second)
|
composed, diagnostics := composeDocumentsWithPolicy(policy, first, second)
|
||||||
if len(diagnostics) != 0 {
|
if len(diagnostics) != 0 {
|
||||||
t.Fatalf("compose diagnostics = %#v", diagnostics)
|
t.Fatalf("compose diagnostics = %#v", diagnostics)
|
||||||
}
|
}
|
||||||
for applicationIndex, application := range composed.applications {
|
for applicationIndex, application := range composed.applications {
|
||||||
for path, want := range map[string]int{"/records": 1, "/other": 1} {
|
for path, want := range map[string]int{"/collections/north/records": 1, "/collections/south/records": 1} {
|
||||||
sequence, present := documentAtPath(application.value, mustParsePath(t, path))
|
sequence, present := documentAtPath(application.value, mustParsePath(t, path))
|
||||||
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != want {
|
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != want {
|
||||||
t.Errorf("application %d retained %s = %#v, %v; want one source fragment item", applicationIndex, path, sequence, present)
|
t.Errorf("application %d retained %s = %#v, %v; want one source fragment item", applicationIndex, path, sequence, present)
|
||||||
@@ -29,14 +30,14 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
working := parseCompositionDocument(t, "defaults", "records: [{id: default}]\nother: [{id: default}]\n")
|
working := parseCompositionDocument(t, "defaults", "collections: {north: {records: [{id: default}]}, south: {records: [{id: default}]}}\n")
|
||||||
index := new(mappingIndex)
|
index := new(mappingIndex)
|
||||||
for _, application := range composed.applications {
|
for _, application := range composed.applications {
|
||||||
applyHistoryApplication(&working, application, index)
|
applyHistoryApplication(&working, application, index)
|
||||||
}
|
}
|
||||||
for path, want := range map[string][]string{
|
for path, want := range map[string][]string{
|
||||||
"/records": {"a", "b"},
|
"/collections/north/records": {"a", "b"},
|
||||||
"/other": {"x", "y"},
|
"/collections/south/records": {"x", "y"},
|
||||||
} {
|
} {
|
||||||
sequence, present := documentAtPath(working, mustParsePath(t, path))
|
sequence, present := documentAtPath(working, mustParsePath(t, path))
|
||||||
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != len(want) {
|
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != len(want) {
|
||||||
@@ -53,14 +54,14 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
|||||||
application := composed.applications[1]
|
application := composed.applications[1]
|
||||||
cloned := cloneHistoryApplications(composed.applications)
|
cloned := cloneHistoryApplications(composed.applications)
|
||||||
cloned[1].sequences[0].path.segments[0].key = "mutated"
|
cloned[1].sequences[0].path.segments[0].key = "mutated"
|
||||||
if composed.applications[1].sequences[0].path.String() != "/records" {
|
if composed.applications[1].sequences[0].path.String() != "/collections/north/records" {
|
||||||
t.Fatal("cloned sequence history path aliases its source")
|
t.Fatal("cloned sequence history path aliases its source")
|
||||||
}
|
}
|
||||||
addedPath := Keys("records").Index(1).Key("value")
|
addedPath := Keys("collections", "north", "records").Index(1).Key("value")
|
||||||
if operation, relevant := applicationOperationPath(application, addedPath, nil); !relevant || operation.String() != addedPath.String() {
|
if operation, relevant := applicationOperationPath(application, addedPath, nil); !relevant || operation.String() != addedPath.String() {
|
||||||
t.Fatalf("appended value operation = %s, %v", operation.String(), relevant)
|
t.Fatalf("appended value operation = %s, %v", operation.String(), relevant)
|
||||||
}
|
}
|
||||||
if _, relevant := applicationOperationPath(application, Keys("records").Index(0).Key("value"), nil); relevant {
|
if _, relevant := applicationOperationPath(application, Keys("collections", "north", "records").Index(0).Key("value"), nil); relevant {
|
||||||
t.Fatal("later contribution was reported as changing an earlier record")
|
t.Fatal("later contribution was reported as changing an earlier record")
|
||||||
}
|
}
|
||||||
origin := historyApplicationOrigin(application, addedPath, nil)
|
origin := historyApplicationOrigin(application, addedPath, nil)
|
||||||
@@ -69,10 +70,10 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
overlay := historyApplication{
|
overlay := historyApplication{
|
||||||
layer: LayerOverlay,
|
layer: LayerOverlay,
|
||||||
value: parseCompositionDocument(t, "overlay", "records: []\n"),
|
value: parseCompositionDocument(t, "overlay", "collections: {north: {records: []}}\n"),
|
||||||
}
|
}
|
||||||
applyHistoryApplication(&working, overlay, index)
|
applyHistoryApplication(&working, overlay, index)
|
||||||
replaced, present := documentAtPath(working, Keys("records"))
|
replaced, present := documentAtPath(working, Keys("collections", "north", "records"))
|
||||||
if !present || replaced.Kind != document.Sequence || len(replaced.Sequence) != 0 {
|
if !present || replaced.Kind != document.Sequence || len(replaced.Sequence) != 0 {
|
||||||
t.Fatalf("ordinary later list replacement = %#v, %v", replaced, present)
|
t.Fatalf("ordinary later list replacement = %#v, %v", replaced, present)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func projectTierHistoryApplications(applications []historyApplication, operation
|
|||||||
projected := cloneHistoryApplications(applications)
|
projected := cloneHistoryApplications(applications)
|
||||||
for index, original := range applications {
|
for index, original := range applications {
|
||||||
application := &projected[index]
|
application := &projected[index]
|
||||||
|
var originalLookup *documentLookup
|
||||||
if path, found := projectSequenceOperationPath(original.path, projections); found {
|
if path, found := projectSequenceOperationPath(original.path, projections); found {
|
||||||
application.path = path
|
application.path = path
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,10 @@ func projectTierHistoryApplications(applications []historyApplication, operation
|
|||||||
if !active || operation.mode != sequenceHistoryMapped {
|
if !active || operation.mode != sequenceHistoryMapped {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
value, found := documentAtPath(original.value, source.path)
|
if originalLookup == nil {
|
||||||
|
originalLookup = buildDocumentLookup(original.value)
|
||||||
|
}
|
||||||
|
value, found := documentAtPathWithLookup(original.value, source.path, originalLookup)
|
||||||
if !found || value.Kind != document.Sequence {
|
if !found || value.Kind != document.Sequence {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user