@joiner-platform/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +148 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* `tiles inspect` orchestration: the slot, the freshness-build-copy
|
|
4
|
+
* transaction under the build lock, one child per variant, the merged
|
|
5
|
+
* report, and pruning.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
cpSync,
|
|
10
|
+
existsSync,
|
|
11
|
+
readdirSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import {
|
|
17
|
+
type BuildRecord,
|
|
18
|
+
distFingerprint,
|
|
19
|
+
fingerprintSource,
|
|
20
|
+
readBuildRecord,
|
|
21
|
+
type StaleReason,
|
|
22
|
+
sourceFingerprint,
|
|
23
|
+
staleReason,
|
|
24
|
+
UNFINGERPRINTED,
|
|
25
|
+
writeBuildRecord,
|
|
26
|
+
} from "./inspect-freshness.js";
|
|
27
|
+
import {
|
|
28
|
+
acquireAny,
|
|
29
|
+
type FileLock,
|
|
30
|
+
slotPaths,
|
|
31
|
+
tryLock,
|
|
32
|
+
} from "./inspect-lock.js";
|
|
33
|
+
import {
|
|
34
|
+
InspectExit2 as Exit2,
|
|
35
|
+
type InspectExit2,
|
|
36
|
+
type InspectPlan,
|
|
37
|
+
} from "./inspect-options.js";
|
|
38
|
+
import type { InspectReport } from "./inspect-report.js";
|
|
39
|
+
import {
|
|
40
|
+
absorb,
|
|
41
|
+
type InspectDeps,
|
|
42
|
+
input,
|
|
43
|
+
notStarted,
|
|
44
|
+
RETAINED_RUNS,
|
|
45
|
+
Run,
|
|
46
|
+
} from "./inspect-run-state.js";
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
defaultSlotDir,
|
|
50
|
+
type InspectDeps,
|
|
51
|
+
newRunId,
|
|
52
|
+
} from "./inspect-run-state.js";
|
|
53
|
+
|
|
54
|
+
export type InspectOutcome =
|
|
55
|
+
| { report: InspectReport }
|
|
56
|
+
/** `warnings` are those the run gathered before the error. */
|
|
57
|
+
| { error: InspectExit2; warnings: string[] };
|
|
58
|
+
|
|
59
|
+
const BUILD_OUTPUT_BYTES = 4 * 1024;
|
|
60
|
+
|
|
61
|
+
async function takeSlot(run: Run, signal: AbortSignal): Promise<void> {
|
|
62
|
+
const slot = await acquireAny(
|
|
63
|
+
slotPaths(run.deps.slotDir),
|
|
64
|
+
signal,
|
|
65
|
+
"machine-wide slot cap",
|
|
66
|
+
undefined,
|
|
67
|
+
() => run.deps.now(),
|
|
68
|
+
);
|
|
69
|
+
run.timings.slotWaitMs = slot.waitMs;
|
|
70
|
+
if (slot.lock) run.locks.push(slot.lock);
|
|
71
|
+
if (slot.warning) run.warnings.push(slot.warning);
|
|
72
|
+
if (slot.waitMs > 1000)
|
|
73
|
+
run.warnings.push(
|
|
74
|
+
`waited ${slot.waitMs} ms for one of the 2 inspect slots`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The `dist` fingerprint; past DIST_LIMITS, an exit-2 error that ends with `hint`. */
|
|
79
|
+
function readDist(run: Run, hint: string): string | null {
|
|
80
|
+
try {
|
|
81
|
+
return distFingerprint(join(run.plan.tileDir, "dist"));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error instanceof Exit2 && error.code === "dist-too-large")
|
|
84
|
+
throw new Exit2(error.code, `${error.message}. ${hint}`);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Stands for an existing `dist` over the limits; no fingerprint equals it, so it is stale. */
|
|
90
|
+
const OVER_LIMIT_DIST = "over-limit";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The existing `dist`'s fingerprint. One over the limits is stale when a
|
|
94
|
+
* build may replace it (the build's output is checked again); with
|
|
95
|
+
* --no-build it ends the run.
|
|
96
|
+
*/
|
|
97
|
+
function existingDist(run: Run): string | null {
|
|
98
|
+
if (run.plan.noBuild) {
|
|
99
|
+
return readDist(
|
|
100
|
+
run,
|
|
101
|
+
"Rebuild it with `bun run build`, or run inspect without --no-build.",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
return distFingerprint(join(run.plan.tileDir, "dist"));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (error instanceof Exit2) return OVER_LIMIT_DIST;
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function buildIfStale(
|
|
113
|
+
run: Run,
|
|
114
|
+
reason: StaleReason,
|
|
115
|
+
buildLock: FileLock | null,
|
|
116
|
+
signal: AbortSignal,
|
|
117
|
+
): Promise<string> {
|
|
118
|
+
const { tileDir } = run.plan;
|
|
119
|
+
run.deps.log(`Building (${reason})...`);
|
|
120
|
+
const started = run.deps.now();
|
|
121
|
+
const fds = buildLock ? [...run.fds, buildLock.fd] : run.fds;
|
|
122
|
+
const result = await run.deps.runBuild(tileDir, fds, signal);
|
|
123
|
+
run.timings.buildMs = run.deps.now() - started;
|
|
124
|
+
if (result.aborted) throw signal.reason ?? new Error("aborted");
|
|
125
|
+
if (result.exitCode !== 0) {
|
|
126
|
+
throw new Exit2(
|
|
127
|
+
"build-failed",
|
|
128
|
+
`bun run build failed (exit ${result.exitCode ?? result.signal}):\n${result.output.slice(-BUILD_OUTPUT_BYTES)}`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
run.build.ran = true;
|
|
132
|
+
run.build.reason = reason;
|
|
133
|
+
const dist = readDist(
|
|
134
|
+
run,
|
|
135
|
+
"dist/ is still over the limits after the build: make the build's output smaller, or delete dist/ and rebuild if the file is left over from an earlier build.",
|
|
136
|
+
);
|
|
137
|
+
if (dist === null)
|
|
138
|
+
throw new Exit2("build-failed", "bun run build produced no dist/");
|
|
139
|
+
return dist;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* With --no-build, uses `dist` as it is and fails only when it is missing.
|
|
144
|
+
* Inspect cannot prove a `dist` stale: a rebuild after an edit the bundler
|
|
145
|
+
* ignores gives the same bytes. So a possibly stale `dist` only warns, and
|
|
146
|
+
* no build record is written.
|
|
147
|
+
*/
|
|
148
|
+
function acceptUnbuiltDist(
|
|
149
|
+
run: Run,
|
|
150
|
+
source: string,
|
|
151
|
+
dist: string | null,
|
|
152
|
+
record: BuildRecord | null,
|
|
153
|
+
): void {
|
|
154
|
+
if (dist === null) {
|
|
155
|
+
throw new Exit2(
|
|
156
|
+
"build-stale",
|
|
157
|
+
"there is no built dist/ and --no-build was given; run `bun run build`",
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const unchangedSinceSourceEdit =
|
|
161
|
+
source !== UNFINGERPRINTED &&
|
|
162
|
+
record?.distFingerprint === dist &&
|
|
163
|
+
record.sourceFingerprint !== source;
|
|
164
|
+
run.warnings.push(
|
|
165
|
+
unchangedSinceSourceEdit
|
|
166
|
+
? "--no-build: the source changed after inspect built this dist/, and dist/ has the same content since; it uses dist/ as it is, which is stale if the change affects the build"
|
|
167
|
+
: "--no-build: inspect did not build this dist/, so it cannot tell whether dist/ matches the source; it uses dist/ as it is",
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Records the build of `source`, warning when the source moved while it ran. */
|
|
172
|
+
function recordBuild(
|
|
173
|
+
run: Run,
|
|
174
|
+
recordPath: string,
|
|
175
|
+
source: string,
|
|
176
|
+
dist: string,
|
|
177
|
+
): void {
|
|
178
|
+
if (
|
|
179
|
+
source !== UNFINGERPRINTED &&
|
|
180
|
+
sourceFingerprint(run.plan.tileDir) !== source
|
|
181
|
+
) {
|
|
182
|
+
run.warnings.push(
|
|
183
|
+
"the source changed while it was building; the next run rebuilds",
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
writeBuildRecord(recordPath, {
|
|
187
|
+
sourceFingerprint: source,
|
|
188
|
+
distFingerprint: dist,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Freshness, build, and copy, as one transaction under the tile's build lock. */
|
|
193
|
+
async function freshCopy(run: Run, signal: AbortSignal): Promise<void> {
|
|
194
|
+
const { tileDir } = run.plan;
|
|
195
|
+
const lock = await acquireAny(
|
|
196
|
+
[join(run.inspectDir, "build.lock")],
|
|
197
|
+
signal,
|
|
198
|
+
"build lock",
|
|
199
|
+
);
|
|
200
|
+
if (lock.warning) run.warnings.push(lock.warning);
|
|
201
|
+
try {
|
|
202
|
+
const { fingerprint: source, problem } = fingerprintSource(tileDir);
|
|
203
|
+
if (problem) {
|
|
204
|
+
run.warnings.push(
|
|
205
|
+
`the source could not be fingerprinted, so every run rebuilds: ${problem}`,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
const recordPath = join(run.inspectDir, "build.json");
|
|
209
|
+
let dist = existingDist(run);
|
|
210
|
+
const record = readBuildRecord(recordPath);
|
|
211
|
+
const reason = staleReason(source, dist, record);
|
|
212
|
+
if (reason && run.plan.noBuild) {
|
|
213
|
+
acceptUnbuiltDist(run, source, dist, record);
|
|
214
|
+
} else if (reason) {
|
|
215
|
+
dist = await buildIfStale(run, reason, lock.lock, signal);
|
|
216
|
+
recordBuild(run, recordPath, source, dist);
|
|
217
|
+
}
|
|
218
|
+
run.build.sourceFingerprint = source;
|
|
219
|
+
run.build.distFingerprint = dist ?? "";
|
|
220
|
+
cpSync(join(tileDir, "dist"), join(run.runDir, "dist"), {
|
|
221
|
+
recursive: true,
|
|
222
|
+
});
|
|
223
|
+
} finally {
|
|
224
|
+
lock.lock?.release();
|
|
225
|
+
}
|
|
226
|
+
if (run.plan.scriptInSource) {
|
|
227
|
+
run.warnings.push(
|
|
228
|
+
"the script is part of the tile's source, so editing it causes a rebuild; keep inspect scripts in .inspect-scripts/",
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
if (run.plan.scriptInVisualChecks) {
|
|
232
|
+
run.warnings.push(
|
|
233
|
+
"the script is under .visual-checks/, which is temporary (in Creator it is deleted when the container sleeps); keep inspect scripts in .inspect-scripts/",
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const SOURCE_MOVED =
|
|
239
|
+
"the source changed after the build was copied; the script and the served build may differ";
|
|
240
|
+
|
|
241
|
+
function warnIfSourceMoved(run: Run, copied: string): void {
|
|
242
|
+
if (
|
|
243
|
+
run.plan.body.kind !== "script" ||
|
|
244
|
+
copied === UNFINGERPRINTED ||
|
|
245
|
+
run.warnings.includes(SOURCE_MOVED)
|
|
246
|
+
)
|
|
247
|
+
return;
|
|
248
|
+
if (sourceFingerprint(run.plan.tileDir) !== copied)
|
|
249
|
+
run.warnings.push(SOURCE_MOVED);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function runVariants(run: Run, signal: AbortSignal): Promise<void> {
|
|
253
|
+
run.setStage("running");
|
|
254
|
+
run.deps.writeEntry(run.runDir);
|
|
255
|
+
const started = run.deps.now();
|
|
256
|
+
try {
|
|
257
|
+
for (const v of run.plan.variants) {
|
|
258
|
+
if (signal.aborted) {
|
|
259
|
+
run.variants.push(notStarted(v));
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
warnIfSourceMoved(run, run.build.sourceFingerprint);
|
|
263
|
+
// biome-ignore lint/performance/noAwaitInLoops: variants run one at a time, each in its own process.
|
|
264
|
+
const result = await run.deps.runVariant({
|
|
265
|
+
tileDir: run.plan.tileDir,
|
|
266
|
+
input: input(run, v),
|
|
267
|
+
inheritFds: run.fds,
|
|
268
|
+
signal,
|
|
269
|
+
});
|
|
270
|
+
if (result.usageError)
|
|
271
|
+
throw new Exit2(result.usageError.code, result.usageError.message);
|
|
272
|
+
absorb(run, v, result);
|
|
273
|
+
}
|
|
274
|
+
} finally {
|
|
275
|
+
run.timings.variantsMs = run.deps.now() - started;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Deletes finished run directories beyond the newest few. A live run holds
|
|
281
|
+
* its lock (the caller's own run included), and without working locks
|
|
282
|
+
* nothing is deleted, because a live run cannot be told from a finished one.
|
|
283
|
+
*/
|
|
284
|
+
export function pruneRuns(inspectDir: string, keep = RETAINED_RUNS): void {
|
|
285
|
+
const runs = readdirSync(inspectDir, { withFileTypes: true })
|
|
286
|
+
.filter(
|
|
287
|
+
(e) =>
|
|
288
|
+
e.isDirectory() && existsSync(join(inspectDir, e.name, "run.json")),
|
|
289
|
+
)
|
|
290
|
+
.map((e) => e.name)
|
|
291
|
+
.sort()
|
|
292
|
+
.reverse();
|
|
293
|
+
for (const name of runs.slice(keep)) {
|
|
294
|
+
const lock = tryLock(join(inspectDir, name, "run.lock"));
|
|
295
|
+
if (typeof lock === "string") continue;
|
|
296
|
+
try {
|
|
297
|
+
rmSync(join(inspectDir, name), { recursive: true, force: true });
|
|
298
|
+
} finally {
|
|
299
|
+
lock.release();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Cleanup that must not hide the run's result: a failure is only logged. */
|
|
305
|
+
function tryOrLog(run: Run, what: string, step: () => void): void {
|
|
306
|
+
try {
|
|
307
|
+
step();
|
|
308
|
+
} catch (error) {
|
|
309
|
+
run.deps.log(`${what} failed: ${String(error)}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function finish(run: Run): void {
|
|
314
|
+
tryOrLog(run, "removing the served build copy", () =>
|
|
315
|
+
rmSync(join(run.runDir, "dist"), { recursive: true, force: true }),
|
|
316
|
+
);
|
|
317
|
+
// Prune while this run still holds its run.lock, so it never deletes itself.
|
|
318
|
+
tryOrLog(run, "pruning old inspect runs", () => pruneRuns(run.inspectDir));
|
|
319
|
+
for (const lock of run.locks) lock.release();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** An error that is not a usage, build, or deadline problem, as exit 2. */
|
|
323
|
+
function internalError(deps: InspectDeps, error: unknown): InspectExit2 {
|
|
324
|
+
if (error instanceof Error && error.stack) deps.log(error.stack);
|
|
325
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
326
|
+
return new Exit2("internal", `inspect failed: ${message}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Runs the steps up to the report; returns an exit-2 error, or null for a report. */
|
|
330
|
+
async function runSteps(
|
|
331
|
+
run: Run,
|
|
332
|
+
signal: AbortSignal,
|
|
333
|
+
): Promise<InspectExit2 | null> {
|
|
334
|
+
try {
|
|
335
|
+
await takeSlot(run, signal);
|
|
336
|
+
run.setStage("building");
|
|
337
|
+
await freshCopy(run, signal);
|
|
338
|
+
await runVariants(run, signal);
|
|
339
|
+
if (!signal.aborted) run.setStage("done");
|
|
340
|
+
return null;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error instanceof Exit2) return error;
|
|
343
|
+
return signal.aborted ? null : internalError(run.deps, error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Runs the whole inspection; never throws, and always releases what it took. */
|
|
348
|
+
export async function runInspection(
|
|
349
|
+
plan: InspectPlan,
|
|
350
|
+
deps: InspectDeps,
|
|
351
|
+
signal: AbortSignal,
|
|
352
|
+
): Promise<InspectOutcome> {
|
|
353
|
+
let run: Run;
|
|
354
|
+
try {
|
|
355
|
+
run = new Run(plan, deps);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return { error: internalError(deps, error), warnings: [] };
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const error = await runSteps(run, signal);
|
|
361
|
+
if (error) return { error, warnings: run.warnings };
|
|
362
|
+
for (const v of plan.variants.slice(run.variants.length))
|
|
363
|
+
run.variants.push(notStarted(v));
|
|
364
|
+
const report = run.report();
|
|
365
|
+
writeFileSync(
|
|
366
|
+
join(run.runDir, "report.json"),
|
|
367
|
+
JSON.stringify(report, null, "\t"),
|
|
368
|
+
);
|
|
369
|
+
return { report };
|
|
370
|
+
} catch (error) {
|
|
371
|
+
return { error: internalError(deps, error), warnings: run.warnings };
|
|
372
|
+
} finally {
|
|
373
|
+
finish(run);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* Child processes for `tiles inspect`: each runs in its own process group,
|
|
4
|
+
* inherits the run's lock descriptors (so an orphaned child keeps the locks
|
|
5
|
+
* until it exits), and keeps only the tail of its output.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import { startWatchdog } from "./inspect-watchdog.js";
|
|
10
|
+
|
|
11
|
+
export interface GroupResult {
|
|
12
|
+
exitCode: number | null;
|
|
13
|
+
signal: NodeJS.Signals | null;
|
|
14
|
+
/**
|
|
15
|
+
* The last `outputBytes` of stdout and stderr, interleaved in arrival
|
|
16
|
+
* order. They are separate pipes, so a stdout write can arrive after a
|
|
17
|
+
* later stderr write.
|
|
18
|
+
*/
|
|
19
|
+
output: string;
|
|
20
|
+
/** True when `signal` ended the child. */
|
|
21
|
+
aborted: boolean;
|
|
22
|
+
/** Why the orphan watchdog did not watch, when one was asked for; else null. */
|
|
23
|
+
watchdogFailure: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GroupOptions {
|
|
27
|
+
command: string;
|
|
28
|
+
args: string[];
|
|
29
|
+
cwd: string;
|
|
30
|
+
/** Lock descriptors the child inherits (as its fd 3, 4, ...). */
|
|
31
|
+
inheritFds: number[];
|
|
32
|
+
signal: AbortSignal;
|
|
33
|
+
outputBytes: number;
|
|
34
|
+
/** Called with each chunk, for streaming to stderr. */
|
|
35
|
+
onOutput?: (chunk: string) => void;
|
|
36
|
+
/** Between SIGTERM and SIGKILL after an abort. */
|
|
37
|
+
killGraceMs?: number;
|
|
38
|
+
/** After exit, how long to wait for output still in the pipes. */
|
|
39
|
+
drainMs?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Ends the child's group if this process dies first, through a separate
|
|
42
|
+
* watchdog process (SIGTERM, then SIGKILL after `killGraceMs`); see
|
|
43
|
+
* inspect-watchdog.ts.
|
|
44
|
+
*/
|
|
45
|
+
watchdog?: boolean;
|
|
46
|
+
/** The Bun that runs the watchdog; the CLI's own unless a test names one. */
|
|
47
|
+
watchdogRuntime?: string;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Keeps the last `limit` bytes of everything appended. */
|
|
52
|
+
export class Tail {
|
|
53
|
+
private chunks: Buffer[] = [];
|
|
54
|
+
private size = 0;
|
|
55
|
+
truncated = false;
|
|
56
|
+
|
|
57
|
+
constructor(private readonly limit: number) {}
|
|
58
|
+
|
|
59
|
+
append(chunk: Buffer): void {
|
|
60
|
+
this.chunks.push(chunk);
|
|
61
|
+
this.size += chunk.length;
|
|
62
|
+
while (this.size > this.limit && this.chunks.length > 0) {
|
|
63
|
+
const first = this.chunks[0]!;
|
|
64
|
+
const excess = this.size - this.limit;
|
|
65
|
+
this.truncated = true;
|
|
66
|
+
if (first.length <= excess) {
|
|
67
|
+
this.chunks.shift();
|
|
68
|
+
this.size -= first.length;
|
|
69
|
+
} else {
|
|
70
|
+
this.chunks[0] = first.subarray(excess);
|
|
71
|
+
this.size -= excess;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
text(): string {
|
|
77
|
+
return Buffer.concat(this.chunks)
|
|
78
|
+
.toString("utf8")
|
|
79
|
+
.replace(/^\uFFFD+/, "");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function killGroup(
|
|
84
|
+
pid: number | undefined,
|
|
85
|
+
signal: NodeJS.Signals,
|
|
86
|
+
): void {
|
|
87
|
+
if (pid === undefined) return;
|
|
88
|
+
try {
|
|
89
|
+
process.kill(-pid, signal);
|
|
90
|
+
} catch {
|
|
91
|
+
// Already gone.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Runs a command in its own process group; an abort sends SIGTERM, then SIGKILL. */
|
|
96
|
+
export function runInGroup(options: GroupOptions): Promise<GroupResult> {
|
|
97
|
+
const tail = new Tail(options.outputBytes);
|
|
98
|
+
const child = spawn(options.command, options.args, {
|
|
99
|
+
cwd: options.cwd,
|
|
100
|
+
detached: true,
|
|
101
|
+
env: options.env ?? process.env,
|
|
102
|
+
stdio: ["ignore", "pipe", "pipe", ...options.inheritFds],
|
|
103
|
+
});
|
|
104
|
+
const grace = options.killGraceMs ?? 7_000;
|
|
105
|
+
const watchdog =
|
|
106
|
+
options.watchdog && child.pid !== undefined
|
|
107
|
+
? startWatchdog(child.pid, grace, options.watchdogRuntime)
|
|
108
|
+
: null;
|
|
109
|
+
const collect = (chunk: Buffer) => {
|
|
110
|
+
tail.append(chunk);
|
|
111
|
+
options.onOutput?.(chunk.toString("utf8"));
|
|
112
|
+
};
|
|
113
|
+
child.stdout?.on("data", collect);
|
|
114
|
+
child.stderr?.on("data", collect);
|
|
115
|
+
let aborted = false;
|
|
116
|
+
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
117
|
+
const onAbort = () => {
|
|
118
|
+
aborted = true;
|
|
119
|
+
killGroup(child.pid, "SIGTERM");
|
|
120
|
+
const kill = () => killGroup(child.pid, "SIGKILL");
|
|
121
|
+
// biome-ignore lint: the grace period before SIGKILL; not test code.
|
|
122
|
+
killTimer = setTimeout(kill, grace);
|
|
123
|
+
};
|
|
124
|
+
if (options.signal.aborted) onAbort();
|
|
125
|
+
else options.signal.addEventListener("abort", onAbort, { once: true });
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
let drainTimer: ReturnType<typeof setTimeout> | undefined;
|
|
128
|
+
let settled = false;
|
|
129
|
+
let closed = false;
|
|
130
|
+
let onClose: (() => void) | null = null;
|
|
131
|
+
child.on("close", () => {
|
|
132
|
+
closed = true;
|
|
133
|
+
onClose?.();
|
|
134
|
+
});
|
|
135
|
+
const cleanUp = () => {
|
|
136
|
+
watchdog?.stop();
|
|
137
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
138
|
+
clearTimeout(killTimer);
|
|
139
|
+
clearTimeout(drainTimer);
|
|
140
|
+
};
|
|
141
|
+
child.on("error", (error) => {
|
|
142
|
+
cleanUp();
|
|
143
|
+
reject(error);
|
|
144
|
+
});
|
|
145
|
+
// Settle on exit, not on close: a process that left the group can
|
|
146
|
+
// hold the output pipes open, and then close never comes.
|
|
147
|
+
child.on("exit", (exitCode, signal) => {
|
|
148
|
+
// Anything the child left in its group (a server it started) goes
|
|
149
|
+
// too. Playwright's browser leads its own group; it exits when its
|
|
150
|
+
// pipe to the dead child closes.
|
|
151
|
+
killGroup(child.pid, "SIGKILL");
|
|
152
|
+
const settle = () => {
|
|
153
|
+
if (settled) return;
|
|
154
|
+
settled = true;
|
|
155
|
+
cleanUp();
|
|
156
|
+
child.stdout?.destroy();
|
|
157
|
+
child.stderr?.destroy();
|
|
158
|
+
resolve({
|
|
159
|
+
exitCode,
|
|
160
|
+
signal,
|
|
161
|
+
output: tail.text(),
|
|
162
|
+
aborted,
|
|
163
|
+
watchdogFailure: watchdog?.failure() ?? null,
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
if (closed) return settle();
|
|
167
|
+
onClose = settle;
|
|
168
|
+
// biome-ignore lint: the wait for the last output after exit; not test code.
|
|
169
|
+
drainTimer = setTimeout(settle, options.drainMs ?? 2_000);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* The `--ready` target, checked before anything waits or builds. It mirrors
|
|
4
|
+
* the `Target` type of the SDK's inspect actions (contract 1); the child
|
|
5
|
+
* checks it again with the tile's own SDK, which stays the authority.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type InspectTarget =
|
|
9
|
+
| { text: string; exact?: boolean; nth?: number }
|
|
10
|
+
| { role: string; name?: string; nth?: number }
|
|
11
|
+
| { testId: string; nth?: number }
|
|
12
|
+
| { css: string; nth?: number };
|
|
13
|
+
|
|
14
|
+
/** The SDK's string limit for action arguments: 1 KB of UTF-8. */
|
|
15
|
+
const STRING_BYTES = 1024;
|
|
16
|
+
const NTH_MAX = 99;
|
|
17
|
+
|
|
18
|
+
type FieldKind = "string" | "boolean" | "nth";
|
|
19
|
+
|
|
20
|
+
/** One branch per target kind, in the SDK's order; the first present key picks it. */
|
|
21
|
+
const BRANCHES: ReadonlyArray<{
|
|
22
|
+
key: string;
|
|
23
|
+
fields: Readonly<Record<string, FieldKind>>;
|
|
24
|
+
}> = [
|
|
25
|
+
{ key: "text", fields: { text: "string", exact: "boolean", nth: "nth" } },
|
|
26
|
+
{ key: "role", fields: { role: "string", name: "string", nth: "nth" } },
|
|
27
|
+
{ key: "testId", fields: { testId: "string", nth: "nth" } },
|
|
28
|
+
{ key: "css", fields: { css: "string", nth: "nth" } },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function checkField(value: unknown, kind: FieldKind, path: string) {
|
|
32
|
+
if (kind === "boolean")
|
|
33
|
+
return typeof value === "boolean" ? null : `${path} must be a boolean`;
|
|
34
|
+
if (kind === "nth") {
|
|
35
|
+
return Number.isInteger(value) &&
|
|
36
|
+
(value as number) >= 0 &&
|
|
37
|
+
(value as number) <= NTH_MAX
|
|
38
|
+
? null
|
|
39
|
+
: `${path} must be an integer from 0 to ${NTH_MAX}`;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value !== "string") return `${path} must be a string`;
|
|
42
|
+
return Buffer.byteLength(value) > STRING_BYTES
|
|
43
|
+
? `${path} must be at most ${STRING_BYTES} bytes`
|
|
44
|
+
: null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns a problem starting with "ready", or null for a valid target. */
|
|
48
|
+
export function checkReadyTarget(value: unknown): string | null {
|
|
49
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
50
|
+
return "ready must be an object";
|
|
51
|
+
const record = value as Record<string, unknown>;
|
|
52
|
+
const branch = BRANCHES.find((b) => record[b.key] !== undefined);
|
|
53
|
+
if (!branch)
|
|
54
|
+
return "ready must be a target: {text}, {role, name?}, {testId}, or {css}";
|
|
55
|
+
const fields = Object.keys(branch.fields);
|
|
56
|
+
const unknown = Object.keys(record).find((k) => !fields.includes(k));
|
|
57
|
+
if (unknown !== undefined)
|
|
58
|
+
return `ready has an unknown field "${unknown}" (allowed: ${fields.join(", ")})`;
|
|
59
|
+
for (const [key, kind] of Object.entries(branch.fields)) {
|
|
60
|
+
if (record[key] === undefined) continue;
|
|
61
|
+
const problem = checkField(record[key], kind, `ready.${key}`);
|
|
62
|
+
if (problem) return problem;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|