@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,235 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* `tiles inspect` reports: merging the variant reports, the report size
|
|
4
|
+
* limit, the exit code, and the human-readable summary.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
InspectReport,
|
|
9
|
+
InspectVariantReport,
|
|
10
|
+
} from "./inspect-contract.js";
|
|
11
|
+
|
|
12
|
+
export const REPORT_MAX_BYTES = 512 * 1024;
|
|
13
|
+
|
|
14
|
+
export type { InspectReport, InspectVariantReport };
|
|
15
|
+
|
|
16
|
+
export function overallOutcome(
|
|
17
|
+
variants: readonly InspectVariantReport[],
|
|
18
|
+
): InspectReport["outcome"] {
|
|
19
|
+
const kinds = variants.map((v) => v.outcome.kind);
|
|
20
|
+
if (kinds.some((k) => k === "timed-out" || k === "not-started"))
|
|
21
|
+
return "timed-out";
|
|
22
|
+
if (kinds.some((k) => k !== "passed")) return "failed";
|
|
23
|
+
return "passed";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function exitCodeFor(report: InspectReport): 0 | 1 | 3 {
|
|
27
|
+
if (report.outcome === "passed") return 0;
|
|
28
|
+
return report.outcome === "failed" ? 1 : 3;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The size as emitted: `--json` prints with two-space indentation, the
|
|
33
|
+
* widest of the forms written (report.json uses tabs).
|
|
34
|
+
*/
|
|
35
|
+
function size(report: InspectReport): number {
|
|
36
|
+
return Buffer.byteLength(JSON.stringify(report, null, 2));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The step the outcome names, which a cut must keep. */
|
|
40
|
+
function outcomeStep(variant: InspectVariantReport): unknown {
|
|
41
|
+
const outcome = variant.outcome;
|
|
42
|
+
if (outcome.kind === "step-failed" || outcome.kind === "page-error")
|
|
43
|
+
return outcome.step;
|
|
44
|
+
return outcome.kind === "timed-out" ? outcome.lastCompletedStep : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function cutLists(variant: InspectVariantReport, keep: number): boolean {
|
|
48
|
+
let cut = false;
|
|
49
|
+
const trim = <T>(list: T[]): T[] => {
|
|
50
|
+
if (list.length <= keep) return list;
|
|
51
|
+
cut = true;
|
|
52
|
+
return list.slice(0, keep);
|
|
53
|
+
};
|
|
54
|
+
const named = outcomeStep(variant);
|
|
55
|
+
const kept = variant.steps.find((s) => s.index === named);
|
|
56
|
+
variant.steps = trim(variant.steps);
|
|
57
|
+
if (kept && !variant.steps.includes(kept))
|
|
58
|
+
variant.steps = [...variant.steps.slice(0, keep - 1), kept];
|
|
59
|
+
variant.artifacts = trim(variant.artifacts);
|
|
60
|
+
// Reopens add a client each; the ones with page errors (the evidence
|
|
61
|
+
// for a page-error outcome) go first.
|
|
62
|
+
const withPageErrors = variant.clients.filter((c) => c.pageErrors.length);
|
|
63
|
+
variant.clients = trim([
|
|
64
|
+
...withPageErrors,
|
|
65
|
+
...variant.clients.filter((c) => !withPageErrors.includes(c)),
|
|
66
|
+
]);
|
|
67
|
+
for (const client of variant.clients) {
|
|
68
|
+
client.consoleErrors = trim(client.consoleErrors);
|
|
69
|
+
client.consoleWarnings = trim(client.consoleWarnings);
|
|
70
|
+
client.pageErrors = trim(client.pageErrors);
|
|
71
|
+
client.failedRequests = trim(client.failedRequests);
|
|
72
|
+
}
|
|
73
|
+
return cut;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function dropInline(report: InspectReport): void {
|
|
77
|
+
for (const variant of report.variants) {
|
|
78
|
+
// A value has no file; its inline text is the only copy.
|
|
79
|
+
for (const artifact of variant.artifacts)
|
|
80
|
+
if (artifact.kind !== "value") artifact.inline = null;
|
|
81
|
+
variant.output = variant.output?.slice(-1024) ?? null;
|
|
82
|
+
}
|
|
83
|
+
report.truncated.push("report-size:inline");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** UTF-8 byte budgets for each text a summary keeps, tried in order until it fits. */
|
|
87
|
+
const SUMMARY_TEXT_BYTES = [1024, 256, 64, 0] as const;
|
|
88
|
+
|
|
89
|
+
/** The longest start of `text` within `maxBytes` UTF-8 bytes. */
|
|
90
|
+
export function clipUtf8(text: string, maxBytes: number): string {
|
|
91
|
+
const bytes = Buffer.from(text);
|
|
92
|
+
if (bytes.length <= maxBytes) return text;
|
|
93
|
+
// A cut inside a character decodes as U+FFFD; drop it.
|
|
94
|
+
return bytes.subarray(0, maxBytes).toString("utf8").replace(/�+$/, "");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The last resort: each variant keeps its outcome, its outcome's step, and
|
|
99
|
+
* its warnings, each text at most `textBytes` UTF-8 bytes, and nothing
|
|
100
|
+
* else. With a budget of 0 only the structure stays, about 2 KB for the
|
|
101
|
+
* most variants (6).
|
|
102
|
+
*/
|
|
103
|
+
function summarize(report: InspectReport, textBytes: number): void {
|
|
104
|
+
const clip = (text: string) => clipUtf8(text, textBytes);
|
|
105
|
+
for (const variant of report.variants) {
|
|
106
|
+
const outcome = variant.outcome;
|
|
107
|
+
if ("error" in outcome) outcome.error = clip(outcome.error);
|
|
108
|
+
const named = outcomeStep(variant);
|
|
109
|
+
variant.steps = variant.steps
|
|
110
|
+
.filter((s) => s.index === named)
|
|
111
|
+
.map((s) => ({ ...s, error: s.error && clip(s.error) }));
|
|
112
|
+
variant.clients = [];
|
|
113
|
+
variant.artifacts = [];
|
|
114
|
+
variant.actions = {};
|
|
115
|
+
variant.output = null;
|
|
116
|
+
variant.returnValue = variant.returnValue && clip(variant.returnValue);
|
|
117
|
+
variant.warnings = variant.warnings.slice(0, 4).map(clip);
|
|
118
|
+
variant.truncated = variant.truncated.slice(0, 16).map(clip);
|
|
119
|
+
}
|
|
120
|
+
report.warnings = report.warnings.slice(0, 8).map(clip);
|
|
121
|
+
if (!report.truncated.includes("report-size:summary"))
|
|
122
|
+
report.truncated.push("report-size:summary");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Keeps the report under its size limit: inline content goes first, then
|
|
127
|
+
* entry lists (client history included) are cut, then only a summary of
|
|
128
|
+
* each variant stays; each step is marked in `truncated`.
|
|
129
|
+
*/
|
|
130
|
+
export function fitReport(
|
|
131
|
+
report: InspectReport,
|
|
132
|
+
maxBytes = REPORT_MAX_BYTES,
|
|
133
|
+
): InspectReport {
|
|
134
|
+
if (size(report) <= maxBytes) return report;
|
|
135
|
+
dropInline(report);
|
|
136
|
+
if (size(report) <= maxBytes) return report;
|
|
137
|
+
report.truncated.push("report-size:lists");
|
|
138
|
+
for (
|
|
139
|
+
let keep = 64;
|
|
140
|
+
keep >= 1 && size(report) > maxBytes;
|
|
141
|
+
keep = Math.floor(keep / 2)
|
|
142
|
+
) {
|
|
143
|
+
for (const variant of report.variants) cutLists(variant, keep);
|
|
144
|
+
}
|
|
145
|
+
// Each smaller text budget is tried while the report is still over.
|
|
146
|
+
for (const textBytes of SUMMARY_TEXT_BYTES) {
|
|
147
|
+
if (size(report) <= maxBytes) break;
|
|
148
|
+
summarize(report, textBytes);
|
|
149
|
+
}
|
|
150
|
+
return report;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function outcomeLine(variant: InspectVariantReport): string {
|
|
154
|
+
const outcome = variant.outcome;
|
|
155
|
+
switch (outcome.kind) {
|
|
156
|
+
case "passed":
|
|
157
|
+
case "not-started":
|
|
158
|
+
return outcome.kind;
|
|
159
|
+
case "timed-out":
|
|
160
|
+
return `timed out (last completed step: ${outcome.lastCompletedStep ?? "none"})`;
|
|
161
|
+
default:
|
|
162
|
+
return `${outcome.kind} at step ${outcome.step}: ${outcome.error}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function clientLines(variant: InspectVariantReport): string[] {
|
|
167
|
+
return variant.clients.flatMap((client) =>
|
|
168
|
+
(
|
|
169
|
+
[
|
|
170
|
+
["page error", client.pageErrors],
|
|
171
|
+
["console error", client.consoleErrors],
|
|
172
|
+
["failed request", client.failedRequests],
|
|
173
|
+
] as const
|
|
174
|
+
).flatMap(([label, list]) =>
|
|
175
|
+
list.map((entry) => ` ${client.clientId} ${label}: ${entry}`),
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function stepLine(step: InspectVariantReport["steps"][number]): string {
|
|
181
|
+
const state = step.ok
|
|
182
|
+
? "ok"
|
|
183
|
+
: step.interrupted
|
|
184
|
+
? "interrupted"
|
|
185
|
+
: step.caught
|
|
186
|
+
? "failed (caught)"
|
|
187
|
+
: "FAILED";
|
|
188
|
+
const error = step.error ? `: ${step.error.split("\n")[0]}` : "";
|
|
189
|
+
return ` step ${step.index} ${step.action} p${step.player ?? "-"} ${state} ${step.ms}ms${error}`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function artifactLine(
|
|
193
|
+
artifact: InspectVariantReport["artifacts"][number],
|
|
194
|
+
): string {
|
|
195
|
+
return artifact.kind === "value"
|
|
196
|
+
? ` value ${artifact.name} = ${artifact.inline}`
|
|
197
|
+
: ` ${artifact.kind} ${artifact.path}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function variantLines(variant: InspectVariantReport): string[] {
|
|
201
|
+
const lines = [
|
|
202
|
+
`\n${variant.id}: ${outcomeLine(variant)}`,
|
|
203
|
+
...clientLines(variant),
|
|
204
|
+
...variant.steps.map(stepLine),
|
|
205
|
+
...variant.artifacts.map(artifactLine),
|
|
206
|
+
];
|
|
207
|
+
if (variant.returnValue !== null)
|
|
208
|
+
lines.push(` returned: ${variant.returnValue}`);
|
|
209
|
+
if (variant.output)
|
|
210
|
+
lines.push(
|
|
211
|
+
" output:",
|
|
212
|
+
...variant.output
|
|
213
|
+
.split("\n")
|
|
214
|
+
.slice(-20)
|
|
215
|
+
.map((l) => ` ${l}`),
|
|
216
|
+
);
|
|
217
|
+
lines.push(...variant.warnings.map((w) => ` warning: ${w}`));
|
|
218
|
+
if (variant.truncated.length > 0)
|
|
219
|
+
lines.push(` truncated: ${variant.truncated.join(", ")}`);
|
|
220
|
+
return lines;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The human summary: outcome, stage, timings, then each variant. */
|
|
224
|
+
export function formatReport(report: InspectReport): string {
|
|
225
|
+
const t = report.timings;
|
|
226
|
+
const lines = [
|
|
227
|
+
`Inspect ${report.runId}: ${report.outcome} (stage ${report.stage})`,
|
|
228
|
+
` slot wait ${t.slotWaitMs}ms, build ${t.buildMs}ms${report.build.ran ? ` (ran: ${report.build.reason})` : ""}, variants ${t.variantsMs}ms, total ${t.totalMs}ms`,
|
|
229
|
+
...report.warnings.map((w) => ` warning: ${w}`),
|
|
230
|
+
...report.variants.flatMap(variantLines),
|
|
231
|
+
];
|
|
232
|
+
if (report.truncated.length > 0)
|
|
233
|
+
lines.push(`truncated: ${report.truncated.join(", ")}`);
|
|
234
|
+
return lines.join("\n");
|
|
235
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* `tiles inspect` run state: the run record, budgets carried between
|
|
4
|
+
* variants, and folding each variant's result into the run.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { type FileLock, tryLock } from "./inspect-lock.js";
|
|
12
|
+
import type { InspectPlan } from "./inspect-options.js";
|
|
13
|
+
import type { GroupResult } from "./inspect-process.js";
|
|
14
|
+
import {
|
|
15
|
+
fitReport,
|
|
16
|
+
type InspectReport,
|
|
17
|
+
type InspectVariantReport,
|
|
18
|
+
overallOutcome,
|
|
19
|
+
} from "./inspect-report.js";
|
|
20
|
+
import {
|
|
21
|
+
SUPPORTED_CONTRACT_VERSIONS,
|
|
22
|
+
type VariantInput,
|
|
23
|
+
type VariantResult,
|
|
24
|
+
} from "./inspect-run.js";
|
|
25
|
+
|
|
26
|
+
export const RETAINED_RUNS = 5;
|
|
27
|
+
const NAMED_SCREENSHOTS = 40;
|
|
28
|
+
const TERMINAL_SCREENSHOTS = 6;
|
|
29
|
+
const NAMED_SNAPSHOTS = 40;
|
|
30
|
+
|
|
31
|
+
export interface InspectDeps {
|
|
32
|
+
/** Runs `bun run build` in the tile, inheriting the lock descriptors. */
|
|
33
|
+
runBuild(
|
|
34
|
+
tileDir: string,
|
|
35
|
+
inheritFds: number[],
|
|
36
|
+
signal: AbortSignal,
|
|
37
|
+
): Promise<GroupResult>;
|
|
38
|
+
runVariant(params: {
|
|
39
|
+
tileDir: string;
|
|
40
|
+
input: VariantInput;
|
|
41
|
+
inheritFds: number[];
|
|
42
|
+
signal: AbortSignal;
|
|
43
|
+
}): Promise<VariantResult>;
|
|
44
|
+
writeEntry(runDir: string): void;
|
|
45
|
+
slotDir: string;
|
|
46
|
+
now(): number;
|
|
47
|
+
log(message: string): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type Stage = InspectReport["stage"];
|
|
51
|
+
|
|
52
|
+
export function newRunId(now: Date): string {
|
|
53
|
+
const stamp = now
|
|
54
|
+
.toISOString()
|
|
55
|
+
.replace(/[-:]/g, "")
|
|
56
|
+
.replace("T", "-")
|
|
57
|
+
.slice(0, 15);
|
|
58
|
+
return `${stamp}-${randomBytes(2).toString("hex")}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function defaultSlotDir(): string {
|
|
62
|
+
return join(tmpdir(), "poe-tiles-inspect");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function variantId(v: {
|
|
66
|
+
viewport: string;
|
|
67
|
+
colorScheme: string;
|
|
68
|
+
}): string {
|
|
69
|
+
return `${v.viewport}-${v.colorScheme}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function notStarted(v: {
|
|
73
|
+
viewport: string;
|
|
74
|
+
colorScheme: "light" | "dark";
|
|
75
|
+
}): InspectVariantReport {
|
|
76
|
+
return {
|
|
77
|
+
id: variantId(v),
|
|
78
|
+
viewport: v.viewport as InspectVariantReport["viewport"],
|
|
79
|
+
colorScheme: v.colorScheme,
|
|
80
|
+
outcome: { kind: "not-started" },
|
|
81
|
+
timings: { serverMs: 0, browserMs: 0, openMs: 0, bodyMs: 0 },
|
|
82
|
+
clients: [],
|
|
83
|
+
steps: [],
|
|
84
|
+
artifacts: [],
|
|
85
|
+
actions: {},
|
|
86
|
+
output: null,
|
|
87
|
+
returnValue: null,
|
|
88
|
+
warnings: [],
|
|
89
|
+
truncated: [],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class Run {
|
|
94
|
+
readonly runId: string;
|
|
95
|
+
readonly runDir: string;
|
|
96
|
+
readonly inspectDir: string;
|
|
97
|
+
readonly started: number;
|
|
98
|
+
readonly locks: FileLock[] = [];
|
|
99
|
+
readonly warnings: string[] = [];
|
|
100
|
+
stage: Stage = "queued";
|
|
101
|
+
timings = { slotWaitMs: 0, buildMs: 0, variantsMs: 0, totalMs: 0 };
|
|
102
|
+
build: InspectReport["build"] = {
|
|
103
|
+
ran: false,
|
|
104
|
+
reason: null,
|
|
105
|
+
sourceFingerprint: "",
|
|
106
|
+
distFingerprint: "",
|
|
107
|
+
};
|
|
108
|
+
variants: InspectVariantReport[] = [];
|
|
109
|
+
budget = {
|
|
110
|
+
named: NAMED_SCREENSHOTS,
|
|
111
|
+
terminal: TERMINAL_SCREENSHOTS,
|
|
112
|
+
snapshots: NAMED_SNAPSHOTS,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
constructor(
|
|
116
|
+
readonly plan: InspectPlan,
|
|
117
|
+
readonly deps: InspectDeps,
|
|
118
|
+
) {
|
|
119
|
+
this.started = deps.now();
|
|
120
|
+
this.runId = newRunId(new Date(this.started));
|
|
121
|
+
this.inspectDir = join(plan.tileDir, ".visual-checks", "inspect");
|
|
122
|
+
this.runDir = join(this.inspectDir, this.runId);
|
|
123
|
+
mkdirSync(this.runDir, { recursive: true });
|
|
124
|
+
const runLock = tryLock(join(this.runDir, "run.lock"));
|
|
125
|
+
if (typeof runLock !== "string") this.locks.push(runLock);
|
|
126
|
+
this.setStage("queued");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get fds(): number[] {
|
|
130
|
+
return this.locks.map((l) => l.fd);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setStage(stage: Stage): void {
|
|
134
|
+
this.stage = stage;
|
|
135
|
+
writeFileSync(
|
|
136
|
+
join(this.runDir, "run.json"),
|
|
137
|
+
JSON.stringify(
|
|
138
|
+
{
|
|
139
|
+
runId: this.runId,
|
|
140
|
+
stage,
|
|
141
|
+
pid: process.pid,
|
|
142
|
+
startedAt: new Date(this.started).toISOString(),
|
|
143
|
+
plan: this.plan,
|
|
144
|
+
},
|
|
145
|
+
null,
|
|
146
|
+
"\t",
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
report(): InspectReport {
|
|
152
|
+
this.timings.totalMs = this.deps.now() - this.started;
|
|
153
|
+
return fitReport({
|
|
154
|
+
contractVersion: 1,
|
|
155
|
+
runId: this.runId,
|
|
156
|
+
mode: this.plan.body.kind,
|
|
157
|
+
outcome: overallOutcome(this.variants),
|
|
158
|
+
stage: this.stage,
|
|
159
|
+
timings: this.timings,
|
|
160
|
+
build: this.build,
|
|
161
|
+
warnings: this.warnings,
|
|
162
|
+
variants: this.variants,
|
|
163
|
+
truncated: [],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function input(
|
|
169
|
+
run: Run,
|
|
170
|
+
v: InspectPlan["variants"][number],
|
|
171
|
+
): VariantInput {
|
|
172
|
+
const plan = run.plan;
|
|
173
|
+
return {
|
|
174
|
+
variantId: variantId(v),
|
|
175
|
+
parentPid: process.pid,
|
|
176
|
+
supportedContracts: SUPPORTED_CONTRACT_VERSIONS,
|
|
177
|
+
options: {
|
|
178
|
+
distDir: join(run.runDir, "dist"),
|
|
179
|
+
runDir: run.runDir,
|
|
180
|
+
runId: run.runId,
|
|
181
|
+
variant: v,
|
|
182
|
+
players: plan.players,
|
|
183
|
+
screenshotBudget: {
|
|
184
|
+
named: run.budget.named,
|
|
185
|
+
terminal: run.budget.terminal,
|
|
186
|
+
},
|
|
187
|
+
snapshotBudget: run.budget.snapshots,
|
|
188
|
+
time: plan.time,
|
|
189
|
+
ready: plan.ready,
|
|
190
|
+
body: plan.body,
|
|
191
|
+
tileDir: plan.tileDir,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
type Budget = Run["budget"];
|
|
197
|
+
type Artifact = InspectVariantReport["artifacts"][number];
|
|
198
|
+
|
|
199
|
+
/** Orders clients as the SDK does: by player, then by client number (`p<n>-c<k>`). */
|
|
200
|
+
function clientRank(a: Artifact): number {
|
|
201
|
+
const clientNo = Number(/-c(\d+)$/.exec(a.client ?? "")?.[1] ?? 1e6);
|
|
202
|
+
return (a.player ?? 1e6) * 1e7 + clientNo;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The terminal screenshots the SDK takes outside the budget: for each of
|
|
207
|
+
* final and failure, the lowest open client's (player 1's, even after a
|
|
208
|
+
* reopen gave it a new client).
|
|
209
|
+
*/
|
|
210
|
+
function exemptTerminals(artifacts: readonly Artifact[]): Set<Artifact> {
|
|
211
|
+
const primary = new Map<string, Artifact>();
|
|
212
|
+
for (const a of artifacts) {
|
|
213
|
+
if (a.kind !== "screenshot" || typeof a.at === "object") continue;
|
|
214
|
+
const best = primary.get(a.at);
|
|
215
|
+
if (!best || clientRank(a) < clientRank(best)) primary.set(a.at, a);
|
|
216
|
+
}
|
|
217
|
+
return new Set(primary.values());
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Which run-wide budget a capture spends, if any. */
|
|
221
|
+
function budgetOf(a: Artifact, exempt: Set<Artifact>): keyof Budget | null {
|
|
222
|
+
const named = typeof a.at === "object";
|
|
223
|
+
if (a.kind === "snapshot") return named ? "snapshots" : null;
|
|
224
|
+
if (a.kind !== "screenshot") return null;
|
|
225
|
+
if (named) return "named";
|
|
226
|
+
return exempt.has(a) ? null : "terminal";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Charges the variant's captures against the run-wide budgets. */
|
|
230
|
+
function spend(run: Run, report: InspectVariantReport): void {
|
|
231
|
+
const exempt = exemptTerminals(report.artifacts);
|
|
232
|
+
for (const artifact of report.artifacts) {
|
|
233
|
+
const key = budgetOf(artifact, exempt);
|
|
234
|
+
if (key) run.budget[key] = Math.max(0, run.budget[key] - 1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A variant killed at the deadline whose report could not be rebuilt. */
|
|
239
|
+
function lostReport(
|
|
240
|
+
v: InspectPlan["variants"][number],
|
|
241
|
+
result: VariantResult,
|
|
242
|
+
): InspectVariantReport {
|
|
243
|
+
const report = notStarted(v);
|
|
244
|
+
report.outcome = { kind: "timed-out", lastCompletedStep: null };
|
|
245
|
+
report.warnings.push(
|
|
246
|
+
`the variant was stopped at the deadline; ${result.reportProblem ?? "it left no report"}`,
|
|
247
|
+
);
|
|
248
|
+
return report;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** A variant process that failed on its own: warn, and fail a variant that looks fine. */
|
|
252
|
+
function markCrashed(
|
|
253
|
+
report: InspectVariantReport,
|
|
254
|
+
result: VariantResult,
|
|
255
|
+
): void {
|
|
256
|
+
if (result.reportProblem) report.warnings.push(result.reportProblem);
|
|
257
|
+
report.warnings.push(
|
|
258
|
+
`the variant process exited with ${result.exitCode}: ${result.output.slice(-1024)}`,
|
|
259
|
+
);
|
|
260
|
+
// A rebuilt report says timed-out for any variant that started and did
|
|
261
|
+
// not finish; with no deadline, that is the crash, not a timeout.
|
|
262
|
+
const kind = report.outcome.kind;
|
|
263
|
+
if (kind === "passed" || kind === "not-started" || kind === "timed-out") {
|
|
264
|
+
report.outcome = {
|
|
265
|
+
kind: "step-failed",
|
|
266
|
+
step: "harness",
|
|
267
|
+
error: result.output.slice(-2048) || "the variant process crashed",
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function absorb(
|
|
273
|
+
run: Run,
|
|
274
|
+
v: InspectPlan["variants"][number],
|
|
275
|
+
result: VariantResult,
|
|
276
|
+
): void {
|
|
277
|
+
const report =
|
|
278
|
+
result.report ?? (result.aborted ? lostReport(v, result) : notStarted(v));
|
|
279
|
+
if (
|
|
280
|
+
run.plan.body.kind === "script" &&
|
|
281
|
+
report.output === null &&
|
|
282
|
+
result.output
|
|
283
|
+
)
|
|
284
|
+
report.output = result.output;
|
|
285
|
+
// A usage error (exit 2 with error.json) ends the run before this point.
|
|
286
|
+
const crashed =
|
|
287
|
+
result.exitCode !== 0 || result.report === null || result.reportRebuilt;
|
|
288
|
+
if (!result.aborted && crashed) markCrashed(report, result);
|
|
289
|
+
if (result.watchdogFailure) {
|
|
290
|
+
report.warnings.push(
|
|
291
|
+
`the orphan watchdog did not watch this variant (${result.watchdogFailure}); had the CLI died, only the variant's own parent check could have stopped it`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
spend(run, report);
|
|
295
|
+
run.variants.push(report);
|
|
296
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* Runs one `tiles inspect` variant in its own `bun` process, in the tile's
|
|
4
|
+
* directory, so Playwright, the SDK, and a script's imports resolve from
|
|
5
|
+
* the tile's own `node_modules` and no module state carries between
|
|
6
|
+
* variants.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { CHILD_ENTRY } from "./inspect-child-entry.js";
|
|
12
|
+
import { runInGroup } from "./inspect-process.js";
|
|
13
|
+
import type { InspectVariantReport } from "./inspect-report.js";
|
|
14
|
+
|
|
15
|
+
/** Contract versions this CLI can read. */
|
|
16
|
+
export const SUPPORTED_CONTRACT_VERSIONS = [1] as const;
|
|
17
|
+
|
|
18
|
+
export const SCRIPT_OUTPUT_BYTES = 16 * 1024;
|
|
19
|
+
const REBUILD_TIMEOUT_MS = 10_000;
|
|
20
|
+
|
|
21
|
+
export interface VariantInput {
|
|
22
|
+
variantId: string;
|
|
23
|
+
/** The CLI's pid, which the child checks against its parent. */
|
|
24
|
+
parentPid: number;
|
|
25
|
+
supportedContracts: readonly number[];
|
|
26
|
+
options: {
|
|
27
|
+
distDir: string;
|
|
28
|
+
runDir: string;
|
|
29
|
+
runId: string;
|
|
30
|
+
variant: { viewport: string; colorScheme: "light" | "dark" };
|
|
31
|
+
players: number;
|
|
32
|
+
screenshotBudget: { named: number; terminal: number };
|
|
33
|
+
snapshotBudget: number;
|
|
34
|
+
time: string | null;
|
|
35
|
+
ready: unknown;
|
|
36
|
+
body:
|
|
37
|
+
| { kind: "code"; source: string }
|
|
38
|
+
| { kind: "script"; modulePath: string }
|
|
39
|
+
| { kind: "look" };
|
|
40
|
+
tileDir: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface VariantResult {
|
|
45
|
+
report: InspectVariantReport | null;
|
|
46
|
+
usageError: { code: string; message: string } | null;
|
|
47
|
+
/** The child's stdout and stderr tail. */
|
|
48
|
+
output: string;
|
|
49
|
+
exitCode: number | null;
|
|
50
|
+
aborted: boolean;
|
|
51
|
+
/** Why `report` is null when the variant wrote none and none could be rebuilt. */
|
|
52
|
+
reportProblem: string | null;
|
|
53
|
+
/** True when the variant wrote no report and `report` was rebuilt from its progress. */
|
|
54
|
+
reportRebuilt: boolean;
|
|
55
|
+
/** Why the orphan watchdog did not watch; the variant then had only its own parent check. */
|
|
56
|
+
watchdogFailure: string | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function writeChildEntry(runDir: string): string {
|
|
60
|
+
const path = join(runDir, "entry.mjs");
|
|
61
|
+
writeFileSync(path, CHILD_ENTRY);
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readJson<T>(path: string): T | null {
|
|
66
|
+
if (!existsSync(path)) return null;
|
|
67
|
+
try {
|
|
68
|
+
return JSON.parse(readFileSync(path, "utf8")) as T;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Rebuilds a killed variant's report from the progress log, with the tile's SDK. */
|
|
75
|
+
async function rebuildReport(
|
|
76
|
+
entry: string,
|
|
77
|
+
tileDir: string,
|
|
78
|
+
runDir: string,
|
|
79
|
+
variantId: string,
|
|
80
|
+
timeoutMs: number,
|
|
81
|
+
): Promise<{ report: InspectVariantReport | null; problem: string | null }> {
|
|
82
|
+
const out = join(runDir, `${variantId}.rebuilt.json`);
|
|
83
|
+
const result = await runInGroup({
|
|
84
|
+
command: process.execPath,
|
|
85
|
+
args: [entry, "--rebuild", runDir, variantId, out],
|
|
86
|
+
cwd: tileDir,
|
|
87
|
+
inheritFds: [],
|
|
88
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
89
|
+
outputBytes: 4 * 1024,
|
|
90
|
+
});
|
|
91
|
+
const report = readJson<InspectVariantReport>(out);
|
|
92
|
+
if (report) return { report, problem: null };
|
|
93
|
+
const why = result.aborted
|
|
94
|
+
? `it took longer than ${timeoutMs / 1000} s`
|
|
95
|
+
: `exit ${result.exitCode ?? result.signal}`;
|
|
96
|
+
const output = result.output.slice(-1024);
|
|
97
|
+
return {
|
|
98
|
+
report: null,
|
|
99
|
+
problem: `the variant's report could not be rebuilt (${why})${output ? `: ${output}` : ""}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function runVariant(params: {
|
|
104
|
+
entry: string;
|
|
105
|
+
tileDir: string;
|
|
106
|
+
input: VariantInput;
|
|
107
|
+
inheritFds: number[];
|
|
108
|
+
signal: AbortSignal;
|
|
109
|
+
killGraceMs?: number;
|
|
110
|
+
/** How long rebuilding the report of a variant that left none may take. */
|
|
111
|
+
rebuildTimeoutMs?: number;
|
|
112
|
+
}): Promise<VariantResult> {
|
|
113
|
+
const { runDir } = params.input.options;
|
|
114
|
+
const id = params.input.variantId;
|
|
115
|
+
const inputPath = join(runDir, `${id}.input.json`);
|
|
116
|
+
writeFileSync(inputPath, JSON.stringify(params.input));
|
|
117
|
+
const result = await runInGroup({
|
|
118
|
+
command: process.execPath,
|
|
119
|
+
args: [params.entry, inputPath],
|
|
120
|
+
cwd: params.tileDir,
|
|
121
|
+
inheritFds: params.inheritFds,
|
|
122
|
+
signal: params.signal,
|
|
123
|
+
outputBytes: SCRIPT_OUTPUT_BYTES,
|
|
124
|
+
// A variant holds a browser, the run lock, and a slot: it must not
|
|
125
|
+
// outlive the CLI, even when a script blocks its event loop.
|
|
126
|
+
watchdog: true,
|
|
127
|
+
...(params.killGraceMs === undefined
|
|
128
|
+
? {}
|
|
129
|
+
: { killGraceMs: params.killGraceMs }),
|
|
130
|
+
});
|
|
131
|
+
const usage = readJson<{ error: { code: string; message: string } }>(
|
|
132
|
+
join(runDir, id, "error.json"),
|
|
133
|
+
);
|
|
134
|
+
const written = readJson<InspectVariantReport>(
|
|
135
|
+
join(runDir, id, "report.json"),
|
|
136
|
+
);
|
|
137
|
+
const rebuilt =
|
|
138
|
+
written || usage
|
|
139
|
+
? { report: written, problem: null }
|
|
140
|
+
: await rebuildReport(
|
|
141
|
+
params.entry,
|
|
142
|
+
params.tileDir,
|
|
143
|
+
runDir,
|
|
144
|
+
id,
|
|
145
|
+
params.rebuildTimeoutMs ?? REBUILD_TIMEOUT_MS,
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
report: rebuilt.report,
|
|
149
|
+
reportProblem: rebuilt.problem,
|
|
150
|
+
reportRebuilt: written === null && rebuilt.report !== null,
|
|
151
|
+
usageError: usage?.error ?? null,
|
|
152
|
+
output: result.output,
|
|
153
|
+
exitCode: result.exitCode,
|
|
154
|
+
aborted: result.aborted,
|
|
155
|
+
watchdogFailure: result.watchdogFailure,
|
|
156
|
+
};
|
|
157
|
+
}
|