"""Focused HTTP acceptance for original-file references and generated Markdown attachments.""" import argparse import json import uuid from pathlib import Path import httpx def run(base,build_id): passed=[] def check(value,name): if not value:raise AssertionError(name) passed.append(name);print('PASS '+name,flush=True) with httpx.Client(base_url=base,timeout=120,trust_env=False) as client,httpx.Client(base_url=base,timeout=120,trust_env=False) as other: health=client.get('/health/live');health.raise_for_status() check(health.json().get('build_id')==build_id,'expected build is live') check(health.json().get('mode')=='public-isolated-real','real model mode') def login(c,prefix,name,password): result=c.post(prefix+'/auth/login',json={'username':name,'password':password});result.raise_for_status() return {'Authorization':'Bearer '+result.json()['access_token']} user=login(client,'/api/v1','lin','demo123');peer=login(other,'/api/v1','lin','demo123') admin=login(client,'/manage/api/v1','admin','admin123') def call(method,path,data=None): result=client.request(method,path,json=data,headers={**user,'Idempotency-Key':uuid.uuid4().hex});result.raise_for_status();return result.json() settings=client.get('/manage/api/v1/admin/llm',headers=admin);settings.raise_for_status();settings=settings.json() check(settings['credential_storage']=='space-bound-aes256-gcm' and settings['credential_space_id']=='dellweb3/workos-office','Space-bound encrypted credentials active') wid=call('POST','/api/v1/workspaces',{'title':'原文件展示发布验收'})['workspace_id'] text='原文件发布验收标记\r\n'+''.join(f'原始记录第{i}行,责任人需要核对资料及期限。\r\n' for i in range(750))+'原文件结尾' original=text.encode('utf-8') upload=client.post('/api/v1/workspaces/'+wid+'/attachments',files={'file':('会议原始记录.txt',original,'text/plain')},headers={**user,'Idempotency-Key':uuid.uuid4().hex});upload.raise_for_status() hit=call('POST','/api/v1/knowledge/search',{'workspace_id':wid,'query':'原文件发布验收标记','base_ids':['kb-personal'],'top_k':3})['items'][0] path='/api/v1/citations/'+hit['citation_id'] source=call('GET',path+'/document?workspace_id='+wid) check(source['text']==text and source['preview_scope']=='document','long original previews completely without overlapping fragments') downloaded=client.get(path+'/original',params={'workspace_id':wid},headers=user);downloaded.raise_for_status() check(downloaded.content==original,'original download matches uploaded bytes') denied=other.get(path+'/document',params={'workspace_id':wid},headers=peer) check(denied.status_code==404,'original remains isolated between visitors') meeting_wid=call('POST','/api/v1/workspaces',{'title':'会议纪要 MD 发布验收'})['workspace_id'] result=call('POST','/api/v1/workspaces/'+meeting_wid+'/chat',{'content':'2026年11月12日会议确定:周宁在11月13日17点前补齐模板,陈敏同一天完成权限核对,核对完成后再开放知识库。请整理会议纪要。','employee_id':'meeting-assistant'}) check(result['mode']=='real' and bool(result['meeting']),'meeting generated by real model') aid=result['artifact']['artifact_id'];files=result.get('files',[]) check(any(f['artifact_id']==aid and f['filename'].endswith('.md') for f in files),'meeting workflow returns generated Markdown attachment') md_path='/api/v1/artifacts/'+aid+'/export.md' md=client.get(md_path,headers=user);md.raise_for_status() check(md.content==result['artifact']['content'].encode('utf-8') and md.headers['content-type'].startswith('text/markdown'),'Markdown download matches complete generated minutes') check(md.headers.get('content-disposition','').endswith('.md'),'Markdown has downloadable filename') check(other.get(md_path,headers=peer).status_code==404,'generated Markdown remains isolated between visitors') turns=call('GET','/api/v1/workspaces/'+meeting_wid+'/chat-turns')['items'] check(any(t.get('files')==files for t in turns),'generated attachment survives reopening conversation') js=client.get('/employee/office.js');js.raise_for_status() app=client.get('/employee/app.js');app.raise_for_status() check('data-export-md' in js.text and '生成的附件' in js.text,'attachment card and Markdown download button deployed') check('sourceDocuments(items)' in app.text and "+'/document'" in app.text,'file-grouped reference UI and full-document preview deployed') return {'status':'passed','profile':'documents-and-md','checks':passed,'count':len(passed),'build_id':build_id,'base_url':base} if __name__=='__main__': parser=argparse.ArgumentParser();parser.add_argument('base_url');parser.add_argument('--build-id',required=True);parser.add_argument('--out',required=True);args=parser.parse_args() try: result=run(args.base_url,args.build_id) Path(args.out).write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') print(json.dumps({'status':result['status'],'passed':result['count']},ensure_ascii=False)) except Exception as exc: print('Document acceptance failed: '+type(exc).__name__) raise SystemExit(1)