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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%2
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=min(state+1,2)
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the latch cycle rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches["modifier"]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the latch key rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.clear()
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches[key]=0
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the unlock removal rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical={key}
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.symmetric_difference_update({key})
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the physical down rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.clear()
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.add(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the physical up rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical & set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the effective union rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,list(reversed(sorted(effective)))])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(physical)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the modifier order rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==1}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v!=0}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the once consumption rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': physical.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear(); physical.clear()
            elif kind=='blur':
                latches.clear(); physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the cancel scope rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                latches.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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(cases):
    def run(c):
        latches={}; physical=set(); out=[]
        for kind,key in c:
            if kind=='tap':
                state=latches.get(key,0)
                next_state=(state+1)%3
                if next_state: latches[key]=next_state
                else: latches.pop(key,None)
            elif kind=='down': physical.add(key)
            elif kind=='up': physical.discard(key)
            elif kind=='char':
                effective=physical | set(latches)
                out.append([key,sorted(effective)])
                latches={k:v for k,v in latches.items() if v==2}
            elif kind=='cancel': latches.clear()
            elif kind=='blur':
                physical.clear()
        return [out,sorted([[k,v] for k,v in latches.items()]),sorted(physical)]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('sticky-modifiers scenario 0', solve([[]] * N), [[[], [], []]] * N)
check('sticky-modifiers scenario 1', solve([[['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', []]], [], []]] * N)
check('sticky-modifiers scenario 2', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['char', 'A'], ['char', 'B']]] * N), [[[['A', ['Shift']], ['B', ['Shift']]], [['Shift', 2]], []]] * N)
check('sticky-modifiers scenario 3', solve([[['tap', 'Shift'], ['tap', 'Shift'], ['tap', 'Alt'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Alt']]], [], []]] * N)
check('sticky-modifiers scenario 4', solve([[['down', 'Control'], ['down', 'Alt'], ['down', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Alt', 'Control']]], [], ['Alt', 'Control']]] * N)
check('sticky-modifiers scenario 5', solve([[['down', 'Control'], ['down', 'Alt'], ['up', 'Alt'], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 6', solve([[['down', 'Control'], ['tap', 'Shift'], ['char', 'A']]] * N), [[[['A', ['Control', 'Shift']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 7', solve([[['down', 'Control'], ['tap', 'Shift'], ['cancel', ''], ['char', 'A']]] * N), [[[['A', ['Control']]], [], ['Control']]] * N)
check('sticky-modifiers scenario 8', solve([[['down', 'Control'], ['tap', 'Shift'], ['blur', '']]] * N), [[[], [], []]] * N)
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 event trace violates the blur reset rule and produces incorrect keyboard state or command output.

Events [kind,key]. Tap of modifier cycles absent -> once -> locked -> absent. Modifier down/up sets physical state independently. Character emits [key,sorted effective modifiers] then consumes all once latches but preserves locked and physical modifiers. Cancel clears latches only; blur clears both. Return emitted events, latches and physical state. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and not cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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 event trace violates the keydown cancelable rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly and not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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 event trace violates the readonly gate rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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 event trace violates the insertion kind rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace': lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,hi-2)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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 event trace violates the backspace selection rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access


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

N = 1
observations = []
def solve(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete': hi=min(len(text),hi+1)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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(cases):
    def run(c):
        text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly=c
        log=['keydown']; original=[text,lo,hi]
        if prevent_down and cancelable:
            return original+[log+['keyup']]
        if readonly or not (len(key)==1 or key in ('Backspace','Delete')):
            return original+[log+['keyup']]
        insert=key if len(key)==1 else ''
        if key=='Backspace' and lo==hi: lo=max(0,lo-1)
        elif key=='Delete' and lo==hi: hi=min(len(text),hi+2)
        changed=text[:lo]+insert+text[hi:]
        if changed==text:
            return original+[log+['keyup']]
        log.append('beforeinput')
        if prevent_before:
            return original+[log+['keyup']]
        text=changed
        hi=lo+len(insert); lo=hi
        log.append('input')
        return [text,lo,hi,log+['keyup']]
    return [run(c) for c in cases]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('key-default-edit scenario 0', solve([['abc', 1, 1, 'X', False, False, True, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 1', solve([['abc', 1, 2, 'XY', False, False, True, False]] * N), [['abc', 1, 2, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 2', solve([['abcd', 1, 3, 'Z', False, False, True, False]] * N), [['aZd', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 3', solve([['abcd', 1, 3, 'Backspace', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 4', solve([['abcd', 1, 3, 'Delete', False, False, True, False]] * N), [['ad', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 5', solve([['abcd', 2, 2, 'Backspace', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 6', solve([['abcd', 1, 1, 'Delete', False, False, True, False]] * N), [['acd', 1, 1, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 7', solve([['abc', 0, 0, 'Backspace', False, False, True, False]] * N), [['abc', 0, 0, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 8', solve([['abc', 0, 3, 'Delete', False, False, True, False]] * N), [['', 0, 0, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 9', solve([['abc', 1, 1, 'X', True, False, False, False]] * N), [['aXbc', 2, 2, ['keydown', 'beforeinput', 'input', 'keyup']]] * N)
check('key-default-edit scenario 10', solve([['abc', 1, 1, 'X', True, False, True, False]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
check('key-default-edit scenario 11', solve([['abc', 1, 1, 'X', False, True, False, False]] * N), [['abc', 1, 1, ['keydown', 'beforeinput', 'keyup']]] * N)
check('key-default-edit scenario 12', solve([['abc', 1, 1, 'X', False, False, True, True]] * N), [['abc', 1, 1, ['keydown', 'keyup']]] * N)
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 event trace violates the delete selection rule and produces incorrect keyboard state or command output.

Case [text,lo,hi,key,prevent_down,prevent_before,cancelable,readonly]. Selection is a valid half-open code-point interval. Printable single characters replace selection, Backspace deletes previous point and Delete deletes next point for collapsed selections. Other keys do not edit. A cancelable prevented keydown stops editing; readonly suppresses beforeinput. A changed candidate fires beforeinput, cancellation suppresses mutation; successful edit fires input. Always log keydown and keyup. Return text, selection endpoints and event log. Inputs are finite ordered event traces; return the stated deterministic state. Batch entries are independent. N varies the number of independent input transactions.

split: open-access