broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,len(text)])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,0])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text+e[1]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=1; cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]-1); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor][::-1]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=min(cursor,len(text))
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=0
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]+1); cue=['remove',text[cursor+1:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=[max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))]
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=0,len(text)
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a+len(e[3])
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=a
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    text=''; cursor=0; history=[]; silent=False; out=[]
    for e in events:
        op=e[0]
        if op=='move': cursor=max(0,min(len(text),e[1]))
        elif op=='silent': silent=e[1]
        elif op=='undo' and history:
            text,cursor=history.pop()
            if not silent: out.append(['undo',text])
        elif op in ('insert','backspace','delete','replace'):
            history.append([text,cursor])
            if op=='insert':
                text=text[:cursor]+e[1]+text[cursor:]; cursor+=len(e[1]); cue=['insert',e[1]]
            elif op=='backspace':
                start=max(0,cursor-e[1]); cue=['remove',text[start:cursor]]
                text=text[:start]+text[cursor:]; cursor=start
            elif op=='delete':
                end=min(len(text),cursor+e[1]); cue=['remove',text[cursor:end]]
                text=text[:cursor]+text[end:]
            else:
                a,b=sorted([max(0,min(len(text),e[1])),max(0,min(len(text),e[2]))])
                cue=['replace',text[a:b],e[3]]; text=text[:a]+e[3]+text[b:]; cursor=b
            if not silent: out.append(cue)
    return [out,text,cursor]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['insert','abcd'*N],['move',2],['insert','XY'],['backspace',2],['undo'],['undo']]", "[['insert','abcdef'*N],['move',4],['backspace',2]]", "[['insert','abcdef'*N],['move',2],['delete',2]]", "[['insert','abcdef'*N],['replace',5,2,'Z']]", "[['insert','abcdef'*N],['replace',5,2,'Z'],['undo']]", "[['silent',True],['insert','secret'*N],['silent',False],['move',99],['insert','!']]", "[['insert','x'*N],['move',-5],['backspace',4],['delete',99],['undo']]", '[]']
expected = {1: [[[['insert', 'abcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcd'], ['undo', 'abcd']], 'abcd', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['remove', 'cd']], 'abef', 2], [[['insert', 'abcdef'], ['replace', 'cde', 'Z']], 'abZf', 3], [[['insert', 'abcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdef']], 'abcdef', 6], [[['insert', '!']], 'secret!', 7], [[['insert', 'x'], ['remove', ''], ['remove', 'x'], ['undo', 'x']], 'x', 0], [[], '', 0]], 2: [[[['insert', 'abcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcd'], ['undo', 'abcdabcd']], 'abcdabcd', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['remove', 'cd']], 'abefabcdef', 2], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdef', 3], [[['insert', 'abcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdef']], 'abcdefabcdef', 12], [[['insert', '!']], 'secretsecret!', 13], [[['insert', 'xx'], ['remove', ''], ['remove', 'xx'], ['undo', 'xx']], 'xx', 0], [[], '', 0]], 3: [[[['insert', 'abcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcd'], ['undo', 'abcdabcdabcd']], 'abcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdef']], 'abcdefabcdefabcdef', 18], [[['insert', '!']], 'secretsecretsecret!', 19], [[['insert', 'xxx'], ['remove', ''], ['remove', 'xxx'], ['undo', 'xxx']], 'xxx', 0], [[], '', 0]], 4: [[[['insert', 'abcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcd']], 'abcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdef', 24], [[['insert', '!']], 'secretsecretsecretsecret!', 25], [[['insert', 'xxxx'], ['remove', ''], ['remove', 'xxxx'], ['undo', 'xxxx']], 'xxxx', 0], [[], '', 0]], 5: [[[['insert', 'abcdabcdabcdabcdabcd'], ['insert', 'XY'], ['remove', 'XY'], ['undo', 'abXYcdabcdabcdabcdabcd'], ['undo', 'abcdabcdabcdabcdabcd']], 'abcdabcdabcdabcdabcd', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['remove', 'cd']], 'abefabcdefabcdefabcdefabcdef', 2], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z']], 'abZfabcdefabcdefabcdefabcdef', 3], [[['insert', 'abcdefabcdefabcdefabcdefabcdef'], ['replace', 'cde', 'Z'], ['undo', 'abcdefabcdefabcdefabcdefabcdef']], 'abcdefabcdefabcdefabcdefabcdef', 30], [[['insert', '!']], 'secretsecretsecretsecretsecret!', 31], [[['insert', 'xxxxx'], ['remove', ''], ['remove', 'xxxxx'], ['undo', 'xxxxx']], 'xxxxx', 0], [[], '', 0]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated edit-narration contract.

Document announcement state stores text and a cursor. Insert inserts at clamped cursor and announces inserted span. Backspace removes up to count before cursor and announces removed span in original order. Delete removes after cursor without moving it. Move clamps cursor. Replace range uses sorted clamped endpoints, announces old/new, moves cursor to replacement end. Undo restores text and cursor from last mutating edit and announces restored text. Silent toggles suppress cues but not state or undo. Return cues,text,cursor.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    budget=10; q=[]; out=[]
    for e in events:
        if e[0]=='budget': budget=e[1]
        elif e[0]=='phrase':
            if e[1]: q.append([e[2],e[1]])
        elif e[0]=='break': q.append(None)
        elif e[0]=='cancel': q=[x for x in q if x is None or x[0]!=e[1]]
        elif e[0]=='flush':
            current=None
            for row in q:
                if row is None:
                    if current is not None: out.append(current); current=None
                    continue
                if current is not None and current[0]==row[0] and len(current[1])+1+len(row[1])<=budget:
                    current[1]+=' '+row[1]
                else:
                    if current is not None: out.append(current)
                    current=list(row)
            if current is not None: out.append(current)
            q.clear()
    return [out,len(q),budget]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['budget',2*N+1],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['phrase','c','en'],['flush']]", "[['budget',2*N],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['flush']]", "[['budget',100],['phrase','hello'*N,'en-US'],['phrase','hi','en-GB'],['break'],['phrase','x','en-GB'],['flush']]", "[['phrase','a','en'],['break'],['phrase','b','en'],['phrase','non','fr'],['cancel','fr'],['flush']]", "[['budget',1],['phrase','oversize'*N,'en'],['flush']]", "[['budget',0],['phrase','','en'],['phrase','  ','en'],['flush']]", "[['flush'],['break'],['flush']]"]
expected = {1: [[[['en', 'a b'], ['en', 'c']], 0, 3], [[['en', 'a'], ['en', 'b']], 0, 2], [[['en-US', 'hello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 2: [[[['en', 'aa bb'], ['en', 'c']], 0, 5], [[['en', 'aa'], ['en', 'bb']], 0, 4], [[['en-US', 'hellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 3: [[[['en', 'aaa bbb'], ['en', 'c']], 0, 7], [[['en', 'aaa'], ['en', 'bbb']], 0, 6], [[['en-US', 'hellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 4: [[[['en', 'aaaa bbbb'], ['en', 'c']], 0, 9], [[['en', 'aaaa'], ['en', 'bbbb']], 0, 8], [[['en-US', 'hellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 5: [[[['en', 'aaaaa bbbbb'], ['en', 'c']], 0, 11], [[['en', 'aaaaa'], ['en', 'bbbbb']], 0, 10], [[['en-US', 'hellohellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    budget=10; q=[]; out=[]
    for e in events:
        if e[0]=='budget': budget=max(2,e[1])
        elif e[0]=='phrase':
            if e[1]: q.append([e[2],e[1]])
        elif e[0]=='break': q.append(None)
        elif e[0]=='cancel': q=[x for x in q if x is None or x[0]!=e[1]]
        elif e[0]=='flush':
            current=None
            for row in q:
                if row is None:
                    if current is not None: out.append(current); current=None
                    continue
                if current is not None and current[0]==row[0] and len(current[1])+1+len(row[1])<=budget:
                    current[1]+=' '+row[1]
                else:
                    if current is not None: out.append(current)
                    current=list(row)
            if current is not None: out.append(current)
            q.clear()
    return [out,len(q),budget]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['budget',2*N+1],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['phrase','c','en'],['flush']]", "[['budget',2*N],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['flush']]", "[['budget',100],['phrase','hello'*N,'en-US'],['phrase','hi','en-GB'],['break'],['phrase','x','en-GB'],['flush']]", "[['phrase','a','en'],['break'],['phrase','b','en'],['phrase','non','fr'],['cancel','fr'],['flush']]", "[['budget',1],['phrase','oversize'*N,'en'],['flush']]", "[['budget',0],['phrase','','en'],['phrase','  ','en'],['flush']]", "[['flush'],['break'],['flush']]"]
expected = {1: [[[['en', 'a b'], ['en', 'c']], 0, 3], [[['en', 'a'], ['en', 'b']], 0, 2], [[['en-US', 'hello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 2: [[[['en', 'aa bb'], ['en', 'c']], 0, 5], [[['en', 'aa'], ['en', 'bb']], 0, 4], [[['en-US', 'hellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 3: [[[['en', 'aaa bbb'], ['en', 'c']], 0, 7], [[['en', 'aaa'], ['en', 'bbb']], 0, 6], [[['en-US', 'hellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 4: [[[['en', 'aaaa bbbb'], ['en', 'c']], 0, 9], [[['en', 'aaaa'], ['en', 'bbbb']], 0, 8], [[['en-US', 'hellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 5: [[[['en', 'aaaaa bbbbb'], ['en', 'c']], 0, 11], [[['en', 'aaaaa'], ['en', 'bbbbb']], 0, 10], [[['en-US', 'hellohellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated sentence-packing contract.

Input operations configure character budget then append indivisible phrases [text,language]. Flush packs consecutive same-language phrases with one space while within budget. A phrase longer than budget is emitted alone intact. Language change always starts a new packet. Empty phrases are ignored. Break inserts hard boundary. Cancel removes queued phrases of one language. Returned packets are [language,text], queued phrase count and budget; flush consumes pending phrases.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    budget=10; q=[]; out=[]
    for e in events:
        if e[0]=='budget': budget=max(1,e[1])
        elif e[0]=='phrase':
            q.append([e[2],e[1]])
        elif e[0]=='break': q.append(None)
        elif e[0]=='cancel': q=[x for x in q if x is None or x[0]!=e[1]]
        elif e[0]=='flush':
            current=None
            for row in q:
                if row is None:
                    if current is not None: out.append(current); current=None
                    continue
                if current is not None and current[0]==row[0] and len(current[1])+1+len(row[1])<=budget:
                    current[1]+=' '+row[1]
                else:
                    if current is not None: out.append(current)
                    current=list(row)
            if current is not None: out.append(current)
            q.clear()
    return [out,len(q),budget]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['budget',2*N+1],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['phrase','c','en'],['flush']]", "[['budget',2*N],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['flush']]", "[['budget',100],['phrase','hello'*N,'en-US'],['phrase','hi','en-GB'],['break'],['phrase','x','en-GB'],['flush']]", "[['phrase','a','en'],['break'],['phrase','b','en'],['phrase','non','fr'],['cancel','fr'],['flush']]", "[['budget',1],['phrase','oversize'*N,'en'],['flush']]", "[['budget',0],['phrase','','en'],['phrase','  ','en'],['flush']]", "[['flush'],['break'],['flush']]"]
expected = {1: [[[['en', 'a b'], ['en', 'c']], 0, 3], [[['en', 'a'], ['en', 'b']], 0, 2], [[['en-US', 'hello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 2: [[[['en', 'aa bb'], ['en', 'c']], 0, 5], [[['en', 'aa'], ['en', 'bb']], 0, 4], [[['en-US', 'hellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 3: [[[['en', 'aaa bbb'], ['en', 'c']], 0, 7], [[['en', 'aaa'], ['en', 'bbb']], 0, 6], [[['en-US', 'hellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 4: [[[['en', 'aaaa bbbb'], ['en', 'c']], 0, 9], [[['en', 'aaaa'], ['en', 'bbbb']], 0, 8], [[['en-US', 'hellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 5: [[[['en', 'aaaaa bbbbb'], ['en', 'c']], 0, 11], [[['en', 'aaaaa'], ['en', 'bbbbb']], 0, 10], [[['en-US', 'hellohellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events):
    budget=10; q=[]; out=[]
    for e in events:
        if e[0]=='budget': budget=max(1,e[1])
        elif e[0]=='phrase':
            if e[1].strip(): q.append([e[2],e[1].strip()])
        elif e[0]=='break': q.append(None)
        elif e[0]=='cancel': q=[x for x in q if x is None or x[0]!=e[1]]
        elif e[0]=='flush':
            current=None
            for row in q:
                if row is None:
                    if current is not None: out.append(current); current=None
                    continue
                if current is not None and current[0]==row[0] and len(current[1])+1+len(row[1])<=budget:
                    current[1]+=' '+row[1]
                else:
                    if current is not None: out.append(current)
                    current=list(row)
            if current is not None: out.append(current)
            q.clear()
    return [out,len(q),budget]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = ["[['budget',2*N+1],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['phrase','c','en'],['flush']]", "[['budget',2*N],['phrase','a'*N,'en'],['phrase','b'*N,'en'],['flush']]", "[['budget',100],['phrase','hello'*N,'en-US'],['phrase','hi','en-GB'],['break'],['phrase','x','en-GB'],['flush']]", "[['phrase','a','en'],['break'],['phrase','b','en'],['phrase','non','fr'],['cancel','fr'],['flush']]", "[['budget',1],['phrase','oversize'*N,'en'],['flush']]", "[['budget',0],['phrase','','en'],['phrase','  ','en'],['flush']]", "[['flush'],['break'],['flush']]"]
expected = {1: [[[['en', 'a b'], ['en', 'c']], 0, 3], [[['en', 'a'], ['en', 'b']], 0, 2], [[['en-US', 'hello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 2: [[[['en', 'aa bb'], ['en', 'c']], 0, 5], [[['en', 'aa'], ['en', 'bb']], 0, 4], [[['en-US', 'hellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 3: [[[['en', 'aaa bbb'], ['en', 'c']], 0, 7], [[['en', 'aaa'], ['en', 'bbb']], 0, 6], [[['en-US', 'hellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 4: [[[['en', 'aaaa bbbb'], ['en', 'c']], 0, 9], [[['en', 'aaaa'], ['en', 'bbbb']], 0, 8], [[['en-US', 'hellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]], 5: [[[['en', 'aaaaa bbbbb'], ['en', 'c']], 0, 11], [[['en', 'aaaaa'], ['en', 'bbbbb']], 0, 10], [[['en-US', 'hellohellohellohellohello'], ['en-GB', 'hi'], ['en-GB', 'x']], 0, 100], [[['en', 'a'], ['en', 'b']], 0, 10], [[['en', 'oversizeoversizeoversizeoversizeoversize']], 0, 1], [[['en', '  ']], 0, 1], [[], 0, 10]]}[N]
for i, expression in enumerate(fixtures):
    check("trace-"+str(i+1), solve(eval(expression)), expected[i])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The announcement trace violates the stated sentence-packing contract.

Input operations configure character budget then append indivisible phrases [text,language]. Flush packs consecutive same-language phrases with one space while within budget. A phrase longer than budget is emitted alone intact. Language change always starts a new packet. Empty phrases are ignored. Break inserts hard boundary. Cancel removes queued phrases of one language. Returned packets are [language,text], queued phrase count and budget; flush consumes pending phrases.

split: open-access