diff --git a/tasks/autom-fulfillment-release-007/tests/replay.py b/tasks/autom-fulfillment-release-007/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-007/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-007/tests/target.json b/tasks/autom-fulfillment-release-007/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..3e17e8d893e1c46a9f0f71378853157d0e296e24 --- /dev/null +++ b/tasks/autom-fulfillment-release-007/tests/target.json @@ -0,0 +1,396 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-007/tests/test.sh b/tasks/autom-fulfillment-release-007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-007/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-007/tests/world.json b/tasks/autom-fulfillment-release-007/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..7129538a276e81e0cd2e3c2901e792f5b743200f --- /dev/null +++ b/tasks/autom-fulfillment-release-007/tests/world.json @@ -0,0 +1,342 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-007/tests/world_check.py b/tasks/autom-fulfillment-release-007/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-007/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-007/validation/openenv.json b/tasks/autom-fulfillment-release-007/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-007/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-008/environment/inputs/apps.py b/tasks/autom-fulfillment-release-008/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-008/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-008/environment/inputs/world.json b/tasks/autom-fulfillment-release-008/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..65381ab7b21b363e17b394f3ff050094d5b8c127 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/environment/inputs/world.json @@ -0,0 +1,292 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-008/instruction.md b/tasks/autom-fulfillment-release-008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ff0c048ef4496b7662b4f904624b949434fca350 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/instruction.md @@ -0,0 +1,17 @@ +Release 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-` 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-` 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. diff --git a/tasks/autom-fulfillment-release-008/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-008/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..ea7c6cb3a0662d59ddeeadc78e60e68377fd16e4 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/solution/files/actions.jsonl @@ -0,0 +1,25 @@ +{"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"} diff --git a/tasks/autom-fulfillment-release-008/solution/solve.sh b/tasks/autom-fulfillment-release-008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-008/task.toml b/tasks/autom-fulfillment-release-008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a19b6cb99a7dd8a844d37a9f233ebdae70ba35ca --- /dev/null +++ b/tasks/autom-fulfillment-release-008/task.toml @@ -0,0 +1,46 @@ +schema_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 = 8 +source = "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 = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-008/tests/expected.json b/tasks/autom-fulfillment-release-008/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-008/tests/grade.py b/tasks/autom-fulfillment-release-008/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-008/tests/replay.py b/tasks/autom-fulfillment-release-008/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-008/tests/target.json b/tasks/autom-fulfillment-release-008/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..ab8a182a98336e8b34574747577c19795f05209e --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/target.json @@ -0,0 +1,352 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-008/tests/test.sh b/tasks/autom-fulfillment-release-008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-008/tests/world.json b/tasks/autom-fulfillment-release-008/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..65381ab7b21b363e17b394f3ff050094d5b8c127 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/world.json @@ -0,0 +1,292 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-008/tests/world_check.py b/tasks/autom-fulfillment-release-008/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-008/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-008/validation/openenv.json b/tasks/autom-fulfillment-release-008/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-008/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-009/environment/inputs/apps.py b/tasks/autom-fulfillment-release-009/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-009/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-009/environment/inputs/world.json b/tasks/autom-fulfillment-release-009/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..7dd8b0147f5313cb275f80689f3a48cf53b5d930 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/environment/inputs/world.json @@ -0,0 +1,242 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-009/instruction.md b/tasks/autom-fulfillment-release-009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0efe282510313d1d1d408f3318628a14f4717a2f --- /dev/null +++ b/tasks/autom-fulfillment-release-009/instruction.md @@ -0,0 +1,17 @@ +Release 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-` 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-` 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. diff --git a/tasks/autom-fulfillment-release-009/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-009/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..baa13d69ba66f32f71dbc9fe195e861b23341b0d --- /dev/null +++ b/tasks/autom-fulfillment-release-009/solution/files/actions.jsonl @@ -0,0 +1,16 @@ +{"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"} diff --git a/tasks/autom-fulfillment-release-009/solution/solve.sh b/tasks/autom-fulfillment-release-009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-009/task.toml b/tasks/autom-fulfillment-release-009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6240d348a8b73dd1d5773f456d7b7d0177f4f480 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/task.toml @@ -0,0 +1,46 @@ +schema_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 = 9 +source = "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 = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-009/tests/expected.json b/tasks/autom-fulfillment-release-009/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-009/tests/grade.py b/tasks/autom-fulfillment-release-009/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-009/tests/replay.py b/tasks/autom-fulfillment-release-009/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-009/tests/target.json b/tasks/autom-fulfillment-release-009/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..ba4ba9f64f09ab5b6b7eaade2b26147e9254f362 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/target.json @@ -0,0 +1,278 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-009/tests/test.sh b/tasks/autom-fulfillment-release-009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-009/tests/world.json b/tasks/autom-fulfillment-release-009/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..7dd8b0147f5313cb275f80689f3a48cf53b5d930 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/world.json @@ -0,0 +1,242 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-009/tests/world_check.py b/tasks/autom-fulfillment-release-009/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-009/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-009/validation/openenv.json b/tasks/autom-fulfillment-release-009/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-009/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-015/environment/inputs/apps.py b/tasks/autom-fulfillment-release-015/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-015/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-015/environment/inputs/world.json b/tasks/autom-fulfillment-release-015/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..cd31f501b9c4cb8714f4b946167c3a5b670c00aa --- /dev/null +++ b/tasks/autom-fulfillment-release-015/environment/inputs/world.json @@ -0,0 +1,250 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-015/instruction.md b/tasks/autom-fulfillment-release-015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8f733a960943a1dd374865d8a8c37619c5aee20f --- /dev/null +++ b/tasks/autom-fulfillment-release-015/instruction.md @@ -0,0 +1,17 @@ +Release 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-` 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-` 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. diff --git a/tasks/autom-fulfillment-release-015/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-015/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..d072a1f06404b928ddad9a345027be1ba67ea9a0 --- /dev/null +++ b/tasks/autom-fulfillment-release-015/solution/files/actions.jsonl @@ -0,0 +1,16 @@ +{"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"} diff --git a/tasks/autom-fulfillment-release-015/solution/solve.sh b/tasks/autom-fulfillment-release-015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-015/task.toml b/tasks/autom-fulfillment-release-015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..10653b87763f5b038bc216e5c637b41efef200ab --- /dev/null +++ b/tasks/autom-fulfillment-release-015/task.toml @@ -0,0 +1,46 @@ +schema_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 = 15 +source = "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 = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-015/tests/expected.json b/tasks/autom-fulfillment-release-015/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-015/tests/grade.py b/tasks/autom-fulfillment-release-015/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-015/tests/replay.py b/tasks/autom-fulfillment-release-015/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-015/tests/target.json b/tasks/autom-fulfillment-release-015/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..c0e732e1511152d1dbde4f58381c2e9a32147b3f --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/target.json @@ -0,0 +1,286 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-015/tests/test.sh b/tasks/autom-fulfillment-release-015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-015/tests/world.json b/tasks/autom-fulfillment-release-015/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..cd31f501b9c4cb8714f4b946167c3a5b670c00aa --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/world.json @@ -0,0 +1,250 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-015/tests/world_check.py b/tasks/autom-fulfillment-release-015/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-015/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-015/validation/openenv.json b/tasks/autom-fulfillment-release-015/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-015/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-016/environment/inputs/apps.py b/tasks/autom-fulfillment-release-016/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-016/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-016/environment/inputs/world.json b/tasks/autom-fulfillment-release-016/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..7b78f844a09f09b9ce62a1b7654c7eb8c9321085 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/environment/inputs/world.json @@ -0,0 +1,266 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-016/instruction.md b/tasks/autom-fulfillment-release-016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d30233e06d5096002d2d47685b64c5578e6e202a --- /dev/null +++ b/tasks/autom-fulfillment-release-016/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Tampa as of 2026-01-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-` 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 2026-02-07. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-` 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. diff --git a/tasks/autom-fulfillment-release-016/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-016/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..d030229a32613f407d5146bccd2b82a1becffc79 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/solution/files/actions.jsonl @@ -0,0 +1,24 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-25266-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-97259-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-85347-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-82157-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43165-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-17485-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-48464-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-97009-8", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-49028-11", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-76364-12", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43150-13", "op": "update"} +{"app": "inventory", "fields": {"reserved": 5}, "id": "Tampa-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 19}, "id": "Tampa-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 23}, "id": "Tampa-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 31}, "id": "Denver-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-76364-12", "site": "Denver", "sku": "CAP", "units": 27}, "id": "pick-SO-76364-12", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-97009-8", "site": "Tampa", "sku": "RNG", "units": 14}, "id": "pick-SO-97009-8", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43150-13", "site": "Tampa", "sku": "PLT", "units": 10}, "id": "pick-SO-43150-13", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-25266-0", "site": "Tampa", "sku": "CAP", "units": 1}, "id": "pick-SO-25266-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-49028-11", "site": "Tampa", "sku": "RNG", "units": 8}, "id": "pick-SO-49028-11", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43165-4", "site": "Tampa", "sku": "PLT", "units": 4}, "id": "pick-SO-43165-4", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CAP", "status": "draft", "units": 54}, "id": "req-Tampa-CAP", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "PLT", "status": "draft", "units": 65}, "id": "req-Tampa-PLT", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "RNG", "status": "draft", "units": 51}, "id": "req-Tampa-RNG", "op": "create"} diff --git a/tasks/autom-fulfillment-release-016/solution/solve.sh b/tasks/autom-fulfillment-release-016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-016/task.toml b/tasks/autom-fulfillment-release-016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..934ca44338c54309a9b08d62182f1e0119d87f2c --- /dev/null +++ b/tasks/autom-fulfillment-release-016/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-016" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 16 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-016" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-016/tests/expected.json b/tasks/autom-fulfillment-release-016/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-016/tests/grade.py b/tasks/autom-fulfillment-release-016/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-016/tests/replay.py b/tasks/autom-fulfillment-release-016/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-016/tests/target.json b/tasks/autom-fulfillment-release-016/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..234075a3837a8a4c54fad10003621fda327ca0fb --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/target.json @@ -0,0 +1,320 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-25266-0": { + "order": "SO-25266-0", + "site": "Tampa", + "sku": "CAP", + "units": 1 + }, + "pick-SO-43150-13": { + "order": "SO-43150-13", + "site": "Tampa", + "sku": "PLT", + "units": 10 + }, + "pick-SO-43165-4": { + "order": "SO-43165-4", + "site": "Tampa", + "sku": "PLT", + "units": 4 + }, + "pick-SO-49028-11": { + "order": "SO-49028-11", + "site": "Tampa", + "sku": "RNG", + "units": 8 + }, + "pick-SO-76364-12": { + "order": "SO-76364-12", + "site": "Denver", + "sku": "CAP", + "units": 27 + }, + "pick-SO-97009-8": { + "order": "SO-97009-8", + "site": "Tampa", + "sku": "RNG", + "units": 14 + } + }, + "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": 31, + "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": 5, + "safety": 6, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-PLT": { + "on_hand": 28, + "reserved": 19, + "safety": 4, + "site": "Tampa", + "sku": "PLT" + }, + "Tampa-RNG": { + "on_hand": 35, + "reserved": 23, + "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": "backorder", + "units": 22 + }, + "SO-25266-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-01-27", + "sku": "CAP", + "state": "allocated", + "units": 1 + }, + "SO-43150-13": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-01-25", + "sku": "PLT", + "state": "allocated", + "units": 10 + }, + "SO-43165-4": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-01-29", + "sku": "PLT", + "state": "allocated", + "units": 4 + }, + "SO-48464-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-01-24", + "sku": "CAP", + "state": "backorder", + "units": 27 + }, + "SO-49028-11": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-01-27", + "sku": "RNG", + "state": "allocated", + "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": "allocated", + "units": 27 + }, + "SO-82157-3": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-01-28", + "sku": "CAP", + "state": "backorder", + "units": 27 + }, + "SO-85347-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-01-31", + "sku": "RNG", + "state": "backorder", + "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": "allocated", + "units": 14 + }, + "SO-97259-1": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-01-26", + "sku": "PLT", + "state": "backorder", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Tampa-CAP": { + "site": "Tampa", + "sku": "CAP", + "status": "draft", + "units": 54 + }, + "req-Tampa-PLT": { + "site": "Tampa", + "sku": "PLT", + "status": "draft", + "units": 65 + }, + "req-Tampa-RNG": { + "site": "Tampa", + "sku": "RNG", + "status": "draft", + "units": 51 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-016/tests/test.sh b/tasks/autom-fulfillment-release-016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-016/tests/world.json b/tasks/autom-fulfillment-release-016/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..7b78f844a09f09b9ce62a1b7654c7eb8c9321085 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/world.json @@ -0,0 +1,266 @@ +{ + "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 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-016/tests/world_check.py b/tasks/autom-fulfillment-release-016/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-016/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-016/validation/openenv.json b/tasks/autom-fulfillment-release-016/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-016/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-017/environment/inputs/apps.py b/tasks/autom-fulfillment-release-017/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-017/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-017/environment/inputs/world.json b/tasks/autom-fulfillment-release-017/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..52c43ffa797825f44405d32603ddd53f681c1f64 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/environment/inputs/world.json @@ -0,0 +1,290 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-03", + "open_units": 4, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-02-27", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-03-04", + "open_units": 1, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-04", + "open_units": 9, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-02-26", + "open_units": 4, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-03-02", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-02-26", + "open_units": 8, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2026-03-01", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2026-02-27", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 34, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 33, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Denver-BRK": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 33, + "reserved": 2, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 36, + "reserved": 1, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 28, + "reserved": 5, + "safety": 6, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CPL": { + "on_hand": 47, + "reserved": 1, + "safety": 6, + "site": "Tampa", + "sku": "CPL" + } + }, + "orders": { + "SO-17166-6": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-02-16", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-20218-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-26141-4": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-22", + "sku": "BRK", + "state": "open", + "units": 28 + }, + "SO-34937-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-28", + "sku": "BRK", + "state": "open", + "units": 26 + }, + "SO-42419-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "CPL", + "state": "open", + "units": 18 + }, + "SO-45691-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-18", + "sku": "CPL", + "state": "open", + "units": 24 + }, + "SO-51893-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-58624-10": { + "origin": "Denver", + "priority": 3, + "promise": "2026-02-15", + "sku": "BRK", + "state": "open", + "units": 4 + }, + "SO-61269-11": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "CPL", + "state": "open", + "units": 20 + }, + "SO-61672-9": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-13", + "sku": "CAP", + "state": "shipped", + "units": 4 + }, + "SO-62731-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-20", + "sku": "CAP", + "state": "open", + "units": 17 + }, + "SO-63641-14": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-19", + "sku": "CPL", + "state": "open", + "units": 31 + }, + "SO-77783-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-19", + "sku": "CPL", + "state": "shipped", + "units": 23 + }, + "SO-80822-8": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-27", + "sku": "CPL", + "state": "open", + "units": 17 + }, + "SO-83228-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-26", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-84450-15": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-28", + "sku": "CAP", + "state": "open", + "units": 18 + }, + "SO-91705-13": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-03-01", + "sku": "BRK", + "state": "open", + "units": 13 + }, + "SO-92703-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-16", + "sku": "CAP", + "state": "open", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-017/instruction.md b/tasks/autom-fulfillment-release-017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2df2a8cc89be25a1952cd26b6a35a7ee686b900a --- /dev/null +++ b/tasks/autom-fulfillment-release-017/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Tampa as of 2026-02-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 Tampa. If the origin cannot cover the complete order, try Albany 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-` 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 2026-03-02. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-` 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. diff --git a/tasks/autom-fulfillment-release-017/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-017/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..50cb5f2972356e1b1d10425a186af4746feb9098 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-92703-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-51893-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-45691-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-62731-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-26141-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-42419-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17166-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-61269-11", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-63641-14", "op": "update"} +{"app": "inventory", "fields": {"reserved": 13}, "id": "Tampa-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 29}, "id": "Tampa-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 25}, "id": "Tampa-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 17}, "id": "Albany-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-92703-0", "site": "Tampa", "sku": "CAP", "units": 1}, "id": "pick-SO-92703-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-45691-2", "site": "Tampa", "sku": "CPL", "units": 24}, "id": "pick-SO-45691-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-26141-4", "site": "Tampa", "sku": "BRK", "units": 28}, "id": "pick-SO-26141-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-17166-6", "site": "Tampa", "sku": "CAP", "units": 7}, "id": "pick-SO-17166-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-62731-3", "site": "Albany", "sku": "CAP", "units": 17}, "id": "pick-SO-62731-3", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CPL", "status": "draft", "units": 69}, "id": "req-Tampa-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "BRK", "status": "draft", "units": 57}, "id": "req-Tampa-BRK", "op": "create"} diff --git a/tasks/autom-fulfillment-release-017/solution/solve.sh b/tasks/autom-fulfillment-release-017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-017/task.toml b/tasks/autom-fulfillment-release-017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..209ea6579d25148b671bb67fa7e661bedf8b4816 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-017" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 17 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-017" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-017/tests/expected.json b/tasks/autom-fulfillment-release-017/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-017/tests/grade.py b/tasks/autom-fulfillment-release-017/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-017/tests/replay.py b/tasks/autom-fulfillment-release-017/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-017/tests/target.json b/tasks/autom-fulfillment-release-017/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..2903cd004c046bb2589b638b3417db71f415209a --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/target.json @@ -0,0 +1,332 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-17166-6": { + "order": "SO-17166-6", + "site": "Tampa", + "sku": "CAP", + "units": 7 + }, + "pick-SO-26141-4": { + "order": "SO-26141-4", + "site": "Tampa", + "sku": "BRK", + "units": 28 + }, + "pick-SO-45691-2": { + "order": "SO-45691-2", + "site": "Tampa", + "sku": "CPL", + "units": 24 + }, + "pick-SO-62731-3": { + "order": "SO-62731-3", + "site": "Albany", + "sku": "CAP", + "units": 17 + }, + "pick-SO-92703-0": { + "order": "SO-92703-0", + "site": "Tampa", + "sku": "CAP", + "units": 1 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-03", + "open_units": 4, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-02-27", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-03-04", + "open_units": 1, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-04", + "open_units": 9, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-02-26", + "open_units": 4, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-03-02", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-02-26", + "open_units": 8, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2026-03-01", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2026-02-27", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 34, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 33, + "reserved": 17, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Denver-BRK": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 33, + "reserved": 2, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 36, + "reserved": 29, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 28, + "reserved": 13, + "safety": 6, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CPL": { + "on_hand": 47, + "reserved": 25, + "safety": 6, + "site": "Tampa", + "sku": "CPL" + } + }, + "orders": { + "SO-17166-6": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-02-16", + "sku": "CAP", + "state": "allocated", + "units": 7 + }, + "SO-20218-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-26141-4": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-22", + "sku": "BRK", + "state": "allocated", + "units": 28 + }, + "SO-34937-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-28", + "sku": "BRK", + "state": "open", + "units": 26 + }, + "SO-42419-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "CPL", + "state": "backorder", + "units": 18 + }, + "SO-45691-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-18", + "sku": "CPL", + "state": "allocated", + "units": 24 + }, + "SO-51893-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "BRK", + "state": "backorder", + "units": 65 + }, + "SO-58624-10": { + "origin": "Denver", + "priority": 3, + "promise": "2026-02-15", + "sku": "BRK", + "state": "open", + "units": 4 + }, + "SO-61269-11": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "CPL", + "state": "backorder", + "units": 20 + }, + "SO-61672-9": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-13", + "sku": "CAP", + "state": "shipped", + "units": 4 + }, + "SO-62731-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-20", + "sku": "CAP", + "state": "allocated", + "units": 17 + }, + "SO-63641-14": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-19", + "sku": "CPL", + "state": "backorder", + "units": 31 + }, + "SO-77783-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-19", + "sku": "CPL", + "state": "shipped", + "units": 23 + }, + "SO-80822-8": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-27", + "sku": "CPL", + "state": "open", + "units": 17 + }, + "SO-83228-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-26", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-84450-15": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-28", + "sku": "CAP", + "state": "open", + "units": 18 + }, + "SO-91705-13": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-03-01", + "sku": "BRK", + "state": "open", + "units": 13 + }, + "SO-92703-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-16", + "sku": "CAP", + "state": "allocated", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Tampa-BRK": { + "site": "Tampa", + "sku": "BRK", + "status": "draft", + "units": 57 + }, + "req-Tampa-CPL": { + "site": "Tampa", + "sku": "CPL", + "status": "draft", + "units": 69 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-017/tests/test.sh b/tasks/autom-fulfillment-release-017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-017/tests/world.json b/tasks/autom-fulfillment-release-017/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..52c43ffa797825f44405d32603ddd53f681c1f64 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/world.json @@ -0,0 +1,290 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-03", + "open_units": 4, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-02-27", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-03-04", + "open_units": 1, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-04", + "open_units": 9, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-02-26", + "open_units": 4, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-03-02", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-02-26", + "open_units": 8, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2026-03-01", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2026-02-27", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 34, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 33, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Denver-BRK": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 33, + "reserved": 2, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 36, + "reserved": 1, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 28, + "reserved": 5, + "safety": 6, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CPL": { + "on_hand": 47, + "reserved": 1, + "safety": 6, + "site": "Tampa", + "sku": "CPL" + } + }, + "orders": { + "SO-17166-6": { + "origin": "Tampa", + "priority": 2, + "promise": "2026-02-16", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-20218-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-26141-4": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-22", + "sku": "BRK", + "state": "open", + "units": 28 + }, + "SO-34937-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-28", + "sku": "BRK", + "state": "open", + "units": 26 + }, + "SO-42419-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "CPL", + "state": "open", + "units": 18 + }, + "SO-45691-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-18", + "sku": "CPL", + "state": "open", + "units": 24 + }, + "SO-51893-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-23", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-58624-10": { + "origin": "Denver", + "priority": 3, + "promise": "2026-02-15", + "sku": "BRK", + "state": "open", + "units": 4 + }, + "SO-61269-11": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-16", + "sku": "CPL", + "state": "open", + "units": 20 + }, + "SO-61672-9": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-13", + "sku": "CAP", + "state": "shipped", + "units": 4 + }, + "SO-62731-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-20", + "sku": "CAP", + "state": "open", + "units": 17 + }, + "SO-63641-14": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-19", + "sku": "CPL", + "state": "open", + "units": 31 + }, + "SO-77783-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-19", + "sku": "CPL", + "state": "shipped", + "units": 23 + }, + "SO-80822-8": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-27", + "sku": "CPL", + "state": "open", + "units": 17 + }, + "SO-83228-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-02-26", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-84450-15": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-28", + "sku": "CAP", + "state": "open", + "units": 18 + }, + "SO-91705-13": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-03-01", + "sku": "BRK", + "state": "open", + "units": 13 + }, + "SO-92703-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-02-16", + "sku": "CAP", + "state": "open", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-017/tests/world_check.py b/tasks/autom-fulfillment-release-017/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-017/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-017/validation/openenv.json b/tasks/autom-fulfillment-release-017/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-017/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-018/environment/inputs/apps.py b/tasks/autom-fulfillment-release-018/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-018/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-018/environment/inputs/world.json b/tasks/autom-fulfillment-release-018/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..53972217b95fa3888e41db9f0a31c9f73505815a --- /dev/null +++ b/tasks/autom-fulfillment-release-018/environment/inputs/world.json @@ -0,0 +1,390 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-19", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-03-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2026-03-28", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2026-03-25", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2026-03-27", + "open_units": 12, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-21", + "open_units": 1, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-03-20", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-03-28", + "open_units": 9, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-27", + "open_units": 7, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2026-03-26", + "open_units": 9, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2026-03-26", + "open_units": 6, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CAP": { + "due": "2026-03-19", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2026-03-27", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-25", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-24", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 2, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 46, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 24, + "reserved": 2, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 42, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-RNG": { + "on_hand": 28, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 43, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 22, + "reserved": 3, + "safety": 5, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 37, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-RNG": { + "on_hand": 38, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 17, + "reserved": 4, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 39, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 47, + "reserved": 3, + "safety": 5, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 24, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 2, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-19976-11": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-09", + "sku": "RNG", + "state": "open", + "units": 17 + }, + "SO-32233-19": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CAP", + "state": "open", + "units": 12 + }, + "SO-32352-9": { + "origin": "Denver", + "priority": 1, + "promise": "2026-03-08", + "sku": "CAP", + "state": "open", + "units": 8 + }, + "SO-34944-1": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-35696-7": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "shipped", + "units": 19 + }, + "SO-39986-5": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CPL", + "state": "open", + "units": 14 + }, + "SO-46592-15": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-20", + "sku": "CPL", + "state": "open", + "units": 28 + }, + "SO-47255-16": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "open", + "units": 12 + }, + "SO-52851-0": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "CPL", + "state": "open", + "units": 1 + }, + "SO-57380-8": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-58266-17": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-19", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-60527-2": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-17", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-62806-4": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-13", + "sku": "CAP", + "state": "open", + "units": 29 + }, + "SO-64347-3": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-11", + "sku": "BRK", + "state": "open", + "units": 16 + }, + "SO-66301-14": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-15", + "sku": "CAP", + "state": "shipped", + "units": 31 + }, + "SO-72448-13": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-20", + "sku": "BRK", + "state": "open", + "units": 3 + }, + "SO-84716-6": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-16", + "sku": "RNG", + "state": "open", + "units": 6 + }, + "SO-85049-18": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-18", + "sku": "BRK", + "state": "shipped", + "units": 27 + }, + "SO-85371-12": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-14", + "sku": "CLP", + "state": "open", + "units": 18 + }, + "SO-99858-10": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "CPL", + "state": "open", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-018/instruction.md b/tasks/autom-fulfillment-release-018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..08f702654ee1dcfac42a8b41bb6ecd9e58049850 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Waco as of 2026-03-18. 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 Waco. 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-` 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 Waco, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-03-25. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Waco-` 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. diff --git a/tasks/autom-fulfillment-release-018/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-018/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..85a943188035bc248c890179f69c4a66ba51bdb7 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/solution/files/actions.jsonl @@ -0,0 +1,25 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-52851-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-34944-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-60527-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-64347-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-62806-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-39986-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-84716-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-57380-8", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-99858-10", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-19976-11", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-85371-12", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-32233-19", "op": "update"} +{"app": "inventory", "fields": {"reserved": 6}, "id": "Waco-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 19}, "id": "Waco-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 42}, "id": "Waco-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 12}, "id": "Waco-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-19976-11", "site": "Waco", "sku": "RNG", "units": 17}, "id": "pick-SO-19976-11", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-32233-19", "site": "Waco", "sku": "CAP", "units": 12}, "id": "pick-SO-32233-19", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-85371-12", "site": "Waco", "sku": "CLP", "units": 18}, "id": "pick-SO-85371-12", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-60527-2", "site": "Waco", "sku": "CLP", "units": 21}, "id": "pick-SO-60527-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-52851-0", "site": "Waco", "sku": "CPL", "units": 1}, "id": "pick-SO-52851-0", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "BRK", "status": "draft", "units": 49}, "id": "req-Waco-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "CPL", "status": "draft", "units": 18}, "id": "req-Waco-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "CAP", "status": "draft", "units": 29}, "id": "req-Waco-CAP", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "RNG", "status": "draft", "units": 61}, "id": "req-Waco-RNG", "op": "create"} diff --git a/tasks/autom-fulfillment-release-018/solution/solve.sh b/tasks/autom-fulfillment-release-018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-018/task.toml b/tasks/autom-fulfillment-release-018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..189fc8e56c521e7e558aca9291360f0069c03f22 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-018" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 18 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-018" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-018/tests/expected.json b/tasks/autom-fulfillment-release-018/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-018/tests/grade.py b/tasks/autom-fulfillment-release-018/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-018/tests/replay.py b/tasks/autom-fulfillment-release-018/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-018/tests/target.json b/tasks/autom-fulfillment-release-018/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..92b33997bf6e8105d8beb16adb895574a48124d9 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/target.json @@ -0,0 +1,444 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-19976-11": { + "order": "SO-19976-11", + "site": "Waco", + "sku": "RNG", + "units": 17 + }, + "pick-SO-32233-19": { + "order": "SO-32233-19", + "site": "Waco", + "sku": "CAP", + "units": 12 + }, + "pick-SO-52851-0": { + "order": "SO-52851-0", + "site": "Waco", + "sku": "CPL", + "units": 1 + }, + "pick-SO-60527-2": { + "order": "SO-60527-2", + "site": "Waco", + "sku": "CLP", + "units": 21 + }, + "pick-SO-85371-12": { + "order": "SO-85371-12", + "site": "Waco", + "sku": "CLP", + "units": 18 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-19", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-03-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2026-03-28", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2026-03-25", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2026-03-27", + "open_units": 12, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-21", + "open_units": 1, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-03-20", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-03-28", + "open_units": 9, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-27", + "open_units": 7, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2026-03-26", + "open_units": 9, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2026-03-26", + "open_units": 6, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CAP": { + "due": "2026-03-19", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2026-03-27", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-25", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-24", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 2, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 46, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 24, + "reserved": 2, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 42, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-RNG": { + "on_hand": 28, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 43, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 22, + "reserved": 3, + "safety": 5, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 37, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-RNG": { + "on_hand": 38, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 17, + "reserved": 4, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 39, + "reserved": 12, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 47, + "reserved": 42, + "safety": 5, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 24, + "reserved": 6, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 19, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-19976-11": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-09", + "sku": "RNG", + "state": "allocated", + "units": 17 + }, + "SO-32233-19": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CAP", + "state": "allocated", + "units": 12 + }, + "SO-32352-9": { + "origin": "Denver", + "priority": 1, + "promise": "2026-03-08", + "sku": "CAP", + "state": "open", + "units": 8 + }, + "SO-34944-1": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-35696-7": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "shipped", + "units": 19 + }, + "SO-39986-5": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CPL", + "state": "backorder", + "units": 14 + }, + "SO-46592-15": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-20", + "sku": "CPL", + "state": "open", + "units": 28 + }, + "SO-47255-16": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "open", + "units": 12 + }, + "SO-52851-0": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "CPL", + "state": "allocated", + "units": 1 + }, + "SO-57380-8": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "BRK", + "state": "backorder", + "units": 33 + }, + "SO-58266-17": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-19", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-60527-2": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-17", + "sku": "CLP", + "state": "allocated", + "units": 21 + }, + "SO-62806-4": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-13", + "sku": "CAP", + "state": "backorder", + "units": 29 + }, + "SO-64347-3": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-11", + "sku": "BRK", + "state": "backorder", + "units": 16 + }, + "SO-66301-14": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-15", + "sku": "CAP", + "state": "shipped", + "units": 31 + }, + "SO-72448-13": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-20", + "sku": "BRK", + "state": "open", + "units": 3 + }, + "SO-84716-6": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-16", + "sku": "RNG", + "state": "backorder", + "units": 6 + }, + "SO-85049-18": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-18", + "sku": "BRK", + "state": "shipped", + "units": 27 + }, + "SO-85371-12": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-14", + "sku": "CLP", + "state": "allocated", + "units": 18 + }, + "SO-99858-10": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "CPL", + "state": "backorder", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Waco-BRK": { + "site": "Waco", + "sku": "BRK", + "status": "draft", + "units": 49 + }, + "req-Waco-CAP": { + "site": "Waco", + "sku": "CAP", + "status": "draft", + "units": 29 + }, + "req-Waco-CPL": { + "site": "Waco", + "sku": "CPL", + "status": "draft", + "units": 18 + }, + "req-Waco-RNG": { + "site": "Waco", + "sku": "RNG", + "status": "draft", + "units": 61 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-018/tests/test.sh b/tasks/autom-fulfillment-release-018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-018/tests/world.json b/tasks/autom-fulfillment-release-018/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..53972217b95fa3888e41db9f0a31c9f73505815a --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/world.json @@ -0,0 +1,390 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-03-19", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-03-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2026-03-28", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2026-03-25", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2026-03-27", + "open_units": 12, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-03-21", + "open_units": 1, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-03-20", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-03-28", + "open_units": 9, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-27", + "open_units": 7, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2026-03-26", + "open_units": 9, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2026-03-26", + "open_units": 6, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CAP": { + "due": "2026-03-19", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2026-03-27", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-25", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-24", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 2, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 46, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 24, + "reserved": 2, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 42, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-RNG": { + "on_hand": 28, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 43, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 22, + "reserved": 3, + "safety": 5, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 37, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-RNG": { + "on_hand": 38, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 17, + "reserved": 4, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 39, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 47, + "reserved": 3, + "safety": 5, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 24, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 2, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-19976-11": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-09", + "sku": "RNG", + "state": "open", + "units": 17 + }, + "SO-32233-19": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CAP", + "state": "open", + "units": 12 + }, + "SO-32352-9": { + "origin": "Denver", + "priority": 1, + "promise": "2026-03-08", + "sku": "CAP", + "state": "open", + "units": 8 + }, + "SO-34944-1": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-35696-7": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "shipped", + "units": 19 + }, + "SO-39986-5": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-12", + "sku": "CPL", + "state": "open", + "units": 14 + }, + "SO-46592-15": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-20", + "sku": "CPL", + "state": "open", + "units": 28 + }, + "SO-47255-16": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "open", + "units": 12 + }, + "SO-52851-0": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-18", + "sku": "CPL", + "state": "open", + "units": 1 + }, + "SO-57380-8": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-58266-17": { + "origin": "Denver", + "priority": 2, + "promise": "2026-03-19", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-60527-2": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-17", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-62806-4": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-13", + "sku": "CAP", + "state": "open", + "units": 29 + }, + "SO-64347-3": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-11", + "sku": "BRK", + "state": "open", + "units": 16 + }, + "SO-66301-14": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-15", + "sku": "CAP", + "state": "shipped", + "units": 31 + }, + "SO-72448-13": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-20", + "sku": "BRK", + "state": "open", + "units": 3 + }, + "SO-84716-6": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-16", + "sku": "RNG", + "state": "open", + "units": 6 + }, + "SO-85049-18": { + "origin": "Waco", + "priority": 2, + "promise": "2026-03-18", + "sku": "BRK", + "state": "shipped", + "units": 27 + }, + "SO-85371-12": { + "origin": "Waco", + "priority": 3, + "promise": "2026-03-14", + "sku": "CLP", + "state": "open", + "units": 18 + }, + "SO-99858-10": { + "origin": "Waco", + "priority": 1, + "promise": "2026-03-14", + "sku": "CPL", + "state": "open", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-018/tests/world_check.py b/tasks/autom-fulfillment-release-018/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-018/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-018/validation/openenv.json b/tasks/autom-fulfillment-release-018/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-018/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-021/environment/inputs/apps.py b/tasks/autom-fulfillment-release-021/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-021/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-021/environment/inputs/world.json b/tasks/autom-fulfillment-release-021/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..c2aa17a33a0b49a12c3cfc7cede3cda962f1cc07 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/environment/inputs/world.json @@ -0,0 +1,342 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-06-03", + "open_units": 7, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-06-04", + "open_units": 2, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-06-04", + "open_units": 10, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-06-02", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2026-06-02", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-06-06", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-06-06", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-05-29", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-05-29", + "open_units": 10, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-PLT": { + "due": "2026-06-05", + "open_units": 3, + "site": "Denver", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-06-03", + "open_units": 8, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2026-05-30", + "open_units": 9, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-06-05", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-06-06", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2026-05-27", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 33, + "reserved": 0, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 44, + "reserved": 3, + "safety": 7, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 38, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 20, + "reserved": 1, + "safety": 7, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 22, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Denver-BRK": { + "on_hand": 26, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 22, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 29, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 38, + "reserved": 5, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-PLT": { + "on_hand": 18, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 23, + "reserved": 2, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 23, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 18, + "reserved": 2, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 29, + "reserved": 2, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 25, + "reserved": 3, + "safety": 8, + "site": "Fresno", + "sku": "PLT" + } + }, + "orders": { + "SO-14549-8": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-16", + "sku": "PLT", + "state": "shipped", + "units": 10 + }, + "SO-17012-13": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-18", + "sku": "PLT", + "state": "open", + "units": 24 + }, + "SO-22137-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-19", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-27001-11": { + "origin": "Denver", + "priority": 2, + "promise": "2026-05-24", + "sku": "CPL", + "state": "open", + "units": 16 + }, + "SO-32121-3": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "PLT", + "state": "open", + "units": 14 + }, + "SO-33297-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-17", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-43549-2": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-20", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-45102-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-05-22", + "sku": "CAP", + "state": "open", + "units": 12 + }, + "SO-53166-4": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-20", + "sku": "BRK", + "state": "open", + "units": 20 + }, + "SO-62825-5": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-25", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-65102-9": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "BRK", + "state": "open", + "units": 7 + }, + "SO-71901-6": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-22", + "sku": "CPL", + "state": "open", + "units": 9 + }, + "SO-74454-7": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-17", + "sku": "CAP", + "state": "open", + "units": 19 + }, + "SO-88271-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-05-26", + "sku": "CPL", + "state": "open", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-021/instruction.md b/tasks/autom-fulfillment-release-021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4bb3e2142f5804585d204b50b04539c4d7b0523f --- /dev/null +++ b/tasks/autom-fulfillment-release-021/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Albany as of 2026-05-26. 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 Albany. 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-` 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 Albany, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-06-02. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Albany-` 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. diff --git a/tasks/autom-fulfillment-release-021/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-021/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..d5d10e8fb54a4943e7ec6705f84d6cb68676aad3 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/solution/files/actions.jsonl @@ -0,0 +1,25 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-22137-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-88271-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43549-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-32121-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-53166-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-62825-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-71901-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-74454-7", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-65102-9", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-33297-10", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-17012-13", "op": "update"} +{"app": "inventory", "fields": {"reserved": 34}, "id": "Albany-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 10}, "id": "Albany-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 27}, "id": "Albany-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 7}, "id": "Albany-BRK", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-33297-10", "site": "Albany", "sku": "CLP", "units": 33}, "id": "pick-SO-33297-10", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-22137-0", "site": "Albany", "sku": "CLP", "units": 1}, "id": "pick-SO-22137-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43549-2", "site": "Albany", "sku": "CAP", "units": 24}, "id": "pick-SO-43549-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-65102-9", "site": "Albany", "sku": "BRK", "units": 7}, "id": "pick-SO-65102-9", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-71901-6", "site": "Albany", "sku": "CPL", "units": 9}, "id": "pick-SO-71901-6", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CLP", "status": "draft", "units": 8}, "id": "req-Albany-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "PLT", "status": "draft", "units": 38}, "id": "req-Albany-PLT", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CPL", "status": "draft", "units": 65}, "id": "req-Albany-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CAP", "status": "draft", "units": 19}, "id": "req-Albany-CAP", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "BRK", "status": "draft", "units": 20}, "id": "req-Albany-BRK", "op": "create"} diff --git a/tasks/autom-fulfillment-release-021/solution/solve.sh b/tasks/autom-fulfillment-release-021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-021/task.toml b/tasks/autom-fulfillment-release-021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5f96a8e5b6c774d3542323d9db215236e9a15051 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-021" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 21 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-021" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-021/tests/expected.json b/tasks/autom-fulfillment-release-021/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-021/tests/grade.py b/tasks/autom-fulfillment-release-021/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-021/tests/replay.py b/tasks/autom-fulfillment-release-021/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-021/tests/target.json b/tasks/autom-fulfillment-release-021/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..4c5bfc484f46915e020a89b166ac83476d331e1b --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/target.json @@ -0,0 +1,402 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-22137-0": { + "order": "SO-22137-0", + "site": "Albany", + "sku": "CLP", + "units": 1 + }, + "pick-SO-33297-10": { + "order": "SO-33297-10", + "site": "Albany", + "sku": "CLP", + "units": 33 + }, + "pick-SO-43549-2": { + "order": "SO-43549-2", + "site": "Albany", + "sku": "CAP", + "units": 24 + }, + "pick-SO-65102-9": { + "order": "SO-65102-9", + "site": "Albany", + "sku": "BRK", + "units": 7 + }, + "pick-SO-71901-6": { + "order": "SO-71901-6", + "site": "Albany", + "sku": "CPL", + "units": 9 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-06-03", + "open_units": 7, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-06-04", + "open_units": 2, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-06-04", + "open_units": 10, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-06-02", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2026-06-02", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-06-06", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-06-06", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-05-29", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-05-29", + "open_units": 10, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-PLT": { + "due": "2026-06-05", + "open_units": 3, + "site": "Denver", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-06-03", + "open_units": 8, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2026-05-30", + "open_units": 9, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-06-05", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-06-06", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2026-05-27", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 33, + "reserved": 7, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 44, + "reserved": 27, + "safety": 7, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 38, + "reserved": 34, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 20, + "reserved": 10, + "safety": 7, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 22, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Denver-BRK": { + "on_hand": 26, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 22, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 29, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 38, + "reserved": 5, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-PLT": { + "on_hand": 18, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 23, + "reserved": 2, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 23, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 18, + "reserved": 2, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 29, + "reserved": 2, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 25, + "reserved": 3, + "safety": 8, + "site": "Fresno", + "sku": "PLT" + } + }, + "orders": { + "SO-14549-8": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-16", + "sku": "PLT", + "state": "shipped", + "units": 10 + }, + "SO-17012-13": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-18", + "sku": "PLT", + "state": "backorder", + "units": 24 + }, + "SO-22137-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-19", + "sku": "CLP", + "state": "allocated", + "units": 1 + }, + "SO-27001-11": { + "origin": "Denver", + "priority": 2, + "promise": "2026-05-24", + "sku": "CPL", + "state": "open", + "units": 16 + }, + "SO-32121-3": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "PLT", + "state": "backorder", + "units": 14 + }, + "SO-33297-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-17", + "sku": "CLP", + "state": "allocated", + "units": 33 + }, + "SO-43549-2": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-20", + "sku": "CAP", + "state": "allocated", + "units": 24 + }, + "SO-45102-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-05-22", + "sku": "CAP", + "state": "open", + "units": 12 + }, + "SO-53166-4": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-20", + "sku": "BRK", + "state": "backorder", + "units": 20 + }, + "SO-62825-5": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-25", + "sku": "CLP", + "state": "backorder", + "units": 8 + }, + "SO-65102-9": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "BRK", + "state": "allocated", + "units": 7 + }, + "SO-71901-6": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-22", + "sku": "CPL", + "state": "allocated", + "units": 9 + }, + "SO-74454-7": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-17", + "sku": "CAP", + "state": "backorder", + "units": 19 + }, + "SO-88271-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-05-26", + "sku": "CPL", + "state": "backorder", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Albany-BRK": { + "site": "Albany", + "sku": "BRK", + "status": "draft", + "units": 20 + }, + "req-Albany-CAP": { + "site": "Albany", + "sku": "CAP", + "status": "draft", + "units": 19 + }, + "req-Albany-CLP": { + "site": "Albany", + "sku": "CLP", + "status": "draft", + "units": 8 + }, + "req-Albany-CPL": { + "site": "Albany", + "sku": "CPL", + "status": "draft", + "units": 65 + }, + "req-Albany-PLT": { + "site": "Albany", + "sku": "PLT", + "status": "draft", + "units": 38 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-021/tests/test.sh b/tasks/autom-fulfillment-release-021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-021/tests/world.json b/tasks/autom-fulfillment-release-021/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..c2aa17a33a0b49a12c3cfc7cede3cda962f1cc07 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/world.json @@ -0,0 +1,342 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-06-03", + "open_units": 7, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2026-06-04", + "open_units": 2, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-06-04", + "open_units": 10, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-06-02", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2026-06-02", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-BRK": { + "due": "2026-06-06", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2026-06-06", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2026-05-29", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-05-29", + "open_units": 10, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-PLT": { + "due": "2026-06-05", + "open_units": 3, + "site": "Denver", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-06-03", + "open_units": 8, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2026-05-30", + "open_units": 9, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-06-05", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-06-06", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2026-05-27", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 33, + "reserved": 0, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 44, + "reserved": 3, + "safety": 7, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 38, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 20, + "reserved": 1, + "safety": 7, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 22, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Denver-BRK": { + "on_hand": 26, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 22, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 29, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 38, + "reserved": 5, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-PLT": { + "on_hand": 18, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 23, + "reserved": 2, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 23, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 18, + "reserved": 2, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 29, + "reserved": 2, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 25, + "reserved": 3, + "safety": 8, + "site": "Fresno", + "sku": "PLT" + } + }, + "orders": { + "SO-14549-8": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-16", + "sku": "PLT", + "state": "shipped", + "units": 10 + }, + "SO-17012-13": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-18", + "sku": "PLT", + "state": "open", + "units": 24 + }, + "SO-22137-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-19", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-27001-11": { + "origin": "Denver", + "priority": 2, + "promise": "2026-05-24", + "sku": "CPL", + "state": "open", + "units": 16 + }, + "SO-32121-3": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "PLT", + "state": "open", + "units": 14 + }, + "SO-33297-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-17", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-43549-2": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-20", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-45102-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-05-22", + "sku": "CAP", + "state": "open", + "units": 12 + }, + "SO-53166-4": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-20", + "sku": "BRK", + "state": "open", + "units": 20 + }, + "SO-62825-5": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-25", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-65102-9": { + "origin": "Albany", + "priority": 1, + "promise": "2026-05-26", + "sku": "BRK", + "state": "open", + "units": 7 + }, + "SO-71901-6": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-22", + "sku": "CPL", + "state": "open", + "units": 9 + }, + "SO-74454-7": { + "origin": "Albany", + "priority": 3, + "promise": "2026-05-17", + "sku": "CAP", + "state": "open", + "units": 19 + }, + "SO-88271-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-05-26", + "sku": "CPL", + "state": "open", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-021/tests/world_check.py b/tasks/autom-fulfillment-release-021/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-021/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-021/validation/openenv.json b/tasks/autom-fulfillment-release-021/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-021/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-025/environment/inputs/apps.py b/tasks/autom-fulfillment-release-025/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-025/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-025/environment/inputs/world.json b/tasks/autom-fulfillment-release-025/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..dbc3aa80d2909d479635a6b1b5cb2845500310a5 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/environment/inputs/world.json @@ -0,0 +1,306 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-05-02", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-04-27", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2025-05-03", + "open_units": 12, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2025-04-27", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-05-04", + "open_units": 10, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-04-29", + "open_units": 2, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-29", + "open_units": 12, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 46, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CPL": { + "on_hand": 16, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 15, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 15, + "reserved": 0, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CPL": { + "on_hand": 18, + "reserved": 1, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 15, + "reserved": 5, + "safety": 4, + "site": "Fresno", + "sku": "PLT" + }, + "Waco-BRK": { + "on_hand": 23, + "reserved": 3, + "safety": 5, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CPL": { + "on_hand": 25, + "reserved": 1, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-12009-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-21", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-15118-4": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-19", + "sku": "BRK", + "state": "open", + "units": 22 + }, + "SO-19954-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 6 + }, + "SO-24131-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-23", + "sku": "BRK", + "state": "open", + "units": 29 + }, + "SO-24696-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-28", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-38815-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 9 + }, + "SO-50531-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-21", + "sku": "CPL", + "state": "shipped", + "units": 3 + }, + "SO-51291-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-23", + "sku": "PLT", + "state": "open", + "units": 8 + }, + "SO-57140-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 1 + }, + "SO-69898-19": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "BRK", + "state": "open", + "units": 31 + }, + "SO-71121-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "open", + "units": 27 + }, + "SO-71317-9": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-24", + "sku": "PLT", + "state": "open", + "units": 9 + }, + "SO-72910-17": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-23", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-83270-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-21", + "sku": "CPL", + "state": "open", + "units": 11 + }, + "SO-84837-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-24", + "sku": "BRK", + "state": "open", + "units": 5 + }, + "SO-85489-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 4 + }, + "SO-89525-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-16", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-91391-18": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-28", + "sku": "PLT", + "state": "open", + "units": 11 + }, + "SO-94270-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-17", + "sku": "CPL", + "state": "open", + "units": 28 + }, + "SO-97275-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 5 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-025/instruction.md b/tasks/autom-fulfillment-release-025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8f31346c0e404e7658739dd7d3bf8f2d5951a0ad --- /dev/null +++ b/tasks/autom-fulfillment-release-025/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Fresno as of 2025-04-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 Fresno. If the origin cannot cover the complete order, try Albany 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-` 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 Fresno, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-04-30. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Fresno-` 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. diff --git a/tasks/autom-fulfillment-release-025/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-025/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..64e3dc85f12dbf9f7612974b54b37cbdf691f587 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-57140-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-12009-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-94270-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-97275-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-15118-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-83270-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-51291-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-24131-10", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-19954-15", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-69898-19", "op": "update"} +{"app": "inventory", "fields": {"reserved": 11}, "id": "Fresno-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 9}, "id": "Albany-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 32}, "id": "Albany-BRK", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-69898-19", "site": "Albany", "sku": "BRK", "units": 31}, "id": "pick-SO-69898-19", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-57140-0", "site": "Fresno", "sku": "PLT", "units": 1}, "id": "pick-SO-57140-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-19954-15", "site": "Albany", "sku": "PLT", "units": 6}, "id": "pick-SO-19954-15", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-97275-3", "site": "Fresno", "sku": "PLT", "units": 5}, "id": "pick-SO-97275-3", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CPL", "status": "draft", "units": 34}, "id": "req-Fresno-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "BRK", "status": "draft", "units": 116}, "id": "req-Fresno-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "PLT", "status": "draft", "units": 8}, "id": "req-Fresno-PLT", "op": "create"} diff --git a/tasks/autom-fulfillment-release-025/solution/solve.sh b/tasks/autom-fulfillment-release-025/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-025/task.toml b/tasks/autom-fulfillment-release-025/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bb1a8695b1152830831589de7503a39a472fe500 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-025" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 25 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-025" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-025/tests/expected.json b/tasks/autom-fulfillment-release-025/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-025/tests/grade.py b/tasks/autom-fulfillment-release-025/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-025/tests/replay.py b/tasks/autom-fulfillment-release-025/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-025/tests/target.json b/tasks/autom-fulfillment-release-025/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..0164476565fd90a64e56f48a15ecbf7f8e4f0909 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/target.json @@ -0,0 +1,348 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-19954-15": { + "order": "SO-19954-15", + "site": "Albany", + "sku": "PLT", + "units": 6 + }, + "pick-SO-57140-0": { + "order": "SO-57140-0", + "site": "Fresno", + "sku": "PLT", + "units": 1 + }, + "pick-SO-69898-19": { + "order": "SO-69898-19", + "site": "Albany", + "sku": "BRK", + "units": 31 + }, + "pick-SO-97275-3": { + "order": "SO-97275-3", + "site": "Fresno", + "sku": "PLT", + "units": 5 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-05-02", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-04-27", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2025-05-03", + "open_units": 12, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2025-04-27", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-05-04", + "open_units": 10, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-04-29", + "open_units": 2, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-29", + "open_units": 12, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 46, + "reserved": 32, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CPL": { + "on_hand": 16, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 15, + "reserved": 9, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 15, + "reserved": 0, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CPL": { + "on_hand": 18, + "reserved": 1, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 15, + "reserved": 11, + "safety": 4, + "site": "Fresno", + "sku": "PLT" + }, + "Waco-BRK": { + "on_hand": 23, + "reserved": 3, + "safety": 5, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CPL": { + "on_hand": 25, + "reserved": 1, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-12009-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-21", + "sku": "BRK", + "state": "backorder", + "units": 65 + }, + "SO-15118-4": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-19", + "sku": "BRK", + "state": "backorder", + "units": 22 + }, + "SO-19954-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "allocated", + "units": 6 + }, + "SO-24131-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-23", + "sku": "BRK", + "state": "backorder", + "units": 29 + }, + "SO-24696-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-28", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-38815-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 9 + }, + "SO-50531-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-21", + "sku": "CPL", + "state": "shipped", + "units": 3 + }, + "SO-51291-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-23", + "sku": "PLT", + "state": "backorder", + "units": 8 + }, + "SO-57140-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-16", + "sku": "PLT", + "state": "allocated", + "units": 1 + }, + "SO-69898-19": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "BRK", + "state": "allocated", + "units": 31 + }, + "SO-71121-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "open", + "units": 27 + }, + "SO-71317-9": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-24", + "sku": "PLT", + "state": "open", + "units": 9 + }, + "SO-72910-17": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-23", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-83270-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-21", + "sku": "CPL", + "state": "backorder", + "units": 11 + }, + "SO-84837-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-24", + "sku": "BRK", + "state": "open", + "units": 5 + }, + "SO-85489-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 4 + }, + "SO-89525-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-16", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-91391-18": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-28", + "sku": "PLT", + "state": "open", + "units": 11 + }, + "SO-94270-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-17", + "sku": "CPL", + "state": "backorder", + "units": 28 + }, + "SO-97275-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "allocated", + "units": 5 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Fresno-BRK": { + "site": "Fresno", + "sku": "BRK", + "status": "draft", + "units": 116 + }, + "req-Fresno-CPL": { + "site": "Fresno", + "sku": "CPL", + "status": "draft", + "units": 34 + }, + "req-Fresno-PLT": { + "site": "Fresno", + "sku": "PLT", + "status": "draft", + "units": 8 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-025/tests/test.sh b/tasks/autom-fulfillment-release-025/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-025/tests/world.json b/tasks/autom-fulfillment-release-025/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..dbc3aa80d2909d479635a6b1b5cb2845500310a5 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/world.json @@ -0,0 +1,306 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-05-02", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-04-27", + "open_units": 6, + "site": "Albany", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2025-05-03", + "open_units": 12, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2025-04-27", + "open_units": 5, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-05-04", + "open_units": 10, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-04-29", + "open_units": 2, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-04-26", + "open_units": 10, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-29", + "open_units": 12, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 46, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CPL": { + "on_hand": 16, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 15, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "PLT" + }, + "Fresno-BRK": { + "on_hand": 15, + "reserved": 0, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CPL": { + "on_hand": 18, + "reserved": 1, + "safety": 8, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-PLT": { + "on_hand": 15, + "reserved": 5, + "safety": 4, + "site": "Fresno", + "sku": "PLT" + }, + "Waco-BRK": { + "on_hand": 23, + "reserved": 3, + "safety": 5, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CPL": { + "on_hand": 25, + "reserved": 1, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-12009-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-21", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-15118-4": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-19", + "sku": "BRK", + "state": "open", + "units": 22 + }, + "SO-19954-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 6 + }, + "SO-24131-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-23", + "sku": "BRK", + "state": "open", + "units": 29 + }, + "SO-24696-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-28", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-38815-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 9 + }, + "SO-50531-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-21", + "sku": "CPL", + "state": "shipped", + "units": 3 + }, + "SO-51291-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-23", + "sku": "PLT", + "state": "open", + "units": 8 + }, + "SO-57140-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 1 + }, + "SO-69898-19": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "BRK", + "state": "open", + "units": 31 + }, + "SO-71121-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "open", + "units": 27 + }, + "SO-71317-9": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-24", + "sku": "PLT", + "state": "open", + "units": 9 + }, + "SO-72910-17": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-23", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-83270-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-21", + "sku": "CPL", + "state": "open", + "units": 11 + }, + "SO-84837-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-24", + "sku": "BRK", + "state": "open", + "units": 5 + }, + "SO-85489-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-25", + "sku": "CPL", + "state": "open", + "units": 4 + }, + "SO-89525-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-04-16", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-91391-18": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-28", + "sku": "PLT", + "state": "open", + "units": 11 + }, + "SO-94270-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-17", + "sku": "CPL", + "state": "open", + "units": 28 + }, + "SO-97275-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-16", + "sku": "PLT", + "state": "open", + "units": 5 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-025/tests/world_check.py b/tasks/autom-fulfillment-release-025/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-025/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-025/validation/openenv.json b/tasks/autom-fulfillment-release-025/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-025/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-026/environment/inputs/apps.py b/tasks/autom-fulfillment-release-026/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-026/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-026/environment/inputs/world.json b/tasks/autom-fulfillment-release-026/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..dd9a45155e7569c4285203d72cff468506481e17 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/environment/inputs/world.json @@ -0,0 +1,382 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-05-18", + "open_units": 10, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-05-19", + "open_units": 1, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-05-23", + "open_units": 11, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-05-20", + "open_units": 1, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-05-25", + "open_units": 1, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-05-19", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-05-24", + "open_units": 4, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-05-25", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-05-26", + "open_units": 12, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-05-21", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-05-26", + "open_units": 12, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-05-24", + "open_units": 3, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-05-27", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-05-24", + "open_units": 5, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2025-05-20", + "open_units": 11, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 28, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 33, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 43, + "reserved": 0, + "safety": 8, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 31, + "reserved": 5, + "safety": 7, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 27, + "reserved": 0, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 24, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-PLT": { + "on_hand": 23, + "reserved": 1, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Tampa-RNG": { + "on_hand": 20, + "reserved": 5, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 30, + "reserved": 1, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 13, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 36, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 43, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 13, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14067-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-14", + "sku": "CAP", + "state": "shipped", + "units": 5 + }, + "SO-19389-13": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 31 + }, + "SO-21328-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 18 + }, + "SO-23944-11": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-14", + "sku": "PLT", + "state": "shipped", + "units": 12 + }, + "SO-29593-2": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-16", + "sku": "CAP", + "state": "open", + "units": 11 + }, + "SO-33559-1": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-11", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-40417-18": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-22", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-45084-8": { + "origin": "Albany", + "priority": 3, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 14 + }, + "SO-55452-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-12", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-56073-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-11", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-58201-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-07", + "sku": "PLT", + "state": "open", + "units": 21 + }, + "SO-58308-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 27 + }, + "SO-60235-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-10", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-62842-12": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-07", + "sku": "CAP", + "state": "open", + "units": 10 + }, + "SO-74037-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-10", + "sku": "CPL", + "state": "open", + "units": 25 + }, + "SO-82008-3": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-12", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-85247-15": { + "origin": "Albany", + "priority": 2, + "promise": "2025-05-20", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-88787-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-15", + "sku": "CAP", + "state": "open", + "units": 29 + }, + "SO-95950-6": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-09", + "sku": "PLT", + "state": "open", + "units": 7 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-026/instruction.md b/tasks/autom-fulfillment-release-026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b0af8c36b5c09b95ac68ca134edbc8e4312cfce7 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Tampa as of 2025-05-16. 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 Waco 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-` 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-05-23. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-` 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. diff --git a/tasks/autom-fulfillment-release-026/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-026/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..0b449bd80593ae3def959c30647323a45b1ccd9f --- /dev/null +++ b/tasks/autom-fulfillment-release-026/solution/files/actions.jsonl @@ -0,0 +1,28 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-60235-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-33559-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-29593-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-82008-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-74037-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-55452-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-95950-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-56073-10", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-62842-12", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-58201-16", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-88787-17", "op": "update"} +{"app": "inventory", "fields": {"reserved": 17}, "id": "Tampa-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 8}, "id": "Tampa-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 15}, "id": "Tampa-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 24}, "id": "Waco-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 12}, "id": "Waco-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 28}, "id": "Waco-CPL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-62842-12", "site": "Tampa", "sku": "CAP", "units": 10}, "id": "pick-SO-62842-12", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-58201-16", "site": "Waco", "sku": "PLT", "units": 21}, "id": "pick-SO-58201-16", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-95950-6", "site": "Tampa", "sku": "PLT", "units": 7}, "id": "pick-SO-95950-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-60235-0", "site": "Tampa", "sku": "CLP", "units": 1}, "id": "pick-SO-60235-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-74037-4", "site": "Waco", "sku": "CPL", "units": 25}, "id": "pick-SO-74037-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-55452-5", "site": "Tampa", "sku": "CLP", "units": 16}, "id": "pick-SO-55452-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-29593-2", "site": "Waco", "sku": "CAP", "units": 11}, "id": "pick-SO-29593-2", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "PLT", "status": "draft", "units": 65}, "id": "req-Tampa-PLT", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CLP", "status": "draft", "units": 24}, "id": "req-Tampa-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "RNG", "status": "draft", "units": 31}, "id": "req-Tampa-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CAP", "status": "draft", "units": 29}, "id": "req-Tampa-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-026/solution/solve.sh b/tasks/autom-fulfillment-release-026/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-026/task.toml b/tasks/autom-fulfillment-release-026/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9b3319f913702d90b54a9628bf682934dbc253c0 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-026" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 26 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-026" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-026/tests/expected.json b/tasks/autom-fulfillment-release-026/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-026/tests/grade.py b/tasks/autom-fulfillment-release-026/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-026/tests/replay.py b/tasks/autom-fulfillment-release-026/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-026/tests/target.json b/tasks/autom-fulfillment-release-026/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..fb679b51d6ce87136f03b7ef4c23e1d522a528e0 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/target.json @@ -0,0 +1,448 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-29593-2": { + "order": "SO-29593-2", + "site": "Waco", + "sku": "CAP", + "units": 11 + }, + "pick-SO-55452-5": { + "order": "SO-55452-5", + "site": "Tampa", + "sku": "CLP", + "units": 16 + }, + "pick-SO-58201-16": { + "order": "SO-58201-16", + "site": "Waco", + "sku": "PLT", + "units": 21 + }, + "pick-SO-60235-0": { + "order": "SO-60235-0", + "site": "Tampa", + "sku": "CLP", + "units": 1 + }, + "pick-SO-62842-12": { + "order": "SO-62842-12", + "site": "Tampa", + "sku": "CAP", + "units": 10 + }, + "pick-SO-74037-4": { + "order": "SO-74037-4", + "site": "Waco", + "sku": "CPL", + "units": 25 + }, + "pick-SO-95950-6": { + "order": "SO-95950-6", + "site": "Tampa", + "sku": "PLT", + "units": 7 + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-05-18", + "open_units": 10, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-05-19", + "open_units": 1, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-05-23", + "open_units": 11, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-05-20", + "open_units": 1, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-05-25", + "open_units": 1, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-05-19", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-05-24", + "open_units": 4, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-05-25", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-05-26", + "open_units": 12, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-05-21", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-05-26", + "open_units": 12, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-05-24", + "open_units": 3, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-05-27", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-05-24", + "open_units": 5, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2025-05-20", + "open_units": 11, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 28, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 33, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 43, + "reserved": 0, + "safety": 8, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 31, + "reserved": 15, + "safety": 7, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 27, + "reserved": 17, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 24, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-PLT": { + "on_hand": 23, + "reserved": 8, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Tampa-RNG": { + "on_hand": 20, + "reserved": 5, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 30, + "reserved": 12, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 13, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 36, + "reserved": 28, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 43, + "reserved": 24, + "safety": 7, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 13, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14067-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-14", + "sku": "CAP", + "state": "shipped", + "units": 5 + }, + "SO-19389-13": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 31 + }, + "SO-21328-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 18 + }, + "SO-23944-11": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-14", + "sku": "PLT", + "state": "shipped", + "units": 12 + }, + "SO-29593-2": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-16", + "sku": "CAP", + "state": "allocated", + "units": 11 + }, + "SO-33559-1": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-11", + "sku": "PLT", + "state": "backorder", + "units": 65 + }, + "SO-40417-18": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-22", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-45084-8": { + "origin": "Albany", + "priority": 3, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 14 + }, + "SO-55452-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-12", + "sku": "CLP", + "state": "allocated", + "units": 16 + }, + "SO-56073-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-11", + "sku": "CLP", + "state": "backorder", + "units": 24 + }, + "SO-58201-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-07", + "sku": "PLT", + "state": "allocated", + "units": 21 + }, + "SO-58308-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 27 + }, + "SO-60235-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-10", + "sku": "CLP", + "state": "allocated", + "units": 1 + }, + "SO-62842-12": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-07", + "sku": "CAP", + "state": "allocated", + "units": 10 + }, + "SO-74037-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-10", + "sku": "CPL", + "state": "allocated", + "units": 25 + }, + "SO-82008-3": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-12", + "sku": "RNG", + "state": "backorder", + "units": 33 + }, + "SO-85247-15": { + "origin": "Albany", + "priority": 2, + "promise": "2025-05-20", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-88787-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-15", + "sku": "CAP", + "state": "backorder", + "units": 29 + }, + "SO-95950-6": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-09", + "sku": "PLT", + "state": "allocated", + "units": 7 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Tampa-CAP": { + "site": "Tampa", + "sku": "CAP", + "status": "draft", + "units": 29 + }, + "req-Tampa-CLP": { + "site": "Tampa", + "sku": "CLP", + "status": "draft", + "units": 24 + }, + "req-Tampa-PLT": { + "site": "Tampa", + "sku": "PLT", + "status": "draft", + "units": 65 + }, + "req-Tampa-RNG": { + "site": "Tampa", + "sku": "RNG", + "status": "draft", + "units": 31 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-026/tests/test.sh b/tasks/autom-fulfillment-release-026/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-026/tests/world.json b/tasks/autom-fulfillment-release-026/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..dd9a45155e7569c4285203d72cff468506481e17 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/world.json @@ -0,0 +1,382 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-05-18", + "open_units": 10, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-05-19", + "open_units": 1, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-05-23", + "open_units": 11, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-PLT": { + "due": "2025-05-20", + "open_units": 1, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-05-25", + "open_units": 1, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-05-19", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-05-24", + "open_units": 4, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-05-25", + "open_units": 7, + "site": "Tampa", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-05-26", + "open_units": 12, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-05-21", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-05-26", + "open_units": 12, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-05-24", + "open_units": 3, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-05-27", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-05-24", + "open_units": 5, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2025-05-20", + "open_units": 11, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 28, + "reserved": 4, + "safety": 8, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 33, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 29, + "reserved": 3, + "safety": 8, + "site": "Albany", + "sku": "CPL" + }, + "Albany-PLT": { + "on_hand": 43, + "reserved": 0, + "safety": 8, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 31, + "reserved": 5, + "safety": 7, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 27, + "reserved": 0, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 24, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-PLT": { + "on_hand": 23, + "reserved": 1, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Tampa-RNG": { + "on_hand": 20, + "reserved": 5, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 30, + "reserved": 1, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 13, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 36, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-PLT": { + "on_hand": 43, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 13, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14067-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-14", + "sku": "CAP", + "state": "shipped", + "units": 5 + }, + "SO-19389-13": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 31 + }, + "SO-21328-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 18 + }, + "SO-23944-11": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-14", + "sku": "PLT", + "state": "shipped", + "units": 12 + }, + "SO-29593-2": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-16", + "sku": "CAP", + "state": "open", + "units": 11 + }, + "SO-33559-1": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-11", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-40417-18": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-22", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-45084-8": { + "origin": "Albany", + "priority": 3, + "promise": "2025-05-21", + "sku": "RNG", + "state": "open", + "units": 14 + }, + "SO-55452-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-12", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-56073-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-11", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-58201-16": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-07", + "sku": "PLT", + "state": "open", + "units": 21 + }, + "SO-58308-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-05-20", + "sku": "CPL", + "state": "open", + "units": 27 + }, + "SO-60235-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-10", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-62842-12": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-07", + "sku": "CAP", + "state": "open", + "units": 10 + }, + "SO-74037-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-05-10", + "sku": "CPL", + "state": "open", + "units": 25 + }, + "SO-82008-3": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-12", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-85247-15": { + "origin": "Albany", + "priority": 2, + "promise": "2025-05-20", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-88787-17": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-15", + "sku": "CAP", + "state": "open", + "units": 29 + }, + "SO-95950-6": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-05-09", + "sku": "PLT", + "state": "open", + "units": 7 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-026/tests/world_check.py b/tasks/autom-fulfillment-release-026/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-026/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-026/validation/openenv.json b/tasks/autom-fulfillment-release-026/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-026/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-029/environment/inputs/apps.py b/tasks/autom-fulfillment-release-029/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-029/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-029/environment/inputs/world.json b/tasks/autom-fulfillment-release-029/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..db6849b8607a5a0c98d44e3fa87fbe67de31365b --- /dev/null +++ b/tasks/autom-fulfillment-release-029/environment/inputs/world.json @@ -0,0 +1,324 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-07-26", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-07-31", + "open_units": 11, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-08-04", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-07-29", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2025-08-01", + "open_units": 3, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2025-07-31", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-07-27", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2025-08-03", + "open_units": 11, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-07-26", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-27", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-08-01", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-07-27", + "open_units": 8, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 14, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 29, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 45, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-RNG": { + "on_hand": 30, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 21, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 13, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 42, + "reserved": 1, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-RNG": { + "on_hand": 27, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 32, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 41, + "reserved": 4, + "safety": 7, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 27, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17351-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-21", + "sku": "CAP", + "state": "open", + "units": 16 + }, + "SO-22728-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-27511-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "RNG", + "state": "open", + "units": 27 + }, + "SO-29140-13": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-19", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-29205-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-46756-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "RNG", + "state": "shipped", + "units": 31 + }, + "SO-50207-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "CLP", + "state": "open", + "units": 13 + }, + "SO-50601-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CAP", + "state": "open", + "units": 22 + }, + "SO-57103-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-25", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-61370-8": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "BRK", + "state": "shipped", + "units": 26 + }, + "SO-63567-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "open", + "units": 31 + }, + "SO-72673-1": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-84008-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-87938-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-21", + "sku": "BRK", + "state": "open", + "units": 20 + }, + "SO-89032-7": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 9 + }, + "SO-89468-12": { + "origin": "Denver", + "priority": 3, + "promise": "2025-07-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-92389-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 22 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-029/instruction.md b/tasks/autom-fulfillment-release-029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ea540b4d9aaac1fb2b6e2cc855c543a096015484 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Denver as of 2025-07-24. 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. If the origin cannot cover the complete order, try Albany 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-` 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-07-31. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-` 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. diff --git a/tasks/autom-fulfillment-release-029/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-029/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..e35d078a94f6df65d171a622123002705799ac9f --- /dev/null +++ b/tasks/autom-fulfillment-release-029/solution/files/actions.jsonl @@ -0,0 +1,21 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-29205-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-72673-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-50207-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17351-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-87938-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-27511-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-63567-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-84008-10", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-50601-15", "op": "update"} +{"app": "inventory", "fields": {"reserved": 3}, "id": "Denver-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 24}, "id": "Denver-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 13}, "id": "Albany-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 20}, "id": "Albany-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-29205-0", "site": "Denver", "sku": "BRK", "units": 1}, "id": "pick-SO-29205-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-84008-10", "site": "Denver", "sku": "CLP", "units": 23}, "id": "pick-SO-84008-10", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-17351-3", "site": "Albany", "sku": "CAP", "units": 16}, "id": "pick-SO-17351-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-50207-2", "site": "Albany", "sku": "CLP", "units": 13}, "id": "pick-SO-50207-2", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "RNG", "status": "draft", "units": 92}, "id": "req-Denver-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "CAP", "status": "draft", "units": 22}, "id": "req-Denver-CAP", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "BRK", "status": "draft", "units": 20}, "id": "req-Denver-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "CLP", "status": "draft", "units": 25}, "id": "req-Denver-CLP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-029/solution/solve.sh b/tasks/autom-fulfillment-release-029/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-029/task.toml b/tasks/autom-fulfillment-release-029/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f856f8116d40374d425a0ec9722c4b67a4acb458 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-029" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 29 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-029" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-029/tests/expected.json b/tasks/autom-fulfillment-release-029/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-029/tests/grade.py b/tasks/autom-fulfillment-release-029/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-029/tests/replay.py b/tasks/autom-fulfillment-release-029/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-029/tests/target.json b/tasks/autom-fulfillment-release-029/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..87df4e4c564dd7924dd6672f31d9060a2dfb510f --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/target.json @@ -0,0 +1,372 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-17351-3": { + "order": "SO-17351-3", + "site": "Albany", + "sku": "CAP", + "units": 16 + }, + "pick-SO-29205-0": { + "order": "SO-29205-0", + "site": "Denver", + "sku": "BRK", + "units": 1 + }, + "pick-SO-50207-2": { + "order": "SO-50207-2", + "site": "Albany", + "sku": "CLP", + "units": 13 + }, + "pick-SO-84008-10": { + "order": "SO-84008-10", + "site": "Denver", + "sku": "CLP", + "units": 23 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-07-26", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-07-31", + "open_units": 11, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-08-04", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-07-29", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2025-08-01", + "open_units": 3, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2025-07-31", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-07-27", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2025-08-03", + "open_units": 11, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-07-26", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-27", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-08-01", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-07-27", + "open_units": 8, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 14, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 29, + "reserved": 20, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 45, + "reserved": 13, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-RNG": { + "on_hand": 30, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 21, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 13, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 42, + "reserved": 24, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-RNG": { + "on_hand": 27, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 32, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 41, + "reserved": 4, + "safety": 7, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 27, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17351-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-21", + "sku": "CAP", + "state": "allocated", + "units": 16 + }, + "SO-22728-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-27511-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "RNG", + "state": "backorder", + "units": 27 + }, + "SO-29140-13": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-19", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-29205-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "BRK", + "state": "allocated", + "units": 1 + }, + "SO-46756-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "RNG", + "state": "shipped", + "units": 31 + }, + "SO-50207-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "CLP", + "state": "allocated", + "units": 13 + }, + "SO-50601-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CAP", + "state": "backorder", + "units": 22 + }, + "SO-57103-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-25", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-61370-8": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "BRK", + "state": "shipped", + "units": 26 + }, + "SO-63567-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "backorder", + "units": 31 + }, + "SO-72673-1": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-84008-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CLP", + "state": "allocated", + "units": 23 + }, + "SO-87938-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-21", + "sku": "BRK", + "state": "backorder", + "units": 20 + }, + "SO-89032-7": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 9 + }, + "SO-89468-12": { + "origin": "Denver", + "priority": 3, + "promise": "2025-07-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-92389-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 22 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Denver-BRK": { + "site": "Denver", + "sku": "BRK", + "status": "draft", + "units": 20 + }, + "req-Denver-CAP": { + "site": "Denver", + "sku": "CAP", + "status": "draft", + "units": 22 + }, + "req-Denver-CLP": { + "site": "Denver", + "sku": "CLP", + "status": "draft", + "units": 25 + }, + "req-Denver-RNG": { + "site": "Denver", + "sku": "RNG", + "status": "draft", + "units": 92 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-029/tests/test.sh b/tasks/autom-fulfillment-release-029/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-029/tests/world.json b/tasks/autom-fulfillment-release-029/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..db6849b8607a5a0c98d44e3fa87fbe67de31365b --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/world.json @@ -0,0 +1,324 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-07-26", + "open_units": 12, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-07-31", + "open_units": 11, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-08-04", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-07-29", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2025-08-01", + "open_units": 3, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2025-07-31", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-07-27", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-RNG": { + "due": "2025-08-03", + "open_units": 11, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-07-26", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-27", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-08-01", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-07-27", + "open_units": 8, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 14, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 29, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 45, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-RNG": { + "on_hand": 30, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Denver-BRK": { + "on_hand": 21, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 13, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 42, + "reserved": 1, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-RNG": { + "on_hand": 27, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 32, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 41, + "reserved": 4, + "safety": 7, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 27, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17351-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-21", + "sku": "CAP", + "state": "open", + "units": 16 + }, + "SO-22728-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-27511-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "RNG", + "state": "open", + "units": 27 + }, + "SO-29140-13": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-19", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-29205-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-46756-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "RNG", + "state": "shipped", + "units": 31 + }, + "SO-50207-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-19", + "sku": "CLP", + "state": "open", + "units": 13 + }, + "SO-50601-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CAP", + "state": "open", + "units": 22 + }, + "SO-57103-16": { + "origin": "Waco", + "priority": 3, + "promise": "2025-07-25", + "sku": "BRK", + "state": "open", + "units": 33 + }, + "SO-61370-8": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-20", + "sku": "BRK", + "state": "shipped", + "units": 26 + }, + "SO-63567-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-24", + "sku": "CLP", + "state": "open", + "units": 31 + }, + "SO-72673-1": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-18", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-84008-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-20", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-87938-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-21", + "sku": "BRK", + "state": "open", + "units": 20 + }, + "SO-89032-7": { + "origin": "Denver", + "priority": 2, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 9 + }, + "SO-89468-12": { + "origin": "Denver", + "priority": 3, + "promise": "2025-07-16", + "sku": "BRK", + "state": "shipped", + "units": 12 + }, + "SO-92389-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-07-29", + "sku": "CAP", + "state": "shipped", + "units": 22 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-029/tests/world_check.py b/tasks/autom-fulfillment-release-029/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-029/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-029/validation/openenv.json b/tasks/autom-fulfillment-release-029/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-029/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-031/environment/inputs/apps.py b/tasks/autom-fulfillment-release-031/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-031/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-031/environment/inputs/world.json b/tasks/autom-fulfillment-release-031/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..aaffd96dae16159be5f8c12116b54740f7f7e97a --- /dev/null +++ b/tasks/autom-fulfillment-release-031/environment/inputs/world.json @@ -0,0 +1,284 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2025-09-10", + "open_units": 10, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-09-19", + "open_units": 7, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-09-10", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-09-09", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-09-18", + "open_units": 1, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-09-18", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-09-15", + "open_units": 10, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-09-17", + "open_units": 10, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-09-18", + "open_units": 9, + "site": "Waco", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-MDL": { + "due": "2025-09-18", + "open_units": 2, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 19, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 21, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 20, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 46, + "reserved": 0, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Tampa-BRK": { + "on_hand": 26, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 4, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 30, + "reserved": 5, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 26, + "reserved": 2, + "safety": 4, + "site": "Tampa", + "sku": "MDL" + }, + "Waco-BRK": { + "on_hand": 22, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 17, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 43, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "MDL" + } + }, + "orders": { + "SO-10866-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-14", + "sku": "CLP", + "state": "open", + "units": 29 + }, + "SO-19118-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-07", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-36152-8": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-09", + "sku": "MDL", + "state": "shipped", + "units": 10 + }, + "SO-40754-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-13", + "sku": "BRK", + "state": "open", + "units": 25 + }, + "SO-42856-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-09-12", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-43065-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-03", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-51754-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "CLP", + "state": "open", + "units": 10 + }, + "SO-52135-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "MDL", + "state": "open", + "units": 31 + }, + "SO-56808-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-05", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-61629-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-65938-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-09-11", + "sku": "CAP", + "state": "open", + "units": 5 + }, + "SO-72068-2": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-02", + "sku": "BRK", + "state": "open", + "units": 9 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-031/instruction.md b/tasks/autom-fulfillment-release-031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..033bd2c44d35333ede0a6ee3c1e601fc09c2b682 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Tampa as of 2025-09-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 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-` 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-09-15. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-` 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. diff --git a/tasks/autom-fulfillment-release-031/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-031/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..3517363f2e26726e3b2605b52ebb7b5a153abfd1 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/solution/files/actions.jsonl @@ -0,0 +1,19 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-56808-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-43065-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-72068-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-51754-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-52135-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-19118-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-61629-6", "op": "update"} +{"app": "inventory", "fields": {"reserved": 3}, "id": "Tampa-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 18}, "id": "Tampa-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 11}, "id": "Tampa-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 15}, "id": "Tampa-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 31}, "id": "Denver-MDL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-56808-0", "site": "Tampa", "sku": "MDL", "units": 1}, "id": "pick-SO-56808-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-72068-2", "site": "Tampa", "sku": "BRK", "units": 9}, "id": "pick-SO-72068-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-51754-3", "site": "Tampa", "sku": "CLP", "units": 10}, "id": "pick-SO-51754-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-52135-4", "site": "Denver", "sku": "MDL", "units": 31}, "id": "pick-SO-52135-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-19118-5", "site": "Tampa", "sku": "CAP", "units": 14}, "id": "pick-SO-19118-5", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "BRK", "status": "draft", "units": 18}, "id": "req-Tampa-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CAP", "status": "draft", "units": 65}, "id": "req-Tampa-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-031/solution/solve.sh b/tasks/autom-fulfillment-release-031/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-031/task.toml b/tasks/autom-fulfillment-release-031/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4e52e1a8ff51363d5e9a0b6735ceede3ff30feff --- /dev/null +++ b/tasks/autom-fulfillment-release-031/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-031" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 31 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-031" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-031/tests/expected.json b/tasks/autom-fulfillment-release-031/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-031/tests/grade.py b/tasks/autom-fulfillment-release-031/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-031/tests/replay.py b/tasks/autom-fulfillment-release-031/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-031/tests/target.json b/tasks/autom-fulfillment-release-031/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..025960451131557ffb38694a15faf276426864ae --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/target.json @@ -0,0 +1,326 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-19118-5": { + "order": "SO-19118-5", + "site": "Tampa", + "sku": "CAP", + "units": 14 + }, + "pick-SO-51754-3": { + "order": "SO-51754-3", + "site": "Tampa", + "sku": "CLP", + "units": 10 + }, + "pick-SO-52135-4": { + "order": "SO-52135-4", + "site": "Denver", + "sku": "MDL", + "units": 31 + }, + "pick-SO-56808-0": { + "order": "SO-56808-0", + "site": "Tampa", + "sku": "MDL", + "units": 1 + }, + "pick-SO-72068-2": { + "order": "SO-72068-2", + "site": "Tampa", + "sku": "BRK", + "units": 9 + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2025-09-10", + "open_units": 10, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-09-19", + "open_units": 7, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-09-10", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-09-09", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-09-18", + "open_units": 1, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-09-18", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-09-15", + "open_units": 10, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-09-17", + "open_units": 10, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-09-18", + "open_units": 9, + "site": "Waco", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-MDL": { + "due": "2025-09-18", + "open_units": 2, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 19, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 21, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 20, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 46, + "reserved": 31, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Tampa-BRK": { + "on_hand": 26, + "reserved": 11, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 18, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 30, + "reserved": 15, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 26, + "reserved": 3, + "safety": 4, + "site": "Tampa", + "sku": "MDL" + }, + "Waco-BRK": { + "on_hand": 22, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 17, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 43, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "MDL" + } + }, + "orders": { + "SO-10866-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-14", + "sku": "CLP", + "state": "open", + "units": 29 + }, + "SO-19118-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-07", + "sku": "CAP", + "state": "allocated", + "units": 14 + }, + "SO-36152-8": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-09", + "sku": "MDL", + "state": "shipped", + "units": 10 + }, + "SO-40754-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-13", + "sku": "BRK", + "state": "open", + "units": 25 + }, + "SO-42856-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-09-12", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-43065-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-03", + "sku": "CAP", + "state": "backorder", + "units": 65 + }, + "SO-51754-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "CLP", + "state": "allocated", + "units": 10 + }, + "SO-52135-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "MDL", + "state": "allocated", + "units": 31 + }, + "SO-56808-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-05", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-61629-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "BRK", + "state": "backorder", + "units": 18 + }, + "SO-65938-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-09-11", + "sku": "CAP", + "state": "open", + "units": 5 + }, + "SO-72068-2": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-02", + "sku": "BRK", + "state": "allocated", + "units": 9 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Tampa-BRK": { + "site": "Tampa", + "sku": "BRK", + "status": "draft", + "units": 18 + }, + "req-Tampa-CAP": { + "site": "Tampa", + "sku": "CAP", + "status": "draft", + "units": 65 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-031/tests/test.sh b/tasks/autom-fulfillment-release-031/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-031/tests/world.json b/tasks/autom-fulfillment-release-031/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..aaffd96dae16159be5f8c12116b54740f7f7e97a --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/world.json @@ -0,0 +1,284 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2025-09-10", + "open_units": 10, + "site": "Denver", + "sku": "BRK", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-09-19", + "open_units": 7, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-09-10", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-09-09", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-09-18", + "open_units": 1, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2025-09-18", + "open_units": 10, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-09-15", + "open_units": 10, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-09-17", + "open_units": 10, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-09-18", + "open_units": 9, + "site": "Waco", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2025-09-18", + "open_units": 4, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-MDL": { + "due": "2025-09-18", + "open_units": 2, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 19, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 21, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 20, + "reserved": 1, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 46, + "reserved": 0, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Tampa-BRK": { + "on_hand": 26, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 4, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 30, + "reserved": 5, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 26, + "reserved": 2, + "safety": 4, + "site": "Tampa", + "sku": "MDL" + }, + "Waco-BRK": { + "on_hand": 22, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 17, + "reserved": 4, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 43, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "MDL" + } + }, + "orders": { + "SO-10866-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-14", + "sku": "CLP", + "state": "open", + "units": 29 + }, + "SO-19118-5": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-07", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-36152-8": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-09", + "sku": "MDL", + "state": "shipped", + "units": 10 + }, + "SO-40754-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-13", + "sku": "BRK", + "state": "open", + "units": 25 + }, + "SO-42856-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-09-12", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-43065-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-03", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-51754-3": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "CLP", + "state": "open", + "units": 10 + }, + "SO-52135-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "MDL", + "state": "open", + "units": 31 + }, + "SO-56808-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-05", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-61629-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-09-02", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-65938-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-09-11", + "sku": "CAP", + "state": "open", + "units": 5 + }, + "SO-72068-2": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-02", + "sku": "BRK", + "state": "open", + "units": 9 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-031/tests/world_check.py b/tasks/autom-fulfillment-release-031/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-031/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-031/validation/openenv.json b/tasks/autom-fulfillment-release-031/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-031/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-032/environment/inputs/apps.py b/tasks/autom-fulfillment-release-032/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-032/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-032/environment/inputs/world.json b/tasks/autom-fulfillment-release-032/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..4ac8392020fca6ab8d12621f8afc069ced7c8000 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/environment/inputs/world.json @@ -0,0 +1,290 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Fresno-BRK": { + "due": "2025-10-04", + "open_units": 5, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-10-11", + "open_units": 10, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-11", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-10-07", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-10-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-10-12", + "open_units": 9, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-10-08", + "open_units": 11, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-10-03", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-10-02", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + } + }, + "inventory": { + "Fresno-BRK": { + "on_hand": 12, + "reserved": 0, + "safety": 5, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 44, + "reserved": 5, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 27, + "reserved": 1, + "safety": 7, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 46, + "reserved": 2, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Tampa", + "sku": "CLP" + }, + "Waco-BRK": { + "on_hand": 15, + "reserved": 5, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 19, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 31, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "CLP" + } + }, + "orders": { + "SO-12121-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "shipped", + "units": 11 + }, + "SO-16266-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-10-05", + "sku": "BRK", + "state": "open", + "units": 9 + }, + "SO-22972-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-28", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-23610-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "open", + "units": 27 + }, + "SO-28088-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-29", + "sku": "CAP", + "state": "open", + "units": 28 + }, + "SO-29028-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-25", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-42258-12": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 14 + }, + "SO-43313-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "CLP", + "state": "open", + "units": 5 + }, + "SO-45176-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-54705-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 26 + }, + "SO-55921-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-26", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-68716-16": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-10-04", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-69515-14": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-28", + "sku": "CAP", + "state": "open", + "units": 17 + }, + "SO-79101-15": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-85357-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "BRK", + "state": "open", + "units": 4 + }, + "SO-91003-11": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-24", + "sku": "CAP", + "state": "shipped", + "units": 22 + }, + "SO-92849-17": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-04", + "sku": "CAP", + "state": "open", + "units": 27 + }, + "SO-99199-10": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-032/instruction.md b/tasks/autom-fulfillment-release-032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5a1dc68c7fba614f6b44ad148928ffd6209c7478 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Fresno as of 2025-10-01. 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 Fresno. If the origin cannot cover the complete order, try Waco 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-` 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 Fresno, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-10-08. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Fresno-` 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. diff --git a/tasks/autom-fulfillment-release-032/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-032/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..7a8574bd3554404229a4f2b3c24b275db2a3fbd5 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-29028-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-55921-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-28088-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43313-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-85357-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-23610-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-22972-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-79101-15", "op": "update"} +{"app": "inventory", "fields": {"reserved": 15}, "id": "Fresno-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 4}, "id": "Fresno-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 32}, "id": "Fresno-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 17}, "id": "Waco-CLP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-29028-0", "site": "Fresno", "sku": "CLP", "units": 1}, "id": "pick-SO-29028-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-79101-15", "site": "Fresno", "sku": "CLP", "units": 8}, "id": "pick-SO-79101-15", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-23610-5", "site": "Fresno", "sku": "CAP", "units": 27}, "id": "pick-SO-23610-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-22972-6", "site": "Waco", "sku": "CLP", "units": 16}, "id": "pick-SO-22972-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43313-3", "site": "Fresno", "sku": "CLP", "units": 5}, "id": "pick-SO-43313-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-85357-4", "site": "Fresno", "sku": "BRK", "units": 4}, "id": "pick-SO-85357-4", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "BRK", "status": "draft", "units": 65}, "id": "req-Fresno-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CAP", "status": "draft", "units": 28}, "id": "req-Fresno-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-032/solution/solve.sh b/tasks/autom-fulfillment-release-032/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-032/task.toml b/tasks/autom-fulfillment-release-032/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7774478b8f24b556622847bd10c6b5a592714918 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-032" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 32 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-032" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-032/tests/expected.json b/tasks/autom-fulfillment-release-032/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-032/tests/grade.py b/tasks/autom-fulfillment-release-032/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-032/tests/replay.py b/tasks/autom-fulfillment-release-032/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-032/tests/target.json b/tasks/autom-fulfillment-release-032/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..82a447846c14125f4e9e52957894639459647ad7 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/target.json @@ -0,0 +1,338 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-22972-6": { + "order": "SO-22972-6", + "site": "Waco", + "sku": "CLP", + "units": 16 + }, + "pick-SO-23610-5": { + "order": "SO-23610-5", + "site": "Fresno", + "sku": "CAP", + "units": 27 + }, + "pick-SO-29028-0": { + "order": "SO-29028-0", + "site": "Fresno", + "sku": "CLP", + "units": 1 + }, + "pick-SO-43313-3": { + "order": "SO-43313-3", + "site": "Fresno", + "sku": "CLP", + "units": 5 + }, + "pick-SO-79101-15": { + "order": "SO-79101-15", + "site": "Fresno", + "sku": "CLP", + "units": 8 + }, + "pick-SO-85357-4": { + "order": "SO-85357-4", + "site": "Fresno", + "sku": "BRK", + "units": 4 + } + }, + "inbound": { + "PO-Fresno-BRK": { + "due": "2025-10-04", + "open_units": 5, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-10-11", + "open_units": 10, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-11", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-10-07", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-10-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-10-12", + "open_units": 9, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-10-08", + "open_units": 11, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-10-03", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-10-02", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + } + }, + "inventory": { + "Fresno-BRK": { + "on_hand": 12, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 44, + "reserved": 32, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 27, + "reserved": 15, + "safety": 7, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 46, + "reserved": 2, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Tampa", + "sku": "CLP" + }, + "Waco-BRK": { + "on_hand": 15, + "reserved": 5, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 19, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 31, + "reserved": 17, + "safety": 6, + "site": "Waco", + "sku": "CLP" + } + }, + "orders": { + "SO-12121-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "shipped", + "units": 11 + }, + "SO-16266-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-10-05", + "sku": "BRK", + "state": "open", + "units": 9 + }, + "SO-22972-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-28", + "sku": "CLP", + "state": "allocated", + "units": 16 + }, + "SO-23610-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "allocated", + "units": 27 + }, + "SO-28088-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-29", + "sku": "CAP", + "state": "backorder", + "units": 28 + }, + "SO-29028-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-25", + "sku": "CLP", + "state": "allocated", + "units": 1 + }, + "SO-42258-12": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 14 + }, + "SO-43313-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "CLP", + "state": "allocated", + "units": 5 + }, + "SO-45176-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-54705-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 26 + }, + "SO-55921-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-26", + "sku": "BRK", + "state": "backorder", + "units": 65 + }, + "SO-68716-16": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-10-04", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-69515-14": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-28", + "sku": "CAP", + "state": "open", + "units": 17 + }, + "SO-79101-15": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "allocated", + "units": 8 + }, + "SO-85357-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "BRK", + "state": "allocated", + "units": 4 + }, + "SO-91003-11": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-24", + "sku": "CAP", + "state": "shipped", + "units": 22 + }, + "SO-92849-17": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-04", + "sku": "CAP", + "state": "open", + "units": 27 + }, + "SO-99199-10": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Fresno-BRK": { + "site": "Fresno", + "sku": "BRK", + "status": "draft", + "units": 65 + }, + "req-Fresno-CAP": { + "site": "Fresno", + "sku": "CAP", + "status": "draft", + "units": 28 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-032/tests/test.sh b/tasks/autom-fulfillment-release-032/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-032/tests/world.json b/tasks/autom-fulfillment-release-032/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..4ac8392020fca6ab8d12621f8afc069ced7c8000 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/world.json @@ -0,0 +1,290 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Fresno-BRK": { + "due": "2025-10-04", + "open_units": 5, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-10-11", + "open_units": 10, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-11", + "open_units": 12, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-10-07", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-10-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-10-12", + "open_units": 9, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-10-08", + "open_units": 11, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-10-03", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-10-02", + "open_units": 5, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + } + }, + "inventory": { + "Fresno-BRK": { + "on_hand": 12, + "reserved": 0, + "safety": 5, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 44, + "reserved": 5, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 27, + "reserved": 1, + "safety": 7, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 46, + "reserved": 2, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Tampa", + "sku": "CLP" + }, + "Waco-BRK": { + "on_hand": 15, + "reserved": 5, + "safety": 8, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 19, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 31, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "CLP" + } + }, + "orders": { + "SO-12121-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "shipped", + "units": 11 + }, + "SO-16266-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-10-05", + "sku": "BRK", + "state": "open", + "units": 9 + }, + "SO-22972-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-28", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-23610-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-27", + "sku": "CAP", + "state": "open", + "units": 27 + }, + "SO-28088-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-29", + "sku": "CAP", + "state": "open", + "units": 28 + }, + "SO-29028-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-25", + "sku": "CLP", + "state": "open", + "units": 1 + }, + "SO-42258-12": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 14 + }, + "SO-43313-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "CLP", + "state": "open", + "units": 5 + }, + "SO-45176-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-54705-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-09-26", + "sku": "CLP", + "state": "shipped", + "units": 26 + }, + "SO-55921-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-26", + "sku": "BRK", + "state": "open", + "units": 65 + }, + "SO-68716-16": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-10-04", + "sku": "BRK", + "state": "open", + "units": 18 + }, + "SO-69515-14": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-09-28", + "sku": "CAP", + "state": "open", + "units": 17 + }, + "SO-79101-15": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-09-26", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-85357-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-29", + "sku": "BRK", + "state": "open", + "units": 4 + }, + "SO-91003-11": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-09-24", + "sku": "CAP", + "state": "shipped", + "units": 22 + }, + "SO-92849-17": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-04", + "sku": "CAP", + "state": "open", + "units": 27 + }, + "SO-99199-10": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-10-07", + "sku": "BRK", + "state": "open", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-032/tests/world_check.py b/tasks/autom-fulfillment-release-032/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-032/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-032/validation/openenv.json b/tasks/autom-fulfillment-release-032/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-032/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-033/environment/inputs/apps.py b/tasks/autom-fulfillment-release-033/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-033/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-033/environment/inputs/world.json b/tasks/autom-fulfillment-release-033/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..3b9632e97a0c2bb3595519d4c9b3a11867b13f1c --- /dev/null +++ b/tasks/autom-fulfillment-release-033/environment/inputs/world.json @@ -0,0 +1,366 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-11-04", + "open_units": 8, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-10-30", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-10-31", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-10-30", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-04", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-10-27", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2025-11-04", + "open_units": 3, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-10-30", + "open_units": 1, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-10-31", + "open_units": 10, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-10-27", + "open_units": 8, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2025-11-04", + "open_units": 11, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-30", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-11-01", + "open_units": 5, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-11-01", + "open_units": 8, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-11-04", + "open_units": 8, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 29, + "reserved": 2, + "safety": 6, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 42, + "reserved": 4, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-MDL": { + "on_hand": 46, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-PLT": { + "on_hand": 36, + "reserved": 1, + "safety": 7, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 5, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 39, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 44, + "reserved": 1, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 36, + "reserved": 0, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 33, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 26, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 12, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + } + }, + "orders": { + "SO-23869-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-26385-11": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-29", + "sku": "PLT", + "state": "shipped", + "units": 11 + }, + "SO-30795-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-10-20", + "sku": "PLT", + "state": "open", + "units": 30 + }, + "SO-34816-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-28", + "sku": "RNG", + "state": "shipped", + "units": 23 + }, + "SO-42398-4": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "CAP", + "state": "open", + "units": 28 + }, + "SO-47008-10": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-27", + "sku": "MDL", + "state": "open", + "units": 6 + }, + "SO-47058-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-22", + "sku": "CLP", + "state": "open", + "units": 9 + }, + "SO-48050-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-10-23", + "sku": "MDL", + "state": "open", + "units": 33 + }, + "SO-49084-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-20", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-51766-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-25", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-52065-5": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-17", + "sku": "MDL", + "state": "open", + "units": 8 + }, + "SO-53477-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-24", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-60064-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-20", + "sku": "CAP", + "state": "shipped", + "units": 13 + }, + "SO-74274-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "CLP", + "state": "open", + "units": 10 + }, + "SO-80189-14": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-15", + "sku": "CAP", + "state": "open", + "units": 11 + }, + "SO-89617-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-23", + "sku": "PLT", + "state": "open", + "units": 16 + }, + "SO-99173-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "RNG", + "state": "open", + "units": 15 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-033/instruction.md b/tasks/autom-fulfillment-release-033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3777fd0acf9d4656d40ec361d4d9be992de28995 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Albany as of 2025-10-24. 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 Albany. 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-` 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 Albany, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-10-31. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Albany-` 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. diff --git a/tasks/autom-fulfillment-release-033/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-033/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..ebec5aefad4d5b79f73de624c282d6b72e65fa58 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/solution/files/actions.jsonl @@ -0,0 +1,23 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-53477-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-23869-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-74274-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-99173-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-42398-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-52065-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-89617-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-47058-12", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-49084-13", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-80189-14", "op": "update"} +{"app": "inventory", "fields": {"reserved": 9}, "id": "Albany-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 17}, "id": "Albany-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 23}, "id": "Albany-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 13}, "id": "Albany-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-53477-0", "site": "Albany", "sku": "MDL", "units": 1}, "id": "pick-SO-53477-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-52065-5", "site": "Albany", "sku": "MDL", "units": 8}, "id": "pick-SO-52065-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-89617-6", "site": "Albany", "sku": "PLT", "units": 16}, "id": "pick-SO-89617-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-80189-14", "site": "Albany", "sku": "CAP", "units": 11}, "id": "pick-SO-80189-14", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-74274-2", "site": "Albany", "sku": "CLP", "units": 10}, "id": "pick-SO-74274-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-47058-12", "site": "Albany", "sku": "CLP", "units": 9}, "id": "pick-SO-47058-12", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "RNG", "status": "draft", "units": 22}, "id": "req-Albany-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "PLT", "status": "draft", "units": 65}, "id": "req-Albany-PLT", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CAP", "status": "draft", "units": 28}, "id": "req-Albany-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-033/solution/solve.sh b/tasks/autom-fulfillment-release-033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-033/task.toml b/tasks/autom-fulfillment-release-033/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ca487f86f2b998d29652d3889c9f0ec1c53b048c --- /dev/null +++ b/tasks/autom-fulfillment-release-033/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-033" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 33 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-033" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-033/tests/expected.json b/tasks/autom-fulfillment-release-033/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-033/tests/grade.py b/tasks/autom-fulfillment-release-033/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-033/tests/replay.py b/tasks/autom-fulfillment-release-033/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-033/tests/target.json b/tasks/autom-fulfillment-release-033/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..702768d303a92262b5d3fbe49c36a90bcd12aa5f --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/target.json @@ -0,0 +1,420 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-47058-12": { + "order": "SO-47058-12", + "site": "Albany", + "sku": "CLP", + "units": 9 + }, + "pick-SO-52065-5": { + "order": "SO-52065-5", + "site": "Albany", + "sku": "MDL", + "units": 8 + }, + "pick-SO-53477-0": { + "order": "SO-53477-0", + "site": "Albany", + "sku": "MDL", + "units": 1 + }, + "pick-SO-74274-2": { + "order": "SO-74274-2", + "site": "Albany", + "sku": "CLP", + "units": 10 + }, + "pick-SO-80189-14": { + "order": "SO-80189-14", + "site": "Albany", + "sku": "CAP", + "units": 11 + }, + "pick-SO-89617-6": { + "order": "SO-89617-6", + "site": "Albany", + "sku": "PLT", + "units": 16 + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-11-04", + "open_units": 8, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-10-30", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-10-31", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-10-30", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-04", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-10-27", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2025-11-04", + "open_units": 3, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-10-30", + "open_units": 1, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-10-31", + "open_units": 10, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-10-27", + "open_units": 8, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2025-11-04", + "open_units": 11, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-30", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-11-01", + "open_units": 5, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-11-01", + "open_units": 8, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-11-04", + "open_units": 8, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 29, + "reserved": 13, + "safety": 6, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 42, + "reserved": 23, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-MDL": { + "on_hand": 46, + "reserved": 9, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-PLT": { + "on_hand": 36, + "reserved": 17, + "safety": 7, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 5, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 39, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 44, + "reserved": 1, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 36, + "reserved": 0, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 33, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 26, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 12, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + } + }, + "orders": { + "SO-23869-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "PLT", + "state": "backorder", + "units": 65 + }, + "SO-26385-11": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-29", + "sku": "PLT", + "state": "shipped", + "units": 11 + }, + "SO-30795-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-10-20", + "sku": "PLT", + "state": "open", + "units": 30 + }, + "SO-34816-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-28", + "sku": "RNG", + "state": "shipped", + "units": 23 + }, + "SO-42398-4": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "CAP", + "state": "backorder", + "units": 28 + }, + "SO-47008-10": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-27", + "sku": "MDL", + "state": "open", + "units": 6 + }, + "SO-47058-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-22", + "sku": "CLP", + "state": "allocated", + "units": 9 + }, + "SO-48050-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-10-23", + "sku": "MDL", + "state": "open", + "units": 33 + }, + "SO-49084-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-20", + "sku": "RNG", + "state": "backorder", + "units": 7 + }, + "SO-51766-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-25", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-52065-5": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-17", + "sku": "MDL", + "state": "allocated", + "units": 8 + }, + "SO-53477-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-24", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-60064-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-20", + "sku": "CAP", + "state": "shipped", + "units": 13 + }, + "SO-74274-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "CLP", + "state": "allocated", + "units": 10 + }, + "SO-80189-14": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-15", + "sku": "CAP", + "state": "allocated", + "units": 11 + }, + "SO-89617-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-23", + "sku": "PLT", + "state": "allocated", + "units": 16 + }, + "SO-99173-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "RNG", + "state": "backorder", + "units": 15 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Albany-CAP": { + "site": "Albany", + "sku": "CAP", + "status": "draft", + "units": 28 + }, + "req-Albany-PLT": { + "site": "Albany", + "sku": "PLT", + "status": "draft", + "units": 65 + }, + "req-Albany-RNG": { + "site": "Albany", + "sku": "RNG", + "status": "draft", + "units": 22 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-033/tests/test.sh b/tasks/autom-fulfillment-release-033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-033/tests/world.json b/tasks/autom-fulfillment-release-033/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..3b9632e97a0c2bb3595519d4c9b3a11867b13f1c --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/world.json @@ -0,0 +1,366 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-11-04", + "open_units": 8, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-CLP": { + "due": "2025-10-30", + "open_units": 6, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-10-31", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-10-30", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-04", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CAP": { + "due": "2025-10-27", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2025-11-04", + "open_units": 3, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-10-30", + "open_units": 1, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-10-31", + "open_units": 10, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-10-27", + "open_units": 8, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-CAP": { + "due": "2025-11-04", + "open_units": 11, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-10-30", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-11-01", + "open_units": 5, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-11-01", + "open_units": 8, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-11-04", + "open_units": 8, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 29, + "reserved": 2, + "safety": 6, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 42, + "reserved": 4, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-MDL": { + "on_hand": 46, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-PLT": { + "on_hand": 36, + "reserved": 1, + "safety": 7, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 5, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 7, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 39, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CLP" + }, + "Denver-MDL": { + "on_hand": 44, + "reserved": 1, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 14, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 36, + "reserved": 0, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 33, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 26, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 30, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 12, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + } + }, + "orders": { + "SO-23869-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-26385-11": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-29", + "sku": "PLT", + "state": "shipped", + "units": 11 + }, + "SO-30795-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-10-20", + "sku": "PLT", + "state": "open", + "units": 30 + }, + "SO-34816-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-28", + "sku": "RNG", + "state": "shipped", + "units": 23 + }, + "SO-42398-4": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-21", + "sku": "CAP", + "state": "open", + "units": 28 + }, + "SO-47008-10": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-27", + "sku": "MDL", + "state": "open", + "units": 6 + }, + "SO-47058-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-22", + "sku": "CLP", + "state": "open", + "units": 9 + }, + "SO-48050-15": { + "origin": "Denver", + "priority": 1, + "promise": "2025-10-23", + "sku": "MDL", + "state": "open", + "units": 33 + }, + "SO-49084-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-20", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-51766-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-10-25", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-52065-5": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-17", + "sku": "MDL", + "state": "open", + "units": 8 + }, + "SO-53477-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-24", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-60064-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-10-20", + "sku": "CAP", + "state": "shipped", + "units": 13 + }, + "SO-74274-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "CLP", + "state": "open", + "units": 10 + }, + "SO-80189-14": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-15", + "sku": "CAP", + "state": "open", + "units": 11 + }, + "SO-89617-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-10-23", + "sku": "PLT", + "state": "open", + "units": 16 + }, + "SO-99173-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-10-17", + "sku": "RNG", + "state": "open", + "units": 15 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-033/tests/world_check.py b/tasks/autom-fulfillment-release-033/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-033/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-033/validation/openenv.json b/tasks/autom-fulfillment-release-033/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-033/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-034/environment/inputs/apps.py b/tasks/autom-fulfillment-release-034/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-034/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-034/environment/inputs/world.json b/tasks/autom-fulfillment-release-034/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..576bf62a23deb9203f02ee90ab4317868a3a96d9 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/environment/inputs/world.json @@ -0,0 +1,324 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CLP": { + "due": "2025-11-27", + "open_units": 11, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-11-18", + "open_units": 3, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-11-21", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-19", + "open_units": 2, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-11-27", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2025-11-22", + "open_units": 3, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-11-17", + "open_units": 2, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-11-21", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-11-21", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2025-11-20", + "open_units": 10, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-11-20", + "open_units": 3, + "site": "Tampa", + "sku": "MDL", + "status": "proposed" + }, + "PO-Tampa-RNG": { + "due": "2025-11-21", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CLP": { + "on_hand": 34, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 22, + "reserved": 2, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 36, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 20, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CLP": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 42, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 24, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 22, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CLP": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 36, + "reserved": 4, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 20, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 14, + "reserved": 4, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-13045-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "open", + "units": 4 + }, + "SO-22337-8": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-21", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-32682-12": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-17", + "sku": "MDL", + "state": "open", + "units": 9 + }, + "SO-44001-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-15", + "sku": "CLP", + "state": "open", + "units": 27 + }, + "SO-45669-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-14", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-45727-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-12", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-50963-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-13", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-53675-1": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-16", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-54039-15": { + "origin": "Albany", + "priority": 1, + "promise": "2025-11-13", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-63480-11": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-13", + "sku": "CPL", + "state": "open", + "units": 11 + }, + "SO-83142-14": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-10", + "sku": "CLP", + "state": "open", + "units": 12 + }, + "SO-86925-3": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-09", + "sku": "CPL", + "state": "open", + "units": 10 + }, + "SO-94656-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "open", + "units": 5 + }, + "SO-96280-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-18", + "sku": "CLP", + "state": "shipped", + "units": 17 + }, + "SO-97728-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-16", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-97917-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-14", + "sku": "MDL", + "state": "open", + "units": 27 + }, + "SO-99439-7": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-07", + "sku": "CPL", + "state": "open", + "units": 30 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-034/instruction.md b/tasks/autom-fulfillment-release-034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4f1c30cbc81c038f2d6b14ca8b1eaad3e2869fd9 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Denver as of 2025-11-16. 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 Denver. If the origin cannot cover the complete order, try Tampa 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-` 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-11-23. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-` 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. diff --git a/tasks/autom-fulfillment-release-034/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-034/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..c692dde69e22d3bb0b6e3b8f2fead3d7d94696a1 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/solution/files/actions.jsonl @@ -0,0 +1,26 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-50963-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-53675-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-45727-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-86925-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-97728-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-13045-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-44001-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-99439-7", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-94656-9", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-63480-11", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-83142-14", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-97917-16", "op": "update"} +{"app": "inventory", "fields": {"reserved": 7}, "id": "Denver-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 11}, "id": "Denver-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 35}, "id": "Denver-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 25}, "id": "Tampa-CPL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-99439-7", "site": "Denver", "sku": "CPL", "units": 30}, "id": "pick-SO-99439-7", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-86925-3", "site": "Tampa", "sku": "CPL", "units": 10}, "id": "pick-SO-86925-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-13045-5", "site": "Denver", "sku": "RNG", "units": 4}, "id": "pick-SO-13045-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-94656-9", "site": "Denver", "sku": "RNG", "units": 5}, "id": "pick-SO-94656-9", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-50963-0", "site": "Denver", "sku": "MDL", "units": 1}, "id": "pick-SO-50963-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-63480-11", "site": "Tampa", "sku": "CPL", "units": 11}, "id": "pick-SO-63480-11", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-97728-4", "site": "Denver", "sku": "MDL", "units": 4}, "id": "pick-SO-97728-4", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "CLP", "status": "draft", "units": 62}, "id": "req-Denver-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "MDL", "status": "draft", "units": 27}, "id": "req-Denver-MDL", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "RNG", "status": "draft", "units": 63}, "id": "req-Denver-RNG", "op": "create"} diff --git a/tasks/autom-fulfillment-release-034/solution/solve.sh b/tasks/autom-fulfillment-release-034/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-034/task.toml b/tasks/autom-fulfillment-release-034/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..06846a25bd318cd88ab82a60634ea9e30ff2be41 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-034" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 34 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-034" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-034/tests/expected.json b/tasks/autom-fulfillment-release-034/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-034/tests/grade.py b/tasks/autom-fulfillment-release-034/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-034/tests/replay.py b/tasks/autom-fulfillment-release-034/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-034/tests/target.json b/tasks/autom-fulfillment-release-034/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..438d37f74413785342312a8f418841add691120d --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/target.json @@ -0,0 +1,384 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-13045-5": { + "order": "SO-13045-5", + "site": "Denver", + "sku": "RNG", + "units": 4 + }, + "pick-SO-50963-0": { + "order": "SO-50963-0", + "site": "Denver", + "sku": "MDL", + "units": 1 + }, + "pick-SO-63480-11": { + "order": "SO-63480-11", + "site": "Tampa", + "sku": "CPL", + "units": 11 + }, + "pick-SO-86925-3": { + "order": "SO-86925-3", + "site": "Tampa", + "sku": "CPL", + "units": 10 + }, + "pick-SO-94656-9": { + "order": "SO-94656-9", + "site": "Denver", + "sku": "RNG", + "units": 5 + }, + "pick-SO-97728-4": { + "order": "SO-97728-4", + "site": "Denver", + "sku": "MDL", + "units": 4 + }, + "pick-SO-99439-7": { + "order": "SO-99439-7", + "site": "Denver", + "sku": "CPL", + "units": 30 + } + }, + "inbound": { + "PO-Albany-CLP": { + "due": "2025-11-27", + "open_units": 11, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-11-18", + "open_units": 3, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-11-21", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-19", + "open_units": 2, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-11-27", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2025-11-22", + "open_units": 3, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-11-17", + "open_units": 2, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-11-21", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-11-21", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2025-11-20", + "open_units": 10, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-11-20", + "open_units": 3, + "site": "Tampa", + "sku": "MDL", + "status": "proposed" + }, + "PO-Tampa-RNG": { + "due": "2025-11-21", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CLP": { + "on_hand": 34, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 22, + "reserved": 2, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 36, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 20, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CLP": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 42, + "reserved": 35, + "safety": 4, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 24, + "reserved": 7, + "safety": 4, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 22, + "reserved": 11, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CLP": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 36, + "reserved": 25, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 20, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 14, + "reserved": 4, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-13045-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "allocated", + "units": 4 + }, + "SO-22337-8": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-21", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-32682-12": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-17", + "sku": "MDL", + "state": "open", + "units": 9 + }, + "SO-44001-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-15", + "sku": "CLP", + "state": "backorder", + "units": 27 + }, + "SO-45669-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-14", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-45727-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-12", + "sku": "CLP", + "state": "backorder", + "units": 23 + }, + "SO-50963-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-13", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-53675-1": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-16", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-54039-15": { + "origin": "Albany", + "priority": 1, + "promise": "2025-11-13", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-63480-11": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-13", + "sku": "CPL", + "state": "allocated", + "units": 11 + }, + "SO-83142-14": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-10", + "sku": "CLP", + "state": "backorder", + "units": 12 + }, + "SO-86925-3": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-09", + "sku": "CPL", + "state": "allocated", + "units": 10 + }, + "SO-94656-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "allocated", + "units": 5 + }, + "SO-96280-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-18", + "sku": "CLP", + "state": "shipped", + "units": 17 + }, + "SO-97728-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-16", + "sku": "MDL", + "state": "allocated", + "units": 4 + }, + "SO-97917-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-14", + "sku": "MDL", + "state": "backorder", + "units": 27 + }, + "SO-99439-7": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-07", + "sku": "CPL", + "state": "allocated", + "units": 30 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Denver-CLP": { + "site": "Denver", + "sku": "CLP", + "status": "draft", + "units": 62 + }, + "req-Denver-MDL": { + "site": "Denver", + "sku": "MDL", + "status": "draft", + "units": 27 + }, + "req-Denver-RNG": { + "site": "Denver", + "sku": "RNG", + "status": "draft", + "units": 63 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-034/tests/test.sh b/tasks/autom-fulfillment-release-034/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-034/tests/world.json b/tasks/autom-fulfillment-release-034/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..576bf62a23deb9203f02ee90ab4317868a3a96d9 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/world.json @@ -0,0 +1,324 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CLP": { + "due": "2025-11-27", + "open_units": 11, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2025-11-18", + "open_units": 3, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2025-11-21", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-11-19", + "open_units": 2, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Denver-CLP": { + "due": "2025-11-27", + "open_units": 12, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2025-11-22", + "open_units": 3, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-11-17", + "open_units": 2, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-11-21", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2025-11-21", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2025-11-20", + "open_units": 10, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-11-20", + "open_units": 3, + "site": "Tampa", + "sku": "MDL", + "status": "proposed" + }, + "PO-Tampa-RNG": { + "due": "2025-11-21", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CLP": { + "on_hand": 34, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 22, + "reserved": 2, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 36, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 20, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "RNG" + }, + "Denver-CLP": { + "on_hand": 14, + "reserved": 4, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 42, + "reserved": 5, + "safety": 4, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 24, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 22, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CLP": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 36, + "reserved": 4, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 20, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 14, + "reserved": 4, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-13045-5": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "open", + "units": 4 + }, + "SO-22337-8": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-21", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-32682-12": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-17", + "sku": "MDL", + "state": "open", + "units": 9 + }, + "SO-44001-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-15", + "sku": "CLP", + "state": "open", + "units": 27 + }, + "SO-45669-13": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-14", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-45727-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-12", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-50963-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-13", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-53675-1": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-16", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-54039-15": { + "origin": "Albany", + "priority": 1, + "promise": "2025-11-13", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-63480-11": { + "origin": "Denver", + "priority": 3, + "promise": "2025-11-13", + "sku": "CPL", + "state": "open", + "units": 11 + }, + "SO-83142-14": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-10", + "sku": "CLP", + "state": "open", + "units": 12 + }, + "SO-86925-3": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-09", + "sku": "CPL", + "state": "open", + "units": 10 + }, + "SO-94656-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-12", + "sku": "RNG", + "state": "open", + "units": 5 + }, + "SO-96280-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-11-18", + "sku": "CLP", + "state": "shipped", + "units": 17 + }, + "SO-97728-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-16", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-97917-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-11-14", + "sku": "MDL", + "state": "open", + "units": 27 + }, + "SO-99439-7": { + "origin": "Denver", + "priority": 1, + "promise": "2025-11-07", + "sku": "CPL", + "state": "open", + "units": 30 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-034/tests/world_check.py b/tasks/autom-fulfillment-release-034/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-034/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-034/validation/openenv.json b/tasks/autom-fulfillment-release-034/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-034/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-035/environment/inputs/apps.py b/tasks/autom-fulfillment-release-035/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-035/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-035/environment/inputs/world.json b/tasks/autom-fulfillment-release-035/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..d5ea3101e2a8f099743f986600299c6e9b282d71 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/environment/inputs/world.json @@ -0,0 +1,266 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-12-11", + "open_units": 5, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-12-14", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-12-13", + "open_units": 12, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-12-15", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-12-16", + "open_units": 2, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-12-20", + "open_units": 1, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-12-13", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-12-14", + "open_units": 6, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-12-12", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 22, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 30, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 48, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 35, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CLP": { + "on_hand": 47, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 39, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Waco-BRK": { + "on_hand": 21, + "reserved": 5, + "safety": 4, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CLP": { + "on_hand": 46, + "reserved": 5, + "safety": 4, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 20, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "CPL" + } + }, + "orders": { + "SO-14121-1": { + "origin": "Waco", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "open", + "units": 65 + }, + "SO-34677-4": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CPL", + "state": "open", + "units": 5 + }, + "SO-35188-11": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-12-08", + "sku": "CLP", + "state": "open", + "units": 25 + }, + "SO-43921-8": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "open", + "units": 17 + }, + "SO-47643-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-11-29", + "sku": "CLP", + "state": "open", + "units": 12 + }, + "SO-48336-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-05", + "sku": "CPL", + "state": "shipped", + "units": 17 + }, + "SO-52617-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-13", + "sku": "BRK", + "state": "open", + "units": 15 + }, + "SO-56402-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-04", + "sku": "BRK", + "state": "open", + "units": 26 + }, + "SO-58016-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-67277-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-06", + "sku": "BRK", + "state": "open", + "units": 15 + }, + "SO-68856-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-74877-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "BRK", + "state": "shipped", + "units": 11 + }, + "SO-86635-2": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "open", + "units": 14 + }, + "SO-95174-5": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-04", + "sku": "CLP", + "state": "open", + "units": 26 + }, + "SO-98317-10": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "CPL", + "state": "open", + "units": 3 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-035/instruction.md b/tasks/autom-fulfillment-release-035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0b5adab85ed08b788f7845d007983f25eb11bc6d --- /dev/null +++ b/tasks/autom-fulfillment-release-035/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Waco as of 2025-12-09. 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 Waco. If the origin cannot cover the complete order, try Albany 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-` 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 Waco, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-12-16. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Waco-` 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. diff --git a/tasks/autom-fulfillment-release-035/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-035/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..a1440190d7d1aca70de81934b044d212f473797e --- /dev/null +++ b/tasks/autom-fulfillment-release-035/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-68856-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-14121-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-86635-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-56402-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-34677-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-95174-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-67277-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43921-8", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-98317-10", "op": "update"} +{"app": "inventory", "fields": {"reserved": 6}, "id": "Waco-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 12}, "id": "Waco-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 36}, "id": "Waco-CLP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-68856-0", "site": "Waco", "sku": "BRK", "units": 1}, "id": "pick-SO-68856-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-98317-10", "site": "Waco", "sku": "CPL", "units": 3}, "id": "pick-SO-98317-10", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-34677-4", "site": "Waco", "sku": "CPL", "units": 5}, "id": "pick-SO-34677-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43921-8", "site": "Waco", "sku": "CLP", "units": 17}, "id": "pick-SO-43921-8", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-86635-2", "site": "Waco", "sku": "CLP", "units": 14}, "id": "pick-SO-86635-2", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "BRK", "status": "draft", "units": 41}, "id": "req-Waco-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "CLP", "status": "draft", "units": 20}, "id": "req-Waco-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "CPL", "status": "draft", "units": 65}, "id": "req-Waco-CPL", "op": "create"} diff --git a/tasks/autom-fulfillment-release-035/solution/solve.sh b/tasks/autom-fulfillment-release-035/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-035/task.toml b/tasks/autom-fulfillment-release-035/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ad3b387fccf3e99a78c44dafbe6080c5ee8013f1 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-035" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 35 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-035" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-035/tests/expected.json b/tasks/autom-fulfillment-release-035/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-035/tests/grade.py b/tasks/autom-fulfillment-release-035/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-035/tests/replay.py b/tasks/autom-fulfillment-release-035/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-035/tests/target.json b/tasks/autom-fulfillment-release-035/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..8566ac4d02cec28b6a5358ce5ddbda90d0dc1537 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/target.json @@ -0,0 +1,314 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-34677-4": { + "order": "SO-34677-4", + "site": "Waco", + "sku": "CPL", + "units": 5 + }, + "pick-SO-43921-8": { + "order": "SO-43921-8", + "site": "Waco", + "sku": "CLP", + "units": 17 + }, + "pick-SO-68856-0": { + "order": "SO-68856-0", + "site": "Waco", + "sku": "BRK", + "units": 1 + }, + "pick-SO-86635-2": { + "order": "SO-86635-2", + "site": "Waco", + "sku": "CLP", + "units": 14 + }, + "pick-SO-98317-10": { + "order": "SO-98317-10", + "site": "Waco", + "sku": "CPL", + "units": 3 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-12-11", + "open_units": 5, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-12-14", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-12-13", + "open_units": 12, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-12-15", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-12-16", + "open_units": 2, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-12-20", + "open_units": 1, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-12-13", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-12-14", + "open_units": 6, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-12-12", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 22, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 30, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 48, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 35, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CLP": { + "on_hand": 47, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 39, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Waco-BRK": { + "on_hand": 21, + "reserved": 6, + "safety": 4, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CLP": { + "on_hand": 46, + "reserved": 36, + "safety": 4, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 20, + "reserved": 12, + "safety": 8, + "site": "Waco", + "sku": "CPL" + } + }, + "orders": { + "SO-14121-1": { + "origin": "Waco", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "backorder", + "units": 65 + }, + "SO-34677-4": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CPL", + "state": "allocated", + "units": 5 + }, + "SO-35188-11": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-12-08", + "sku": "CLP", + "state": "open", + "units": 25 + }, + "SO-43921-8": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "allocated", + "units": 17 + }, + "SO-47643-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-11-29", + "sku": "CLP", + "state": "open", + "units": 12 + }, + "SO-48336-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-05", + "sku": "CPL", + "state": "shipped", + "units": 17 + }, + "SO-52617-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-13", + "sku": "BRK", + "state": "open", + "units": 15 + }, + "SO-56402-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-04", + "sku": "BRK", + "state": "backorder", + "units": 26 + }, + "SO-58016-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-67277-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-06", + "sku": "BRK", + "state": "backorder", + "units": 15 + }, + "SO-68856-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "BRK", + "state": "allocated", + "units": 1 + }, + "SO-74877-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "BRK", + "state": "shipped", + "units": 11 + }, + "SO-86635-2": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "allocated", + "units": 14 + }, + "SO-95174-5": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-04", + "sku": "CLP", + "state": "backorder", + "units": 26 + }, + "SO-98317-10": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "CPL", + "state": "allocated", + "units": 3 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Waco-BRK": { + "site": "Waco", + "sku": "BRK", + "status": "draft", + "units": 41 + }, + "req-Waco-CLP": { + "site": "Waco", + "sku": "CLP", + "status": "draft", + "units": 20 + }, + "req-Waco-CPL": { + "site": "Waco", + "sku": "CPL", + "status": "draft", + "units": 65 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-035/tests/test.sh b/tasks/autom-fulfillment-release-035/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-035/tests/world.json b/tasks/autom-fulfillment-release-035/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..d5ea3101e2a8f099743f986600299c6e9b282d71 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/world.json @@ -0,0 +1,266 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-12-11", + "open_units": 5, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-12-14", + "open_units": 2, + "site": "Albany", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Albany-CPL": { + "due": "2025-12-13", + "open_units": 12, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2025-12-15", + "open_units": 12, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-12-16", + "open_units": 2, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-CPL": { + "due": "2025-12-20", + "open_units": 1, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-BRK": { + "due": "2025-12-13", + "open_units": 3, + "site": "Waco", + "sku": "BRK", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-12-14", + "open_units": 6, + "site": "Waco", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Waco-CPL": { + "due": "2025-12-12", + "open_units": 3, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 22, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 30, + "reserved": 3, + "safety": 6, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 48, + "reserved": 5, + "safety": 6, + "site": "Albany", + "sku": "CPL" + }, + "Tampa-BRK": { + "on_hand": 35, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CLP": { + "on_hand": 47, + "reserved": 1, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-CPL": { + "on_hand": 39, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "CPL" + }, + "Waco-BRK": { + "on_hand": 21, + "reserved": 5, + "safety": 4, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CLP": { + "on_hand": 46, + "reserved": 5, + "safety": 4, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 20, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "CPL" + } + }, + "orders": { + "SO-14121-1": { + "origin": "Waco", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "open", + "units": 65 + }, + "SO-34677-4": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CPL", + "state": "open", + "units": 5 + }, + "SO-35188-11": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-12-08", + "sku": "CLP", + "state": "open", + "units": 25 + }, + "SO-43921-8": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "open", + "units": 17 + }, + "SO-47643-14": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-11-29", + "sku": "CLP", + "state": "open", + "units": 12 + }, + "SO-48336-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-05", + "sku": "CPL", + "state": "shipped", + "units": 17 + }, + "SO-52617-9": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-13", + "sku": "BRK", + "state": "open", + "units": 15 + }, + "SO-56402-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-04", + "sku": "BRK", + "state": "open", + "units": 26 + }, + "SO-58016-7": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-12-08", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-67277-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-06", + "sku": "BRK", + "state": "open", + "units": 15 + }, + "SO-68856-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-74877-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "BRK", + "state": "shipped", + "units": 11 + }, + "SO-86635-2": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-02", + "sku": "CLP", + "state": "open", + "units": 14 + }, + "SO-95174-5": { + "origin": "Waco", + "priority": 2, + "promise": "2025-12-04", + "sku": "CLP", + "state": "open", + "units": 26 + }, + "SO-98317-10": { + "origin": "Waco", + "priority": 1, + "promise": "2025-12-06", + "sku": "CPL", + "state": "open", + "units": 3 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-035/tests/world_check.py b/tasks/autom-fulfillment-release-035/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-035/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-035/validation/openenv.json b/tasks/autom-fulfillment-release-035/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-035/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-036/environment/inputs/apps.py b/tasks/autom-fulfillment-release-036/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-036/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-036/environment/inputs/world.json b/tasks/autom-fulfillment-release-036/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..197a42e0faf32ea2167fefac4487fa95f35f2e62 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/environment/inputs/world.json @@ -0,0 +1,308 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-01-08", + "open_units": 11, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-01-09", + "open_units": 12, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-01-04", + "open_units": 9, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-01-03", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2026-01-08", + "open_units": 12, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-01-11", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-01-07", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-MDL": { + "due": "2026-01-05", + "open_units": 7, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-01-02", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-01-02", + "open_units": 3, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-01-09", + "open_units": 6, + "site": "Fresno", + "sku": "CPL", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2026-01-03", + "open_units": 3, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 4, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 18, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 35, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "MDL" + }, + "Denver-BRK": { + "on_hand": 38, + "reserved": 1, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CLP": { + "on_hand": 46, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 32, + "reserved": 0, + "safety": 8, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 20, + "reserved": 3, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Fresno-BRK": { + "on_hand": 30, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CLP": { + "on_hand": 31, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 36, + "reserved": 5, + "safety": 8, + "site": "Fresno", + "sku": "MDL" + } + }, + "orders": { + "SO-11234-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "BRK", + "state": "open", + "units": 14 + }, + "SO-15293-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-27", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-17088-6": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-30567-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-04", + "sku": "MDL", + "state": "open", + "units": 11 + }, + "SO-32050-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-01-06", + "sku": "MDL", + "state": "open", + "units": 22 + }, + "SO-34019-7": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-07", + "sku": "BRK", + "state": "open", + "units": 30 + }, + "SO-38098-13": { + "origin": "Denver", + "priority": 1, + "promise": "2026-01-01", + "sku": "CPL", + "state": "open", + "units": 29 + }, + "SO-42953-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-27", + "sku": "CLP", + "state": "open", + "units": 13 + }, + "SO-51612-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-12-28", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-68535-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-12-24", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-75781-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-31", + "sku": "BRK", + "state": "open", + "units": 16 + }, + "SO-78741-4": { + "origin": "Denver", + "priority": 3, + "promise": "2025-12-31", + "sku": "MDL", + "state": "open", + "units": 33 + }, + "SO-83922-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-30", + "sku": "CLP", + "state": "open", + "units": 11 + }, + "SO-84329-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-28", + "sku": "CPL", + "state": "open", + "units": 23 + }, + "SO-95050-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-26", + "sku": "CPL", + "state": "open", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-036/instruction.md b/tasks/autom-fulfillment-release-036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..307345a2b2f20f62180678aa6a47f83afeca1053 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Denver as of 2026-01-01. 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 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-` 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-08. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-` 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. diff --git a/tasks/autom-fulfillment-release-036/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-036/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..493d99f78401b10a5b668baa987e32f3ada0adca --- /dev/null +++ b/tasks/autom-fulfillment-release-036/solution/files/actions.jsonl @@ -0,0 +1,23 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-15293-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-95050-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-42953-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-11234-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-78741-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-84329-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17088-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-83922-10", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-75781-11", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-38098-13", "op": "update"} +{"app": "inventory", "fields": {"reserved": 4}, "id": "Denver-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 23}, "id": "Denver-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 38}, "id": "Denver-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 31}, "id": "Denver-BRK", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-15293-0", "site": "Denver", "sku": "MDL", "units": 1}, "id": "pick-SO-15293-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-42953-2", "site": "Denver", "sku": "CLP", "units": 13}, "id": "pick-SO-42953-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-84329-5", "site": "Denver", "sku": "CPL", "units": 23}, "id": "pick-SO-84329-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-11234-3", "site": "Denver", "sku": "BRK", "units": 14}, "id": "pick-SO-11234-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-17088-6", "site": "Denver", "sku": "CLP", "units": 23}, "id": "pick-SO-17088-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-75781-11", "site": "Denver", "sku": "BRK", "units": 16}, "id": "pick-SO-75781-11", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "CPL", "status": "draft", "units": 88}, "id": "req-Denver-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "CLP", "status": "draft", "units": 11}, "id": "req-Denver-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "MDL", "status": "draft", "units": 26}, "id": "req-Denver-MDL", "op": "create"} diff --git a/tasks/autom-fulfillment-release-036/solution/solve.sh b/tasks/autom-fulfillment-release-036/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-036/task.toml b/tasks/autom-fulfillment-release-036/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..829034d13b552f031e95c0ba5f68d8384e994b02 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-036" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 36 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-036" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-036/tests/expected.json b/tasks/autom-fulfillment-release-036/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-036/tests/grade.py b/tasks/autom-fulfillment-release-036/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-036/tests/replay.py b/tasks/autom-fulfillment-release-036/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-036/tests/target.json b/tasks/autom-fulfillment-release-036/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..3b430aa4221ebdc3323f80e721ce9e1f719274ba --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/target.json @@ -0,0 +1,362 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-11234-3": { + "order": "SO-11234-3", + "site": "Denver", + "sku": "BRK", + "units": 14 + }, + "pick-SO-15293-0": { + "order": "SO-15293-0", + "site": "Denver", + "sku": "MDL", + "units": 1 + }, + "pick-SO-17088-6": { + "order": "SO-17088-6", + "site": "Denver", + "sku": "CLP", + "units": 23 + }, + "pick-SO-42953-2": { + "order": "SO-42953-2", + "site": "Denver", + "sku": "CLP", + "units": 13 + }, + "pick-SO-75781-11": { + "order": "SO-75781-11", + "site": "Denver", + "sku": "BRK", + "units": 16 + }, + "pick-SO-84329-5": { + "order": "SO-84329-5", + "site": "Denver", + "sku": "CPL", + "units": 23 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-01-08", + "open_units": 11, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-01-09", + "open_units": 12, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-01-04", + "open_units": 9, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-01-03", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2026-01-08", + "open_units": 12, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-01-11", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-01-07", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-MDL": { + "due": "2026-01-05", + "open_units": 7, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-01-02", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-01-02", + "open_units": 3, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-01-09", + "open_units": 6, + "site": "Fresno", + "sku": "CPL", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2026-01-03", + "open_units": 3, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 4, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 18, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 35, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "MDL" + }, + "Denver-BRK": { + "on_hand": 38, + "reserved": 31, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CLP": { + "on_hand": 46, + "reserved": 38, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 32, + "reserved": 23, + "safety": 8, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 20, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Fresno-BRK": { + "on_hand": 30, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CLP": { + "on_hand": 31, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 36, + "reserved": 5, + "safety": 8, + "site": "Fresno", + "sku": "MDL" + } + }, + "orders": { + "SO-11234-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "BRK", + "state": "allocated", + "units": 14 + }, + "SO-15293-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-27", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-17088-6": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "CLP", + "state": "allocated", + "units": 23 + }, + "SO-30567-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-04", + "sku": "MDL", + "state": "open", + "units": 11 + }, + "SO-32050-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-01-06", + "sku": "MDL", + "state": "open", + "units": 22 + }, + "SO-34019-7": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-07", + "sku": "BRK", + "state": "open", + "units": 30 + }, + "SO-38098-13": { + "origin": "Denver", + "priority": 1, + "promise": "2026-01-01", + "sku": "CPL", + "state": "backorder", + "units": 29 + }, + "SO-42953-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-27", + "sku": "CLP", + "state": "allocated", + "units": 13 + }, + "SO-51612-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-12-28", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-68535-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-12-24", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-75781-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-31", + "sku": "BRK", + "state": "allocated", + "units": 16 + }, + "SO-78741-4": { + "origin": "Denver", + "priority": 3, + "promise": "2025-12-31", + "sku": "MDL", + "state": "backorder", + "units": 33 + }, + "SO-83922-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-30", + "sku": "CLP", + "state": "backorder", + "units": 11 + }, + "SO-84329-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-28", + "sku": "CPL", + "state": "allocated", + "units": 23 + }, + "SO-95050-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-26", + "sku": "CPL", + "state": "backorder", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Denver-CLP": { + "site": "Denver", + "sku": "CLP", + "status": "draft", + "units": 11 + }, + "req-Denver-CPL": { + "site": "Denver", + "sku": "CPL", + "status": "draft", + "units": 88 + }, + "req-Denver-MDL": { + "site": "Denver", + "sku": "MDL", + "status": "draft", + "units": 26 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-036/tests/test.sh b/tasks/autom-fulfillment-release-036/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-036/tests/world.json b/tasks/autom-fulfillment-release-036/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..197a42e0faf32ea2167fefac4487fa95f35f2e62 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/world.json @@ -0,0 +1,308 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2026-01-08", + "open_units": 11, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2026-01-09", + "open_units": 12, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-CPL": { + "due": "2026-01-04", + "open_units": 9, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-01-03", + "open_units": 6, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Denver-BRK": { + "due": "2026-01-08", + "open_units": 12, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-01-11", + "open_units": 6, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Denver-CPL": { + "due": "2026-01-07", + "open_units": 6, + "site": "Denver", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Denver-MDL": { + "due": "2026-01-05", + "open_units": 7, + "site": "Denver", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-01-02", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-01-02", + "open_units": 3, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-01-09", + "open_units": 6, + "site": "Fresno", + "sku": "CPL", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2026-01-03", + "open_units": 3, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 12, + "reserved": 4, + "safety": 4, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CLP": { + "on_hand": 18, + "reserved": 3, + "safety": 4, + "site": "Albany", + "sku": "CLP" + }, + "Albany-CPL": { + "on_hand": 35, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 8, + "site": "Albany", + "sku": "MDL" + }, + "Denver-BRK": { + "on_hand": 38, + "reserved": 1, + "safety": 6, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CLP": { + "on_hand": 46, + "reserved": 2, + "safety": 7, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 32, + "reserved": 0, + "safety": 8, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 20, + "reserved": 3, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Fresno-BRK": { + "on_hand": 30, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CLP": { + "on_hand": 31, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 36, + "reserved": 5, + "safety": 8, + "site": "Fresno", + "sku": "MDL" + } + }, + "orders": { + "SO-11234-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "BRK", + "state": "open", + "units": 14 + }, + "SO-15293-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-27", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-17088-6": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-29", + "sku": "CLP", + "state": "open", + "units": 23 + }, + "SO-30567-12": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-04", + "sku": "MDL", + "state": "open", + "units": 11 + }, + "SO-32050-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-01-06", + "sku": "MDL", + "state": "open", + "units": 22 + }, + "SO-34019-7": { + "origin": "Denver", + "priority": 3, + "promise": "2026-01-07", + "sku": "BRK", + "state": "open", + "units": 30 + }, + "SO-38098-13": { + "origin": "Denver", + "priority": 1, + "promise": "2026-01-01", + "sku": "CPL", + "state": "open", + "units": 29 + }, + "SO-42953-2": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-27", + "sku": "CLP", + "state": "open", + "units": 13 + }, + "SO-51612-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-12-28", + "sku": "CLP", + "state": "open", + "units": 4 + }, + "SO-68535-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-12-24", + "sku": "CPL", + "state": "shipped", + "units": 12 + }, + "SO-75781-11": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-31", + "sku": "BRK", + "state": "open", + "units": 16 + }, + "SO-78741-4": { + "origin": "Denver", + "priority": 3, + "promise": "2025-12-31", + "sku": "MDL", + "state": "open", + "units": 33 + }, + "SO-83922-10": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-30", + "sku": "CLP", + "state": "open", + "units": 11 + }, + "SO-84329-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-12-28", + "sku": "CPL", + "state": "open", + "units": 23 + }, + "SO-95050-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-12-26", + "sku": "CPL", + "state": "open", + "units": 65 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-036/tests/world_check.py b/tasks/autom-fulfillment-release-036/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-036/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-036/validation/openenv.json b/tasks/autom-fulfillment-release-036/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-036/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-039/environment/inputs/apps.py b/tasks/autom-fulfillment-release-039/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-039/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-039/environment/inputs/world.json b/tasks/autom-fulfillment-release-039/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..40dab6392c7a89fa9a10e9e9654eb0d7d65fff02 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/environment/inputs/world.json @@ -0,0 +1,308 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-CLP": { + "due": "2026-03-15", + "open_units": 8, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-20", + "open_units": 11, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2026-03-22", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2026-03-20", + "open_units": 5, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2026-03-19", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-03-17", + "open_units": 4, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-03-13", + "open_units": 4, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-03-19", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2026-03-12", + "open_units": 12, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-20", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2026-03-20", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-18", + "open_units": 7, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CLP": { + "on_hand": 48, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 21, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 39, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CLP": { + "on_hand": 29, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 22, + "reserved": 3, + "safety": 4, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 18, + "reserved": 1, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 30, + "reserved": 2, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CLP": { + "on_hand": 38, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 32, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-MDL": { + "on_hand": 15, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17953-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-08", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-23093-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "open", + "units": 29 + }, + "SO-31414-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-04", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-35666-7": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CPL", + "state": "open", + "units": 15 + }, + "SO-46816-10": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "open", + "units": 18 + }, + "SO-48695-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-06", + "sku": "RNG", + "state": "open", + "units": 8 + }, + "SO-50141-13": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-02", + "sku": "MDL", + "state": "open", + "units": 32 + }, + "SO-54556-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-08", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-57531-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-06", + "sku": "MDL", + "state": "open", + "units": 9 + }, + "SO-63193-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-10", + "sku": "MDL", + "state": "open", + "units": 65 + }, + "SO-65922-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-05", + "sku": "CLP", + "state": "open", + "units": 7 + }, + "SO-70908-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-01", + "sku": "CPL", + "state": "open", + "units": 13 + }, + "SO-76275-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-09", + "sku": "RNG", + "state": "open", + "units": 1 + }, + "SO-82420-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-07", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-98582-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-11", + "sku": "CPL", + "state": "open", + "units": 8 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-039/instruction.md b/tasks/autom-fulfillment-release-039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a9eccc3091ea588e40f63ce2d4e62ce159db1118 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Fresno as of 2026-03-11. 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 Fresno. 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-` 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 Fresno, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-03-18. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Fresno-` 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. diff --git a/tasks/autom-fulfillment-release-039/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-039/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..719eb42fe773669d02e9794dbb1a1346b7bca06b --- /dev/null +++ b/tasks/autom-fulfillment-release-039/solution/files/actions.jsonl @@ -0,0 +1,27 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-76275-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-63193-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-65922-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-98582-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-31414-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17953-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-82420-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-23093-8", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-57531-9", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-70908-11", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-48695-12", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-50141-13", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-54556-14", "op": "update"} +{"app": "inventory", "fields": {"reserved": 18}, "id": "Fresno-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 5}, "id": "Fresno-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 11}, "id": "Fresno-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 16}, "id": "Fresno-CPL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-31414-4", "site": "Fresno", "sku": "RNG", "units": 7}, "id": "pick-SO-31414-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-17953-5", "site": "Fresno", "sku": "MDL", "units": 4}, "id": "pick-SO-17953-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-76275-0", "site": "Fresno", "sku": "RNG", "units": 1}, "id": "pick-SO-76275-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-70908-11", "site": "Fresno", "sku": "CPL", "units": 13}, "id": "pick-SO-70908-11", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-65922-2", "site": "Fresno", "sku": "CLP", "units": 7}, "id": "pick-SO-65922-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-48695-12", "site": "Fresno", "sku": "RNG", "units": 8}, "id": "pick-SO-48695-12", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "MDL", "status": "draft", "units": 102}, "id": "req-Fresno-MDL", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "RNG", "status": "draft", "units": 29}, "id": "req-Fresno-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CLP", "status": "draft", "units": 40}, "id": "req-Fresno-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CPL", "status": "draft", "units": 4}, "id": "req-Fresno-CPL", "op": "create"} diff --git a/tasks/autom-fulfillment-release-039/solution/solve.sh b/tasks/autom-fulfillment-release-039/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-039/task.toml b/tasks/autom-fulfillment-release-039/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..faf1a230aadb0dd27d47df7081fcdf6d00619ae6 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-039" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 39 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-039" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-039/tests/expected.json b/tasks/autom-fulfillment-release-039/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-039/tests/grade.py b/tasks/autom-fulfillment-release-039/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-039/tests/replay.py b/tasks/autom-fulfillment-release-039/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-039/tests/target.json b/tasks/autom-fulfillment-release-039/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..2a598cb7b596d321e4c7b01679dd818a6ffc40c8 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/target.json @@ -0,0 +1,368 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-17953-5": { + "order": "SO-17953-5", + "site": "Fresno", + "sku": "MDL", + "units": 4 + }, + "pick-SO-31414-4": { + "order": "SO-31414-4", + "site": "Fresno", + "sku": "RNG", + "units": 7 + }, + "pick-SO-48695-12": { + "order": "SO-48695-12", + "site": "Fresno", + "sku": "RNG", + "units": 8 + }, + "pick-SO-65922-2": { + "order": "SO-65922-2", + "site": "Fresno", + "sku": "CLP", + "units": 7 + }, + "pick-SO-70908-11": { + "order": "SO-70908-11", + "site": "Fresno", + "sku": "CPL", + "units": 13 + }, + "pick-SO-76275-0": { + "order": "SO-76275-0", + "site": "Fresno", + "sku": "RNG", + "units": 1 + } + }, + "inbound": { + "PO-Denver-CLP": { + "due": "2026-03-15", + "open_units": 8, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-20", + "open_units": 11, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2026-03-22", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2026-03-20", + "open_units": 5, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2026-03-19", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-03-17", + "open_units": 4, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-03-13", + "open_units": 4, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-03-19", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2026-03-12", + "open_units": 12, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-20", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2026-03-20", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-18", + "open_units": 7, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CLP": { + "on_hand": 48, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 21, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 39, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CLP": { + "on_hand": 29, + "reserved": 11, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 22, + "reserved": 16, + "safety": 4, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 18, + "reserved": 5, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 30, + "reserved": 18, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CLP": { + "on_hand": 38, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 32, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-MDL": { + "on_hand": 15, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17953-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-08", + "sku": "MDL", + "state": "allocated", + "units": 4 + }, + "SO-23093-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "backorder", + "units": 29 + }, + "SO-31414-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-04", + "sku": "RNG", + "state": "allocated", + "units": 7 + }, + "SO-35666-7": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CPL", + "state": "open", + "units": 15 + }, + "SO-46816-10": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "open", + "units": 18 + }, + "SO-48695-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-06", + "sku": "RNG", + "state": "allocated", + "units": 8 + }, + "SO-50141-13": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-02", + "sku": "MDL", + "state": "backorder", + "units": 32 + }, + "SO-54556-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-08", + "sku": "CLP", + "state": "backorder", + "units": 24 + }, + "SO-57531-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-06", + "sku": "MDL", + "state": "backorder", + "units": 9 + }, + "SO-63193-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-10", + "sku": "MDL", + "state": "backorder", + "units": 65 + }, + "SO-65922-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-05", + "sku": "CLP", + "state": "allocated", + "units": 7 + }, + "SO-70908-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-01", + "sku": "CPL", + "state": "allocated", + "units": 13 + }, + "SO-76275-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-09", + "sku": "RNG", + "state": "allocated", + "units": 1 + }, + "SO-82420-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-07", + "sku": "CLP", + "state": "backorder", + "units": 16 + }, + "SO-98582-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-11", + "sku": "CPL", + "state": "backorder", + "units": 8 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Fresno-CLP": { + "site": "Fresno", + "sku": "CLP", + "status": "draft", + "units": 40 + }, + "req-Fresno-CPL": { + "site": "Fresno", + "sku": "CPL", + "status": "draft", + "units": 4 + }, + "req-Fresno-MDL": { + "site": "Fresno", + "sku": "MDL", + "status": "draft", + "units": 102 + }, + "req-Fresno-RNG": { + "site": "Fresno", + "sku": "RNG", + "status": "draft", + "units": 29 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-039/tests/test.sh b/tasks/autom-fulfillment-release-039/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-039/tests/world.json b/tasks/autom-fulfillment-release-039/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..40dab6392c7a89fa9a10e9e9654eb0d7d65fff02 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/world.json @@ -0,0 +1,308 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-CLP": { + "due": "2026-03-15", + "open_units": 8, + "site": "Denver", + "sku": "CLP", + "status": "proposed" + }, + "PO-Denver-CPL": { + "due": "2026-03-20", + "open_units": 11, + "site": "Denver", + "sku": "CPL", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2026-03-22", + "open_units": 11, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2026-03-20", + "open_units": 5, + "site": "Denver", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2026-03-19", + "open_units": 10, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-CPL": { + "due": "2026-03-17", + "open_units": 4, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-03-13", + "open_units": 4, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-03-19", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CLP": { + "due": "2026-03-12", + "open_units": 12, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-CPL": { + "due": "2026-03-20", + "open_units": 12, + "site": "Waco", + "sku": "CPL", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2026-03-20", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Waco-RNG": { + "due": "2026-03-18", + "open_units": 7, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CLP": { + "on_hand": 48, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Denver-CPL": { + "on_hand": 45, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "CPL" + }, + "Denver-MDL": { + "on_hand": 21, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 39, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-CLP": { + "on_hand": 29, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-CPL": { + "on_hand": 22, + "reserved": 3, + "safety": 4, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 18, + "reserved": 1, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 30, + "reserved": 2, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CLP": { + "on_hand": 38, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "CLP" + }, + "Waco-CPL": { + "on_hand": 32, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "CPL" + }, + "Waco-MDL": { + "on_hand": 15, + "reserved": 3, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 42, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-17953-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-08", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-23093-8": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-08", + "sku": "RNG", + "state": "open", + "units": 29 + }, + "SO-31414-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-04", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-35666-7": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CPL", + "state": "open", + "units": 15 + }, + "SO-46816-10": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-15", + "sku": "CLP", + "state": "open", + "units": 18 + }, + "SO-48695-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-06", + "sku": "RNG", + "state": "open", + "units": 8 + }, + "SO-50141-13": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-02", + "sku": "MDL", + "state": "open", + "units": 32 + }, + "SO-54556-14": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-08", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-57531-9": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-06", + "sku": "MDL", + "state": "open", + "units": 9 + }, + "SO-63193-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-10", + "sku": "MDL", + "state": "open", + "units": 65 + }, + "SO-65922-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-05", + "sku": "CLP", + "state": "open", + "units": 7 + }, + "SO-70908-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-01", + "sku": "CPL", + "state": "open", + "units": 13 + }, + "SO-76275-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-09", + "sku": "RNG", + "state": "open", + "units": 1 + }, + "SO-82420-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-07", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-98582-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-11", + "sku": "CPL", + "state": "open", + "units": 8 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-039/tests/world_check.py b/tasks/autom-fulfillment-release-039/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-039/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-039/validation/openenv.json b/tasks/autom-fulfillment-release-039/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-039/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-040/environment/inputs/apps.py b/tasks/autom-fulfillment-release-040/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-040/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-040/environment/inputs/world.json b/tasks/autom-fulfillment-release-040/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..d33edc77d3314ddde2d45d22b29f072bb4039f95 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/environment/inputs/world.json @@ -0,0 +1,250 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2026-04-12", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2026-04-09", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-04-11", + "open_units": 5, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-04-09", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2026-04-14", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-04-13", + "open_units": 6, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-04-07", + "open_units": 2, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2026-04-13", + "open_units": 11, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2026-04-06", + "open_units": 12, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 36, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Fresno-BRK": { + "on_hand": 47, + "reserved": 5, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 19, + "reserved": 1, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 35, + "reserved": 3, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 0, + "safety": 4, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 25, + "reserved": 2, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 25, + "reserved": 5, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + } + }, + "orders": { + "SO-12984-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "BRK", + "state": "open", + "units": 8 + }, + "SO-17125-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-27", + "sku": "CAP", + "state": "open", + "units": 6 + }, + "SO-38808-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "BRK", + "state": "shipped", + "units": 25 + }, + "SO-45712-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-04-03", + "sku": "CAP", + "state": "open", + "units": 18 + }, + "SO-47065-8": { + "origin": "Denver", + "priority": 3, + "promise": "2026-03-26", + "sku": "BRK", + "state": "shipped", + "units": 4 + }, + "SO-49918-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-06", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-62202-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-04-08", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-63901-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-29", + "sku": "BRK", + "state": "open", + "units": 19 + }, + "SO-65804-3": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-03", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-67540-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-29", + "sku": "CLP", + "state": "open", + "units": 27 + }, + "SO-75136-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-28", + "sku": "CLP", + "state": "open", + "units": 65 + }, + "SO-93556-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "CLP", + "state": "open", + "units": 7 + }, + "SO-96783-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "CAP", + "state": "open", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-040/instruction.md b/tasks/autom-fulfillment-release-040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a8603eeb1c666db042990d7dcd0c78d894668552 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Fresno as of 2026-04-03. 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 Fresno. If the origin cannot cover the complete order, try Tampa 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-` 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 Fresno, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-04-10. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Fresno-` 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. diff --git a/tasks/autom-fulfillment-release-040/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-040/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..cd7d533a5bbf1fe7a24895031609b5ef1f76571d --- /dev/null +++ b/tasks/autom-fulfillment-release-040/solution/files/actions.jsonl @@ -0,0 +1,21 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-96783-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-75136-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-12984-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-65804-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-67540-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-63901-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17125-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-93556-7", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-45712-12", "op": "update"} +{"app": "inventory", "fields": {"reserved": 8}, "id": "Fresno-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 10}, "id": "Fresno-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 32}, "id": "Fresno-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 9}, "id": "Tampa-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-12984-2", "site": "Fresno", "sku": "BRK", "units": 8}, "id": "pick-SO-12984-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-96783-0", "site": "Fresno", "sku": "CAP", "units": 1}, "id": "pick-SO-96783-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-17125-6", "site": "Fresno", "sku": "CAP", "units": 6}, "id": "pick-SO-17125-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-93556-7", "site": "Fresno", "sku": "CLP", "units": 7}, "id": "pick-SO-93556-7", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-63901-5", "site": "Fresno", "sku": "BRK", "units": 19}, "id": "pick-SO-63901-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-65804-3", "site": "Tampa", "sku": "CAP", "units": 7}, "id": "pick-SO-65804-3", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CLP", "status": "draft", "units": 92}, "id": "req-Fresno-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CAP", "status": "draft", "units": 18}, "id": "req-Fresno-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-040/solution/solve.sh b/tasks/autom-fulfillment-release-040/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-040/task.toml b/tasks/autom-fulfillment-release-040/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..585edc9c7224985a1450583642c00b2836b374bc --- /dev/null +++ b/tasks/autom-fulfillment-release-040/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-040" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 40 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-040" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-040/tests/expected.json b/tasks/autom-fulfillment-release-040/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-040/tests/grade.py b/tasks/autom-fulfillment-release-040/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-040/tests/replay.py b/tasks/autom-fulfillment-release-040/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-040/tests/target.json b/tasks/autom-fulfillment-release-040/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..8a3ae9b3199f5a22ee43b636c51f723cfcc32ca9 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/target.json @@ -0,0 +1,298 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-12984-2": { + "order": "SO-12984-2", + "site": "Fresno", + "sku": "BRK", + "units": 8 + }, + "pick-SO-17125-6": { + "order": "SO-17125-6", + "site": "Fresno", + "sku": "CAP", + "units": 6 + }, + "pick-SO-63901-5": { + "order": "SO-63901-5", + "site": "Fresno", + "sku": "BRK", + "units": 19 + }, + "pick-SO-65804-3": { + "order": "SO-65804-3", + "site": "Tampa", + "sku": "CAP", + "units": 7 + }, + "pick-SO-93556-7": { + "order": "SO-93556-7", + "site": "Fresno", + "sku": "CLP", + "units": 7 + }, + "pick-SO-96783-0": { + "order": "SO-96783-0", + "site": "Fresno", + "sku": "CAP", + "units": 1 + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2026-04-12", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2026-04-09", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-04-11", + "open_units": 5, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-04-09", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2026-04-14", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-04-13", + "open_units": 6, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-04-07", + "open_units": 2, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2026-04-13", + "open_units": 11, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2026-04-06", + "open_units": 12, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 36, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Fresno-BRK": { + "on_hand": 47, + "reserved": 32, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 19, + "reserved": 8, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 35, + "reserved": 10, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 0, + "safety": 4, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 25, + "reserved": 9, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 25, + "reserved": 5, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + } + }, + "orders": { + "SO-12984-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "BRK", + "state": "allocated", + "units": 8 + }, + "SO-17125-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-27", + "sku": "CAP", + "state": "allocated", + "units": 6 + }, + "SO-38808-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "BRK", + "state": "shipped", + "units": 25 + }, + "SO-45712-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-04-03", + "sku": "CAP", + "state": "backorder", + "units": 18 + }, + "SO-47065-8": { + "origin": "Denver", + "priority": 3, + "promise": "2026-03-26", + "sku": "BRK", + "state": "shipped", + "units": 4 + }, + "SO-49918-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-06", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-62202-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-04-08", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-63901-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-29", + "sku": "BRK", + "state": "allocated", + "units": 19 + }, + "SO-65804-3": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-03", + "sku": "CAP", + "state": "allocated", + "units": 7 + }, + "SO-67540-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-29", + "sku": "CLP", + "state": "backorder", + "units": 27 + }, + "SO-75136-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-28", + "sku": "CLP", + "state": "backorder", + "units": 65 + }, + "SO-93556-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "CLP", + "state": "allocated", + "units": 7 + }, + "SO-96783-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "CAP", + "state": "allocated", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Fresno-CAP": { + "site": "Fresno", + "sku": "CAP", + "status": "draft", + "units": 18 + }, + "req-Fresno-CLP": { + "site": "Fresno", + "sku": "CLP", + "status": "draft", + "units": 92 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-040/tests/test.sh b/tasks/autom-fulfillment-release-040/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-040/tests/world.json b/tasks/autom-fulfillment-release-040/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..d33edc77d3314ddde2d45d22b29f072bb4039f95 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/world.json @@ -0,0 +1,250 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-BRK": { + "due": "2026-04-12", + "open_units": 2, + "site": "Denver", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Denver-CAP": { + "due": "2026-04-09", + "open_units": 6, + "site": "Denver", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Denver-CLP": { + "due": "2026-04-11", + "open_units": 5, + "site": "Denver", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-BRK": { + "due": "2026-04-09", + "open_units": 4, + "site": "Fresno", + "sku": "BRK", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2026-04-14", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Fresno-CLP": { + "due": "2026-04-13", + "open_units": 6, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Tampa-BRK": { + "due": "2026-04-07", + "open_units": 2, + "site": "Tampa", + "sku": "BRK", + "status": "proposed" + }, + "PO-Tampa-CAP": { + "due": "2026-04-13", + "open_units": 11, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-CLP": { + "due": "2026-04-06", + "open_units": 12, + "site": "Tampa", + "sku": "CLP", + "status": "confirmed" + } + }, + "inventory": { + "Denver-BRK": { + "on_hand": 42, + "reserved": 4, + "safety": 5, + "site": "Denver", + "sku": "BRK" + }, + "Denver-CAP": { + "on_hand": 36, + "reserved": 2, + "safety": 4, + "site": "Denver", + "sku": "CAP" + }, + "Denver-CLP": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Denver", + "sku": "CLP" + }, + "Fresno-BRK": { + "on_hand": 47, + "reserved": 5, + "safety": 4, + "site": "Fresno", + "sku": "BRK" + }, + "Fresno-CAP": { + "on_hand": 19, + "reserved": 1, + "safety": 8, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 35, + "reserved": 3, + "safety": 5, + "site": "Fresno", + "sku": "CLP" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 0, + "safety": 4, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 25, + "reserved": 2, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 25, + "reserved": 5, + "safety": 7, + "site": "Tampa", + "sku": "CLP" + } + }, + "orders": { + "SO-12984-2": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "BRK", + "state": "open", + "units": 8 + }, + "SO-17125-6": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-27", + "sku": "CAP", + "state": "open", + "units": 6 + }, + "SO-38808-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "BRK", + "state": "shipped", + "units": 25 + }, + "SO-45712-12": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-04-03", + "sku": "CAP", + "state": "open", + "units": 18 + }, + "SO-47065-8": { + "origin": "Denver", + "priority": 3, + "promise": "2026-03-26", + "sku": "BRK", + "state": "shipped", + "units": 4 + }, + "SO-49918-10": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-06", + "sku": "CLP", + "state": "open", + "units": 21 + }, + "SO-62202-9": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-04-08", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-63901-5": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-29", + "sku": "BRK", + "state": "open", + "units": 19 + }, + "SO-65804-3": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-04-03", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-67540-4": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-29", + "sku": "CLP", + "state": "open", + "units": 27 + }, + "SO-75136-1": { + "origin": "Fresno", + "priority": 3, + "promise": "2026-03-28", + "sku": "CLP", + "state": "open", + "units": 65 + }, + "SO-93556-7": { + "origin": "Fresno", + "priority": 2, + "promise": "2026-03-28", + "sku": "CLP", + "state": "open", + "units": 7 + }, + "SO-96783-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2026-03-27", + "sku": "CAP", + "state": "open", + "units": 1 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-040/tests/world_check.py b/tasks/autom-fulfillment-release-040/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-040/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-040/validation/openenv.json b/tasks/autom-fulfillment-release-040/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-040/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-041/environment/inputs/apps.py b/tasks/autom-fulfillment-release-041/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-041/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-041/environment/inputs/world.json b/tasks/autom-fulfillment-release-041/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..204184a123047927ba1a14ab18950decdf00f149 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/environment/inputs/world.json @@ -0,0 +1,250 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CPL": { + "due": "2026-04-29", + "open_units": 7, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-05-06", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Albany-RNG": { + "due": "2026-05-02", + "open_units": 5, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CPL": { + "due": "2026-05-07", + "open_units": 7, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-05-02", + "open_units": 10, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-05-07", + "open_units": 9, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2026-05-05", + "open_units": 6, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2026-05-01", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2026-05-04", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CPL": { + "on_hand": 26, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 16, + "reserved": 1, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 39, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CPL": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 39, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Tampa-CPL": { + "on_hand": 13, + "reserved": 4, + "safety": 4, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 29, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-10015-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-20", + "sku": "CPL", + "state": "open", + "units": 1 + }, + "SO-28479-2": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "MDL", + "state": "open", + "units": 26 + }, + "SO-51268-4": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-23", + "sku": "RNG", + "state": "open", + "units": 16 + }, + "SO-55778-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 5 + }, + "SO-57372-6": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "CPL", + "state": "open", + "units": 20 + }, + "SO-61215-5": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-21", + "sku": "MDL", + "state": "open", + "units": 19 + }, + "SO-64974-3": { + "origin": "Albany", + "priority": 3, + "promise": "2026-04-25", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-65169-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-16", + "sku": "RNG", + "state": "open", + "units": 25 + }, + "SO-71360-11": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-29", + "sku": "MDL", + "state": "open", + "units": 31 + }, + "SO-72122-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-20", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-85364-8": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-17", + "sku": "MDL", + "state": "open", + "units": 28 + }, + "SO-91515-7": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-23", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-97923-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-041/instruction.md b/tasks/autom-fulfillment-release-041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..be2eb25bde6cd3c49f7c4fb1492e42876db42cba --- /dev/null +++ b/tasks/autom-fulfillment-release-041/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Albany as of 2026-04-26. 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 Albany. If the origin cannot cover the complete order, try Fresno 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-` 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 Albany, deduct confirmed inbound open units for that site/SKU with due date on or before 2026-05-03. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Albany-` 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. diff --git a/tasks/autom-fulfillment-release-041/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-041/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..5363fc8edfc2535d1f7b39cbab32080ad777e3f2 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-10015-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-72122-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-28479-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-64974-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-51268-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-61215-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-57372-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-91515-7", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-85364-8", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-65169-10", "op": "update"} +{"app": "inventory", "fields": {"reserved": 6}, "id": "Albany-CPL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 25}, "id": "Albany-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 35}, "id": "Fresno-RNG", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-65169-10", "site": "Albany", "sku": "RNG", "units": 25}, "id": "pick-SO-65169-10", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-10015-0", "site": "Albany", "sku": "CPL", "units": 1}, "id": "pick-SO-10015-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-51268-4", "site": "Fresno", "sku": "RNG", "units": 16}, "id": "pick-SO-51268-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-91515-7", "site": "Fresno", "sku": "RNG", "units": 18}, "id": "pick-SO-91515-7", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "MDL", "status": "draft", "units": 73}, "id": "req-Albany-MDL", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CPL", "status": "draft", "units": 39}, "id": "req-Albany-CPL", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "RNG", "status": "draft", "units": 65}, "id": "req-Albany-RNG", "op": "create"} diff --git a/tasks/autom-fulfillment-release-041/solution/solve.sh b/tasks/autom-fulfillment-release-041/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-041/task.toml b/tasks/autom-fulfillment-release-041/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9a2902fc99619e4129d44eb500e4e42cc9d69e9f --- /dev/null +++ b/tasks/autom-fulfillment-release-041/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-041" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 41 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-041" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-041/tests/expected.json b/tasks/autom-fulfillment-release-041/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-041/tests/grade.py b/tasks/autom-fulfillment-release-041/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-041/tests/replay.py b/tasks/autom-fulfillment-release-041/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-041/tests/target.json b/tasks/autom-fulfillment-release-041/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..33b5dca1fbf4bc835ce9ce54c7a8fe74d18dfef6 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/target.json @@ -0,0 +1,292 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-10015-0": { + "order": "SO-10015-0", + "site": "Albany", + "sku": "CPL", + "units": 1 + }, + "pick-SO-51268-4": { + "order": "SO-51268-4", + "site": "Fresno", + "sku": "RNG", + "units": 16 + }, + "pick-SO-65169-10": { + "order": "SO-65169-10", + "site": "Albany", + "sku": "RNG", + "units": 25 + }, + "pick-SO-91515-7": { + "order": "SO-91515-7", + "site": "Fresno", + "sku": "RNG", + "units": 18 + } + }, + "inbound": { + "PO-Albany-CPL": { + "due": "2026-04-29", + "open_units": 7, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-05-06", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Albany-RNG": { + "due": "2026-05-02", + "open_units": 5, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CPL": { + "due": "2026-05-07", + "open_units": 7, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-05-02", + "open_units": 10, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-05-07", + "open_units": 9, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2026-05-05", + "open_units": 6, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2026-05-01", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2026-05-04", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CPL": { + "on_hand": 26, + "reserved": 6, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 16, + "reserved": 1, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 39, + "reserved": 25, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CPL": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 39, + "reserved": 35, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Tampa-CPL": { + "on_hand": 13, + "reserved": 4, + "safety": 4, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 29, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-10015-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-20", + "sku": "CPL", + "state": "allocated", + "units": 1 + }, + "SO-28479-2": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "MDL", + "state": "backorder", + "units": 26 + }, + "SO-51268-4": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-23", + "sku": "RNG", + "state": "allocated", + "units": 16 + }, + "SO-55778-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 5 + }, + "SO-57372-6": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "CPL", + "state": "backorder", + "units": 20 + }, + "SO-61215-5": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-21", + "sku": "MDL", + "state": "backorder", + "units": 19 + }, + "SO-64974-3": { + "origin": "Albany", + "priority": 3, + "promise": "2026-04-25", + "sku": "CPL", + "state": "backorder", + "units": 26 + }, + "SO-65169-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-16", + "sku": "RNG", + "state": "allocated", + "units": 25 + }, + "SO-71360-11": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-29", + "sku": "MDL", + "state": "open", + "units": 31 + }, + "SO-72122-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-20", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-85364-8": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-17", + "sku": "MDL", + "state": "backorder", + "units": 28 + }, + "SO-91515-7": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-23", + "sku": "RNG", + "state": "allocated", + "units": 18 + }, + "SO-97923-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Albany-CPL": { + "site": "Albany", + "sku": "CPL", + "status": "draft", + "units": 39 + }, + "req-Albany-MDL": { + "site": "Albany", + "sku": "MDL", + "status": "draft", + "units": 73 + }, + "req-Albany-RNG": { + "site": "Albany", + "sku": "RNG", + "status": "draft", + "units": 65 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-041/tests/test.sh b/tasks/autom-fulfillment-release-041/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-041/tests/world.json b/tasks/autom-fulfillment-release-041/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..204184a123047927ba1a14ab18950decdf00f149 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/world.json @@ -0,0 +1,250 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CPL": { + "due": "2026-04-29", + "open_units": 7, + "site": "Albany", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Albany-MDL": { + "due": "2026-05-06", + "open_units": 4, + "site": "Albany", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Albany-RNG": { + "due": "2026-05-02", + "open_units": 5, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CPL": { + "due": "2026-05-07", + "open_units": 7, + "site": "Fresno", + "sku": "CPL", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2026-05-02", + "open_units": 10, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2026-05-07", + "open_units": 9, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CPL": { + "due": "2026-05-05", + "open_units": 6, + "site": "Tampa", + "sku": "CPL", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2026-05-01", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2026-05-04", + "open_units": 2, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Albany-CPL": { + "on_hand": 26, + "reserved": 5, + "safety": 5, + "site": "Albany", + "sku": "CPL" + }, + "Albany-MDL": { + "on_hand": 16, + "reserved": 1, + "safety": 5, + "site": "Albany", + "sku": "MDL" + }, + "Albany-RNG": { + "on_hand": 39, + "reserved": 0, + "safety": 5, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CPL": { + "on_hand": 19, + "reserved": 3, + "safety": 6, + "site": "Fresno", + "sku": "CPL" + }, + "Fresno-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 5, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-RNG": { + "on_hand": 39, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "RNG" + }, + "Tampa-CPL": { + "on_hand": 13, + "reserved": 4, + "safety": 4, + "site": "Tampa", + "sku": "CPL" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 29, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "RNG" + } + }, + "orders": { + "SO-10015-0": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-20", + "sku": "CPL", + "state": "open", + "units": 1 + }, + "SO-28479-2": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "MDL", + "state": "open", + "units": 26 + }, + "SO-51268-4": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-23", + "sku": "RNG", + "state": "open", + "units": 16 + }, + "SO-55778-12": { + "origin": "Tampa", + "priority": 3, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 5 + }, + "SO-57372-6": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-19", + "sku": "CPL", + "state": "open", + "units": 20 + }, + "SO-61215-5": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-21", + "sku": "MDL", + "state": "open", + "units": 19 + }, + "SO-64974-3": { + "origin": "Albany", + "priority": 3, + "promise": "2026-04-25", + "sku": "CPL", + "state": "open", + "units": 26 + }, + "SO-65169-10": { + "origin": "Albany", + "priority": 1, + "promise": "2026-04-16", + "sku": "RNG", + "state": "open", + "units": 25 + }, + "SO-71360-11": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-29", + "sku": "MDL", + "state": "open", + "units": 31 + }, + "SO-72122-1": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-20", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-85364-8": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-17", + "sku": "MDL", + "state": "open", + "units": 28 + }, + "SO-91515-7": { + "origin": "Albany", + "priority": 2, + "promise": "2026-04-23", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-97923-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2026-04-30", + "sku": "CPL", + "state": "open", + "units": 16 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-041/tests/world_check.py b/tasks/autom-fulfillment-release-041/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-041/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-041/validation/openenv.json b/tasks/autom-fulfillment-release-041/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-041/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-043/environment/inputs/apps.py b/tasks/autom-fulfillment-release-043/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-043/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-043/environment/inputs/world.json b/tasks/autom-fulfillment-release-043/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..47dfb6a8d35b165d5b8e8339ebfa2ad439c5aae6 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/environment/inputs/world.json @@ -0,0 +1,306 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-MDL": { + "due": "2025-02-17", + "open_units": 5, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-02-08", + "open_units": 4, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-02-12", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2025-02-11", + "open_units": 8, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-02-11", + "open_units": 6, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2025-02-15", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-02-08", + "open_units": 9, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-02-07", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-02-07", + "open_units": 4, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-MDL": { + "on_hand": 39, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 32, + "reserved": 5, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-MDL": { + "on_hand": 42, + "reserved": 5, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 35, + "reserved": 2, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 32, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-MDL": { + "on_hand": 28, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 28, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 32, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-12793-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-02", + "sku": "PLT", + "state": "open", + "units": 8 + }, + "SO-15035-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-06", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-16195-15": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-04", + "sku": "MDL", + "state": "open", + "units": 29 + }, + "SO-16349-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-11", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-17032-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-03", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-29573-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-01", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-38797-11": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-04", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-38888-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-05", + "sku": "MDL", + "state": "shipped", + "units": 12 + }, + "SO-42158-10": { + "origin": "Waco", + "priority": 3, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 15 + }, + "SO-47008-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-02", + "sku": "MDL", + "state": "open", + "units": 29 + }, + "SO-52841-8": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-09", + "sku": "RNG", + "state": "shipped", + "units": 13 + }, + "SO-52875-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "RNG", + "state": "open", + "units": 28 + }, + "SO-53588-19": { + "origin": "Denver", + "priority": 1, + "promise": "2025-01-31", + "sku": "PLT", + "state": "shipped", + "units": 16 + }, + "SO-67453-18": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-07", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-70902-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "MDL", + "state": "open", + "units": 3 + }, + "SO-80012-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-08", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-87726-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 19 + }, + "SO-89788-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-01-31", + "sku": "PLT", + "state": "open", + "units": 14 + }, + "SO-97726-17": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-07", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-98941-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-30", + "sku": "PLT", + "state": "open", + "units": 24 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-043/instruction.md b/tasks/autom-fulfillment-release-043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d53baef0ba735edfc5f075e53d4b1c045c5a227a --- /dev/null +++ b/tasks/autom-fulfillment-release-043/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Denver as of 2025-02-06. 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. If the origin cannot cover the complete order, try Fresno 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-` 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-02-13. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Denver-` 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. diff --git a/tasks/autom-fulfillment-release-043/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-043/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..66a322a2229230e0fe714e41b1e70ae8bc2583a0 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/solution/files/actions.jsonl @@ -0,0 +1,20 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-17032-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-15035-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-29573-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-70902-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-98941-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-52875-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-47008-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-12793-7", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-16195-15", "op": "update"} +{"app": "inventory", "fields": {"reserved": 34}, "id": "Denver-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 32}, "id": "Denver-PLT", "op": "update"} +{"app": "inventory", "fields": {"reserved": 34}, "id": "Fresno-MDL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-17032-0", "site": "Denver", "sku": "MDL", "units": 1}, "id": "pick-SO-17032-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-70902-3", "site": "Denver", "sku": "MDL", "units": 3}, "id": "pick-SO-70902-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-98941-4", "site": "Denver", "sku": "PLT", "units": 24}, "id": "pick-SO-98941-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-47008-6", "site": "Denver", "sku": "MDL", "units": 29}, "id": "pick-SO-47008-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-16195-15", "site": "Fresno", "sku": "MDL", "units": 29}, "id": "pick-SO-16195-15", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-12793-7", "site": "Denver", "sku": "PLT", "units": 8}, "id": "pick-SO-12793-7", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "RNG", "status": "draft", "units": 59}, "id": "req-Denver-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Denver", "sku": "PLT", "status": "draft", "units": 65}, "id": "req-Denver-PLT", "op": "create"} diff --git a/tasks/autom-fulfillment-release-043/solution/solve.sh b/tasks/autom-fulfillment-release-043/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-043/task.toml b/tasks/autom-fulfillment-release-043/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..400451ab6401019cdb8ed7db88a4024ffd82bcd2 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-043" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 43 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-043" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-043/tests/expected.json b/tasks/autom-fulfillment-release-043/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-043/tests/grade.py b/tasks/autom-fulfillment-release-043/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-043/tests/replay.py b/tasks/autom-fulfillment-release-043/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-043/tests/target.json b/tasks/autom-fulfillment-release-043/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..938d30bae18de4b258e700588d6e9df84b8efd21 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/target.json @@ -0,0 +1,354 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-12793-7": { + "order": "SO-12793-7", + "site": "Denver", + "sku": "PLT", + "units": 8 + }, + "pick-SO-16195-15": { + "order": "SO-16195-15", + "site": "Fresno", + "sku": "MDL", + "units": 29 + }, + "pick-SO-17032-0": { + "order": "SO-17032-0", + "site": "Denver", + "sku": "MDL", + "units": 1 + }, + "pick-SO-47008-6": { + "order": "SO-47008-6", + "site": "Denver", + "sku": "MDL", + "units": 29 + }, + "pick-SO-70902-3": { + "order": "SO-70902-3", + "site": "Denver", + "sku": "MDL", + "units": 3 + }, + "pick-SO-98941-4": { + "order": "SO-98941-4", + "site": "Denver", + "sku": "PLT", + "units": 24 + } + }, + "inbound": { + "PO-Denver-MDL": { + "due": "2025-02-17", + "open_units": 5, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-02-08", + "open_units": 4, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-02-12", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2025-02-11", + "open_units": 8, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-02-11", + "open_units": 6, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2025-02-15", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-02-08", + "open_units": 9, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-02-07", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-02-07", + "open_units": 4, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-MDL": { + "on_hand": 39, + "reserved": 34, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 42, + "reserved": 32, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 32, + "reserved": 5, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-MDL": { + "on_hand": 42, + "reserved": 34, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 35, + "reserved": 2, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 32, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-MDL": { + "on_hand": 28, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 28, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 32, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-12793-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-02", + "sku": "PLT", + "state": "allocated", + "units": 8 + }, + "SO-15035-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-06", + "sku": "PLT", + "state": "backorder", + "units": 65 + }, + "SO-16195-15": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-04", + "sku": "MDL", + "state": "allocated", + "units": 29 + }, + "SO-16349-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-11", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-17032-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-03", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-29573-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-01", + "sku": "RNG", + "state": "backorder", + "units": 33 + }, + "SO-38797-11": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-04", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-38888-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-05", + "sku": "MDL", + "state": "shipped", + "units": 12 + }, + "SO-42158-10": { + "origin": "Waco", + "priority": 3, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 15 + }, + "SO-47008-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-02", + "sku": "MDL", + "state": "allocated", + "units": 29 + }, + "SO-52841-8": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-09", + "sku": "RNG", + "state": "shipped", + "units": 13 + }, + "SO-52875-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "RNG", + "state": "backorder", + "units": 28 + }, + "SO-53588-19": { + "origin": "Denver", + "priority": 1, + "promise": "2025-01-31", + "sku": "PLT", + "state": "shipped", + "units": 16 + }, + "SO-67453-18": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-07", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-70902-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "MDL", + "state": "allocated", + "units": 3 + }, + "SO-80012-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-08", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-87726-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 19 + }, + "SO-89788-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-01-31", + "sku": "PLT", + "state": "open", + "units": 14 + }, + "SO-97726-17": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-07", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-98941-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-30", + "sku": "PLT", + "state": "allocated", + "units": 24 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Denver-PLT": { + "site": "Denver", + "sku": "PLT", + "status": "draft", + "units": 65 + }, + "req-Denver-RNG": { + "site": "Denver", + "sku": "RNG", + "status": "draft", + "units": 59 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-043/tests/test.sh b/tasks/autom-fulfillment-release-043/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-043/tests/world.json b/tasks/autom-fulfillment-release-043/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..47dfb6a8d35b165d5b8e8339ebfa2ad439c5aae6 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/world.json @@ -0,0 +1,306 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-MDL": { + "due": "2025-02-17", + "open_units": 5, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-PLT": { + "due": "2025-02-08", + "open_units": 4, + "site": "Denver", + "sku": "PLT", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-02-12", + "open_units": 2, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Fresno-MDL": { + "due": "2025-02-11", + "open_units": 8, + "site": "Fresno", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-02-11", + "open_units": 6, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Fresno-RNG": { + "due": "2025-02-15", + "open_units": 7, + "site": "Fresno", + "sku": "RNG", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-02-08", + "open_units": 9, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-02-07", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-02-07", + "open_units": 4, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-MDL": { + "on_hand": 39, + "reserved": 1, + "safety": 5, + "site": "Denver", + "sku": "MDL" + }, + "Denver-PLT": { + "on_hand": 42, + "reserved": 0, + "safety": 6, + "site": "Denver", + "sku": "PLT" + }, + "Denver-RNG": { + "on_hand": 32, + "reserved": 5, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Fresno-MDL": { + "on_hand": 42, + "reserved": 5, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 35, + "reserved": 2, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 32, + "reserved": 4, + "safety": 5, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-MDL": { + "on_hand": 28, + "reserved": 5, + "safety": 5, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 28, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 32, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-12793-7": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-02", + "sku": "PLT", + "state": "open", + "units": 8 + }, + "SO-15035-1": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-06", + "sku": "PLT", + "state": "open", + "units": 65 + }, + "SO-16195-15": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-04", + "sku": "MDL", + "state": "open", + "units": 29 + }, + "SO-16349-12": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-11", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-17032-0": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-03", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-29573-2": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-01", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-38797-11": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-04", + "sku": "RNG", + "state": "shipped", + "units": 30 + }, + "SO-38888-9": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-05", + "sku": "MDL", + "state": "shipped", + "units": 12 + }, + "SO-42158-10": { + "origin": "Waco", + "priority": 3, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 15 + }, + "SO-47008-6": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-02", + "sku": "MDL", + "state": "open", + "units": 29 + }, + "SO-52841-8": { + "origin": "Denver", + "priority": 3, + "promise": "2025-02-09", + "sku": "RNG", + "state": "shipped", + "units": 13 + }, + "SO-52875-5": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "RNG", + "state": "open", + "units": 28 + }, + "SO-53588-19": { + "origin": "Denver", + "priority": 1, + "promise": "2025-01-31", + "sku": "PLT", + "state": "shipped", + "units": 16 + }, + "SO-67453-18": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-07", + "sku": "MDL", + "state": "open", + "units": 5 + }, + "SO-70902-3": { + "origin": "Denver", + "priority": 1, + "promise": "2025-02-06", + "sku": "MDL", + "state": "open", + "units": 3 + }, + "SO-80012-14": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-08", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-87726-16": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-27", + "sku": "PLT", + "state": "shipped", + "units": 19 + }, + "SO-89788-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-01-31", + "sku": "PLT", + "state": "open", + "units": 14 + }, + "SO-97726-17": { + "origin": "Denver", + "priority": 2, + "promise": "2025-02-07", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-98941-4": { + "origin": "Denver", + "priority": 2, + "promise": "2025-01-30", + "sku": "PLT", + "state": "open", + "units": 24 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-043/tests/world_check.py b/tasks/autom-fulfillment-release-043/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-043/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-043/validation/openenv.json b/tasks/autom-fulfillment-release-043/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-043/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-044/environment/inputs/apps.py b/tasks/autom-fulfillment-release-044/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-044/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-044/environment/inputs/world.json b/tasks/autom-fulfillment-release-044/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..b36710aaa9cfd6bc9946e4b0bc067c73a147e058 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/environment/inputs/world.json @@ -0,0 +1,274 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-CAP": { + "due": "2025-03-09", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-03-07", + "open_units": 10, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-03-04", + "open_units": 12, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-03-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-03", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-03-08", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-07", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-09", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-03-06", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-MDL": { + "on_hand": 26, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-MDL": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 35, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-MDL": { + "on_hand": 14, + "reserved": 4, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 4, + "safety": 4, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11754-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "MDL", + "state": "open", + "units": 19 + }, + "SO-22558-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-05", + "sku": "CAP", + "state": "open", + "units": 33 + }, + "SO-30113-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-27", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-30364-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-02-21", + "sku": "MDL", + "state": "open", + "units": 12 + }, + "SO-35214-7": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-43997-4": { + "origin": "Waco", + "priority": 1, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 24 + }, + "SO-47729-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-24", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-51154-8": { + "origin": "Waco", + "priority": 3, + "promise": "2025-03-03", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-52134-2": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-24", + "sku": "CAP", + "state": "open", + "units": 33 + }, + "SO-52479-5": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-27", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-62315-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-65069-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-22", + "sku": "MDL", + "state": "open", + "units": 20 + }, + "SO-70894-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-88886-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-01", + "sku": "CAP", + "state": "shipped", + "units": 29 + }, + "SO-92142-1": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-22", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-95293-15": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-23", + "sku": "MDL", + "state": "open", + "units": 12 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-044/instruction.md b/tasks/autom-fulfillment-release-044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f0994e18b58ae2acf0861694c1dfedfdf124256c --- /dev/null +++ b/tasks/autom-fulfillment-release-044/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Waco as of 2025-03-01. 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 Waco. 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-` 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 Waco, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-03-08. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Waco-` 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. diff --git a/tasks/autom-fulfillment-release-044/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-044/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..bd48e87c458cb0257ae65c6dc0c683dbed3d985f --- /dev/null +++ b/tasks/autom-fulfillment-release-044/solution/files/actions.jsonl @@ -0,0 +1,19 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-30113-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-92142-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-52134-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-65069-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-43997-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-52479-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-47729-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-11754-12", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-95293-15", "op": "update"} +{"app": "inventory", "fields": {"reserved": 5}, "id": "Waco-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 28}, "id": "Waco-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 19}, "id": "Denver-MDL", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-95293-15", "site": "Denver", "sku": "MDL", "units": 12}, "id": "pick-SO-95293-15", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-47729-6", "site": "Denver", "sku": "MDL", "units": 4}, "id": "pick-SO-47729-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-30113-0", "site": "Waco", "sku": "MDL", "units": 1}, "id": "pick-SO-30113-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-43997-4", "site": "Waco", "sku": "RNG", "units": 24}, "id": "pick-SO-43997-4", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "MDL", "status": "draft", "units": 39}, "id": "req-Waco-MDL", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "RNG", "status": "draft", "units": 55}, "id": "req-Waco-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Waco", "sku": "CAP", "status": "draft", "units": 64}, "id": "req-Waco-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-044/solution/solve.sh b/tasks/autom-fulfillment-release-044/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-044/task.toml b/tasks/autom-fulfillment-release-044/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e4a67848564a6a261889a228839c8d06fe76c10f --- /dev/null +++ b/tasks/autom-fulfillment-release-044/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-044" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 44 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-044" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-044/tests/expected.json b/tasks/autom-fulfillment-release-044/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-044/tests/grade.py b/tasks/autom-fulfillment-release-044/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-044/tests/replay.py b/tasks/autom-fulfillment-release-044/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-044/tests/target.json b/tasks/autom-fulfillment-release-044/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..5ed87454465e027e68d0da3081cec4593b672c4c --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/target.json @@ -0,0 +1,316 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-30113-0": { + "order": "SO-30113-0", + "site": "Waco", + "sku": "MDL", + "units": 1 + }, + "pick-SO-43997-4": { + "order": "SO-43997-4", + "site": "Waco", + "sku": "RNG", + "units": 24 + }, + "pick-SO-47729-6": { + "order": "SO-47729-6", + "site": "Denver", + "sku": "MDL", + "units": 4 + }, + "pick-SO-95293-15": { + "order": "SO-95293-15", + "site": "Denver", + "sku": "MDL", + "units": 12 + } + }, + "inbound": { + "PO-Denver-CAP": { + "due": "2025-03-09", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-03-07", + "open_units": 10, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-03-04", + "open_units": 12, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-03-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-03", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-03-08", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-07", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-09", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-03-06", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-MDL": { + "on_hand": 26, + "reserved": 19, + "safety": 7, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-MDL": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 35, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-MDL": { + "on_hand": 14, + "reserved": 5, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 28, + "safety": 4, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11754-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "MDL", + "state": "backorder", + "units": 19 + }, + "SO-22558-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-05", + "sku": "CAP", + "state": "open", + "units": 33 + }, + "SO-30113-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-27", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-30364-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-02-21", + "sku": "MDL", + "state": "open", + "units": 12 + }, + "SO-35214-7": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-43997-4": { + "origin": "Waco", + "priority": 1, + "promise": "2025-03-01", + "sku": "RNG", + "state": "allocated", + "units": 24 + }, + "SO-47729-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-24", + "sku": "MDL", + "state": "allocated", + "units": 4 + }, + "SO-51154-8": { + "origin": "Waco", + "priority": 3, + "promise": "2025-03-03", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-52134-2": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-24", + "sku": "CAP", + "state": "backorder", + "units": 33 + }, + "SO-52479-5": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-27", + "sku": "CAP", + "state": "backorder", + "units": 31 + }, + "SO-62315-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-65069-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-22", + "sku": "MDL", + "state": "backorder", + "units": 20 + }, + "SO-70894-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-88886-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-01", + "sku": "CAP", + "state": "shipped", + "units": 29 + }, + "SO-92142-1": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-22", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-95293-15": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-23", + "sku": "MDL", + "state": "allocated", + "units": 12 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Waco-CAP": { + "site": "Waco", + "sku": "CAP", + "status": "draft", + "units": 64 + }, + "req-Waco-MDL": { + "site": "Waco", + "sku": "MDL", + "status": "draft", + "units": 39 + }, + "req-Waco-RNG": { + "site": "Waco", + "sku": "RNG", + "status": "draft", + "units": 55 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-044/tests/test.sh b/tasks/autom-fulfillment-release-044/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-044/tests/world.json b/tasks/autom-fulfillment-release-044/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..b36710aaa9cfd6bc9946e4b0bc067c73a147e058 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/world.json @@ -0,0 +1,274 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Denver-CAP": { + "due": "2025-03-09", + "open_units": 12, + "site": "Denver", + "sku": "CAP", + "status": "proposed" + }, + "PO-Denver-MDL": { + "due": "2025-03-07", + "open_units": 10, + "site": "Denver", + "sku": "MDL", + "status": "proposed" + }, + "PO-Denver-RNG": { + "due": "2025-03-04", + "open_units": 12, + "site": "Denver", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-03-05", + "open_units": 7, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-03", + "open_units": 9, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-03-08", + "open_units": 12, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-07", + "open_units": 6, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-09", + "open_units": 7, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-03-06", + "open_units": 10, + "site": "Waco", + "sku": "RNG", + "status": "confirmed" + } + }, + "inventory": { + "Denver-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Denver", + "sku": "CAP" + }, + "Denver-MDL": { + "on_hand": 26, + "reserved": 3, + "safety": 7, + "site": "Denver", + "sku": "MDL" + }, + "Denver-RNG": { + "on_hand": 43, + "reserved": 4, + "safety": 7, + "site": "Denver", + "sku": "RNG" + }, + "Tampa-CAP": { + "on_hand": 39, + "reserved": 1, + "safety": 8, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-MDL": { + "on_hand": 47, + "reserved": 2, + "safety": 6, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-RNG": { + "on_hand": 21, + "reserved": 5, + "safety": 8, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 35, + "reserved": 0, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-MDL": { + "on_hand": 14, + "reserved": 4, + "safety": 7, + "site": "Waco", + "sku": "MDL" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 4, + "safety": 4, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11754-12": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "MDL", + "state": "open", + "units": 19 + }, + "SO-22558-14": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-05", + "sku": "CAP", + "state": "open", + "units": 33 + }, + "SO-30113-0": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-27", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-30364-9": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-02-21", + "sku": "MDL", + "state": "open", + "units": 12 + }, + "SO-35214-7": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-43997-4": { + "origin": "Waco", + "priority": 1, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 24 + }, + "SO-47729-6": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-24", + "sku": "MDL", + "state": "open", + "units": 4 + }, + "SO-51154-8": { + "origin": "Waco", + "priority": 3, + "promise": "2025-03-03", + "sku": "CAP", + "state": "open", + "units": 14 + }, + "SO-52134-2": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-24", + "sku": "CAP", + "state": "open", + "units": 33 + }, + "SO-52479-5": { + "origin": "Waco", + "priority": 3, + "promise": "2025-02-27", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-62315-10": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-01", + "sku": "RNG", + "state": "open", + "units": 18 + }, + "SO-65069-3": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-22", + "sku": "MDL", + "state": "open", + "units": 20 + }, + "SO-70894-13": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-25", + "sku": "RNG", + "state": "shipped", + "units": 7 + }, + "SO-88886-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-03-01", + "sku": "CAP", + "state": "shipped", + "units": 29 + }, + "SO-92142-1": { + "origin": "Waco", + "priority": 2, + "promise": "2025-02-22", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-95293-15": { + "origin": "Waco", + "priority": 1, + "promise": "2025-02-23", + "sku": "MDL", + "state": "open", + "units": 12 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-044/tests/world_check.py b/tasks/autom-fulfillment-release-044/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-044/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-044/validation/openenv.json b/tasks/autom-fulfillment-release-044/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-044/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-045/environment/inputs/apps.py b/tasks/autom-fulfillment-release-045/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-045/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-045/environment/inputs/world.json b/tasks/autom-fulfillment-release-045/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..55c008a4c1ec2fa43205081f391e4462f7cb0d77 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/environment/inputs/world.json @@ -0,0 +1,284 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Fresno-CAP": { + "due": "2025-03-30", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-01", + "open_units": 9, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-03-31", + "open_units": 6, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-03", + "open_units": 12, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-04-03", + "open_units": 8, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-03-27", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-25", + "open_units": 4, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-04-03", + "open_units": 4, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-29", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-02", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-30", + "open_units": 4, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-03-27", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Fresno-CAP": { + "on_hand": 14, + "reserved": 5, + "safety": 7, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 16, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 31, + "reserved": 1, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 31, + "reserved": 3, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Tampa-CAP": { + "on_hand": 37, + "reserved": 0, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 18, + "reserved": 1, + "safety": 8, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-PLT": { + "on_hand": 43, + "reserved": 5, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Waco-CAP": { + "on_hand": 14, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 44, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 37, + "reserved": 0, + "safety": 5, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-11786-8": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-03-22", + "sku": "MDL", + "state": "shipped", + "units": 25 + }, + "SO-14978-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-22", + "sku": "MDL", + "state": "open", + "units": 18 + }, + "SO-16319-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-17", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-30719-3": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-24", + "sku": "PLT", + "state": "open", + "units": 13 + }, + "SO-35000-5": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-19", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-60186-10": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-26", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-69171-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-21", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-77970-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-03-27", + "sku": "PLT", + "state": "shipped", + "units": 20 + }, + "SO-79880-7": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-19", + "sku": "PLT", + "state": "open", + "units": 13 + }, + "SO-88684-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-24", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-91947-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-21", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-98032-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-20", + "sku": "CAP", + "state": "open", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-045/instruction.md b/tasks/autom-fulfillment-release-045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..015394b84421af4ccc67e3b4e98a314565029c37 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Tampa as of 2025-03-24. 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 Tampa. 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-` 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-03-31. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Tampa-` 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. diff --git a/tasks/autom-fulfillment-release-045/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-045/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..5ed03ec41b5f1159c96f468d84c945d27353d3d9 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/solution/files/actions.jsonl @@ -0,0 +1,21 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-16319-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-88684-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-69171-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-30719-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-14978-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-35000-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-91947-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-79880-7", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-98032-9", "op": "update"} +{"app": "inventory", "fields": {"reserved": 3}, "id": "Tampa-MDL", "op": "update"} +{"app": "inventory", "fields": {"reserved": 31}, "id": "Tampa-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 9}, "id": "Tampa-CLP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 31}, "id": "Tampa-PLT", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-16319-0", "site": "Tampa", "sku": "MDL", "units": 1}, "id": "pick-SO-16319-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-79880-7", "site": "Tampa", "sku": "PLT", "units": 13}, "id": "pick-SO-79880-7", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-69171-2", "site": "Tampa", "sku": "CLP", "units": 8}, "id": "pick-SO-69171-2", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-35000-5", "site": "Tampa", "sku": "CAP", "units": 31}, "id": "pick-SO-35000-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-30719-3", "site": "Tampa", "sku": "PLT", "units": 13}, "id": "pick-SO-30719-3", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CAP", "status": "draft", "units": 88}, "id": "req-Tampa-CAP", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "CLP", "status": "draft", "units": 33}, "id": "req-Tampa-CLP", "op": "create"} +{"app": "procurement", "fields": {"site": "Tampa", "sku": "MDL", "status": "draft", "units": 14}, "id": "req-Tampa-MDL", "op": "create"} diff --git a/tasks/autom-fulfillment-release-045/solution/solve.sh b/tasks/autom-fulfillment-release-045/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-045/task.toml b/tasks/autom-fulfillment-release-045/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..07c2256adcf14095f0d3fea993a7b134f98bea20 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-045" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 45 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-045" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-045/tests/expected.json b/tasks/autom-fulfillment-release-045/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-045/tests/grade.py b/tasks/autom-fulfillment-release-045/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-045/tests/replay.py b/tasks/autom-fulfillment-release-045/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-045/tests/target.json b/tasks/autom-fulfillment-release-045/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..8d73045c4c638e4d73a9277128b43fe5977b783f --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/target.json @@ -0,0 +1,332 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-16319-0": { + "order": "SO-16319-0", + "site": "Tampa", + "sku": "MDL", + "units": 1 + }, + "pick-SO-30719-3": { + "order": "SO-30719-3", + "site": "Tampa", + "sku": "PLT", + "units": 13 + }, + "pick-SO-35000-5": { + "order": "SO-35000-5", + "site": "Tampa", + "sku": "CAP", + "units": 31 + }, + "pick-SO-69171-2": { + "order": "SO-69171-2", + "site": "Tampa", + "sku": "CLP", + "units": 8 + }, + "pick-SO-79880-7": { + "order": "SO-79880-7", + "site": "Tampa", + "sku": "PLT", + "units": 13 + } + }, + "inbound": { + "PO-Fresno-CAP": { + "due": "2025-03-30", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-01", + "open_units": 9, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-03-31", + "open_units": 6, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-03", + "open_units": 12, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-04-03", + "open_units": 8, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-03-27", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-25", + "open_units": 4, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-04-03", + "open_units": 4, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-29", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-02", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-30", + "open_units": 4, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-03-27", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Fresno-CAP": { + "on_hand": 14, + "reserved": 5, + "safety": 7, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 16, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 31, + "reserved": 1, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 31, + "reserved": 3, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Tampa-CAP": { + "on_hand": 37, + "reserved": 31, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 18, + "reserved": 9, + "safety": 8, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 3, + "safety": 7, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-PLT": { + "on_hand": 43, + "reserved": 31, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Waco-CAP": { + "on_hand": 14, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 44, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 37, + "reserved": 0, + "safety": 5, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-11786-8": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-03-22", + "sku": "MDL", + "state": "shipped", + "units": 25 + }, + "SO-14978-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-22", + "sku": "MDL", + "state": "backorder", + "units": 18 + }, + "SO-16319-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-17", + "sku": "MDL", + "state": "allocated", + "units": 1 + }, + "SO-30719-3": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-24", + "sku": "PLT", + "state": "allocated", + "units": 13 + }, + "SO-35000-5": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-19", + "sku": "CAP", + "state": "allocated", + "units": 31 + }, + "SO-60186-10": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-26", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-69171-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-21", + "sku": "CLP", + "state": "allocated", + "units": 8 + }, + "SO-77970-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-03-27", + "sku": "PLT", + "state": "shipped", + "units": 20 + }, + "SO-79880-7": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-19", + "sku": "PLT", + "state": "allocated", + "units": 13 + }, + "SO-88684-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-24", + "sku": "CAP", + "state": "backorder", + "units": 65 + }, + "SO-91947-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-21", + "sku": "CLP", + "state": "backorder", + "units": 33 + }, + "SO-98032-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-20", + "sku": "CAP", + "state": "backorder", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Tampa-CAP": { + "site": "Tampa", + "sku": "CAP", + "status": "draft", + "units": 88 + }, + "req-Tampa-CLP": { + "site": "Tampa", + "sku": "CLP", + "status": "draft", + "units": 33 + }, + "req-Tampa-MDL": { + "site": "Tampa", + "sku": "MDL", + "status": "draft", + "units": 14 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-045/tests/test.sh b/tasks/autom-fulfillment-release-045/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-045/tests/world.json b/tasks/autom-fulfillment-release-045/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..55c008a4c1ec2fa43205081f391e4462f7cb0d77 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/world.json @@ -0,0 +1,284 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Fresno-CAP": { + "due": "2025-03-30", + "open_units": 12, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-01", + "open_units": 9, + "site": "Fresno", + "sku": "CLP", + "status": "proposed" + }, + "PO-Fresno-MDL": { + "due": "2025-03-31", + "open_units": 6, + "site": "Fresno", + "sku": "MDL", + "status": "proposed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-03", + "open_units": 12, + "site": "Fresno", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-04-03", + "open_units": 8, + "site": "Tampa", + "sku": "CAP", + "status": "proposed" + }, + "PO-Tampa-CLP": { + "due": "2025-03-27", + "open_units": 7, + "site": "Tampa", + "sku": "CLP", + "status": "proposed" + }, + "PO-Tampa-MDL": { + "due": "2025-03-25", + "open_units": 4, + "site": "Tampa", + "sku": "MDL", + "status": "confirmed" + }, + "PO-Tampa-PLT": { + "due": "2025-04-03", + "open_units": 4, + "site": "Tampa", + "sku": "PLT", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-03-29", + "open_units": 3, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-02", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-MDL": { + "due": "2025-03-30", + "open_units": 4, + "site": "Waco", + "sku": "MDL", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-03-27", + "open_units": 2, + "site": "Waco", + "sku": "PLT", + "status": "confirmed" + } + }, + "inventory": { + "Fresno-CAP": { + "on_hand": 14, + "reserved": 5, + "safety": 7, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 16, + "reserved": 1, + "safety": 4, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-MDL": { + "on_hand": 31, + "reserved": 1, + "safety": 7, + "site": "Fresno", + "sku": "MDL" + }, + "Fresno-PLT": { + "on_hand": 31, + "reserved": 3, + "safety": 7, + "site": "Fresno", + "sku": "PLT" + }, + "Tampa-CAP": { + "on_hand": 37, + "reserved": 0, + "safety": 4, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-CLP": { + "on_hand": 18, + "reserved": 1, + "safety": 8, + "site": "Tampa", + "sku": "CLP" + }, + "Tampa-MDL": { + "on_hand": 16, + "reserved": 2, + "safety": 7, + "site": "Tampa", + "sku": "MDL" + }, + "Tampa-PLT": { + "on_hand": 43, + "reserved": 5, + "safety": 5, + "site": "Tampa", + "sku": "PLT" + }, + "Waco-CAP": { + "on_hand": 14, + "reserved": 2, + "safety": 5, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 44, + "reserved": 3, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-MDL": { + "on_hand": 23, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "MDL" + }, + "Waco-PLT": { + "on_hand": 37, + "reserved": 0, + "safety": 5, + "site": "Waco", + "sku": "PLT" + } + }, + "orders": { + "SO-11786-8": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-03-22", + "sku": "MDL", + "state": "shipped", + "units": 25 + }, + "SO-14978-4": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-22", + "sku": "MDL", + "state": "open", + "units": 18 + }, + "SO-16319-0": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-17", + "sku": "MDL", + "state": "open", + "units": 1 + }, + "SO-30719-3": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-24", + "sku": "PLT", + "state": "open", + "units": 13 + }, + "SO-35000-5": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-19", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-60186-10": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-26", + "sku": "CLP", + "state": "open", + "units": 16 + }, + "SO-69171-2": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-21", + "sku": "CLP", + "state": "open", + "units": 8 + }, + "SO-77970-11": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-03-27", + "sku": "PLT", + "state": "shipped", + "units": 20 + }, + "SO-79880-7": { + "origin": "Tampa", + "priority": 1, + "promise": "2025-03-19", + "sku": "PLT", + "state": "open", + "units": 13 + }, + "SO-88684-1": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-24", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-91947-6": { + "origin": "Tampa", + "priority": 3, + "promise": "2025-03-21", + "sku": "CLP", + "state": "open", + "units": 33 + }, + "SO-98032-9": { + "origin": "Tampa", + "priority": 2, + "promise": "2025-03-20", + "sku": "CAP", + "state": "open", + "units": 23 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-045/tests/world_check.py b/tasks/autom-fulfillment-release-045/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-045/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-045/validation/openenv.json b/tasks/autom-fulfillment-release-045/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-045/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-046/environment/inputs/apps.py b/tasks/autom-fulfillment-release-046/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-046/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-046/environment/inputs/world.json b/tasks/autom-fulfillment-release-046/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..8ee900b1c5e7a1f83d89f06bbb61d158e2728a7f --- /dev/null +++ b/tasks/autom-fulfillment-release-046/environment/inputs/world.json @@ -0,0 +1,348 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-04-22", + "open_units": 5, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-04-25", + "open_units": 9, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-04-17", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-04-17", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-04-26", + "open_units": 6, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-22", + "open_units": 7, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-19", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-04-27", + "open_units": 12, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-04-24", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-27", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-25", + "open_units": 8, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-04-18", + "open_units": 3, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 43, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "CLP" + }, + "Albany-PLT": { + "on_hand": 30, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 34, + "reserved": 1, + "safety": 4, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 45, + "reserved": 4, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 40, + "reserved": 4, + "safety": 8, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-PLT": { + "on_hand": 22, + "reserved": 1, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 25, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 45, + "reserved": 1, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-PLT": { + "on_hand": 24, + "reserved": 3, + "safety": 4, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14572-17": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "CAP", + "state": "shipped", + "units": 24 + }, + "SO-19154-14": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-11", + "sku": "PLT", + "state": "open", + "units": 30 + }, + "SO-25550-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-13", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-33368-6": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "PLT", + "state": "open", + "units": 23 + }, + "SO-40268-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-12", + "sku": "PLT", + "state": "open", + "units": 33 + }, + "SO-41872-9": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-19", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-48963-19": { + "origin": "Albany", + "priority": 2, + "promise": "2025-04-21", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-49801-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-15", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-51653-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-54508-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-18", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-60635-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "open", + "units": 1 + }, + "SO-61816-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-65700-11": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-11", + "sku": "CLP", + "state": "open", + "units": 3 + }, + "SO-68530-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-77190-16": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-06", + "sku": "RNG", + "state": "shipped", + "units": 26 + }, + "SO-77988-1": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-13", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-87561-10": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-10", + "sku": "PLT", + "state": "shipped", + "units": 14 + }, + "SO-88038-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "CLP", + "state": "open", + "units": 20 + }, + "SO-94772-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-09", + "sku": "CLP", + "state": "shipped", + "units": 3 + }, + "SO-97645-18": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "shipped", + "units": 26 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-046/instruction.md b/tasks/autom-fulfillment-release-046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6f2b841c5fbe0c255b211e15cb54883bfca4a4e7 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Fresno as of 2025-04-16. 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 Fresno. If the origin cannot cover the complete order, try Waco 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-` 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 Fresno, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-04-23. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Fresno-` 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. diff --git a/tasks/autom-fulfillment-release-046/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-046/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..d2db02752b512858eb9f9fe219b8207afbdcdc0d --- /dev/null +++ b/tasks/autom-fulfillment-release-046/solution/files/actions.jsonl @@ -0,0 +1,18 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-60635-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-77988-1", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-40268-2", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-88038-3", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-61816-4", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-25550-5", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-33368-6", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-49801-13", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-19154-14", "op": "update"} +{"app": "inventory", "fields": {"reserved": 5}, "id": "Fresno-RNG", "op": "update"} +{"app": "inventory", "fields": {"reserved": 28}, "id": "Fresno-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 24}, "id": "Fresno-CLP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-61816-4", "site": "Fresno", "sku": "RNG", "units": 3}, "id": "pick-SO-61816-4", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-88038-3", "site": "Fresno", "sku": "CLP", "units": 20}, "id": "pick-SO-88038-3", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-25550-5", "site": "Fresno", "sku": "CAP", "units": 24}, "id": "pick-SO-25550-5", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-60635-0", "site": "Fresno", "sku": "RNG", "units": 1}, "id": "pick-SO-60635-0", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "PLT", "status": "draft", "units": 86}, "id": "req-Fresno-PLT", "op": "create"} +{"app": "procurement", "fields": {"site": "Fresno", "sku": "CAP", "status": "draft", "units": 96}, "id": "req-Fresno-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-046/solution/solve.sh b/tasks/autom-fulfillment-release-046/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-046/task.toml b/tasks/autom-fulfillment-release-046/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..505de676335256707498cb1425ae09c59753c930 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-046" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 46 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-046" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-046/tests/expected.json b/tasks/autom-fulfillment-release-046/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-046/tests/grade.py b/tasks/autom-fulfillment-release-046/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-046/tests/replay.py b/tasks/autom-fulfillment-release-046/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-046/tests/target.json b/tasks/autom-fulfillment-release-046/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..7ab46e857c02293b8b319d1d3466dd1fc8c82d74 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/target.json @@ -0,0 +1,384 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-25550-5": { + "order": "SO-25550-5", + "site": "Fresno", + "sku": "CAP", + "units": 24 + }, + "pick-SO-60635-0": { + "order": "SO-60635-0", + "site": "Fresno", + "sku": "RNG", + "units": 1 + }, + "pick-SO-61816-4": { + "order": "SO-61816-4", + "site": "Fresno", + "sku": "RNG", + "units": 3 + }, + "pick-SO-88038-3": { + "order": "SO-88038-3", + "site": "Fresno", + "sku": "CLP", + "units": 20 + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-04-22", + "open_units": 5, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-04-25", + "open_units": 9, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-04-17", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-04-17", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-04-26", + "open_units": 6, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-22", + "open_units": 7, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-19", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-04-27", + "open_units": 12, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-04-24", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-27", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-25", + "open_units": 8, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-04-18", + "open_units": 3, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 43, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "CLP" + }, + "Albany-PLT": { + "on_hand": 30, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 34, + "reserved": 1, + "safety": 4, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 45, + "reserved": 28, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 40, + "reserved": 24, + "safety": 8, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-PLT": { + "on_hand": 22, + "reserved": 1, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 25, + "reserved": 5, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 45, + "reserved": 1, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-PLT": { + "on_hand": 24, + "reserved": 3, + "safety": 4, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14572-17": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "CAP", + "state": "shipped", + "units": 24 + }, + "SO-19154-14": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-11", + "sku": "PLT", + "state": "backorder", + "units": 30 + }, + "SO-25550-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-13", + "sku": "CAP", + "state": "allocated", + "units": 24 + }, + "SO-33368-6": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "PLT", + "state": "backorder", + "units": 23 + }, + "SO-40268-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-12", + "sku": "PLT", + "state": "backorder", + "units": 33 + }, + "SO-41872-9": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-19", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-48963-19": { + "origin": "Albany", + "priority": 2, + "promise": "2025-04-21", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-49801-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-15", + "sku": "CAP", + "state": "backorder", + "units": 31 + }, + "SO-51653-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-54508-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-18", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-60635-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "allocated", + "units": 1 + }, + "SO-61816-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "RNG", + "state": "allocated", + "units": 3 + }, + "SO-65700-11": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-11", + "sku": "CLP", + "state": "open", + "units": 3 + }, + "SO-68530-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-77190-16": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-06", + "sku": "RNG", + "state": "shipped", + "units": 26 + }, + "SO-77988-1": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-13", + "sku": "CAP", + "state": "backorder", + "units": 65 + }, + "SO-87561-10": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-10", + "sku": "PLT", + "state": "shipped", + "units": 14 + }, + "SO-88038-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "CLP", + "state": "allocated", + "units": 20 + }, + "SO-94772-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-09", + "sku": "CLP", + "state": "shipped", + "units": 3 + }, + "SO-97645-18": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "shipped", + "units": 26 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Fresno-CAP": { + "site": "Fresno", + "sku": "CAP", + "status": "draft", + "units": 96 + }, + "req-Fresno-PLT": { + "site": "Fresno", + "sku": "PLT", + "status": "draft", + "units": 86 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-046/tests/test.sh b/tasks/autom-fulfillment-release-046/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-046/tests/world.json b/tasks/autom-fulfillment-release-046/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..8ee900b1c5e7a1f83d89f06bbb61d158e2728a7f --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/world.json @@ -0,0 +1,348 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-CAP": { + "due": "2025-04-22", + "open_units": 5, + "site": "Albany", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Albany-CLP": { + "due": "2025-04-25", + "open_units": 9, + "site": "Albany", + "sku": "CLP", + "status": "proposed" + }, + "PO-Albany-PLT": { + "due": "2025-04-17", + "open_units": 4, + "site": "Albany", + "sku": "PLT", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-04-17", + "open_units": 10, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Fresno-CAP": { + "due": "2025-04-26", + "open_units": 6, + "site": "Fresno", + "sku": "CAP", + "status": "proposed" + }, + "PO-Fresno-CLP": { + "due": "2025-04-22", + "open_units": 7, + "site": "Fresno", + "sku": "CLP", + "status": "confirmed" + }, + "PO-Fresno-PLT": { + "due": "2025-04-19", + "open_units": 4, + "site": "Fresno", + "sku": "PLT", + "status": "proposed" + }, + "PO-Fresno-RNG": { + "due": "2025-04-27", + "open_units": 12, + "site": "Fresno", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-04-24", + "open_units": 4, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-CLP": { + "due": "2025-04-27", + "open_units": 9, + "site": "Waco", + "sku": "CLP", + "status": "proposed" + }, + "PO-Waco-PLT": { + "due": "2025-04-25", + "open_units": 8, + "site": "Waco", + "sku": "PLT", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-04-18", + "open_units": 3, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-CAP": { + "on_hand": 27, + "reserved": 4, + "safety": 5, + "site": "Albany", + "sku": "CAP" + }, + "Albany-CLP": { + "on_hand": 43, + "reserved": 1, + "safety": 8, + "site": "Albany", + "sku": "CLP" + }, + "Albany-PLT": { + "on_hand": 30, + "reserved": 0, + "safety": 4, + "site": "Albany", + "sku": "PLT" + }, + "Albany-RNG": { + "on_hand": 34, + "reserved": 1, + "safety": 4, + "site": "Albany", + "sku": "RNG" + }, + "Fresno-CAP": { + "on_hand": 45, + "reserved": 4, + "safety": 4, + "site": "Fresno", + "sku": "CAP" + }, + "Fresno-CLP": { + "on_hand": 40, + "reserved": 4, + "safety": 8, + "site": "Fresno", + "sku": "CLP" + }, + "Fresno-PLT": { + "on_hand": 22, + "reserved": 1, + "safety": 5, + "site": "Fresno", + "sku": "PLT" + }, + "Fresno-RNG": { + "on_hand": 25, + "reserved": 1, + "safety": 6, + "site": "Fresno", + "sku": "RNG" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "CAP" + }, + "Waco-CLP": { + "on_hand": 45, + "reserved": 1, + "safety": 8, + "site": "Waco", + "sku": "CLP" + }, + "Waco-PLT": { + "on_hand": 24, + "reserved": 3, + "safety": 4, + "site": "Waco", + "sku": "PLT" + }, + "Waco-RNG": { + "on_hand": 33, + "reserved": 2, + "safety": 6, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-14572-17": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "CAP", + "state": "shipped", + "units": 24 + }, + "SO-19154-14": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-11", + "sku": "PLT", + "state": "open", + "units": 30 + }, + "SO-25550-5": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-13", + "sku": "CAP", + "state": "open", + "units": 24 + }, + "SO-33368-6": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-15", + "sku": "PLT", + "state": "open", + "units": 23 + }, + "SO-40268-2": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-12", + "sku": "PLT", + "state": "open", + "units": 33 + }, + "SO-41872-9": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-19", + "sku": "CAP", + "state": "open", + "units": 7 + }, + "SO-48963-19": { + "origin": "Albany", + "priority": 2, + "promise": "2025-04-21", + "sku": "CLP", + "state": "open", + "units": 6 + }, + "SO-49801-13": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-15", + "sku": "CAP", + "state": "open", + "units": 31 + }, + "SO-51653-12": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-21", + "sku": "RNG", + "state": "open", + "units": 33 + }, + "SO-54508-15": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-18", + "sku": "CLP", + "state": "open", + "units": 24 + }, + "SO-60635-0": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "open", + "units": 1 + }, + "SO-61816-4": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-65700-11": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-11", + "sku": "CLP", + "state": "open", + "units": 3 + }, + "SO-68530-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-04-14", + "sku": "RNG", + "state": "open", + "units": 7 + }, + "SO-77190-16": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-06", + "sku": "RNG", + "state": "shipped", + "units": 26 + }, + "SO-77988-1": { + "origin": "Fresno", + "priority": 2, + "promise": "2025-04-13", + "sku": "CAP", + "state": "open", + "units": 65 + }, + "SO-87561-10": { + "origin": "Albany", + "priority": 3, + "promise": "2025-04-10", + "sku": "PLT", + "state": "shipped", + "units": 14 + }, + "SO-88038-3": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-09", + "sku": "CLP", + "state": "open", + "units": 20 + }, + "SO-94772-7": { + "origin": "Fresno", + "priority": 1, + "promise": "2025-04-09", + "sku": "CLP", + "state": "shipped", + "units": 3 + }, + "SO-97645-18": { + "origin": "Fresno", + "priority": 3, + "promise": "2025-04-19", + "sku": "PLT", + "state": "shipped", + "units": 26 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-046/tests/world_check.py b/tasks/autom-fulfillment-release-046/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-046/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-046/validation/openenv.json b/tasks/autom-fulfillment-release-046/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-046/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-049/environment/inputs/apps.py b/tasks/autom-fulfillment-release-049/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-049/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-049/environment/inputs/world.json b/tasks/autom-fulfillment-release-049/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..c1a114fc3aa731e8d0aaa73804b91ae738be0a6c --- /dev/null +++ b/tasks/autom-fulfillment-release-049/environment/inputs/world.json @@ -0,0 +1,282 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-06-29", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-06-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-06-27", + "open_units": 7, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-07-02", + "open_units": 7, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-07-04", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-07-01", + "open_units": 11, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-06-27", + "open_units": 1, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-05", + "open_units": 7, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-06-29", + "open_units": 1, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 31, + "reserved": 5, + "safety": 7, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 20, + "reserved": 5, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 3, + "safety": 8, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 41, + "reserved": 3, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-RNG": { + "on_hand": 19, + "reserved": 3, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 27, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "CAP" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11618-7": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "RNG", + "state": "open", + "units": 29 + }, + "SO-12394-4": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-20", + "sku": "RNG", + "state": "open", + "units": 23 + }, + "SO-23614-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-23", + "sku": "BRK", + "state": "open", + "units": 27 + }, + "SO-29649-16": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-30", + "sku": "RNG", + "state": "shipped", + "units": 27 + }, + "SO-34378-14": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-15", + "sku": "CAP", + "state": "open", + "units": 21 + }, + "SO-36339-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-21", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-40439-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-27", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-46288-12": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "BRK", + "state": "shipped", + "units": 13 + }, + "SO-56250-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-22", + "sku": "BRK", + "state": "open", + "units": 3 + }, + "SO-57231-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-19", + "sku": "CAP", + "state": "open", + "units": 25 + }, + "SO-57267-15": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "BRK", + "state": "open", + "units": 14 + }, + "SO-66099-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-17", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-71570-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "CAP", + "state": "open", + "units": 8 + }, + "SO-73572-5": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-23", + "sku": "CAP", + "state": "open", + "units": 22 + }, + "SO-77432-13": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-15", + "sku": "RNG", + "state": "shipped", + "units": 33 + }, + "SO-77917-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-22", + "sku": "CAP", + "state": "open", + "units": 10 + }, + "SO-96924-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-18", + "sku": "BRK", + "state": "open", + "units": 25 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-049/instruction.md b/tasks/autom-fulfillment-release-049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..03c973d982ba0a37175286cfc24ada7b0aa3826b --- /dev/null +++ b/tasks/autom-fulfillment-release-049/instruction.md @@ -0,0 +1,17 @@ +Release the overdue and due order queue at Albany as of 2025-06-24. 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 Albany. If the origin cannot cover the complete order, try Tampa 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-` 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 Albany, deduct confirmed inbound open units for that site/SKU with due date on or before 2025-07-01. Leave other inventory quantities out of this replenishment rule. For each positive remainder create procurement record `req-Albany-` 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. diff --git a/tasks/autom-fulfillment-release-049/solution/files/actions.jsonl b/tasks/autom-fulfillment-release-049/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..2922ac117b277edf7b1ee0f19b057daab7f5767c --- /dev/null +++ b/tasks/autom-fulfillment-release-049/solution/files/actions.jsonl @@ -0,0 +1,23 @@ +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-36339-0", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-66099-1", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-71570-2", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-96924-3", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-12394-4", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-73572-5", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-56250-6", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-77917-8", "op": "update"} +{"app": "orders", "fields": {"state": "backorder"}, "id": "SO-23614-9", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-34378-14", "op": "update"} +{"app": "orders", "fields": {"state": "allocated"}, "id": "SO-57267-15", "op": "update"} +{"app": "inventory", "fields": {"reserved": 23}, "id": "Albany-BRK", "op": "update"} +{"app": "inventory", "fields": {"reserved": 15}, "id": "Albany-CAP", "op": "update"} +{"app": "inventory", "fields": {"reserved": 32}, "id": "Tampa-CAP", "op": "update"} +{"app": "dispatch", "fields": {"order": "SO-36339-0", "site": "Albany", "sku": "BRK", "units": 1}, "id": "pick-SO-36339-0", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-77917-8", "site": "Albany", "sku": "CAP", "units": 10}, "id": "pick-SO-77917-8", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-34378-14", "site": "Tampa", "sku": "CAP", "units": 21}, "id": "pick-SO-34378-14", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-56250-6", "site": "Albany", "sku": "BRK", "units": 3}, "id": "pick-SO-56250-6", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-57267-15", "site": "Albany", "sku": "BRK", "units": 14}, "id": "pick-SO-57267-15", "op": "create"} +{"app": "dispatch", "fields": {"order": "SO-71570-2", "site": "Tampa", "sku": "CAP", "units": 8}, "id": "pick-SO-71570-2", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "RNG", "status": "draft", "units": 88}, "id": "req-Albany-RNG", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "BRK", "status": "draft", "units": 51}, "id": "req-Albany-BRK", "op": "create"} +{"app": "procurement", "fields": {"site": "Albany", "sku": "CAP", "status": "draft", "units": 22}, "id": "req-Albany-CAP", "op": "create"} diff --git a/tasks/autom-fulfillment-release-049/solution/solve.sh b/tasks/autom-fulfillment-release-049/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-fulfillment-release-049/task.toml b/tasks/autom-fulfillment-release-049/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9d899755c2f19df5386784d501e4a53b3a510048 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-fulfillment-release-049" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "operations"] +dataset = "Original simulated workflows" +job = "operations" +seed = 49 +source = "local/original-automation-workflows" +source_revision = "1" +source_split = "synthetic" +source_task_id = "autom-fulfillment-release-049" +template_family = "automation:fulfillment-release" +workflow_template = "fulfillment-release" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-fulfillment-release-049/tests/expected.json b/tasks/autom-fulfillment-release-049/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-049/tests/grade.py b/tasks/autom-fulfillment-release-049/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-fulfillment-release-049/tests/replay.py b/tasks/autom-fulfillment-release-049/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-fulfillment-release-049/tests/target.json b/tasks/autom-fulfillment-release-049/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..128c8ccbb442b921a764526cf12700a14bd54da2 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/target.json @@ -0,0 +1,336 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + }, + "pick-SO-34378-14": { + "order": "SO-34378-14", + "site": "Tampa", + "sku": "CAP", + "units": 21 + }, + "pick-SO-36339-0": { + "order": "SO-36339-0", + "site": "Albany", + "sku": "BRK", + "units": 1 + }, + "pick-SO-56250-6": { + "order": "SO-56250-6", + "site": "Albany", + "sku": "BRK", + "units": 3 + }, + "pick-SO-57267-15": { + "order": "SO-57267-15", + "site": "Albany", + "sku": "BRK", + "units": 14 + }, + "pick-SO-71570-2": { + "order": "SO-71570-2", + "site": "Tampa", + "sku": "CAP", + "units": 8 + }, + "pick-SO-77917-8": { + "order": "SO-77917-8", + "site": "Albany", + "sku": "CAP", + "units": 10 + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-06-29", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-06-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-06-27", + "open_units": 7, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-07-02", + "open_units": 7, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-07-04", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-07-01", + "open_units": 11, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-06-27", + "open_units": 1, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-05", + "open_units": 7, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-06-29", + "open_units": 1, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 31, + "reserved": 23, + "safety": 7, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 20, + "reserved": 15, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 3, + "safety": 8, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 41, + "reserved": 32, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-RNG": { + "on_hand": 19, + "reserved": 3, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 27, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "CAP" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11618-7": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "RNG", + "state": "open", + "units": 29 + }, + "SO-12394-4": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-20", + "sku": "RNG", + "state": "backorder", + "units": 23 + }, + "SO-23614-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-23", + "sku": "BRK", + "state": "backorder", + "units": 27 + }, + "SO-29649-16": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-30", + "sku": "RNG", + "state": "shipped", + "units": 27 + }, + "SO-34378-14": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-15", + "sku": "CAP", + "state": "allocated", + "units": 21 + }, + "SO-36339-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-21", + "sku": "BRK", + "state": "allocated", + "units": 1 + }, + "SO-40439-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-27", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-46288-12": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "BRK", + "state": "shipped", + "units": 13 + }, + "SO-56250-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-22", + "sku": "BRK", + "state": "allocated", + "units": 3 + }, + "SO-57231-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-19", + "sku": "CAP", + "state": "open", + "units": 25 + }, + "SO-57267-15": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "BRK", + "state": "allocated", + "units": 14 + }, + "SO-66099-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-17", + "sku": "RNG", + "state": "backorder", + "units": 65 + }, + "SO-71570-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "CAP", + "state": "allocated", + "units": 8 + }, + "SO-73572-5": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-23", + "sku": "CAP", + "state": "backorder", + "units": 22 + }, + "SO-77432-13": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-15", + "sku": "RNG", + "state": "shipped", + "units": 33 + }, + "SO-77917-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-22", + "sku": "CAP", + "state": "allocated", + "units": 10 + }, + "SO-96924-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-18", + "sku": "BRK", + "state": "backorder", + "units": 25 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + }, + "req-Albany-BRK": { + "site": "Albany", + "sku": "BRK", + "status": "draft", + "units": 51 + }, + "req-Albany-CAP": { + "site": "Albany", + "sku": "CAP", + "status": "draft", + "units": 22 + }, + "req-Albany-RNG": { + "site": "Albany", + "sku": "RNG", + "status": "draft", + "units": 88 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-049/tests/test.sh b/tasks/autom-fulfillment-release-049/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-fulfillment-release-049/tests/world.json b/tasks/autom-fulfillment-release-049/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..c1a114fc3aa731e8d0aaa73804b91ae738be0a6c --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/world.json @@ -0,0 +1,282 @@ +{ + "dispatch": { + "REL-OLD": { + "order": "archived", + "state": "shipped" + } + }, + "inbound": { + "PO-Albany-BRK": { + "due": "2025-06-29", + "open_units": 1, + "site": "Albany", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Albany-CAP": { + "due": "2025-06-28", + "open_units": 4, + "site": "Albany", + "sku": "CAP", + "status": "proposed" + }, + "PO-Albany-RNG": { + "due": "2025-06-27", + "open_units": 7, + "site": "Albany", + "sku": "RNG", + "status": "proposed" + }, + "PO-Tampa-BRK": { + "due": "2025-07-02", + "open_units": 7, + "site": "Tampa", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Tampa-CAP": { + "due": "2025-07-04", + "open_units": 1, + "site": "Tampa", + "sku": "CAP", + "status": "confirmed" + }, + "PO-Tampa-RNG": { + "due": "2025-07-01", + "open_units": 11, + "site": "Tampa", + "sku": "RNG", + "status": "confirmed" + }, + "PO-Waco-BRK": { + "due": "2025-06-27", + "open_units": 1, + "site": "Waco", + "sku": "BRK", + "status": "confirmed" + }, + "PO-Waco-CAP": { + "due": "2025-07-05", + "open_units": 7, + "site": "Waco", + "sku": "CAP", + "status": "proposed" + }, + "PO-Waco-RNG": { + "due": "2025-06-29", + "open_units": 1, + "site": "Waco", + "sku": "RNG", + "status": "proposed" + } + }, + "inventory": { + "Albany-BRK": { + "on_hand": 31, + "reserved": 5, + "safety": 7, + "site": "Albany", + "sku": "BRK" + }, + "Albany-CAP": { + "on_hand": 20, + "reserved": 5, + "safety": 4, + "site": "Albany", + "sku": "CAP" + }, + "Albany-RNG": { + "on_hand": 14, + "reserved": 2, + "safety": 7, + "site": "Albany", + "sku": "RNG" + }, + "Tampa-BRK": { + "on_hand": 28, + "reserved": 3, + "safety": 8, + "site": "Tampa", + "sku": "BRK" + }, + "Tampa-CAP": { + "on_hand": 41, + "reserved": 3, + "safety": 5, + "site": "Tampa", + "sku": "CAP" + }, + "Tampa-RNG": { + "on_hand": 19, + "reserved": 3, + "safety": 5, + "site": "Tampa", + "sku": "RNG" + }, + "Waco-BRK": { + "on_hand": 27, + "reserved": 2, + "safety": 7, + "site": "Waco", + "sku": "BRK" + }, + "Waco-CAP": { + "on_hand": 26, + "reserved": 1, + "safety": 6, + "site": "Waco", + "sku": "CAP" + }, + "Waco-RNG": { + "on_hand": 27, + "reserved": 4, + "safety": 8, + "site": "Waco", + "sku": "RNG" + } + }, + "orders": { + "SO-11618-7": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "RNG", + "state": "open", + "units": 29 + }, + "SO-12394-4": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-20", + "sku": "RNG", + "state": "open", + "units": 23 + }, + "SO-23614-9": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-23", + "sku": "BRK", + "state": "open", + "units": 27 + }, + "SO-29649-16": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-30", + "sku": "RNG", + "state": "shipped", + "units": 27 + }, + "SO-34378-14": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-15", + "sku": "CAP", + "state": "open", + "units": 21 + }, + "SO-36339-0": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-21", + "sku": "BRK", + "state": "open", + "units": 1 + }, + "SO-40439-10": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-27", + "sku": "RNG", + "state": "open", + "units": 3 + }, + "SO-46288-12": { + "origin": "Waco", + "priority": 1, + "promise": "2025-06-24", + "sku": "BRK", + "state": "shipped", + "units": 13 + }, + "SO-56250-6": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-22", + "sku": "BRK", + "state": "open", + "units": 3 + }, + "SO-57231-11": { + "origin": "Waco", + "priority": 2, + "promise": "2025-06-19", + "sku": "CAP", + "state": "open", + "units": 25 + }, + "SO-57267-15": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "BRK", + "state": "open", + "units": 14 + }, + "SO-66099-1": { + "origin": "Albany", + "priority": 2, + "promise": "2025-06-17", + "sku": "RNG", + "state": "open", + "units": 65 + }, + "SO-71570-2": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-21", + "sku": "CAP", + "state": "open", + "units": 8 + }, + "SO-73572-5": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-23", + "sku": "CAP", + "state": "open", + "units": 22 + }, + "SO-77432-13": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-15", + "sku": "RNG", + "state": "shipped", + "units": 33 + }, + "SO-77917-8": { + "origin": "Albany", + "priority": 1, + "promise": "2025-06-22", + "sku": "CAP", + "state": "open", + "units": 10 + }, + "SO-96924-3": { + "origin": "Albany", + "priority": 3, + "promise": "2025-06-18", + "sku": "BRK", + "state": "open", + "units": 25 + } + }, + "procurement": { + "REQ-OLD": { + "status": "approved", + "units": 50 + } + } +} \ No newline at end of file diff --git a/tasks/autom-fulfillment-release-049/tests/world_check.py b/tasks/autom-fulfillment-release-049/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-fulfillment-release-049/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-fulfillment-release-049/validation/openenv.json b/tasks/autom-fulfillment-release-049/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..ab7501c2c11e3e03b15316cf79a2bbe2b2bb5c84 --- /dev/null +++ b/tasks/autom-fulfillment-release-049/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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 +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/apps.py b/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/world.json b/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..e83b3ec9b48add7121f2a716d03b201500d25142 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/environment/inputs/world.json @@ -0,0 +1,247 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1212-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-25" + }, + "L-3637-7": { + "consent": false, + "email": "BUYER7@site7.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-28" + }, + "L-5291-11": { + "consent": false, + "email": "BUYER11@newgroup.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-15" + }, + "L-6794-6": { + "consent": true, + "email": "BUYER6@brand2.example", + "region": "Central", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-01-19" + }, + "L-6811-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-27" + }, + "L-7589-10": { + "consent": true, + "email": "BUYER10@site10.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-24" + }, + "L-7832-2": { + "consent": true, + "email": "BUYER2@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-23" + }, + "L-8086-12": { + "consent": false, + "email": "BUYER12@site12.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-28" + }, + "L-8417-0": { + "consent": true, + "email": "first@site0.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-25" + }, + "L-8450-5": { + "consent": true, + "email": "BUYER5@brand2.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-24" + }, + "L-8466-13": { + "consent": true, + "email": "BUYER13@site13.example", + "region": "Central", + "sector": "Retail", + "state": "closed", + "submitted": "2025-01-16" + }, + "L-8721-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-14" + }, + "L-8777-8": { + "consent": false, + "email": "BUYER8@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-20" + }, + "L-8896-3": { + "consent": true, + "email": "BUYER3@newgroup.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-26" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 1, + "capacity": 7, + "region": "Central", + "sectors": [ + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 0, + "capacity": 6, + "region": "Central", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-3": { + "active": true, + "assigned": 0, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "South", + "sectors": [ + "Retail", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 4, + "region": "South", + "sectors": [ + "Retail", + "Industrial" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-000-v2/instruction.md b/tasks/autom-inbound-lead-handoff-000-v2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..89acad1201c1536f127de771334da56571b0f0eb --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/instruction.md @@ -0,0 +1,19 @@ +Work the inbound sales desk for Central at 2025-01-28. Process new leads in that region submitted from 2025-01-21 through 2025-01-28, inclusive, in ascending submission date then lead ID. Domain matching uses the lowercased portion after @, with exact matches only. + +If consent is false or the domain appears in the privacy suppression list, set only lead state to `suppressed`. Otherwise search account domains. On an exact match route to its existing owner if active, even if outside the territory, without expertise, or at capacity. An inactive existing owner requires manual triage with reason `inactive_owner`. If no account matches, choose an active seller in-region covering the sector and below capacity, taking fewest currently assigned, then smallest seller ID. If nobody qualifies, triage with reason `no_capacity`. + +For manual triage set only lead state to `manual` and create sales_ops record `triage-` with `lead` and `reason`. For each assignment, increase the selected seller's running load by one when calculating the next lead's routing. Persist the final assigned count for each affected seller, set lead `state=assigned` and `owner`, and create outreach record `handoff-` with `lead`, `owner`, original-case `email` and `route` equal to `account` for an existing-account match or `territory` otherwise. Preserve all other fields and records. + +Calculate the plan in the stated queue order using all earlier decisions. Once calculated, you may apply the resulting changes in any order or combine updates to the same record. The action log is checked for the final business state and for any write to a protected record or field. + +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. diff --git a/tasks/autom-inbound-lead-handoff-000-v2/solution/files/actions.jsonl b/tasks/autom-inbound-lead-handoff-000-v2/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..27b37bb98aa3d4462a1a6b22df6071a05c6722c4 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/solution/files/actions.jsonl @@ -0,0 +1,17 @@ +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-1212-4", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-3637-7", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-6811-1", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-7589-10", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-7832-2", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-8086-12", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-3", "state": "assigned"}, "id": "L-8417-0", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-8450-5", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-8896-3", "op": "update"} +{"app": "outreach", "fields": {"email": "BUYER10@site10.example", "lead": "L-7589-10", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-7589-10", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER5@brand2.example", "lead": "L-8450-5", "owner": "AE-2", "route": "account"}, "id": "handoff-L-8450-5", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER4@brand2.example", "lead": "L-1212-4", "owner": "AE-2", "route": "account"}, "id": "handoff-L-1212-4", "op": "create"} +{"app": "outreach", "fields": {"email": "first@site0.example", "lead": "L-8417-0", "owner": "AE-3", "route": "territory"}, "id": "handoff-L-8417-0", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER3@newgroup.example", "lead": "L-8896-3", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-8896-3", "op": "create"} +{"app": "seller_roster", "fields": {"assigned": 2}, "id": "AE-0", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 2}, "id": "AE-2", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 1}, "id": "AE-3", "op": "update"} diff --git a/tasks/autom-inbound-lead-handoff-000-v2/solution/solve.sh b/tasks/autom-inbound-lead-handoff-000-v2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-inbound-lead-handoff-000-v2/task.toml b/tasks/autom-inbound-lead-handoff-000-v2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..04ab431a9b18e8acce2bf411e17da6f8c767361a --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-inbound-lead-handoff-000-v2" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "sales"] +dataset = "Original simulated workflows" +job = "sales" +seed = 0 +source = "local/original-automation-workflows" +source_revision = "2" +source_split = "synthetic" +source_task_id = "autom-inbound-lead-handoff-000" +template_family = "automation:inbound-lead-handoff" +workflow_template = "inbound-lead-handoff" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/expected.json b/tasks/autom-inbound-lead-handoff-000-v2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/grade.py b/tasks/autom-inbound-lead-handoff-000-v2/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/replay.py b/tasks/autom-inbound-lead-handoff-000-v2/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/target.json b/tasks/autom-inbound-lead-handoff-000-v2/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..791c3ef005d5d0185aa79442dab5f811bf34a08b --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/target.json @@ -0,0 +1,282 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1212-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "owner": "AE-2", + "region": "Central", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-01-25" + }, + "L-3637-7": { + "consent": false, + "email": "BUYER7@site7.example", + "region": "Central", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-01-28" + }, + "L-5291-11": { + "consent": false, + "email": "BUYER11@newgroup.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-15" + }, + "L-6794-6": { + "consent": true, + "email": "BUYER6@brand2.example", + "region": "Central", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-01-19" + }, + "L-6811-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "Central", + "sector": "Software", + "state": "suppressed", + "submitted": "2025-01-27" + }, + "L-7589-10": { + "consent": true, + "email": "BUYER10@site10.example", + "owner": "AE-0", + "region": "Central", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-01-24" + }, + "L-7832-2": { + "consent": true, + "email": "BUYER2@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Industrial", + "state": "suppressed", + "submitted": "2025-01-23" + }, + "L-8086-12": { + "consent": false, + "email": "BUYER12@site12.example", + "region": "Central", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-01-28" + }, + "L-8417-0": { + "consent": true, + "email": "first@site0.example", + "owner": "AE-3", + "region": "Central", + "sector": "Software", + "state": "assigned", + "submitted": "2025-01-25" + }, + "L-8450-5": { + "consent": true, + "email": "BUYER5@brand2.example", + "owner": "AE-2", + "region": "Central", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-01-24" + }, + "L-8466-13": { + "consent": true, + "email": "BUYER13@site13.example", + "region": "Central", + "sector": "Retail", + "state": "closed", + "submitted": "2025-01-16" + }, + "L-8721-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-14" + }, + "L-8777-8": { + "consent": false, + "email": "BUYER8@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-20" + }, + "L-8896-3": { + "consent": true, + "email": "BUYER3@newgroup.example", + "owner": "AE-0", + "region": "Central", + "sector": "Software", + "state": "assigned", + "submitted": "2025-01-26" + } + }, + "outreach": { + "existing": { + "status": "sent" + }, + "handoff-L-1212-4": { + "email": "BUYER4@brand2.example", + "lead": "L-1212-4", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-7589-10": { + "email": "BUYER10@site10.example", + "lead": "L-7589-10", + "owner": "AE-0", + "route": "territory" + }, + "handoff-L-8417-0": { + "email": "first@site0.example", + "lead": "L-8417-0", + "owner": "AE-3", + "route": "territory" + }, + "handoff-L-8450-5": { + "email": "BUYER5@brand2.example", + "lead": "L-8450-5", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-8896-3": { + "email": "BUYER3@newgroup.example", + "lead": "L-8896-3", + "owner": "AE-0", + "route": "territory" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 2, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 1, + "capacity": 7, + "region": "Central", + "sectors": [ + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 2, + "capacity": 6, + "region": "Central", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-3": { + "active": true, + "assigned": 1, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "South", + "sectors": [ + "Retail", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 4, + "region": "South", + "sectors": [ + "Retail", + "Industrial" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/test.sh b/tasks/autom-inbound-lead-handoff-000-v2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/world.json b/tasks/autom-inbound-lead-handoff-000-v2/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..e83b3ec9b48add7121f2a716d03b201500d25142 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/world.json @@ -0,0 +1,247 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1212-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-25" + }, + "L-3637-7": { + "consent": false, + "email": "BUYER7@site7.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-28" + }, + "L-5291-11": { + "consent": false, + "email": "BUYER11@newgroup.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-15" + }, + "L-6794-6": { + "consent": true, + "email": "BUYER6@brand2.example", + "region": "Central", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-01-19" + }, + "L-6811-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-27" + }, + "L-7589-10": { + "consent": true, + "email": "BUYER10@site10.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-24" + }, + "L-7832-2": { + "consent": true, + "email": "BUYER2@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-23" + }, + "L-8086-12": { + "consent": false, + "email": "BUYER12@site12.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-28" + }, + "L-8417-0": { + "consent": true, + "email": "first@site0.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-25" + }, + "L-8450-5": { + "consent": true, + "email": "BUYER5@brand2.example", + "region": "Central", + "sector": "Retail", + "state": "new", + "submitted": "2025-01-24" + }, + "L-8466-13": { + "consent": true, + "email": "BUYER13@site13.example", + "region": "Central", + "sector": "Retail", + "state": "closed", + "submitted": "2025-01-16" + }, + "L-8721-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-01-14" + }, + "L-8777-8": { + "consent": false, + "email": "BUYER8@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-20" + }, + "L-8896-3": { + "consent": true, + "email": "BUYER3@newgroup.example", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-01-26" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 1, + "capacity": 7, + "region": "Central", + "sectors": [ + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 0, + "capacity": 6, + "region": "Central", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-3": { + "active": true, + "assigned": 0, + "capacity": 7, + "region": "Central", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "South", + "sectors": [ + "Retail", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 4, + "region": "South", + "sectors": [ + "Retail", + "Industrial" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-000-v2/tests/world_check.py b/tasks/autom-inbound-lead-handoff-000-v2/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-inbound-lead-handoff-000-v2/validation/openenv.json b/tasks/autom-inbound-lead-handoff-000-v2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..cce52a23189bf8d6e4689400ae2af4a22fbdbfd6 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-000-v2/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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", + "sales" + ] + }, + "requires_credentials": false +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/apps.py b/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/world.json b/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..b3f444bec43a5723fcdb2f77f84eed45475306a8 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/environment/inputs/world.json @@ -0,0 +1,312 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1997-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-16" + }, + "L-2232-11": { + "consent": true, + "email": "BUYER11@company5.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-10" + }, + "L-2788-17": { + "consent": true, + "email": "BUYER17@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-21" + }, + "L-3239-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-20" + }, + "L-3967-14": { + "consent": true, + "email": "BUYER14@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-22" + }, + "L-4411-0": { + "consent": true, + "email": "first@site0.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-14" + }, + "L-4452-10": { + "consent": true, + "email": "BUYER10@site10.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-10" + }, + "L-5046-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-14" + }, + "L-5274-9": { + "consent": false, + "email": "BUYER9@site9.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-14" + }, + "L-5429-13": { + "consent": true, + "email": "BUYER13@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-15" + }, + "L-5446-15": { + "consent": true, + "email": "BUYER15@company5.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-05" + }, + "L-5547-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-16" + }, + "L-6608-12": { + "consent": true, + "email": "BUYER12@newgroup.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-22" + }, + "L-6724-2": { + "consent": false, + "email": "BUYER2@newgroup.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-18" + }, + "L-7072-6": { + "consent": true, + "email": "BUYER6@company5.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-17" + }, + "L-7597-8": { + "consent": true, + "email": "BUYER8@company5.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-07" + }, + "L-8158-18": { + "consent": true, + "email": "BUYER18@brand2.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-18" + }, + "L-8174-5": { + "consent": false, + "email": "BUYER5@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-18" + }, + "L-8653-16": { + "consent": true, + "email": "BUYER16@site16.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-21" + }, + "L-specialist-1": { + "consent": true, + "email": "intake1@new-energy.example", + "region": "East", + "sector": "Energy", + "state": "new", + "submitted": "2025-02-13" + }, + "L-specialist-2": { + "consent": true, + "email": "intake2@new-energy.example", + "region": "East", + "sector": "Energy", + "state": "new", + "submitted": "2025-02-13" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 0, + "capacity": 8, + "region": "East", + "sectors": [ + "Software", + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 5, + "capacity": 6, + "region": "East", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 2, + "capacity": 8, + "region": "North", + "sectors": [ + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-specialist": { + "active": true, + "assigned": 3, + "capacity": 4, + "region": "East", + "sectors": [ + "Energy" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-001-v2/instruction.md b/tasks/autom-inbound-lead-handoff-001-v2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6378969da59f82ef54517f75648ddcd60afe27f6 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/instruction.md @@ -0,0 +1,19 @@ +Work the inbound sales desk for East at 2025-02-20. Process new leads in that region submitted from 2025-02-13 through 2025-02-20, inclusive, in ascending submission date then lead ID. Domain matching uses the lowercased portion after @, with exact matches only. + +If consent is false or the domain appears in the privacy suppression list, set only lead state to `suppressed`. Otherwise search account domains. On an exact match route to its existing owner if active, even if outside the territory, without expertise, or at capacity. An inactive existing owner requires manual triage with reason `inactive_owner`. If no account matches, choose an active seller in-region covering the sector and below capacity, taking fewest currently assigned, then smallest seller ID. If nobody qualifies, triage with reason `no_capacity`. + +For manual triage set only lead state to `manual` and create sales_ops record `triage-` with `lead` and `reason`. For each assignment, increase the selected seller's running load by one when calculating the next lead's routing. Persist the final assigned count for each affected seller, set lead `state=assigned` and `owner`, and create outreach record `handoff-` with `lead`, `owner`, original-case `email` and `route` equal to `account` for an existing-account match or `territory` otherwise. Preserve all other fields and records. + +Calculate the plan in the stated queue order using all earlier decisions. Once calculated, you may apply the resulting changes in any order or combine updates to the same record. The action log is checked for the final business state and for any write to a protected record or field. + +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. diff --git a/tasks/autom-inbound-lead-handoff-001-v2/solution/files/actions.jsonl b/tasks/autom-inbound-lead-handoff-001-v2/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..7459078db5bb1723a98d196edb6e3075926c7714 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/solution/files/actions.jsonl @@ -0,0 +1,24 @@ +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-1997-1", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-3239-4", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-4411-0", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-5046-3", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-5274-9", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-5429-13", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-5547-7", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-6724-2", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-7072-6", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-8158-18", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-8174-5", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-specialist", "state": "assigned"}, "id": "L-specialist-1", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-specialist-2", "op": "update"} +{"app": "outreach", "fields": {"email": "intake1@new-energy.example", "lead": "L-specialist-1", "owner": "AE-specialist", "route": "territory"}, "id": "handoff-L-specialist-1", "op": "create"} +{"app": "outreach", "fields": {"email": "first@site0.example", "lead": "L-4411-0", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-4411-0", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER3@brand2.example", "lead": "L-5046-3", "owner": "AE-2", "route": "account"}, "id": "handoff-L-5046-3", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER18@brand2.example", "lead": "L-8158-18", "owner": "AE-2", "route": "account"}, "id": "handoff-L-8158-18", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER4@brand2.example", "lead": "L-3239-4", "owner": "AE-2", "route": "account"}, "id": "handoff-L-3239-4", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-specialist-2", "reason": "no_capacity"}, "id": "triage-L-specialist-2", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-5547-7", "reason": "inactive_owner"}, "id": "triage-L-5547-7", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-7072-6", "reason": "inactive_owner"}, "id": "triage-L-7072-6", "op": "create"} +{"app": "seller_roster", "fields": {"assigned": 1}, "id": "AE-0", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 8}, "id": "AE-2", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 4}, "id": "AE-specialist", "op": "update"} diff --git a/tasks/autom-inbound-lead-handoff-001-v2/solution/solve.sh b/tasks/autom-inbound-lead-handoff-001-v2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-inbound-lead-handoff-001-v2/task.toml b/tasks/autom-inbound-lead-handoff-001-v2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eca376945253f60e829b07fad607df663726618b --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-inbound-lead-handoff-001-v2" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "sales"] +dataset = "Original simulated workflows" +job = "sales" +seed = 1 +source = "local/original-automation-workflows" +source_revision = "2" +source_split = "synthetic" +source_task_id = "autom-inbound-lead-handoff-001" +template_family = "automation:inbound-lead-handoff" +workflow_template = "inbound-lead-handoff" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/expected.json b/tasks/autom-inbound-lead-handoff-001-v2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/grade.py b/tasks/autom-inbound-lead-handoff-001-v2/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/replay.py b/tasks/autom-inbound-lead-handoff-001-v2/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/target.json b/tasks/autom-inbound-lead-handoff-001-v2/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..6702e67db3bf0b4bc8471197c2d1a5631a554374 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/target.json @@ -0,0 +1,359 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1997-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "East", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-02-16" + }, + "L-2232-11": { + "consent": true, + "email": "BUYER11@company5.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-10" + }, + "L-2788-17": { + "consent": true, + "email": "BUYER17@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-21" + }, + "L-3239-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "owner": "AE-2", + "region": "East", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-02-20" + }, + "L-3967-14": { + "consent": true, + "email": "BUYER14@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-22" + }, + "L-4411-0": { + "consent": true, + "email": "first@site0.example", + "owner": "AE-0", + "region": "East", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-02-14" + }, + "L-4452-10": { + "consent": true, + "email": "BUYER10@site10.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-10" + }, + "L-5046-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "owner": "AE-2", + "region": "East", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-02-14" + }, + "L-5274-9": { + "consent": false, + "email": "BUYER9@site9.example", + "region": "East", + "sector": "Software", + "state": "suppressed", + "submitted": "2025-02-14" + }, + "L-5429-13": { + "consent": true, + "email": "BUYER13@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "suppressed", + "submitted": "2025-02-15" + }, + "L-5446-15": { + "consent": true, + "email": "BUYER15@company5.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-05" + }, + "L-5547-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "East", + "sector": "Software", + "state": "manual", + "submitted": "2025-02-16" + }, + "L-6608-12": { + "consent": true, + "email": "BUYER12@newgroup.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-22" + }, + "L-6724-2": { + "consent": false, + "email": "BUYER2@newgroup.example", + "region": "East", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-02-18" + }, + "L-7072-6": { + "consent": true, + "email": "BUYER6@company5.example", + "region": "East", + "sector": "Industrial", + "state": "manual", + "submitted": "2025-02-17" + }, + "L-7597-8": { + "consent": true, + "email": "BUYER8@company5.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-07" + }, + "L-8158-18": { + "consent": true, + "email": "BUYER18@brand2.example", + "owner": "AE-2", + "region": "East", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-02-18" + }, + "L-8174-5": { + "consent": false, + "email": "BUYER5@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "suppressed", + "submitted": "2025-02-18" + }, + "L-8653-16": { + "consent": true, + "email": "BUYER16@site16.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-21" + }, + "L-specialist-1": { + "consent": true, + "email": "intake1@new-energy.example", + "owner": "AE-specialist", + "region": "East", + "sector": "Energy", + "state": "assigned", + "submitted": "2025-02-13" + }, + "L-specialist-2": { + "consent": true, + "email": "intake2@new-energy.example", + "region": "East", + "sector": "Energy", + "state": "manual", + "submitted": "2025-02-13" + } + }, + "outreach": { + "existing": { + "status": "sent" + }, + "handoff-L-3239-4": { + "email": "BUYER4@brand2.example", + "lead": "L-3239-4", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-4411-0": { + "email": "first@site0.example", + "lead": "L-4411-0", + "owner": "AE-0", + "route": "territory" + }, + "handoff-L-5046-3": { + "email": "BUYER3@brand2.example", + "lead": "L-5046-3", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-8158-18": { + "email": "BUYER18@brand2.example", + "lead": "L-8158-18", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-specialist-1": { + "email": "intake1@new-energy.example", + "lead": "L-specialist-1", + "owner": "AE-specialist", + "route": "territory" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + }, + "triage-L-5547-7": { + "lead": "L-5547-7", + "reason": "inactive_owner" + }, + "triage-L-7072-6": { + "lead": "L-7072-6", + "reason": "inactive_owner" + }, + "triage-L-specialist-2": { + "lead": "L-specialist-2", + "reason": "no_capacity" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 1, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 0, + "capacity": 8, + "region": "East", + "sectors": [ + "Software", + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 8, + "capacity": 6, + "region": "East", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 2, + "capacity": 8, + "region": "North", + "sectors": [ + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-specialist": { + "active": true, + "assigned": 4, + "capacity": 4, + "region": "East", + "sectors": [ + "Energy" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/test.sh b/tasks/autom-inbound-lead-handoff-001-v2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/world.json b/tasks/autom-inbound-lead-handoff-001-v2/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..b3f444bec43a5723fcdb2f77f84eed45475306a8 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/world.json @@ -0,0 +1,312 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1997-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-16" + }, + "L-2232-11": { + "consent": true, + "email": "BUYER11@company5.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-10" + }, + "L-2788-17": { + "consent": true, + "email": "BUYER17@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-21" + }, + "L-3239-4": { + "consent": true, + "email": "BUYER4@brand2.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-20" + }, + "L-3967-14": { + "consent": true, + "email": "BUYER14@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-22" + }, + "L-4411-0": { + "consent": true, + "email": "first@site0.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-14" + }, + "L-4452-10": { + "consent": true, + "email": "BUYER10@site10.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-10" + }, + "L-5046-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-14" + }, + "L-5274-9": { + "consent": false, + "email": "BUYER9@site9.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-14" + }, + "L-5429-13": { + "consent": true, + "email": "BUYER13@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-15" + }, + "L-5446-15": { + "consent": true, + "email": "BUYER15@company5.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-05" + }, + "L-5547-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-16" + }, + "L-6608-12": { + "consent": true, + "email": "BUYER12@newgroup.example", + "region": "East", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-02-22" + }, + "L-6724-2": { + "consent": false, + "email": "BUYER2@newgroup.example", + "region": "East", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-18" + }, + "L-7072-6": { + "consent": true, + "email": "BUYER6@company5.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-17" + }, + "L-7597-8": { + "consent": true, + "email": "BUYER8@company5.example", + "region": "East", + "sector": "Software", + "state": "new", + "submitted": "2025-02-07" + }, + "L-8158-18": { + "consent": true, + "email": "BUYER18@brand2.example", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-18" + }, + "L-8174-5": { + "consent": false, + "email": "BUYER5@RESTRICTED.EXAMPLE", + "region": "East", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-18" + }, + "L-8653-16": { + "consent": true, + "email": "BUYER16@site16.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-02-21" + }, + "L-specialist-1": { + "consent": true, + "email": "intake1@new-energy.example", + "region": "East", + "sector": "Energy", + "state": "new", + "submitted": "2025-02-13" + }, + "L-specialist-2": { + "consent": true, + "email": "intake2@new-energy.example", + "region": "East", + "sector": "Energy", + "state": "new", + "submitted": "2025-02-13" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 0, + "capacity": 8, + "region": "East", + "sectors": [ + "Software", + "Retail" + ] + }, + "AE-2": { + "active": true, + "assigned": 5, + "capacity": 6, + "region": "East", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "East", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 2, + "capacity": 8, + "region": "North", + "sectors": [ + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-specialist": { + "active": true, + "assigned": 3, + "capacity": 4, + "region": "East", + "sectors": [ + "Energy" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-001-v2/tests/world_check.py b/tasks/autom-inbound-lead-handoff-001-v2/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-inbound-lead-handoff-001-v2/validation/openenv.json b/tasks/autom-inbound-lead-handoff-001-v2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..cce52a23189bf8d6e4689400ae2af4a22fbdbfd6 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-001-v2/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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", + "sales" + ] + }, + "requires_credentials": false +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/apps.py b/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/world.json b/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..a05bab30a9e9cd5abf30050ecc3ce013eb0bcd81 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/environment/inputs/world.json @@ -0,0 +1,256 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1280-6": { + "consent": true, + "email": "BUYER6@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-28" + }, + "L-1867-11": { + "consent": true, + "email": "BUYER11@newgroup.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-04" + }, + "L-3390-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-13" + }, + "L-4191-4": { + "consent": true, + "email": "BUYER4@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-14" + }, + "L-4744-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-07" + }, + "L-5551-5": { + "consent": true, + "email": "BUYER5@site5.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-10" + }, + "L-6123-14": { + "consent": false, + "email": "BUYER14@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-03" + }, + "L-6362-12": { + "consent": true, + "email": "BUYER12@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-17" + }, + "L-6659-0": { + "consent": true, + "email": "first@site0.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-14" + }, + "L-7041-8": { + "consent": false, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "closed", + "submitted": "2025-03-05" + }, + "L-8008-10": { + "consent": true, + "email": "BUYER10@company5.example", + "region": "West", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-02" + }, + "L-8850-2": { + "consent": true, + "email": "BUYER2@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-13" + }, + "L-8995-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-11" + }, + "L-9396-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-11" + }, + "L-9894-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-10" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-2": { + "active": true, + "assigned": 4, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 0, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "West", + "sectors": [ + "Software", + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-002-v2/instruction.md b/tasks/autom-inbound-lead-handoff-002-v2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3db6d9c12e5d706bc6800bfde45c3b0b3ddf51dd --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/instruction.md @@ -0,0 +1,19 @@ +Work the inbound sales desk for North at 2025-03-15. Process new leads in that region submitted from 2025-03-08 through 2025-03-15, inclusive, in ascending submission date then lead ID. Domain matching uses the lowercased portion after @, with exact matches only. + +If consent is false or the domain appears in the privacy suppression list, set only lead state to `suppressed`. Otherwise search account domains. On an exact match route to its existing owner if active, even if outside the territory, without expertise, or at capacity. An inactive existing owner requires manual triage with reason `inactive_owner`. If no account matches, choose an active seller in-region covering the sector and below capacity, taking fewest currently assigned, then smallest seller ID. If nobody qualifies, triage with reason `no_capacity`. + +For manual triage set only lead state to `manual` and create sales_ops record `triage-` with `lead` and `reason`. For each assignment, increase the selected seller's running load by one when calculating the next lead's routing. Persist the final assigned count for each affected seller, set lead `state=assigned` and `owner`, and create outreach record `handoff-` with `lead`, `owner`, original-case `email` and `route` equal to `account` for an existing-account match or `territory` otherwise. Preserve all other fields and records. + +Calculate the plan in the stated queue order using all earlier decisions. Once calculated, you may apply the resulting changes in any order or combine updates to the same record. The action log is checked for the final business state and for any write to a protected record or field. + +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. diff --git a/tasks/autom-inbound-lead-handoff-002-v2/solution/files/actions.jsonl b/tasks/autom-inbound-lead-handoff-002-v2/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..63c5144daf9ccef0dd5d06e85092d3dfc53f19a8 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/solution/files/actions.jsonl @@ -0,0 +1,19 @@ +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-3390-1", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-3", "state": "assigned"}, "id": "L-4191-4", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-5551-5", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-1", "state": "assigned"}, "id": "L-6659-0", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-8850-2", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-8995-3", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-9396-13", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-9894-9", "op": "update"} +{"app": "outreach", "fields": {"email": "BUYER5@site5.example", "lead": "L-5551-5", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-5551-5", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER9@site9.example", "lead": "L-9894-9", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-9894-9", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER3@brand2.example", "lead": "L-8995-3", "owner": "AE-2", "route": "account"}, "id": "handoff-L-8995-3", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER4@newgroup.example", "lead": "L-4191-4", "owner": "AE-3", "route": "territory"}, "id": "handoff-L-4191-4", "op": "create"} +{"app": "outreach", "fields": {"email": "first@site0.example", "lead": "L-6659-0", "owner": "AE-1", "route": "territory"}, "id": "handoff-L-6659-0", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-9396-13", "reason": "inactive_owner"}, "id": "triage-L-9396-13", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-8850-2", "reason": "inactive_owner"}, "id": "triage-L-8850-2", "op": "create"} +{"app": "seller_roster", "fields": {"assigned": 2}, "id": "AE-0", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 2}, "id": "AE-1", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 5}, "id": "AE-2", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 1}, "id": "AE-3", "op": "update"} diff --git a/tasks/autom-inbound-lead-handoff-002-v2/solution/solve.sh b/tasks/autom-inbound-lead-handoff-002-v2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-inbound-lead-handoff-002-v2/task.toml b/tasks/autom-inbound-lead-handoff-002-v2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f6b742dc3767060448bc95a7da26ca4d3d3e484f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-inbound-lead-handoff-002-v2" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "sales"] +dataset = "Original simulated workflows" +job = "sales" +seed = 2 +source = "local/original-automation-workflows" +source_revision = "2" +source_split = "synthetic" +source_task_id = "autom-inbound-lead-handoff-002" +template_family = "automation:inbound-lead-handoff" +workflow_template = "inbound-lead-handoff" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/expected.json b/tasks/autom-inbound-lead-handoff-002-v2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/grade.py b/tasks/autom-inbound-lead-handoff-002-v2/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/replay.py b/tasks/autom-inbound-lead-handoff-002-v2/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/target.json b/tasks/autom-inbound-lead-handoff-002-v2/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..001edfb55c0e22d4b8468f8ecfffa274f2ce4448 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/target.json @@ -0,0 +1,299 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1280-6": { + "consent": true, + "email": "BUYER6@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-28" + }, + "L-1867-11": { + "consent": true, + "email": "BUYER11@newgroup.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-04" + }, + "L-3390-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Industrial", + "state": "suppressed", + "submitted": "2025-03-13" + }, + "L-4191-4": { + "consent": true, + "email": "BUYER4@newgroup.example", + "owner": "AE-3", + "region": "North", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-03-14" + }, + "L-4744-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-07" + }, + "L-5551-5": { + "consent": true, + "email": "BUYER5@site5.example", + "owner": "AE-0", + "region": "North", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-03-10" + }, + "L-6123-14": { + "consent": false, + "email": "BUYER14@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-03" + }, + "L-6362-12": { + "consent": true, + "email": "BUYER12@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-17" + }, + "L-6659-0": { + "consent": true, + "email": "first@site0.example", + "owner": "AE-1", + "region": "North", + "sector": "Software", + "state": "assigned", + "submitted": "2025-03-14" + }, + "L-7041-8": { + "consent": false, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "closed", + "submitted": "2025-03-05" + }, + "L-8008-10": { + "consent": true, + "email": "BUYER10@company5.example", + "region": "West", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-02" + }, + "L-8850-2": { + "consent": true, + "email": "BUYER2@company5.example", + "region": "North", + "sector": "Industrial", + "state": "manual", + "submitted": "2025-03-13" + }, + "L-8995-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "owner": "AE-2", + "region": "North", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-03-11" + }, + "L-9396-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Industrial", + "state": "manual", + "submitted": "2025-03-11" + }, + "L-9894-9": { + "consent": true, + "email": "BUYER9@site9.example", + "owner": "AE-0", + "region": "North", + "sector": "Software", + "state": "assigned", + "submitted": "2025-03-10" + } + }, + "outreach": { + "existing": { + "status": "sent" + }, + "handoff-L-4191-4": { + "email": "BUYER4@newgroup.example", + "lead": "L-4191-4", + "owner": "AE-3", + "route": "territory" + }, + "handoff-L-5551-5": { + "email": "BUYER5@site5.example", + "lead": "L-5551-5", + "owner": "AE-0", + "route": "territory" + }, + "handoff-L-6659-0": { + "email": "first@site0.example", + "lead": "L-6659-0", + "owner": "AE-1", + "route": "territory" + }, + "handoff-L-8995-3": { + "email": "BUYER3@brand2.example", + "lead": "L-8995-3", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-9894-9": { + "email": "BUYER9@site9.example", + "lead": "L-9894-9", + "owner": "AE-0", + "route": "territory" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + }, + "triage-L-8850-2": { + "lead": "L-8850-2", + "reason": "inactive_owner" + }, + "triage-L-9396-13": { + "lead": "L-9396-13", + "reason": "inactive_owner" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 2, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 2, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-2": { + "active": true, + "assigned": 5, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 1, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "West", + "sectors": [ + "Software", + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/test.sh b/tasks/autom-inbound-lead-handoff-002-v2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/world.json b/tasks/autom-inbound-lead-handoff-002-v2/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..a05bab30a9e9cd5abf30050ecc3ce013eb0bcd81 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/world.json @@ -0,0 +1,256 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1280-6": { + "consent": true, + "email": "BUYER6@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-02-28" + }, + "L-1867-11": { + "consent": true, + "email": "BUYER11@newgroup.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-04" + }, + "L-3390-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-13" + }, + "L-4191-4": { + "consent": true, + "email": "BUYER4@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-14" + }, + "L-4744-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-07" + }, + "L-5551-5": { + "consent": true, + "email": "BUYER5@site5.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-10" + }, + "L-6123-14": { + "consent": false, + "email": "BUYER14@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-03" + }, + "L-6362-12": { + "consent": true, + "email": "BUYER12@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-17" + }, + "L-6659-0": { + "consent": true, + "email": "first@site0.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-14" + }, + "L-7041-8": { + "consent": false, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "closed", + "submitted": "2025-03-05" + }, + "L-8008-10": { + "consent": true, + "email": "BUYER10@company5.example", + "region": "West", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-02" + }, + "L-8850-2": { + "consent": true, + "email": "BUYER2@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-13" + }, + "L-8995-3": { + "consent": true, + "email": "BUYER3@brand2.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-11" + }, + "L-9396-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-03-11" + }, + "L-9894-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-03-10" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-2": { + "active": true, + "assigned": 4, + "capacity": 6, + "region": "North", + "sectors": [ + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 0, + "capacity": 5, + "region": "North", + "sectors": [ + "Industrial", + "Retail" + ] + }, + "AE-4": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "West", + "sectors": [ + "Software", + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-002-v2/tests/world_check.py b/tasks/autom-inbound-lead-handoff-002-v2/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-inbound-lead-handoff-002-v2/validation/openenv.json b/tasks/autom-inbound-lead-handoff-002-v2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..cce52a23189bf8d6e4689400ae2af4a22fbdbfd6 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-002-v2/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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", + "sales" + ] + }, + "requires_credentials": false +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/apps.py b/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/world.json b/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..a4046b50430c4177a947d57717c473004ad5de0c --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/environment/inputs/world.json @@ -0,0 +1,290 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1121-7": { + "consent": true, + "email": "BUYER7@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-30" + }, + "L-1391-17": { + "consent": false, + "email": "BUYER17@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-01" + }, + "L-1985-2": { + "consent": false, + "email": "BUYER2@site2.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-2914-5": { + "consent": false, + "email": "BUYER5@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-06" + }, + "L-3438-12": { + "consent": true, + "email": "BUYER12@brand2.example", + "region": "West", + "sector": "Software", + "state": "new", + "submitted": "2025-03-30" + }, + "L-3783-3": { + "consent": true, + "email": "BUYER3@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-3902-18": { + "consent": false, + "email": "BUYER18@company5.example", + "region": "North", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-26" + }, + "L-4298-6": { + "consent": false, + "email": "BUYER6@brand2.example", + "region": "North", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-02" + }, + "L-4611-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-07" + }, + "L-4618-0": { + "consent": true, + "email": "first@site0.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-07" + }, + "L-4897-4": { + "consent": true, + "email": "BUYER4@site4.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-05" + }, + "L-6096-10": { + "consent": true, + "email": "BUYER10@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-31" + }, + "L-6330-11": { + "consent": true, + "email": "BUYER11@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-7502-16": { + "consent": true, + "email": "BUYER16@brand2.example", + "region": "West", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-08" + }, + "L-7782-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-7842-14": { + "consent": true, + "email": "BUYER14@site14.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-8510-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-07" + }, + "L-8897-8": { + "consent": true, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-05" + }, + "L-9310-15": { + "consent": false, + "email": "BUYER15@site15.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-01" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 4, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 5, + "capacity": 4, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-2": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-3": { + "active": true, + "assigned": 4, + "capacity": 7, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "West", + "sectors": [ + "Retail" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-003-v2/instruction.md b/tasks/autom-inbound-lead-handoff-003-v2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..678274c313fd290219c2ae654da52ed5b7174ad9 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/instruction.md @@ -0,0 +1,19 @@ +Work the inbound sales desk for North at 2025-04-07. Process new leads in that region submitted from 2025-03-31 through 2025-04-07, inclusive, in ascending submission date then lead ID. Domain matching uses the lowercased portion after @, with exact matches only. + +If consent is false or the domain appears in the privacy suppression list, set only lead state to `suppressed`. Otherwise search account domains. On an exact match route to its existing owner if active, even if outside the territory, without expertise, or at capacity. An inactive existing owner requires manual triage with reason `inactive_owner`. If no account matches, choose an active seller in-region covering the sector and below capacity, taking fewest currently assigned, then smallest seller ID. If nobody qualifies, triage with reason `no_capacity`. + +For manual triage set only lead state to `manual` and create sales_ops record `triage-` with `lead` and `reason`. For each assignment, increase the selected seller's running load by one when calculating the next lead's routing. Persist the final assigned count for each affected seller, set lead `state=assigned` and `owner`, and create outreach record `handoff-` with `lead`, `owner`, original-case `email` and `route` equal to `account` for an existing-account match or `territory` otherwise. Preserve all other fields and records. + +Calculate the plan in the stated queue order using all earlier decisions. Once calculated, you may apply the resulting changes in any order or combine updates to the same record. The action log is checked for the final business state and for any write to a protected record or field. + +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. diff --git a/tasks/autom-inbound-lead-handoff-003-v2/solution/files/actions.jsonl b/tasks/autom-inbound-lead-handoff-003-v2/solution/files/actions.jsonl new file mode 100644 index 0000000000000000000000000000000000000000..dbc38f28cf93b2d54d3a73b16c5146c196b09adc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/solution/files/actions.jsonl @@ -0,0 +1,19 @@ +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-1391-17", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-1985-2", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-2914-5", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-3783-3", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-4611-1", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-4618-0", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-4897-4", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-2", "state": "assigned"}, "id": "L-6096-10", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "manual"}, "id": "L-7782-13", "op": "update"} +{"app": "inbound_leads", "fields": {"owner": "AE-0", "state": "assigned"}, "id": "L-8510-9", "op": "update"} +{"app": "inbound_leads", "fields": {"state": "suppressed"}, "id": "L-9310-15", "op": "update"} +{"app": "outreach", "fields": {"email": "BUYER10@brand2.example", "lead": "L-6096-10", "owner": "AE-2", "route": "account"}, "id": "handoff-L-6096-10", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER4@site4.example", "lead": "L-4897-4", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-4897-4", "op": "create"} +{"app": "outreach", "fields": {"email": "first@site0.example", "lead": "L-4618-0", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-4618-0", "op": "create"} +{"app": "outreach", "fields": {"email": "BUYER9@site9.example", "lead": "L-8510-9", "owner": "AE-0", "route": "territory"}, "id": "handoff-L-8510-9", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-3783-3", "reason": "inactive_owner"}, "id": "triage-L-3783-3", "op": "create"} +{"app": "sales_ops", "fields": {"lead": "L-7782-13", "reason": "inactive_owner"}, "id": "triage-L-7782-13", "op": "create"} +{"app": "seller_roster", "fields": {"assigned": 3}, "id": "AE-0", "op": "update"} +{"app": "seller_roster", "fields": {"assigned": 2}, "id": "AE-2", "op": "update"} diff --git a/tasks/autom-inbound-lead-handoff-003-v2/solution/solve.sh b/tasks/autom-inbound-lead-handoff-003-v2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2a287da2db131d4ef042f5a6c2d1c3bed03acf0 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /workspace/outputs +cp -R /solution/files/. /workspace/outputs/ diff --git a/tasks/autom-inbound-lead-handoff-003-v2/task.toml b/tasks/autom-inbound-lead-handoff-003-v2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b2be32d117df2d2bb24f6b40249c0bd36b48099f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/task.toml @@ -0,0 +1,46 @@ +schema_version = "1.3" + +[task] +name = "apex-gap/autom-inbound-lead-handoff-003-v2" + +[metadata.apex_gap] +capability_tags = ["cross-app-workflows", "conditional-execution", "protected-state", "sales"] +dataset = "Original simulated workflows" +job = "sales" +seed = 3 +source = "local/original-automation-workflows" +source_revision = "2" +source_split = "synthetic" +source_task_id = "autom-inbound-lead-handoff-003" +template_family = "automation:inbound-lead-handoff" +workflow_template = "inbound-lead-handoff" + +[metadata.openenv_hf_sandbox] +variant = "apex-gap-hfsandbox-v1" +task_modified_for_hf_sandbox = true +network_enabled = true + +[environment] +docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf" +workdir = "/workspace" +cpus = 1 +memory_mb = 4096 +build_timeout_sec = 600 +network_mode = "public" + +[agent] +timeout_sec = 1800 +network_mode = "public" + +[verifier] +timeout_sec = 600 +network_mode = "public" +environment_mode = "separate" + +[verifier.environment] +network_mode = "public" +cpus = 1 +memory_mb = 4096 + +[[artifacts]] +source = "/workspace/outputs" diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/expected.json b/tasks/autom-inbound-lead-handoff-003-v2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..404f50550b5d272df3418f73b71a3814579ffa30 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/expected.json @@ -0,0 +1,9 @@ +{ + "checks": [ + { + "id": "business-outcomes", + "type": "custom", + "module": "world_check" + } + ] +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/grade.py b/tasks/autom-inbound-lead-handoff-003-v2/tests/grade.py new file mode 100644 index 0000000000000000000000000000000000000000..037f80a598ed5029d076841c21fa3c475432155e --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/grade.py @@ -0,0 +1,330 @@ +"""Deterministic grader shared by converted knowledge-work tasks. + +Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the +submitted /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/ vs tests/ over sheet!range (SpreadsheetBench rules) + xlsx_cell recalculated outputs/ sheet!cell vs value with tolerance (optional alt_values) + file_contains outputs/ text (docx/pdf/ics/eml/txt) must contain every needle + custom tests/.py defines check(spec, outputs_dir, tests_dir) -> (bool, str) +""" + +import datetime as dt +import json +import re +import shutil +import subprocess +import sys +import tempfile +import unicodedata +from 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 = """ + +0 +0 + +""" + + +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()) diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/replay.py b/tasks/autom-inbound-lead-handoff-003-v2/tests/replay.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/replay.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/target.json b/tasks/autom-inbound-lead-handoff-003-v2/tests/target.json new file mode 100644 index 0000000000000000000000000000000000000000..3bd84e6344755c7924cc13ee6f530c4ba775d1b9 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/target.json @@ -0,0 +1,326 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1121-7": { + "consent": true, + "email": "BUYER7@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-30" + }, + "L-1391-17": { + "consent": false, + "email": "BUYER17@brand2.example", + "region": "North", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-04-01" + }, + "L-1985-2": { + "consent": false, + "email": "BUYER2@site2.example", + "region": "North", + "sector": "Software", + "state": "suppressed", + "submitted": "2025-04-04" + }, + "L-2914-5": { + "consent": false, + "email": "BUYER5@company5.example", + "region": "North", + "sector": "Software", + "state": "suppressed", + "submitted": "2025-04-06" + }, + "L-3438-12": { + "consent": true, + "email": "BUYER12@brand2.example", + "region": "West", + "sector": "Software", + "state": "new", + "submitted": "2025-03-30" + }, + "L-3783-3": { + "consent": true, + "email": "BUYER3@company5.example", + "region": "North", + "sector": "Software", + "state": "manual", + "submitted": "2025-04-04" + }, + "L-3902-18": { + "consent": false, + "email": "BUYER18@company5.example", + "region": "North", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-26" + }, + "L-4298-6": { + "consent": false, + "email": "BUYER6@brand2.example", + "region": "North", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-02" + }, + "L-4611-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Retail", + "state": "suppressed", + "submitted": "2025-04-07" + }, + "L-4618-0": { + "consent": true, + "email": "first@site0.example", + "owner": "AE-0", + "region": "North", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-04-07" + }, + "L-4897-4": { + "consent": true, + "email": "BUYER4@site4.example", + "owner": "AE-0", + "region": "North", + "sector": "Industrial", + "state": "assigned", + "submitted": "2025-04-05" + }, + "L-6096-10": { + "consent": true, + "email": "BUYER10@brand2.example", + "owner": "AE-2", + "region": "North", + "sector": "Retail", + "state": "assigned", + "submitted": "2025-03-31" + }, + "L-6330-11": { + "consent": true, + "email": "BUYER11@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-7502-16": { + "consent": true, + "email": "BUYER16@brand2.example", + "region": "West", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-08" + }, + "L-7782-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Software", + "state": "manual", + "submitted": "2025-04-04" + }, + "L-7842-14": { + "consent": true, + "email": "BUYER14@site14.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-8510-9": { + "consent": true, + "email": "BUYER9@site9.example", + "owner": "AE-0", + "region": "North", + "sector": "Software", + "state": "assigned", + "submitted": "2025-04-07" + }, + "L-8897-8": { + "consent": true, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-05" + }, + "L-9310-15": { + "consent": false, + "email": "BUYER15@site15.example", + "region": "North", + "sector": "Software", + "state": "suppressed", + "submitted": "2025-04-01" + } + }, + "outreach": { + "existing": { + "status": "sent" + }, + "handoff-L-4618-0": { + "email": "first@site0.example", + "lead": "L-4618-0", + "owner": "AE-0", + "route": "territory" + }, + "handoff-L-4897-4": { + "email": "BUYER4@site4.example", + "lead": "L-4897-4", + "owner": "AE-0", + "route": "territory" + }, + "handoff-L-6096-10": { + "email": "BUYER10@brand2.example", + "lead": "L-6096-10", + "owner": "AE-2", + "route": "account" + }, + "handoff-L-8510-9": { + "email": "BUYER9@site9.example", + "lead": "L-8510-9", + "owner": "AE-0", + "route": "territory" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + }, + "triage-L-3783-3": { + "lead": "L-3783-3", + "reason": "inactive_owner" + }, + "triage-L-7782-13": { + "lead": "L-7782-13", + "reason": "inactive_owner" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 3, + "capacity": 4, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 5, + "capacity": 4, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-2": { + "active": true, + "assigned": 2, + "capacity": 6, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-3": { + "active": true, + "assigned": 4, + "capacity": 7, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "West", + "sectors": [ + "Retail" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/test.sh b/tasks/autom-inbound-lead-handoff-003-v2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56afc332f7a5880f3b6f1fbcc47b0d82b2e327a3 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu +mkdir -p /logs/verifier /workspace/outputs +exec python3 -B -I /tests/grade.py diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/world.json b/tasks/autom-inbound-lead-handoff-003-v2/tests/world.json new file mode 100644 index 0000000000000000000000000000000000000000..a4046b50430c4177a947d57717c473004ad5de0c --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/world.json @@ -0,0 +1,290 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1121-7": { + "consent": true, + "email": "BUYER7@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-30" + }, + "L-1391-17": { + "consent": false, + "email": "BUYER17@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-01" + }, + "L-1985-2": { + "consent": false, + "email": "BUYER2@site2.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-2914-5": { + "consent": false, + "email": "BUYER5@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-06" + }, + "L-3438-12": { + "consent": true, + "email": "BUYER12@brand2.example", + "region": "West", + "sector": "Software", + "state": "new", + "submitted": "2025-03-30" + }, + "L-3783-3": { + "consent": true, + "email": "BUYER3@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-3902-18": { + "consent": false, + "email": "BUYER18@company5.example", + "region": "North", + "sector": "Software", + "state": "closed", + "submitted": "2025-03-26" + }, + "L-4298-6": { + "consent": false, + "email": "BUYER6@brand2.example", + "region": "North", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-02" + }, + "L-4611-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-07" + }, + "L-4618-0": { + "consent": true, + "email": "first@site0.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-07" + }, + "L-4897-4": { + "consent": true, + "email": "BUYER4@site4.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-05" + }, + "L-6096-10": { + "consent": true, + "email": "BUYER10@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-03-31" + }, + "L-6330-11": { + "consent": true, + "email": "BUYER11@brand2.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-7502-16": { + "consent": true, + "email": "BUYER16@brand2.example", + "region": "West", + "sector": "Industrial", + "state": "closed", + "submitted": "2025-04-08" + }, + "L-7782-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-04" + }, + "L-7842-14": { + "consent": true, + "email": "BUYER14@site14.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-08" + }, + "L-8510-9": { + "consent": true, + "email": "BUYER9@site9.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-07" + }, + "L-8897-8": { + "consent": true, + "email": "BUYER8@newgroup.example", + "region": "West", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-05" + }, + "L-9310-15": { + "consent": false, + "email": "BUYER15@site15.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-01" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 4, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 5, + "capacity": 4, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-2": { + "active": true, + "assigned": 1, + "capacity": 6, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-3": { + "active": true, + "assigned": 4, + "capacity": 7, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-4": { + "active": true, + "assigned": 5, + "capacity": 8, + "region": "West", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-5": { + "active": false, + "assigned": 0, + "capacity": 5, + "region": "West", + "sectors": [ + "Retail" + ] + } + } +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-003-v2/tests/world_check.py b/tasks/autom-inbound-lead-handoff-003-v2/tests/world_check.py new file mode 100644 index 0000000000000000000000000000000000000000..c1ae1d241cf41e839dc140339b0367d0c9b3591f --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/tests/world_check.py @@ -0,0 +1,26 @@ +"""Replay submitted mutations from the private verifier's initial state.""" +from types import ModuleType +import 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,'' diff --git a/tasks/autom-inbound-lead-handoff-003-v2/validation/openenv.json b/tasks/autom-inbound-lead-handoff-003-v2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..cce52a23189bf8d6e4689400ae2af4a22fbdbfd6 --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-003-v2/validation/openenv.json @@ -0,0 +1,28 @@ +{ + "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", + "sales" + ] + }, + "requires_credentials": false +} \ No newline at end of file diff --git a/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/apps.py b/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..b977e92875fd7b16c40b939c4533b214315a31bc --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/apps.py @@ -0,0 +1,68 @@ +"""Offline business-app client. Print usage with --help.""" +import argparse +import copy +import fcntl +import json +import os +from 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() diff --git a/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/world.json b/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/world.json new file mode 100644 index 0000000000000000000000000000000000000000..42c112c8f2eff68b272348808dbca1bfbcce2def --- /dev/null +++ b/tasks/autom-inbound-lead-handoff-004-v2/environment/inputs/world.json @@ -0,0 +1,288 @@ +{ + "accounts": { + "org-0": { + "domains": [ + "company0.example", + "brand0.example" + ], + "owner": "AE-0" + }, + "org-1": { + "domains": [ + "company1.example", + "brand1.example" + ], + "owner": "AE-1" + }, + "org-2": { + "domains": [ + "company2.example", + "brand2.example" + ], + "owner": "AE-2" + }, + "org-3": { + "domains": [ + "company3.example", + "brand3.example" + ], + "owner": "AE-3" + }, + "org-4": { + "domains": [ + "company4.example", + "brand4.example" + ], + "owner": "AE-4" + }, + "org-5": { + "domains": [ + "company5.example", + "brand5.example" + ], + "owner": "AE-5" + }, + "org-6": { + "domains": [ + "company6.example", + "brand6.example" + ], + "owner": "AE-0" + } + }, + "inbound_leads": { + "L-1629-0": { + "consent": true, + "email": "first@site0.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-26" + }, + "L-1631-16": { + "consent": true, + "email": "BUYER16@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Software", + "state": "closed", + "submitted": "2025-04-20" + }, + "L-2417-17": { + "consent": true, + "email": "BUYER17@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-28" + }, + "L-2433-14": { + "consent": true, + "email": "BUYER14@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-19" + }, + "L-2484-8": { + "consent": true, + "email": "BUYER8@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-05-02" + }, + "L-2798-3": { + "consent": true, + "email": "BUYER3@newgroup.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-26" + }, + "L-3402-12": { + "consent": true, + "email": "BUYER12@RESTRICTED.EXAMPLE", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-05-02" + }, + "L-4504-2": { + "consent": true, + "email": "BUYER2@newgroup.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-04-28" + }, + "L-5255-18": { + "consent": true, + "email": "BUYER18@company5.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-28" + }, + "L-5342-9": { + "consent": false, + "email": "BUYER9@RESTRICTED.EXAMPLE", + "region": "Central", + "sector": "Software", + "state": "new", + "submitted": "2025-04-16" + }, + "L-5735-6": { + "consent": true, + "email": "BUYER6@brand2.example", + "region": "North", + "sector": "Software", + "state": "new", + "submitted": "2025-05-02" + }, + "L-7421-7": { + "consent": true, + "email": "BUYER7@company5.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-19" + }, + "L-7610-15": { + "consent": false, + "email": "BUYER15@newgroup.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-15" + }, + "L-8186-1": { + "consent": true, + "email": "buyer@restricted.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-26" + }, + "L-8407-13": { + "consent": true, + "email": "BUYER13@company5.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-22" + }, + "L-9307-11": { + "consent": true, + "email": "BUYER11@company5.example", + "region": "North", + "sector": "Retail", + "state": "closed", + "submitted": "2025-05-01" + }, + "L-9410-5": { + "consent": true, + "email": "BUYER5@site5.example", + "region": "North", + "sector": "Retail", + "state": "new", + "submitted": "2025-04-26" + }, + "L-9484-4": { + "consent": false, + "email": "BUYER4@newgroup.example", + "region": "North", + "sector": "Industrial", + "state": "new", + "submitted": "2025-04-26" + }, + "L-9749-10": { + "consent": false, + "email": "BUYER10@newgroup.example", + "region": "Central", + "sector": "Software", + "state": "closed", + "submitted": "2025-04-29" + } + }, + "outreach": { + "existing": { + "status": "sent" + } + }, + "privacy": { + "privacy": { + "domains": [ + "restricted.example" + ] + } + }, + "sales_ops": { + "existing": { + "status": "closed" + } + }, + "seller_roster": { + "AE-0": { + "active": true, + "assigned": 0, + "capacity": 4, + "region": "North", + "sectors": [ + "Industrial", + "Retail", + "Software" + ] + }, + "AE-1": { + "active": true, + "assigned": 0, + "capacity": 4, + "region": "North", + "sectors": [ + "Software", + "Retail", + "Industrial" + ] + }, + "AE-2": { + "active": true, + "assigned": 5, + "capacity": 6, + "region": "North", + "sectors": [ + "Retail", + "Industrial", + "Software" + ] + }, + "AE-3": { + "active": true, + "assigned": 1, + "capacity": 7, + "region": "North", + "sectors": [ + "Industrial" + ] + }, + "AE-4": { + "active": true, + "assigned": 2, + "capacity": 8, + "region": "Central", + "sectors": [ + "Industrial" + ] + }, + "AE-5": { + "active": false, + "assigned": 5, + "capacity": 8, + "region": "Central", + "sectors": [ + "Software", + "Industrial", + "Retail" + ] + } + } +} \ No newline at end of file