also looking at this
feat(ios): scheduleNotification — the deferral that expired on its own, ratchet 26 → 25
#110
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.
| @@ -344,3 +344,45 @@ describe('Zig runtime installation', () => { | ||
| 344 | 344 | expect(existsSync(join(output, 'Runtime'))).toBe(false) |
| 345 | 345 | }) |
| 346 | 346 | }) |
| 347 | ||
| 348 | describe('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 | }) | |
| @@ -112,6 +112,12 @@ export interface BuildOptions { | ||
| 112 | 112 | devServer?: string |
| 113 | 113 | output: string |
| 114 | 114 | 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 | |
| 115 | 121 | } |
| 116 | 122 | |
| 117 | 123 | export interface OpenOptions { |
| @@ -480,6 +486,37 @@ export async function installRuntime(output: string, runtimeDir: string): Promis | ||
| 480 | 486 | return true |
| 481 | 487 | } |
| 482 | 488 | |
| 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 | */ | |
| 507 | async 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 | ||
| 483 | 520 | export async function init(options: InitOptions): Promise<void> { |
| 484 | 521 | const { name, bundleId, teamId, output } = options |
| 485 | 522 | |
| @@ -706,6 +743,8 @@ export async function build(options: BuildOptions): Promise<void> { | ||
| 706 | 743 | console.log(` Synced: ${htmlPath} → dist/`) |
| 707 | 744 | } |
| 708 | 745 | |
| 746 | await refreshRuntime(output, options.runtimeDir) | |
| 747 | ||
| 709 | 748 | if (!generateProject) return |
| 710 | 749 | |
| 711 | 750 | // Generate Xcode project using xcodegen |