"""Publish once; no published evidence is rewritten."""
from pathlib import Path
import json,hashlib,html
root=Path.cwd();out=root/'engine/public/benchmarks/text-markdown1';out.mkdir(exist_ok=False);r=root/'benchmarks/research/text-markdown1'
v=json.loads((r/'local1-validation.json').read_text());b=json.loads((r/'qa/local-browser.json').read_text());c=json.loads((r/'comparison.json').read_text())
assert v['downloads']==6 and len(v['checks'])==24 and not v['failures']
assert b['stats']['expected']==10 and b['stats']['unexpected']==0 and b['stats']['flaky']==0
assert len(c['rows'])==2 and all(row['tabmorph']['literalBlockMatches']for row in c['rows'])
def copy(p,name):
 q=out/name;q.parent.mkdir(parents=True,exist_ok=True);q.write_bytes(p.read_bytes())
for group,base in [('fixtures',root/'benchmarks/fixtures/text-markdown1'),('local1',r/'local1'),('cloud1',r/'cloud1')]:
 for p in base.rglob('*'):
  if p.is_file():copy(p,Path(group)/p.relative_to(base))
for name in ['local1-validation.json','comparison.json','contact.png','contact-method.json','contact-render.json']:copy(r/name,Path(name))
copy(r/'qa/local-browser.json',Path('local-browser.json'))
for name in ['generate-text-markdown-fixtures.py','validate-text-markdown.py','render-text-markdown-comparison.py','capture-text-markdown-contact.mjs','publish-text-markdown-evidence.py']:copy(root/'scripts'/name,Path('drivers')/name)
copy(root/'e2e/text-markdown.spec.ts',Path('drivers/text-markdown.spec.ts'))
for name in ['commonmark-0.9.1.whl','LICENSE.txt','provenance.json']:copy(root/'benchmarks/research/word-text-breaks/qa-reader'/name,Path('reader')/name)
q={'goalComplete':False,'newNormalizedPairs':1,'newFormats':0,'originalCorpora':2,'encodingDerivatives':1,'localBrowserCases':10,'corpusDownloads':6,'independentChecks':24,'independentFailures':0,'cloudRequests':2,'contract':v['contract'],'competitiveScope':c['scope'],'observedControls':{'decomposedAcute':{'source':1,'tabmorph':1,'cloudDefault':0},'tabs':{'source':2,'tabmorph':2,'cloudDefault':0},'linesEndingInTwoSpaces':{'source':2,'tabmorph':2,'cloudDefault':0}},'limitations':['Literal code-block output; no inferred prose formatting','CRLF/CR to LF; missing final newline gains one','Readers that omit fenced code blocks cannot display the content','Two original synthetic corpora and one encoding derivative are not broad document compatibility evidence','Size points use different provider formatting defaults and are not rate-distortion curves','CloudConvert prose/default formatting is a different contract; broad competitive quality UNVERIFIED']}
(out/'quality.json').write_text(json.dumps(q,indent=2,ensure_ascii=False)+'\n')
(out/'README.txt').write_text('TXT to Markdown: original CC0 corpora, unchanged default CloudConvert reference outputs/settings/task IDs, six offline Chromium/WebKit corpus downloads and independent CommonMark 0.9.1 literal-text checks. Text remains in one code block without interpreting HTML, links, emphasis or fence runs. Existing whitespace stays literal; CRLF/CR becomes LF and a missing final newline gains one. UTF-16 is an encoding derivative, not a third original. CloudConvert defaults create different prose/code formatting. Specific source controls are measured; broad quality superiority and matched size advantage are unverified. Raw source/reference/download bytes remain unchanged. The contact PNG is presentation only; its HTML source is retained in Git and excluded here because engine CSP intentionally refuses document framing. Production verification is retained separately in the repository. No user-file uploads, new dependencies, payments, accounts, ads or CSP changes.\n')
names=sorted(str(p.relative_to(out))for p in out.rglob('*')if p.is_file())
(out/'index.html').write_text('<!doctype html><meta charset="utf-8"><title>TXT to Markdown: literal-text comparisons</title><h1>TXT to Markdown: literal-text comparisons</h1><p>Two original corpora, two same-input CloudConvert references. Specific controls only; broad competitive quality remains UNVERIFIED.</p><p><a href="quality.json">Scope</a> · <a href="files.json">Hashes</a> · <a href="README.txt">Method</a></p><ul>'+''.join('<li><a href="'+html.escape(n,quote=True)+'">'+html.escape(n)+'</a></li>'for n in names)+'</ul>')
pins={}
for p in sorted(out.rglob('*')):
 if p.is_file():data=p.read_bytes();pins[str(p.relative_to(out))]={'bytes':len(data),'sha256':hashlib.sha256(data).hexdigest()}
(out/'files.json').write_text(json.dumps(pins,indent=2)+'\n');raw=(out/'files.json').read_bytes();print(json.dumps({'physicalFiles':len(pins)+1,'manifestSha256':hashlib.sha256(raw).hexdigest()}))
