chore: preserve opaque app IDs and interactive tests #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR 81 reviewed fixes | |
| on: | |
| push: | |
| branches: | |
| - claude/comprehensive-audit-optimization-suldrn | |
| paths: | |
| - .github/pr81-fix.py | |
| - .github/workflows/pr81-autofix.yml | |
| permissions: | |
| contents: write | |
| jobs: | |
| apply-test-publish: | |
| if: github.actor != 'github-actions[bot]' | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| timeout-minutes: 30 | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Apply reviewed fixes | |
| run: | | |
| python3 .github/pr81-fix.py | |
| sed -i 's/appKey?: string;/appKey: string;/' src/app.ts | |
| python3 - <<'PY' | |
| from pathlib import Path | |
| def replace_once(path: str, old: str, new: str) -> None: | |
| file = Path(path) | |
| text = file.read_text(encoding='utf-8') | |
| count = text.count(old) | |
| if count != 1: | |
| raise RuntimeError(f'{path}: expected one match, found {count}') | |
| file.write_text(text.replace(old, new, 1), encoding='utf-8') | |
| def replace_all(path: str, old: str, new: str, expected: int) -> None: | |
| file = Path(path) | |
| text = file.read_text(encoding='utf-8') | |
| count = text.count(old) | |
| if count != expected: | |
| raise RuntimeError(f'{path}: expected {expected} matches, found {count}') | |
| file.write_text(text.replace(old, new), encoding='utf-8') | |
| # App IDs are opaque at API boundaries; strict numeric validation is | |
| # limited to the selectApp/deleteApp CLI arguments that previously | |
| # used parseInt and could silently select a different ID. | |
| replace_once( | |
| 'src/app.ts', | |
| " const appId = String(parsePositiveIntegerId(String(options.appId)));\n", | |
| " const appId = String(options.appId);\n", | |
| ) | |
| 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""" | |
| replace_once( | |
| 'tests/package-optimization.test.ts', | |
| "import * as utils from '../src/utils';\n", | |
| "import * as utils from '../src/utils';\n" + helper, | |
| ) | |
| replace_all( | |
| 'tests/package-optimization.test.ts', | |
| " const result = await choosePackage('app123');\n", | |
| " const result = await withInteractiveStdin(() =>\n choosePackage('app123'),\n );\n", | |
| 2, | |
| ) | |
| replace_once( | |
| 'tests/versions.test.ts', | |
| "} from '../src/versions';\n", | |
| "} from '../src/versions';\n" + helper, | |
| ) | |
| replace_once( | |
| 'tests/versions.test.ts', | |
| """ await publish({\n args: ['bundle.ppk'],\n options: { platform: 'android' },\n });\n""", | |
| """ await withInteractiveStdin(() =>\n publish({\n args: ['bundle.ppk'],\n options: { platform: 'android' },\n }),\n );\n""", | |
| ) | |
| PY | |
| rm .github/pr81-fix.py .github/workflows/pr81-autofix.yml | |
| - uses: oven-sh/setup-bun@v2 | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Format, lint, and typecheck | |
| run: bun run lint:fix | |
| - name: Run tests with coverage | |
| run: bun run test:coverage | |
| - name: Build package | |
| run: bun run build | |
| - name: Set up the oldest supported Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: '18.17.0' | |
| - name: Run Node 18 smoke tests | |
| run: node scripts/smoke-lib.js | |
| - name: Commit tested fixes | |
| run: | | |
| git diff --check | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "fix: address PR review findings" | |
| git push --force origin HEAD:refs/heads/pr81-reviewed-fixes |