@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.bfa11ebe98c6
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 +88 -2
- package/dist/bridge/bridge-chat.types.d.ts +111 -0
- package/dist/bridge/bridge-chat.types.js +401 -0
- package/dist/bridge/bridge.base.d.ts +4 -1
- package/dist/bridge/bridge.service.d.ts +72 -3
- package/dist/bridge/bridge.service.js +1562 -152
- package/dist/bridge/bridge.types.d.ts +46 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +25 -0
- package/dist/bridge/dispatch-result-outbox.js +62 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/readiness-result-outbox.d.ts +21 -0
- package/dist/bridge/readiness-result-outbox.js +54 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +15 -0
- package/dist/bridge/runner-host-capabilities.js +93 -0
- package/dist/cleanup/cleanup.service.d.ts +1 -0
- package/dist/cleanup/cleanup.service.js +70 -9
- package/dist/cli/cli.help.js +2 -2
- package/dist/cli/cli.service.d.ts +14 -6
- package/dist/cli/cli.service.js +75 -16
- package/dist/cli/local-config.d.ts +1 -0
- package/dist/cli/local-config.js +4 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +341 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +11 -0
- package/dist/runtime/attempt-process-supervisor.js +67 -20
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +90 -0
- package/dist/runtime/docker-engine-probe.js +333 -0
- package/dist/runtime/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +62 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +191 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-runtime-contract.d.ts +12 -1
- package/dist/runtime/host-runtime-contract.js +107 -53
- package/dist/runtime/host-runtime-lease.d.ts +90 -8
- package/dist/runtime/host-runtime-lease.js +1097 -108
- package/dist/runtime/host-runtime-promotion.d.ts +12 -3
- package/dist/runtime/host-runtime-promotion.js +59 -12
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
- package/dist/runtime/native-test-postgres-fallback.js +91 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +28 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +1 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +53 -5
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +17 -8
- package/dist/sandbox/runtime.d.ts +6 -1
- package/dist/sandbox/runtime.js +132 -103
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- package/dist/session/managed-attempt-tools.d.ts +17 -1
- package/dist/session/managed-attempt-tools.js +481 -31
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +105 -0
- package/dist/session/managed-build-receipt.d.ts +21 -0
- package/dist/session/managed-build-receipt.js +337 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/phase-completion.artifacts.d.ts +17 -0
- package/dist/session/phase-completion.artifacts.js +224 -22
- package/dist/session/phase-completion.d.ts +11 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +30 -7
- package/dist/session/phase-completion.js +14 -3
- package/dist/session/phase-completion.prompts.js +17 -18
- package/dist/session/phase-completion.runtime.d.ts +3 -1
- package/dist/session/phase-completion.runtime.js +118 -16
- package/dist/session/phase-completion.schemas.js +49 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +111 -21
- package/dist/session/pre-publication-validation.d.ts +75 -0
- package/dist/session/pre-publication-validation.js +657 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +4 -2
- package/dist/session/provider-cli/provider-cli.artifacts.js +47 -13
- package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.process.d.ts +51 -0
- package/dist/session/provider-cli/provider-cli.process.js +422 -22
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +136 -16
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +40 -3
- package/dist/session/provider-cli/provider-cli.service.d.ts +30 -5
- package/dist/session/provider-cli/provider-cli.service.js +771 -68
- package/dist/session/provider-cli/provider-cli.types.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +10 -0
- package/dist/session/provider-cli/provider-output-state.js +361 -17
- package/dist/session/provider-cli/provider-usage.d.ts +7 -0
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/session-redaction.js +434 -9
- package/dist/session/session.service.js +145 -23
- package/dist/session/session.types.d.ts +147 -2
- package/dist/session/session.types.js +587 -7
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-supervisor.d.ts +2 -0
- package/dist/shared/process/host-process-supervisor.js +57 -9
- package/dist/shared/process/process.d.ts +2 -0
- package/dist/shared/process/process.js +12 -7
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +85 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +41 -9
- package/dist/worktree/dependency-warmer.js +497 -22
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/worktree.service.d.ts +7 -0
- package/dist/worktree/worktree.service.js +253 -21
- package/dist/worktree/worktree.types.d.ts +7 -1
- package/package.json +7 -5
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { resetGeneratedOutputs } from "../runtime/generated-output-reset.js";
|
|
5
|
-
import {
|
|
5
|
+
import { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
6
|
+
import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
|
|
7
|
+
import { nativeTestPostgresFallbackConfigEnvironment, nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresFallbackEnvironment, readNativeTestPostgresFallback, } from "../runtime/native-test-postgres-fallback.js";
|
|
8
|
+
import { redactText } from "../shared/redaction/redaction.js";
|
|
9
|
+
import { ManagedBuildCoordinator } from "./managed-build-coordinator.js";
|
|
10
|
+
import { managedBuildConfiguration, publishManagedBuildReceipt, verifyManagedBuildReceipt, } from "./managed-build-receipt.js";
|
|
11
|
+
import { managedLongTierTimeoutMs, managedMaximumCommandTimeoutMs, managedVerificationTierTimeoutMs, } from "./managed-verification-timeouts.js";
|
|
12
|
+
import { resolveWindowsCommandFromPath, StreamingProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
6
13
|
const managedCommandNames = new Set(["forge.run_managed_command", "run_managed_command"]);
|
|
7
14
|
const startManagedCommandNames = new Set(["forge.start_managed_command", "start_managed_command"]);
|
|
8
15
|
const getManagedCommandNames = new Set(["forge.get_managed_command", "get_managed_command"]);
|
|
9
16
|
const waitManagedCommandNames = new Set(["forge.wait_managed_command", "wait_managed_command"]);
|
|
17
|
+
const startManagedVerificationNames = new Set(["forge.start_managed_verification", "start_managed_verification"]);
|
|
10
18
|
const resetGeneratedOutputNames = new Set(["forge.reset_generated_outputs", "reset_generated_outputs"]);
|
|
11
19
|
const maximumCapturedCharacters = 200_000;
|
|
12
|
-
const maximumReturnedOutputCharacters =
|
|
20
|
+
const maximumReturnedOutputCharacters = 4_000;
|
|
13
21
|
const maximumReportedFailedTests = 50;
|
|
14
|
-
|
|
22
|
+
// Keep a wait slice comfortably below the MCP transport deadline. The managed
|
|
23
|
+
// process remains supervised and its durable receipt continues to update after
|
|
24
|
+
// this call returns, so a shorter slice avoids converting healthy long-running
|
|
25
|
+
// commands into ambiguous MCP failures.
|
|
26
|
+
const maximumSynchronousWaitMs = 45_000;
|
|
27
|
+
const managedCommandRetryAfterMs = 60_000;
|
|
15
28
|
const managedCommandLaunchTimeoutMs = 60_000;
|
|
16
29
|
const managedCommandProgressPersistIntervalMs = 5_000;
|
|
17
30
|
const managedCommandReceiptPollIntervalMs = 1_000;
|
|
@@ -24,6 +37,7 @@ const terminalManagedCommandStatuses = new Set([
|
|
|
24
37
|
"timeout_termination_failed",
|
|
25
38
|
"runner_error",
|
|
26
39
|
]);
|
|
40
|
+
const managedVerificationBuildCoverage = "forge_dotnet_test_graph_v1";
|
|
27
41
|
const managedCommandTasks = new Map();
|
|
28
42
|
export const managedAttemptToolNames = [
|
|
29
43
|
"forge.run_managed_command",
|
|
@@ -34,6 +48,8 @@ export const managedAttemptToolNames = [
|
|
|
34
48
|
"get_managed_command",
|
|
35
49
|
"forge.wait_managed_command",
|
|
36
50
|
"wait_managed_command",
|
|
51
|
+
"forge.start_managed_verification",
|
|
52
|
+
"start_managed_verification",
|
|
37
53
|
"forge.reset_generated_outputs",
|
|
38
54
|
"reset_generated_outputs",
|
|
39
55
|
];
|
|
@@ -42,15 +58,39 @@ export function isManagedAttemptTool(name) {
|
|
|
42
58
|
|| startManagedCommandNames.has(name)
|
|
43
59
|
|| getManagedCommandNames.has(name)
|
|
44
60
|
|| waitManagedCommandNames.has(name)
|
|
61
|
+
|| startManagedVerificationNames.has(name)
|
|
45
62
|
|| resetGeneratedOutputNames.has(name);
|
|
46
63
|
}
|
|
47
64
|
export function managedAttemptToolDefinition(name) {
|
|
65
|
+
if (startManagedVerificationNames.has(name)) {
|
|
66
|
+
return {
|
|
67
|
+
name,
|
|
68
|
+
description: "Start a canonical Forge verification profile with runner-owned cwd, arguments, attempt output, timeout, and process supervision. Prefer this over reconstructing broad .NET commands. Continue independent work, then use forge.wait_managed_command for a transport-safe terminal receipt.",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
required: ["profile"],
|
|
73
|
+
properties: {
|
|
74
|
+
profile: {
|
|
75
|
+
type: "string",
|
|
76
|
+
enum: ["dotnet_unit", "dotnet_contract", "dotnet_api_component", "dotnet_orchestration", "dotnet_infrastructure", "dotnet_solution", "dotnet_affected"],
|
|
77
|
+
},
|
|
78
|
+
shard_count: { type: "integer", minimum: 1, maximum: 32, default: 1 },
|
|
79
|
+
shard_index: { type: "integer", minimum: 0, maximum: 31, default: 0 },
|
|
80
|
+
run_all_shards: { type: "boolean", default: false },
|
|
81
|
+
max_parallelism: { type: "integer", minimum: 1, maximum: 4, default: 2 },
|
|
82
|
+
no_build: { type: "boolean", default: false },
|
|
83
|
+
timeout_ms: { type: "integer", minimum: 1000, maximum: 7200000 },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
48
88
|
if (managedCommandNames.has(name) || startManagedCommandNames.has(name)) {
|
|
49
89
|
return {
|
|
50
90
|
name,
|
|
51
91
|
description: startManagedCommandNames.has(name)
|
|
52
|
-
? "Start a long command in an attempt-owned process tree and return a durable command ID immediately. Continue independent work, then
|
|
53
|
-
: "Run a short command in an attempt-owned process tree. Commands with a timeout above four minutes automatically start asynchronously; continue independent work, then
|
|
92
|
+
? "Start a long command in an attempt-owned process tree and return a durable command ID immediately. Continue independent work, then use forge.wait_managed_command for a transport-safe terminal receipt."
|
|
93
|
+
: "Run a short command in an attempt-owned process tree. Commands with a timeout above four minutes automatically start asynchronously; continue independent work, then use forge.wait_managed_command for the durable result.",
|
|
54
94
|
inputSchema: {
|
|
55
95
|
type: "object",
|
|
56
96
|
additionalProperties: false,
|
|
@@ -81,14 +121,14 @@ export function managedAttemptToolDefinition(name) {
|
|
|
81
121
|
if (waitManagedCommandNames.has(name)) {
|
|
82
122
|
return {
|
|
83
123
|
name,
|
|
84
|
-
description: "Wait
|
|
124
|
+
description: "Wait up to 45 seconds for a managed command terminal receipt. If it remains active, the call succeeds with command_continues=true and retry_after_ms; continue independent work or wait again later. Live progress remains in the durable receipt/UI; do not poll get_managed_command.",
|
|
85
125
|
inputSchema: {
|
|
86
126
|
type: "object",
|
|
87
127
|
additionalProperties: false,
|
|
88
128
|
required: ["command_id"],
|
|
89
129
|
properties: {
|
|
90
130
|
command_id: { type: "string", minLength: 1 },
|
|
91
|
-
wait_timeout_ms: { type: "integer", minimum: 1000, maximum:
|
|
131
|
+
wait_timeout_ms: { type: "integer", minimum: 1000, maximum: 45000, default: 45000 },
|
|
92
132
|
},
|
|
93
133
|
},
|
|
94
134
|
};
|
|
@@ -113,6 +153,7 @@ export async function callManagedAttemptTool(name, input, worktreePath) {
|
|
|
113
153
|
structuredContent: {
|
|
114
154
|
status: "pass",
|
|
115
155
|
quarantined_paths: result.quarantinedPaths,
|
|
156
|
+
retained_paths: result.retainedPaths,
|
|
116
157
|
quarantine_directory: result.quarantineDirectory,
|
|
117
158
|
},
|
|
118
159
|
};
|
|
@@ -123,14 +164,20 @@ export async function callManagedAttemptTool(name, input, worktreePath) {
|
|
|
123
164
|
if (waitManagedCommandNames.has(name)) {
|
|
124
165
|
return await waitManagedCommand(input);
|
|
125
166
|
}
|
|
167
|
+
if (startManagedVerificationNames.has(name)) {
|
|
168
|
+
return await startManagedVerification(input, worktreePath);
|
|
169
|
+
}
|
|
126
170
|
if (!managedCommandNames.has(name) && !startManagedCommandNames.has(name)) {
|
|
127
171
|
throw new Error(`Unknown managed attempt tool: ${name}`);
|
|
128
172
|
}
|
|
129
|
-
|
|
173
|
+
return await launchManagedCommand(asRecord(input), worktreePath, startManagedCommandNames.has(name));
|
|
174
|
+
}
|
|
175
|
+
async function launchManagedCommand(record, worktreePath, forceAsync, verificationProfile, buildProducingOverride, buildReceiptReuse) {
|
|
130
176
|
const command = requiredInputString(record, "command");
|
|
131
177
|
const args = requiredStringArray(record, "args");
|
|
132
178
|
const timeoutMs = optionalTimeout(record.timeout_ms);
|
|
133
179
|
const cwd = await containedWorkingDirectory(worktreePath, record.cwd);
|
|
180
|
+
await validatePlaywrightCommandProject(command, args, cwd);
|
|
134
181
|
const logDirectory = requiredAttemptEnvironment("FORGE_LOG_DIR");
|
|
135
182
|
await fs.mkdir(path.join(logDirectory, "managed-commands"), { recursive: true, mode: 0o700 });
|
|
136
183
|
const commandId = randomUUID();
|
|
@@ -146,8 +193,12 @@ export async function callManagedAttemptTool(name, input, worktreePath) {
|
|
|
146
193
|
metadataPath,
|
|
147
194
|
receiptPath,
|
|
148
195
|
startedAt: Date.now(),
|
|
196
|
+
verificationProfile,
|
|
197
|
+
worktreePath,
|
|
198
|
+
buildProducing: buildProducingOverride ?? isBuildProducingManagedCommand(command, args),
|
|
199
|
+
buildReceiptReuse,
|
|
149
200
|
};
|
|
150
|
-
if (
|
|
201
|
+
if (forceAsync || timeoutMs > maximumSynchronousWaitMs) {
|
|
151
202
|
const started = managedCommandResult({
|
|
152
203
|
...invocation,
|
|
153
204
|
timedOut: false,
|
|
@@ -161,16 +212,195 @@ export async function callManagedAttemptTool(name, input, worktreePath) {
|
|
|
161
212
|
managedCommandTasks.set(commandId, task);
|
|
162
213
|
void task.finally(() => managedCommandTasks.delete(commandId)).catch(() => undefined);
|
|
163
214
|
return {
|
|
164
|
-
...started,
|
|
215
|
+
...managedCommandPublicResult(started),
|
|
165
216
|
content: [{
|
|
166
217
|
type: "text",
|
|
167
|
-
text: `Forge managed command ${commandId} started asynchronously. Continue independent work, then
|
|
218
|
+
text: `Forge managed command ${commandId} started asynchronously. Continue independent work, then use forge.wait_managed_command with this command_id for a transport-safe terminal receipt.`,
|
|
168
219
|
}],
|
|
169
220
|
};
|
|
170
221
|
}
|
|
171
222
|
return await executeManagedCommand(invocation);
|
|
172
223
|
}
|
|
224
|
+
async function startManagedVerification(input, worktreePath) {
|
|
225
|
+
const record = asRecord(input);
|
|
226
|
+
const profile = requiredInputString(record, "profile");
|
|
227
|
+
const shardCount = optionalBoundedInteger(record.shard_count, "shard_count", 1, 32, 1);
|
|
228
|
+
const shardIndex = optionalBoundedInteger(record.shard_index, "shard_index", 0, 31, 0);
|
|
229
|
+
if (shardIndex >= shardCount) {
|
|
230
|
+
throw new Error("managed_verification_invalid: shard_index must be less than shard_count.");
|
|
231
|
+
}
|
|
232
|
+
const noBuild = optionalBoolean(record.no_build, "no_build", false);
|
|
233
|
+
const runAllShards = optionalBoolean(record.run_all_shards, "run_all_shards", false);
|
|
234
|
+
const maxParallelism = optionalBoundedInteger(record.max_parallelism, "max_parallelism", 1, 4, 2);
|
|
235
|
+
if (runAllShards && shardCount < 2) {
|
|
236
|
+
throw new Error("managed_verification_invalid: run_all_shards requires shard_count of at least 2.");
|
|
237
|
+
}
|
|
238
|
+
if (runAllShards && shardIndex !== 0) {
|
|
239
|
+
throw new Error("managed_verification_invalid: shard_index must be 0 when run_all_shards is enabled.");
|
|
240
|
+
}
|
|
241
|
+
if (runAllShards && noBuild) {
|
|
242
|
+
throw new Error("managed_verification_invalid: run_all_shards owns the single prerequisite build and cannot be combined with no_build.");
|
|
243
|
+
}
|
|
244
|
+
const outputDirectory = requiredAttemptEnvironment("FORGE_TEST_OUTPUT_DIR");
|
|
245
|
+
const profileCommand = buildManagedVerificationCommand(profile, outputDirectory, shardCount, shardIndex, noBuild, runAllShards, maxParallelism);
|
|
246
|
+
const buildReceiptReuse = noBuild
|
|
247
|
+
? await verifyManagedBuildReceipt({
|
|
248
|
+
worktreePath,
|
|
249
|
+
configuration: managedBuildConfiguration(profileCommand.command, profileCommand.args),
|
|
250
|
+
requiredCoverage: managedVerificationBuildCoverage,
|
|
251
|
+
})
|
|
252
|
+
: undefined;
|
|
253
|
+
return await launchManagedCommand({
|
|
254
|
+
command: profileCommand.command,
|
|
255
|
+
args: profileCommand.args,
|
|
256
|
+
timeout_ms: record.timeout_ms ?? profileCommand.timeoutMs,
|
|
257
|
+
}, worktreePath, true, profile, !noBuild, buildReceiptReuse);
|
|
258
|
+
}
|
|
259
|
+
export function buildManagedVerificationCommand(profile, outputDirectory, shardCount, shardIndex, noBuild, runAllShards = false, maxParallelism = 2) {
|
|
260
|
+
if (profile === "dotnet_affected") {
|
|
261
|
+
// The tests an uncommitted change can affect: one build, Unit and Contract whole, then
|
|
262
|
+
// only the affected heavier-tier classes. The script owns its build and its selection.
|
|
263
|
+
if (runAllShards || shardCount !== 1 || shardIndex !== 0 || noBuild) {
|
|
264
|
+
throw new Error("managed_verification_invalid: dotnet_affected selects its own tests and owns its build; it accepts no sharding or no_build.");
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
command: process.execPath,
|
|
268
|
+
args: ["scripts/run-affected-dotnet-tests.mjs", "--results-directory", outputDirectory],
|
|
269
|
+
// A change that reaches tests without naming a type runs the heavier tiers whole.
|
|
270
|
+
timeoutMs: managedMaximumCommandTimeoutMs,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (profile === "dotnet_solution") {
|
|
274
|
+
if (runAllShards) {
|
|
275
|
+
throw new Error("managed_verification_invalid: dotnet_solution does not support run_all_shards; select a test tier instead.");
|
|
276
|
+
}
|
|
277
|
+
if (shardCount !== 1 || shardIndex !== 0) {
|
|
278
|
+
throw new Error("managed_verification_invalid: dotnet_solution does not accept sharding; select a test tier instead.");
|
|
279
|
+
}
|
|
280
|
+
const command = preferredPowerShellExecutable();
|
|
281
|
+
const args = [
|
|
282
|
+
"-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "scripts/run-dotnet-test-suite.ps1",
|
|
283
|
+
"-ResultsDirectory", outputDirectory,
|
|
284
|
+
"-MaxParallelism", String(maxParallelism),
|
|
285
|
+
];
|
|
286
|
+
if (noBuild)
|
|
287
|
+
args.push("-NoBuild");
|
|
288
|
+
return { command, args, timeoutMs: managedLongTierTimeoutMs };
|
|
289
|
+
}
|
|
290
|
+
const tiers = {
|
|
291
|
+
dotnet_unit: "Unit",
|
|
292
|
+
dotnet_contract: "Contract",
|
|
293
|
+
dotnet_api_component: "ApiComponent",
|
|
294
|
+
dotnet_orchestration: "Orchestration",
|
|
295
|
+
dotnet_infrastructure: "Infrastructure",
|
|
296
|
+
};
|
|
297
|
+
const tier = tiers[profile];
|
|
298
|
+
if (!tier)
|
|
299
|
+
throw new Error(`managed_verification_invalid: unsupported profile ${profile}.`);
|
|
300
|
+
const command = preferredPowerShellExecutable();
|
|
301
|
+
if (runAllShards) {
|
|
302
|
+
return {
|
|
303
|
+
command,
|
|
304
|
+
args: [
|
|
305
|
+
"-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "scripts/run-dotnet-test-tier-set.ps1",
|
|
306
|
+
"-Tier", tier,
|
|
307
|
+
"-ResultsDirectory", outputDirectory,
|
|
308
|
+
"-ShardCount", String(shardCount),
|
|
309
|
+
"-MaxParallelism", String(maxParallelism),
|
|
310
|
+
],
|
|
311
|
+
timeoutMs: managedVerificationTierTimeoutMs(tier, { shardCount, maxParallelism }),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const args = [
|
|
315
|
+
"-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "scripts/run-dotnet-test-tier.ps1",
|
|
316
|
+
"-Tier", tier,
|
|
317
|
+
"-ResultsDirectory", outputDirectory,
|
|
318
|
+
"-ShardCount", String(shardCount),
|
|
319
|
+
"-ShardIndex", String(shardIndex),
|
|
320
|
+
];
|
|
321
|
+
if (noBuild)
|
|
322
|
+
args.push("-NoBuild");
|
|
323
|
+
return { command, args, timeoutMs: managedVerificationTierTimeoutMs(tier) };
|
|
324
|
+
}
|
|
325
|
+
export function preferredPowerShellExecutable(platform = process.platform, pathValue = process.env.PATH ?? "") {
|
|
326
|
+
if (platform !== "win32")
|
|
327
|
+
return "pwsh";
|
|
328
|
+
return resolveWindowsCommandFromPath("pwsh.exe", pathValue) ?? "powershell.exe";
|
|
329
|
+
}
|
|
330
|
+
export function validatePlaywrightProjectName(project, availableProjects) {
|
|
331
|
+
if (!availableProjects.includes(project)) {
|
|
332
|
+
throw new Error(`managed_command_capability_unavailable: Playwright project '${project}' is not advertised by the selected config. Available projects: ${availableProjects.join(", ") || "none"}.`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async function validatePlaywrightCommandProject(command, args, cwd) {
|
|
336
|
+
const invocation = [path.basename(command).toLowerCase(), ...args.map(argument => argument.toLowerCase())];
|
|
337
|
+
if (!invocation.some(argument => argument.includes("playwright")))
|
|
338
|
+
return;
|
|
339
|
+
const project = optionValue(args, "--project");
|
|
340
|
+
if (!project)
|
|
341
|
+
return;
|
|
342
|
+
const configuredPath = optionValue(args, "--config") ?? process.env.FORGE_PLAYWRIGHT_CONFIG;
|
|
343
|
+
const candidates = configuredPath
|
|
344
|
+
? [path.resolve(cwd, configuredPath)]
|
|
345
|
+
: ["playwright.config.ts", "playwright.config.js", "playwright.config.mjs"].map(file => path.join(cwd, file));
|
|
346
|
+
for (const candidate of candidates) {
|
|
347
|
+
try {
|
|
348
|
+
const source = await fs.readFile(candidate, "utf8");
|
|
349
|
+
const projects = playwrightProjectNamesFromConfigSource(source);
|
|
350
|
+
validatePlaywrightProjectName(project, projects);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
if (error.code !== "ENOENT")
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
throw new Error("managed_command_capability_unavailable: Playwright config was not found; project selection cannot be validated.");
|
|
359
|
+
}
|
|
360
|
+
export function playwrightProjectNamesFromConfigSource(source) {
|
|
361
|
+
const marker = source.match(/^\/\/ forge-playwright-projects: (\[[^\r\n]*\])$/mu)?.[1];
|
|
362
|
+
if (!marker) {
|
|
363
|
+
return [...source.matchAll(/\bname\s*:\s*["']([^"']+)["']/gu)].map(match => match[1]);
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
const parsed = JSON.parse(marker);
|
|
367
|
+
return Array.isArray(parsed)
|
|
368
|
+
? parsed.filter((value) => typeof value === "string" && value.trim().length > 0)
|
|
369
|
+
: [];
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function optionValue(args, name) {
|
|
376
|
+
const direct = args.find(argument => argument.startsWith(`${name}=`));
|
|
377
|
+
if (direct)
|
|
378
|
+
return direct.slice(name.length + 1).trim() || null;
|
|
379
|
+
const index = args.indexOf(name);
|
|
380
|
+
return index >= 0 ? args[index + 1]?.trim() || null : null;
|
|
381
|
+
}
|
|
173
382
|
async function executeManagedCommand(invocation) {
|
|
383
|
+
if (!invocation.buildProducing)
|
|
384
|
+
return await executeManagedCommandProcess(invocation);
|
|
385
|
+
return await new ManagedBuildCoordinator().withBuildSlot(invocation.worktreePath, async (buildQueueWaitMs) => await executeManagedCommandProcess({ ...invocation, buildQueueWaitMs }), async () => {
|
|
386
|
+
const waiting = managedCommandResult({
|
|
387
|
+
...invocation,
|
|
388
|
+
timedOut: false,
|
|
389
|
+
status: "waiting_for_build_slot",
|
|
390
|
+
exitCode: null,
|
|
391
|
+
stdout: "",
|
|
392
|
+
stderr: "",
|
|
393
|
+
});
|
|
394
|
+
await persistManagedCommandReceipt(invocation.receiptPath, waiting.structuredContent);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
async function executeManagedCommandProcess(invocation) {
|
|
398
|
+
assertHostDatabaseCapabilityBoundary();
|
|
399
|
+
const databaseEnvironment = invocation.verificationProfile
|
|
400
|
+
? await managedVerificationDatabaseEnvironment()
|
|
401
|
+
: {};
|
|
402
|
+
const exactSecrets = Object.values(databaseEnvironment)
|
|
403
|
+
.filter(value => value !== nativeTestPostgresFallbackDatabaseMode);
|
|
174
404
|
const environment = inheritedEnvironment({
|
|
175
405
|
FORGE_RUNTIME_MODE: "host",
|
|
176
406
|
FORGE_RESOURCE_LEASE_ID: requiredAttemptEnvironment("FORGE_RESOURCE_LEASE_ID"),
|
|
@@ -183,6 +413,17 @@ async function executeManagedCommand(invocation) {
|
|
|
183
413
|
FORGE_TEST_OUTPUT_DIR: requiredAttemptEnvironment("FORGE_TEST_OUTPUT_DIR"),
|
|
184
414
|
FORGE_PROCESS_SUPERVISOR_ID: `managed-${invocation.commandId.replaceAll("-", "")}`,
|
|
185
415
|
FORGE_PROCESS_SUPERVISOR_METADATA_PATH: invocation.metadataPath,
|
|
416
|
+
...(invocation.verificationProfile
|
|
417
|
+
? {
|
|
418
|
+
FORGE_MANAGED_VERIFICATION_PROFILE: invocation.verificationProfile,
|
|
419
|
+
// Managed verification executes mutable worktree scripts, SDK targets,
|
|
420
|
+
// and test assemblies. It uses an attempt-owned container, or the
|
|
421
|
+
// dedicated native test cluster while Docker is unavailable; it never
|
|
422
|
+
// receives a capability for a server that holds real data.
|
|
423
|
+
FORGE_MANAGED_VERIFICATION_DATABASE_MODE: "container_only",
|
|
424
|
+
...databaseEnvironment,
|
|
425
|
+
}
|
|
426
|
+
: {}),
|
|
186
427
|
});
|
|
187
428
|
let stdout = "";
|
|
188
429
|
let stderr = "";
|
|
@@ -191,8 +432,29 @@ async function executeManagedCommand(invocation) {
|
|
|
191
432
|
let timer = null;
|
|
192
433
|
let outputRevision = 0;
|
|
193
434
|
let lastOutputAt = null;
|
|
435
|
+
let lastOutputStream = null;
|
|
194
436
|
let lastProgressPersistedAt = 0;
|
|
195
437
|
let progressPersistence = Promise.resolve();
|
|
438
|
+
let progressHeartbeat = null;
|
|
439
|
+
let progressFinished = false;
|
|
440
|
+
const persistProgress = (force = false) => {
|
|
441
|
+
if (progressFinished)
|
|
442
|
+
return progressPersistence;
|
|
443
|
+
const next = persistManagedCommandProgressIfDue(invocation, () => ({ stdout, stderr, outputRevision, lastOutputAt, lastOutputStream }), progressPersistence, () => lastProgressPersistedAt, value => { lastProgressPersistedAt = value; }, force);
|
|
444
|
+
// A heartbeat write is best-effort: one failed write (a locked or full disk) must
|
|
445
|
+
// not poison the chain, freeze later heartbeats, or fail a command that succeeded.
|
|
446
|
+
progressPersistence = force ? next.catch(() => undefined) : next;
|
|
447
|
+
return progressPersistence;
|
|
448
|
+
};
|
|
449
|
+
// Stop progress writes and let any in flight land before a terminal receipt is
|
|
450
|
+
// written, so a late "running" snapshot can never replace it.
|
|
451
|
+
const settleProgress = async () => {
|
|
452
|
+
progressFinished = true;
|
|
453
|
+
if (progressHeartbeat)
|
|
454
|
+
clearInterval(progressHeartbeat);
|
|
455
|
+
progressHeartbeat = null;
|
|
456
|
+
await progressPersistence;
|
|
457
|
+
};
|
|
196
458
|
const launchTimer = setTimeout(() => {
|
|
197
459
|
timedOut = true;
|
|
198
460
|
controller.abort(new Error(`managed_command_launch_timeout: process supervisor was not ready within ${managedCommandLaunchTimeoutMs}ms.`));
|
|
@@ -216,30 +478,51 @@ async function executeManagedCommand(invocation) {
|
|
|
216
478
|
stderr,
|
|
217
479
|
outputRevision,
|
|
218
480
|
lastOutputAt,
|
|
481
|
+
lastOutputStream,
|
|
219
482
|
});
|
|
220
483
|
await persistManagedCommandReceipt(invocation.receiptPath, running.structuredContent);
|
|
221
484
|
timer = setTimeout(() => {
|
|
222
485
|
timedOut = true;
|
|
223
486
|
controller.abort(new Error(`managed_command_timeout: exceeded ${invocation.timeoutMs}ms.`));
|
|
224
487
|
}, invocation.timeoutMs);
|
|
488
|
+
// Output alone does not keep the receipt current: a test tier can print a burst
|
|
489
|
+
// and then run quietly for many minutes. Without this heartbeat the elapsed time
|
|
490
|
+
// and the burst's last lines freeze, and a waiting agent sees a hung command.
|
|
491
|
+
// The run can already have failed while the "running" write above was pending.
|
|
492
|
+
if (progressFinished)
|
|
493
|
+
return;
|
|
494
|
+
progressHeartbeat = setInterval(() => {
|
|
495
|
+
void persistProgress(true);
|
|
496
|
+
}, managedCommandProgressPersistIntervalMs);
|
|
497
|
+
progressHeartbeat.unref();
|
|
225
498
|
},
|
|
226
499
|
onStdoutLine: (line) => {
|
|
227
|
-
stdout = appendBounded(stdout, line);
|
|
500
|
+
stdout = appendBounded(stdout, redactText(line, exactSecrets));
|
|
228
501
|
outputRevision += 1;
|
|
229
502
|
lastOutputAt = Date.now();
|
|
230
|
-
|
|
231
|
-
return
|
|
503
|
+
lastOutputStream = "stdout";
|
|
504
|
+
return persistProgress();
|
|
232
505
|
},
|
|
233
506
|
onStderrLine: (line) => {
|
|
234
|
-
stderr = appendBounded(stderr, line);
|
|
507
|
+
stderr = appendBounded(stderr, redactText(line, exactSecrets));
|
|
235
508
|
outputRevision += 1;
|
|
236
509
|
lastOutputAt = Date.now();
|
|
237
|
-
|
|
238
|
-
return
|
|
510
|
+
lastOutputStream = "stderr";
|
|
511
|
+
return persistProgress();
|
|
239
512
|
},
|
|
240
513
|
}, controller.signal);
|
|
241
|
-
await
|
|
514
|
+
await settleProgress();
|
|
242
515
|
const status = timedOut ? "timed_out" : result.exitCode === 0 ? "pass" : "fail";
|
|
516
|
+
const receiptCoverage = managedBuildReceiptCoverage(invocation);
|
|
517
|
+
const buildReceipt = status === "pass" && receiptCoverage
|
|
518
|
+
? await publishManagedBuildReceipt({
|
|
519
|
+
worktreePath: invocation.worktreePath,
|
|
520
|
+
command: invocation.command,
|
|
521
|
+
args: invocation.args,
|
|
522
|
+
configuration: managedBuildConfiguration(invocation.command, invocation.args),
|
|
523
|
+
coverage: receiptCoverage,
|
|
524
|
+
})
|
|
525
|
+
: invocation.buildReceiptReuse;
|
|
243
526
|
const receipt = managedCommandResult({
|
|
244
527
|
...invocation,
|
|
245
528
|
timedOut,
|
|
@@ -249,13 +532,21 @@ async function executeManagedCommand(invocation) {
|
|
|
249
532
|
stderr,
|
|
250
533
|
outputRevision,
|
|
251
534
|
lastOutputAt,
|
|
535
|
+
lastOutputStream,
|
|
536
|
+
buildReceipt,
|
|
537
|
+
buildReceiptReused: invocation.buildReceiptReuse !== undefined,
|
|
252
538
|
});
|
|
253
539
|
await persistManagedCommandReceipt(invocation.receiptPath, receipt.structuredContent);
|
|
254
|
-
return receipt;
|
|
540
|
+
return managedCommandPublicResult(receipt);
|
|
255
541
|
}
|
|
256
542
|
catch (error) {
|
|
257
|
-
|
|
543
|
+
// The failure may be a progress write itself; it is reported below.
|
|
544
|
+
await settleProgress().catch(() => undefined);
|
|
545
|
+
const message = redactText(error instanceof Error ? error.message : String(error), exactSecrets);
|
|
258
546
|
stderr = appendBounded(stderr, message);
|
|
547
|
+
outputRevision += 1;
|
|
548
|
+
lastOutputAt = Date.now();
|
|
549
|
+
lastOutputStream = "stderr";
|
|
259
550
|
const receipt = managedCommandResult({
|
|
260
551
|
...invocation,
|
|
261
552
|
timedOut,
|
|
@@ -265,14 +556,17 @@ async function executeManagedCommand(invocation) {
|
|
|
265
556
|
stderr,
|
|
266
557
|
outputRevision,
|
|
267
558
|
lastOutputAt,
|
|
559
|
+
lastOutputStream,
|
|
268
560
|
});
|
|
269
561
|
await persistManagedCommandReceipt(invocation.receiptPath, receipt.structuredContent);
|
|
270
|
-
return receipt;
|
|
562
|
+
return managedCommandPublicResult(receipt);
|
|
271
563
|
}
|
|
272
564
|
finally {
|
|
273
565
|
clearTimeout(launchTimer);
|
|
274
566
|
if (timer)
|
|
275
567
|
clearTimeout(timer);
|
|
568
|
+
if (progressHeartbeat)
|
|
569
|
+
clearInterval(progressHeartbeat);
|
|
276
570
|
}
|
|
277
571
|
}
|
|
278
572
|
async function readManagedCommand(input) {
|
|
@@ -291,7 +585,7 @@ async function readManagedCommand(input) {
|
|
|
291
585
|
const status = typeof receipt.status === "string" ? receipt.status : "unknown";
|
|
292
586
|
const stdout = typeof receipt.stdout === "string" ? receipt.stdout : "";
|
|
293
587
|
const stderr = typeof receipt.stderr === "string" ? receipt.stderr : "";
|
|
294
|
-
return {
|
|
588
|
+
return managedCommandPublicResult({
|
|
295
589
|
content: [{
|
|
296
590
|
type: "text",
|
|
297
591
|
text: terminalManagedCommandStatuses.has(status)
|
|
@@ -307,12 +601,13 @@ async function readManagedCommand(input) {
|
|
|
307
601
|
}],
|
|
308
602
|
structuredContent: receipt,
|
|
309
603
|
isError: terminalManagedCommandStatuses.has(status) && status !== "pass",
|
|
310
|
-
};
|
|
604
|
+
});
|
|
311
605
|
}
|
|
312
606
|
async function waitManagedCommand(input) {
|
|
313
607
|
const record = asRecord(input);
|
|
314
608
|
const commandId = validatedCommandId(record);
|
|
315
|
-
const
|
|
609
|
+
const requestedWaitTimeoutMs = optionalWaitTimeout(record.wait_timeout_ms);
|
|
610
|
+
const waitTimeoutMs = Math.min(requestedWaitTimeoutMs, maximumSynchronousWaitMs);
|
|
316
611
|
const deadline = Date.now() + waitTimeoutMs;
|
|
317
612
|
const receiptPath = managedCommandReceiptPath(requiredAttemptEnvironment("FORGE_LOG_DIR"), commandId);
|
|
318
613
|
const task = managedCommandTasks.get(commandId);
|
|
@@ -332,12 +627,35 @@ async function waitManagedCommand(input) {
|
|
|
332
627
|
await delay(Math.min(managedCommandReceiptPollIntervalMs, Math.max(1, deadline - Date.now())));
|
|
333
628
|
}
|
|
334
629
|
const receipt = await readManagedCommand({ command_id: commandId });
|
|
630
|
+
// Only a running receipt is refreshed on a heartbeat; queued or starting receipts are
|
|
631
|
+
// written once, so their elapsed time says nothing about progress.
|
|
632
|
+
const elapsedMs = receipt.structuredContent.elapsed_ms;
|
|
633
|
+
const timeoutMs = receipt.structuredContent.timeout_ms;
|
|
634
|
+
const lastOutputAt = Date.parse(String(receipt.structuredContent.last_output_at));
|
|
635
|
+
const progress = receipt.structuredContent.status === "running" && typeof elapsedMs === "number"
|
|
636
|
+
? ` It has run for ${Math.round(elapsedMs / 1000)}s`
|
|
637
|
+
+ (Number.isFinite(lastOutputAt) ? `, last output ${Math.max(0, Math.round((Date.now() - lastOutputAt) / 1000))}s ago` : ", with no output yet")
|
|
638
|
+
+ `. Forge refreshes this receipt every ${managedCommandProgressPersistIntervalMs / 1000}s, so a rising elapsed time means the command is still alive even when it is quiet.`
|
|
639
|
+
// Agents otherwise abandon long verification tiers and record a blocker that is not one.
|
|
640
|
+
+ (typeof timeoutMs === "number"
|
|
641
|
+
? ` Forge itself ends it at its ${Math.round(timeoutMs / 60_000)}-minute limit if it hangs, so keep waiting; a running command is not a blocker.`
|
|
642
|
+
: "")
|
|
643
|
+
: "";
|
|
335
644
|
return {
|
|
336
645
|
...receipt,
|
|
337
646
|
content: [{
|
|
338
647
|
type: "text",
|
|
339
|
-
text: `Forge is still supervising managed command ${commandId} after
|
|
648
|
+
text: `Forge is still supervising managed command ${commandId} after this ${waitTimeoutMs}ms transport-safe wait.${progress} Continue independent work or call forge.wait_managed_command again after ${managedCommandRetryAfterMs}ms. Its durable receipt remains at ${receiptPath}.`,
|
|
340
649
|
}],
|
|
650
|
+
structuredContent: {
|
|
651
|
+
...receipt.structuredContent,
|
|
652
|
+
command_continues: true,
|
|
653
|
+
terminal: false,
|
|
654
|
+
wait_timeout_ms: waitTimeoutMs,
|
|
655
|
+
requested_wait_timeout_ms: requestedWaitTimeoutMs,
|
|
656
|
+
retry_after_ms: managedCommandRetryAfterMs,
|
|
657
|
+
},
|
|
658
|
+
isError: false,
|
|
341
659
|
};
|
|
342
660
|
}
|
|
343
661
|
function managedCommandReceiptPath(logDirectory, commandId) {
|
|
@@ -403,16 +721,70 @@ function managedCommandResult(values) {
|
|
|
403
721
|
|| values.stderr.length >= maximumCapturedCharacters,
|
|
404
722
|
output_revision: values.outputRevision ?? 0,
|
|
405
723
|
last_output_at: values.lastOutputAt ? new Date(values.lastOutputAt).toISOString() : null,
|
|
724
|
+
last_output_stream: values.lastOutputStream ?? null,
|
|
406
725
|
supervisor_metadata_path: values.metadataPath,
|
|
407
726
|
receipt_path: values.receiptPath,
|
|
727
|
+
verification_profile: values.verificationProfile ?? null,
|
|
728
|
+
verification_profile_runner_authored: values.verificationProfile !== undefined,
|
|
729
|
+
build_producing: values.buildProducing,
|
|
730
|
+
build_coordination: values.buildProducing ? "per_worktree_exclusive" : null,
|
|
731
|
+
build_queue_wait_ms: values.buildQueueWaitMs ?? 0,
|
|
732
|
+
build_receipt_reused: values.buildReceiptReused ?? false,
|
|
733
|
+
build_receipt: values.buildReceipt ? {
|
|
734
|
+
fingerprint: values.buildReceipt.fingerprint,
|
|
735
|
+
receipt_path: values.buildReceipt.receiptPath,
|
|
736
|
+
producer_command: values.buildReceipt.producerCommand,
|
|
737
|
+
configuration: values.buildReceipt.configuration,
|
|
738
|
+
coverage: values.buildReceipt.coverage,
|
|
739
|
+
output_count: values.buildReceipt.outputCount,
|
|
740
|
+
} : null,
|
|
741
|
+
runtime_configuration: managedRuntimeConfiguration(),
|
|
408
742
|
process_tree_terminated: values.status === "timed_out" ? true : values.timedOut ? false : undefined,
|
|
409
743
|
},
|
|
410
744
|
isError: isTerminal && values.status !== "pass",
|
|
411
745
|
};
|
|
412
746
|
}
|
|
413
|
-
function
|
|
747
|
+
function managedRuntimeConfiguration() {
|
|
748
|
+
const providerOnlySpecs = process.env.FORGE_CI_REPAIR_PROVIDER_ONLY_SPECS?.trim();
|
|
749
|
+
let providerOnlySpecCount = 0;
|
|
750
|
+
if (providerOnlySpecs) {
|
|
751
|
+
try {
|
|
752
|
+
const parsed = JSON.parse(providerOnlySpecs);
|
|
753
|
+
providerOnlySpecCount = Array.isArray(parsed)
|
|
754
|
+
? parsed.filter(value => typeof value === "string" && value.length > 0).length
|
|
755
|
+
: 0;
|
|
756
|
+
}
|
|
757
|
+
catch {
|
|
758
|
+
providerOnlySpecCount = 0;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
attempt_database_schema: process.env.FORGE_ATTEMPT_DATABASE_SCHEMA ?? null,
|
|
763
|
+
attempt_database_readiness_path: process.env.FORGE_ATTEMPT_DATABASE_READINESS_PATH ?? null,
|
|
764
|
+
playwright_config: process.env.FORGE_PLAYWRIGHT_CONFIG ?? null,
|
|
765
|
+
provider_only_spec_count: providerOnlySpecCount,
|
|
766
|
+
provider_only_spec_fingerprint: providerOnlySpecs
|
|
767
|
+
? `sha256:${createHash("sha256").update(providerOnlySpecs).digest("hex")}`
|
|
768
|
+
: null,
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function managedCommandPublicResult(result) {
|
|
772
|
+
const stdout = typeof result.structuredContent.stdout === "string" ? result.structuredContent.stdout : "";
|
|
773
|
+
const stderr = typeof result.structuredContent.stderr === "string" ? result.structuredContent.stderr : "";
|
|
774
|
+
const { stdout: _stdout, stderr: _stderr, ...receipt } = result.structuredContent;
|
|
775
|
+
return {
|
|
776
|
+
...result,
|
|
777
|
+
structuredContent: {
|
|
778
|
+
...receipt,
|
|
779
|
+
stdout_tail: tail(stdout, maximumReturnedOutputCharacters),
|
|
780
|
+
stderr_tail: tail(stderr, maximumReturnedOutputCharacters),
|
|
781
|
+
full_output_in_receipt: true,
|
|
782
|
+
},
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function persistManagedCommandProgressIfDue(invocation, snapshot, previousPersistence, lastPersistedAt, setLastPersistedAt, force = false) {
|
|
414
786
|
const now = Date.now();
|
|
415
|
-
if (now - lastPersistedAt() < managedCommandProgressPersistIntervalMs)
|
|
787
|
+
if (!force && now - lastPersistedAt() < managedCommandProgressPersistIntervalMs)
|
|
416
788
|
return previousPersistence;
|
|
417
789
|
setLastPersistedAt(now);
|
|
418
790
|
const current = snapshot();
|
|
@@ -447,12 +819,75 @@ function inheritedEnvironment(overrides) {
|
|
|
447
819
|
}
|
|
448
820
|
return { ...env, ...overrides };
|
|
449
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Runner-authored verification normally uses its attempt-owned Testcontainers
|
|
824
|
+
* database. Only when the Docker engine is unavailable does it switch to the
|
|
825
|
+
* operator-provisioned native test cluster, which holds no real data.
|
|
826
|
+
*/
|
|
827
|
+
export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().refresh(true)).available, readFallback = () => {
|
|
828
|
+
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
829
|
+
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
830
|
+
}) {
|
|
831
|
+
const fallback = readFallback();
|
|
832
|
+
if (!fallback || await dockerAvailable())
|
|
833
|
+
return {};
|
|
834
|
+
return nativeTestPostgresFallbackEnvironment(fallback);
|
|
835
|
+
}
|
|
836
|
+
export function isBuildProducingManagedCommand(command, args) {
|
|
837
|
+
const executable = path.basename(command).toLowerCase();
|
|
838
|
+
if (executable === "dotnet" || executable === "dotnet.exe") {
|
|
839
|
+
const verb = args.find(argument => !argument.startsWith("-"))?.toLowerCase();
|
|
840
|
+
if (!verb || !new Set(["build", "test", "restore", "publish", "pack", "msbuild"]).has(verb))
|
|
841
|
+
return false;
|
|
842
|
+
return verb === "restore" || !args.some(argument => argument.toLowerCase() === "--no-build");
|
|
843
|
+
}
|
|
844
|
+
if (["powershell", "powershell.exe", "pwsh", "pwsh.exe"].includes(executable)) {
|
|
845
|
+
const fileIndex = args.findIndex(argument => argument.toLowerCase() === "-file");
|
|
846
|
+
const script = fileIndex >= 0 ? path.basename(args[fileIndex + 1] ?? "").toLowerCase() : "";
|
|
847
|
+
if (script === "run-dotnet-test-tier-set.ps1" || script === "run-dotnet-test-suite.ps1") {
|
|
848
|
+
return !args.some(argument => argument.toLowerCase() === "-nobuild");
|
|
849
|
+
}
|
|
850
|
+
if (script === "run-dotnet-test-tier.ps1") {
|
|
851
|
+
return !args.some(argument => argument.toLowerCase() === "-nobuild");
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
function managedBuildReceiptCoverage(invocation) {
|
|
857
|
+
if (!invocation.buildProducing)
|
|
858
|
+
return null;
|
|
859
|
+
if (invocation.verificationProfile)
|
|
860
|
+
return managedVerificationBuildCoverage;
|
|
861
|
+
const executable = path.basename(invocation.command).toLowerCase();
|
|
862
|
+
if (executable === "dotnet" || executable === "dotnet.exe") {
|
|
863
|
+
const verb = invocation.args.find(argument => !argument.startsWith("-"))?.toLowerCase();
|
|
864
|
+
if (!verb || !new Set(["build", "test"]).has(verb))
|
|
865
|
+
return null;
|
|
866
|
+
const target = invocation.args.find(argument => /\.(?:sln|slnx|csproj)$/iu.test(argument));
|
|
867
|
+
if (target && (/\.(?:sln|slnx)$/iu.test(target) || /(?:^|[\\/])Forge\.Api\.Tests\.csproj$/iu.test(target))) {
|
|
868
|
+
return managedVerificationBuildCoverage;
|
|
869
|
+
}
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
if (["powershell", "powershell.exe", "pwsh", "pwsh.exe"].includes(executable)) {
|
|
873
|
+
const fileIndex = invocation.args.findIndex(argument => argument.toLowerCase() === "-file");
|
|
874
|
+
const script = fileIndex >= 0 ? path.basename(invocation.args[fileIndex + 1] ?? "").toLowerCase() : "";
|
|
875
|
+
if (["run-dotnet-test-tier.ps1", "run-dotnet-test-tier-set.ps1", "run-dotnet-test-suite.ps1"].includes(script)
|
|
876
|
+
&& !invocation.args.some(argument => argument.toLowerCase() === "-nobuild")) {
|
|
877
|
+
return managedVerificationBuildCoverage;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
450
882
|
function looksSensitiveEnvironmentName(name) {
|
|
451
883
|
const normalized = name.trim().toUpperCase();
|
|
452
884
|
return normalized.includes("SECRET")
|
|
453
885
|
|| normalized.includes("TOKEN")
|
|
454
886
|
|| normalized.includes("PASSWORD")
|
|
455
887
|
|| normalized.includes("CREDENTIAL")
|
|
888
|
+
|| normalized.includes("CONNECTION_STRING")
|
|
889
|
+
|| normalized.startsWith("CONNECTIONSTRINGS__")
|
|
890
|
+
|| normalized.startsWith("CONNECTIONSTRINGS:")
|
|
456
891
|
|| normalized.endsWith("_API_KEY")
|
|
457
892
|
|| normalized === "OPENAI_API_KEY";
|
|
458
893
|
}
|
|
@@ -499,12 +934,27 @@ function optionalTimeout(value) {
|
|
|
499
934
|
}
|
|
500
935
|
function optionalWaitTimeout(value) {
|
|
501
936
|
if (value === undefined)
|
|
502
|
-
return
|
|
503
|
-
if (!Number.isSafeInteger(value) || value < 1_000 || value >
|
|
504
|
-
throw new Error(
|
|
937
|
+
return maximumSynchronousWaitMs;
|
|
938
|
+
if (!Number.isSafeInteger(value) || value < 1_000 || value > maximumSynchronousWaitMs) {
|
|
939
|
+
throw new Error(`managed_command_invalid: wait_timeout_ms must be an integer from 1000 through ${maximumSynchronousWaitMs}.`);
|
|
505
940
|
}
|
|
506
941
|
return value;
|
|
507
942
|
}
|
|
943
|
+
function optionalBoundedInteger(value, name, minimum, maximum, fallback) {
|
|
944
|
+
if (value === undefined)
|
|
945
|
+
return fallback;
|
|
946
|
+
if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
|
|
947
|
+
throw new Error(`managed_verification_invalid: ${name} must be an integer from ${minimum} through ${maximum}.`);
|
|
948
|
+
}
|
|
949
|
+
return value;
|
|
950
|
+
}
|
|
951
|
+
function optionalBoolean(value, name, fallback) {
|
|
952
|
+
if (value === undefined)
|
|
953
|
+
return fallback;
|
|
954
|
+
if (typeof value !== "boolean")
|
|
955
|
+
throw new Error(`managed_verification_invalid: ${name} must be a boolean.`);
|
|
956
|
+
return value;
|
|
957
|
+
}
|
|
508
958
|
async function delay(ms) {
|
|
509
959
|
await new Promise(resolve => setTimeout(resolve, ms));
|
|
510
960
|
}
|