Repository navigation
feat: load a project plugin module for an iOS target - #6693
janicduplessis wants to merge 24 commits into
Conversation
|
Fresh review of fa53d38. Verdict: findings. The loader, containment, name check, version handling, build id and documents hold up well. One finding breaks the maintainer's rule as the issue states it, and four more are smaller. I ran the worktree build in scratch Stim homes with Findings1. Breaks the rule: plugin code runs in a native Android or Swift package root that holds the plugin's marker. The yield rule works one operation at a time. In a folder where a bundled integration serves Android or macOS but not iOS, the plugin still serves
The unit sentinel test's native Android and Swift rows do not hold the marker, so it misses this. React Native and Expo roots with the marker are clean, because those integrations serve iOS. These texts say this cannot happen:
One possible fix: the plugin yields every operation at a root where any bundled integration recognises an application. Either way, the maintainer should pick the rule. 2. Staleness: the stamp is keyed by the module file, not the plugin directory. In one process, I loaded a plugin whose LLP 0023 says a process "refuses that plugin once a file of its directory ... changes". Keying Two smaller gaps in the same rule:
3. Hang: a module that keeps a handle open stops the command from exiting. A module whose top level calls The 30 s limit covers only the import and the factory. Nothing names the plugin. In stimd this does no harm, but every CLI command in that root hangs. 4. A child the module started outlives the refused command. A factory that awaits
Related: 5. Wrong refusal: an
6. Document says less than the code: the It says the module is imported "only to build and run an iOS app". 7. Minor notes (not blocking).
What checked out
Choices the maintainer has not stated, most consequential first
Checks at this head
|
…module # Conflicts: # scripts/build-compat.json
|
Fresh review of e889314 (round 2). Verdict: findings. The round 1 fixes hold: the whole-folder rule, doctor scoping, the abort on a refused load, the guarded getters, the promise refusal and the explicit exit all work as described, and version 1 plugins behave exactly as on I ran the worktree build in a scratch Stim home ( Findings1. Breaks the rule: a native Xcode project that Stim does not count as an iOS app still runs the plugin's module.
This matches the pull request's literal wording ("recognises as an application"), since the native Xcode integration does not call that folder an application. But a person would call it a native Xcode (macOS) project, a project of another type, so it conflicts with the maintainer's sentence. It also contradicts the website, which says every command "in a project of another type" reads the A constructed variant: a root that is executable but not listable ( 2. Document says less than the code: the staleness stamp. In one Node process, loading a plugin twice from source with a change in between:
The documents name the dot-entry and On "refuses forever": in stimd every refusal lasts until stimd exits, including after a revert or a plain 3. Document says less than the code: what
4. Document says more than the code: the website.
5. Document says more than the maintainer stated: rules in LLP 0023 not labelled as the pull request's own. LLP 0023's closing list of the pull request's choices names the factory, host members, field names, members, the 30 s limit, the refusal code, the whole-folder rule, the explicit exit, the stamp rule, the digest file and 6. Minor.
What checked out
Choices the maintainer has not stated, most consequential first
Checks at this headExit 0 for each: Not verified: a full |
|
Coordinator note: stepping back from this pull request instead of running a third fix round. Two review rounds in a row found confirmed problems in code the previous round had added (the round 1 and round 2 review comments above, plus two adversarial passes whose findings are summarised below). An independent read of the issue, the diff, both rounds and the decision documents concluded that patching will not converge, because three of the four classes of findings come from two choices in the approach:
The path taken, which stays inside the maintainer's decisions on #6599:
The boundary rule for step 3 goes to the maintainer, because both candidate rules are readings of "regular commands for projects of other types": the whole-folder rule this pull request implemented, or "only for iOS work in a folder that holds every marker of the plugin, and only when no bundled integration builds iOS there", which is enforced in one place (the registry's iOS selection) and does not depend on integration internals. This pull request will be closed when the preparation pull request is open; its branch stays for the commits that move. |
Description
A project plugin on
mainis manifest-only: Stim readsstimPlugin.projectand imports nothing, so a plugin can declare an Android build as a fixed command (#6631) and cannot serve an iOS build that needs logic, as Exact's does. This is slice S4 of the design, as amended by #6648, #6650 and #6666: a plugin's module is loaded for an iOS target and plugs into the host adapter inpackages/stim-cli/src/integrations/plugin-ios.tsthat the in-tree Exact module already uses.Maintainer decisions this implements, quoted on #6599:
stimpackage, enabled by name".This pull request imports plugin code for the first time and rewrites the passage of LLP 0023 the maintainer approved, so it stays a draft for the maintainer to read.
Fixes #6680. Covers item 1 of #6678 (the shipped plugin's package name is checked before its module is imported).
Solution
Manifest.
PROJECT_API_VERSIONis 2 and Stim acceptskinds.project1 and 2. A 1 manifest reads exactly as before (targets.iosstill rejects it with the same message). A 2 manifest may declaretargets.ios: {}and must then namemodule, a relative path of plain segments;modulewithouttargets.iosrejects the manifest. Detection, platforms and refusals still come from the manifest alone and stay synchronous.When the module is imported. Only for an iOS operation (
stim ios,--plan, a build, or a doctor that covers iOS, plainstim doctorincluded) in a root the registry selected the plugin for iOS, and only when no bundled integration recognises that folder as an application (or cannot read it).ios()loader refuses withSTIM_NO_PROJECT, naming the bundled project type, and its doctor reports a note; neither imports anything. Version 1 targets keep their per-operation yield unchanged.project-registry.ts), sostim doctor --platform android, or an unscoped doctor where a bundled integration won iOS, never imports the module of a plugin that also has an Android target.loadPluginIos(integrations/plugin-module.ts). A new lint rule,stim/computed-import, rejects animport()of a computed path anywhere else inpackages/stim-cli/src, with the three existing ones listed in.oxlintrc.json. It does not seecreateRequire(...)(path).Loading.
loadPluginIos:@stim-cli/plugin-<name>for the entry that named it. The same check rejects the entry where manifests are read, sostim plugin listandstim doctorshow it.join(dir, module)withrealpathand requires a regular file inside the directory, so..(already refused by the manifest) and a symbolic link out are refused.loadKind(kind check, factory check, 30 s limit).createProjectPlugin(host)with one host object:root, the operation's abortsignal, andexec(file, args, { timeoutMs, env }), which runs throughrunFileAsyncin the root with no shell and resolves{ code, stdout, stderr }for any exit.iosso every call checks its result's shape on a structured clone, refuses a promise (and consumes its rejection), and reads the returned object only inside the guard, so a throwing getter is a refusal naming the plugin.A refused or timed-out load aborts the host's signal, which ends any program the factory started through
exec;execrejects atimeoutMsthat is not a positive number. A CLI command that imported a plugin module exits once its result and output are written (bin/cli.ts, through the same path a failing command already takes), so a timer the module left open cannot keep it running. stimd does not take that path; a handle a module leaves open there stays until stimd exits.The result is an
IosPluginSourcefor the existingpluginIosProjectandpluginIosDoctor, with an offload that always says a plugin build does not run on a build machine. Any failure (missing file, path escape, import error, missing export or member, a throw, a wrong return shape, a program that is not an absolute path) is an error with codeSTIM_NO_PROJECTand a remedy, naming the plugin and the reason; it never falls back. A doctor load failure is onecostfinding, not a failed doctor. Exact still registers and runs exactly as before.Shipping and staleness.
build-plugins.ts(run by the tsdown build) copies each shipped plugin's files, withoutnode_modules, todist/plugins/<name>, and writesdist/shipped-plugins-digest.mjs, whose bytes are a sha256 over every copied file. The build id hashes the top-level*.mjsofdist, so it now changes when a shipped plugin does, without changing the id algorithm that other Stim versions compute for adist. A stimd of the old build restarts on the new one as it does for any build change, and a build machine never reuses another build's plugin code.loadPluginIosrecords a stamp of the canonical plugin directory's files (path, size, mtime) at the first import in a process and refuses the plugin in that process once the stamp changes, with a remedy to run the command from a terminal. An unreadable directory is a refusal. The stamp does not covernode_modulesor entries whose name starts with a dot: an updated dependency there is served stale, and LLP 0023, the guide and the website say so. A CLI command imports in its own process, so this only stops a long-lived stimd from serving old code.Public API.
stim/pluginadds the typesProjectPluginModule,ProjectPluginHost,ProjectPluginTargets,ProjectPluginIos,ProjectPluginFindingandProjectPluginIosTarget;ProjectPluginManifestgainsmodule?andtargets.ios?;PROJECT_API_VERSIONgoes from 1 to 2.plugin.api.txtchanges by those lines only (57 added, 1 removed: the constant), andProjectPluginModuleis added to the report's implemented interfaces. The release notes carry theproject 2line the API gate asks for.stim plugin list --jsonreportsapi.project: 2.stim plugin test. For a project plugin it now also checks thatmodulenames a file inside the plugin directory. It does not import the module; the kit for this kind keeps running in the CLI process, where the other kinds' worker isolation does not apply.Documents. LLP 0023 "Frozen and experimental plugin kinds", LLP 0014 "Use fixed invocations" and LLP 0009 "Run the client build" are updated;
stim guide apiand the website's programmatic API page describe the iOS target. Theapiguide budget goes from 27500 to 28600 bytes for that text.Before, LLP 0023:
After, LLP 0023 (first bullet; four bullets follow it for the version rule, loading, staleness and the decisions):
LLP 0014 keeps its approved manifest-command passage and its closing paragraph word for word, including "The plugin passage is meant to keep the rule's purpose: the person who owns the machine chooses the program and its arguments, and neither the manifest rules nor Stim's lookup let a checkout replace them." It adds one paragraph after them for module builds, which says that purpose does not hold for a module's build:
The
pluginssetting description in the settings registry drops "never imports its code" and says when a module is imported.Choices the maintainer has not stated
Most consequential first.
stim doctorandstim ios --planin the plugin's own root import the module, and so does the Desktop next-build plan, which stimd runs in its own process.host.execruns any program, including a shell or a bare name found onPATH; only the build programios.build()returns must be an absolute path.incrementalreceive the full operation environment, which is now part of the published types.speaks project 2, this stim speaks 1: stim engine update).moduleandtargets.ios,targets.iosbeing an empty object,modulerequired by and only withtargets.ios, and a version 1 manifest still ignoring amodulekey as it did.createProjectPlugin(host), sync or async, called once per load (each operation), returning{ ios }. TheProjectPluginIosmembers mirror the internalIosPluginas merged, all required;doctor()returnsProjectPluginFinding(nocode).root,signal(the operation's, read throughprocessContext), andexecresolving for any exit and rejecting on spawn failure, timeout or cancellation;cwdfixed to the root;envadded to the operation's environment;timeoutMsrequired.loadKind.STIM_NO_PROJECTas the code of every module failure, and its two remedies (fix the plugin and runstim plugin test, or for a shipped plugin update Stim).stim doctorreporting a load failure as onecostfinding.node_modulesand dot-entries) that refuses after a change, rather than a restart of stimd.dist/shipped-plugins-digest.mjsas the way the build id covers shipped plugins, and copying a shipped plugin's whole folder withoutnode_modules.packages/stim-cli/src) and its three listed exceptions.stim plugin testchecking the module path without importing the module, and its changed help text.pluginssetting description, the guide text and the website section.Not in this pull request
plugin-ios.ts, registered as before. No plugin replaces a bundled integration (D3), no remote build of a plugin project, nothing machine-wide.stim statusprints an iOS-only plugin project asapp: <bundle id> (bare), notproject: <name> (plugin ...):commands/status.tskeys that line on the Android selection and is being refactored in Read what a project type declares about its outputs through one seam, starting with Exact's names and paths #6679.Test plan
plugin-ios-module.test.ts(new): the sentinel test calls everyProjectRegistrymethod, every load it hands out and doctor unscoped, for iOS and for Android, in React Native, Expo, native Android, Swift package and Exact roots, each with and without the plugin's marker, and a web root, with a configured plugin whose module writes a sentinel and throws; no sentinel, andstim iosin the native Android root with the marker refuses naming that type. A plugin with both targets imports nothing for an Android doctor in its own root or for an unscoped doctor in an Exact root holding its marker, and does import for an unscoped doctor in its own root. The native Android, Swift package and two-target rows fail against the integration code before the whole-folder rule. In the plugin's own rootselectIos().load()refuses withSTIM_NO_PROJECTnaming the failure and the sentinel exists, and the doctor reports one finding. Other cases: a loaded module whose factory runs/bin/shthroughhost.execin the root; a missing file, a symbolic link out, no factory, a throwing factory, noios, a missing member and a wrong return shape each refuse naming the plugin; a non-absolute build program refuses; a shipped plugin with another package name is refused before import; after a load, pointingmoduleat another entry that imports the same changed helper makes the next load refuse; an unreadable plugin directory refuses; an async member (whose promise later rejects, with no unhandled rejection), aniosgetter that throws andhost.execwithtimeoutMs: 'unbounded'each refuse naming the plugin.plugin-ios-module.integration.test.ts(new, real processes): a factory that startssleep 300throughhost.execand then fails leaves no child behind; removing the abort makes it fail.shipped-plugin-name.test.ts(new): a shipped entry whosepackage.jsonnames another package is rejected where manifests are read. Breaking the loader to import fromplatforms()fails the sentinel test.shipped-plugins.test.ts: the build copy includes a module's files, leaves outnode_modules, andstimBuildIdof thedistchanges when a plugin file changes.project-registry.test.ts: version 2 manifest rules (iOS target without module, module without iOS target,..path, absolute path, iOS target with fields). One existing row changed: "another integer" now declares project 3, since 2 is accepted.plugin-command.integration.test.ts:plugin testpasses a contained module without importing it and fails a module linked out of the directory. Theapi.projectexpectation is 2.test/runtime-floor.mjs(built package): a plugin whose module starts asetIntervalletsios --planexit. With the sentinel plugin configured,status,ios --plan,android --planandstopin a React Native app that holds the marker leave no sentinel;ios --planin the plugin's root refuses withSTIM_NO_PROJECTand the sentinel exists.scripts/oxlint/stim.test.mjs: the new rule accepts literal imports and rejects computed ones.plugin-android.test.ts,exact-ios.test.ts,exact-offload.test.ts,exact-offload-worker.integration.test.ts,guide.test.ts,guide-budget.test.ts.pnpm run format:check,lint,build,typecheck,knip,test:runtime,node scripts/build-compat.mjs(record updated, no compatibility bump: plugin builds never reach a build machine),node scripts/plugin-api-report.mjs,node scripts/dist-closure.mjs --enforce cli,ios,android,status,status-command,agent-device,net,agent-driver,api.Real run on a Mac (
xcodebuild -version: Xcode 27.1; simulator iPhone 18 Pro on iOS 27.0), in a scratchSTIM_HOMEwithiosSimulatorAppandandroidEmulatorAppset tostim-desktop,daemon.mode offand a scratchSTIM_ENGINE_ROOT. The fixture is a plugin directory whose module runsxcrun --sdk iphonesimulator --show-sdk-paththroughhost.execand returns a build of the app's ownbuild.sh, which compiles a SwiftUI@mainapp withxcrun swiftcfor the simulator and signs it ad hoc:stim plugin listproject 2 selected by plugins; "This Stim speaks ... project 2"stim plugin test <dir>stim ios --planapp dev.stim.fixture6680,cache miss: the fixture builds with its own script, builds on this machinestim iosbuild ok (1.5s), installed, launched, "process alive 3s after launch";launchctl listin the simulator showsUIKitApplication:dev.stim.fixture6680stim statusbare, see above)stim logs --errorsstim stoppackages/plugin-fixture(@stim-cli/plugin-fixture), built,pnpm pack, tarball extracted and run withplugins: ["fixture"]plugin listshowsfixture project 2;ios --planandstim iosbuild, install and launch the same app fromdist/plugins/fixture;status,logs --errors,stopas above. The folder was removed afterwards.apps/mobile), without and then with the plugin's marker filestim status,stim doctor,stim ios --planandstim stopall exit 0 and leave no sentinelstim ioson the fixture builds and launches again;stim status(all workspaces),stim doctor,stim ios --plan,stim stopin the Expo app andstim gc(preview) leave no sentinelsettings.gradle.kts,gradlew) and Swift package folder (Package.swift), each holding the sentinel plugin's markerstim doctorandstim doctor --jsonexit 0 with the note "The plugin stim-plugin-sentinel does not run here";stim ios --planrefuses:STIM_NO_PROJECT: The plugin stim-plugin-sentinel does not build the Sentinel project at ... for iOS: Stim also recognises this folder as a native Android project, and it runs no plugin code in a folder a bundled integration serves.(the Swift folder names "a Swift package project"); no sentinelstim doctor --platform androidin its rootsetInterval,stim ios --planin its roothost.execofsleep 300stim ios --planrefuses after 30 s with... the module did not load within 30000ms.; thesleepprocess is gonestim iosagain on that buildstatusrecords the build;stopandworktree removedelete the simulatorstim ios --planandstim ios --jsonrefuse withSTIM_NO_PROJECT: The plugin stim-plugin-sentinel cannot serve the Sentinel project at ...: the sentinel module ran.and its remedy; the sentinel names the CLI process;stim doctorreports "The plugin stim-plugin-sentinel cannot load"