|
26 | 26 | run: | |
27 | 27 | python3 .github/pr81-fix.py |
28 | 28 | sed -i 's/appKey?: string;/appKey: string;/' src/app.ts |
| 29 | + python3 - <<'PY' |
| 30 | + from pathlib import Path |
| 31 | +
|
| 32 | + def replace_once(path: str, old: str, new: str) -> None: |
| 33 | + file = Path(path) |
| 34 | + text = file.read_text(encoding='utf-8') |
| 35 | + count = text.count(old) |
| 36 | + if count != 1: |
| 37 | + raise RuntimeError(f'{path}: expected one match, found {count}') |
| 38 | + file.write_text(text.replace(old, new, 1), encoding='utf-8') |
| 39 | +
|
| 40 | + def replace_all(path: str, old: str, new: str, expected: int) -> None: |
| 41 | + file = Path(path) |
| 42 | + text = file.read_text(encoding='utf-8') |
| 43 | + count = text.count(old) |
| 44 | + if count != expected: |
| 45 | + raise RuntimeError(f'{path}: expected {expected} matches, found {count}') |
| 46 | + file.write_text(text.replace(old, new), encoding='utf-8') |
| 47 | +
|
| 48 | + # App IDs are opaque at API boundaries; strict numeric validation is |
| 49 | + # limited to the selectApp/deleteApp CLI arguments that previously |
| 50 | + # used parseInt and could silently select a different ID. |
| 51 | + replace_once( |
| 52 | + 'src/app.ts', |
| 53 | + " const appId = String(parsePositiveIntegerId(String(options.appId)));\n", |
| 54 | + " const appId = String(options.appId);\n", |
| 55 | + ) |
| 56 | +
|
| 57 | + helper = """\nasync function withInteractiveStdin<T>(\n task: () => Promise<T>,\n): Promise<T> {\n const descriptor = Object.getOwnPropertyDescriptor(process.stdin, 'isTTY');\n Object.defineProperty(process.stdin, 'isTTY', {\n configurable: true,\n value: true,\n });\n try {\n return await task();\n } finally {\n if (descriptor) {\n Object.defineProperty(process.stdin, 'isTTY', descriptor);\n } else {\n Reflect.deleteProperty(process.stdin, 'isTTY');\n }\n }\n}\n""" |
| 58 | +
|
| 59 | + replace_once( |
| 60 | + 'tests/package-optimization.test.ts', |
| 61 | + "import * as utils from '../src/utils';\n", |
| 62 | + "import * as utils from '../src/utils';\n" + helper, |
| 63 | + ) |
| 64 | + replace_all( |
| 65 | + 'tests/package-optimization.test.ts', |
| 66 | + " const result = await choosePackage('app123');\n", |
| 67 | + " const result = await withInteractiveStdin(() =>\n choosePackage('app123'),\n );\n", |
| 68 | + 2, |
| 69 | + ) |
| 70 | +
|
| 71 | + replace_once( |
| 72 | + 'tests/versions.test.ts', |
| 73 | + "} from '../src/versions';\n", |
| 74 | + "} from '../src/versions';\n" + helper, |
| 75 | + ) |
| 76 | + replace_once( |
| 77 | + 'tests/versions.test.ts', |
| 78 | + """ await publish({\n args: ['bundle.ppk'],\n options: { platform: 'android' },\n });\n""", |
| 79 | + """ await withInteractiveStdin(() =>\n publish({\n args: ['bundle.ppk'],\n options: { platform: 'android' },\n }),\n );\n""", |
| 80 | + ) |
| 81 | + PY |
29 | 82 | rm .github/pr81-fix.py .github/workflows/pr81-autofix.yml |
30 | 83 |
|
31 | 84 | - uses: oven-sh/setup-bun@v2 |
|
0 commit comments