amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:43:15 +08:00

368 lines
19 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Private map/tuple oracle. Candidate execution produces observations only."""
import base64
import copy
import json
from pathlib import Path
import random
import re
import subprocess
import sys
import tempfile
CANDIDATES = ['priority_syntax.cpp', 'registry_compile.cpp', 'registry_project.cpp', 'registry_replay.cpp']
def valid_id(text):
return 1 <= len(text) <= 32 and re.fullmatch(r'[A-Za-z0-9_-]+', text) is not None
def valid_path(text):
return (2 <= len(text) <= 128 and text.startswith('/') and
all(part not in ('', '.', '..') and re.fullmatch(r'[A-Za-z0-9_.+-]+', part)
for part in text[1:].split('/')))
def priority(text):
if not 1 <= len(text) <= 11 or re.fullmatch(r'[+-]?[0-9]+', text) is None:
return None
value = int(text)
return value if -2147483648 <= value <= 2147483647 else None
def canonical(raw):
if len(raw) > 64 or sum(len(g[5]) for g in raw) > 256 or sum(len(g[4]) for g in raw) > 256:
return None
names, links, output = set(), set(), []
for name, master, mode, pin, slots, candidates in copy.deepcopy(raw):
if not valid_id(name) or name in names or not valid_path(master) or master in links:
return None
names.add(name); links.add(master)
if len(slots) > 16 or len(candidates) > 64:
return None
slot_names = set()
for slot, link in slots:
if not valid_id(slot) or slot in slot_names or not valid_path(link) or link in links:
return None
slot_names.add(slot); links.add(link)
paths = set()
for path, rank, enabled, attachments in candidates:
if not valid_path(path) or path in paths or len(attachments) > 16:
return None
paths.add(path)
used = set()
for slot, target in attachments:
if not valid_id(slot) or slot not in slot_names or slot in used or not valid_path(target):
return None
used.add(slot)
attachments.sort()
if mode not in (0, 1) or (mode == 0 and pin != '') or (mode == 1 and pin not in paths):
return None
output.append([name, master, mode, pin, sorted(slots), sorted(candidates)])
return sorted(output)
def projection(world):
selections, bindings = [], []
for name, master, mode, pin, slots, candidates in world:
installed = {row[0]: row for row in candidates}
selected = installed.get(pin) if mode else next(iter(sorted(
(row for row in candidates if row[2]), key=lambda row: (-row[1], row[0]))), None)
if selected is not None and not selected[2]:
selected = None
selections.append([name, mode, pin, selected[0] if selected else ''])
bindings.append([master, selected[0] if selected else ''])
attachments = dict(selected[3]) if selected else {}
bindings.extend([link, attachments.get(slot, '')] for slot, link in slots)
return [selections, sorted(bindings)]
def transcript(initial, events):
if len(events) > 128:
return None
world, frames = copy.deepcopy(initial), []
for op, name, path, rank, enabled, attachments in events:
if op not in range(5) or not valid_id(name):
return None
if op == 0:
parsed = priority(rank)
if not valid_path(path) or parsed is None:
return None
elif rank or attachments or (op in (1, 2, 3) and enabled):
return None
elif (op == 3 and path) or (op != 3 and not valid_path(path)):
return None
by_name = {row[0]: row for row in world}
if name not in by_name:
return None
previous = dict(projection(world)[1])
group = by_name[name]
candidates = {row[0]: row for row in group[5]}
if op == 0:
candidates[path] = [path, parsed, enabled, copy.deepcopy(attachments)]
elif op == 1:
if path in candidates:
del candidates[path]
if group[2] == 1 and group[3] == path:
group[2:4] = [0, '']
elif op == 2:
if path not in candidates:
return None
group[2:4] = [1, path]
elif op == 3:
group[2:4] = [0, '']
else:
if path not in candidates:
return None
candidates[path][2] = enabled
group[5] = list(candidates.values())
world = canonical(list(by_name.values()))
if world is None:
return None
projected = projection(world)
delta = [[link, previous[link], target] for link, target in projected[1] if previous[link] != target]
frames.append([copy.deepcopy(world), projected, delta])
return [world, frames]
def hx(text):
return text.encode('latin1').hex() or '-'
class Cases:
def __init__(self):
self.commands, self.expected, self.labels = [], [], []
self.world, self.events, self.last = [], [], [[], []]
def add(self, wire, result, label):
self.commands.append(wire); self.expected.append(result); self.labels.append(label)
def config(self, raw, label='C08'):
self.add('R', 0, label)
for gi, (name, master, mode, pin, slots, candidates) in enumerate(raw):
self.add('G %s %s %d %s' % (hx(name), hx(master), mode, hx(pin)), 0, label)
for slot, link in slots:
self.add('S %d %s %s' % (gi, hx(slot), hx(link)), 0, label)
for ci, (path, rank, enabled, attachments) in enumerate(candidates):
self.add('C %d %s %d %d' % (gi, hx(path), rank, enabled), 0, label)
for slot, target in attachments:
self.add('T %d %d %s %s' % (gi, ci, hx(slot), hx(target)), 0, label)
compiled = canonical(raw)
self.world = compiled
self.add('W', [int(compiled is None), compiled or [], True], label)
return compiled is not None
def project(self, label='C09'):
self.add('P', [projection(self.world), True], label)
def replay(self, events, label='C20', commit=False):
self.add('X', 0, label)
self.events = copy.deepcopy(events)
for op, name, path, rank, enabled, attachments in events:
wire = 'E %d %s %s %s %d %d' % (op, hx(name), hx(path), hx(rank), enabled, len(attachments))
for slot, target in attachments:
wire += ' %s %s' % (hx(slot), hx(target))
self.add(wire, 0, label)
value = transcript(self.world, events)
self.last = value or [[], []]
self.add('F', [int(value is None), self.last, True], label)
self.add('J', [True, True], 'C22')
if commit and value is not None:
self.add('U', 0, label); self.world = copy.deepcopy(value[0])
return value is not None
def group(name='g', mode=0, pin='', candidates=None, slots=None):
return [name, '/alt/' + name, mode, pin,
slots if slots is not None else [['edit', '/alt/' + name + '_edit']],
candidates if candidates is not None else [['/bin/a', 20, True, [['edit', '/bin/editor']]], ['/bin/b', 10, True, []]]]
def event(op, name='g', path='', rank='', enabled=False, attachments=None):
return [op, name, path, rank, enabled, attachments or []]
def cases():
c = Cases()
for text in ['', 'a', 'a' * 32, 'a' * 33, 'a b', 'é', 'a\0', '_-9', '/', '//a', '/a/', '/a//b',
'/.', '/..', '/a/../b', '/a/./b', '/a.b/+x-y_z', '/a\\b', '/a\0b', '/a' + 'b' * 126,
'/a' + 'b' * 127, 'relative', '/9', '/É']:
c.add('I ' + hx(text), [valid_id(text), bool(valid_path(text)), True], 'C01' if not text.startswith('/') else 'C02')
for text in ['', '0', '-0', '+0', '-2147483648', '2147483647', '+2147483647', '-2147483649',
'2147483648', '+0000000000', '-0000000000', '00000000000', '000000000000',
'00000000001', '+00000000001', '-', '+', '--1', '+-1', ' 1', '1 ', '1e3',
'1.0', '1\0', '12', '9' * 100]:
# Non-Latin1 Unicode is supplied as its UTF-8 bytes: never an ASCII digit.
if any(ord(ch) > 255 for ch in text): text = text.encode().decode('latin1')
value = priority(text)
c.add('K ' + hx(text), [int(value is None), value or 0, True], 'C03')
c.config([]); c.project('C11'); c.replay([], 'C22'); c.project('C24')
for ranks in [[-2147483648], [-1, -1], [-100, -3, -20], [0, 2147483647, -2147483648]]:
raw = [group(candidates=[['/bin/p%d' % i, rank, True, []] for i, rank in enumerate(ranks)])]
c.config(raw); c.project('C09')
c.config([group('shell')]); c.project('C11')
c.replay([event(2, 'shell', '/bin/b')], 'C12')
c.config([group()]); c.project('C09')
c.replay([event(2, path='/bin/b'), event(4, path='/bin/b', enabled=False),
event(0, path='/bin/a', rank='2147483647', enabled=True), event(1, path='/bin/a'),
event(4, path='/bin/b', enabled=True), event(0, path='/bin/b', rank='-2147483648', enabled=False),
event(2, path='/bin/b'), event(1, path='/absent'), event(4, path='/bin/b', enabled=True),
event(3), event(1, path='/bin/b')], 'C10', commit=True)
c.project('C17')
c.config([group(mode=1, pin='/bin/a')])
c.replay([event(1, path='/bin/b')], 'C17')
c.replay([event(0, path='/bin/a', rank='-9', enabled=True), event(0, path='/bin/b', rank='99', enabled=True)], 'C16')
c.replay([event(4, path='/bin/a', enabled=False), event(1, path='/bin/b'), event(1, path='/bin/a')], 'C17')
c.replay([event(2, path='/bin/b'), event(2, path='/bin/b'), event(3), event(3), event(4, path='/bin/a', enabled=True)], 'C21')
c.replay([event(0, path='/bin/a', rank='20', enabled=True, attachments=[['edit', '/bin/new']]),
event(0, path='/bin/a', rank='20', enabled=True)], 'C15')
# Reordering and disjoint groups, including a shared candidate path.
raw = [group('z', slots=[['b', '/z/b'], ['a', '/z/a']]), group('a')]
raw[0][5] = [['/bin/a', 7, True, [['b', '/bin/b'], ['a', '/bin/a']]]]
c.config(raw); c.project('C08')
c.replay([event(2, 'z', '/bin/a'), event(4, 'a', '/bin/a', enabled=False), event(1, 'z', '/bin/a')], 'C25')
bad_worlds = []
def bad(change):
item = [group()]; change(item); bad_worlds.append(item)
bad(lambda r: r.append(copy.deepcopy(r[0])))
bad(lambda r: r[0].__setitem__(0, ''))
bad(lambda r: r[0].__setitem__(1, '/a//b'))
bad(lambda r: r[0].__setitem__(2, 5))
bad(lambda r: r[0].__setitem__(3, '/bin/a'))
bad(lambda r: r[0].__setitem__(2, 1))
bad(lambda r: r[0][4].append(copy.deepcopy(r[0][4][0])))
bad(lambda r: r[0][4].append(['other', r[0][1]]))
bad(lambda r: r[0][5].append(copy.deepcopy(r[0][5][0])))
bad(lambda r: r[0][5][1].__setitem__(0, '/bin/..'))
bad(lambda r: r[0][5][1][3].append(['unknown', '/good']))
bad(lambda r: r[0][5][0][3].append(['edit', '/repeat']))
bad(lambda r: r[0][5][1][3].append(['edit', '/bad/']))
for raw in bad_worlds: c.config(raw, 'C04')
other = group('h'); other[4][0][1] = '/alt/g'
c.config([group(), other], 'C05')
sleeping = group(mode=1, pin='/bin/a'); sleeping[5][0][2] = False
c.config([sleeping], 'C07'); c.project('C10')
c.replay([event(1, path='/bin/b'), event(4, path='/bin/a', enabled=True)], 'C19')
c.config([group()])
invalid = [event(8), event(3, 'missing'), event(3, path='/unused'), event(3, enabled=True),
event(1, path='/bin/a', rank='0'), event(2, path='/missing'), event(4, path='/missing'),
event(1, path='/bin/a', attachments=[['edit', '/target']]),
event(0, path='/new', rank='2147483648'), event(0, path='/new', rank='1', enabled=True, attachments=[['unknown', '/target']]),
event(0, path='/new', rank='1', enabled=False, attachments=[['edit', '/bad/']]),
event(2, path='/bin/a', enabled=True), event(4, path='/bin/a', rank='unused')]
for e in invalid:
c.replay([event(2, path='/bin/a'), e], 'C23')
c.replay([event(3)], 'C24')
c.replay([event(3)] * 128, 'C23'); c.replay([event(3)] * 129, 'C23')
# Exact capacities. A transient excess cannot be repaired by later remove.
full = group(candidates=[['/c/%d' % i, -i, bool(i % 2), []] for i in range(64)])
c.config([full], 'C04'); c.project('C09')
c.replay([event(0, path='/c/0', rank='0', enabled=True)], 'C15')
c.replay([event(0, path='/new', rank='1', enabled=True), event(1, path='/c/0')], 'C15')
c.replay([event(1, path='/c/0'), event(0, path='/new', rank='1', enabled=True)], 'C15')
over = copy.deepcopy(full); over[5].append(['/over', 0, True, []]); c.config([over], 'C04')
all_groups = [group('n%d' % i, candidates=[], slots=[]) for i in range(64)]
c.config(all_groups, 'C04'); c.project('C11'); c.config(all_groups + [group('extra')], 'C04')
all_groups = [group('n%d' % i, candidates=[['/c/%d' % j, j, True, []] for j in range(64)], slots=[]) for i in range(4)]
c.config(all_groups, 'C04'); c.project('C09')
c.replay([event(0, 'n0', '/new', '1', True)], 'C15')
# The group can still fit while the world total cannot.
global_full = copy.deepcopy(all_groups)
global_full[0][5].pop()
global_full.append(group('extra', candidates=[['/one', 0, True, []]], slots=[]))
c.config(global_full, 'C04')
c.replay([event(0, 'n0', '/new', '1', True), event(1, 'extra', '/one')], 'C15')
c.replay([event(1, 'extra', '/one'), event(0, 'n0', '/new', '1', True)], 'C15')
all_groups.append(group('extra', candidates=[['/new', 1, False, []]], slots=[])); c.config(all_groups, 'C04')
slots16 = [['s%d' % i, '/slots/%d' % i] for i in range(16)]
one = group(slots=slots16, candidates=[['/one', 1, True, [['s%d' % i, '/target/%d' % i] for i in range(16)]]])
c.config([one], 'C06'); c.project('C11')
one[4].append(['extra', '/slots/extra']); c.config([one], 'C04')
all_groups = [group('s%d' % i, candidates=[], slots=[['v%d' % j, '/s/%d/%d' % (i,j)] for j in range(16)]) for i in range(16)]
c.config(all_groups, 'C04'); c.project('C11')
all_groups.append(group('extra', candidates=[], slots=[['one', '/extra/slot']])); c.config(all_groups, 'C04')
# Seeded traces use an independent dictionary state oracle; every API result is observed.
rng = random.Random(20261017013)
for trial in range(36):
names = ['g%d_%d' % (trial, i) for i in range(rng.randrange(1, 4))]
raw = []
for name in names:
choices = []
for i in range(rng.randrange(1, 6)):
attachments = [['edit', '/edit/%d' % i]] if rng.randrange(2) else []
choices.append(['/candidate/%d' % i, rng.choice([-2147483648, -7, -1, 0, 5, 5, 2147483647]), bool(rng.randrange(2)), attachments])
rng.shuffle(choices)
mode = rng.randrange(2)
raw.append(group(name, mode, rng.choice(choices)[0] if mode else '', choices))
rng.shuffle(raw); c.config(raw); c.project('C09')
for chunk in range(3):
events = []
state = copy.deepcopy(c.world)
for _ in range(12):
name = rng.choice(names); current = next(g for g in state if g[0] == name)
installed = [row[0] for row in current[5]]
op = rng.choice([0, 1, 2, 3, 4] if installed else [0, 1, 3])
path = rng.choice(installed) if installed else '/candidate/0'
if op == 0:
path = '/candidate/%d' % rng.randrange(6)
rank = rng.choice(['-2147483648', '+0000000000', '-9', '9', '2147483647'])
e = event(0, name, path, rank, bool(rng.randrange(2)), [['edit', '/edit/new']] if rng.randrange(2) else [])
elif op == 3: e = event(3, name)
else: e = event(op, name, path, enabled=bool(rng.randrange(2)) if op == 4 else False)
events.append(e)
state = transcript(state, [e])[0]
c.replay(events, 'C20', commit=True); c.project('C21')
return c
def main():
matrix = cases()
context = json.loads((Path(__file__).resolve().parent / 'context.json').read_text())
scratch = Path(tempfile.mkdtemp(prefix='embedded-hard-alternative-', dir='/tmp'))
for name, text in context.items(): (scratch / name).write_text(text)
for name in CANDIDATES: (scratch / name).write_bytes((Path(sys.argv[1]) / name).read_bytes())
build = subprocess.run(['g++', '-std=c++17', '-O2', '-Wall', '-Wextra', '-pedantic',
'registry_observe.cpp', *CANDIDATES, '-o', 'registry_observe'],
cwd=scratch, text=True, encoding='utf-8', errors='replace', capture_output=True, timeout=30)
if build.returncode:
print('FAILED_CHECKS ["C27"] build failed: ' + build.stderr[-1200:].replace('\n', ' ')); return 1
# shortcut: shared scratch remains for container destruction or separate trusted
# owner cleanup; after child execution only pipe output is inspected.
timed_out = False
try:
result = subprocess.run([str(scratch / 'registry_observe')], cwd=scratch,
input='\n'.join(matrix.commands) + '\n', text=True,
encoding='utf-8', errors='replace', capture_output=True, timeout=15)
output, exit_code = result.stdout, result.returncode
except subprocess.TimeoutExpired as error:
timed_out = True; output = error.stdout or b''
if isinstance(output, bytes): output = output.decode('utf-8', 'replace')
exit_code = -9
actual = output.splitlines()
failures = set(['C29'] if timed_out else ['C28'] if exit_code else [])
examples, indexes = [], []
count = max(len(actual), len(matrix.expected))
for index in range(count):
label = matrix.labels[index] if index < len(matrix.labels) else 'C28'
wanted = matrix.expected[index] if index < len(matrix.expected) else '<end>'
try: observed = json.loads(actual[index]) if index < len(actual) else '<missing>'
except ValueError: observed = actual[index]
if index >= len(actual) or index >= len(matrix.expected) or observed != wanted:
indexes.append(index); failures.add(label)
if len(examples) < 8:
examples.append('%s observation=%d got=%s expected=%s' % (label, index, repr(observed)[:220], repr(wanted)[:220]))
if failures:
print('FAILED_CHECKS ' + json.dumps(sorted(failures)))
for example in examples: print(example)
bitmap = bytearray((count + 7) // 8)
for index in indexes: bitmap[index // 8] |= 1 << (index % 8)
diagnostic = {'observations': count, 'bits_lsb0': base64.b64encode(bitmap).decode(),
'failed_checks': sorted(failures), 'candidate_exit': exit_code, 'timeout': timed_out}
for example in examples[:3]: print(example, file=sys.stderr)
print('MISMATCH_BITMAP ' + json.dumps(diagnostic, separators=(',', ':')), file=sys.stderr)
return 1
print('PASS'); return 0
if __name__ == '__main__':
raise SystemExit(main())