diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index aabbcf4..56e3949 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -41,6 +41,11 @@ jobs: - name: Lint if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: bun run lint + - name: iOS release-record consistency tests and draft check + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: | + node --test scripts/ios-release/*.test.mjs + node scripts/ios-release/check.mjs - name: Unit and backend tests if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: bun run test diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore new file mode 100644 index 0000000..b57f48a --- /dev/null +++ b/apps/mobile/.gitignore @@ -0,0 +1,2 @@ +# Editable release records are source, unlike generated desktop release output. +!/release/ diff --git a/apps/mobile/APP-STORE.md b/apps/mobile/APP-STORE.md new file mode 100644 index 0000000..07c6f93 --- /dev/null +++ b/apps/mobile/APP-STORE.md @@ -0,0 +1,81 @@ +# iOS release tracker + +Status: preparation only. No approved public name, signed candidate, App Store record, TestFlight acceptance or public release is recorded here. The current native app still uses Convex. A JavaScript export does not prove an offline iOS release. + +Parent: [#38](https://github.com/HemSoft/yahtzee/issues/38). Release records: [#47](https://github.com/HemSoft/yahtzee/issues/47). + +## Ownership and authority + +The repository maintainer owns implementation, repeatable checks and evidence collection. The owner must approve public identity and rights, contact publication, price/territories, legal declarations, spending, external tester invitations, App Review submission and publication. A green script does not supply those approvals. Keep credentials, private contact information, identity documents and signing keys out of GitHub. + +## Proposed scope, not a legal approval + +Use the existing Expo/React Native app and shared TypeScript engine. The reversible engineering baseline is one local human, zero to three AI opponents, mobile presets of five/six/eight/ten dice and English. Preserve the current Castle rule of two distinct triples and the all-dice-matching rule in larger games. Do not invent a dedicated six-of-a-kind category or treat these choices as an owner-approved public rules contract. + +Proposed v1 excludes accounts, remote multiplayer, cloud scores/sync, analytics, ads, purchases, subscriptions, Game Center, widgets and Watch. Device/orientation/minimum-OS details require native qualification. Keep the current development identifier private to development; do not reserve or publish an App Store identity under it. + +The release scope and rights decision remains [#39](https://github.com/HemSoft/yahtzee/issues/39). Existing repository branding and its MIT license are not trademark clearance. + +## Candidate mapping and checks + +[release/candidate.json](release/candidate.json) is an explicitly incomplete 1.0.0, build 1 proposal, separate from Windows 0.1.0. It links the [iOS changelog](CHANGELOG.md), [TestFlight notes](release/testflight-notes.md), [listing sources](release/metadata/en-US/listing.json) and [screenshot manifest](release/screenshots.json). + +From the repository root: + +```sh +node --test scripts/ios-release/*.test.mjs +node scripts/ios-release/check.mjs +``` + +Draft mode validates the record and source-file structure, prints every remaining release blocker, and never uploads anything. `consistent: false` is expected now. It is not a release pass. + +For a real candidate, configure the accepted native version/build first. Compare the proposed build number against the latest App Store Connect build and every prior local archive; increment it and never reuse an uploaded number. Commit the approved source and metadata. Copy the record to an ignored `reports/ios-candidate.json` and fill its exact source SHA and artifact/evidence references there. Do not try to embed a commit's own SHA inside itself. + +```sh +node scripts/ios-release/check.mjs --release \ + --record reports/ios-candidate.json --archive reports/accepted.ipa \ + --screenshots reports/ios-captures/manifest.json +``` + +The release check fails on an incomplete record, dirty source, mismatched native identity/version/build, wrong source SHA or archive checksum, draft copy, absent listing fields or screenshot provenance mismatch. All referenced copy and planning files must be tracked and match HEAD after CRLF/LF normalization, so clean Windows checkouts remain valid. Ignored, absolute and untracked source paths are rejected. + +The tracked screenshot JSON is a scene plan, not a capture receipt. Generate the accepted capture manifest beside the images after freezing the source commit, then store its SHA-256 in the external candidate record. Give it status `accepted`, matching sourceCommit/version/buildNumber, and a nonempty captures array. Each capture needs filename relative to that artifact folder, sourceCommit, deviceFamily `iphone` or `ipad`, locale, appearance `light` or `dark`, pixel width/height, and SHA-256. The checker verifies each file's PNG signature, dimensions and hash; capture paths and symlinks cannot escape that folder. This does not replace visual review or Apple's current device-size requirements. Set listing status to `approved` only after the owner approves the copy. Each `sourceReviews` role also needs `approved` and the SHA-256 of its accepted UTF-8 text with LF line endings. Any later text change invalidates that receipt. Remove draft instructions and placeholders from accepted test and store notes. These recorded statuses do not grant legal authority; the maintainer must verify the owner's evidence separately. This is a consistency guard, not a signing validator or proof that cited owner/device evidence is genuine. Review those receipts separately. If dynamic Expo configuration replaces app.json, update the checker to consume the resolved configuration before using it for release. + +Retain the accepted JSON beside the archive and sanitized QA receipts. Its iOS tag must point to the source SHA. On public release, verify the matching GitHub tag/release, public App Store version and dated changelog entry. No automatic release/changelog workflow currently publishes these files; do not duplicate Unreleased entries in generated notes if one is introduced. + +## Editable content + +The local metadata layout is Fastlane-style, but no Fastlane/EAS upload is configured. [description.txt](release/metadata/en-US/description.txt), [review_notes.txt](release/metadata/en-US/review_notes.txt) and [release_notes.txt](release/metadata/en-US/release_notes.txt) are clearly marked drafts. Null listing fields are unresolved decisions, not accepted defaults. Never upload these templates unchanged. First-release What's New may be absent in App Store Connect; do not require an updates-only field for the initial version. + +## Release checklist and evidence + +Leave a checkbox open until its linked receipt proves the exact candidate. + +| Gate | Owner | Evidence and prerequisite | +| --- | --- | --- | +| Public identity, rights, scope, commerce | Owner | [#39](https://github.com/HemSoft/yahtzee/issues/39), not approved | +| Shared baseline and native configuration | Maintainer | [#40](https://github.com/HemSoft/yahtzee/issues/40), baseline PR under review | +| Offline saves, recovery and resume | Maintainer | [#41](https://github.com/HemSoft/yahtzee/issues/41), real-device evidence required | +| Native UI and accessibility | Maintainer and device tester | [#42](https://github.com/HemSoft/yahtzee/issues/42) | +| Team/app record, price, territories, EULA, trader status, age rating | Owner | [#43](https://github.com/HemSoft/yahtzee/issues/43), App Store state not verified | +| Rules, support, privacy, reset and review paths | Maintainer | [#44](https://github.com/HemSoft/yahtzee/issues/44) | +| Original licensed icon/launch assets | Maintainer and owner | [#45](https://github.com/HemSoft/yahtzee/issues/45) | +| Native CI, archive, signing, checksum | Maintainer and signing owner | [#46](https://github.com/HemSoft/yahtzee/issues/46) | +| Data flows, native manifests, privacy/export declarations | Maintainer and owner | [#48](https://github.com/HemSoft/yahtzee/issues/48) | +| Public marketing/support/privacy URLs | Maintainer and owner | [#49](https://github.com/HemSoft/yahtzee/issues/49) | +| Listing fields, claims and previews | Maintainer and owner | [#50](https://github.com/HemSoft/yahtzee/issues/50) | +| Ordered native screenshots | Maintainer | [#51](https://github.com/HemSoft/yahtzee/issues/51) | +| Signed TestFlight acceptance | Device tester and owner | [#52](https://github.com/HemSoft/yahtzee/issues/52) | +| Submission approval, review correspondence and Apple approval | Owner | [#53](https://github.com/HemSoft/yahtzee/issues/53) | +| Publication, store-installed smoke, source tag and support check | Owner and maintainer | [#54](https://github.com/HemSoft/yahtzee/issues/54) | + +- [ ] Record accepted app ID, bundle ID, version/build, source commit, archive hash and private receipt locations. +- [ ] Confirm all implementation and native QA gates, including offline restart and save recovery on iPhone and iPad. +- [ ] Recheck [Apple upload requirements](https://developer.apple.com/news/upcoming-requirements/) and [submission requirements](https://developer.apple.com/app-store/submitting/). +- [ ] Review current privacy/export/age/content-rights answers and owner approvals against the actual archive. +- [ ] Verify public URLs, localized copy, screenshots and required App Store Connect fields without placeholders. +- [ ] Get explicit TestFlight upload/invitation and App Review submission approval. Record sanitized IDs/status separately. +- [ ] Default to manual first release; obtain explicit publication approval after Apple approval. +- [ ] Verify the live listing and store-installed app, publish the dated iOS changelog/tag, and assign post-release support. + +No checkbox is complete merely because this document exists. Update this tracker when each gate changes; record dates in Eastern Time. diff --git a/apps/mobile/CHANGELOG.md b/apps/mobile/CHANGELOG.md new file mode 100644 index 0000000..be7b54f --- /dev/null +++ b/apps/mobile/CHANGELOG.md @@ -0,0 +1,15 @@ +# iOS changelog + +No iOS version has shipped. Windows and web changes have their own release history. + +## Unreleased + +### Added + +- Draft release records, editable listing sources and a fail-closed candidate check. Tracked in [#47](https://github.com/HemSoft/yahtzee/issues/47). + +## Release entry format + +After public-store verification, move the applicable Unreleased entries under `## 1.0.0 - YYYY-MM-DD`, using the release date in Eastern Time. Include the exact iOS build, source commit, source tag and public listing link. Link implementation PRs; do not list planned features as shipped. + +Later entries use Added, Changed and Fixed only when applicable. App Store What's New text is a short summary of that release's user-visible changes. The first submission may not expose this updates-only field. Never invent a prior release or a release date to fill it. diff --git a/apps/mobile/release/candidate.json b/apps/mobile/release/candidate.json new file mode 100644 index 0000000..aab6cad --- /dev/null +++ b/apps/mobile/release/candidate.json @@ -0,0 +1,20 @@ +{ + "schemaVersion": 1, + "status": "draft", + "version": "1.0.0", + "buildNumber": "1", + "sourceCommit": null, + "tag": "ios/v1.0.0", + "appStoreVersion": "1.0.0", + "appStoreId": null, + "bundleIdentifier": null, + "archiveSha256": null, + "screenshotManifestSha256": null, + "testFlightBuildId": null, + "ownerApprovalEvidence": null, + "nativeQualificationEvidence": null, + "changelog": "CHANGELOG.md", + "testNotes": "release/testflight-notes.md", + "metadataDirectory": "release/metadata/en-US", + "screenshots": "release/screenshots.json" +} diff --git a/apps/mobile/release/metadata/en-US/description.txt b/apps/mobile/release/metadata/en-US/description.txt new file mode 100644 index 0000000..5f84086 --- /dev/null +++ b/apps/mobile/release/metadata/en-US/description.txt @@ -0,0 +1,7 @@ +DRAFT, NOT APPROVED FOR UPLOAD + +Proposed first-release copy, contingent on native implementation and device qualification: + +Play a local dice game on iPhone or iPad. Roll, hold dice and choose a scoring combination. Play solo or against up to three computer opponents. The proposed release keeps games and scores on your device and works offline. + +Replace this draft only after the supported modes, house rules, resume behavior, original public name and rights are approved. Do not claim remote multiplayer, cloud leaderboards, licensed affiliation or unqualified accessibility support. diff --git a/apps/mobile/release/metadata/en-US/listing.json b/apps/mobile/release/metadata/en-US/listing.json new file mode 100644 index 0000000..d6aec25 --- /dev/null +++ b/apps/mobile/release/metadata/en-US/listing.json @@ -0,0 +1,21 @@ +{ + "status": "draft", + "sourceReviews": { + "description": { "status": "draft", "sha256": null }, + "reviewNotes": { "status": "draft", "sha256": null }, + "releaseNotes": { "status": "draft", "sha256": null }, + "testNotes": { "status": "draft", "sha256": null } + }, + "name": null, + "subtitle": null, + "promotionalText": null, + "keywords": null, + "copyright": null, + "supportUrl": null, + "marketingUrl": null, + "privacyUrl": null, + "accessibilityUrl": null, + "primaryCategory": null, + "secondaryCategory": null, + "notes": "Owner-approved identity, contact details, commercial/legal decisions and tested claims are required. Null is deliberately incomplete, not an upload value." +} diff --git a/apps/mobile/release/metadata/en-US/release_notes.txt b/apps/mobile/release/metadata/en-US/release_notes.txt new file mode 100644 index 0000000..5a49ced --- /dev/null +++ b/apps/mobile/release/metadata/en-US/release_notes.txt @@ -0,0 +1,3 @@ +DRAFT, NOT APPROVED FOR UPLOAD + +First iOS release, pending implementation, qualification and approval. Do not publish this placeholder. For the first submission, omit What's New if App Store Connect does not expose it. Later versions summarize only the user-visible changes in the corresponding dated iOS changelog entry. diff --git a/apps/mobile/release/metadata/en-US/review_notes.txt b/apps/mobile/release/metadata/en-US/review_notes.txt new file mode 100644 index 0000000..297f80a --- /dev/null +++ b/apps/mobile/release/metadata/en-US/review_notes.txt @@ -0,0 +1,5 @@ +DRAFT, NOT APPROVED FOR SUBMISSION + +After native qualification, describe the actual offline access, account requirements, dice modes, house rules, computer opponents, persistence, reset and support paths. Provide numbered steps through the shipping app, not a fixture mode or developer server. Do not claim that Convex has been removed until the native release proves it. + +Enter review contact information privately in App Store Connect. Do not commit contact phone numbers, credentials, tester details or private review correspondence here. diff --git a/apps/mobile/release/screenshots.json b/apps/mobile/release/screenshots.json new file mode 100644 index 0000000..5318abe --- /dev/null +++ b/apps/mobile/release/screenshots.json @@ -0,0 +1,11 @@ +{ + "status": "not-captured", + "sourceCommit": null, + "version": "1.0.0", + "buildNumber": "1", + "locales": ["en-US"], + "scenes": ["setup", "hold-dice", "score-combination", "bonus-progress", "results", "history"], + "captures": [], + "appPreview": "deferred", + "note": "No approved native captures yet. Record device family, pixel dimensions, appearance, locale, filename, SHA-256 and source commit for each accepted capture. Verify Apple's current listing requirements before capture or upload." +} diff --git a/apps/mobile/release/testflight-notes.md b/apps/mobile/release/testflight-notes.md new file mode 100644 index 0000000..bc28c85 --- /dev/null +++ b/apps/mobile/release/testflight-notes.md @@ -0,0 +1,11 @@ +# Proposed 1.0 testing notes + +Draft only. No signed candidate has been accepted or uploaded. + +Before inviting testers, bind these notes to the exact source commit, version, build and TestFlight build ID in candidate.json. Confirm the shipped app's behavior before replacing this draft with tester-facing copy. + +Test offline cold launch, all approved dice modes, solo and three AI opponents, hold/reroll/score, bonus thresholds, results, duplicate-save prevention, backgrounding, force termination and explicit resume/discard. Exercise corrupt and interrupted storage recovery, an upgrade from the previous beta, support previews and reset confirmation. + +Record iPhone and iPad models/OS versions without device identifiers or tester email addresses. Include VoiceOver, large text, Reduce Motion, safe areas, allowed rotation and iPad resizing. Link sanitized results in the release tracker. A JavaScript export or mobile web adapter is not native device evidence. + +External invitations require owner approval. Uploading a build does not submit it for App Review or publish it. diff --git a/bun.lock b/bun.lock index 6b81650..6b2285c 100644 --- a/bun.lock +++ b/bun.lock @@ -26,6 +26,7 @@ "mutation-testing-metrics": "3.8.4", "mutation-testing-report-schema": "3.9.0", "playwright": "1.63.0", + "pngjs": "7.0.0", "react": "19.2.3", "react-dom": "19.2.3", "react-native-web": "0.21.2", @@ -1337,7 +1338,7 @@ "plist": ["plist@3.1.1", "", { "dependencies": { "@xmldom/xmldom": "^0.9.10", "base64-js": "^1.5.1", "xmlbuilder": "^15.1.1" } }, "sha512-ZIfcLJC+7E7FBFnDxm9MPmt7D+DidyQ26lewieO75AdhA2ayMtsJSES0iWzqJQbcVRSrTufQoy0DR94xHue0oA=="], - "pngjs": ["pngjs@3.4.0", "", {}, "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="], + "pngjs": ["pngjs@7.0.0", "", {}, "sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow=="], "postcss": ["postcss@8.5.28", "", { "dependencies": { "nanoid": "^3.3.18", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A=="], @@ -1981,6 +1982,8 @@ "ora/chalk": ["chalk@2.4.2", "", { "dependencies": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" } }, "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ=="], + "parse-png/pngjs": ["pngjs@3.4.0", "", {}, "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="], + "path-scurry/lru-cache": ["lru-cache@11.5.2", "", {}, "sha512-4pfM1Ff0x50o0tQwb5ucw/RzNyD0/YJME6IVcStalZuMWxdt3sR3huStTtxz4PUmvZfRguvDejasvQ2kifR11g=="], "plist/@xmldom/xmldom": ["@xmldom/xmldom@0.9.12", "", {}, "sha512-5AXjrcMClTryPe9LgZrygpB1lj7s0S9E0+W+AHaVKAVyHanafK86iPSvG5xHVSp/jC+VH1UXu0TAEmY279xH7A=="], diff --git a/package.json b/package.json index e8d4572..7985d0c 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "mutation-testing-metrics": "3.8.4", "mutation-testing-report-schema": "3.9.0", "playwright": "1.63.0", + "pngjs": "7.0.0", "react": "19.2.3", "react-dom": "19.2.3", "react-native-web": "0.21.2", diff --git a/scripts/ios-release/check.mjs b/scripts/ios-release/check.mjs new file mode 100644 index 0000000..e1e47dd --- /dev/null +++ b/scripts/ios-release/check.mjs @@ -0,0 +1,79 @@ +import { readFileSync } from "node:fs"; +import { resolve, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; +import { execFileSync } from "node:child_process"; +import { sha256, readSource, copyBlockers, screenshotBlockers, artifactImageReader } from "./evidence.mjs"; + +export function draftErrors(record) { + if (!record || typeof record !== "object" || Array.isArray(record)) return ["Record must be an object"]; + const errors = []; + if (record.schemaVersion !== 1) errors.push("Unsupported record schema"); + if (!/^\d+\.\d+\.\d+$/.test(record.version ?? "")) errors.push("Invalid marketing version"); + if (typeof record.buildNumber !== "string" || !/^[1-9]\d*$/.test(record.buildNumber)) errors.push("Build number must be a positive integer string"); + if (record.tag !== `ios/v${record.version}`) errors.push("Tag does not match the iOS version"); + if (record.appStoreVersion !== record.version) errors.push("App Store version mismatch"); + if (!["draft", "candidate"].includes(record.status)) errors.push("Unknown candidate status"); + return errors; +} + +export function releaseBlockers(record, context) { + const blockers = [...draftErrors(record)]; + if (blockers.length) return blockers; + if (record.status !== "candidate") blockers.push("Candidate is still a draft"); + if (!/^[a-f0-9]{40}$/.test(record.sourceCommit ?? "") || record.sourceCommit !== context.commit) blockers.push("Source commit does not match HEAD"); + if (context.dirty) blockers.push("Tracked or untracked source changes remain"); + if (record.version !== context.expo.version) blockers.push("Native marketing version mismatch"); + if (record.buildNumber !== context.expo.ios?.buildNumber) blockers.push("Native build number mismatch"); + if (!record.bundleIdentifier || record.bundleIdentifier !== context.expo.ios?.bundleIdentifier) blockers.push("Approved bundle identifier missing or mismatched"); + if (!/^[1-9]\d*$/.test(record.appStoreId ?? "")) blockers.push("App Store app ID missing"); + if (!/^[a-f0-9]{64}$/.test(record.archiveSha256 ?? "") || record.archiveSha256 !== context.archiveSha256) blockers.push("Archive checksum missing or mismatched"); + for (const key of ["testFlightBuildId", "ownerApprovalEvidence", "nativeQualificationEvidence"]) { + if (typeof record[key] !== "string" || !record[key].trim()) blockers.push(`${key} missing`); + } + return blockers; +} + +function sourceFiles(record, mobile, committedBytes) { + const metadata = record.metadataDirectory; + const sources = { changelog: record.changelog, testNotes: record.testNotes, screenshots: record.screenshots, + listing: `${metadata}/listing.json`, description: `${metadata}/description.txt`, + reviewNotes: `${metadata}/review_notes.txt`, releaseNotes: `${metadata}/release_notes.txt` }; + return Object.entries(sources).map(([role, path]) => ({ ...readSource(mobile, path, committedBytes), role })); +} + +export function listingRecord(files) { + return JSON.parse(files.find((file) => file.role === "listing").text); +} + +function run() { + const mobile = resolve(dirname(fileURLToPath(import.meta.url)), "../../apps/mobile"); + const args = process.argv.slice(2); + const release = args.includes("--release"); + const option = (key) => args.includes(key) ? args[args.indexOf(key) + 1] : undefined; + const record = JSON.parse(readFileSync(resolve(option("--record") ?? resolve(mobile, "release/candidate.json")), "utf8")); + const errors = draftErrors(record); + if (errors.length) throw new Error(errors.join("; ")); + const root = resolve(mobile, "../.."); + const git = (...parts) => execFileSync("git", parts, { cwd: root, encoding: "utf8" }).trim(); + const committedBytes = (path) => execFileSync("git", ["show", `HEAD:${path}`], { cwd: root }); + const files = sourceFiles(record, mobile, release ? committedBytes : undefined); + const archive = option("--archive"); + const context = { + commit: git("rev-parse", "HEAD"), dirty: Boolean(git("status", "--porcelain")), + expo: JSON.parse(readFileSync(resolve(mobile, "app.json"), "utf8")).expo, + archiveSha256: archive ? sha256(readFileSync(resolve(archive))) : null, + }; + const blockers = releaseBlockers(record, context); + const listing = listingRecord(files); + blockers.push(...copyBlockers(files, listing)); + const screenshotPath = option("--screenshots"); + if (screenshotPath) { + const bytes = readFileSync(resolve(screenshotPath)); + if (sha256(bytes) !== record.screenshotManifestSha256) blockers.push("Screenshot manifest checksum mismatch"); + blockers.push(...screenshotBlockers(JSON.parse(bytes.toString("utf8")), record, artifactImageReader(dirname(resolve(screenshotPath))))); + } else blockers.push("Accepted screenshot artifact manifest missing"); + console.log(JSON.stringify({ mode: release ? "release" : "draft", version: record.version, build: record.buildNumber, consistent: blockers.length === 0, blockers, note: "Consistency only. This command does not validate signing, grant approval, upload, submit or publish." }, null, 2)); + if (release && blockers.length) process.exitCode = 1; +} + +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) run(); diff --git a/scripts/ios-release/check.test.mjs b/scripts/ios-release/check.test.mjs new file mode 100644 index 0000000..1f99da4 --- /dev/null +++ b/scripts/ios-release/check.test.mjs @@ -0,0 +1,45 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { draftErrors, releaseBlockers, listingRecord } from "./check.mjs"; + +const commit = "a".repeat(40); +const archiveSha256 = "b".repeat(64); +function candidate() { + return { schemaVersion: 1, status: "candidate", version: "1.0.0", buildNumber: "1", tag: "ios/v1.0.0", appStoreVersion: "1.0.0", sourceCommit: commit, bundleIdentifier: "example.originalgame", appStoreId: "123456", archiveSha256, testFlightBuildId: "test-build", ownerApprovalEvidence: "test-reference", nativeQualificationEvidence: "test-reference" }; +} +function context() { + return { commit, dirty: false, archiveSha256, expo: { version: "1.0.0", ios: { buildNumber: "1", bundleIdentifier: "example.originalgame" } } }; +} + +test("listing selection uses the assigned role, not another source's filename", () => { + const files = [ + { role: "changelog", path: "misleading/listing.json", text: '{"status":"approved"}' }, + { role: "listing", path: "metadata/listing.json", text: '{"status":"draft"}' }, + ]; + assert.equal(listingRecord(files).status, "draft"); +}); + +test("draft shape accepts an explicitly incomplete proposal without asserting readiness", () => { + const draft = { ...candidate(), status: "draft", sourceCommit: null, archiveSha256: null, ownerApprovalEvidence: null }; + assert.deepEqual(draftErrors(draft), []); + assert.ok(releaseBlockers(draft, context()).length >= 4); +}); +test("rejects invalid schemas, malformed versions and non-string build numbers", () => { + for (const input of [null, [], { ...candidate(), schemaVersion: 2 }, { ...candidate(), version: "latest" }, { ...candidate(), buildNumber: 1 }, { ...candidate(), buildNumber: "0" }, { ...candidate(), tag: "v1.0.0" }, { ...candidate(), appStoreVersion: "2.0.0" }]) assert.ok(draftErrors(input).length); +}); +test("a matching synthetic record passes only the consistency check", () => { + assert.deepEqual(releaseBlockers(candidate(), context()), []); +}); +test("rejects stale source, dirty checkout, native version/build/identity drift and archive drift", () => { + const variants = [ + { ...context(), commit: "c".repeat(40) }, { ...context(), dirty: true }, + { ...context(), expo: { ...context().expo, version: "0.1.0" } }, + { ...context(), expo: { version: "1.0.0", ios: { buildNumber: "2", bundleIdentifier: "example.originalgame" } } }, + { ...context(), expo: { version: "1.0.0", ios: { buildNumber: "1", bundleIdentifier: "other.app" } } }, + { ...context(), archiveSha256: null }, + ]; + for (const value of variants) assert.ok(releaseBlockers(candidate(), value).length); +}); +test("requires app, beta and evidence references without claiming to authenticate them", () => { + for (const key of ["appStoreId", "testFlightBuildId", "ownerApprovalEvidence", "nativeQualificationEvidence"]) assert.ok(releaseBlockers({ ...candidate(), [key]: null }, context()).length); +}); diff --git a/scripts/ios-release/evidence.mjs b/scripts/ios-release/evidence.mjs new file mode 100644 index 0000000..4aed6a8 --- /dev/null +++ b/scripts/ios-release/evidence.mjs @@ -0,0 +1,79 @@ +import { readFileSync, realpathSync } from "node:fs"; +import { isAbsolute, resolve, relative, sep } from "node:path"; +import { createHash } from "node:crypto"; +import { PNG } from "pngjs"; + +export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex"); + +export function relativeSource(path) { + if (typeof path !== "string" || isAbsolute(path) || !/^[A-Za-z0-9][A-Za-z0-9_./-]*$/.test(path) || path.split("/").includes("..")) throw new Error("Source paths must be repository-relative"); + return path; +} + +export function readSource(mobile, path, committedBytes) { + relativeSource(path); + const bytes = readFileSync(resolve(mobile, path)); + // git show fails for ignored/untracked files, and bytes must match that commit. + const text = bytes.toString("utf8").replaceAll("\r\n", "\n"); + if (committedBytes && text !== committedBytes(`apps/mobile/${path}`).toString("utf8").replaceAll("\r\n", "\n")) throw new Error(`Source differs from committed text: ${path}`); + if (!text.trim()) throw new Error(`Empty release source: ${path}`); + return { path, text }; +} + +export function copyBlockers(files, listing) { + const blockers = []; + for (const file of files) { + if (/DRAFT, NOT APPROVED|\bDraft only\b|\bNOT APPROVED FOR (?:UPLOAD|SUBMISSION)\b|Do not publish this placeholder|pending implementation|After native qualification, describe|replacing this draft with tester-facing copy/i.test(file.text)) blockers.push(`Unapproved copy: ${file.path}`); + } + if (listing.status !== "approved") blockers.push("Listing status is not approved"); + for (const role of ["description", "reviewNotes", "releaseNotes", "testNotes"]) { + const source = files.find((file) => file.role === role); + const review = listing.sourceReviews?.[role]; + if (!source || review?.status !== "approved" || review.sha256 !== sha256(Buffer.from(source.text.replaceAll("\r\n", "\n")))) blockers.push(`Source review missing or stale: ${role}`); + } + for (const key of ["name", "subtitle", "keywords", "primaryCategory", "copyright", "supportUrl", "marketingUrl", "privacyUrl"]) { + if (typeof listing[key] !== "string" || !listing[key].trim()) blockers.push(`Listing field missing: ${key}`); + } + return blockers; +} + +export function captureBlockers(capture, record, readImage) { + const blockers = []; + if (!capture || typeof capture !== "object") return ["Invalid screenshot capture"]; + if (capture.sourceCommit !== record.sourceCommit) blockers.push("Capture source commit mismatch"); + if (!["iphone", "ipad"].includes(capture.deviceFamily)) blockers.push("Capture device family missing"); + if (!/^[a-z]{2}(?:-[A-Z]{2})?$/.test(capture.locale ?? "")) blockers.push("Capture locale missing"); + if (!["light", "dark"].includes(capture.appearance)) blockers.push("Capture appearance missing"); + if (!Number.isSafeInteger(capture.width) || !Number.isSafeInteger(capture.height) || capture.width <= 0 || capture.height <= 0) blockers.push("Capture dimensions invalid"); + try { + const bytes = readImage(relativeSource(capture.filename)); + const png = bytes.length >= 33 && bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) && bytes.toString("ascii", 12, 16) === "IHDR"; + if (!png) throw new Error("Invalid PNG header"); + // Bound decode allocation before trusting any dimensions in the artifact. + const width = bytes.readUInt32BE(16), height = bytes.readUInt32BE(20); + if (bytes.length > 64 * 1024 * 1024 || width > 8192 || height > 8192 || width * height > 32_000_000) throw new Error("PNG exceeds capture limits"); + const image = PNG.sync.read(bytes); + if (image.width !== capture.width || image.height !== capture.height) blockers.push("Capture dimensions do not match PNG"); + if (sha256(bytes) !== capture.sha256) blockers.push("Capture checksum mismatch"); + } catch { blockers.push("Capture file missing, invalid PNG, or outside artifact directory"); } + return blockers; +} + +export function screenshotBlockers(manifest, record, readImage) { + if (!manifest || manifest.status !== "accepted") return ["Screenshot manifest is not accepted"]; + const blockers = []; + if (manifest.sourceCommit !== record.sourceCommit || manifest.version !== record.version || manifest.buildNumber !== record.buildNumber) blockers.push("Screenshot provenance mismatch"); + if (!Array.isArray(manifest.captures) || manifest.captures.length === 0) return [...blockers, "No native screenshot captures recorded"]; + for (const capture of manifest.captures) blockers.push(...captureBlockers(capture, record, readImage)); + return blockers; +} + +export function artifactImageReader(directory) { + const root = realpathSync(directory); + return (filename) => { + const file = realpathSync(resolve(root, relativeSource(filename))); + const inside = relative(root, file); + if (inside.startsWith(`..${sep}`) || isAbsolute(inside)) throw new Error("Capture escapes artifact directory"); + return readFileSync(file); + }; +} diff --git a/scripts/ios-release/evidence.test.mjs b/scripts/ios-release/evidence.test.mjs new file mode 100644 index 0000000..f38938f --- /dev/null +++ b/scripts/ios-release/evidence.test.mjs @@ -0,0 +1,70 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { relativeSource, readSource, copyBlockers, screenshotBlockers, sha256, artifactImageReader } from "./evidence.mjs"; + +import { PNG } from "pngjs"; + +const png = PNG.sync.write(new PNG({ width: 1, height: 1 })); +const record = { sourceCommit: "a".repeat(40), version: "1.0.0", buildNumber: "1" }; +const capture = { filename: "iphone.png", sourceCommit: record.sourceCommit, deviceFamily: "iphone", locale: "en-US", appearance: "light", width: 1, height: 1, sha256: sha256(png) }; +const manifest = { ...record, status: "accepted", captures: [capture] }; + +test("source paths reject absolute and parent traversal", () => { + for (const path of ["/tmp/secret", "C:/secret", "../secret", "release/../../secret", null]) assert.throws(() => relativeSource(path)); + assert.equal(relativeSource("release/metadata/en-US/listing.json"), "release/metadata/en-US/listing.json"); +}); +test("release source must exist in the commit and match its bytes", () => { + const root = mkdtempSync(join(tmpdir(), "ios-source-")); + try { + writeFileSync(join(root, "copy.txt"), "approved copy"); + assert.equal(readSource(root, "copy.txt", () => Buffer.from("approved copy")).text, "approved copy"); + assert.throws(() => readSource(root, "copy.txt", () => Buffer.from("other copy")), /differs/); + writeFileSync(join(root, "copy.txt"), "approved\r\ncopy\r\n"); + assert.equal(readSource(root, "copy.txt", () => Buffer.from("approved\ncopy\n")).text, "approved\ncopy\n"); + mkdirSync(join(root, "reports")); writeFileSync(join(root, "reports", "untracked.txt"), "ignored draft"); + assert.throws(() => readSource(root, "reports/untracked.txt", () => { throw new Error("not in commit"); }), /not in commit/); + } finally { rmSync(root, { recursive: true }); } +}); +test("mixed-case draft notes and structured draft statuses cannot pass", () => { + const listing = { status: "approved", name: "Game", subtitle: "Dice", keywords: "dice", primaryCategory: "GAMES", copyright: "Owner", supportUrl: "https://example.test/support", marketingUrl: "https://example.test", privacyUrl: "https://example.test/privacy" }; + const files = ["description", "reviewNotes", "releaseNotes", "testNotes"].map((role) => ({ path: role, role, text: "Accepted copy" })); + listing.sourceReviews = Object.fromEntries(files.map((file) => [file.role, { status: "approved", sha256: sha256(Buffer.from(file.text)) }])); + assert.deepEqual(copyBlockers(files, listing), []); + for (const key of ["primaryCategory", "keywords"]) assert.ok(copyBlockers(files, { ...listing, [key]: null }).length); + assert.ok(copyBlockers([{ ...files[0], text: "Changed after review" }, ...files.slice(1)], listing).length); + for (const text of ["Draft only. No signed candidate", "draft, not approved for upload", "NOT APPROVED FOR SUBMISSION", "Do not publish this placeholder", "pending implementation", "After native qualification, describe...", "replacing this draft with tester-facing copy"]) assert.ok(copyBlockers([{ ...files[0], text }, ...files.slice(1)], listing).length); + assert.ok(copyBlockers([], { ...listing, status: "draft" }).length); + assert.ok(screenshotBlockers({ ...manifest, status: "not-captured" }, record, () => png).length); +}); +test("empty or invented screenshot entries fail while a matching file passes", () => { + assert.deepEqual(screenshotBlockers(manifest, record, () => png), []); + for (const captures of [[], [{}], [null], [{ ...capture, filename: "../outside.png" }]]) assert.ok(screenshotBlockers({ ...manifest, captures }, record, () => png).length); + assert.ok(screenshotBlockers(manifest, record, () => { throw new Error("missing"); }).length); +}); +test("each capture requires provenance, device, locale, appearance, dimensions and checksum", () => { + const invalid = [{ sourceCommit: "b".repeat(40) }, { deviceFamily: null }, { locale: null }, { appearance: null }, { width: 2 }, { height: 0 }, { sha256: "0".repeat(64) }]; + for (const patch of invalid) assert.ok(screenshotBlockers({ ...manifest, captures: [{ ...capture, ...patch }] }, record, () => png).length); + assert.ok(screenshotBlockers(manifest, record, () => Buffer.from("not an image")).length); + assert.ok(screenshotBlockers({ ...manifest, buildNumber: "2" }, record, () => png).length); +}); +test("a matching checksum cannot bless a truncated PNG, bad CRC, or oversized decode", () => { + const corrupt = Buffer.from(png); corrupt[29] ^= 1; + const oversized = Buffer.from(png); oversized.writeUInt32BE(100_000, 16); + for (const bytes of [png.subarray(0, 33), png.subarray(0, -12), corrupt, oversized]) { + const captures = [{ ...capture, sha256: sha256(bytes) }]; + assert.ok(screenshotBlockers({ ...manifest, captures }, record, () => bytes).length); + } +}); + +test("artifact reader resolves only files inside its own directory", () => { + const root = mkdtempSync(join(tmpdir(), "ios-images-")); + try { + writeFileSync(join(root, "iphone.png"), png); + const read = artifactImageReader(root); + assert.deepEqual(read("iphone.png"), png); + assert.throws(() => read("../outside.png")); + } finally { rmSync(root, { recursive: true }); } +});