|
| 1 | +import os,json,subprocess |
| 2 | +from pathlib import Path |
| 3 | +root=Path.cwd() |
| 4 | +report={'config':[]} |
| 5 | +def config(value): |
| 6 | + env=dict(os.environ) |
| 7 | + if value is None:env.pop('NEXT_BUILD_PERSISTENT_CACHE',None) |
| 8 | + else:env['NEXT_BUILD_PERSISTENT_CACHE']=value |
| 9 | + code="import config from './next.config.ts'; process.stdout.write(JSON.stringify({cache:config.experimental?.turbopackFileSystemCacheForBuild}));" |
| 10 | + r=subprocess.run(['bun','--no-env-file','-e',code],cwd=root/'apps/sim',env=env,capture_output=True,text=True,check=True) |
| 11 | + return json.loads(r.stdout)['cache'] |
| 12 | +try: |
| 13 | + for value,expected in [(None,False),('false',False),('true',True)]: |
| 14 | + actual=config(value);report['config'].append({'flag':value,'expected':expected,'actual':actual});assert actual==expected,'Explicit compiler cache opt-in did not enable the cache' |
| 15 | + def task_hash(value): |
| 16 | + env={**os.environ,'NEXT_BUILD_PERSISTENT_CACHE':value} |
| 17 | + r=subprocess.run(['bunx','turbo','run','build','--filter=@sim/app','--dry=json'],env=env,capture_output=True,text=True,check=True) |
| 18 | + tasks=json.loads(r.stdout)['tasks'];return next(t['hash'] for t in tasks if t['taskId']=='@sim/app#build') |
| 19 | + report['hashes']={v:task_hash(v) for v in ['true','false']};assert len(set(report['hashes'].values()))==2,'Compiler cache modes share a build cache key' |
| 20 | + p=root/'apps/sim/turbo.json';original=p.read_bytes() |
| 21 | + try: |
| 22 | + d=json.loads(original);d['tasks']['build']['env'].remove('NEXT_BUILD_PERSISTENT_CACHE');p.write_text(json.dumps(d)) |
| 23 | + report['missingGuardHashes']={v:task_hash(v) for v in ['true','false']};assert len(set(report['missingGuardHashes'].values()))==1,'Expected removed cache guard to lose flag distinction' |
| 24 | + finally:p.write_bytes(original) |
| 25 | +finally: |
| 26 | + Path(os.environ['RUNNER_TEMP'],'compiler-config-report.json').write_text(json.dumps(report,indent=2)) |
| 27 | +print(json.dumps(report,indent=2)) |
0 commit comments