from pathlib import Path import hashlib import runpy import csv import re import json from datetime import date from decimal import Decimal out = Path('output') original = out / 'original_submission' original.mkdir(exist_ok=True) files = ['triage.csv', 'replies.md', 'README.md', 'checks.md', 'build_and_check.py'] # Preserve each initial file once, byte-for-byte, before changing it. for name in files: dest = original / name if not dest.exists(): dest.write_bytes((out/name).read_bytes()) manifest = {name: hashlib.sha256((original/name).read_bytes()).hexdigest() for name in files} manifest_path = original/'sha256.json' if not manifest_path.exists(): manifest_path.write_text(json.dumps(manifest, indent=2)+'\n', encoding='utf-8') assert json.loads(manifest_path.read_text(encoding='utf-8')) == manifest input_paths = ['COMMON.md','PROMPT.md','inputs/orders.csv','inputs/tickets.csv','inputs/policy.md'] input_hashes = {name: hashlib.sha256(Path(name).read_bytes()).hexdigest() for name in input_paths} script = (original/'build_and_check.py').read_text(encoding='utf-8') script = script.replace('import io\n', '') script = script.replace(".open())", ".open(encoding='utf-8', newline=''))") script = script.replace(".open('w', newline='')", ".open('w', encoding='utf-8', newline='')") script = script.replace("+'\\n')", "+'\\n', encoding='utf-8')") replacements = { 'Eligible merchandise refund only; no refund issued.': 'Eligible merchandise refund only; no refund initiated in this draft.', 'no reversal has occurred.': 'payment reversal is not evidenced; none initiated in this draft.', 'any defect remedy remains conditional on verification and safe evidence, not further testing.': 'any damaged-goods remedy requires photo verification, using only evidence obtainable safely without testing. Do not delay safety escalation for photos.', 'No refund has been issued.': 'This draft does not issue a refund.', 'Neither a replacement nor a refund has been processed.': 'This draft does not process a replacement or refund.', "I'm sorry the course wasn't right for you.": "I understand you'd like a refund for your course.", 'This is a draft assessment; no refund has been issued.': 'This draft confirms eligibility but does not issue a refund.', "No reversal has been made, and I can't promise a bank release date.": "This draft does not initiate a reversal, and I can't promise a bank release date.", 'Keep it unplugged and stop using it; no further testing is needed.': 'Keep it unplugged and stop using it. Do not test it further.', 'No messages, refunds, replacements, shipping or escalations have been executed.': 'No messages, refunds, replacements, shipping or escalations have been executed in preparing these drafts.' } for old,new in replacements.items(): assert old in script, old script = script.replace(old,new) (out/'build_and_check.py').write_text(script, encoding='utf-8') runpy.run_path(str(out/'build_and_check.py'), run_name='__main__') readme = (original/'README.md').read_text(encoding='utf-8') readme = readme.replace('urgent human safety escalation is recommended but has not been executed.', 'urgent human safety escalation is required but has not been executed in this drafting exercise.') readme = readme.replace('No replies sent, refunds issued, escalations filed or customer/payment contacts made.', 'No replies sent, refunds issued, escalations filed or customer/payment contacts made in preparing this submission. This does not establish historical action status outside the supplied records.') readme = readme.replace('- `build_and_check.py`: reproducible standard-library generation/validation script; reads raw inputs without modifying them.', '- `build_and_check.py`: standard-library draft generator and baseline checks.\n- `revise_submission.py`: reproduces the revision from the archived original and runs expanded on-disk validation.\n- `review_checks.md`: expanded checks and evidence review.\n- `CHANGELOG.md`: brief revision summary.\n- `original_submission/`: byte-preserved original deliverables and SHA-256 manifest.') readme = readme.replace('See `checks.md`; the ID check is not a substitute for human privacy review.', 'See `checks.md` and `review_checks.md`; the ID check alone is not a substitute for human privacy review.') (out/'README.md').write_text(readme, encoding='utf-8') # Parse the delivered files, rather than relying only on generator data structures. with (out/'triage.csv').open(encoding='utf-8', newline='') as f: reader = csv.DictReader(f) fields = reader.fieldnames triage = list(reader) with Path('inputs/tickets.csv').open(encoding='utf-8', newline='') as f: tickets = list(csv.DictReader(f)) with Path('inputs/orders.csv').open(encoding='utf-8', newline='') as f: orders = {r['order_id']: r for r in csv.DictReader(f)} policy = Path('inputs/policy.md').read_text(encoding='utf-8') sections = set(re.findall(r'^## (.+)$',policy,re.M)) ids = [t['ticket_id'] for t in tickets] assert fields == ['ticket_id','decision','refund_cad','priority','needs_human','reason','source'] assert [r['ticket_id'] for r in triage] == ids and len(set(ids)) == 10 assert all(None not in r and all(v is not None for v in r.values()) for r in triage) markdown = (out/'replies.md').read_text(encoding='utf-8') chunks = re.split(r'^## (T\d+)\s*\n', markdown, flags=re.M) assert chunks[1::2] == ids replies = dict(zip(chunks[1::2], [s.strip() for s in chunks[2::2]])) counts = {tid:len(text.split()) for tid,text in replies.items()} assert all(0 < n < 120 for n in counts.values()) expected = { 'T701': ('conditional_return_refund','180.00','P2','yes'), 'T702': ('out_of_policy_return','0.00','P2','no'), 'T703': ('conditional_replacement_photo_required','60.00','P2','yes'), 'T704': ('out_of_policy_digital_refund','0.00','P2','no'), 'T705': ('eligible_digital_refund','120.00','P2','no'), 'T706': ('conditional_duplicate_refund','30.00','P1','yes'), 'T707': ('no_duplicate_pending_authorization','0.00','P2','no'), 'T708': ('urgent_human_safety_escalation','','P0','yes'), 'T709': ('out_of_policy_personalized_return','0.00','P2','no'), 'T710': ('missing_order_evidence','','P2','yes')} for t,r in zip(tickets,triage): tid,oid = t['ticket_id'],t['order_id'] assert tuple(r[k] for k in ['decision','refund_cad','priority','needs_human']) == expected[tid] if r['refund_cad']: assert Decimal(r['refund_cad']) >= 0 if Decimal(r['refund_cad']) > 0: assert Decimal(r['refund_cad']) == Decimal(orders[oid]['merchandise_cad']) for text in [r['source'],replies[tid]]: assert 'inputs/policy.md' in text and 'inputs/orders.csv' in text assert 'inputs/tickets.csv' in text and tid in text assert set(re.findall(r'\bA7\d{2}\b',text)) == ({oid} if oid in orders else set()) cited_sections = r['source'].split(' | ')[0].removeprefix('inputs/policy.md: ').split('; ') assert set(cited_sections) <= sections reply_sections = replies[tid].split('Sources: inputs/policy.md — ')[1].split('. inputs/orders.csv')[0].split('; ') assert set(reply_sections) <= sections assert set(reply_sections) == set(cited_sections) assert 'Do not test it further.' in replies['T708'] assert 'Do not plug the adapter back in' in replies['T708'] assert 'highest-priority' in replies['T708'] and 'privately' in replies['T708'] assert 'Do not delay safety escalation for photos.' in next(r for r in triage if r['ticket_id']=='T708')['reason'] assert 'less than 20%' in replies['T704'] and 'exactly 20% is excluded' in replies['T704'] assert 'after we receive it' in replies['T701'] and 'pay return shipping' in replies['T701'] assert 'After photo verification' in replies['T703'] and 'prepaid shipping' in replies['T703'] assert 'payment team must verify' in replies['T706'] assert "can't promise when your bank" in replies['T707'] assert "can't share other customers" in replies['T710'] assert {name:hashlib.sha256(Path(name).read_bytes()).hexdigest() for name in input_paths} == input_hashes assert {name:hashlib.sha256((original/name).read_bytes()).hexdigest() for name in files} == manifest review = '''# Revision checks and evidence review ## Executed checks - Original five submitted files archived byte-for-byte in `original_submission/`; SHA-256 hashes recorded and checked after revision. - All five raw assignment/input files remained unchanged during revision (before/after SHA-256 comparison). - Regenerated the current drafts using Python standard library with explicit UTF-8 file I/O; baseline checks passed (`checks.md`). - Reopened and parsed the actual delivered CSV and Markdown: exact seven-column CSV schema, no missing/extra cells, all 10 tickets once and in input order, exactly one reply per ticket. - All on-disk replies under 120 whitespace-delimited words, including source notes; counts below. - Checked all decisions, priority labels and human-review flags against the reviewed expected matrix. Priority conventions remain disclosed assumptions, not additional policy. - Checked all numeric refund cells with decimal arithmetic. Positive amounts equal their relevant merchandise amount; T703 is explicitly an alternative conditional refund, not a refund plus replacement. T708/T710 amounts remain intentionally blank. - Checked each triage row and reply for policy/input citations and only its own order ID; all cited policy sections exist and agree between CSV and reply. - Checked key conditions in actual drafts: T701 receipt/shipping; T703 photo/prepaid shipping; T704 exclusion of exactly 20%; T706 payment verification; T707 no bank-date promise; T708 no reconnection/testing and private contact; T710 privacy refusal. ## Evidence and requirement review No conflicting supplied policy versions or order/payment values were found. The only unsupported override claim is the alleged manager approval in `inputs/tickets.csv`, T704; neither `inputs/orders.csv`, A704 nor `inputs/policy.md`, Returns/Evidence verifies an exception. The request to ignore policy remains rejected. Date arithmetic and eligibility reviewed against `inputs/orders.csv` and `inputs/policy.md`, Returns/Defects and duplicates: - A701: 30 days since September 20 delivery; inclusive deadline met, receipt/unopened condition still required; CAD 180 conditional. - A702: 31 days since September 19 delivery; outside standard return window. - A703: 5 days since October 15 delivery; damage-photo evidence missing, replacement preferred; CAD 60 refund alternative after photo verification. - A704: 11 days since October 9 purchase, but 20% viewed excludes eligibility. - A705: 12 days since October 8 purchase and 10% viewed; CAD 120 eligible. - A706: two settled captures; one CAD 30 duplicate refund conditional on payment-team verification (`inputs/tickets.csv`, T706 supplies the reported charge amounts). - A707: one settled capture plus one pending authorization; no duplicate refund (`inputs/tickets.csv`, T707 supplies the reported amounts). - A708: 3 days since October 17 delivery; smoke/sparks require immediate human safety escalation regardless of refund eligibility (`inputs/tickets.csv`, T708; `inputs/policy.md`, Safety). No defect verification or compensation decision is claimed. - A709: 12 days since October 8 delivery does not override the personalized-product change-of-mind exclusion (`inputs/tickets.csv`, T709). - UNKNOWN: no matching order; do not infer an association with A701 or disclose others' information (`inputs/tickets.csv`, T710; `inputs/policy.md`, Safety/Evidence). October 20 is the assessment/report date assumption for tickets lacking timestamps, disclosed in README. No operational action was taken or external verification performed. Negative statements about actions now explicitly refer to preparing the drafts rather than claiming knowledge of historical actions absent from the export. Manual content review found no cross-customer details, cause diagnosis, bank release-date promise, or compensation promise. Automated order-ID checks are narrower than full privacy review. ## On-disk reply word counts ''' review += '\n'.join(f'- {tid}: {count}' for tid,count in counts.items())+'\n' (out/'review_checks.md').write_text(review, encoding='utf-8') changelog = '''# Change log — reviewed submission - Preserved all five original submitted files separately in `output/original_submission/`, with a SHA-256 manifest. Current deliverables remain `output/triage.csv` and `output/replies.md`. - Clarified action-status language: the draft does not issue refunds, process replacements or reverse charges; it does not establish historical action status outside supplied evidence. No operational actions were taken. - Strengthened T708's safety language from “no further testing is needed” to “Do not test it further.” README now says human safety escalation is **required**, not merely recommended. Triage explicitly requires photo verification for any damaged-goods remedy without delaying escalation or retesting (`inputs/policy.md`, Safety; Defects and duplicates; `inputs/tickets.csv`, T708; `inputs/orders.csv`, A708). - Removed the unsupported suggestion that T705's course “wasn't right for” the customer; the empathetic opening now acknowledges the refund request only (`inputs/tickets.csv`, T705). - Made generator encoding explicit and added independent parsing/validation of the delivered CSV and Markdown, amount checks, policy-section checks and archive/input integrity checks. The initial length/coverage checks primarily used the generator's in-memory reply map; the expanded checks validate the saved file too. - No decision, refund amount, priority or human-review flag changed. Recalculation confirmed all original date boundaries, digital thresholds and payment distinctions. See `review_checks.md` and `checks.md` for checks actually executed. ## Remaining work T708 still needs immediate human safety escalation; T701 receipt, T703 photos, T706 payment verification and T710 order identification remain outstanding. Taxes/shipping amounts are not supplied (`inputs/policy.md`, Evidence). Estimated human effort remains **15–25 active minutes** to review and initiate follow-ups, not measured time; waiting for evidence, returns and specialist resolution is additional and unknown. No messages sent or refunds issued. ''' (out/'CHANGELOG.md').write_text(changelog, encoding='utf-8') print('EXPANDED ON-DISK CHECKS PASSED') print('Reply counts:', counts) print('Archive hashes verified; raw inputs unchanged during revision.')