+64
-36
@@ -104,6 +104,13 @@ type
|
||||
anchor: (int, int)
|
||||
sig: string
|
||||
|
||||
MarkerSeen = object
|
||||
## One marker id the subject was sent, resolved to the GM-truth wall it belongs to. Keying by
|
||||
## wall (not by anchor) is what keeps two candidate walls that share a midpoint distinct. A
|
||||
## `wall` of -1 means no candidate wall stands at that anchor (an extra marker).
|
||||
wall: int
|
||||
pos: (int, int)
|
||||
|
||||
Group = object
|
||||
label: string
|
||||
gmMsgs: seq[JsonNode]
|
||||
@@ -466,7 +473,7 @@ proc main() =
|
||||
var encounterable: HashSet[string] # token ids the subject may have met (independent oracle)
|
||||
var viewCharacters: HashSet[string] # character ids the subject was sent
|
||||
var prevController: Table[string, int] # controller of each token at the previous group
|
||||
var markers: Table[string, (int, int)] # marker id -> anchor, what the subject was sent
|
||||
var markers: Table[string, MarkerSeen] # marker id -> the GM-truth wall it was minted for
|
||||
var expectedMarkers: Table[int, ExpectedMarker] # wall id -> accumulated memory (#59/#60)
|
||||
var markerPositive = false # the scenario exercised the oracle at least once
|
||||
|
||||
@@ -775,9 +782,43 @@ proc main() =
|
||||
if m["full"].getBool: markers.clear()
|
||||
for e in m["set"]:
|
||||
let id = e["id"].getStr
|
||||
let pos = (e["pos"][0].getInt, e["pos"][1].getInt)
|
||||
if markers.hasKey(id):
|
||||
fail "PROTOCOL", "duplicate marker id " & id & " (group " & g.label & ")"
|
||||
markers[id] = (e["pos"][0].getInt, e["pos"][1].getInt)
|
||||
continue
|
||||
# Resolve the id to a GM-truth wall by anchor. Prefer the wall the oracle expects and
|
||||
# that has no id yet, so two candidates sharing a midpoint each get their own id; then
|
||||
# any free candidate; then the marker is extra (or a re-mint, below).
|
||||
var cand: seq[int]
|
||||
for mw in truth.markerWalls:
|
||||
if anchorOf(mw) == pos: cand.add mw.id
|
||||
var pick = -1
|
||||
for c in cand:
|
||||
var used = false
|
||||
for _, seen in markers:
|
||||
if seen.wall == c: used = true
|
||||
if not used and expectedMarkers.hasKey(c):
|
||||
pick = c
|
||||
break
|
||||
if pick < 0:
|
||||
for c in cand:
|
||||
var used = false
|
||||
for _, seen in markers:
|
||||
if seen.wall == c: used = true
|
||||
if not used:
|
||||
pick = c
|
||||
break
|
||||
if pick < 0 and cand.len == 1 and expectedMarkers.hasKey(cand[0]):
|
||||
# The one wall this anchor belongs to already has a live id: the marker was re-minted
|
||||
# without the old one dying. A marker id is minted once and stable across refreshes
|
||||
# (5.8); only a re-earn after a retraction gets a fresh one. This is a protocol break,
|
||||
# not one of the four marker fault classes (documented in TESTING 10.3).
|
||||
fail "PROTOCOL", "marker for wall " & $cand[0] & " re-minted as " & id &
|
||||
" while its old id is still live (group " & g.label & ")"
|
||||
if pick < 0:
|
||||
markers[id] = MarkerSeen(wall: -1, pos: pos) # extra: no free candidate at anchor
|
||||
else:
|
||||
markers[id] = MarkerSeen(wall: pick, pos: pos)
|
||||
if m.hasKey("del"):
|
||||
for d in m["del"]:
|
||||
let id = d.getStr
|
||||
@@ -802,42 +843,29 @@ proc main() =
|
||||
if expectedMarkers.hasKey(mw.id): continue
|
||||
if extentSeen(polysChecks, mw.a, mw.b):
|
||||
expectedMarkers[mw.id] = ExpectedMarker(anchor: anchorOf(mw), sig: markerSig(mw))
|
||||
var wantPos: seq[(int, int)]
|
||||
for _, em in expectedMarkers: wantPos.add em.anchor
|
||||
var gotPos: seq[(int, int)]
|
||||
for _, pos in markers: gotPos.add pos
|
||||
wantPos.sort()
|
||||
gotPos.sort()
|
||||
# Multiset difference: `missing` markers the memory expects, `extra` ones it does not. An
|
||||
# extra at a marker candidate's anchor was sent before its extent was seen (EARLY); an extra
|
||||
# with no candidate wall at all must never exist (EXTRA).
|
||||
var missingMarkers, extraMarkers: seq[(int, int)]
|
||||
var wi = 0
|
||||
var gi = 0
|
||||
while wi < wantPos.len or gi < gotPos.len:
|
||||
if wi >= wantPos.len:
|
||||
extraMarkers.add gotPos[gi]; inc gi
|
||||
elif gi >= gotPos.len:
|
||||
missingMarkers.add wantPos[wi]; inc wi
|
||||
elif wantPos[wi] == gotPos[gi]:
|
||||
inc wi; inc gi
|
||||
elif wantPos[wi] < gotPos[gi]:
|
||||
missingMarkers.add wantPos[wi]; inc wi
|
||||
else:
|
||||
extraMarkers.add gotPos[gi]; inc gi
|
||||
if missingMarkers.len > 0:
|
||||
fail "MARKER_OFF", "marker " & $missingMarkers[0] & " was never sent (" &
|
||||
$missingMarkers.len & " missing; group " & g.label & ")"
|
||||
var candidateAnchors: seq[(int, int)]
|
||||
for mw in truth.markerWalls: candidateAnchors.add anchorOf(mw)
|
||||
for pos in extraMarkers:
|
||||
if pos in candidateAnchors:
|
||||
fail "MARKER_EARLY", "marker " & $pos & " sent before its wall was seen (group " &
|
||||
var owned: HashSet[int]
|
||||
for _, seen in markers:
|
||||
if seen.wall >= 0: owned.incl seen.wall
|
||||
# Keyed by wall, not by anchor: two candidate walls sharing a midpoint stay two obligations,
|
||||
# and an id's stability is its wall's ownership (a re-mint is caught when the set arrives).
|
||||
var missingWalls: seq[int]
|
||||
for wallId in expectedMarkers.keys:
|
||||
if wallId notin owned: missingWalls.add wallId
|
||||
if missingWalls.len > 0:
|
||||
missingWalls.sort()
|
||||
fail "MARKER_OFF", "marker for wall " & $missingWalls[0] & " was never sent (" &
|
||||
$missingWalls.len & " missing; group " & g.label & ")"
|
||||
for _, seen in markers:
|
||||
if seen.wall < 0:
|
||||
fail "MARKER_EXTRA", "marker " & $seen.pos & " has no marker candidate wall (group " &
|
||||
g.label & ")"
|
||||
else:
|
||||
fail "MARKER_EXTRA", "marker " & $pos & " has no marker candidate wall (group " &
|
||||
elif not expectedMarkers.hasKey(seen.wall):
|
||||
# It maps to a current candidate wall the oracle does not expect: sent before that wall's
|
||||
# extent was seen (MARKER_EARLY), or a cause change whose del never arrived. It is a marker
|
||||
# at a candidate's anchor either way, which is the class TESTING 10.3 defines.
|
||||
fail "MARKER_EARLY", "marker " & $seen.pos & " sent before its wall was seen (group " &
|
||||
g.label & ")"
|
||||
if wantPos.len > 0:
|
||||
if expectedMarkers.len > 0:
|
||||
markerPositive = true
|
||||
|
||||
# --- CONTROLLER_CHANGE (10.3) ----------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user