@air-jam/devtools 0.0.0-stage → 1.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-2O67AXCU.js +470 -0
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/chunk-MEIMOSZC.js +749 -0
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-O3XG3FNL.js +1014 -0
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +67 -0
- package/dist/controller.js +40 -0
- package/dist/controller.js.map +1 -0
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dev.d.ts +21 -0
- package/dist/dev.js +19 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -0
- package/dist/game-session-broker.js +40 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +3934 -0
- package/dist/game-session.js +195 -0
- package/dist/game-session.js.map +1 -0
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +28 -0
- package/dist/games.js +16 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +204 -0
- package/dist/harness/visual.js +46 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +15 -0
- package/dist/logs.js +57 -0
- package/dist/logs.js.map +1 -0
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +191 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +9 -0
- package/dist/platform-auth.js +45 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +347 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +87 -0
- package/dist/platform-games.js +183 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +16 -0
- package/dist/quality.js +62 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1304 -0
- package/dist/release.js +34 -0
- package/dist/release.js.map +1 -0
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.d.ts +2 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.d.ts +2 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +931 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +25 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +203 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/types-CdYrgrG_.d.ts +1036 -0
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +21 -0
- package/dist/visual.js +219 -0
- package/dist/visual.js.map +1 -0
- package/package.json +150 -3
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +218 -0
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +1526 -0
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +995 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +106 -0
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +793 -0
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +206 -0
- package/src/game-settings.ts +295 -0
- package/src/games.ts +262 -0
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +549 -0
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +8 -0
- package/src/harness/visual/scenario-helpers.ts +67 -0
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +400 -0
- package/src/harness/visual/types.ts +184 -0
- package/src/harness/visual.ts +7 -0
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +69 -0
- package/src/installed-dependencies.ts +74 -0
- package/src/logs.ts +67 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/mcp-config.ts +262 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +594 -0
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +217 -0
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1683 -0
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +218 -0
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +441 -0
- package/src/tooling/list-visual-scenarios.ts +21 -0
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +231 -0
- package/src/tooling/runtime-owner-actions.ts +65 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +11 -0
- package/src/types.ts +928 -0
- package/src/visual.ts +296 -0
- package/src/windows-process-scopes.ts +189 -0
- package/src/workspace-contract.ts +32 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// src/testing.ts
|
|
2
|
+
import {
|
|
3
|
+
controllerLeasedControlAckSchema,
|
|
4
|
+
leasedControlRequestSchema,
|
|
5
|
+
participantActionOperationSchema,
|
|
6
|
+
participantInputOperationSchema,
|
|
7
|
+
participantReleaseOperationSchema
|
|
8
|
+
} from "@air-jam/sdk/protocol";
|
|
9
|
+
import { z as z2 } from "zod";
|
|
10
|
+
|
|
11
|
+
// src/policy-artifact-contract.ts
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
var policyArtifactPathSchema = z.string().min(1).max(240).refine(
|
|
14
|
+
(value) => !value.includes("\\") && !value.startsWith("/") && value.split("/").every((part) => part !== "" && part !== "." && part !== ".."),
|
|
15
|
+
"Artifacts require canonical relative paths."
|
|
16
|
+
);
|
|
17
|
+
var policyArtifactManifestSchema = z.object({
|
|
18
|
+
version: z.literal(1),
|
|
19
|
+
provenance: z.record(z.string().min(1).max(80), z.json()),
|
|
20
|
+
files: z.array(
|
|
21
|
+
z.object({
|
|
22
|
+
path: policyArtifactPathSchema,
|
|
23
|
+
bytes: z.number().int().positive().max(4 * 1024 ** 3),
|
|
24
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/)
|
|
25
|
+
}).strict()
|
|
26
|
+
).min(1).max(32)
|
|
27
|
+
}).strict().refine(
|
|
28
|
+
(value) => new Set(value.files.map((file) => file.path)).size === value.files.length && value.files.reduce((bytes, file) => bytes + file.bytes, 0) <= 4 * 1024 ** 3,
|
|
29
|
+
"Artifact files must be unique and fit the 4 GiB bundle allowance."
|
|
30
|
+
);
|
|
31
|
+
var policyArtifactReceiptSchema = z.object({
|
|
32
|
+
manifestSha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
33
|
+
manifest: policyArtifactManifestSchema,
|
|
34
|
+
verifyMs: z.number().finite().nonnegative()
|
|
35
|
+
}).strict();
|
|
36
|
+
|
|
37
|
+
// src/testing.ts
|
|
38
|
+
var id = z2.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);
|
|
39
|
+
var profileStepSchema = z2.discriminatedUnion("lane", [
|
|
40
|
+
z2.object({
|
|
41
|
+
lane: z2.literal("host"),
|
|
42
|
+
actionId: participantActionOperationSchema.shape.actionId,
|
|
43
|
+
input: z2.json().optional()
|
|
44
|
+
}).strict(),
|
|
45
|
+
z2.object({
|
|
46
|
+
lane: z2.literal("participant"),
|
|
47
|
+
seatId: id,
|
|
48
|
+
actionId: participantActionOperationSchema.shape.actionId,
|
|
49
|
+
input: z2.json().optional()
|
|
50
|
+
}).strict()
|
|
51
|
+
]);
|
|
52
|
+
var airJamTestProfileDescriptionSchema = z2.object({
|
|
53
|
+
id,
|
|
54
|
+
label: z2.string().min(1).max(120),
|
|
55
|
+
seats: z2.array(z2.object({ id, label: z2.string().min(1).max(80) }).strict()).min(1).max(8),
|
|
56
|
+
setup: z2.array(profileStepSchema).max(32),
|
|
57
|
+
/**
|
|
58
|
+
* The steps that return the creator's room to where people pick up after a
|
|
59
|
+
* test, usually the lobby, run once play ends and before the run's players
|
|
60
|
+
* leave. Only rooms that outlive the run need them; an empty list says the
|
|
61
|
+
* room needs nothing.
|
|
62
|
+
*/
|
|
63
|
+
handBack: z2.array(profileStepSchema).max(32).optional(),
|
|
64
|
+
actions: z2.array(participantActionOperationSchema.shape.actionId).max(64),
|
|
65
|
+
scope: z2.enum(["player", "diagnostic"]),
|
|
66
|
+
includeImage: z2.boolean(),
|
|
67
|
+
timing: z2.object({
|
|
68
|
+
intervalMs: z2.number().int().min(20).max(5e3),
|
|
69
|
+
decisionMs: z2.number().int().min(50).max(1500),
|
|
70
|
+
inputTtlMs: participantInputOperationSchema.shape.ttlMs
|
|
71
|
+
}).strict(),
|
|
72
|
+
policies: z2.array(
|
|
73
|
+
z2.object({
|
|
74
|
+
id,
|
|
75
|
+
label: z2.string().min(1).max(120),
|
|
76
|
+
artifacts: policyArtifactPathSchema.optional()
|
|
77
|
+
}).strict()
|
|
78
|
+
).min(1).max(16),
|
|
79
|
+
metrics: z2.array(z2.object({ id, label: z2.string().min(1).max(120) }).strict()).max(16)
|
|
80
|
+
}).strict();
|
|
81
|
+
var PLAY_RUN_PLAYER = {
|
|
82
|
+
seats: [{ id: "player", label: "Player" }],
|
|
83
|
+
scope: "player",
|
|
84
|
+
includeImage: false,
|
|
85
|
+
timing: { intervalMs: 100, decisionMs: 1200, inputTtlMs: 1500 }
|
|
86
|
+
};
|
|
87
|
+
var byteLength = (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
88
|
+
var policyDiagnosticsSchema = z2.record(id, z2.union([z2.string().max(160), z2.number().finite(), z2.boolean()])).refine(
|
|
89
|
+
(value) => Object.keys(value).length <= 16 && byteLength(value) <= 1024,
|
|
90
|
+
"Policy diagnostics exceed 1 KiB or 16 entries."
|
|
91
|
+
);
|
|
92
|
+
var playControlSchema = z2.discriminatedUnion("kind", [
|
|
93
|
+
participantReleaseOperationSchema,
|
|
94
|
+
participantInputOperationSchema.omit({ deadlineMs: true, ttlMs: true }),
|
|
95
|
+
participantActionOperationSchema.omit({ deadlineMs: true })
|
|
96
|
+
]);
|
|
97
|
+
var QUESTION_STATE_LINES = 32;
|
|
98
|
+
var TURN_STATE_LINES = QUESTION_STATE_LINES - 2;
|
|
99
|
+
var airJamDecisionQuestionSchema = z2.object({
|
|
100
|
+
state: z2.array(z2.string().min(1).max(8e3)).min(1).max(QUESTION_STATE_LINES),
|
|
101
|
+
question: z2.string().min(1).max(1e3),
|
|
102
|
+
options: z2.record(
|
|
103
|
+
z2.string().min(1, "A decision option key must not be empty."),
|
|
104
|
+
z2.object({
|
|
105
|
+
when: z2.string().min(1).max(500),
|
|
106
|
+
control: playControlSchema
|
|
107
|
+
}).strict()
|
|
108
|
+
).refine((options) => {
|
|
109
|
+
const count = Object.keys(options).length;
|
|
110
|
+
return count >= 1 && count <= 16;
|
|
111
|
+
}, "A decision offers between 1 and 16 options.")
|
|
112
|
+
}).strict();
|
|
113
|
+
var airJamPolicyDecisionSchema = z2.union([
|
|
114
|
+
z2.object({
|
|
115
|
+
diagnostics: policyDiagnosticsSchema.optional(),
|
|
116
|
+
control: playControlSchema
|
|
117
|
+
}).strict().refine(
|
|
118
|
+
(value) => byteLength(value) <= 16e3,
|
|
119
|
+
"Policy decision exceeds 16 KB."
|
|
120
|
+
),
|
|
121
|
+
z2.object({
|
|
122
|
+
diagnostics: policyDiagnosticsSchema.optional(),
|
|
123
|
+
ask: airJamDecisionQuestionSchema
|
|
124
|
+
}).strict().refine(
|
|
125
|
+
(value) => byteLength(value) <= 32e3,
|
|
126
|
+
"Decision question exceeds 32 KB."
|
|
127
|
+
)
|
|
128
|
+
]);
|
|
129
|
+
var airJamRunReceiptSchema = z2.object({
|
|
130
|
+
index: z2.number().int().positive(),
|
|
131
|
+
seatId: z2.string(),
|
|
132
|
+
phase: z2.enum(["setup", "play", "cleanup"]),
|
|
133
|
+
sequence: z2.number().int().positive(),
|
|
134
|
+
attempts: z2.union([z2.literal(1), z2.literal(2)]),
|
|
135
|
+
operation: leasedControlRequestSchema.shape.operation,
|
|
136
|
+
acknowledgement: controllerLeasedControlAckSchema
|
|
137
|
+
}).strict();
|
|
138
|
+
var airJamScenarioVerdictSchema = z2.object({
|
|
139
|
+
status: z2.enum(["pending", "passed", "failed"]),
|
|
140
|
+
message: z2.string().min(1).max(1e3).optional(),
|
|
141
|
+
metrics: z2.record(id, z2.number().finite()).optional()
|
|
142
|
+
}).strict();
|
|
143
|
+
var policyPreparationSchema = z2.array(
|
|
144
|
+
z2.object({
|
|
145
|
+
seatId: z2.string(),
|
|
146
|
+
prepareMs: z2.number().finite().nonnegative()
|
|
147
|
+
}).strict()
|
|
148
|
+
).max(8);
|
|
149
|
+
function describeAirJamTestProfiles(profiles) {
|
|
150
|
+
return Object.entries(profiles).map(([profileId, profile]) => {
|
|
151
|
+
const { evaluator, ...metadata } = profile;
|
|
152
|
+
if (typeof evaluator?.create !== "function")
|
|
153
|
+
throw new Error("A scenario must create an independent evaluator.");
|
|
154
|
+
for (const policy of Object.values(profile.policies)) {
|
|
155
|
+
if (typeof policy.create !== "function")
|
|
156
|
+
throw new Error("A test policy must create a decision function.");
|
|
157
|
+
}
|
|
158
|
+
const description = airJamTestProfileDescriptionSchema.parse({
|
|
159
|
+
...metadata,
|
|
160
|
+
id: profileId,
|
|
161
|
+
policies: Object.entries(profile.policies).map(([policyId, policy]) => ({
|
|
162
|
+
id: policyId,
|
|
163
|
+
label: policy.label,
|
|
164
|
+
...policy.artifacts === void 0 ? {} : { artifacts: policy.artifacts }
|
|
165
|
+
}))
|
|
166
|
+
});
|
|
167
|
+
const seats = new Set(description.seats.map((seat) => seat.id));
|
|
168
|
+
if (seats.size !== description.seats.length)
|
|
169
|
+
throw new Error(`Duplicate seats in profile ${profileId}.`);
|
|
170
|
+
if (new Set(description.metrics.map((metric) => metric.id)).size !== description.metrics.length)
|
|
171
|
+
throw new Error(`Duplicate metrics in profile ${profileId}.`);
|
|
172
|
+
if (description.timing.inputTtlMs < description.timing.intervalMs)
|
|
173
|
+
throw new Error("Input lifetime must cover the round interval.");
|
|
174
|
+
for (const step of [
|
|
175
|
+
...description.setup,
|
|
176
|
+
...description.handBack ?? []
|
|
177
|
+
]) {
|
|
178
|
+
if (step.lane === "participant" && !seats.has(step.seatId))
|
|
179
|
+
throw new Error(`Unknown seat ${step.seatId} in profile ${profileId}.`);
|
|
180
|
+
}
|
|
181
|
+
return description;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function defineAirJamTestProfiles(profiles) {
|
|
185
|
+
describeAirJamTestProfiles(profiles);
|
|
186
|
+
return profiles;
|
|
187
|
+
}
|
|
188
|
+
function createAirJamPlayerPolicy(contract) {
|
|
189
|
+
airJamDecisionQuestionSchema.shape.state.element.parse(contract.brief);
|
|
190
|
+
if (typeof contract.turn !== "function")
|
|
191
|
+
throw new Error("A player contract must describe each turn.");
|
|
192
|
+
const act = contract.act;
|
|
193
|
+
if (act && (!Number.isInteger(act.rethinkMs) || act.rethinkMs < 1 || typeof act.create !== "function"))
|
|
194
|
+
throw new Error(
|
|
195
|
+
"A player contract's act needs a positive whole rethinkMs and create."
|
|
196
|
+
);
|
|
197
|
+
return {
|
|
198
|
+
label: "Decision model",
|
|
199
|
+
create: ({ random }) => {
|
|
200
|
+
const actor = act?.create({ random });
|
|
201
|
+
let asked;
|
|
202
|
+
return {
|
|
203
|
+
decide: ({ observation, seatId, intent, answer, elapsedMs }) => {
|
|
204
|
+
const turn = contract.turn({
|
|
205
|
+
observation,
|
|
206
|
+
seatId,
|
|
207
|
+
random,
|
|
208
|
+
elapsedMs
|
|
209
|
+
});
|
|
210
|
+
if (!turn) return { control: { kind: "release" } };
|
|
211
|
+
if (turn.state.length > TURN_STATE_LINES)
|
|
212
|
+
throw new Error(
|
|
213
|
+
`A player contract turn may describe at most ${TURN_STATE_LINES} state lines, so it still fits once the seat is given a goal.`
|
|
214
|
+
);
|
|
215
|
+
if (act && actor && asked && answer && Object.hasOwn(turn.options, answer.choice) && asked.intent === intent) {
|
|
216
|
+
asked.answeredAtMs ??= elapsedMs;
|
|
217
|
+
if (elapsedMs - asked.answeredAtMs < act.rethinkMs)
|
|
218
|
+
return {
|
|
219
|
+
control: actor.control({
|
|
220
|
+
observation,
|
|
221
|
+
seatId,
|
|
222
|
+
choice: answer.choice,
|
|
223
|
+
elapsedMs
|
|
224
|
+
}) ?? { kind: "release" }
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
asked = { intent };
|
|
228
|
+
return {
|
|
229
|
+
ask: {
|
|
230
|
+
...turn,
|
|
231
|
+
state: [
|
|
232
|
+
contract.brief,
|
|
233
|
+
...intent ? [`My goal right now: ${intent}`] : [],
|
|
234
|
+
...turn.state
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function defineAirJamTesting(declaration) {
|
|
244
|
+
const model = declaration.player && createAirJamPlayerPolicy(declaration.player);
|
|
245
|
+
const profiles = Object.fromEntries(
|
|
246
|
+
Object.entries(declaration.profiles).map(([id2, profile]) => {
|
|
247
|
+
if (Object.hasOwn(profile.policies, "model"))
|
|
248
|
+
throw new Error(
|
|
249
|
+
`AJ_TEST_POLICY_RESERVED: Profile "${id2}" must declare its player in defineAirJamTesting.player, not a model policy.`
|
|
250
|
+
);
|
|
251
|
+
return [
|
|
252
|
+
id2,
|
|
253
|
+
{
|
|
254
|
+
...profile,
|
|
255
|
+
policies: { ...profile.policies, ...model ? { model } : {} }
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
describeAirJamTestProfiles(profiles);
|
|
261
|
+
return { ...declaration, profiles };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export {
|
|
265
|
+
policyArtifactManifestSchema,
|
|
266
|
+
policyArtifactReceiptSchema,
|
|
267
|
+
airJamTestProfileDescriptionSchema,
|
|
268
|
+
PLAY_RUN_PLAYER,
|
|
269
|
+
airJamDecisionQuestionSchema,
|
|
270
|
+
airJamPolicyDecisionSchema,
|
|
271
|
+
airJamRunReceiptSchema,
|
|
272
|
+
airJamScenarioVerdictSchema,
|
|
273
|
+
policyPreparationSchema,
|
|
274
|
+
describeAirJamTestProfiles,
|
|
275
|
+
defineAirJamTestProfiles,
|
|
276
|
+
createAirJamPlayerPolicy,
|
|
277
|
+
defineAirJamTesting
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=chunk-PMNE5GIN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts","../src/policy-artifact-contract.ts"],"sourcesContent":["import {\n controllerLeasedControlAckSchema,\n leasedControlRequestSchema,\n participantActionOperationSchema,\n participantInputOperationSchema,\n participantReleaseOperationSchema,\n} from \"@air-jam/sdk/protocol\";\nimport type { HostObservation } from \"@air-jam/sdk/runtime-control\";\nimport { z } from \"zod\";\nimport type { policyArtifactReceiptSchema } from \"./policy-artifact-contract.js\";\nimport { policyArtifactPathSchema } from \"./policy-artifact-contract.js\";\n\nconst id = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);\nconst profileStepSchema = z.discriminatedUnion(\"lane\", [\n z\n .object({\n lane: z.literal(\"host\"),\n actionId: participantActionOperationSchema.shape.actionId,\n input: z.json().optional(),\n })\n .strict(),\n z\n .object({\n lane: z.literal(\"participant\"),\n seatId: id,\n actionId: participantActionOperationSchema.shape.actionId,\n input: z.json().optional(),\n })\n .strict(),\n]);\nexport const airJamTestProfileDescriptionSchema = z\n .object({\n id,\n label: z.string().min(1).max(120),\n seats: z\n .array(z.object({ id, label: z.string().min(1).max(80) }).strict())\n .min(1)\n .max(8),\n setup: z.array(profileStepSchema).max(32),\n /**\n * The steps that return the creator's room to where people pick up after a\n * test, usually the lobby, run once play ends and before the run's players\n * leave. Only rooms that outlive the run need them; an empty list says the\n * room needs nothing.\n */\n handBack: z.array(profileStepSchema).max(32).optional(),\n actions: z.array(participantActionOperationSchema.shape.actionId).max(64),\n scope: z.enum([\"player\", \"diagnostic\"]),\n includeImage: z.boolean(),\n timing: z\n .object({\n intervalMs: z.number().int().min(20).max(5000),\n decisionMs: z.number().int().min(50).max(1500),\n inputTtlMs: participantInputOperationSchema.shape.ttlMs,\n })\n .strict(),\n policies: z\n .array(\n z\n .object({\n id,\n label: z.string().min(1).max(120),\n artifacts: policyArtifactPathSchema.optional(),\n })\n .strict(),\n )\n .min(1)\n .max(16),\n metrics: z\n .array(z.object({ id, label: z.string().min(1).max(120) }).strict())\n .max(16),\n })\n .strict();\nexport type AirJamTestProfileDescription = z.infer<\n typeof airJamTestProfileDescriptionSchema\n>;\n\nexport const PLAY_RUN_PLAYER = {\n seats: [{ id: \"player\", label: \"Player\" }],\n scope: \"player\",\n includeImage: false,\n timing: { intervalMs: 100, decisionMs: 1200, inputTtlMs: 1500 },\n} satisfies AirJamRunPlayers;\nexport type AirJamRunPlayers = Pick<\n AirJamTestProfileDescription,\n \"seats\" | \"scope\" | \"includeImage\" | \"timing\"\n>;\n\nconst byteLength = (value: unknown) =>\n new TextEncoder().encode(JSON.stringify(value)).byteLength;\nconst policyDiagnosticsSchema = z\n .record(id, z.union([z.string().max(160), z.number().finite(), z.boolean()]))\n .refine(\n (value) => Object.keys(value).length <= 16 && byteLength(value) <= 1024,\n \"Policy diagnostics exceed 1 KiB or 16 entries.\",\n );\nconst playControlSchema = z.discriminatedUnion(\"kind\", [\n participantReleaseOperationSchema,\n participantInputOperationSchema.omit({ deadlineMs: true, ttlMs: true }),\n participantActionOperationSchema.omit({ deadlineMs: true }),\n]);\nexport type AirJamPlayControl = z.infer<typeof playControlSchema>;\n\nconst QUESTION_STATE_LINES = 32;\n/** A turn's own lines, leaving room for the brief and a goal line. */\nconst TURN_STATE_LINES = QUESTION_STATE_LINES - 2;\n\n/**\n * A turn resolved by the run owner, asking its decision model only when there\n * is more than one option. Every option is an ordinary\n * play control (an input, an action, or doing nothing), so the model can only\n * ever pick among controls the game already accepts. The size bound keeps the\n * question inside the fast context of current typed decision models.\n */\nexport const airJamDecisionQuestionSchema = z\n .object({\n state: z\n .array(z.string().min(1).max(8000))\n .min(1)\n .max(QUESTION_STATE_LINES),\n question: z.string().min(1).max(1000),\n options: z\n .record(\n z.string().min(1, \"A decision option key must not be empty.\"),\n z\n .object({\n when: z.string().min(1).max(500),\n control: playControlSchema,\n })\n .strict(),\n )\n .refine((options) => {\n const count = Object.keys(options).length;\n return count >= 1 && count <= 16;\n }, \"A decision offers between 1 and 16 options.\"),\n })\n .strict();\nexport type AirJamDecisionQuestion = z.infer<\n typeof airJamDecisionQuestionSchema\n>;\n\nexport const airJamPolicyDecisionSchema = z.union([\n z\n .object({\n diagnostics: policyDiagnosticsSchema.optional(),\n control: playControlSchema,\n })\n .strict()\n .refine(\n (value) => byteLength(value) <= 16_000,\n \"Policy decision exceeds 16 KB.\",\n ),\n z\n .object({\n diagnostics: policyDiagnosticsSchema.optional(),\n ask: airJamDecisionQuestionSchema,\n })\n .strict()\n .refine(\n (value) => byteLength(value) <= 32_000,\n \"Decision question exceeds 32 KB.\",\n ),\n]);\nexport type AirJamPolicyDecision = z.infer<typeof airJamPolicyDecisionSchema>;\n\nexport const airJamRunReceiptSchema = z\n .object({\n index: z.number().int().positive(),\n seatId: z.string(),\n phase: z.enum([\"setup\", \"play\", \"cleanup\"]),\n sequence: z.number().int().positive(),\n attempts: z.union([z.literal(1), z.literal(2)]),\n operation: leasedControlRequestSchema.shape.operation,\n acknowledgement: controllerLeasedControlAckSchema,\n })\n .strict();\nexport type AirJamRunReceipt = z.infer<typeof airJamRunReceiptSchema>;\n\nexport const airJamScenarioVerdictSchema = z\n .object({\n status: z.enum([\"pending\", \"passed\", \"failed\"]),\n message: z.string().min(1).max(1000).optional(),\n metrics: z.record(id, z.number().finite()).optional(),\n })\n .strict();\nexport type AirJamScenarioVerdict = z.infer<typeof airJamScenarioVerdictSchema>;\nexport type AirJamScenarioSample = {\n phase: \"play\" | \"final\";\n observation: HostObservation;\n seats: Array<{ seatId: string; controllerId: string }>;\n receipts: AirJamRunReceipt[];\n elapsedMs: number;\n};\n\nexport type AirJamPolicyStep = {\n observation: HostObservation;\n seatId: string;\n /** What this seat is currently trying to do, if anyone has said. */\n intent: string | null;\n /** The decision model's answer to this seat's latest question, if any. */\n answer: { choice: string; confidence: number } | null;\n step: number;\n elapsedMs: number;\n receipts: AirJamRunReceipt[];\n};\nexport type AirJamPolicyDecider = {\n decide: (\n step: AirJamPolicyStep,\n ) => AirJamPolicyDecision | Promise<AirJamPolicyDecision>;\n};\nexport type AirJamTestPolicy = {\n label: string;\n artifacts?: string;\n create: (context: {\n seatId: string;\n random: () => number;\n artifacts?: {\n directory: string;\n receipt: z.infer<typeof policyArtifactReceiptSchema>;\n };\n }) => AirJamPolicyDecider | Promise<AirJamPolicyDecider>;\n};\nexport const policyPreparationSchema = z\n .array(\n z\n .object({\n seatId: z.string(),\n prepareMs: z.number().finite().nonnegative(),\n })\n .strict(),\n )\n .max(8);\nexport type AirJamTestProfile = Omit<\n AirJamTestProfileDescription,\n \"id\" | \"policies\"\n> & {\n policies: Record<string, AirJamTestPolicy>;\n evaluator: {\n create: (context: { seats: readonly string[] }) => {\n evaluate: (sample: AirJamScenarioSample) => AirJamScenarioVerdict;\n };\n };\n};\n\nexport function describeAirJamTestProfiles(\n profiles: Record<string, AirJamTestProfile>,\n) {\n return Object.entries(profiles).map(([profileId, profile]) => {\n const { evaluator, ...metadata } = profile;\n if (typeof evaluator?.create !== \"function\")\n throw new Error(\"A scenario must create an independent evaluator.\");\n for (const policy of Object.values(profile.policies)) {\n if (typeof policy.create !== \"function\")\n throw new Error(\"A test policy must create a decision function.\");\n }\n const description = airJamTestProfileDescriptionSchema.parse({\n ...metadata,\n id: profileId,\n policies: Object.entries(profile.policies).map(([policyId, policy]) => ({\n id: policyId,\n label: policy.label,\n ...(policy.artifacts === undefined\n ? {}\n : { artifacts: policy.artifacts }),\n })),\n });\n const seats = new Set(description.seats.map((seat) => seat.id));\n if (seats.size !== description.seats.length)\n throw new Error(`Duplicate seats in profile ${profileId}.`);\n if (\n new Set(description.metrics.map((metric) => metric.id)).size !==\n description.metrics.length\n )\n throw new Error(`Duplicate metrics in profile ${profileId}.`);\n if (description.timing.inputTtlMs < description.timing.intervalMs)\n throw new Error(\"Input lifetime must cover the round interval.\");\n for (const step of [\n ...description.setup,\n ...(description.handBack ?? []),\n ]) {\n if (step.lane === \"participant\" && !seats.has(step.seatId))\n throw new Error(`Unknown seat ${step.seatId} in profile ${profileId}.`);\n }\n return description;\n });\n}\n\nexport function defineAirJamTestProfiles<\n const T extends Record<string, AirJamTestProfile>,\n>(profiles: T): T {\n describeAirJamTestProfiles(profiles);\n return profiles;\n}\n\n/**\n * How a game is played by a typed decision model, written by whoever writes the\n * game. The brief explains the game to a reader who has never seen it; each\n * turn describes the current state in words and offers choices that resolve to\n * the game's own inputs or actions. A seat with nothing to decide returns null.\n */\nexport type AirJamPlayerContract = {\n brief: string;\n turn: (context: {\n observation: HostObservation;\n seatId: string;\n /** The seat's seeded randomness, so a run replays the same choices. */\n random: () => number;\n /** Play time so far: game time in a headless room. */\n elapsedMs: number;\n }) => AirJamDecisionQuestion | null;\n /**\n * For games that need control faster than a model answers. Between\n * questions the seat keeps acting on the model's last choice at the run's\n * step rate, for `rethinkMs` after the answer arrives, and is asked again\n * sooner when its goal changes or that choice is no longer offered.\n * `create` runs once per seat, so a seat can keep state such as a pilot.\n */\n act?: {\n rethinkMs: number;\n create: (context: { random: () => number }) => {\n control: (context: {\n observation: HostObservation;\n seatId: string;\n choice: string;\n elapsedMs: number;\n }) => AirJamPlayControl | null;\n };\n };\n};\n\n/**\n * A test policy that plays every seat through the run's decision model. The\n * brief and any seat intent lead every question, so a turn may describe at\n * most 30 state lines.\n */\nexport function createAirJamPlayerPolicy(\n contract: AirJamPlayerContract,\n): AirJamTestPolicy {\n airJamDecisionQuestionSchema.shape.state.element.parse(contract.brief);\n if (typeof contract.turn !== \"function\")\n throw new Error(\"A player contract must describe each turn.\");\n const act = contract.act;\n if (\n act &&\n (!Number.isInteger(act.rethinkMs) ||\n act.rethinkMs < 1 ||\n typeof act.create !== \"function\")\n )\n throw new Error(\n \"A player contract's act needs a positive whole rethinkMs and create.\",\n );\n return {\n label: \"Decision model\",\n create: ({ random }) => {\n const actor = act?.create({ random });\n let asked: { intent: string | null; answeredAtMs?: number } | undefined;\n return {\n decide: ({ observation, seatId, intent, answer, elapsedMs }) => {\n const turn = contract.turn({\n observation,\n seatId,\n random,\n elapsedMs,\n });\n if (!turn) return { control: { kind: \"release\" } };\n if (turn.state.length > TURN_STATE_LINES)\n throw new Error(\n `A player contract turn may describe at most ${TURN_STATE_LINES} state lines, so it still fits once the seat is given a goal.`,\n );\n if (\n act &&\n actor &&\n asked &&\n answer &&\n Object.hasOwn(turn.options, answer.choice) &&\n asked.intent === intent\n ) {\n asked.answeredAtMs ??= elapsedMs;\n if (elapsedMs - asked.answeredAtMs < act.rethinkMs)\n return {\n control: actor.control({\n observation,\n seatId,\n choice: answer.choice,\n elapsedMs,\n }) ?? { kind: \"release\" },\n };\n }\n asked = { intent };\n return {\n ask: {\n ...turn,\n state: [\n contract.brief,\n ...(intent ? [`My goal right now: ${intent}`] : []),\n ...turn.state,\n ],\n },\n };\n },\n };\n },\n };\n}\n\nexport function defineAirJamTesting(declaration: {\n player?: AirJamPlayerContract;\n profiles: Record<string, AirJamTestProfile>;\n visual?: import(\"./harness/visual.js\").VisualScenarioPack;\n}) {\n const model =\n declaration.player && createAirJamPlayerPolicy(declaration.player);\n const profiles = Object.fromEntries(\n Object.entries(declaration.profiles).map(([id, profile]) => {\n if (Object.hasOwn(profile.policies, \"model\"))\n throw new Error(\n `AJ_TEST_POLICY_RESERVED: Profile \"${id}\" must declare its player in defineAirJamTesting.player, not a model policy.`,\n );\n return [\n id,\n {\n ...profile,\n policies: { ...profile.policies, ...(model ? { model } : {}) },\n },\n ];\n }),\n );\n describeAirJamTestProfiles(profiles);\n return { ...declaration, profiles };\n}\n","import { z } from \"zod\";\n\nexport const policyArtifactPathSchema = z\n .string()\n .min(1)\n .max(240)\n .refine(\n (value) =>\n !value.includes(\"\\\\\") &&\n !value.startsWith(\"/\") &&\n value\n .split(\"/\")\n .every((part) => part !== \"\" && part !== \".\" && part !== \"..\"),\n \"Artifacts require canonical relative paths.\",\n );\nexport const policyArtifactManifestSchema = z\n .object({\n version: z.literal(1),\n provenance: z.record(z.string().min(1).max(80), z.json()),\n files: z\n .array(\n z\n .object({\n path: policyArtifactPathSchema,\n bytes: z\n .number()\n .int()\n .positive()\n .max(4 * 1024 ** 3),\n sha256: z.string().regex(/^[a-f0-9]{64}$/),\n })\n .strict(),\n )\n .min(1)\n .max(32),\n })\n .strict()\n .refine(\n (value) =>\n new Set(value.files.map((file) => file.path)).size ===\n value.files.length &&\n value.files.reduce((bytes, file) => bytes + file.bytes, 0) <=\n 4 * 1024 ** 3,\n \"Artifact files must be unique and fit the 4 GiB bundle allowance.\",\n );\nexport const policyArtifactReceiptSchema = z\n .object({\n manifestSha256: z.string().regex(/^[a-f0-9]{64}$/),\n manifest: policyArtifactManifestSchema,\n verifyMs: z.number().finite().nonnegative(),\n })\n .strict();\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,KAAAA,UAAS;;;ACRlB,SAAS,SAAS;AAEX,IAAM,2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;AACnC,SAAO,EAAE,GAAG,aAAa,SAAS;AACpC;","names":["z","z","id"]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dependencyInstallObservationSchema
|
|
3
|
+
} from "./chunk-OM6SCJ7H.js";
|
|
4
|
+
|
|
5
|
+
// src/dependencies.ts
|
|
6
|
+
import crossSpawn from "cross-spawn";
|
|
7
|
+
import { rm } from "fs/promises";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { createInterface } from "readline";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
var eventSchema = z.object({
|
|
12
|
+
name: z.string().optional(),
|
|
13
|
+
packageId: z.string().optional(),
|
|
14
|
+
status: z.string().optional(),
|
|
15
|
+
stage: z.string().optional(),
|
|
16
|
+
method: z.string().optional(),
|
|
17
|
+
added: z.number().int().optional(),
|
|
18
|
+
level: z.string().optional()
|
|
19
|
+
});
|
|
20
|
+
var DependencyInstallObservation = class {
|
|
21
|
+
packages = /* @__PURE__ */ new Map();
|
|
22
|
+
started = performance.now();
|
|
23
|
+
stages = [];
|
|
24
|
+
added = 0;
|
|
25
|
+
importMethods = /* @__PURE__ */ new Set();
|
|
26
|
+
errors = "";
|
|
27
|
+
accept(line) {
|
|
28
|
+
let value;
|
|
29
|
+
try {
|
|
30
|
+
value = JSON.parse(line);
|
|
31
|
+
} catch {
|
|
32
|
+
this.errors = (this.errors + "\n" + line).slice(-16384);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const parsed = eventSchema.safeParse(value);
|
|
36
|
+
if (!parsed.success) return;
|
|
37
|
+
const event = parsed.data;
|
|
38
|
+
if (event.method && (event.name === "pnpm:package-import-method" || event.name === "pnpm:progress" && event.status === "imported"))
|
|
39
|
+
this.importMethods.add(event.method);
|
|
40
|
+
if (event.name === "pnpm:progress" && event.packageId && event.status) {
|
|
41
|
+
const states = this.packages.get(event.packageId) ?? /* @__PURE__ */ new Set();
|
|
42
|
+
states.add(event.status);
|
|
43
|
+
this.packages.set(event.packageId, states);
|
|
44
|
+
}
|
|
45
|
+
if (event.name === "pnpm:stage" && event.stage && ["importing_started", "importing_done"].includes(event.stage))
|
|
46
|
+
this.stages.push({
|
|
47
|
+
stage: event.stage,
|
|
48
|
+
offsetMs: performance.now() - this.started
|
|
49
|
+
});
|
|
50
|
+
if (event.name === "pnpm:stats" && event.added !== void 0 && Number.isSafeInteger(event.added))
|
|
51
|
+
this.added = event.added;
|
|
52
|
+
if (event.level === "error")
|
|
53
|
+
this.errors = (this.errors + "\n" + line).slice(-16384);
|
|
54
|
+
}
|
|
55
|
+
failure(exitCode, signal = null) {
|
|
56
|
+
return new Error(
|
|
57
|
+
`Dependency installation failed (exit=${exitCode}, signal=${signal}): ${JSON.stringify(this.finish())}${this.errors}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
finish() {
|
|
61
|
+
const count = (status) => [...this.packages.values()].filter((states) => states.has(status)).length;
|
|
62
|
+
return dependencyInstallObservationSchema.parse({
|
|
63
|
+
durationMs: performance.now() - this.started,
|
|
64
|
+
packageCount: this.packages.size,
|
|
65
|
+
reused: count("found_in_store"),
|
|
66
|
+
downloaded: count("fetched"),
|
|
67
|
+
added: this.added,
|
|
68
|
+
stages: this.stages,
|
|
69
|
+
importMethods: [...this.importMethods].sort()
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
assertIndependentImports() {
|
|
73
|
+
if (this.added > 0 && this.importMethods.size === 0)
|
|
74
|
+
throw new Error(
|
|
75
|
+
"Dependency installation did not report its import method."
|
|
76
|
+
);
|
|
77
|
+
if ([...this.importMethods].some(
|
|
78
|
+
(method) => method !== "copy" && method !== "clone"
|
|
79
|
+
))
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Dependency installation requires independent copies; pnpm reported ${[...this.importMethods].join(", ")}.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
async function installDependencies(directory, options = {}) {
|
|
86
|
+
options.signal?.throwIfAborted();
|
|
87
|
+
const observation = new DependencyInstallObservation();
|
|
88
|
+
const child = crossSpawn(
|
|
89
|
+
"pnpm",
|
|
90
|
+
[
|
|
91
|
+
"install",
|
|
92
|
+
options.lockfile === "update" ? "--no-frozen-lockfile" : "--frozen-lockfile",
|
|
93
|
+
"--reporter=ndjson",
|
|
94
|
+
`--package-import-method=${options.packageImportMethod ?? "copy"}`,
|
|
95
|
+
...options.scripts === "ignore" ? ["--ignore-scripts"] : [],
|
|
96
|
+
...options.network && options.network !== "online" ? [`--${options.network}`] : []
|
|
97
|
+
],
|
|
98
|
+
{
|
|
99
|
+
cwd: directory,
|
|
100
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
101
|
+
signal: options.signal,
|
|
102
|
+
killSignal: "SIGKILL"
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
if (!child.stderr || !child.stdout)
|
|
106
|
+
throw new Error("The dependency installer requires piped output.");
|
|
107
|
+
const output = [child.stdout, child.stderr].map(
|
|
108
|
+
(input) => createInterface({ input })
|
|
109
|
+
);
|
|
110
|
+
const reading = Promise.all(
|
|
111
|
+
output.map(async (reader) => {
|
|
112
|
+
for await (const line of reader) observation.accept(line);
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
const finished = new Promise((resolve, reject) => {
|
|
116
|
+
child.once("error", reject);
|
|
117
|
+
child.once("close", (exitCode, signal) => resolve({ exitCode, signal }));
|
|
118
|
+
});
|
|
119
|
+
const closed = new Promise(
|
|
120
|
+
(resolve) => child.once("close", () => resolve())
|
|
121
|
+
);
|
|
122
|
+
try {
|
|
123
|
+
const [{ exitCode, signal }] = await Promise.all([finished, reading]);
|
|
124
|
+
if (exitCode !== 0) throw observation.failure(exitCode, signal);
|
|
125
|
+
observation.assertIndependentImports();
|
|
126
|
+
return observation.finish();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
child.kill("SIGKILL");
|
|
129
|
+
await closed;
|
|
130
|
+
const failure = options.signal?.aborted ? new Error(
|
|
131
|
+
observation.failure(child.exitCode, child.signalCode).message,
|
|
132
|
+
{ cause: error }
|
|
133
|
+
) : error;
|
|
134
|
+
await rm(path.join(directory, "node_modules"), {
|
|
135
|
+
recursive: true,
|
|
136
|
+
force: true
|
|
137
|
+
});
|
|
138
|
+
throw failure;
|
|
139
|
+
} finally {
|
|
140
|
+
for (const reader of output) reader.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
DependencyInstallObservation,
|
|
146
|
+
installDependencies
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=chunk-QAWI64VR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dependencies.ts"],"sourcesContent":["import crossSpawn from \"cross-spawn\";\nimport { rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { z } from \"zod\";\nimport { dependencyInstallObservationSchema } from \"./dependency-install-contract.js\";\n\nconst eventSchema = z.object({\n name: z.string().optional(),\n packageId: z.string().optional(),\n status: z.string().optional(),\n stage: z.string().optional(),\n method: z.string().optional(),\n added: z.number().int().optional(),\n level: z.string().optional(),\n});\n\nexport class DependencyInstallObservation {\n private packages = new Map<string, Set<string>>();\n private started = performance.now();\n private stages: z.infer<typeof dependencyInstallObservationSchema>[\"stages\"] =\n [];\n private added = 0;\n private importMethods = new Set<string>();\n private errors = \"\";\n accept(line: string) {\n let value: unknown;\n try {\n value = JSON.parse(line);\n } catch {\n this.errors = (this.errors + \"\\n\" + line).slice(-16_384);\n return;\n }\n const parsed = eventSchema.safeParse(value);\n if (!parsed.success) return;\n const event = parsed.data;\n if (\n event.method &&\n (event.name === \"pnpm:package-import-method\" ||\n (event.name === \"pnpm:progress\" && event.status === \"imported\"))\n )\n this.importMethods.add(event.method);\n if (event.name === \"pnpm:progress\" && event.packageId && event.status) {\n const states = this.packages.get(event.packageId) ?? new Set<string>();\n states.add(event.status);\n this.packages.set(event.packageId, states);\n }\n if (\n event.name === \"pnpm:stage\" &&\n event.stage &&\n [\"importing_started\", \"importing_done\"].includes(event.stage)\n )\n this.stages.push({\n stage: event.stage,\n offsetMs: performance.now() - this.started,\n });\n if (\n event.name === \"pnpm:stats\" &&\n event.added !== undefined &&\n Number.isSafeInteger(event.added)\n )\n this.added = event.added;\n if (event.level === \"error\")\n this.errors = (this.errors + \"\\n\" + line).slice(-16_384);\n }\n failure(exitCode: number | null, signal: NodeJS.Signals | null = null) {\n return new Error(\n `Dependency installation failed (exit=${exitCode}, signal=${signal}): ${JSON.stringify(this.finish())}${this.errors}`,\n );\n }\n finish() {\n const count = (status: string) =>\n [...this.packages.values()].filter((states) => states.has(status)).length;\n return dependencyInstallObservationSchema.parse({\n durationMs: performance.now() - this.started,\n packageCount: this.packages.size,\n reused: count(\"found_in_store\"),\n downloaded: count(\"fetched\"),\n added: this.added,\n stages: this.stages,\n importMethods: [...this.importMethods].sort(),\n });\n }\n assertIndependentImports() {\n if (this.added > 0 && this.importMethods.size === 0)\n throw new Error(\n \"Dependency installation did not report its import method.\",\n );\n if (\n [...this.importMethods].some(\n (method) => method !== \"copy\" && method !== \"clone\",\n )\n )\n throw new Error(\n `Dependency installation requires independent copies; pnpm reported ${[...this.importMethods].join(\", \")}.`,\n );\n }\n}\n\n/** Workspace preparation, explicit upgrades and pinned tests share one installer. */\nexport async function installDependencies(\n directory: string,\n options: {\n signal?: AbortSignal;\n network?: \"online\" | \"prefer-offline\" | \"offline\";\n lockfile?: \"frozen\" | \"update\";\n scripts?: \"run\" | \"ignore\";\n packageImportMethod?: \"copy\" | \"clone-or-copy\";\n } = {},\n) {\n options.signal?.throwIfAborted();\n const observation = new DependencyInstallObservation();\n const child = crossSpawn(\n \"pnpm\",\n [\n \"install\",\n options.lockfile === \"update\"\n ? \"--no-frozen-lockfile\"\n : \"--frozen-lockfile\",\n \"--reporter=ndjson\",\n `--package-import-method=${options.packageImportMethod ?? \"copy\"}`,\n ...(options.scripts === \"ignore\" ? [\"--ignore-scripts\"] : []),\n ...(options.network && options.network !== \"online\"\n ? [`--${options.network}`]\n : []),\n ],\n {\n cwd: directory,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n signal: options.signal,\n killSignal: \"SIGKILL\",\n },\n );\n if (!child.stderr || !child.stdout)\n throw new Error(\"The dependency installer requires piped output.\");\n const output = [child.stdout, child.stderr].map((input) =>\n createInterface({ input }),\n );\n const reading = Promise.all(\n output.map(async (reader) => {\n for await (const line of reader) observation.accept(line);\n }),\n );\n const finished = new Promise<{\n exitCode: number | null;\n signal: NodeJS.Signals | null;\n }>((resolve, reject) => {\n child.once(\"error\", reject);\n child.once(\"close\", (exitCode, signal) => resolve({ exitCode, signal }));\n });\n const closed = new Promise<void>((resolve) =>\n child.once(\"close\", () => resolve()),\n );\n try {\n const [{ exitCode, signal }] = await Promise.all([finished, reading]);\n if (exitCode !== 0) throw observation.failure(exitCode, signal);\n observation.assertIndependentImports();\n return observation.finish();\n } catch (error) {\n child.kill(\"SIGKILL\");\n await closed;\n const failure = options.signal?.aborted\n ? new Error(\n observation.failure(child.exitCode, child.signalCode).message,\n { cause: error },\n )\n : error;\n await rm(path.join(directory, \"node_modules\"), {\n recursive: true,\n force: true,\n });\n throw failure;\n } finally {\n for (const reader of output) reader.close();\n }\n}\n"],"mappings":";;;;;AAAA,OAAO,gBAAgB;AACvB,SAAS,UAAU;AACnB,OAAO,UAAU;AACjB,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAGlB,IAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACjC,OAAO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