|
| 1 | +from pathlib import Path |
| 2 | +import json,os,subprocess,time |
| 3 | +out=Path(os.environ['RUNNER_TEMP']);config=Path('scripts/tsconfig.json');source=Path('scripts/prune-turbopack-cache.mts');original_config=config.read_text();original_source=source.read_text();report={} |
| 4 | +def run(args): |
| 5 | + start=time.monotonic();r=subprocess.run(args,capture_output=True,text=True,timeout=120);return r,(time.monotonic()-start) |
| 6 | +def included(text): |
| 7 | + return any(Path(line.strip()).resolve()==source.resolve() for line in text.splitlines() if line.strip()) |
| 8 | +try: |
| 9 | + r,_=run(['bunx','tsc','--version']);assert r.returncode==0 and 'Version 7.' in r.stdout,(r.stdout,r.stderr);report['compiler']=r.stdout.strip() |
| 10 | + old=json.loads(original_config);old['include']=[p for p in old['include'] if not p.endswith('.mts')];config.write_text(json.dumps(old)) |
| 11 | + r,seconds=run(['bunx','tsc','--project',str(config),'--listFilesOnly']);report['before']={'included':included(r.stdout),'exit':r.returncode,'seconds':seconds};assert not included(r.stdout),'Old project unexpectedly includes maintenance script' |
| 12 | + config.write_text(original_config) |
| 13 | + r,seconds=run(['bunx','tsc','--project',str(config),'--listFilesOnly']);report['after']={'included':included(r.stdout),'exit':r.returncode,'seconds':seconds};assert included(r.stdout),'Fixed project still excludes maintenance script' |
| 14 | + command=['bun','run','type-check:scripts:esm'] |
| 15 | + r,seconds=run(command);report['typecheck']={'exit':r.returncode,'seconds':seconds};assert r.returncode==0,(r.stdout+r.stderr) |
| 16 | + old='const limit = BUILD_CACHE ?';assert original_source.count(old)==1;source.write_text(original_source.replace(old,'const limit: string = BUILD_CACHE ?')) |
| 17 | + r,seconds=run(command);text=r.stdout+r.stderr;(out/'mts-negative-control.log').write_text(text);report['negative']={'exit':r.returncode,'seconds':seconds,'expectedDiagnostic':'TS2322' in text and 'prune-turbopack-cache.mts' in text};assert r.returncode!=0 and report['negative']['expectedDiagnostic'],text |
| 18 | + source.write_text(original_source) |
| 19 | + r,seconds=run(command);report['restored']={'exit':r.returncode,'seconds':seconds};assert r.returncode==0,r.stdout+r.stderr |
| 20 | +finally: |
| 21 | + config.write_text(original_config);source.write_text(original_source);(out/'mts-typecheck-proof.json').write_text(json.dumps(report,indent=2));print(json.dumps(report,indent=2)) |
0 commit comments