Harbor format: 502 knowledge_work tasks (part 6)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +33 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/solution/solve.sh +4 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/task.toml +44 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/expected.json +60 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/grade.py +330 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/test.sh +4 -0
- tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/validation/openenv.json +26 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/environment/inputs/FTENETWORKS_INC_02_18_2016-EX-99.4-STRATEGIC_ALLIANCE_AGREEMENT.pdf +3 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/instruction.md +23 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/solution/files/answer.json +10 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/solution/solve.sh +4 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/task.toml +44 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/expected.json +60 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/grade.py +330 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/test.sh +4 -0
- tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/validation/openenv.json +26 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/environment/inputs/FulucaiProductionsLtd_20131223_10-Q_EX-10.9_8368347_EX-10.9_Content_License_Agreement.pdf +3 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/instruction.md +22 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/solution/files/answer.json +9 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/solution/solve.sh +4 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/task.toml +44 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/expected.json +59 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/grade.py +330 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/test.sh +4 -0
- tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/validation/openenv.json +26 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/environment/inputs/GlobalTechnologiesGroupInc_20050928_10KSB_EX-10.9_4148808_EX-10.9_Content_License_Agreement.pdf +3 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/instruction.md +23 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/solution/files/answer.json +10 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/solution/solve.sh +4 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/task.toml +44 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/expected.json +66 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/grade.py +330 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/test.sh +4 -0
- tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/validation/openenv.json +26 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/environment/inputs/GluMobileInc_20070319_S-1A_EX-10.09_436630_EX-10.09_Content_License_Agreement1.pdf +3 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/instruction.md +23 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/solution/files/answer.json +10 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/solution/solve.sh +4 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/task.toml +44 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/expected.json +66 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/grade.py +330 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/test.sh +4 -0
- tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/validation/openenv.json +26 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/environment/inputs/GOLDRESOURCECORP_12_11_2008-EX-10.1-STRATEGIC_ALLIANCE_AGREEMENT.pdf +3 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/instruction.md +22 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/solution/files/answer.json +9 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/solution/solve.sh +4 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/task.toml +44 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/tests/expected.json +59 -0
- tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/tests/grade.py +330 -0
.gitattributes
CHANGED
|
@@ -164,3 +164,36 @@ tasks/cuad-dd-elandiainternationalinc-04-25-2007-ex-10-8f8ca97f-v3/environment/i
|
|
| 164 |
tasks/cuad-dd-elfbeauty-inc-07-02-2020-ex-10-1-coopera-4857c747/environment/inputs/ELFBEAUTY_INC_07_02_2020-EX-10.1-COOPERATION_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 165 |
tasks/cuad-dd-euromediaholdingscorp-20070215-10sb12g-e-28af50c4/environment/inputs/EuromediaHoldingsCorp_20070215_10SB12G_EX-10.B_01__525118_EX-10.B_01__Content_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 166 |
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/environment/inputs/FIBROGENINC_10_01_2014-EX-10.11-COLLABORATION_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
tasks/cuad-dd-elfbeauty-inc-07-02-2020-ex-10-1-coopera-4857c747/environment/inputs/ELFBEAUTY_INC_07_02_2020-EX-10.1-COOPERATION_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 165 |
tasks/cuad-dd-euromediaholdingscorp-20070215-10sb12g-e-28af50c4/environment/inputs/EuromediaHoldingsCorp_20070215_10SB12G_EX-10.B_01__525118_EX-10.B_01__Content_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 166 |
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/environment/inputs/FIBROGENINC_10_01_2014-EX-10.11-COLLABORATION_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 167 |
+
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/environment/inputs/FTENETWORKS_INC_02_18_2016-EX-99.4-STRATEGIC_ALLIANCE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 168 |
+
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/environment/inputs/FulucaiProductionsLtd_20131223_10-Q_EX-10.9_8368347_EX-10.9_Content_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 169 |
+
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/environment/inputs/GlobalTechnologiesGroupInc_20050928_10KSB_EX-10.9_4148808_EX-10.9_Content_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 170 |
+
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/environment/inputs/GluMobileInc_20070319_S-1A_EX-10.09_436630_EX-10.09_Content_License_Agreement1.pdf filter=lfs diff=lfs merge=lfs -text
|
| 171 |
+
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/environment/inputs/GOLDRESOURCECORP_12_11_2008-EX-10.1-STRATEGIC_ALLIANCE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 172 |
+
tasks/cuad-dd-gpaqacquisitionholdingsinc-20200123-s-4a-24fcbe48/environment/inputs/GpaqAcquisitionHoldingsInc_20200123_S-4A_EX-10.6_11951677_EX-10.6_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 173 |
+
tasks/cuad-dd-gridironbionutrients-inc-02-05-2020-ex-1-5a68fb60-v2/environment/inputs/GRIDIRONBIONUTRIENTS_INC_02_05_2020-EX-10.3-SUPPLY_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 174 |
+
tasks/cuad-dd-healthgatedatacorp-11-24-1999-ex-10-1-ho-c456bfc3/environment/inputs/HEALTHGATEDATACORP_11_24_1999-EX-10.1-HOSTING_AND_MANAGEMENT_AGREEMENT_1.pdf filter=lfs diff=lfs merge=lfs -text
|
| 175 |
+
tasks/cuad-dd-ibioinc-20200313-8-k-ex-10-1-12052678-ex-5ded7f3c-v2/environment/inputs/IbioInc_20200313_8-K_EX-10.1_12052678_EX-10.1_Development_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 176 |
+
tasks/cuad-dd-ideanomicsinc-20160330-10-k-ex-10-26-951-34feb55f/environment/inputs/IdeanomicsInc_20160330_10-K_EX-10.26_9512211_EX-10.26_Content_License_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 177 |
+
tasks/cuad-dd-idreamskytechnologyltd-07-03-2014-ex-10--92e3e5c0-v2/environment/inputs/IDREAMSKYTECHNOLOGYLTD_07_03_2014-EX-10.39-Cooperation_Agreement_on_Mobile_Game_Business.pdf filter=lfs diff=lfs merge=lfs -text
|
| 178 |
+
tasks/cuad-dd-igenebiotechnologyinc-05-13-2003-ex-1-jo-71fbfebb-v2/environment/inputs/IGENEBIOTECHNOLOGYINC_05_13_2003-EX-1-JOINT_VENTURE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 179 |
+
tasks/cuad-dd-iminecorp-20180725-s-1-ex-10-5-11275970--06080324-v2/environment/inputs/ImineCorp_20180725_S-1_EX-10.5_11275970_EX-10.5_Distributor_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 180 |
+
tasks/cuad-dd-impressecorp-20000322-s-1a-ex-10-11-5199-95c2d66c/environment/inputs/ImpresseCorp_20000322_S-1A_EX-10.11_5199234_EX-10.11_Co-Branding_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 181 |
+
tasks/cuad-dd-internationalfastfoodcorp-04-04-1997-ex--4f3232be-v3/environment/inputs/INTERNATIONALFASTFOODCORP_04_04_1997-EX-99-FRANCHISE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 182 |
+
tasks/cuad-dd-intersectent-inc-05-11-2020-ex-10-1-supp-cb82a343-v2/environment/inputs/INTERSECTENT_INC_05_11_2020-EX-10.1-SUPPLY_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 183 |
+
tasks/cuad-dd-iovancebiotherapeutics-inc-08-03-2017-ex-5067cd14/environment/inputs/IOVANCEBIOTHERAPEUTICS_INC_08_03_2017-EX-10.1-STRATEGIC_ALLIANCE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 184 |
+
tasks/cuad-dd-jingweiinternationalltd-10-04-2007-ex-10-6361913d/environment/inputs/JINGWEIINTERNATIONALLTD_10_04_2007-EX-10.7-INTELLECTUAL_PROPERTY_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 185 |
+
tasks/cuad-dd-lejuholdingsltd-20140121-drs-on-f-1-ex--daa077cf/environment/inputs/LejuHoldingsLtd_20140121_DRS_on_F-1__EX-10.26_8473102_EX-10.26_Content_License_Agreement1.pdf filter=lfs diff=lfs merge=lfs -text
|
| 186 |
+
tasks/cuad-dd-loyaltypointinc-11-16-2004-ex-10-2-resel-96103a19/environment/inputs/LOYALTYPOINTINC_11_16_2004-EX-10.2-RESELLER_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 187 |
+
tasks/cuad-dd-magenta-therapeutics-inc---master-devel-4b001d95/environment/inputs/Magenta_Therapeutics_Inc._-_Master_Development_and_Manufacturing_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 188 |
+
tasks/cuad-dd-ofgbancorp-03-28-2007-ex-10-23-outsourci-6d2c44f4/environment/inputs/OFGBANCORP_03_28_2007-EX-10.23-OUTSOURCING_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 189 |
+
tasks/cuad-dd-oldapiwind-downltd-01-08-2016-ex-1-3-age-36744ba9/environment/inputs/OLDAPIWIND-DOWNLTD_01_08_2016-EX-1.3-AGENCY_AGREEMENT1.pdf filter=lfs diff=lfs merge=lfs -text
|
| 190 |
+
tasks/cuad-dd-paratekpharmaceuticalsinc-20170505-10-ka-9136ba4e/environment/inputs/ParatekPharmaceuticalsInc_20170505_10-KA_EX-10.29_10323872_EX-10.29_Outsourcing_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 191 |
+
tasks/cuad-dd-pelicandeliversinc-20200211-s-1-ex-10-3--5a88247f/environment/inputs/PelicanDeliversInc_20200211_S-1_EX-10.3_11975895_EX-10.3_Development_Agreement2.pdf filter=lfs diff=lfs merge=lfs -text
|
| 192 |
+
tasks/cuad-dd-premierbiomedicalinc-05-14-2020-ex-10-2--a6870dfb/environment/inputs/PREMIERBIOMEDICALINC_05_14_2020-EX-10.2-INTELLECTUAL_PROPERTY_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 193 |
+
tasks/cuad-dd-rareelementresourcesltd-20171019-sc-13d--1ce0b720/environment/inputs/RareElementResourcesLtd_20171019_SC_13D_EX-99.4_10897534_EX-99.4_Intellectual_Property_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 194 |
+
tasks/cuad-dd-reganholdingcorp-03-31-2008-ex-10-licens-68a0b439/environment/inputs/REGANHOLDINGCORP_03_31_2008-EX-10-LICENSE_AND_HOSTING_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 195 |
+
tasks/cuad-dd-reynoldsconsumerproductsinc-20200121-s-1-7fd06763/environment/inputs/ReynoldsConsumerProductsInc_20200121_S-1A_EX-10.22_11948918_EX-10.22_Service_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
| 196 |
+
tasks/cuad-dd-rubiosrestaurantsinc-03-31-2008-ex-10-75-04fcb1ea-v2/environment/inputs/RUBIOSRESTAURANTSINC_03_31_2008-EX-10.75-SPONSORSHIP_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 197 |
+
tasks/cuad-dd-scoutcaminc-05-12-2020-ex-10-22-services-2af3cb66/environment/inputs/SCOUTCAMINC_05_12_2020-EX-10.22-SERVICES_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 198 |
+
tasks/cuad-dd-spienergyco-ltd-03-09-2011-ex-99-5-opera-c468dc5d/environment/inputs/SPIENERGYCO_LTD_03_09_2011-EX-99.5-OPERATIONS_AND_MAINTENANCE_AGREEMENT.pdf filter=lfs diff=lfs merge=lfs -text
|
| 199 |
+
tasks/cuad-dd-stampscominc-20001114-10-q-ex-10-47-2631-979f273c-v2/environment/inputs/StampscomInc_20001114_10-Q_EX-10.47_2631630_EX-10.47_Co-Branding_Agreement.pdf filter=lfs diff=lfs merge=lfs -text
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "FIBROGENINC_10_01_2014-EX-10.11-COLLABORATION AGREEMENT.PDF:agreement_date,exclusivity,most_favored_nation,audit_rights,ip_ownership_assignment,liquidated_damages,source_code_escrow,no_solicit_of_employees"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/expected.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "agreement_date",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "agreement_date",
|
| 7 |
+
"kind": "date",
|
| 8 |
+
"value": "2005-06-01"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "exclusivity",
|
| 12 |
+
"type": "answer",
|
| 13 |
+
"field": "exclusivity",
|
| 14 |
+
"kind": "bool",
|
| 15 |
+
"value": true
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"id": "most_favored_nation",
|
| 19 |
+
"type": "answer",
|
| 20 |
+
"field": "most_favored_nation",
|
| 21 |
+
"kind": "bool",
|
| 22 |
+
"value": false
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"id": "audit_rights",
|
| 26 |
+
"type": "answer",
|
| 27 |
+
"field": "audit_rights",
|
| 28 |
+
"kind": "bool",
|
| 29 |
+
"value": true
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": "ip_ownership_assignment",
|
| 33 |
+
"type": "answer",
|
| 34 |
+
"field": "ip_ownership_assignment",
|
| 35 |
+
"kind": "bool",
|
| 36 |
+
"value": true
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "liquidated_damages",
|
| 40 |
+
"type": "answer",
|
| 41 |
+
"field": "liquidated_damages",
|
| 42 |
+
"kind": "bool",
|
| 43 |
+
"value": true
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"id": "source_code_escrow",
|
| 47 |
+
"type": "answer",
|
| 48 |
+
"field": "source_code_escrow",
|
| 49 |
+
"kind": "bool",
|
| 50 |
+
"value": false
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": "no_solicit_of_employees",
|
| 54 |
+
"type": "answer",
|
| 55 |
+
"field": "no_solicit_of_employees",
|
| 56 |
+
"kind": "bool",
|
| 57 |
+
"value": false
|
| 58 |
+
}
|
| 59 |
+
]
|
| 60 |
+
}
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/tests/test.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /logs/verifier /workspace/outputs
|
| 4 |
+
exec python3 -B -I /tests/grade.py
|
tasks/cuad-dd-fibrogeninc-10-01-2014-ex-10-11-collabor-10a96028/validation/openenv.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"profile": "harbor-semantic-v1",
|
| 3 |
+
"reward_key": "reward",
|
| 4 |
+
"reward": {
|
| 5 |
+
"range": [
|
| 6 |
+
0,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"oracle_tolerance": 0,
|
| 10 |
+
"floor_margin": 0.1
|
| 11 |
+
},
|
| 12 |
+
"resources": {
|
| 13 |
+
"cpu": 1,
|
| 14 |
+
"memory_mb": 4096,
|
| 15 |
+
"disk_mb": 10240,
|
| 16 |
+
"episode_timeout_s": 1800
|
| 17 |
+
},
|
| 18 |
+
"types": {
|
| 19 |
+
"tags": [
|
| 20 |
+
"knowledge-work",
|
| 21 |
+
"legal-documents",
|
| 22 |
+
"pdf-extraction"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"requires_credentials": false
|
| 26 |
+
}
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/environment/inputs/FTENETWORKS_INC_02_18_2016-EX-99.4-STRATEGIC_ALLIANCE_AGREEMENT.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d2fe1782e48ca203e5e9a287f8b81009ec4acd8db89c910304b03bd2d6b06909
|
| 3 |
+
size 125249
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/instruction.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a corporate associate running legal due diligence on a target company's material contracts. The contract under review is `/workspace/inputs/FTENETWORKS_INC_02_18_2016-EX-99.4-STRATEGIC_ALLIANCE_AGREEMENT.pdf`. Read it and complete the checklist below. Each item names the JSON field that holds its answer.
|
| 2 |
+
|
| 3 |
+
Answer formats:
|
| 4 |
+
|
| 5 |
+
- Dates are strings in `YYYY-MM-DD` form.
|
| 6 |
+
- Clause questions take the string `Yes` if the contract contains any clause matching the definition, for either party and even if subject to exceptions, and `No` otherwise.
|
| 7 |
+
- Governing law is a string naming the jurisdiction: a US state by its name alone (for example `Delaware`), a Canadian province or Australian state as `Province, Country` (for example `Ontario, Canada`), and any other jurisdiction by country (for example `Germany`; use `England` for the law of England and Wales).
|
| 8 |
+
|
| 9 |
+
Checklist:
|
| 10 |
+
|
| 11 |
+
1. **Expiration date** (`expiration_date`): The date the initial term ends, before any renewal.
|
| 12 |
+
2. **Anti-assignment** (`anti_assignment`): Consent or notice of a party is required if the contract is assigned to a third party.
|
| 13 |
+
3. **Most favored nation** (`most_favored_nation`): If a third party gets better terms on the licensing or sale of the technology, goods or services in the contract, the buyer under this contract is entitled to those better terms.
|
| 14 |
+
4. **Insurance** (`insurance`): One party must maintain insurance for the benefit of the counterparty.
|
| 15 |
+
5. **Liquidated damages** (`liquidated_damages`): Either party can be awarded liquidated damages for breach, or a fee on termination of the contract (a termination fee).
|
| 16 |
+
6. **Source code escrow** (`source_code_escrow`): One party must deposit its source code with a third-party escrow agent for release to the counterparty on certain events such as bankruptcy or insolvency.
|
| 17 |
+
7. **Non-disparagement** (`non_disparagement`): A party must not disparage the counterparty.
|
| 18 |
+
8. **Revenue or profit sharing** (`revenue_profit_sharing`): One party must share revenue or profit with the counterparty for any technology, goods or services.
|
| 19 |
+
|
| 20 |
+
## Deliverable
|
| 21 |
+
|
| 22 |
+
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in
|
| 23 |
+
`/workspace/outputs/`; only that directory is graded. Write `/workspace/outputs/answer.json`, a JSON object with exactly the fields listed in the checklist (`expiration_date`, `anti_assignment`, `most_favored_nation`, `insurance`, `liquidated_damages`, `source_code_escrow`, `non_disparagement`, `revenue_profit_sharing`).
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/solution/files/answer.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"expiration_date": "2019-02-16",
|
| 3 |
+
"anti_assignment": "Yes",
|
| 4 |
+
"most_favored_nation": "No",
|
| 5 |
+
"insurance": "Yes",
|
| 6 |
+
"liquidated_damages": "Yes",
|
| 7 |
+
"source_code_escrow": "No",
|
| 8 |
+
"non_disparagement": "No",
|
| 9 |
+
"revenue_profit_sharing": "No"
|
| 10 |
+
}
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "FTENETWORKS,INC_02_18_2016-EX-99.4-STRATEGIC ALLIANCE AGREEMENT.PDF:expiration_date,anti_assignment,most_favored_nation,insurance,liquidated_damages,source_code_escrow,non_disparagement,revenue_profit_sharing"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/expected.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "expiration_date",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "expiration_date",
|
| 7 |
+
"kind": "date",
|
| 8 |
+
"value": "2019-02-16"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "anti_assignment",
|
| 12 |
+
"type": "answer",
|
| 13 |
+
"field": "anti_assignment",
|
| 14 |
+
"kind": "bool",
|
| 15 |
+
"value": true
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"id": "most_favored_nation",
|
| 19 |
+
"type": "answer",
|
| 20 |
+
"field": "most_favored_nation",
|
| 21 |
+
"kind": "bool",
|
| 22 |
+
"value": false
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"id": "insurance",
|
| 26 |
+
"type": "answer",
|
| 27 |
+
"field": "insurance",
|
| 28 |
+
"kind": "bool",
|
| 29 |
+
"value": true
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": "liquidated_damages",
|
| 33 |
+
"type": "answer",
|
| 34 |
+
"field": "liquidated_damages",
|
| 35 |
+
"kind": "bool",
|
| 36 |
+
"value": true
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "source_code_escrow",
|
| 40 |
+
"type": "answer",
|
| 41 |
+
"field": "source_code_escrow",
|
| 42 |
+
"kind": "bool",
|
| 43 |
+
"value": false
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"id": "non_disparagement",
|
| 47 |
+
"type": "answer",
|
| 48 |
+
"field": "non_disparagement",
|
| 49 |
+
"kind": "bool",
|
| 50 |
+
"value": false
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": "revenue_profit_sharing",
|
| 54 |
+
"type": "answer",
|
| 55 |
+
"field": "revenue_profit_sharing",
|
| 56 |
+
"kind": "bool",
|
| 57 |
+
"value": false
|
| 58 |
+
}
|
| 59 |
+
]
|
| 60 |
+
}
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/tests/test.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /logs/verifier /workspace/outputs
|
| 4 |
+
exec python3 -B -I /tests/grade.py
|
tasks/cuad-dd-ftenetworks-inc-02-18-2016-ex-99-4-strat-3263edde/validation/openenv.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"profile": "harbor-semantic-v1",
|
| 3 |
+
"reward_key": "reward",
|
| 4 |
+
"reward": {
|
| 5 |
+
"range": [
|
| 6 |
+
0,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"oracle_tolerance": 0,
|
| 10 |
+
"floor_margin": 0.1
|
| 11 |
+
},
|
| 12 |
+
"resources": {
|
| 13 |
+
"cpu": 1,
|
| 14 |
+
"memory_mb": 4096,
|
| 15 |
+
"disk_mb": 10240,
|
| 16 |
+
"episode_timeout_s": 1800
|
| 17 |
+
},
|
| 18 |
+
"types": {
|
| 19 |
+
"tags": [
|
| 20 |
+
"knowledge-work",
|
| 21 |
+
"legal-documents",
|
| 22 |
+
"pdf-extraction"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"requires_credentials": false
|
| 26 |
+
}
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/environment/inputs/FulucaiProductionsLtd_20131223_10-Q_EX-10.9_8368347_EX-10.9_Content_License_Agreement.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a030ed8d8f65605e86f7e6e48316aa823800a0b5ece674ad7fea0147e1a00ad
|
| 3 |
+
size 110262
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/instruction.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a corporate associate running legal due diligence on a target company's material contracts. The contract under review is `/workspace/inputs/FulucaiProductionsLtd_20131223_10-Q_EX-10.9_8368347_EX-10.9_Content_License_Agreement.pdf`. Read it and complete the checklist below. Each item names the JSON field that holds its answer.
|
| 2 |
+
|
| 3 |
+
Answer formats:
|
| 4 |
+
|
| 5 |
+
- Dates are strings in `YYYY-MM-DD` form.
|
| 6 |
+
- Clause questions take the string `Yes` if the contract contains any clause matching the definition, for either party and even if subject to exceptions, and `No` otherwise.
|
| 7 |
+
- Governing law is a string naming the jurisdiction: a US state by its name alone (for example `Delaware`), a Canadian province or Australian state as `Province, Country` (for example `Ontario, Canada`), and any other jurisdiction by country (for example `Germany`; use `England` for the law of England and Wales).
|
| 8 |
+
|
| 9 |
+
Checklist:
|
| 10 |
+
|
| 11 |
+
1. **Agreement date** (`agreement_date`): The date of the contract: the date it is dated or entered into, as stated in the document.
|
| 12 |
+
2. **Governing law** (`governing_law`): the jurisdiction whose law governs the contract.
|
| 13 |
+
3. **Exclusivity** (`exclusivity`): There is an exclusive dealing commitment with the counterparty: a commitment to procure all requirements from one party, or a prohibition on licensing or selling to third parties or on working with other parties, during or after the contract. An exclusive license, appointment or territory granted to the counterparty counts.
|
| 14 |
+
4. **Termination for convenience** (`termination_for_convenience`): A party can terminate the contract without cause, solely by giving notice and letting a waiting period expire.
|
| 15 |
+
5. **Most favored nation** (`most_favored_nation`): If a third party gets better terms on the licensing or sale of the technology, goods or services in the contract, the buyer under this contract is entitled to those better terms.
|
| 16 |
+
6. **Audit rights** (`audit_rights`): A party has the right to audit the books, records or physical locations of the counterparty to check compliance with the contract.
|
| 17 |
+
7. **Non-disparagement** (`non_disparagement`): A party must not disparage the counterparty.
|
| 18 |
+
|
| 19 |
+
## Deliverable
|
| 20 |
+
|
| 21 |
+
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in
|
| 22 |
+
`/workspace/outputs/`; only that directory is graded. Write `/workspace/outputs/answer.json`, a JSON object with exactly the fields listed in the checklist (`agreement_date`, `governing_law`, `exclusivity`, `termination_for_convenience`, `most_favored_nation`, `audit_rights`, `non_disparagement`).
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/solution/files/answer.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"agreement_date": "2012-11-15",
|
| 3 |
+
"governing_law": "Florida",
|
| 4 |
+
"exclusivity": "Yes",
|
| 5 |
+
"termination_for_convenience": "No",
|
| 6 |
+
"most_favored_nation": "No",
|
| 7 |
+
"audit_rights": "Yes",
|
| 8 |
+
"non_disparagement": "No"
|
| 9 |
+
}
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "FulucaiProductionsLtd_20131223_10-Q_EX-10.9_8368347_EX-10.9_Content License Agreement.pdf:agreement_date,governing_law,exclusivity,termination_for_convenience,most_favored_nation,audit_rights,non_disparagement"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/expected.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "agreement_date",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "agreement_date",
|
| 7 |
+
"kind": "date",
|
| 8 |
+
"value": "2012-11-15"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "governing_law",
|
| 12 |
+
"type": "answer",
|
| 13 |
+
"field": "governing_law",
|
| 14 |
+
"kind": "text",
|
| 15 |
+
"value": "Florida",
|
| 16 |
+
"accept": [
|
| 17 |
+
"Florida",
|
| 18 |
+
"State of Florida",
|
| 19 |
+
"Florida, USA",
|
| 20 |
+
"Florida, United States"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"id": "exclusivity",
|
| 25 |
+
"type": "answer",
|
| 26 |
+
"field": "exclusivity",
|
| 27 |
+
"kind": "bool",
|
| 28 |
+
"value": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "termination_for_convenience",
|
| 32 |
+
"type": "answer",
|
| 33 |
+
"field": "termination_for_convenience",
|
| 34 |
+
"kind": "bool",
|
| 35 |
+
"value": false
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"id": "most_favored_nation",
|
| 39 |
+
"type": "answer",
|
| 40 |
+
"field": "most_favored_nation",
|
| 41 |
+
"kind": "bool",
|
| 42 |
+
"value": false
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "audit_rights",
|
| 46 |
+
"type": "answer",
|
| 47 |
+
"field": "audit_rights",
|
| 48 |
+
"kind": "bool",
|
| 49 |
+
"value": true
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": "non_disparagement",
|
| 53 |
+
"type": "answer",
|
| 54 |
+
"field": "non_disparagement",
|
| 55 |
+
"kind": "bool",
|
| 56 |
+
"value": false
|
| 57 |
+
}
|
| 58 |
+
]
|
| 59 |
+
}
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/tests/test.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /logs/verifier /workspace/outputs
|
| 4 |
+
exec python3 -B -I /tests/grade.py
|
tasks/cuad-dd-fulucaiproductionsltd-20131223-10-q-ex-1-f4941a31/validation/openenv.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"profile": "harbor-semantic-v1",
|
| 3 |
+
"reward_key": "reward",
|
| 4 |
+
"reward": {
|
| 5 |
+
"range": [
|
| 6 |
+
0,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"oracle_tolerance": 0,
|
| 10 |
+
"floor_margin": 0.1
|
| 11 |
+
},
|
| 12 |
+
"resources": {
|
| 13 |
+
"cpu": 1,
|
| 14 |
+
"memory_mb": 4096,
|
| 15 |
+
"disk_mb": 10240,
|
| 16 |
+
"episode_timeout_s": 1800
|
| 17 |
+
},
|
| 18 |
+
"types": {
|
| 19 |
+
"tags": [
|
| 20 |
+
"knowledge-work",
|
| 21 |
+
"legal-documents",
|
| 22 |
+
"pdf-extraction"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"requires_credentials": false
|
| 26 |
+
}
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/environment/inputs/GlobalTechnologiesGroupInc_20050928_10KSB_EX-10.9_4148808_EX-10.9_Content_License_Agreement.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b668fc77aeeae09a02221d0032814a43c160b5d5b4ab2a1ab9915a73e567f525
|
| 3 |
+
size 203465
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/instruction.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a corporate associate running legal due diligence on a target company's material contracts. The contract under review is `/workspace/inputs/GlobalTechnologiesGroupInc_20050928_10KSB_EX-10.9_4148808_EX-10.9_Content_License_Agreement.pdf`. Read it and complete the checklist below. Each item names the JSON field that holds its answer.
|
| 2 |
+
|
| 3 |
+
Answer formats:
|
| 4 |
+
|
| 5 |
+
- Dates are strings in `YYYY-MM-DD` form.
|
| 6 |
+
- Clause questions take the string `Yes` if the contract contains any clause matching the definition, for either party and even if subject to exceptions, and `No` otherwise.
|
| 7 |
+
- Governing law is a string naming the jurisdiction: a US state by its name alone (for example `Delaware`), a Canadian province or Australian state as `Province, Country` (for example `Ontario, Canada`), and any other jurisdiction by country (for example `Germany`; use `England` for the law of England and Wales).
|
| 8 |
+
|
| 9 |
+
Checklist:
|
| 10 |
+
|
| 11 |
+
1. **Governing law** (`governing_law`): the jurisdiction whose law governs the contract.
|
| 12 |
+
2. **Anti-assignment** (`anti_assignment`): Consent or notice of a party is required if the contract is assigned to a third party.
|
| 13 |
+
3. **Cap on liability** (`cap_on_liability`): The contract limits a party's liability for breach: a maximum recoverable amount, an exclusion of categories of damages (for example indirect, consequential or lost-profit damages), or a time limit for the counterparty to bring claims.
|
| 14 |
+
4. **Most favored nation** (`most_favored_nation`): If a third party gets better terms on the licensing or sale of the technology, goods or services in the contract, the buyer under this contract is entitled to those better terms.
|
| 15 |
+
5. **Audit rights** (`audit_rights`): A party has the right to audit the books, records or physical locations of the counterparty to check compliance with the contract.
|
| 16 |
+
6. **Liquidated damages** (`liquidated_damages`): Either party can be awarded liquidated damages for breach, or a fee on termination of the contract (a termination fee).
|
| 17 |
+
7. **Source code escrow** (`source_code_escrow`): One party must deposit its source code with a third-party escrow agent for release to the counterparty on certain events such as bankruptcy or insolvency.
|
| 18 |
+
8. **License grant** (`license_grant`): One party grants a license to its counterparty.
|
| 19 |
+
|
| 20 |
+
## Deliverable
|
| 21 |
+
|
| 22 |
+
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in
|
| 23 |
+
`/workspace/outputs/`; only that directory is graded. Write `/workspace/outputs/answer.json`, a JSON object with exactly the fields listed in the checklist (`governing_law`, `anti_assignment`, `cap_on_liability`, `most_favored_nation`, `audit_rights`, `liquidated_damages`, `source_code_escrow`, `license_grant`).
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/solution/files/answer.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"governing_law": "Florida",
|
| 3 |
+
"anti_assignment": "Yes",
|
| 4 |
+
"cap_on_liability": "Yes",
|
| 5 |
+
"most_favored_nation": "No",
|
| 6 |
+
"audit_rights": "No",
|
| 7 |
+
"liquidated_damages": "No",
|
| 8 |
+
"source_code_escrow": "No",
|
| 9 |
+
"license_grant": "Yes"
|
| 10 |
+
}
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "GlobalTechnologiesGroupInc_20050928_10KSB_EX-10.9_4148808_EX-10.9_Content License Agreement.pdf:governing_law,anti_assignment,cap_on_liability,most_favored_nation,audit_rights,liquidated_damages,source_code_escrow,license_grant"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/expected.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "governing_law",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "governing_law",
|
| 7 |
+
"kind": "text",
|
| 8 |
+
"value": "Florida",
|
| 9 |
+
"accept": [
|
| 10 |
+
"Florida",
|
| 11 |
+
"State of Florida",
|
| 12 |
+
"Florida, USA",
|
| 13 |
+
"Florida, United States"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"id": "anti_assignment",
|
| 18 |
+
"type": "answer",
|
| 19 |
+
"field": "anti_assignment",
|
| 20 |
+
"kind": "bool",
|
| 21 |
+
"value": true
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"id": "cap_on_liability",
|
| 25 |
+
"type": "answer",
|
| 26 |
+
"field": "cap_on_liability",
|
| 27 |
+
"kind": "bool",
|
| 28 |
+
"value": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "most_favored_nation",
|
| 32 |
+
"type": "answer",
|
| 33 |
+
"field": "most_favored_nation",
|
| 34 |
+
"kind": "bool",
|
| 35 |
+
"value": false
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"id": "audit_rights",
|
| 39 |
+
"type": "answer",
|
| 40 |
+
"field": "audit_rights",
|
| 41 |
+
"kind": "bool",
|
| 42 |
+
"value": false
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "liquidated_damages",
|
| 46 |
+
"type": "answer",
|
| 47 |
+
"field": "liquidated_damages",
|
| 48 |
+
"kind": "bool",
|
| 49 |
+
"value": false
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": "source_code_escrow",
|
| 53 |
+
"type": "answer",
|
| 54 |
+
"field": "source_code_escrow",
|
| 55 |
+
"kind": "bool",
|
| 56 |
+
"value": false
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "license_grant",
|
| 60 |
+
"type": "answer",
|
| 61 |
+
"field": "license_grant",
|
| 62 |
+
"kind": "bool",
|
| 63 |
+
"value": true
|
| 64 |
+
}
|
| 65 |
+
]
|
| 66 |
+
}
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/tests/test.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /logs/verifier /workspace/outputs
|
| 4 |
+
exec python3 -B -I /tests/grade.py
|
tasks/cuad-dd-globaltechnologiesgroupinc-20050928-10ks-8321c3b8/validation/openenv.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"profile": "harbor-semantic-v1",
|
| 3 |
+
"reward_key": "reward",
|
| 4 |
+
"reward": {
|
| 5 |
+
"range": [
|
| 6 |
+
0,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"oracle_tolerance": 0,
|
| 10 |
+
"floor_margin": 0.1
|
| 11 |
+
},
|
| 12 |
+
"resources": {
|
| 13 |
+
"cpu": 1,
|
| 14 |
+
"memory_mb": 4096,
|
| 15 |
+
"disk_mb": 10240,
|
| 16 |
+
"episode_timeout_s": 1800
|
| 17 |
+
},
|
| 18 |
+
"types": {
|
| 19 |
+
"tags": [
|
| 20 |
+
"knowledge-work",
|
| 21 |
+
"legal-documents",
|
| 22 |
+
"pdf-extraction"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"requires_credentials": false
|
| 26 |
+
}
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/environment/inputs/GluMobileInc_20070319_S-1A_EX-10.09_436630_EX-10.09_Content_License_Agreement1.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fee1c562facd69bcb9d76c614d36fc83bf9d69f8299d6a2bdb83e09789807c93
|
| 3 |
+
size 327959
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/instruction.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a corporate associate running legal due diligence on a target company's material contracts. The contract under review is `/workspace/inputs/GluMobileInc_20070319_S-1A_EX-10.09_436630_EX-10.09_Content_License_Agreement1.pdf`. Read it and complete the checklist below. Each item names the JSON field that holds its answer.
|
| 2 |
+
|
| 3 |
+
Answer formats:
|
| 4 |
+
|
| 5 |
+
- Dates are strings in `YYYY-MM-DD` form.
|
| 6 |
+
- Clause questions take the string `Yes` if the contract contains any clause matching the definition, for either party and even if subject to exceptions, and `No` otherwise.
|
| 7 |
+
- Governing law is a string naming the jurisdiction: a US state by its name alone (for example `Delaware`), a Canadian province or Australian state as `Province, Country` (for example `Ontario, Canada`), and any other jurisdiction by country (for example `Germany`; use `England` for the law of England and Wales).
|
| 8 |
+
|
| 9 |
+
Checklist:
|
| 10 |
+
|
| 11 |
+
1. **Expiration date** (`expiration_date`): The date the initial term ends, before any renewal.
|
| 12 |
+
2. **Governing law** (`governing_law`): the jurisdiction whose law governs the contract.
|
| 13 |
+
3. **Cap on liability** (`cap_on_liability`): The contract limits a party's liability for breach: a maximum recoverable amount, an exclusion of categories of damages (for example indirect, consequential or lost-profit damages), or a time limit for the counterparty to bring claims.
|
| 14 |
+
4. **Most favored nation** (`most_favored_nation`): If a third party gets better terms on the licensing or sale of the technology, goods or services in the contract, the buyer under this contract is entitled to those better terms.
|
| 15 |
+
5. **Audit rights** (`audit_rights`): A party has the right to audit the books, records or physical locations of the counterparty to check compliance with the contract.
|
| 16 |
+
6. **IP ownership assignment** (`ip_ownership_assignment`): Intellectual property created by one party becomes the property of the counterparty, under the contract terms or on the occurrence of certain events.
|
| 17 |
+
7. **Insurance** (`insurance`): One party must maintain insurance for the benefit of the counterparty.
|
| 18 |
+
8. **Revenue or profit sharing** (`revenue_profit_sharing`): One party must share revenue or profit with the counterparty for any technology, goods or services.
|
| 19 |
+
|
| 20 |
+
## Deliverable
|
| 21 |
+
|
| 22 |
+
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in
|
| 23 |
+
`/workspace/outputs/`; only that directory is graded. Write `/workspace/outputs/answer.json`, a JSON object with exactly the fields listed in the checklist (`expiration_date`, `governing_law`, `cap_on_liability`, `most_favored_nation`, `audit_rights`, `ip_ownership_assignment`, `insurance`, `revenue_profit_sharing`).
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/solution/files/answer.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"expiration_date": "2006-12-31",
|
| 3 |
+
"governing_law": "California",
|
| 4 |
+
"cap_on_liability": "Yes",
|
| 5 |
+
"most_favored_nation": "No",
|
| 6 |
+
"audit_rights": "Yes",
|
| 7 |
+
"ip_ownership_assignment": "Yes",
|
| 8 |
+
"insurance": "No",
|
| 9 |
+
"revenue_profit_sharing": "Yes"
|
| 10 |
+
}
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "GluMobileInc_20070319_S-1A_EX-10.09_436630_EX-10.09_Content License Agreement1.pdf:expiration_date,governing_law,cap_on_liability,most_favored_nation,audit_rights,ip_ownership_assignment,insurance,revenue_profit_sharing"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/expected.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "expiration_date",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "expiration_date",
|
| 7 |
+
"kind": "date",
|
| 8 |
+
"value": "2006-12-31"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "governing_law",
|
| 12 |
+
"type": "answer",
|
| 13 |
+
"field": "governing_law",
|
| 14 |
+
"kind": "text",
|
| 15 |
+
"value": "California",
|
| 16 |
+
"accept": [
|
| 17 |
+
"California",
|
| 18 |
+
"State of California",
|
| 19 |
+
"California, USA",
|
| 20 |
+
"California, United States"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"id": "cap_on_liability",
|
| 25 |
+
"type": "answer",
|
| 26 |
+
"field": "cap_on_liability",
|
| 27 |
+
"kind": "bool",
|
| 28 |
+
"value": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "most_favored_nation",
|
| 32 |
+
"type": "answer",
|
| 33 |
+
"field": "most_favored_nation",
|
| 34 |
+
"kind": "bool",
|
| 35 |
+
"value": false
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"id": "audit_rights",
|
| 39 |
+
"type": "answer",
|
| 40 |
+
"field": "audit_rights",
|
| 41 |
+
"kind": "bool",
|
| 42 |
+
"value": true
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "ip_ownership_assignment",
|
| 46 |
+
"type": "answer",
|
| 47 |
+
"field": "ip_ownership_assignment",
|
| 48 |
+
"kind": "bool",
|
| 49 |
+
"value": true
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": "insurance",
|
| 53 |
+
"type": "answer",
|
| 54 |
+
"field": "insurance",
|
| 55 |
+
"kind": "bool",
|
| 56 |
+
"value": false
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "revenue_profit_sharing",
|
| 60 |
+
"type": "answer",
|
| 61 |
+
"field": "revenue_profit_sharing",
|
| 62 |
+
"kind": "bool",
|
| 63 |
+
"value": true
|
| 64 |
+
}
|
| 65 |
+
]
|
| 66 |
+
}
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/tests/test.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /logs/verifier /workspace/outputs
|
| 4 |
+
exec python3 -B -I /tests/grade.py
|
tasks/cuad-dd-glumobileinc-20070319-s-1a-ex-10-09-4366-e73220ff/validation/openenv.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"profile": "harbor-semantic-v1",
|
| 3 |
+
"reward_key": "reward",
|
| 4 |
+
"reward": {
|
| 5 |
+
"range": [
|
| 6 |
+
0,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"oracle_tolerance": 0,
|
| 10 |
+
"floor_margin": 0.1
|
| 11 |
+
},
|
| 12 |
+
"resources": {
|
| 13 |
+
"cpu": 1,
|
| 14 |
+
"memory_mb": 4096,
|
| 15 |
+
"disk_mb": 10240,
|
| 16 |
+
"episode_timeout_s": 1800
|
| 17 |
+
},
|
| 18 |
+
"types": {
|
| 19 |
+
"tags": [
|
| 20 |
+
"knowledge-work",
|
| 21 |
+
"legal-documents",
|
| 22 |
+
"pdf-extraction"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"requires_credentials": false
|
| 26 |
+
}
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/environment/inputs/GOLDRESOURCECORP_12_11_2008-EX-10.1-STRATEGIC_ALLIANCE_AGREEMENT.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dc8efd92da2f9edc2121eef659268eb2c4d3a6ca17db04c84bd72903ccb3f98f
|
| 3 |
+
size 171967
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/instruction.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a corporate associate running legal due diligence on a target company's material contracts. The contract under review is `/workspace/inputs/GOLDRESOURCECORP_12_11_2008-EX-10.1-STRATEGIC_ALLIANCE_AGREEMENT.pdf`. Read it and complete the checklist below. Each item names the JSON field that holds its answer.
|
| 2 |
+
|
| 3 |
+
Answer formats:
|
| 4 |
+
|
| 5 |
+
- Dates are strings in `YYYY-MM-DD` form.
|
| 6 |
+
- Clause questions take the string `Yes` if the contract contains any clause matching the definition, for either party and even if subject to exceptions, and `No` otherwise.
|
| 7 |
+
- Governing law is a string naming the jurisdiction: a US state by its name alone (for example `Delaware`), a Canadian province or Australian state as `Province, Country` (for example `Ontario, Canada`), and any other jurisdiction by country (for example `Germany`; use `England` for the law of England and Wales).
|
| 8 |
+
|
| 9 |
+
Checklist:
|
| 10 |
+
|
| 11 |
+
1. **Governing law** (`governing_law`): the jurisdiction whose law governs the contract.
|
| 12 |
+
2. **Anti-assignment** (`anti_assignment`): Consent or notice of a party is required if the contract is assigned to a third party.
|
| 13 |
+
3. **Non-compete** (`non_compete`): A party is restricted from competing with the counterparty or from operating in a certain geography, business or technology sector.
|
| 14 |
+
4. **Most favored nation** (`most_favored_nation`): Does entering a later agreement with a third party entitle HOC to materially more favourable standstill terms under the strategic alliance?
|
| 15 |
+
5. **Insurance** (`insurance`): Does the agreement require the Company to maintain liability insurance for a director nominated by HOC, subject to the conditions in Article 5?
|
| 16 |
+
6. **Source code escrow** (`source_code_escrow`): One party must deposit its source code with a third-party escrow agent for release to the counterparty on certain events such as bankruptcy or insolvency.
|
| 17 |
+
7. **Non-disparagement** (`non_disparagement`): A party must not disparage the counterparty.
|
| 18 |
+
|
| 19 |
+
## Deliverable
|
| 20 |
+
|
| 21 |
+
Work in `/workspace`. Input files are under `/workspace/inputs/`. Put every deliverable in
|
| 22 |
+
`/workspace/outputs/`; only that directory is graded. Write `/workspace/outputs/answer.json`, a JSON object with exactly the fields listed in the checklist (`governing_law`, `anti_assignment`, `non_compete`, `most_favored_nation`, `insurance`, `source_code_escrow`, `non_disparagement`).
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/solution/files/answer.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"governing_law": "New York",
|
| 3 |
+
"anti_assignment": "Yes",
|
| 4 |
+
"non_compete": "No",
|
| 5 |
+
"most_favored_nation": "Yes",
|
| 6 |
+
"insurance": "Yes",
|
| 7 |
+
"source_code_escrow": "No",
|
| 8 |
+
"non_disparagement": "No"
|
| 9 |
+
}
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -eu
|
| 3 |
+
mkdir -p /workspace/outputs
|
| 4 |
+
cp -R /solution/files/. /workspace/outputs/
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/task.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "apex-gap/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3"
|
| 5 |
+
|
| 6 |
+
[metadata.apex_gap]
|
| 7 |
+
capability_tags = ["legal-documents", "pdf-extraction"]
|
| 8 |
+
job = "corporate-law"
|
| 9 |
+
source = "theatticusproject/cuad"
|
| 10 |
+
source_license = "CC-BY-4.0"
|
| 11 |
+
source_revision = "a3c393f5d103fd0c516374e4fdff676c8176dcb1"
|
| 12 |
+
source_split = "train (cuad-qa@6d9a118fb629814c4384a1e63cfc84f5c01894b3 contract split)"
|
| 13 |
+
source_task_id = "GOLDRESOURCECORP_12_11_2008-EX-10.1-STRATEGIC ALLIANCE AGREEMENT.PDF:governing_law,anti_assignment,non_compete,most_favored_nation,insurance,source_code_escrow,non_disparagement"
|
| 14 |
+
task_kind = "single-contract-checklist"
|
| 15 |
+
|
| 16 |
+
[metadata.openenv_hf_sandbox]
|
| 17 |
+
variant = "apex-gap-hfsandbox-v1"
|
| 18 |
+
task_modified_for_hf_sandbox = true
|
| 19 |
+
network_enabled = true
|
| 20 |
+
|
| 21 |
+
[environment]
|
| 22 |
+
docker_image = "ghcr.io/younesbelkada/apex@sha256:24969c952247033023872f87161a16e067003469506be63783bbaa5d96926bdf"
|
| 23 |
+
workdir = "/workspace"
|
| 24 |
+
cpus = 1
|
| 25 |
+
memory_mb = 4096
|
| 26 |
+
build_timeout_sec = 600
|
| 27 |
+
network_mode = "public"
|
| 28 |
+
|
| 29 |
+
[agent]
|
| 30 |
+
timeout_sec = 1800
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
|
| 33 |
+
[verifier]
|
| 34 |
+
timeout_sec = 600
|
| 35 |
+
network_mode = "public"
|
| 36 |
+
environment_mode = "separate"
|
| 37 |
+
|
| 38 |
+
[verifier.environment]
|
| 39 |
+
network_mode = "public"
|
| 40 |
+
cpus = 1
|
| 41 |
+
memory_mb = 4096
|
| 42 |
+
|
| 43 |
+
[[artifacts]]
|
| 44 |
+
source = "/workspace/outputs"
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/tests/expected.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checks": [
|
| 3 |
+
{
|
| 4 |
+
"id": "governing_law",
|
| 5 |
+
"type": "answer",
|
| 6 |
+
"field": "governing_law",
|
| 7 |
+
"kind": "text",
|
| 8 |
+
"value": "New York",
|
| 9 |
+
"accept": [
|
| 10 |
+
"New York",
|
| 11 |
+
"State of New York",
|
| 12 |
+
"New York, USA",
|
| 13 |
+
"New York, United States"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"id": "anti_assignment",
|
| 18 |
+
"type": "answer",
|
| 19 |
+
"field": "anti_assignment",
|
| 20 |
+
"kind": "bool",
|
| 21 |
+
"value": true
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"id": "non_compete",
|
| 25 |
+
"type": "answer",
|
| 26 |
+
"field": "non_compete",
|
| 27 |
+
"kind": "bool",
|
| 28 |
+
"value": false
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "most_favored_nation",
|
| 32 |
+
"type": "answer",
|
| 33 |
+
"field": "most_favored_nation",
|
| 34 |
+
"kind": "bool",
|
| 35 |
+
"value": true
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"id": "insurance",
|
| 39 |
+
"type": "answer",
|
| 40 |
+
"field": "insurance",
|
| 41 |
+
"kind": "bool",
|
| 42 |
+
"value": true
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "source_code_escrow",
|
| 46 |
+
"type": "answer",
|
| 47 |
+
"field": "source_code_escrow",
|
| 48 |
+
"kind": "bool",
|
| 49 |
+
"value": false
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": "non_disparagement",
|
| 53 |
+
"type": "answer",
|
| 54 |
+
"field": "non_disparagement",
|
| 55 |
+
"kind": "bool",
|
| 56 |
+
"value": false
|
| 57 |
+
}
|
| 58 |
+
]
|
| 59 |
+
}
|
tasks/cuad-dd-goldresourcecorp-12-11-2008-ex-10-1-stra-56ce5e27-v3/tests/grade.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic grader shared by converted knowledge-work tasks.
|
| 2 |
+
|
| 3 |
+
Runs inside the separate verifier sandbox. Reads /tests/expected.json, inspects the
|
| 4 |
+
submitted /workspace/outputs tree and writes a binary reward plus per-check details.
|
| 5 |
+
No model calls and no network.
|
| 6 |
+
|
| 7 |
+
expected.json: {"checks": [{"id": ..., "type": ..., ...}, ...]}
|
| 8 |
+
Check types:
|
| 9 |
+
answer field of outputs/answer.json; kind = number|text|choice|date|bool|list
|
| 10 |
+
xlsx_range recalculated outputs/<file> vs tests/<target> over sheet!range (SpreadsheetBench rules)
|
| 11 |
+
xlsx_cell recalculated outputs/<file> sheet!cell vs value with tolerance (optional alt_values)
|
| 12 |
+
file_contains outputs/<file> text (docx/pdf/ics/eml/txt) must contain every needle
|
| 13 |
+
custom tests/<module>.py defines check(spec, outputs_dir, tests_dir) -> (bool, str)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import datetime as dt
|
| 17 |
+
import json
|
| 18 |
+
import re
|
| 19 |
+
import shutil
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import tempfile
|
| 23 |
+
import unicodedata
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
OUT = Path("/workspace/outputs")
|
| 27 |
+
TESTS = Path("/tests")
|
| 28 |
+
LOGS = Path("/logs/verifier")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def norm_text(v):
|
| 32 |
+
v = unicodedata.normalize("NFKC", str(v)).casefold()
|
| 33 |
+
v = re.sub(r"[‘’“”]", "'", v)
|
| 34 |
+
v = re.sub(r"[^\w%.$/-]+", " ", v)
|
| 35 |
+
return " ".join(v.split()).strip(" .")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def to_number(v):
|
| 39 |
+
if isinstance(v, bool):
|
| 40 |
+
raise ValueError("bool")
|
| 41 |
+
if isinstance(v, (int, float)):
|
| 42 |
+
return float(v)
|
| 43 |
+
s = str(v).strip().replace(",", "").replace("$", "").replace("−", "-")
|
| 44 |
+
neg = s.startswith("(") and s.endswith(")")
|
| 45 |
+
s = s.strip("()").strip()
|
| 46 |
+
pct = s.endswith("%")
|
| 47 |
+
s = s.rstrip("%").strip()
|
| 48 |
+
s = re.sub(r"\s*(usd|dollars|million|billion|thousand|m|bn|k)$", "", s, flags=re.I)
|
| 49 |
+
x = float(s)
|
| 50 |
+
x = -x if neg else x
|
| 51 |
+
return x / 100 if pct else x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def number_ok(got, want, rel, abs_):
|
| 55 |
+
try:
|
| 56 |
+
g = to_number(got)
|
| 57 |
+
except (TypeError, ValueError):
|
| 58 |
+
return False
|
| 59 |
+
w = float(want)
|
| 60 |
+
tol = max(abs_, rel * abs(w))
|
| 61 |
+
# "12.5%" may mean the ratio 0.125 or the percent number 12.5; the gold fixes which.
|
| 62 |
+
candidates = [g, g * 100] if isinstance(got, str) and got.strip().endswith("%") else [g]
|
| 63 |
+
return any(abs(c - w) <= tol for c in candidates)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_date(v):
|
| 67 |
+
if isinstance(v, (dt.date, dt.datetime)):
|
| 68 |
+
return v if isinstance(v, dt.date) else v.date()
|
| 69 |
+
s = str(v).strip()
|
| 70 |
+
for fmt in ("%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y", "%d %B %Y", "%B %d, %Y", "%b %d, %Y", "%Y/%m/%d"):
|
| 71 |
+
try:
|
| 72 |
+
return dt.datetime.strptime(s, fmt).date()
|
| 73 |
+
except ValueError:
|
| 74 |
+
continue
|
| 75 |
+
raise ValueError(s)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def check_answer(check, answers):
|
| 79 |
+
key = check["field"]
|
| 80 |
+
if key not in answers:
|
| 81 |
+
return False, f"missing field {key!r}"
|
| 82 |
+
got, want, kind = answers[key], check["value"], check.get("kind", "text")
|
| 83 |
+
if kind == "number":
|
| 84 |
+
ok = number_ok(got, want, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01))
|
| 85 |
+
if not ok and check.get("percent_either"):
|
| 86 |
+
ok = number_ok(got, want * 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) * 100) or (
|
| 87 |
+
number_ok(got, want / 100, check.get("rel_tol", 0.005), check.get("abs_tol", 0.01) / 100)
|
| 88 |
+
)
|
| 89 |
+
elif kind == "date":
|
| 90 |
+
try:
|
| 91 |
+
ok = parse_date(got) == parse_date(want)
|
| 92 |
+
except ValueError:
|
| 93 |
+
ok = False
|
| 94 |
+
elif kind == "bool":
|
| 95 |
+
g = norm_text(got)
|
| 96 |
+
ok = g in {"yes", "true"} if want else g in {"no", "false"}
|
| 97 |
+
elif kind == "choice":
|
| 98 |
+
ok = norm_text(got) == norm_text(want)
|
| 99 |
+
elif kind == "list":
|
| 100 |
+
if not isinstance(got, list):
|
| 101 |
+
return False, f"{key}: expected a JSON list"
|
| 102 |
+
# Filenames may be given with a directory prefix; compare base names.
|
| 103 |
+
base = lambda x: norm_text(str(x).replace("\\", "/").rsplit("/", 1)[-1])
|
| 104 |
+
ok = sorted(base(x) for x in got) == sorted(base(x) for x in want)
|
| 105 |
+
else:
|
| 106 |
+
accepted = check.get("accept", [want])
|
| 107 |
+
ok = norm_text(got) in {norm_text(a) for a in accepted}
|
| 108 |
+
return ok, "" if ok else f"{key}: got {got!r}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# LibreOffice keeps cached formula values on load unless told otherwise; force a full recalculation.
|
| 112 |
+
RECALC_PROFILE = """<?xml version="1.0" encoding="UTF-8"?>
|
| 113 |
+
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
| 114 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="OOXMLRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 115 |
+
<item oor:path="/org.openoffice.Office.Calc/Formula/Load"><prop oor:name="ODFRecalcMode" oor:op="fuse"><value>0</value></prop></item>
|
| 116 |
+
</oor:items>
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def recalc(path, tmp):
|
| 121 |
+
dest = Path(tmp) / f"recalc-{len(list(Path(tmp).glob('recalc-*')))}"
|
| 122 |
+
dest.mkdir()
|
| 123 |
+
profile = Path(tmp) / "lo-profile"
|
| 124 |
+
if not profile.exists():
|
| 125 |
+
(profile / "user").mkdir(parents=True)
|
| 126 |
+
(profile / "user" / "registrymodifications.xcu").write_text(RECALC_PROFILE)
|
| 127 |
+
subprocess.run(
|
| 128 |
+
["soffice", f"-env:UserInstallation=file://{profile}", "--headless", "--calc", "--convert-to",
|
| 129 |
+
"xlsx:Calc MS Excel 2007 XML", "--outdir", str(dest), str(path)],
|
| 130 |
+
stdout=subprocess.DEVNULL,
|
| 131 |
+
stderr=subprocess.DEVNULL,
|
| 132 |
+
timeout=180,
|
| 133 |
+
check=False,
|
| 134 |
+
)
|
| 135 |
+
out = dest / (Path(path).stem + ".xlsx")
|
| 136 |
+
return out if out.exists() else Path(path)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def cell_value(v):
|
| 140 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
| 141 |
+
return round(float(v), 2)
|
| 142 |
+
if isinstance(v, dt.datetime):
|
| 143 |
+
return round((v - dt.datetime(1899, 12, 30)).total_seconds() / 86400.0, 0)
|
| 144 |
+
if isinstance(v, dt.time):
|
| 145 |
+
return v.strftime("%H:%M")
|
| 146 |
+
if isinstance(v, str):
|
| 147 |
+
try:
|
| 148 |
+
return round(float(v), 2)
|
| 149 |
+
except ValueError:
|
| 150 |
+
return v.strip()
|
| 151 |
+
return v
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def time_of(v):
|
| 155 |
+
"""A time or a day fraction in [0, 1) as HH:MM, rounded to the nearest second first. Calc and
|
| 156 |
+
Excel store a time as that fraction; openpyxl returns a time only for time-formatted cells."""
|
| 157 |
+
if isinstance(v, dt.time):
|
| 158 |
+
v = (v.hour * 3600 + v.minute * 60 + v.second + v.microsecond / 1e6) / 86400
|
| 159 |
+
if isinstance(v, (int, float)) and not isinstance(v, bool) and 0 <= v < 1:
|
| 160 |
+
return (dt.datetime(1899, 12, 30) + dt.timedelta(seconds=round(v * 86400))).strftime("%H:%M")
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def same_cell(a, b):
|
| 165 |
+
if isinstance(a, dt.time) is not isinstance(b, dt.time):
|
| 166 |
+
n = b if isinstance(a, dt.time) else a
|
| 167 |
+
if time_of(n) is not None: # a time against a plain day fraction
|
| 168 |
+
return time_of(a) == time_of(b)
|
| 169 |
+
a, b = cell_value(a), cell_value(b)
|
| 170 |
+
if a in (None, "") and b in (None, ""):
|
| 171 |
+
return True
|
| 172 |
+
return type(a) is type(b) and a == b
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
ERRORS = {"#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def is_error(v):
|
| 179 |
+
return isinstance(v, str) and (v in ERRORS or v.startswith("Err:"))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def cells(rng):
|
| 183 |
+
if ":" not in rng:
|
| 184 |
+
return [rng]
|
| 185 |
+
from openpyxl.utils import range_boundaries, get_column_letter
|
| 186 |
+
|
| 187 |
+
c1, r1, c2, r2 = range_boundaries(rng)
|
| 188 |
+
return [f"{get_column_letter(c)}{r}" for r in range(r1, r2 + 1) for c in range(c1, c2 + 1)]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def load(path, tmp):
|
| 192 |
+
import openpyxl
|
| 193 |
+
|
| 194 |
+
return openpyxl.load_workbook(recalc(path, tmp), data_only=True)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def check_xlsx_range(check, tmp, cache):
|
| 198 |
+
sub = OUT / check["file"]
|
| 199 |
+
if not sub.is_file():
|
| 200 |
+
return False, f"missing output {check['file']}"
|
| 201 |
+
if sub not in cache:
|
| 202 |
+
cache[sub] = load(sub, tmp)
|
| 203 |
+
tgt = TESTS / check["target"]
|
| 204 |
+
if tgt not in cache:
|
| 205 |
+
cache[tgt] = load(tgt, tmp)
|
| 206 |
+
got, want = cache[sub], cache[tgt]
|
| 207 |
+
cached = None # the target's stored (Excel-computed) values, read only when Calc errs
|
| 208 |
+
for sheet, rng in check["ranges"]:
|
| 209 |
+
sheet = sheet or want.sheetnames[0]
|
| 210 |
+
if sheet not in got.sheetnames:
|
| 211 |
+
return False, f"sheet {sheet!r} missing"
|
| 212 |
+
for name in cells(rng):
|
| 213 |
+
w = want[sheet][name].value
|
| 214 |
+
if is_error(w):
|
| 215 |
+
# LibreOffice could not evaluate the gold formula (e.g. XLOOKUP, FILTER in Calc 7.4).
|
| 216 |
+
# The value Excel stored is the intended answer.
|
| 217 |
+
if cached is None:
|
| 218 |
+
import openpyxl
|
| 219 |
+
|
| 220 |
+
cached = openpyxl.load_workbook(tgt, data_only=True)
|
| 221 |
+
c = cached[sheet][name].value if sheet in cached.sheetnames else None
|
| 222 |
+
if c is not None and not is_error(c):
|
| 223 |
+
w = c
|
| 224 |
+
if not same_cell(w, got[sheet][name].value):
|
| 225 |
+
return False, f"{sheet}!{name}: want {w!r} got {got[sheet][name].value!r}"
|
| 226 |
+
return True, ""
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def check_xlsx_cell(check, tmp, cache):
|
| 230 |
+
sub = OUT / check["file"]
|
| 231 |
+
if not sub.is_file():
|
| 232 |
+
return False, f"missing output {check['file']}"
|
| 233 |
+
if sub not in cache:
|
| 234 |
+
cache[sub] = load(sub, tmp)
|
| 235 |
+
wb = cache[sub]
|
| 236 |
+
if check["sheet"] not in wb.sheetnames:
|
| 237 |
+
return False, f"sheet {check['sheet']!r} missing"
|
| 238 |
+
got = wb[check["sheet"]][check["cell"]].value
|
| 239 |
+
want = check["value"]
|
| 240 |
+
if isinstance(want, (int, float)):
|
| 241 |
+
# alt_values: other accepted golds where the source admits more than one reading.
|
| 242 |
+
ok = got is not None and any(number_ok(got, w, check.get("rel_tol", 0.0), check.get("abs_tol", 0.01))
|
| 243 |
+
for w in [want, *check.get("alt_values", [])])
|
| 244 |
+
else:
|
| 245 |
+
ok = norm_text(got) == norm_text(want)
|
| 246 |
+
return ok, "" if ok else f"{check['sheet']}!{check['cell']}: want {want!r} got {got!r}"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def text_of(path):
|
| 250 |
+
suffix = path.suffix.lower()
|
| 251 |
+
if suffix == ".docx":
|
| 252 |
+
import docx
|
| 253 |
+
|
| 254 |
+
d = docx.Document(path)
|
| 255 |
+
parts = [p.text for p in d.paragraphs]
|
| 256 |
+
for t in d.tables:
|
| 257 |
+
parts += [c.text for row in t.rows for c in row.cells]
|
| 258 |
+
return "\n".join(parts)
|
| 259 |
+
if suffix == ".pdf":
|
| 260 |
+
import pdfplumber
|
| 261 |
+
|
| 262 |
+
with pdfplumber.open(path) as pdf:
|
| 263 |
+
return "\n".join(page.extract_text() or "" for page in pdf.pages)
|
| 264 |
+
return path.read_text(errors="replace")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def check_file_contains(check, tmp, cache):
|
| 268 |
+
sub = OUT / check["file"]
|
| 269 |
+
if not sub.is_file():
|
| 270 |
+
return False, f"missing output {check['file']}"
|
| 271 |
+
text = text_of(sub)
|
| 272 |
+
hay = text if check.get("case_sensitive") else text.casefold()
|
| 273 |
+
for needle in check["needles"]:
|
| 274 |
+
n = needle if check.get("case_sensitive") else needle.casefold()
|
| 275 |
+
if n not in hay:
|
| 276 |
+
return False, f"{check['file']} lacks {needle!r}"
|
| 277 |
+
return True, ""
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def main():
|
| 281 |
+
LOGS.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
reward_path = LOGS / "reward.txt"
|
| 283 |
+
reward_path.write_text("0\n")
|
| 284 |
+
spec = json.loads((TESTS / "expected.json").read_text())
|
| 285 |
+
answers, details = {}, []
|
| 286 |
+
answer_file = OUT / "answer.json"
|
| 287 |
+
if answer_file.is_file():
|
| 288 |
+
try:
|
| 289 |
+
answers = json.loads(answer_file.read_text())
|
| 290 |
+
if not isinstance(answers, dict):
|
| 291 |
+
answers = {}
|
| 292 |
+
except json.JSONDecodeError:
|
| 293 |
+
answers = {}
|
| 294 |
+
tmp = tempfile.mkdtemp()
|
| 295 |
+
cache = {}
|
| 296 |
+
try:
|
| 297 |
+
for check in spec["checks"]:
|
| 298 |
+
try:
|
| 299 |
+
if check["type"] == "answer":
|
| 300 |
+
ok, why = check_answer(check, answers)
|
| 301 |
+
elif check["type"] == "xlsx_range":
|
| 302 |
+
ok, why = check_xlsx_range(check, tmp, cache)
|
| 303 |
+
elif check["type"] == "xlsx_cell":
|
| 304 |
+
ok, why = check_xlsx_cell(check, tmp, cache)
|
| 305 |
+
elif check["type"] == "file_contains":
|
| 306 |
+
ok, why = check_file_contains(check, tmp, cache)
|
| 307 |
+
elif check["type"] == "custom":
|
| 308 |
+
import importlib.util
|
| 309 |
+
|
| 310 |
+
spec_ = importlib.util.spec_from_file_location("custom_check", TESTS / f"{check['module']}.py")
|
| 311 |
+
mod = importlib.util.module_from_spec(spec_)
|
| 312 |
+
spec_.loader.exec_module(mod)
|
| 313 |
+
ok, why = mod.check(check, OUT, TESTS)
|
| 314 |
+
else:
|
| 315 |
+
ok, why = False, f"unknown check type {check['type']}"
|
| 316 |
+
except Exception as exc: # a malformed submission fails the check, not the grader
|
| 317 |
+
ok, why = False, f"{type(exc).__name__}: {exc}"
|
| 318 |
+
details.append({"id": check["id"], "passed": ok, "detail": why})
|
| 319 |
+
finally:
|
| 320 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 321 |
+
passed = sum(d["passed"] for d in details)
|
| 322 |
+
total = len(details)
|
| 323 |
+
reward = 1 if total and passed == total else 0
|
| 324 |
+
(LOGS / "details.json").write_text(json.dumps({"passed": passed, "total": total, "checks": details}, indent=1))
|
| 325 |
+
reward_path.write_text(f"{reward}\n")
|
| 326 |
+
print(f"{passed}/{total} checks passed; reward {reward}")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
if __name__ == "__main__":
|
| 330 |
+
sys.exit(main())
|