ReviewOS

also looking at this

craft-native/craft

feat(ios): scheduleNotification — the deferral that expired on its own, ratchet 26 → 25

#110
Merged glennmichael123 wants to merge feat/ios-schedule-notification into main
6 files +922 -37

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/ios/src/index.test.tsmodified+42-0
Changes to packages/ios/src/index.test.ts
@@ -344,3 +344,45 @@ describe('Zig runtime installation', () => {
344344 expect(existsSync(join(output, 'Runtime'))).toBe(false)
345345 })
346346})
347
348describe('runtime staleness', () => {
349 function runtimeWith(marker: string): string {
350 const dir = mkdtempSync(join(tmpdir(), 'craft-rt-'))
351 for (const a of ['libcraft-ios.a', 'libcraft-ios-simulator-arm64.a']) {
352 writeFileSync(join(dir, a), marker)
353 }
354 return dir
355 }
356
357 it('build picks up a rebuilt runtime instead of relinking the one init copied', async () => {
358 const output = mkdtempSync(join(tmpdir(), 'craft-app-'))
359 await init({ runtimeDir: runtimeWith('first build'), name: 'Stale', output })
360 const installed = join(output, 'Runtime', 'device', 'libcraft-ios.a')
361 expect(readFileSync(installed, 'utf8')).toBe('first build')
362
363 // The dev loop: edit Zig, rebuild the archives, run the app again. Before
364 // this, xcodebuild relinked the copy from init and the change was absent
365 // with no error anywhere.
366 await build({ output, runtimeDir: runtimeWith('second build'), generateProject: false })
367 expect(readFileSync(installed, 'utf8')).toBe('second build')
368 })
369
370 it('build leaves a runtimeless project alone rather than installing one behind init', async () => {
371 const output = mkdtempSync(join(tmpdir(), 'craft-app-'))
372 await init({ runtimeDir: null, name: 'NoRuntime', output })
373 expect(existsSync(join(output, 'Runtime'))).toBe(false)
374
375 // A runtime is available, but this project does not link one: its
376 // project.yml has no link settings, so archives here would be dead weight.
377 await build({ output, runtimeDir: runtimeWith('ignored'), generateProject: false })
378 expect(existsSync(join(output, 'Runtime'))).toBe(false)
379 })
380
381 it('build keeps the installed runtime when no runtime directory is configured', async () => {
382 const output = mkdtempSync(join(tmpdir(), 'craft-app-'))
383 await init({ runtimeDir: runtimeWith('from init'), name: 'Keep', output })
384 // A shell that forgot the variable must not quietly turn the runtime off.
385 await build({ output, runtimeDir: null, generateProject: false })
386 expect(readFileSync(join(output, 'Runtime', 'device', 'libcraft-ios.a'), 'utf8')).toBe('from init')
387 })
388})
packages/ios/src/index.tsmodified+39-0
Changes to packages/ios/src/index.ts
@@ -112,6 +112,12 @@ export interface BuildOptions {
112112 devServer?: string
113113 output: string
114114 generateProject?: boolean
115 /**
116 * Where to re-read the Zig runtime archives from, overriding
117 * `CRAFT_IOS_RUNTIME`. Same meaning as `InitOptions.runtimeDir`; `null`
118 * leaves whatever `init` installed exactly as it is.
119 */
120 runtimeDir?: string | null
115121}
116122
117123export interface OpenOptions {
@@ -480,6 +486,37 @@ export async function installRuntime(output: string, runtimeDir: string): Promis
480486 return true
481487}
482488
489/**
490 * Re-copy the Zig runtime into a project that already links one.
491 *
492 * The archives are *copied* by `init`, not symlinked, so without this a
493 * rebuilt runtime never reached the app: edit `packages/zig/src`, run `zig
494 * build build-ios-all`, then `craft ios run`, and xcodebuild happily relinks
495 * the archive that was copied when the project was first generated. The build
496 * succeeds, the app launches, and the change is simply absent — the worst
497 * shape a stale artefact can take, because there is no error to chase.
498 *
499 * Only refreshes; never installs and never removes. A project with no
500 * `Runtime/` was generated without a runtime and its `project.yml` carries no
501 * link settings, so copying archives in would leave them unreferenced — that
502 * decision belongs to `init`. And a project that *does* link one keeps working
503 * from the archives it already has when no runtime directory is configured,
504 * because a shell that forgot the variable should not quietly turn the runtime
505 * off.
506 */
507async function refreshRuntime(output: string, override?: string | null): Promise<void> {
508 if (!existsSync(join(output, 'Runtime'))) return
509
510 const dir = resolveRuntimeDir(override)
511 if (!dir) {
512 console.log(' Keeping the Zig runtime installed at init (no runtime directory configured)')
513 return
514 }
515
516 await installRuntime(output, dir)
517 console.log(' Refreshed the Zig runtime from', dir)
518}
519
483520export async function init(options: InitOptions): Promise<void> {
484521 const { name, bundleId, teamId, output } = options
485522
@@ -706,6 +743,8 @@ export async function build(options: BuildOptions): Promise<void> {
706743 console.log(` Synced: ${htmlPath} → dist/`)
707744 }
708745
746 await refreshRuntime(output, options.runtimeDir)
747
709748 if (!generateProject) return
710749
711750 // Generate Xcode project using xcodegen