Harbor format: 210 business_automation tasks (part 4)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- tasks/autom-fulfillment-release-007/tests/replay.pyAdded+68
- tasks/autom-fulfillment-release-007/tests/target.jsonAdded+396
- tasks/autom-fulfillment-release-007/tests/test.shAdded+4
- tasks/autom-fulfillment-release-007/tests/world.jsonAdded+342
- tasks/autom-fulfillment-release-007/tests/world_check.pyAdded+26
- tasks/autom-fulfillment-release-007/validation/openenv.jsonAdded+28
- tasks/autom-fulfillment-release-008/environment/inputs/apps.pyAdded+68
- tasks/autom-fulfillment-release-008/environment/inputs/world.jsonAdded+292
- tasks/autom-fulfillment-release-008/instruction.mdAdded+17
- tasks/autom-fulfillment-release-008/solution/files/actions.jsonlAdded+25
- tasks/autom-fulfillment-release-008/solution/solve.shAdded+4
- tasks/autom-fulfillment-release-008/task.tomlAdded+46
- tasks/autom-fulfillment-release-008/tests/expected.jsonAdded+9
- tasks/autom-fulfillment-release-008/tests/grade.pyAdded+330
- tasks/autom-fulfillment-release-008/tests/replay.pyAdded+68
- tasks/autom-fulfillment-release-008/tests/target.jsonAdded+352
- tasks/autom-fulfillment-release-008/tests/test.shAdded+4
- tasks/autom-fulfillment-release-008/tests/world.jsonAdded+292
- tasks/autom-fulfillment-release-008/tests/world_check.pyAdded+26
- tasks/autom-fulfillment-release-008/validation/openenv.jsonAdded+28
- tasks/autom-fulfillment-release-009/environment/inputs/apps.pyAdded+68
- tasks/autom-fulfillment-release-009/environment/inputs/world.jsonAdded+242
- tasks/autom-fulfillment-release-009/instruction.mdAdded+17
- tasks/autom-fulfillment-release-009/solution/files/actions.jsonlAdded+16
- tasks/autom-fulfillment-release-009/solution/solve.shAdded+4
- tasks/autom-fulfillment-release-009/task.tomlAdded+46
- tasks/autom-fulfillment-release-009/tests/expected.jsonAdded+9
- tasks/autom-fulfillment-release-009/tests/grade.pyAdded+330
- tasks/autom-fulfillment-release-009/tests/replay.pyAdded+68
- tasks/autom-fulfillment-release-009/tests/target.jsonAdded+278
- tasks/autom-fulfillment-release-009/tests/test.shAdded+4
- tasks/autom-fulfillment-release-009/tests/world.jsonAdded+242
- tasks/autom-fulfillment-release-009/tests/world_check.pyAdded+26
- tasks/autom-fulfillment-release-009/validation/openenv.jsonAdded+28
- tasks/autom-fulfillment-release-015/environment/inputs/apps.pyAdded+68
- tasks/autom-fulfillment-release-015/environment/inputs/world.jsonAdded+250
- tasks/autom-fulfillment-release-015/instruction.mdAdded+17
- tasks/autom-fulfillment-release-015/solution/files/actions.jsonlAdded+16
- tasks/autom-fulfillment-release-015/solution/solve.shAdded+4
- tasks/autom-fulfillment-release-015/task.tomlAdded+46
- tasks/autom-fulfillment-release-015/tests/expected.jsonAdded+9
- tasks/autom-fulfillment-release-015/tests/grade.pyAdded+330
- tasks/autom-fulfillment-release-015/tests/replay.pyAdded+68
- tasks/autom-fulfillment-release-015/tests/target.jsonAdded+286
- tasks/autom-fulfillment-release-015/tests/test.shAdded+4
- tasks/autom-fulfillment-release-015/tests/world.jsonAdded+250
- tasks/autom-fulfillment-release-015/tests/world_check.pyAdded+26
- tasks/autom-fulfillment-release-015/validation/openenv.jsonAdded+28
- tasks/autom-fulfillment-release-016/environment/inputs/apps.pyAdded+68
- tasks/autom-fulfillment-release-016/environment/inputs/world.jsonAdded+266
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" }, "pick-SO-17280-6": { "order": "SO-17280-6", "site": "Albany", "sku": "RNG", "units": 27 }, "pick-SO-19346-7": { "order": "SO-19346-7", "site": "Denver", "sku": "PLT", "units": 17 }, "pick-SO-32522-2": { "order": "SO-32522-2", "site": "Albany", "sku": "PLT", "units": 4 }, "pick-SO-47943-4": { "order": "SO-47943-4", "site": "Denver", "sku": "BRK", "units": 11 }, "pick-SO-66671-5": { "order": "SO-66671-5", "site": "Albany", "sku": "CAP", "units": 5 }, "pick-SO-69086-3": { "order": "SO-69086-3", "site": "Albany", "sku": "CLP", "units": 23 }, "pick-SO-79572-0": { "order": "SO-79572-0", "site": "Albany", "sku": "CAP", "units": 1 } }, "inbound": { "PO-Albany-BRK": { "due": "2025-07-19", "open_units": 11, "site": "Albany", "sku": "BRK", "status": "confirmed" }, "PO-Albany-CAP": { "due": "2025-07-17", "open_units": 11, "site": "Albany", "sku": "CAP", "status": "confirmed" }, "PO-Albany-CLP": { "due": "2025-07-10", "open_units": 2, "site": "Albany", "sku": "CLP", "status": "confirmed" }, "PO-Albany-PLT": { "due": "2025-07-09", "open_units": 10, "site": "Albany", "sku": "PLT", "status": "proposed" }, "PO-Albany-RNG": { "due": "2025-07-16", "open_units": 3, "site": "Albany", "sku": "RNG", "status": "confirmed" }, "PO-Denver-BRK": { "due": "2025-07-19", "open_units": 6, "site": "Denver", "sku": "BRK", "status": "confirmed" }, "PO-Denver-CAP": { "due": "2025-07-18", "open_units": 11, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-CLP": { "due": "2025-07-09", "open_units": 9, "site": "Denver", "sku": "CLP", "status": "confirmed" }, "PO-Denver-PLT": { "due": "2025-07-18", "open_units": 9, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2025-07-14", "open_units": 11, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Waco-BRK": { "due": "2025-07-11", "open_units": 2, "site": "Waco", "sku": "BRK", "status": "confirmed" }, "PO-Waco-CAP": { "due": "2025-07-11", "open_units": 3, "site": "Waco", "sku": "CAP", "status": "confirmed" }, "PO-Waco-CLP": { "due": "2025-07-11", "open_units": 5, "site": "Waco", "sku": "CLP", "status": "proposed" }, "PO-Waco-PLT": { "due": "2025-07-14", "open_units": 8, "site": "Waco", "sku": "PLT", "status": "proposed" }, "PO-Waco-RNG": { "due": "2025-07-13", "open_units": 7, "site": "Waco", "sku": "RNG", "status": "confirmed" } }, "inventory": { "Albany-BRK": { "on_hand": 18, "reserved": 3, "safety": 6, "site": "Albany", "sku": "BRK" }, "Albany-CAP": { "on_hand": 40, "reserved": 7, "safety": 6, "site": "Albany", "sku": "CAP" }, "Albany-CLP": { "on_hand": 43, "reserved": 27, "safety": 7, "site": "Albany", "sku": "CLP" }, "Albany-PLT": { "on_hand": 18, "reserved": 4, "safety": 5, "site": "Albany", "sku": "PLT" }, "Albany-RNG": { "on_hand": 38, "reserved": 30, "safety": 7, "site": "Albany", "sku": "RNG" }, "Denver-BRK": { "on_hand": 32, "reserved": 13, "safety": 5, "site": "Denver", "sku": "BRK" }, "Denver-CAP": { "on_hand": 17, "reserved": 4, "safety": 5, "site": "Denver", "sku": "CAP" }, "Denver-CLP": { "on_hand": 34, "reserved": 0, "safety": 8, "site": "Denver", "sku": "CLP" }, "Denver-PLT": { "on_hand": 40, "reserved": 21, "safety": 5, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 42, "reserved": 1, "safety": 8, "site": "Denver", "sku": "RNG" }, "Waco-BRK": { "on_hand": 13, "reserved": 0, "safety": 4, "site": "Waco", "sku": "BRK" }, "Waco-CAP": { "on_hand": 20, "reserved": 1, "safety": 7, "site": "Waco", "sku": "CAP" }, "Waco-CLP": { "on_hand": 29, "reserved": 1, "safety": 7, "site": "Waco", "sku": "CLP" }, "Waco-PLT": { "on_hand": 15, "reserved": 5, "safety": 6, "site": "Waco", "sku": "PLT" }, "Waco-RNG": { "on_hand": 13, "reserved": 1, "safety": 5, "site": "Waco", "sku": "RNG" } }, "orders": { "SO-17280-6": { "origin": "Albany", "priority": 1, "promise": "2025-07-05", "sku": "RNG", "state": "allocated", "units": 27 }, "SO-19346-7": { "origin": "Albany", "priority": 2, "promise": "2025-07-07", "sku": "PLT", "state": "allocated", "units": 17 }, "SO-26246-8": { "origin": "Albany", "priority": 2, "promise": "2025-07-11", "sku": "CLP", "state": "open", "units": 33 }, "SO-32522-2": { "origin": "Albany", "priority": 3, "promise": "2025-07-06", "sku": "PLT", "state": "allocated", "units": 4 }, "SO-47943-4": { "origin": "Albany", "priority": 1, "promise": "2025-07-04", "sku": "BRK", "state": "allocated", "units": 11 }, "SO-53497-13": { "origin": "Albany", "priority": 1, "promise": "2025-07-02", "sku": "CLP", "state": "shipped", "units": 7 }, "SO-54662-10": { "origin": "Waco", "priority": 3, "promise": "2025-07-12", "sku": "CAP", "state": "open", "units": 7 }, "SO-56430-1": { "origin": "Albany", "priority": 2, "promise": "2025-07-05", "sku": "RNG", "state": "backorder", "units": 65 }, "SO-59213-11": { "origin": "Waco", "priority": 2, "promise": "2025-07-12", "sku": "RNG", "state": "open", "units": 12 }, "SO-59221-12": { "origin": "Albany", "priority": 3, "promise": "2025-07-11", "sku": "PLT", "state": "open", "units": 6 }, "SO-66671-5": { "origin": "Albany", "priority": 3, "promise": "2025-07-03", "sku": "CAP", "state": "allocated", "units": 5 }, "SO-69086-3": { "origin": "Albany", "priority": 1, "promise": "2025-07-01", "sku": "CLP", "state": "allocated", "units": 23 }, "SO-73255-9": { "origin": "Albany", "priority": 3, "promise": "2025-07-08", "sku": "BRK", "state": "backorder", "units": 17 }, "SO-79572-0": { "origin": "Albany", "priority": 1, "promise": "2025-07-06", "sku": "CAP", "state": "allocated", "units": 1 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 }, "req-Albany-BRK": { "site": "Albany", "sku": "BRK", "status": "draft", "units": 17 }, "req-Albany-RNG": { "site": "Albany", "sku": "RNG", "status": "draft", "units": 65 } }}1234#!/bin/shset -eumkdir -p /logs/verifier /workspace/outputsexec python3 -B -I /tests/grade.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Albany-BRK": { "due": "2025-07-19", "open_units": 11, "site": "Albany", "sku": "BRK", "status": "confirmed" }, "PO-Albany-CAP": { "due": "2025-07-17", "open_units": 11, "site": "Albany", "sku": "CAP", "status": "confirmed" }, "PO-Albany-CLP": { "due": "2025-07-10", "open_units": 2, "site": "Albany", "sku": "CLP", "status": "confirmed" }, "PO-Albany-PLT": { "due": "2025-07-09", "open_units": 10, "site": "Albany", "sku": "PLT", "status": "proposed" }, "PO-Albany-RNG": { "due": "2025-07-16", "open_units": 3, "site": "Albany", "sku": "RNG", "status": "confirmed" }, "PO-Denver-BRK": { "due": "2025-07-19", "open_units": 6, "site": "Denver", "sku": "BRK", "status": "confirmed" }, "PO-Denver-CAP": { "due": "2025-07-18", "open_units": 11, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-CLP": { "due": "2025-07-09", "open_units": 9, "site": "Denver", "sku": "CLP", "status": "confirmed" }, "PO-Denver-PLT": { "due": "2025-07-18", "open_units": 9, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2025-07-14", "open_units": 11, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Waco-BRK": { "due": "2025-07-11", "open_units": 2, "site": "Waco", "sku": "BRK", "status": "confirmed" }, "PO-Waco-CAP": { "due": "2025-07-11", "open_units": 3, "site": "Waco", "sku": "CAP", "status": "confirmed" }, "PO-Waco-CLP": { "due": "2025-07-11", "open_units": 5, "site": "Waco", "sku": "CLP", "status": "proposed" }, "PO-Waco-PLT": { "due": "2025-07-14", "open_units": 8, "site": "Waco", "sku": "PLT", "status": "proposed" }, "PO-Waco-RNG": { "due": "2025-07-13", "open_units": 7, "site": "Waco", "sku": "RNG", "status": "confirmed" } }, "inventory": { "Albany-BRK": { "on_hand": 18, "reserved": 3, "safety": 6, "site": "Albany", "sku": "BRK" }, "Albany-CAP": { "on_hand": 40, "reserved": 1, "safety": 6, "site": "Albany", "sku": "CAP" }, "Albany-CLP": { "on_hand": 43, "reserved": 4, "safety": 7, "site": "Albany", "sku": "CLP" }, "Albany-PLT": { "on_hand": 18, "reserved": 0, "safety": 5, "site": "Albany", "sku": "PLT" }, "Albany-RNG": { "on_hand": 38, "reserved": 3, "safety": 7, "site": "Albany", "sku": "RNG" }, "Denver-BRK": { "on_hand": 32, "reserved": 2, "safety": 5, "site": "Denver", "sku": "BRK" }, "Denver-CAP": { "on_hand": 17, "reserved": 4, "safety": 5, "site": "Denver", "sku": "CAP" }, "Denver-CLP": { "on_hand": 34, "reserved": 0, "safety": 8, "site": "Denver", "sku": "CLP" }, "Denver-PLT": { "on_hand": 40, "reserved": 4, "safety": 5, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 42, "reserved": 1, "safety": 8, "site": "Denver", "sku": "RNG" }, "Waco-BRK": { "on_hand": 13, "reserved": 0, "safety": 4, "site": "Waco", "sku": "BRK" }, "Waco-CAP": { "on_hand": 20, "reserved": 1, "safety": 7, "site": "Waco", "sku": "CAP" }, "Waco-CLP": { "on_hand": 29, "reserved": 1, "safety": 7, "site": "Waco", "sku": "CLP" }, "Waco-PLT": { "on_hand": 15, "reserved": 5, "safety": 6, "site": "Waco", "sku": "PLT" }, "Waco-RNG": { "on_hand": 13, "reserved": 1, "safety": 5, "site": "Waco", "sku": "RNG" } }, "orders": { "SO-17280-6": { "origin": "Albany", "priority": 1, "promise": "2025-07-05", "sku": "RNG", "state": "open", "units": 27 }, "SO-19346-7": { "origin": "Albany", "priority": 2, "promise": "2025-07-07", "sku": "PLT", "state": "open", "units": 17 }, "SO-26246-8": { "origin": "Albany", "priority": 2, "promise": "2025-07-11", "sku": "CLP", "state": "open", "units": 33 }, "SO-32522-2": { "origin": "Albany", "priority": 3, "promise": "2025-07-06", "sku": "PLT", "state": "open", "units": 4 }, "SO-47943-4": { "origin": "Albany", "priority": 1, "promise": "2025-07-04", "sku": "BRK", "state": "open", "units": 11 }, "SO-53497-13": { "origin": "Albany", "priority": 1, "promise": "2025-07-02", "sku": "CLP", "state": "shipped", "units": 7 }, "SO-54662-10": { "origin": "Waco", "priority": 3, "promise": "2025-07-12", "sku": "CAP", "state": "open", "units": 7 }, "SO-56430-1": { "origin": "Albany", "priority": 2, "promise": "2025-07-05", "sku": "RNG", "state": "open", "units": 65 }, "SO-59213-11": { "origin": "Waco", "priority": 2, "promise": "2025-07-12", "sku": "RNG", "state": "open", "units": 12 }, "SO-59221-12": { "origin": "Albany", "priority": 3, "promise": "2025-07-11", "sku": "PLT", "state": "open", "units": 6 }, "SO-66671-5": { "origin": "Albany", "priority": 3, "promise": "2025-07-03", "sku": "CAP", "state": "open", "units": 5 }, "SO-69086-3": { "origin": "Albany", "priority": 1, "promise": "2025-07-01", "sku": "CLP", "state": "open", "units": 23 }, "SO-73255-9": { "origin": "Albany", "priority": 3, "promise": "2025-07-08", "sku": "BRK", "state": "open", "units": 17 }, "SO-79572-0": { "origin": "Albany", "priority": 1, "promise": "2025-07-06", "sku": "CAP", "state": "open", "units": 1 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617181920212223242526"""Replay submitted mutations from the private verifier's initial state."""from types import ModuleTypeimport json
def check(spec, outputs, tests): replay = ModuleType('workflow_replay') exec(compile((tests/'replay.py').read_bytes(), 'replay.py', 'exec'), replay.__dict__) world = json.loads((tests/'world.json').read_text()) target = json.loads((tests/'target.json').read_text()) # Only fields whose starting and expected values differ may be changed. Attempts # to temporarily alter a protected field fail even when a later write restores it. allowed = { (app,key): {field for field,value in doc.items() if field not in world[app].get(key,{}) or not replay.same(world[app][key][field],value)} for app,records in target.items() for key,doc in records.items() } actions = replay.load_actions(outputs/'actions.jsonl') for event in actions: replay.apply(world,event) touched = set(event['fields']) if not touched <= allowed.get((event['app'],event['id']),set()): return False,'protected field or record write' if not replay.same(world,target): return False,'required business outcomes incomplete' return True,''12345678910111213141516171819202122232425262728{ "profile": "harbor-semantic-v1", "reward_key": "reward", "reward": { "range": [ 0, 1 ], "oracle_tolerance": 0, "floor_margin": 0.1 }, "resources": { "cpu": 1, "memory_mb": 4096, "disk_mb": 10240, "episode_timeout_s": 1800 }, "types": { "tags": [ "knowledge-work", "cross-app-workflows", "conditional-execution", "protected-state", "operations" ] }, "requires_credentials": false}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Albany-CAP": { "due": "2025-08-03", "open_units": 2, "site": "Albany", "sku": "CAP", "status": "confirmed" }, "PO-Albany-CPL": { "due": "2025-08-07", "open_units": 9, "site": "Albany", "sku": "CPL", "status": "confirmed" }, "PO-Albany-MDL": { "due": "2025-08-10", "open_units": 9, "site": "Albany", "sku": "MDL", "status": "confirmed" }, "PO-Albany-RNG": { "due": "2025-08-03", "open_units": 1, "site": "Albany", "sku": "RNG", "status": "proposed" }, "PO-Denver-CAP": { "due": "2025-08-09", "open_units": 4, "site": "Denver", "sku": "CAP", "status": "proposed" }, "PO-Denver-CPL": { "due": "2025-08-05", "open_units": 11, "site": "Denver", "sku": "CPL", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-05", "open_units": 10, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2025-08-01", "open_units": 2, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Tampa-CAP": { "due": "2025-08-08", "open_units": 1, "site": "Tampa", "sku": "CAP", "status": "proposed" }, "PO-Tampa-CPL": { "due": "2025-08-11", "open_units": 8, "site": "Tampa", "sku": "CPL", "status": "proposed" }, "PO-Tampa-MDL": { "due": "2025-08-04", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2025-08-06", "open_units": 5, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Albany-CAP": { "on_hand": 33, "reserved": 2, "safety": 7, "site": "Albany", "sku": "CAP" }, "Albany-CPL": { "on_hand": 39, "reserved": 2, "safety": 4, "site": "Albany", "sku": "CPL" }, "Albany-MDL": { "on_hand": 47, "reserved": 2, "safety": 5, "site": "Albany", "sku": "MDL" }, "Albany-RNG": { "on_hand": 33, "reserved": 3, "safety": 5, "site": "Albany", "sku": "RNG" }, "Denver-CAP": { "on_hand": 21, "reserved": 0, "safety": 4, "site": "Denver", "sku": "CAP" }, "Denver-CPL": { "on_hand": 43, "reserved": 4, "safety": 6, "site": "Denver", "sku": "CPL" }, "Denver-MDL": { "on_hand": 26, "reserved": 1, "safety": 6, "site": "Denver", "sku": "MDL" }, "Denver-RNG": { "on_hand": 22, "reserved": 3, "safety": 8, "site": "Denver", "sku": "RNG" }, "Tampa-CAP": { "on_hand": 32, "reserved": 2, "safety": 4, "site": "Tampa", "sku": "CAP" }, "Tampa-CPL": { "on_hand": 25, "reserved": 2, "safety": 5, "site": "Tampa", "sku": "CPL" }, "Tampa-MDL": { "on_hand": 45, "reserved": 4, "safety": 8, "site": "Tampa", "sku": "MDL" }, "Tampa-RNG": { "on_hand": 26, "reserved": 0, "safety": 7, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-21998-2": { "origin": "Tampa", "priority": 2, "promise": "2025-07-25", "sku": "RNG", "state": "open", "units": 11 }, "SO-26348-12": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "open", "units": 17 }, "SO-40281-11": { "origin": "Tampa", "priority": 2, "promise": "2025-08-03", "sku": "MDL", "state": "open", "units": 21 }, "SO-46517-0": { "origin": "Tampa", "priority": 1, "promise": "2025-07-29", "sku": "CPL", "state": "open", "units": 1 }, "SO-48065-5": { "origin": "Tampa", "priority": 2, "promise": "2025-07-26", "sku": "CAP", "state": "open", "units": 5 }, "SO-48464-10": { "origin": "Albany", "priority": 2, "promise": "2025-07-22", "sku": "RNG", "state": "open", "units": 17 }, "SO-49822-3": { "origin": "Tampa", "priority": 3, "promise": "2025-07-29", "sku": "MDL", "state": "open", "units": 33 }, "SO-52284-6": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "RNG", "state": "open", "units": 26 }, "SO-85258-4": { "origin": "Tampa", "priority": 1, "promise": "2025-07-27", "sku": "CPL", "state": "open", "units": 19 }, "SO-86810-7": { "origin": "Albany", "priority": 2, "promise": "2025-07-25", "sku": "MDL", "state": "shipped", "units": 22 }, "SO-87277-1": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "CAP", "state": "open", "units": 65 }, "SO-88635-8": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "open", "units": 16 }, "SO-99963-9": { "origin": "Tampa", "priority": 3, "promise": "2025-07-30", "sku": "CAP", "state": "open", "units": 10 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617Release the overdue and due order queue at Tampa as of 2025-07-31. Only open orders originating there with promise dates on or before the cutoff are in scope. Process in order of earliest promise date, then ascending priority number, then ascending order ID. The queue policy changes by client.
For each line first try Tampa. If the origin cannot cover the complete order, try Denver as a single backup. Available units equal on-hand less existing reservations and safety stock. Allocate a whole order at one site, with no splitting. Add its units to the selected inventory record's `reserved` total, update order `state` to `allocated`, and create dispatch record `pick-<order ID>` with `order`, `site`, `sku`, `units`. Otherwise set the order `state` to `backorder`.
At the end total all units newly backordered by SKU. Before requesting those units for Tampa, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-08-07. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-<SKU>` with `site`, `sku`, `units` equal to that remainder, and `status` equal to `draft`. Preserve the inbound, historical and out-of-scope records and all other fields.
Use the offline app client at `/workspace/inputs/apps.py`. Call it with python3. Run`apps` to discover apps, `list APP` to see its records, or `get APP ID` for one record.Write with `update APP ID '{"field":"value"}'` or `create APP ID '{"field":"value"}'`.The client records successful writes in `/workspace/outputs/actions.jsonl`.Apply exactly the required changes. Other records and fields must remain untouched,including temporary changes. Actions take effect in the local simulation only.
## Deliverable
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in`/workspace/outputs/`; only that directory is graded. Leave the app action log in the outputs directory.12345678910111213141516171819202122232425{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-46517-0", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-87277-1", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-21998-2", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-49822-3", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-85258-4", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-48065-5", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-52284-6", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-88635-8", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-99963-9", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-26348-12", "op": "update"}{"app": "inventory", "fields": {"reserved": 20}, "id": "Tampa-CPL", "op": "update"}{"app": "inventory", "fields": {"reserved": 17}, "id": "Tampa-CAP", "op": "update"}{"app": "inventory", "fields": {"reserved": 11}, "id": "Tampa-RNG", "op": "update"}{"app": "inventory", "fields": {"reserved": 37}, "id": "Tampa-MDL", "op": "update"}{"app": "inventory", "fields": {"reserved": 23}, "id": "Denver-CPL", "op": "update"}{"app": "dispatch", "fields": {"order": "SO-21998-2", "site": "Tampa", "sku": "RNG", "units": 11}, "id": "pick-SO-21998-2", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-48065-5", "site": "Tampa", "sku": "CAP", "units": 5}, "id": "pick-SO-48065-5", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-85258-4", "site": "Denver", "sku": "CPL", "units": 19}, "id": "pick-SO-85258-4", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-46517-0", "site": "Tampa", "sku": "CPL", "units": 1}, "id": "pick-SO-46517-0", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-49822-3", "site": "Tampa", "sku": "MDL", "units": 33}, "id": "pick-SO-49822-3", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-26348-12", "site": "Tampa", "sku": "CPL", "units": 17}, "id": "pick-SO-26348-12", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-99963-9", "site": "Tampa", "sku": "CAP", "units": 10}, "id": "pick-SO-99963-9", "op": "create"}{"app": "procurement", "fields": {"site": "Tampa", "sku": "RNG", "status": "draft", "units": 26}, "id": "req-Tampa-RNG", "op": "create"}{"app": "procurement", "fields": {"site": "Tampa", "sku": "CAP", "status": "draft", "units": 65}, "id": "req-Tampa-CAP", "op": "create"}{"app": "procurement", "fields": {"site": "Tampa", "sku": "CPL", "status": "draft", "units": 16}, "id": "req-Tampa-CPL", "op": "create"}1234#!/bin/shset -eumkdir -p /workspace/outputscp -R /solution/files/. /workspace/outputs/12345678910111213141516171819202122232425262728293031323334353637383940414243444546schema_version = "1.3"
[task]name = "apex-gap/autom-fulfillment-release-008"
[metadata.apex_gap]capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"]dataset = "Original simulated workflows"job = "operations"seed = 8source = "local/original-automation-workflows"source_revision = "1"source_split = "synthetic"source_task_id = "autom-fulfillment-release-008"template_family = "automation:fulfillment-release"workflow_template = "fulfillment-release"
[metadata.openenv_hf_sandbox]variant = "apex-gap-hfsandbox-v1"task_modified_for_hf_sandbox = truenetwork_enabled = true
[environment]docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"workdir = "/workspace"cpus = 1memory_mb = 4096build_timeout_sec = 600network_mode = "public"
[agent]timeout_sec = 1800network_mode = "public"
[verifier]timeout_sec = 600network_mode = "public"environment_mode = "separate"
[verifier.environment]network_mode = "public"cpus = 1memory_mb = 4096
[[artifacts]]source = "/workspace/outputs"123456789{ "checks": [ { "id": "business-outcomes", "type": "custom", "module": "world_check" } ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330"""Deterministic grader shared by converted knowledge-work tasks.
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects thesubmitted /workspace/outputs tree and writes a binary reward plus per-check details.No model calls and no network.
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}Check types: answer field of outputs/answer.json; kind = number|text|choice|date|bool|list xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules) xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values) file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)"""
import datetime as dtimport jsonimport reimport shutilimport subprocessimport sysimport tempfileimport unicodedatafrom pathlib import Path
OUT = Path("/workspace/outputs")TESTS = Path("/tests")LOGS = Path("/logs/verifier")
def norm_text(v): v = unicodedata.normalize("NFKC", str(v)).casefold() v = re.sub(r"[‘’“”]", "'", v) v = re.sub(r"[^\w%.$/-]+", " ", v) return " ".join(v.split()).strip(" .")
def to_number(v): if isinstance(v, bool): raise ValueError("bool") if isinstance(v, (int, float)): return float(v) s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-") neg = s.startswith("(") and s.endswith(")") s = s.strip("()").strip() pct = s.endswith("%") s = s.rstrip("%").strip() s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I) x = float(s) x = -x if neg else x return x / 100 if pct else x
def number_ok(got, want, rel, abs_): try: g = to_number(got) except (TypeError, ValueError): return False w = float(want) tol = max(abs_, rel * abs(w)) # "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which. candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g] return any(abs(c - w) <= tol for c in candidates)
def parse_date(v): if isinstance(v, (dt.date, dt.datetime)): return v if isinstance(v, dt.date) else v.date() s = str(v).strip() for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"): try: return dt.datetime.strptime(s, fmt).date() except ValueError: continue raise ValueError(s)
def check_answer(check, answers): key = check["field"] if key not in answers: return False, f"missing field {key!r}" got, want, kind = answers[key], check["value"], check.get("kind", "text") if kind == "number": ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01)) if not ok and check.get("percent_either"): ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or ( number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100) ) elif kind == "date": try: ok = parse_date(got) == parse_date(want) except ValueError: ok = False elif kind == "bool": g = norm_text(got) ok = g in {"yes", "true"} if want else g in {"no", "false"} elif kind == "choice": ok = norm_text(got) == norm_text(want) elif kind == "list": if not isinstance(got, list): return False, f"{key}: expected a JSON list" # Filenames may be given with a directory prefix; compare base names. base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1]) ok = sorted(base(x) for x in got) == sorted(base(x) for x in want) else: accepted = check.get("accept", [want]) ok = norm_text(got) in {norm_text(a) for a in accepted} return ok, "" if ok else f"{key}: got {got!r}"
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?><oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item></oor:items>"""
def recalc(path, tmp): dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}" dest.mkdir() profile = Path(tmp) / "lo-profile" if not profile.exists(): (profile / "user").mkdir(parents=True) (profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE) subprocess.run( ["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to", "xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=180, check=False, ) out = dest / (Path(path).stem + ".xlsx") return out if out.exists() else Path(path)
def cell_value(v): if isinstance(v, (int, float)) and not isinstance(v, bool): return round(float(v), 2) if isinstance(v, dt.datetime): return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0) if isinstance(v, dt.time): return v.strftime("%H:%M") if isinstance(v, str): try: return round(float(v), 2) except ValueError: return v.strip() return v
def time_of(v): """A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells.""" if isinstance(v, dt.time): v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400 if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1: return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M") return None
def same_cell(a, b): if isinstance(a, dt.time) is not isinstance(b, dt.time): n = b if isinstance(a, dt.time) else a if time_of(n) is not None: # a time against a plain day fraction return time_of(a) == time_of(b) a, b = cell_value(a), cell_value(b) if a in (None, "") and b in (None, ""): return True return type(a) is type(b) and a == b
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
def is_error(v): return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
def cells(rng): if ":" not in rng: return [rng] from openpyxl.utils import range_boundaries, get_column_letter
c1, r1, c2, r2 = range_boundaries(rng) return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
def load(path, tmp): import openpyxl
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
def check_xlsx_range(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) tgt = TESTS / check["target"] if tgt not in cache: cache[tgt] = load(tgt, tmp) got, want = cache[sub], cache[tgt] cached = None # the target's stored (Excel-computed) values, read only when Calc errs for sheet, rng in check["ranges"]: sheet = sheet or want.sheetnames[0] if sheet not in got.sheetnames: return False, f"sheet {sheet!r} missing" for name in cells(rng): w = want[sheet][name].value if is_error(w): # LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4). # The value Excel stored is the intended answer. if cached is None: import openpyxl
cached = openpyxl.load_workbook(tgt, data_only=True) c = cached[sheet][name].value if sheet in cached.sheetnames else None if c is not None and not is_error(c): w = c if not same_cell(w, got[sheet][name].value): return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}" return True, ""
def check_xlsx_cell(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) wb = cache[sub] if check["sheet"] not in wb.sheetnames: return False, f"sheet {check['sheet']!r} missing" got = wb[check["sheet"]][check["cell"]].value want = check["value"] if isinstance(want, (int, float)): # alt_values: other accepted golds where the source admits more than one reading. ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01)) for w in [want, *check.get("alt_values", [])]) else: ok = norm_text(got) == norm_text(want) return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
def text_of(path): suffix = path.suffix.lower() if suffix == ".docx": import docx
d = docx.Document(path) parts = [p.text for p in d.paragraphs] for t in d.tables: parts += [c.text for row in t.rows for c in row.cells] return "\n".join(parts) if suffix == ".pdf": import pdfplumber
with pdfplumber.open(path) as pdf: return "\n".join(page.extract_text() or "" for page in pdf.pages) return path.read_text(errors="replace")
def check_file_contains(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" text = text_of(sub) hay = text if check.get("case_sensitive") else text.casefold() for needle in check["needles"]: n = needle if check.get("case_sensitive") else needle.casefold() if n not in hay: return False, f"{check['file']} lacks {needle!r}" return True, ""
def main(): LOGS.mkdir(parents=True, exist_ok=True) reward_path = LOGS / "reward.txt" reward_path.write_text("0\n") spec = json.loads((TESTS / "expected.json").read_text()) answers, details = {}, [] answer_file = OUT / "answer.json" if answer_file.is_file(): try: answers = json.loads(answer_file.read_text()) if not isinstance(answers, dict): answers = {} except json.JSONDecodeError: answers = {} tmp = tempfile.mkdtemp() cache = {} try: for check in spec["checks"]: try: if check["type"] == "answer": ok, why = check_answer(check, answers) elif check["type"] == "xlsx_range": ok, why = check_xlsx_range(check, tmp, cache) elif check["type"] == "xlsx_cell": ok, why = check_xlsx_cell(check, tmp, cache) elif check["type"] == "file_contains": ok, why = check_file_contains(check, tmp, cache) elif check["type"] == "custom": import importlib.util
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py") mod = importlib.util.module_from_spec(spec_) spec_.loader.exec_module(mod) ok, why = mod.check(check, OUT, TESTS) else: ok, why = False, f"unknown check type {check['type']}" except Exception as exc: # a malformed submission fails the check, not the grader ok, why = False, f"{type(exc).__name__}: {exc}" details.append({"id": check["id"], "passed": ok, "detail": why}) finally: shutil.rmtree(tmp, ignore_errors=True) passed = sum(d["passed"] for d in details) total = len(details) reward = 1 if total and passed == total else 0 (LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1)) reward_path.write_text(f"{reward}\n") print(f"{passed}/{total} checks passed; reward {reward}")
if __name__ == "__main__": sys.exit(main())1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" }, "pick-SO-21998-2": { "order": "SO-21998-2", "site": "Tampa", "sku": "RNG", "units": 11 }, "pick-SO-26348-12": { "order": "SO-26348-12", "site": "Tampa", "sku": "CPL", "units": 17 }, "pick-SO-46517-0": { "order": "SO-46517-0", "site": "Tampa", "sku": "CPL", "units": 1 }, "pick-SO-48065-5": { "order": "SO-48065-5", "site": "Tampa", "sku": "CAP", "units": 5 }, "pick-SO-49822-3": { "order": "SO-49822-3", "site": "Tampa", "sku": "MDL", "units": 33 }, "pick-SO-85258-4": { "order": "SO-85258-4", "site": "Denver", "sku": "CPL", "units": 19 }, "pick-SO-99963-9": { "order": "SO-99963-9", "site": "Tampa", "sku": "CAP", "units": 10 } }, "inbound": { "PO-Albany-CAP": { "due": "2025-08-03", "open_units": 2, "site": "Albany", "sku": "CAP", "status": "confirmed" }, "PO-Albany-CPL": { "due": "2025-08-07", "open_units": 9, "site": "Albany", "sku": "CPL", "status": "confirmed" }, "PO-Albany-MDL": { "due": "2025-08-10", "open_units": 9, "site": "Albany", "sku": "MDL", "status": "confirmed" }, "PO-Albany-RNG": { "due": "2025-08-03", "open_units": 1, "site": "Albany", "sku": "RNG", "status": "proposed" }, "PO-Denver-CAP": { "due": "2025-08-09", "open_units": 4, "site": "Denver", "sku": "CAP", "status": "proposed" }, "PO-Denver-CPL": { "due": "2025-08-05", "open_units": 11, "site": "Denver", "sku": "CPL", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-05", "open_units": 10, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2025-08-01", "open_units": 2, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Tampa-CAP": { "due": "2025-08-08", "open_units": 1, "site": "Tampa", "sku": "CAP", "status": "proposed" }, "PO-Tampa-CPL": { "due": "2025-08-11", "open_units": 8, "site": "Tampa", "sku": "CPL", "status": "proposed" }, "PO-Tampa-MDL": { "due": "2025-08-04", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2025-08-06", "open_units": 5, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Albany-CAP": { "on_hand": 33, "reserved": 2, "safety": 7, "site": "Albany", "sku": "CAP" }, "Albany-CPL": { "on_hand": 39, "reserved": 2, "safety": 4, "site": "Albany", "sku": "CPL" }, "Albany-MDL": { "on_hand": 47, "reserved": 2, "safety": 5, "site": "Albany", "sku": "MDL" }, "Albany-RNG": { "on_hand": 33, "reserved": 3, "safety": 5, "site": "Albany", "sku": "RNG" }, "Denver-CAP": { "on_hand": 21, "reserved": 0, "safety": 4, "site": "Denver", "sku": "CAP" }, "Denver-CPL": { "on_hand": 43, "reserved": 23, "safety": 6, "site": "Denver", "sku": "CPL" }, "Denver-MDL": { "on_hand": 26, "reserved": 1, "safety": 6, "site": "Denver", "sku": "MDL" }, "Denver-RNG": { "on_hand": 22, "reserved": 3, "safety": 8, "site": "Denver", "sku": "RNG" }, "Tampa-CAP": { "on_hand": 32, "reserved": 17, "safety": 4, "site": "Tampa", "sku": "CAP" }, "Tampa-CPL": { "on_hand": 25, "reserved": 20, "safety": 5, "site": "Tampa", "sku": "CPL" }, "Tampa-MDL": { "on_hand": 45, "reserved": 37, "safety": 8, "site": "Tampa", "sku": "MDL" }, "Tampa-RNG": { "on_hand": 26, "reserved": 11, "safety": 7, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-21998-2": { "origin": "Tampa", "priority": 2, "promise": "2025-07-25", "sku": "RNG", "state": "allocated", "units": 11 }, "SO-26348-12": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "allocated", "units": 17 }, "SO-40281-11": { "origin": "Tampa", "priority": 2, "promise": "2025-08-03", "sku": "MDL", "state": "open", "units": 21 }, "SO-46517-0": { "origin": "Tampa", "priority": 1, "promise": "2025-07-29", "sku": "CPL", "state": "allocated", "units": 1 }, "SO-48065-5": { "origin": "Tampa", "priority": 2, "promise": "2025-07-26", "sku": "CAP", "state": "allocated", "units": 5 }, "SO-48464-10": { "origin": "Albany", "priority": 2, "promise": "2025-07-22", "sku": "RNG", "state": "open", "units": 17 }, "SO-49822-3": { "origin": "Tampa", "priority": 3, "promise": "2025-07-29", "sku": "MDL", "state": "allocated", "units": 33 }, "SO-52284-6": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "RNG", "state": "backorder", "units": 26 }, "SO-85258-4": { "origin": "Tampa", "priority": 1, "promise": "2025-07-27", "sku": "CPL", "state": "allocated", "units": 19 }, "SO-86810-7": { "origin": "Albany", "priority": 2, "promise": "2025-07-25", "sku": "MDL", "state": "shipped", "units": 22 }, "SO-87277-1": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "CAP", "state": "backorder", "units": 65 }, "SO-88635-8": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "backorder", "units": 16 }, "SO-99963-9": { "origin": "Tampa", "priority": 3, "promise": "2025-07-30", "sku": "CAP", "state": "allocated", "units": 10 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 }, "req-Tampa-CAP": { "site": "Tampa", "sku": "CAP", "status": "draft", "units": 65 }, "req-Tampa-CPL": { "site": "Tampa", "sku": "CPL", "status": "draft", "units": 16 }, "req-Tampa-RNG": { "site": "Tampa", "sku": "RNG", "status": "draft", "units": 26 } }}1234#!/bin/shset -eumkdir -p /logs/verifier /workspace/outputsexec python3 -B -I /tests/grade.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Albany-CAP": { "due": "2025-08-03", "open_units": 2, "site": "Albany", "sku": "CAP", "status": "confirmed" }, "PO-Albany-CPL": { "due": "2025-08-07", "open_units": 9, "site": "Albany", "sku": "CPL", "status": "confirmed" }, "PO-Albany-MDL": { "due": "2025-08-10", "open_units": 9, "site": "Albany", "sku": "MDL", "status": "confirmed" }, "PO-Albany-RNG": { "due": "2025-08-03", "open_units": 1, "site": "Albany", "sku": "RNG", "status": "proposed" }, "PO-Denver-CAP": { "due": "2025-08-09", "open_units": 4, "site": "Denver", "sku": "CAP", "status": "proposed" }, "PO-Denver-CPL": { "due": "2025-08-05", "open_units": 11, "site": "Denver", "sku": "CPL", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-05", "open_units": 10, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2025-08-01", "open_units": 2, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Tampa-CAP": { "due": "2025-08-08", "open_units": 1, "site": "Tampa", "sku": "CAP", "status": "proposed" }, "PO-Tampa-CPL": { "due": "2025-08-11", "open_units": 8, "site": "Tampa", "sku": "CPL", "status": "proposed" }, "PO-Tampa-MDL": { "due": "2025-08-04", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2025-08-06", "open_units": 5, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Albany-CAP": { "on_hand": 33, "reserved": 2, "safety": 7, "site": "Albany", "sku": "CAP" }, "Albany-CPL": { "on_hand": 39, "reserved": 2, "safety": 4, "site": "Albany", "sku": "CPL" }, "Albany-MDL": { "on_hand": 47, "reserved": 2, "safety": 5, "site": "Albany", "sku": "MDL" }, "Albany-RNG": { "on_hand": 33, "reserved": 3, "safety": 5, "site": "Albany", "sku": "RNG" }, "Denver-CAP": { "on_hand": 21, "reserved": 0, "safety": 4, "site": "Denver", "sku": "CAP" }, "Denver-CPL": { "on_hand": 43, "reserved": 4, "safety": 6, "site": "Denver", "sku": "CPL" }, "Denver-MDL": { "on_hand": 26, "reserved": 1, "safety": 6, "site": "Denver", "sku": "MDL" }, "Denver-RNG": { "on_hand": 22, "reserved": 3, "safety": 8, "site": "Denver", "sku": "RNG" }, "Tampa-CAP": { "on_hand": 32, "reserved": 2, "safety": 4, "site": "Tampa", "sku": "CAP" }, "Tampa-CPL": { "on_hand": 25, "reserved": 2, "safety": 5, "site": "Tampa", "sku": "CPL" }, "Tampa-MDL": { "on_hand": 45, "reserved": 4, "safety": 8, "site": "Tampa", "sku": "MDL" }, "Tampa-RNG": { "on_hand": 26, "reserved": 0, "safety": 7, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-21998-2": { "origin": "Tampa", "priority": 2, "promise": "2025-07-25", "sku": "RNG", "state": "open", "units": 11 }, "SO-26348-12": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "open", "units": 17 }, "SO-40281-11": { "origin": "Tampa", "priority": 2, "promise": "2025-08-03", "sku": "MDL", "state": "open", "units": 21 }, "SO-46517-0": { "origin": "Tampa", "priority": 1, "promise": "2025-07-29", "sku": "CPL", "state": "open", "units": 1 }, "SO-48065-5": { "origin": "Tampa", "priority": 2, "promise": "2025-07-26", "sku": "CAP", "state": "open", "units": 5 }, "SO-48464-10": { "origin": "Albany", "priority": 2, "promise": "2025-07-22", "sku": "RNG", "state": "open", "units": 17 }, "SO-49822-3": { "origin": "Tampa", "priority": 3, "promise": "2025-07-29", "sku": "MDL", "state": "open", "units": 33 }, "SO-52284-6": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "RNG", "state": "open", "units": 26 }, "SO-85258-4": { "origin": "Tampa", "priority": 1, "promise": "2025-07-27", "sku": "CPL", "state": "open", "units": 19 }, "SO-86810-7": { "origin": "Albany", "priority": 2, "promise": "2025-07-25", "sku": "MDL", "state": "shipped", "units": 22 }, "SO-87277-1": { "origin": "Tampa", "priority": 2, "promise": "2025-07-29", "sku": "CAP", "state": "open", "units": 65 }, "SO-88635-8": { "origin": "Tampa", "priority": 2, "promise": "2025-07-30", "sku": "CPL", "state": "open", "units": 16 }, "SO-99963-9": { "origin": "Tampa", "priority": 3, "promise": "2025-07-30", "sku": "CAP", "state": "open", "units": 10 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617181920212223242526"""Replay submitted mutations from the private verifier's initial state."""from types import ModuleTypeimport json
def check(spec, outputs, tests): replay = ModuleType('workflow_replay') exec(compile((tests/'replay.py').read_bytes(), 'replay.py', 'exec'), replay.__dict__) world = json.loads((tests/'world.json').read_text()) target = json.loads((tests/'target.json').read_text()) # Only fields whose starting and expected values differ may be changed. Attempts # to temporarily alter a protected field fail even when a later write restores it. allowed = { (app,key): {field for field,value in doc.items() if field not in world[app].get(key,{}) or not replay.same(world[app][key][field],value)} for app,records in target.items() for key,doc in records.items() } actions = replay.load_actions(outputs/'actions.jsonl') for event in actions: replay.apply(world,event) touched = set(event['fields']) if not touched <= allowed.get((event['app'],event['id']),set()): return False,'protected field or record write' if not replay.same(world,target): return False,'required business outcomes incomplete' return True,''12345678910111213141516171819202122232425262728{ "profile": "harbor-semantic-v1", "reward_key": "reward", "reward": { "range": [ 0, 1 ], "oracle_tolerance": 0, "floor_margin": 0.1 }, "resources": { "cpu": 1, "memory_mb": 4096, "disk_mb": 10240, "episode_timeout_s": 1800 }, "types": { "tags": [ "knowledge-work", "cross-app-workflows", "conditional-execution", "protected-state", "operations" ] }, "requires_credentials": false}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Denver-CAP": { "due": "2025-09-03", "open_units": 6, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-CLP": { "due": "2025-09-03", "open_units": 3, "site": "Denver", "sku": "CLP", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-28", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Fresno-CAP": { "due": "2025-08-28", "open_units": 1, "site": "Fresno", "sku": "CAP", "status": "confirmed" }, "PO-Fresno-CLP": { "due": "2025-08-31", "open_units": 11, "site": "Fresno", "sku": "CLP", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2025-08-27", "open_units": 1, "site": "Fresno", "sku": "MDL", "status": "confirmed" }, "PO-Waco-CAP": { "due": "2025-09-03", "open_units": 4, "site": "Waco", "sku": "CAP", "status": "proposed" }, "PO-Waco-CLP": { "due": "2025-08-24", "open_units": 3, "site": "Waco", "sku": "CLP", "status": "confirmed" }, "PO-Waco-MDL": { "due": "2025-08-30", "open_units": 11, "site": "Waco", "sku": "MDL", "status": "proposed" } }, "inventory": { "Denver-CAP": { "on_hand": 45, "reserved": 3, "safety": 5, "site": "Denver", "sku": "CAP" }, "Denver-CLP": { "on_hand": 13, "reserved": 4, "safety": 5, "site": "Denver", "sku": "CLP" }, "Denver-MDL": { "on_hand": 45, "reserved": 0, "safety": 4, "site": "Denver", "sku": "MDL" }, "Fresno-CAP": { "on_hand": 47, "reserved": 4, "safety": 4, "site": "Fresno", "sku": "CAP" }, "Fresno-CLP": { "on_hand": 12, "reserved": 5, "safety": 6, "site": "Fresno", "sku": "CLP" }, "Fresno-MDL": { "on_hand": 34, "reserved": 3, "safety": 5, "site": "Fresno", "sku": "MDL" }, "Waco-CAP": { "on_hand": 21, "reserved": 5, "safety": 6, "site": "Waco", "sku": "CAP" }, "Waco-CLP": { "on_hand": 16, "reserved": 1, "safety": 6, "site": "Waco", "sku": "CLP" }, "Waco-MDL": { "on_hand": 40, "reserved": 1, "safety": 4, "site": "Waco", "sku": "MDL" } }, "orders": { "SO-19710-5": { "origin": "Denver", "priority": 3, "promise": "2025-08-17", "sku": "CLP", "state": "open", "units": 29 }, "SO-19952-8": { "origin": "Denver", "priority": 3, "promise": "2025-08-26", "sku": "CLP", "state": "open", "units": 28 }, "SO-30246-6": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "open", "units": 12 }, "SO-43382-4": { "origin": "Denver", "priority": 2, "promise": "2025-08-19", "sku": "CAP", "state": "open", "units": 15 }, "SO-51642-11": { "origin": "Denver", "priority": 2, "promise": "2025-08-14", "sku": "CLP", "state": "open", "units": 14 }, "SO-63256-3": { "origin": "Denver", "priority": 3, "promise": "2025-08-20", "sku": "MDL", "state": "open", "units": 28 }, "SO-77376-2": { "origin": "Denver", "priority": 1, "promise": "2025-08-22", "sku": "CLP", "state": "open", "units": 16 }, "SO-80617-7": { "origin": "Denver", "priority": 3, "promise": "2025-08-28", "sku": "CAP", "state": "open", "units": 9 }, "SO-84856-9": { "origin": "Waco", "priority": 2, "promise": "2025-08-27", "sku": "MDL", "state": "open", "units": 26 }, "SO-89888-10": { "origin": "Waco", "priority": 1, "promise": "2025-08-15", "sku": "CAP", "state": "open", "units": 3 }, "SO-92513-0": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "open", "units": 1 }, "SO-94328-1": { "origin": "Denver", "priority": 2, "promise": "2025-08-22", "sku": "CAP", "state": "open", "units": 65 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617Release the overdue and due order queue at Denver as of 2025-08-23. Only open orders originating there with promise dates on or before the cutoff are in scope. Process in order of ascending priority number, then earliest promise date, then ascending order ID. The queue policy changes by client.
For each line first try Denver. Only the origin depot can supply this review. Available units equal on-hand less existing reservations and safety stock. Allocate a whole order at one site, with no splitting. Add its units to the selected inventory record's `reserved` total, update order `state` to `allocated`, and create dispatch record `pick-<order ID>` with `order`, `site`, `sku`, `units`. Otherwise set the order `state` to `backorder`.
At the end total all units newly backordered by SKU. Before requesting those units for Denver, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-08-30. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-<SKU>` with `site`, `sku`, `units` equal to that remainder, and `status` equal to `draft`. Preserve the inbound, historical and out-of-scope records and all other fields.
Use the offline app client at `/workspace/inputs/apps.py`. Call it with python3. Run`apps` to discover apps, `list APP` to see its records, or `get APP ID` for one record.Write with `update APP ID '{"field":"value"}'` or `create APP ID '{"field":"value"}'`.The client records successful writes in `/workspace/outputs/actions.jsonl`.Apply exactly the required changes. Other records and fields must remain untouched,including temporary changes. Actions take effect in the local simulation only.
## Deliverable
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in`/workspace/outputs/`; only that directory is graded. Leave the app action log in the outputs directory.12345678910111213141516{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-92513-0", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-94328-1", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-77376-2", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-63256-3", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43382-4", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-19710-5", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-30246-6", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-51642-11", "op": "update"}{"app": "inventory", "fields": {"reserved": 41}, "id": "Denver-MDL", "op": "update"}{"app": "inventory", "fields": {"reserved": 18}, "id": "Denver-CAP", "op": "update"}{"app": "dispatch", "fields": {"order": "SO-30246-6", "site": "Denver", "sku": "MDL", "units": 12}, "id": "pick-SO-30246-6", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-92513-0", "site": "Denver", "sku": "MDL", "units": 1}, "id": "pick-SO-92513-0", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-43382-4", "site": "Denver", "sku": "CAP", "units": 15}, "id": "pick-SO-43382-4", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-63256-3", "site": "Denver", "sku": "MDL", "units": 28}, "id": "pick-SO-63256-3", "op": "create"}{"app": "procurement", "fields": {"site": "Denver", "sku": "CLP", "status": "draft", "units": 59}, "id": "req-Denver-CLP", "op": "create"}{"app": "procurement", "fields": {"site": "Denver", "sku": "CAP", "status": "draft", "units": 65}, "id": "req-Denver-CAP", "op": "create"}1234#!/bin/shset -eumkdir -p /workspace/outputscp -R /solution/files/. /workspace/outputs/12345678910111213141516171819202122232425262728293031323334353637383940414243444546schema_version = "1.3"
[task]name = "apex-gap/autom-fulfillment-release-009"
[metadata.apex_gap]capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"]dataset = "Original simulated workflows"job = "operations"seed = 9source = "local/original-automation-workflows"source_revision = "1"source_split = "synthetic"source_task_id = "autom-fulfillment-release-009"template_family = "automation:fulfillment-release"workflow_template = "fulfillment-release"
[metadata.openenv_hf_sandbox]variant = "apex-gap-hfsandbox-v1"task_modified_for_hf_sandbox = truenetwork_enabled = true
[environment]docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"workdir = "/workspace"cpus = 1memory_mb = 4096build_timeout_sec = 600network_mode = "public"
[agent]timeout_sec = 1800network_mode = "public"
[verifier]timeout_sec = 600network_mode = "public"environment_mode = "separate"
[verifier.environment]network_mode = "public"cpus = 1memory_mb = 4096
[[artifacts]]source = "/workspace/outputs"123456789{ "checks": [ { "id": "business-outcomes", "type": "custom", "module": "world_check" } ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330"""Deterministic grader shared by converted knowledge-work tasks.
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects thesubmitted /workspace/outputs tree and writes a binary reward plus per-check details.No model calls and no network.
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}Check types: answer field of outputs/answer.json; kind = number|text|choice|date|bool|list xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules) xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values) file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)"""
import datetime as dtimport jsonimport reimport shutilimport subprocessimport sysimport tempfileimport unicodedatafrom pathlib import Path
OUT = Path("/workspace/outputs")TESTS = Path("/tests")LOGS = Path("/logs/verifier")
def norm_text(v): v = unicodedata.normalize("NFKC", str(v)).casefold() v = re.sub(r"[‘’“”]", "'", v) v = re.sub(r"[^\w%.$/-]+", " ", v) return " ".join(v.split()).strip(" .")
def to_number(v): if isinstance(v, bool): raise ValueError("bool") if isinstance(v, (int, float)): return float(v) s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-") neg = s.startswith("(") and s.endswith(")") s = s.strip("()").strip() pct = s.endswith("%") s = s.rstrip("%").strip() s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I) x = float(s) x = -x if neg else x return x / 100 if pct else x
def number_ok(got, want, rel, abs_): try: g = to_number(got) except (TypeError, ValueError): return False w = float(want) tol = max(abs_, rel * abs(w)) # "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which. candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g] return any(abs(c - w) <= tol for c in candidates)
def parse_date(v): if isinstance(v, (dt.date, dt.datetime)): return v if isinstance(v, dt.date) else v.date() s = str(v).strip() for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"): try: return dt.datetime.strptime(s, fmt).date() except ValueError: continue raise ValueError(s)
def check_answer(check, answers): key = check["field"] if key not in answers: return False, f"missing field {key!r}" got, want, kind = answers[key], check["value"], check.get("kind", "text") if kind == "number": ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01)) if not ok and check.get("percent_either"): ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or ( number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100) ) elif kind == "date": try: ok = parse_date(got) == parse_date(want) except ValueError: ok = False elif kind == "bool": g = norm_text(got) ok = g in {"yes", "true"} if want else g in {"no", "false"} elif kind == "choice": ok = norm_text(got) == norm_text(want) elif kind == "list": if not isinstance(got, list): return False, f"{key}: expected a JSON list" # Filenames may be given with a directory prefix; compare base names. base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1]) ok = sorted(base(x) for x in got) == sorted(base(x) for x in want) else: accepted = check.get("accept", [want]) ok = norm_text(got) in {norm_text(a) for a in accepted} return ok, "" if ok else f"{key}: got {got!r}"
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?><oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item></oor:items>"""
def recalc(path, tmp): dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}" dest.mkdir() profile = Path(tmp) / "lo-profile" if not profile.exists(): (profile / "user").mkdir(parents=True) (profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE) subprocess.run( ["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to", "xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=180, check=False, ) out = dest / (Path(path).stem + ".xlsx") return out if out.exists() else Path(path)
def cell_value(v): if isinstance(v, (int, float)) and not isinstance(v, bool): return round(float(v), 2) if isinstance(v, dt.datetime): return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0) if isinstance(v, dt.time): return v.strftime("%H:%M") if isinstance(v, str): try: return round(float(v), 2) except ValueError: return v.strip() return v
def time_of(v): """A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells.""" if isinstance(v, dt.time): v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400 if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1: return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M") return None
def same_cell(a, b): if isinstance(a, dt.time) is not isinstance(b, dt.time): n = b if isinstance(a, dt.time) else a if time_of(n) is not None: # a time against a plain day fraction return time_of(a) == time_of(b) a, b = cell_value(a), cell_value(b) if a in (None, "") and b in (None, ""): return True return type(a) is type(b) and a == b
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
def is_error(v): return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
def cells(rng): if ":" not in rng: return [rng] from openpyxl.utils import range_boundaries, get_column_letter
c1, r1, c2, r2 = range_boundaries(rng) return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
def load(path, tmp): import openpyxl
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
def check_xlsx_range(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) tgt = TESTS / check["target"] if tgt not in cache: cache[tgt] = load(tgt, tmp) got, want = cache[sub], cache[tgt] cached = None # the target's stored (Excel-computed) values, read only when Calc errs for sheet, rng in check["ranges"]: sheet = sheet or want.sheetnames[0] if sheet not in got.sheetnames: return False, f"sheet {sheet!r} missing" for name in cells(rng): w = want[sheet][name].value if is_error(w): # LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4). # The value Excel stored is the intended answer. if cached is None: import openpyxl
cached = openpyxl.load_workbook(tgt, data_only=True) c = cached[sheet][name].value if sheet in cached.sheetnames else None if c is not None and not is_error(c): w = c if not same_cell(w, got[sheet][name].value): return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}" return True, ""
def check_xlsx_cell(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) wb = cache[sub] if check["sheet"] not in wb.sheetnames: return False, f"sheet {check['sheet']!r} missing" got = wb[check["sheet"]][check["cell"]].value want = check["value"] if isinstance(want, (int, float)): # alt_values: other accepted golds where the source admits more than one reading. ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01)) for w in [want, *check.get("alt_values", [])]) else: ok = norm_text(got) == norm_text(want) return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
def text_of(path): suffix = path.suffix.lower() if suffix == ".docx": import docx
d = docx.Document(path) parts = [p.text for p in d.paragraphs] for t in d.tables: parts += [c.text for row in t.rows for c in row.cells] return "\n".join(parts) if suffix == ".pdf": import pdfplumber
with pdfplumber.open(path) as pdf: return "\n".join(page.extract_text() or "" for page in pdf.pages) return path.read_text(errors="replace")
def check_file_contains(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" text = text_of(sub) hay = text if check.get("case_sensitive") else text.casefold() for needle in check["needles"]: n = needle if check.get("case_sensitive") else needle.casefold() if n not in hay: return False, f"{check['file']} lacks {needle!r}" return True, ""
def main(): LOGS.mkdir(parents=True, exist_ok=True) reward_path = LOGS / "reward.txt" reward_path.write_text("0\n") spec = json.loads((TESTS / "expected.json").read_text()) answers, details = {}, [] answer_file = OUT / "answer.json" if answer_file.is_file(): try: answers = json.loads(answer_file.read_text()) if not isinstance(answers, dict): answers = {} except json.JSONDecodeError: answers = {} tmp = tempfile.mkdtemp() cache = {} try: for check in spec["checks"]: try: if check["type"] == "answer": ok, why = check_answer(check, answers) elif check["type"] == "xlsx_range": ok, why = check_xlsx_range(check, tmp, cache) elif check["type"] == "xlsx_cell": ok, why = check_xlsx_cell(check, tmp, cache) elif check["type"] == "file_contains": ok, why = check_file_contains(check, tmp, cache) elif check["type"] == "custom": import importlib.util
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py") mod = importlib.util.module_from_spec(spec_) spec_.loader.exec_module(mod) ok, why = mod.check(check, OUT, TESTS) else: ok, why = False, f"unknown check type {check['type']}" except Exception as exc: # a malformed submission fails the check, not the grader ok, why = False, f"{type(exc).__name__}: {exc}" details.append({"id": check["id"], "passed": ok, "detail": why}) finally: shutil.rmtree(tmp, ignore_errors=True) passed = sum(d["passed"] for d in details) total = len(details) reward = 1 if total and passed == total else 0 (LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1)) reward_path.write_text(f"{reward}\n") print(f"{passed}/{total} checks passed; reward {reward}")
if __name__ == "__main__": sys.exit(main())1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" }, "pick-SO-30246-6": { "order": "SO-30246-6", "site": "Denver", "sku": "MDL", "units": 12 }, "pick-SO-43382-4": { "order": "SO-43382-4", "site": "Denver", "sku": "CAP", "units": 15 }, "pick-SO-63256-3": { "order": "SO-63256-3", "site": "Denver", "sku": "MDL", "units": 28 }, "pick-SO-92513-0": { "order": "SO-92513-0", "site": "Denver", "sku": "MDL", "units": 1 } }, "inbound": { "PO-Denver-CAP": { "due": "2025-09-03", "open_units": 6, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-CLP": { "due": "2025-09-03", "open_units": 3, "site": "Denver", "sku": "CLP", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-28", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Fresno-CAP": { "due": "2025-08-28", "open_units": 1, "site": "Fresno", "sku": "CAP", "status": "confirmed" }, "PO-Fresno-CLP": { "due": "2025-08-31", "open_units": 11, "site": "Fresno", "sku": "CLP", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2025-08-27", "open_units": 1, "site": "Fresno", "sku": "MDL", "status": "confirmed" }, "PO-Waco-CAP": { "due": "2025-09-03", "open_units": 4, "site": "Waco", "sku": "CAP", "status": "proposed" }, "PO-Waco-CLP": { "due": "2025-08-24", "open_units": 3, "site": "Waco", "sku": "CLP", "status": "confirmed" }, "PO-Waco-MDL": { "due": "2025-08-30", "open_units": 11, "site": "Waco", "sku": "MDL", "status": "proposed" } }, "inventory": { "Denver-CAP": { "on_hand": 45, "reserved": 18, "safety": 5, "site": "Denver", "sku": "CAP" }, "Denver-CLP": { "on_hand": 13, "reserved": 4, "safety": 5, "site": "Denver", "sku": "CLP" }, "Denver-MDL": { "on_hand": 45, "reserved": 41, "safety": 4, "site": "Denver", "sku": "MDL" }, "Fresno-CAP": { "on_hand": 47, "reserved": 4, "safety": 4, "site": "Fresno", "sku": "CAP" }, "Fresno-CLP": { "on_hand": 12, "reserved": 5, "safety": 6, "site": "Fresno", "sku": "CLP" }, "Fresno-MDL": { "on_hand": 34, "reserved": 3, "safety": 5, "site": "Fresno", "sku": "MDL" }, "Waco-CAP": { "on_hand": 21, "reserved": 5, "safety": 6, "site": "Waco", "sku": "CAP" }, "Waco-CLP": { "on_hand": 16, "reserved": 1, "safety": 6, "site": "Waco", "sku": "CLP" }, "Waco-MDL": { "on_hand": 40, "reserved": 1, "safety": 4, "site": "Waco", "sku": "MDL" } }, "orders": { "SO-19710-5": { "origin": "Denver", "priority": 3, "promise": "2025-08-17", "sku": "CLP", "state": "backorder", "units": 29 }, "SO-19952-8": { "origin": "Denver", "priority": 3, "promise": "2025-08-26", "sku": "CLP", "state": "open", "units": 28 }, "SO-30246-6": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "allocated", "units": 12 }, "SO-43382-4": { "origin": "Denver", "priority": 2, "promise": "2025-08-19", "sku": "CAP", "state": "allocated", "units": 15 }, "SO-51642-11": { "origin": "Denver", "priority": 2, "promise": "2025-08-14", "sku": "CLP", "state": "backorder", "units": 14 }, "SO-63256-3": { "origin": "Denver", "priority": 3, "promise": "2025-08-20", "sku": "MDL", "state": "allocated", "units": 28 }, "SO-77376-2": { "origin": "Denver", "priority": 1, "promise": "2025-08-22", "sku": "CLP", "state": "backorder", "units": 16 }, "SO-80617-7": { "origin": "Denver", "priority": 3, "promise": "2025-08-28", "sku": "CAP", "state": "open", "units": 9 }, "SO-84856-9": { "origin": "Waco", "priority": 2, "promise": "2025-08-27", "sku": "MDL", "state": "open", "units": 26 }, "SO-89888-10": { "origin": "Waco", "priority": 1, "promise": "2025-08-15", "sku": "CAP", "state": "open", "units": 3 }, "SO-92513-0": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "allocated", "units": 1 }, "SO-94328-1": { "origin": "Denver", "priority": 2, "promise": "2025-08-22", "sku": "CAP", "state": "backorder", "units": 65 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 }, "req-Denver-CAP": { "site": "Denver", "sku": "CAP", "status": "draft", "units": 65 }, "req-Denver-CLP": { "site": "Denver", "sku": "CLP", "status": "draft", "units": 59 } }}1234#!/bin/shset -eumkdir -p /logs/verifier /workspace/outputsexec python3 -B -I /tests/grade.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Denver-CAP": { "due": "2025-09-03", "open_units": 6, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-CLP": { "due": "2025-09-03", "open_units": 3, "site": "Denver", "sku": "CLP", "status": "proposed" }, "PO-Denver-MDL": { "due": "2025-08-28", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "confirmed" }, "PO-Fresno-CAP": { "due": "2025-08-28", "open_units": 1, "site": "Fresno", "sku": "CAP", "status": "confirmed" }, "PO-Fresno-CLP": { "due": "2025-08-31", "open_units": 11, "site": "Fresno", "sku": "CLP", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2025-08-27", "open_units": 1, "site": "Fresno", "sku": "MDL", "status": "confirmed" }, "PO-Waco-CAP": { "due": "2025-09-03", "open_units": 4, "site": "Waco", "sku": "CAP", "status": "proposed" }, "PO-Waco-CLP": { "due": "2025-08-24", "open_units": 3, "site": "Waco", "sku": "CLP", "status": "confirmed" }, "PO-Waco-MDL": { "due": "2025-08-30", "open_units": 11, "site": "Waco", "sku": "MDL", "status": "proposed" } }, "inventory": { "Denver-CAP": { "on_hand": 45, "reserved": 3, "safety": 5, "site": "Denver", "sku": "CAP" }, "Denver-CLP": { "on_hand": 13, "reserved": 4, "safety": 5, "site": "Denver", "sku": "CLP" }, "Denver-MDL": { "on_hand": 45, "reserved": 0, "safety": 4, "site": "Denver", "sku": "MDL" }, "Fresno-CAP": { "on_hand": 47, "reserved": 4, "safety": 4, "site": "Fresno", "sku": "CAP" }, "Fresno-CLP": { "on_hand": 12, "reserved": 5, "safety": 6, "site": "Fresno", "sku": "CLP" }, "Fresno-MDL": { "on_hand": 34, "reserved": 3, "safety": 5, "site": "Fresno", "sku": "MDL" }, "Waco-CAP": { "on_hand": 21, "reserved": 5, "safety": 6, "site": "Waco", "sku": "CAP" }, "Waco-CLP": { "on_hand": 16, "reserved": 1, "safety": 6, "site": "Waco", "sku": "CLP" }, "Waco-MDL": { "on_hand": 40, "reserved": 1, "safety": 4, "site": "Waco", "sku": "MDL" } }, "orders": { "SO-19710-5": { "origin": "Denver", "priority": 3, "promise": "2025-08-17", "sku": "CLP", "state": "open", "units": 29 }, "SO-19952-8": { "origin": "Denver", "priority": 3, "promise": "2025-08-26", "sku": "CLP", "state": "open", "units": 28 }, "SO-30246-6": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "open", "units": 12 }, "SO-43382-4": { "origin": "Denver", "priority": 2, "promise": "2025-08-19", "sku": "CAP", "state": "open", "units": 15 }, "SO-51642-11": { "origin": "Denver", "priority": 2, "promise": "2025-08-14", "sku": "CLP", "state": "open", "units": 14 }, "SO-63256-3": { "origin": "Denver", "priority": 3, "promise": "2025-08-20", "sku": "MDL", "state": "open", "units": 28 }, "SO-77376-2": { "origin": "Denver", "priority": 1, "promise": "2025-08-22", "sku": "CLP", "state": "open", "units": 16 }, "SO-80617-7": { "origin": "Denver", "priority": 3, "promise": "2025-08-28", "sku": "CAP", "state": "open", "units": 9 }, "SO-84856-9": { "origin": "Waco", "priority": 2, "promise": "2025-08-27", "sku": "MDL", "state": "open", "units": 26 }, "SO-89888-10": { "origin": "Waco", "priority": 1, "promise": "2025-08-15", "sku": "CAP", "state": "open", "units": 3 }, "SO-92513-0": { "origin": "Denver", "priority": 1, "promise": "2025-08-18", "sku": "MDL", "state": "open", "units": 1 }, "SO-94328-1": { "origin": "Denver", "priority": 2, "promise": "2025-08-22", "sku": "CAP", "state": "open", "units": 65 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617181920212223242526"""Replay submitted mutations from the private verifier's initial state."""from types import ModuleTypeimport json
def check(spec, outputs, tests): replay = ModuleType('workflow_replay') exec(compile((tests/'replay.py').read_bytes(), 'replay.py', 'exec'), replay.__dict__) world = json.loads((tests/'world.json').read_text()) target = json.loads((tests/'target.json').read_text()) # Only fields whose starting and expected values differ may be changed. Attempts # to temporarily alter a protected field fail even when a later write restores it. allowed = { (app,key): {field for field,value in doc.items() if field not in world[app].get(key,{}) or not replay.same(world[app][key][field],value)} for app,records in target.items() for key,doc in records.items() } actions = replay.load_actions(outputs/'actions.jsonl') for event in actions: replay.apply(world,event) touched = set(event['fields']) if not touched <= allowed.get((event['app'],event['id']),set()): return False,'protected field or record write' if not replay.same(world,target): return False,'required business outcomes incomplete' return True,''12345678910111213141516171819202122232425262728{ "profile": "harbor-semantic-v1", "reward_key": "reward", "reward": { "range": [ 0, 1 ], "oracle_tolerance": 0, "floor_margin": 0.1 }, "resources": { "cpu": 1, "memory_mb": 4096, "disk_mb": 10240, "episode_timeout_s": 1800 }, "types": { "tags": [ "knowledge-work", "cross-app-workflows", "conditional-execution", "protected-state", "operations" ] }, "requires_credentials": false}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Denver-MDL": { "due": "2026-01-17", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "proposed" }, "PO-Denver-PLT": { "due": "2026-01-17", "open_units": 12, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2026-01-12", "open_units": 5, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2026-01-10", "open_units": 6, "site": "Fresno", "sku": "MDL", "status": "proposed" }, "PO-Fresno-PLT": { "due": "2026-01-09", "open_units": 11, "site": "Fresno", "sku": "PLT", "status": "confirmed" }, "PO-Fresno-RNG": { "due": "2026-01-19", "open_units": 7, "site": "Fresno", "sku": "RNG", "status": "confirmed" }, "PO-Tampa-MDL": { "due": "2026-01-14", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-PLT": { "due": "2026-01-17", "open_units": 6, "site": "Tampa", "sku": "PLT", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2026-01-09", "open_units": 12, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Denver-MDL": { "on_hand": 24, "reserved": 1, "safety": 4, "site": "Denver", "sku": "MDL" }, "Denver-PLT": { "on_hand": 31, "reserved": 2, "safety": 8, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 16, "reserved": 2, "safety": 5, "site": "Denver", "sku": "RNG" }, "Fresno-MDL": { "on_hand": 25, "reserved": 2, "safety": 4, "site": "Fresno", "sku": "MDL" }, "Fresno-PLT": { "on_hand": 17, "reserved": 3, "safety": 7, "site": "Fresno", "sku": "PLT" }, "Fresno-RNG": { "on_hand": 41, "reserved": 5, "safety": 4, "site": "Fresno", "sku": "RNG" }, "Tampa-MDL": { "on_hand": 13, "reserved": 1, "safety": 5, "site": "Tampa", "sku": "MDL" }, "Tampa-PLT": { "on_hand": 18, "reserved": 4, "safety": 7, "site": "Tampa", "sku": "PLT" }, "Tampa-RNG": { "on_hand": 22, "reserved": 3, "safety": 4, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-18277-5": { "origin": "Denver", "priority": 3, "promise": "2026-01-02", "sku": "MDL", "state": "open", "units": 21 }, "SO-27339-10": { "origin": "Fresno", "priority": 3, "promise": "2026-01-07", "sku": "RNG", "state": "open", "units": 5 }, "SO-36828-1": { "origin": "Denver", "priority": 2, "promise": "2026-01-02", "sku": "RNG", "state": "open", "units": 65 }, "SO-51525-12": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "PLT", "state": "open", "units": 20 }, "SO-70516-0": { "origin": "Denver", "priority": 1, "promise": "2026-01-01", "sku": "PLT", "state": "open", "units": 1 }, "SO-71728-2": { "origin": "Denver", "priority": 2, "promise": "2026-01-04", "sku": "MDL", "state": "open", "units": 22 }, "SO-71772-4": { "origin": "Denver", "priority": 2, "promise": "2026-01-05", "sku": "RNG", "state": "open", "units": 9 }, "SO-83517-6": { "origin": "Denver", "priority": 1, "promise": "2026-01-04", "sku": "PLT", "state": "open", "units": 9 }, "SO-84053-8": { "origin": "Denver", "priority": 3, "promise": "2025-12-31", "sku": "MDL", "state": "shipped", "units": 17 }, "SO-88274-11": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "MDL", "state": "open", "units": 13 }, "SO-89015-7": { "origin": "Denver", "priority": 3, "promise": "2026-01-08", "sku": "RNG", "state": "shipped", "units": 33 }, "SO-95590-9": { "origin": "Denver", "priority": 1, "promise": "2025-12-30", "sku": "PLT", "state": "open", "units": 13 }, "SO-99656-3": { "origin": "Denver", "priority": 3, "promise": "2026-01-07", "sku": "PLT", "state": "open", "units": 9 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617Release the overdue and due order queue at Denver as of 2026-01-08. Only open orders originating there with promise dates on or before the cutoff are in scope. Process in order of ascending priority number, then earliest promise date, then ascending order ID. The queue policy changes by client.
For each line first try Denver. Only the origin depot can supply this review. Available units equal on-hand less existing reservations and safety stock. Allocate a whole order at one site, with no splitting. Add its units to the selected inventory record's `reserved` total, update order `state` to `allocated`, and create dispatch record `pick-<order ID>` with `order`, `site`, `sku`, `units`. Otherwise set the order `state` to `backorder`.
At the end total all units newly backordered by SKU. Before requesting those units for Denver, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-01-15. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-<SKU>` with `site`, `sku`, `units` equal to that remainder, and `status` equal to `draft`. Preserve the inbound, historical and out-of-scope records and all other fields.
Use the offline app client at `/workspace/inputs/apps.py`. Call it with python3. Run`apps` to discover apps, `list APP` to see its records, or `get APP ID` for one record.Write with `update APP ID '{"field":"value"}'` or `create APP ID '{"field":"value"}'`.The client records successful writes in `/workspace/outputs/actions.jsonl`.Apply exactly the required changes. Other records and fields must remain untouched,including temporary changes. Actions take effect in the local simulation only.
## Deliverable
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in`/workspace/outputs/`; only that directory is graded. Leave the app action log in the outputs directory.12345678910111213141516{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-70516-0", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-36828-1", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-71728-2", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-99656-3", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-71772-4", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-18277-5", "op": "update"}{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-83517-6", "op": "update"}{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-95590-9", "op": "update"}{"app": "inventory", "fields": {"reserved": 16}, "id": "Denver-PLT", "op": "update"}{"app": "inventory", "fields": {"reserved": 11}, "id": "Denver-RNG", "op": "update"}{"app": "dispatch", "fields": {"order": "SO-95590-9", "site": "Denver", "sku": "PLT", "units": 13}, "id": "pick-SO-95590-9", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-70516-0", "site": "Denver", "sku": "PLT", "units": 1}, "id": "pick-SO-70516-0", "op": "create"}{"app": "dispatch", "fields": {"order": "SO-71772-4", "site": "Denver", "sku": "RNG", "units": 9}, "id": "pick-SO-71772-4", "op": "create"}{"app": "procurement", "fields": {"site": "Denver", "sku": "PLT", "status": "draft", "units": 18}, "id": "req-Denver-PLT", "op": "create"}{"app": "procurement", "fields": {"site": "Denver", "sku": "RNG", "status": "draft", "units": 65}, "id": "req-Denver-RNG", "op": "create"}{"app": "procurement", "fields": {"site": "Denver", "sku": "MDL", "status": "draft", "units": 43}, "id": "req-Denver-MDL", "op": "create"}1234#!/bin/shset -eumkdir -p /workspace/outputscp -R /solution/files/. /workspace/outputs/12345678910111213141516171819202122232425262728293031323334353637383940414243444546schema_version = "1.3"
[task]name = "apex-gap/autom-fulfillment-release-015"
[metadata.apex_gap]capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"]dataset = "Original simulated workflows"job = "operations"seed = 15source = "local/original-automation-workflows"source_revision = "1"source_split = "synthetic"source_task_id = "autom-fulfillment-release-015"template_family = "automation:fulfillment-release"workflow_template = "fulfillment-release"
[metadata.openenv_hf_sandbox]variant = "apex-gap-hfsandbox-v1"task_modified_for_hf_sandbox = truenetwork_enabled = true
[environment]docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"workdir = "/workspace"cpus = 1memory_mb = 4096build_timeout_sec = 600network_mode = "public"
[agent]timeout_sec = 1800network_mode = "public"
[verifier]timeout_sec = 600network_mode = "public"environment_mode = "separate"
[verifier.environment]network_mode = "public"cpus = 1memory_mb = 4096
[[artifacts]]source = "/workspace/outputs"123456789{ "checks": [ { "id": "business-outcomes", "type": "custom", "module": "world_check" } ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330"""Deterministic grader shared by converted knowledge-work tasks.
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects thesubmitted /workspace/outputs tree and writes a binary reward plus per-check details.No model calls and no network.
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}Check types: answer field of outputs/answer.json; kind = number|text|choice|date|bool|list xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules) xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values) file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)"""
import datetime as dtimport jsonimport reimport shutilimport subprocessimport sysimport tempfileimport unicodedatafrom pathlib import Path
OUT = Path("/workspace/outputs")TESTS = Path("/tests")LOGS = Path("/logs/verifier")
def norm_text(v): v = unicodedata.normalize("NFKC", str(v)).casefold() v = re.sub(r"[‘’“”]", "'", v) v = re.sub(r"[^\w%.$/-]+", " ", v) return " ".join(v.split()).strip(" .")
def to_number(v): if isinstance(v, bool): raise ValueError("bool") if isinstance(v, (int, float)): return float(v) s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-") neg = s.startswith("(") and s.endswith(")") s = s.strip("()").strip() pct = s.endswith("%") s = s.rstrip("%").strip() s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I) x = float(s) x = -x if neg else x return x / 100 if pct else x
def number_ok(got, want, rel, abs_): try: g = to_number(got) except (TypeError, ValueError): return False w = float(want) tol = max(abs_, rel * abs(w)) # "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which. candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g] return any(abs(c - w) <= tol for c in candidates)
def parse_date(v): if isinstance(v, (dt.date, dt.datetime)): return v if isinstance(v, dt.date) else v.date() s = str(v).strip() for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"): try: return dt.datetime.strptime(s, fmt).date() except ValueError: continue raise ValueError(s)
def check_answer(check, answers): key = check["field"] if key not in answers: return False, f"missing field {key!r}" got, want, kind = answers[key], check["value"], check.get("kind", "text") if kind == "number": ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01)) if not ok and check.get("percent_either"): ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or ( number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100) ) elif kind == "date": try: ok = parse_date(got) == parse_date(want) except ValueError: ok = False elif kind == "bool": g = norm_text(got) ok = g in {"yes", "true"} if want else g in {"no", "false"} elif kind == "choice": ok = norm_text(got) == norm_text(want) elif kind == "list": if not isinstance(got, list): return False, f"{key}: expected a JSON list" # Filenames may be given with a directory prefix; compare base names. base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1]) ok = sorted(base(x) for x in got) == sorted(base(x) for x in want) else: accepted = check.get("accept", [want]) ok = norm_text(got) in {norm_text(a) for a in accepted} return ok, "" if ok else f"{key}: got {got!r}"
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?><oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item><item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item></oor:items>"""
def recalc(path, tmp): dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}" dest.mkdir() profile = Path(tmp) / "lo-profile" if not profile.exists(): (profile / "user").mkdir(parents=True) (profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE) subprocess.run( ["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to", "xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=180, check=False, ) out = dest / (Path(path).stem + ".xlsx") return out if out.exists() else Path(path)
def cell_value(v): if isinstance(v, (int, float)) and not isinstance(v, bool): return round(float(v), 2) if isinstance(v, dt.datetime): return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0) if isinstance(v, dt.time): return v.strftime("%H:%M") if isinstance(v, str): try: return round(float(v), 2) except ValueError: return v.strip() return v
def time_of(v): """A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells.""" if isinstance(v, dt.time): v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400 if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1: return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M") return None
def same_cell(a, b): if isinstance(a, dt.time) is not isinstance(b, dt.time): n = b if isinstance(a, dt.time) else a if time_of(n) is not None: # a time against a plain day fraction return time_of(a) == time_of(b) a, b = cell_value(a), cell_value(b) if a in (None, "") and b in (None, ""): return True return type(a) is type(b) and a == b
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
def is_error(v): return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
def cells(rng): if ":" not in rng: return [rng] from openpyxl.utils import range_boundaries, get_column_letter
c1, r1, c2, r2 = range_boundaries(rng) return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
def load(path, tmp): import openpyxl
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
def check_xlsx_range(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) tgt = TESTS / check["target"] if tgt not in cache: cache[tgt] = load(tgt, tmp) got, want = cache[sub], cache[tgt] cached = None # the target's stored (Excel-computed) values, read only when Calc errs for sheet, rng in check["ranges"]: sheet = sheet or want.sheetnames[0] if sheet not in got.sheetnames: return False, f"sheet {sheet!r} missing" for name in cells(rng): w = want[sheet][name].value if is_error(w): # LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4). # The value Excel stored is the intended answer. if cached is None: import openpyxl
cached = openpyxl.load_workbook(tgt, data_only=True) c = cached[sheet][name].value if sheet in cached.sheetnames else None if c is not None and not is_error(c): w = c if not same_cell(w, got[sheet][name].value): return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}" return True, ""
def check_xlsx_cell(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" if sub not in cache: cache[sub] = load(sub, tmp) wb = cache[sub] if check["sheet"] not in wb.sheetnames: return False, f"sheet {check['sheet']!r} missing" got = wb[check["sheet"]][check["cell"]].value want = check["value"] if isinstance(want, (int, float)): # alt_values: other accepted golds where the source admits more than one reading. ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01)) for w in [want, *check.get("alt_values", [])]) else: ok = norm_text(got) == norm_text(want) return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
def text_of(path): suffix = path.suffix.lower() if suffix == ".docx": import docx
d = docx.Document(path) parts = [p.text for p in d.paragraphs] for t in d.tables: parts += [c.text for row in t.rows for c in row.cells] return "\n".join(parts) if suffix == ".pdf": import pdfplumber
with pdfplumber.open(path) as pdf: return "\n".join(page.extract_text() or "" for page in pdf.pages) return path.read_text(errors="replace")
def check_file_contains(check, tmp, cache): sub = OUT / check["file"] if not sub.is_file(): return False, f"missing output {check['file']}" text = text_of(sub) hay = text if check.get("case_sensitive") else text.casefold() for needle in check["needles"]: n = needle if check.get("case_sensitive") else needle.casefold() if n not in hay: return False, f"{check['file']} lacks {needle!r}" return True, ""
def main(): LOGS.mkdir(parents=True, exist_ok=True) reward_path = LOGS / "reward.txt" reward_path.write_text("0\n") spec = json.loads((TESTS / "expected.json").read_text()) answers, details = {}, [] answer_file = OUT / "answer.json" if answer_file.is_file(): try: answers = json.loads(answer_file.read_text()) if not isinstance(answers, dict): answers = {} except json.JSONDecodeError: answers = {} tmp = tempfile.mkdtemp() cache = {} try: for check in spec["checks"]: try: if check["type"] == "answer": ok, why = check_answer(check, answers) elif check["type"] == "xlsx_range": ok, why = check_xlsx_range(check, tmp, cache) elif check["type"] == "xlsx_cell": ok, why = check_xlsx_cell(check, tmp, cache) elif check["type"] == "file_contains": ok, why = check_file_contains(check, tmp, cache) elif check["type"] == "custom": import importlib.util
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py") mod = importlib.util.module_from_spec(spec_) spec_.loader.exec_module(mod) ok, why = mod.check(check, OUT, TESTS) else: ok, why = False, f"unknown check type {check['type']}" except Exception as exc: # a malformed submission fails the check, not the grader ok, why = False, f"{type(exc).__name__}: {exc}" details.append({"id": check["id"], "passed": ok, "detail": why}) finally: shutil.rmtree(tmp, ignore_errors=True) passed = sum(d["passed"] for d in details) total = len(details) reward = 1 if total and passed == total else 0 (LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1)) reward_path.write_text(f"{reward}\n") print(f"{passed}/{total} checks passed; reward {reward}")
if __name__ == "__main__": sys.exit(main())1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" }, "pick-SO-70516-0": { "order": "SO-70516-0", "site": "Denver", "sku": "PLT", "units": 1 }, "pick-SO-71772-4": { "order": "SO-71772-4", "site": "Denver", "sku": "RNG", "units": 9 }, "pick-SO-95590-9": { "order": "SO-95590-9", "site": "Denver", "sku": "PLT", "units": 13 } }, "inbound": { "PO-Denver-MDL": { "due": "2026-01-17", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "proposed" }, "PO-Denver-PLT": { "due": "2026-01-17", "open_units": 12, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2026-01-12", "open_units": 5, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2026-01-10", "open_units": 6, "site": "Fresno", "sku": "MDL", "status": "proposed" }, "PO-Fresno-PLT": { "due": "2026-01-09", "open_units": 11, "site": "Fresno", "sku": "PLT", "status": "confirmed" }, "PO-Fresno-RNG": { "due": "2026-01-19", "open_units": 7, "site": "Fresno", "sku": "RNG", "status": "confirmed" }, "PO-Tampa-MDL": { "due": "2026-01-14", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-PLT": { "due": "2026-01-17", "open_units": 6, "site": "Tampa", "sku": "PLT", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2026-01-09", "open_units": 12, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Denver-MDL": { "on_hand": 24, "reserved": 1, "safety": 4, "site": "Denver", "sku": "MDL" }, "Denver-PLT": { "on_hand": 31, "reserved": 16, "safety": 8, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 16, "reserved": 11, "safety": 5, "site": "Denver", "sku": "RNG" }, "Fresno-MDL": { "on_hand": 25, "reserved": 2, "safety": 4, "site": "Fresno", "sku": "MDL" }, "Fresno-PLT": { "on_hand": 17, "reserved": 3, "safety": 7, "site": "Fresno", "sku": "PLT" }, "Fresno-RNG": { "on_hand": 41, "reserved": 5, "safety": 4, "site": "Fresno", "sku": "RNG" }, "Tampa-MDL": { "on_hand": 13, "reserved": 1, "safety": 5, "site": "Tampa", "sku": "MDL" }, "Tampa-PLT": { "on_hand": 18, "reserved": 4, "safety": 7, "site": "Tampa", "sku": "PLT" }, "Tampa-RNG": { "on_hand": 22, "reserved": 3, "safety": 4, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-18277-5": { "origin": "Denver", "priority": 3, "promise": "2026-01-02", "sku": "MDL", "state": "backorder", "units": 21 }, "SO-27339-10": { "origin": "Fresno", "priority": 3, "promise": "2026-01-07", "sku": "RNG", "state": "open", "units": 5 }, "SO-36828-1": { "origin": "Denver", "priority": 2, "promise": "2026-01-02", "sku": "RNG", "state": "backorder", "units": 65 }, "SO-51525-12": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "PLT", "state": "open", "units": 20 }, "SO-70516-0": { "origin": "Denver", "priority": 1, "promise": "2026-01-01", "sku": "PLT", "state": "allocated", "units": 1 }, "SO-71728-2": { "origin": "Denver", "priority": 2, "promise": "2026-01-04", "sku": "MDL", "state": "backorder", "units": 22 }, "SO-71772-4": { "origin": "Denver", "priority": 2, "promise": "2026-01-05", "sku": "RNG", "state": "allocated", "units": 9 }, "SO-83517-6": { "origin": "Denver", "priority": 1, "promise": "2026-01-04", "sku": "PLT", "state": "backorder", "units": 9 }, "SO-84053-8": { "origin": "Denver", "priority": 3, "promise": "2025-12-31", "sku": "MDL", "state": "shipped", "units": 17 }, "SO-88274-11": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "MDL", "state": "open", "units": 13 }, "SO-89015-7": { "origin": "Denver", "priority": 3, "promise": "2026-01-08", "sku": "RNG", "state": "shipped", "units": 33 }, "SO-95590-9": { "origin": "Denver", "priority": 1, "promise": "2025-12-30", "sku": "PLT", "state": "allocated", "units": 13 }, "SO-99656-3": { "origin": "Denver", "priority": 3, "promise": "2026-01-07", "sku": "PLT", "state": "backorder", "units": 9 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 }, "req-Denver-MDL": { "site": "Denver", "sku": "MDL", "status": "draft", "units": 43 }, "req-Denver-PLT": { "site": "Denver", "sku": "PLT", "status": "draft", "units": 18 }, "req-Denver-RNG": { "site": "Denver", "sku": "RNG", "status": "draft", "units": 65 } }}1234#!/bin/shset -eumkdir -p /logs/verifier /workspace/outputsexec python3 -B -I /tests/grade.py123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Denver-MDL": { "due": "2026-01-17", "open_units": 1, "site": "Denver", "sku": "MDL", "status": "proposed" }, "PO-Denver-PLT": { "due": "2026-01-17", "open_units": 12, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2026-01-12", "open_units": 5, "site": "Denver", "sku": "RNG", "status": "proposed" }, "PO-Fresno-MDL": { "due": "2026-01-10", "open_units": 6, "site": "Fresno", "sku": "MDL", "status": "proposed" }, "PO-Fresno-PLT": { "due": "2026-01-09", "open_units": 11, "site": "Fresno", "sku": "PLT", "status": "confirmed" }, "PO-Fresno-RNG": { "due": "2026-01-19", "open_units": 7, "site": "Fresno", "sku": "RNG", "status": "confirmed" }, "PO-Tampa-MDL": { "due": "2026-01-14", "open_units": 6, "site": "Tampa", "sku": "MDL", "status": "proposed" }, "PO-Tampa-PLT": { "due": "2026-01-17", "open_units": 6, "site": "Tampa", "sku": "PLT", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2026-01-09", "open_units": 12, "site": "Tampa", "sku": "RNG", "status": "proposed" } }, "inventory": { "Denver-MDL": { "on_hand": 24, "reserved": 1, "safety": 4, "site": "Denver", "sku": "MDL" }, "Denver-PLT": { "on_hand": 31, "reserved": 2, "safety": 8, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 16, "reserved": 2, "safety": 5, "site": "Denver", "sku": "RNG" }, "Fresno-MDL": { "on_hand": 25, "reserved": 2, "safety": 4, "site": "Fresno", "sku": "MDL" }, "Fresno-PLT": { "on_hand": 17, "reserved": 3, "safety": 7, "site": "Fresno", "sku": "PLT" }, "Fresno-RNG": { "on_hand": 41, "reserved": 5, "safety": 4, "site": "Fresno", "sku": "RNG" }, "Tampa-MDL": { "on_hand": 13, "reserved": 1, "safety": 5, "site": "Tampa", "sku": "MDL" }, "Tampa-PLT": { "on_hand": 18, "reserved": 4, "safety": 7, "site": "Tampa", "sku": "PLT" }, "Tampa-RNG": { "on_hand": 22, "reserved": 3, "safety": 4, "site": "Tampa", "sku": "RNG" } }, "orders": { "SO-18277-5": { "origin": "Denver", "priority": 3, "promise": "2026-01-02", "sku": "MDL", "state": "open", "units": 21 }, "SO-27339-10": { "origin": "Fresno", "priority": 3, "promise": "2026-01-07", "sku": "RNG", "state": "open", "units": 5 }, "SO-36828-1": { "origin": "Denver", "priority": 2, "promise": "2026-01-02", "sku": "RNG", "state": "open", "units": 65 }, "SO-51525-12": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "PLT", "state": "open", "units": 20 }, "SO-70516-0": { "origin": "Denver", "priority": 1, "promise": "2026-01-01", "sku": "PLT", "state": "open", "units": 1 }, "SO-71728-2": { "origin": "Denver", "priority": 2, "promise": "2026-01-04", "sku": "MDL", "state": "open", "units": 22 }, "SO-71772-4": { "origin": "Denver", "priority": 2, "promise": "2026-01-05", "sku": "RNG", "state": "open", "units": 9 }, "SO-83517-6": { "origin": "Denver", "priority": 1, "promise": "2026-01-04", "sku": "PLT", "state": "open", "units": 9 }, "SO-84053-8": { "origin": "Denver", "priority": 3, "promise": "2025-12-31", "sku": "MDL", "state": "shipped", "units": 17 }, "SO-88274-11": { "origin": "Denver", "priority": 3, "promise": "2026-01-12", "sku": "MDL", "state": "open", "units": 13 }, "SO-89015-7": { "origin": "Denver", "priority": 3, "promise": "2026-01-08", "sku": "RNG", "state": "shipped", "units": 33 }, "SO-95590-9": { "origin": "Denver", "priority": 1, "promise": "2025-12-30", "sku": "PLT", "state": "open", "units": 13 }, "SO-99656-3": { "origin": "Denver", "priority": 3, "promise": "2026-01-07", "sku": "PLT", "state": "open", "units": 9 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}1234567891011121314151617181920212223242526"""Replay submitted mutations from the private verifier's initial state."""from types import ModuleTypeimport json
def check(spec, outputs, tests): replay = ModuleType('workflow_replay') exec(compile((tests/'replay.py').read_bytes(), 'replay.py', 'exec'), replay.__dict__) world = json.loads((tests/'world.json').read_text()) target = json.loads((tests/'target.json').read_text()) # Only fields whose starting and expected values differ may be changed. Attempts # to temporarily alter a protected field fail even when a later write restores it. allowed = { (app,key): {field for field,value in doc.items() if field not in world[app].get(key,{}) or not replay.same(world[app][key][field],value)} for app,records in target.items() for key,doc in records.items() } actions = replay.load_actions(outputs/'actions.jsonl') for event in actions: replay.apply(world,event) touched = set(event['fields']) if not touched <= allowed.get((event['app'],event['id']),set()): return False,'protected field or record write' if not replay.same(world,target): return False,'required business outcomes incomplete' return True,''12345678910111213141516171819202122232425262728{ "profile": "harbor-semantic-v1", "reward_key": "reward", "reward": { "range": [ 0, 1 ], "oracle_tolerance": 0, "floor_margin": 0.1 }, "resources": { "cpu": 1, "memory_mb": 4096, "disk_mb": 10240, "episode_timeout_s": 1800 }, "types": { "tags": [ "knowledge-work", "cross-app-workflows", "conditional-execution", "protected-state", "operations" ] }, "requires_credentials": false}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Offline business-app client. Print usage with --help."""import argparseimport copyimport fcntlimport jsonimport osfrom pathlib import Path
def same(left, right): return json.dumps(left, sort_keys=True, allow_nan=False) == json.dumps(right, sort_keys=True, allow_nan=False)
def apply(world, action): if not isinstance(action, dict) or action.keys() != {'op', 'app', 'id', 'fields'}: raise ValueError('expected op, app, id, fields') op, app, key, fields = (action[k] for k in ('op', 'app', 'id', 'fields')) if app not in world or not isinstance(key, str) or not key or not isinstance(fields, dict) or not fields: raise ValueError('unknown app, invalid id or empty fields') collection = world[app] if op == 'update' and key in collection: collection[key].update(copy.deepcopy(fields)) elif op == 'create' and key not in collection: collection[key] = copy.deepcopy(fields) else: raise ValueError(f'invalid {op} for {app}/{key}')
def load_actions(path): if path.is_symlink() or (path.is_file() and path.stat().st_size > 2_000_000): raise ValueError('invalid action log') if not path.exists(): return [] return [json.loads(s) for s in path.read_text().splitlines() if s.strip()]
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('op', choices=('apps','list','get','update','create')) parser.add_argument('app', nargs='?') parser.add_argument('id', nargs='?') parser.add_argument('fields', nargs='?', type=json.loads) args = parser.parse_args() world = json.loads(Path(__file__).with_name('world.json').read_text()) out = Path(os.environ.get('WORKFLOW_OUTPUT_DIR', '/workspace/outputs')) out.mkdir(parents=True, exist_ok=True) log = out/'actions.jsonl' with (out/'.actions.lock').open('a') as lock: fcntl.flock(lock.fileno(), fcntl.LOCK_EX) for event in load_actions(log): apply(world,event) if args.op=='apps': value=sorted(world) elif args.op=='list': value=world[args.app] elif args.op=='get': value=world[args.app][args.id] else: event={'op':args.op, 'app':args.app, 'id':args.id, 'fields':args.fields} apply(world,event) with log.open('a') as handle: handle.write(json.dumps(event,allow_nan=False)+'\n') value=world[args.app][args.id] print(json.dumps(value,sort_keys=True,allow_nan=False))
if __name__=='__main__': main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266{ "dispatch": { "REL-OLD": { "order": "archived", "state": "shipped" } }, "inbound": { "PO-Denver-CAP": { "due": "2026-02-09", "open_units": 9, "site": "Denver", "sku": "CAP", "status": "confirmed" }, "PO-Denver-PLT": { "due": "2026-02-07", "open_units": 10, "site": "Denver", "sku": "PLT", "status": "confirmed" }, "PO-Denver-RNG": { "due": "2026-02-01", "open_units": 6, "site": "Denver", "sku": "RNG", "status": "confirmed" }, "PO-Tampa-CAP": { "due": "2026-02-03", "open_units": 6, "site": "Tampa", "sku": "CAP", "status": "proposed" }, "PO-Tampa-PLT": { "due": "2026-02-07", "open_units": 4, "site": "Tampa", "sku": "PLT", "status": "proposed" }, "PO-Tampa-RNG": { "due": "2026-02-03", "open_units": 5, "site": "Tampa", "sku": "RNG", "status": "proposed" }, "PO-Waco-CAP": { "due": "2026-02-10", "open_units": 12, "site": "Waco", "sku": "CAP", "status": "confirmed" }, "PO-Waco-PLT": { "due": "2026-02-05", "open_units": 4, "site": "Waco", "sku": "PLT", "status": "proposed" }, "PO-Waco-RNG": { "due": "2026-02-06", "open_units": 10, "site": "Waco", "sku": "RNG", "status": "confirmed" } }, "inventory": { "Denver-CAP": { "on_hand": 39, "reserved": 4, "safety": 7, "site": "Denver", "sku": "CAP" }, "Denver-PLT": { "on_hand": 48, "reserved": 3, "safety": 6, "site": "Denver", "sku": "PLT" }, "Denver-RNG": { "on_hand": 30, "reserved": 3, "safety": 8, "site": "Denver", "sku": "RNG" }, "Tampa-CAP": { "on_hand": 33, "reserved": 4, "safety": 6, "site": "Tampa", "sku": "CAP" }, "Tampa-PLT": { "on_hand": 28, "reserved": 5, "safety": 4, "site": "Tampa", "sku": "PLT" }, "Tampa-RNG": { "on_hand": 35, "reserved": 1, "safety": 4, "site": "Tampa", "sku": "RNG" }, "Waco-CAP": { "on_hand": 40, "reserved": 5, "safety": 8, "site": "Waco", "sku": "CAP" }, "Waco-PLT": { "on_hand": 16, "reserved": 4, "safety": 5, "site": "Waco", "sku": "PLT" }, "Waco-RNG": { "on_hand": 32, "reserved": 2, "safety": 8, "site": "Waco", "sku": "RNG" } }, "orders": { "SO-17485-5": { "origin": "Tampa", "priority": 1, "promise": "2026-01-29", "sku": "RNG", "state": "open", "units": 22 }, "SO-25266-0": { "origin": "Tampa", "priority": 1, "promise": "2026-01-27", "sku": "CAP", "state": "open", "units": 1 }, "SO-43150-13": { "origin": "Tampa", "priority": 2, "promise": "2026-01-25", "sku": "PLT", "state": "open", "units": 10 }, "SO-43165-4": { "origin": "Tampa", "priority": 2, "promise": "2026-01-29", "sku": "PLT", "state": "open", "units": 4 }, "SO-48464-6": { "origin": "Tampa", "priority": 3, "promise": "2026-01-24", "sku": "CAP", "state": "open", "units": 27 }, "SO-49028-11": { "origin": "Tampa", "priority": 2, "promise": "2026-01-27", "sku": "RNG", "state": "open", "units": 8 }, "SO-51032-10": { "origin": "Tampa", "priority": 3, "promise": "2026-02-03", "sku": "PLT", "state": "open", "units": 28 }, "SO-51319-7": { "origin": "Waco", "priority": 1, "promise": "2026-01-30", "sku": "PLT", "state": "open", "units": 21 }, "SO-76364-12": { "origin": "Tampa", "priority": 1, "promise": "2026-01-21", "sku": "CAP", "state": "open", "units": 27 }, "SO-82157-3": { "origin": "Tampa", "priority": 2, "promise": "2026-01-28", "sku": "CAP", "state": "open", "units": 27 }, "SO-85347-2": { "origin": "Tampa", "priority": 1, "promise": "2026-01-31", "sku": "RNG", "state": "open", "units": 29 }, "SO-86749-14": { "origin": "Waco", "priority": 2, "promise": "2026-01-31", "sku": "RNG", "state": "shipped", "units": 33 }, "SO-90778-9": { "origin": "Waco", "priority": 3, "promise": "2026-01-30", "sku": "CAP", "state": "open", "units": 6 }, "SO-97009-8": { "origin": "Tampa", "priority": 1, "promise": "2026-01-25", "sku": "RNG", "state": "open", "units": 14 }, "SO-97259-1": { "origin": "Tampa", "priority": 1, "promise": "2026-01-26", "sku": "PLT", "state": "open", "units": 65 } }, "procurement": { "REQ-OLD": { "status": "approved", "units": 50 } }}tasks/autom-fulfillment-release-007/tests/replay.pyAdded+68
tasks/autom-fulfillment-release-007/tests/target.jsonAdded+396
tasks/autom-fulfillment-release-007/tests/test.shAdded+4
tasks/autom-fulfillment-release-007/tests/world.jsonAdded+342
tasks/autom-fulfillment-release-007/tests/world_check.pyAdded+26
tasks/autom-fulfillment-release-007/validation/openenv.jsonAdded+28
tasks/autom-fulfillment-release-008/environment/inputs/apps.pyAdded+68
tasks/autom-fulfillment-release-008/environment/inputs/world.jsonAdded+292
tasks/autom-fulfillment-release-008/instruction.mdAdded+17
tasks/autom-fulfillment-release-008/solution/files/actions.jsonlAdded+25
tasks/autom-fulfillment-release-008/solution/solve.shAdded+4
tasks/autom-fulfillment-release-008/task.tomlAdded+46
tasks/autom-fulfillment-release-008/tests/expected.jsonAdded+9
tasks/autom-fulfillment-release-008/tests/grade.pyAdded+330
tasks/autom-fulfillment-release-008/tests/replay.pyAdded+68
tasks/autom-fulfillment-release-008/tests/target.jsonAdded+352
tasks/autom-fulfillment-release-008/tests/test.shAdded+4
tasks/autom-fulfillment-release-008/tests/world.jsonAdded+292
tasks/autom-fulfillment-release-008/tests/world_check.pyAdded+26
tasks/autom-fulfillment-release-008/validation/openenv.jsonAdded+28
tasks/autom-fulfillment-release-009/environment/inputs/apps.pyAdded+68
tasks/autom-fulfillment-release-009/environment/inputs/world.jsonAdded+242
tasks/autom-fulfillment-release-009/instruction.mdAdded+17
tasks/autom-fulfillment-release-009/solution/files/actions.jsonlAdded+16
tasks/autom-fulfillment-release-009/solution/solve.shAdded+4
tasks/autom-fulfillment-release-009/task.tomlAdded+46
tasks/autom-fulfillment-release-009/tests/expected.jsonAdded+9
tasks/autom-fulfillment-release-009/tests/grade.pyAdded+330
tasks/autom-fulfillment-release-009/tests/replay.pyAdded+68
tasks/autom-fulfillment-release-009/tests/target.jsonAdded+278
tasks/autom-fulfillment-release-009/tests/test.shAdded+4
tasks/autom-fulfillment-release-009/tests/world.jsonAdded+242
tasks/autom-fulfillment-release-009/tests/world_check.pyAdded+26
tasks/autom-fulfillment-release-009/validation/openenv.jsonAdded+28
tasks/autom-fulfillment-release-015/environment/inputs/apps.pyAdded+68
tasks/autom-fulfillment-release-015/environment/inputs/world.jsonAdded+250
tasks/autom-fulfillment-release-015/instruction.mdAdded+17
tasks/autom-fulfillment-release-015/solution/files/actions.jsonlAdded+16
tasks/autom-fulfillment-release-015/solution/solve.shAdded+4
tasks/autom-fulfillment-release-015/task.tomlAdded+46
tasks/autom-fulfillment-release-015/tests/expected.jsonAdded+9
tasks/autom-fulfillment-release-015/tests/grade.pyAdded+330
tasks/autom-fulfillment-release-015/tests/replay.pyAdded+68
tasks/autom-fulfillment-release-015/tests/target.jsonAdded+286
tasks/autom-fulfillment-release-015/tests/test.shAdded+4
tasks/autom-fulfillment-release-015/tests/world.jsonAdded+250
tasks/autom-fulfillment-release-015/tests/world_check.pyAdded+26
tasks/autom-fulfillment-release-015/validation/openenv.jsonAdded+28
tasks/autom-fulfillment-release-016/environment/inputs/apps.pyAdded+68
tasks/autom-fulfillment-release-016/environment/inputs/world.jsonAdded+266