@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5
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 +146 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge.base.d.ts +13 -1
- package/dist/bridge/bridge.service.d.ts +155 -4
- package/dist/bridge/bridge.service.js +1805 -155
- package/dist/bridge/bridge.types.d.ts +68 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -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/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -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 +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +10 -0
- package/dist/cleanup/cleanup.service.js +128 -104
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +22 -4
- package/dist/cli/cli.service.d.ts +30 -6
- package/dist/cli/cli.service.js +216 -31
- package/dist/cli/local-config.d.ts +5 -0
- package/dist/cli/local-config.js +30 -4
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +429 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -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 +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- 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 +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +184 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +149 -0
- package/dist/runtime/host-load-sampler.js +291 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -1
- package/dist/runtime/host-runtime-contract.js +174 -56
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1464 -121
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- 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 +29 -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-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- 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/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -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/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -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 +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +182 -109
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +44 -1
- package/dist/session/managed-attempt-tools.js +816 -46
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +21 -0
- package/dist/session/managed-build-receipt.js +337 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +24 -0
- package/dist/session/phase-completion.artifacts.js +319 -44
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +15 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +18 -3
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -2
- package/dist/session/phase-completion.runtime.js +191 -47
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +87 -0
- package/dist/session/pre-publication-validation.js +668 -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/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +92 -14
- package/dist/session/provider-cli/provider-cli.process.js +583 -210
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
- 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 +14 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
- package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
- package/dist/session/provider-cli/provider-cli.service.js +819 -84
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session-redaction.js +434 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +264 -27
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -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-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +3 -0
- package/dist/shared/process/host-process-supervisor.js +61 -12
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +69 -0
- package/dist/shared/process/process.js +223 -16
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +84 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- 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 +17 -1
- package/dist/worktree/worktree.service.js +293 -21
- package/dist/worktree/worktree.types.d.ts +14 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Linux Pressure Stall Information (PSI) parsing shared by the host load sampler.
|
|
2
|
+
// Format (system-wide /proc/pressure/<resource> and cgroup v2 <resource>.pressure):
|
|
3
|
+
// some avg10=0.12 avg60=0.34 avg300=0.56 total=123456
|
|
4
|
+
// full avg10=0.00 avg60=0.00 avg300=0.00 total=0
|
|
5
|
+
const pressureLinePattern = /^(some|full)\s+(.*)$/u;
|
|
6
|
+
/**
|
|
7
|
+
* Parses one PSI file. Returns null when the content has no well-formed
|
|
8
|
+
* `some`/`full` line, so callers can report PSI as unavailable instead of
|
|
9
|
+
* publishing zeros for a file they could not interpret.
|
|
10
|
+
*/
|
|
11
|
+
export function parsePressureStall(content) {
|
|
12
|
+
let some = null;
|
|
13
|
+
let full = null;
|
|
14
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
15
|
+
const match = pressureLinePattern.exec(rawLine.trim());
|
|
16
|
+
if (!match)
|
|
17
|
+
continue;
|
|
18
|
+
const averages = parseAverages(match[2]);
|
|
19
|
+
if (!averages)
|
|
20
|
+
continue;
|
|
21
|
+
if (match[1] === "some")
|
|
22
|
+
some = averages;
|
|
23
|
+
else
|
|
24
|
+
full = averages;
|
|
25
|
+
}
|
|
26
|
+
return some || full ? { some, full } : null;
|
|
27
|
+
}
|
|
28
|
+
const pressureFieldPattern = /^(avg10|avg60|avg300|total)=(\d+(?:\.\d+)?)$/u;
|
|
29
|
+
/** A PSI line must carry exactly avg10, avg60, avg300 and an integer total; anything else is malformed. */
|
|
30
|
+
function parseAverages(fields) {
|
|
31
|
+
const values = new Map();
|
|
32
|
+
for (const field of fields.trim().split(/\s+/u)) {
|
|
33
|
+
const match = pressureFieldPattern.exec(field);
|
|
34
|
+
if (!match || values.has(match[1]))
|
|
35
|
+
return null;
|
|
36
|
+
values.set(match[1], Number(match[2]));
|
|
37
|
+
}
|
|
38
|
+
const avg10 = values.get("avg10");
|
|
39
|
+
const avg60 = values.get("avg60");
|
|
40
|
+
const avg300 = values.get("avg300");
|
|
41
|
+
const total = values.get("total");
|
|
42
|
+
if (avg10 === undefined || avg60 === undefined || avg300 === undefined
|
|
43
|
+
|| total === undefined || !Number.isSafeInteger(total))
|
|
44
|
+
return null;
|
|
45
|
+
return { avg10: clampPercent(avg10), avg60: clampPercent(avg60), avg300: clampPercent(avg300) };
|
|
46
|
+
}
|
|
47
|
+
function clampPercent(value) {
|
|
48
|
+
return Math.min(100, Math.max(0, value));
|
|
49
|
+
}
|
|
50
|
+
/** Reads `usage_usec` from a cgroup v2 `cpu.stat` file. */
|
|
51
|
+
export function parseCgroupCpuUsageUsec(content) {
|
|
52
|
+
const match = /^usage_usec\s+(\d+)\s*$/mu.exec(content);
|
|
53
|
+
if (!match)
|
|
54
|
+
return null;
|
|
55
|
+
const value = Number(match[1]);
|
|
56
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
57
|
+
}
|
|
58
|
+
/** Reads anonymous (RSS-like, excludes page cache) bytes from cgroup v2 `memory.stat`. */
|
|
59
|
+
export function parseCgroupMemoryAnonBytes(content) {
|
|
60
|
+
const match = /^anon\s+(\d+)\s*$/mu.exec(content);
|
|
61
|
+
if (!match)
|
|
62
|
+
return null;
|
|
63
|
+
const value = Number(match[1]);
|
|
64
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
65
|
+
}
|
|
66
|
+
/** Reads a single non-negative integer file such as cgroup v2 `memory.current`. */
|
|
67
|
+
export function parseNonNegativeInteger(content) {
|
|
68
|
+
const trimmed = content.trim();
|
|
69
|
+
if (!/^\d+$/u.test(trimmed))
|
|
70
|
+
return null;
|
|
71
|
+
const value = Number(trimmed);
|
|
72
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
73
|
+
}
|
|
74
|
+
/** Reads `MemAvailable` (bytes) from /proc/meminfo. */
|
|
75
|
+
export function parseMemAvailableBytes(content) {
|
|
76
|
+
const match = /^MemAvailable:\s+(\d+)\s*kB\s*$/mu.exec(content);
|
|
77
|
+
if (!match)
|
|
78
|
+
return null;
|
|
79
|
+
const value = Number(match[1]) * 1024;
|
|
80
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the unified (cgroup v2) hierarchy path from /proc/self/cgroup.
|
|
84
|
+
* Returns null on pure cgroup v1 hosts (no `0::` entry) and for the root cgroup.
|
|
85
|
+
*/
|
|
86
|
+
export function parseUnifiedCgroupPath(content) {
|
|
87
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
88
|
+
const line = rawLine.trim();
|
|
89
|
+
if (!line.startsWith("0::"))
|
|
90
|
+
continue;
|
|
91
|
+
const cgroupPath = line.slice(3).trim();
|
|
92
|
+
if (!cgroupPath.startsWith("/") || cgroupPath === "/")
|
|
93
|
+
return null;
|
|
94
|
+
if (cgroupPath.split("/").some(segment => segment === ".."))
|
|
95
|
+
return null;
|
|
96
|
+
return cgroupPath;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* This process's cgroup v2 path from `/proc/self/cgroup`, including the root
|
|
102
|
+
* `/` (a container's own cgroup under a cgroup namespace); null for cgroup v1
|
|
103
|
+
* or a malformed entry. `parseUnifiedCgroupPath` excludes the root, because the
|
|
104
|
+
* root is never the bridge's own unit; memory limits apply there all the same.
|
|
105
|
+
*/
|
|
106
|
+
export function parseUnifiedCgroupMembership(content) {
|
|
107
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
108
|
+
const line = rawLine.trim();
|
|
109
|
+
if (!line.startsWith("0::"))
|
|
110
|
+
continue;
|
|
111
|
+
const cgroupPath = line.slice(3).trim();
|
|
112
|
+
if (!cgroupPath.startsWith("/"))
|
|
113
|
+
return null;
|
|
114
|
+
if (cgroupPath.split("/").some(segment => segment === ".."))
|
|
115
|
+
return null;
|
|
116
|
+
return cgroupPath;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/** The leaf cgroup name, e.g. `forge-bridge.service`. */
|
|
121
|
+
export function cgroupLeafName(cgroupPath) {
|
|
122
|
+
return cgroupPath.split("/").filter(Boolean).at(-1) ?? null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Whether the bridge's cgroup is dedicated to it, so its usage can later be
|
|
126
|
+
* subtracted from system pressure as "Forge's own load". Only a systemd
|
|
127
|
+
* `.service` qualifies by default, or exactly the unit an operator names via
|
|
128
|
+
* FORGE_BRIDGE_CGROUP_UNIT. A `.scope` is rejected: a bridge started from a
|
|
129
|
+
* terminal, SSH session or desktop app shares `session-N.scope` /
|
|
130
|
+
* `app-*.scope` with unrelated work (possibly the owner's game).
|
|
131
|
+
* Container cgroups (e.g. `docker-<id>.scope`) are not treated as dedicated yet.
|
|
132
|
+
*/
|
|
133
|
+
export function isDedicatedBridgeUnit(unit, configuredUnit) {
|
|
134
|
+
const configured = configuredUnit?.trim();
|
|
135
|
+
if (configured)
|
|
136
|
+
return unit === configured;
|
|
137
|
+
// `app-*` services are desktop-launched apps (XDG naming); `user@N` is the whole user manager.
|
|
138
|
+
return /^[^@\s]+(@[^\s]+)?\.service$/u.test(unit)
|
|
139
|
+
&& !/^app-/u.test(unit)
|
|
140
|
+
&& !/^user@\d+\.service$/u.test(unit);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Reads the aggregate `cpu` line of /proc/stat. Busy time is user + nice +
|
|
144
|
+
* system + irq + softirq + steal (guest time is already inside user/nice);
|
|
145
|
+
* idle and iowait are not busy. Both counters are additive CPU time, so a
|
|
146
|
+
* cgroup's `cpu.stat` usage over the same window can be subtracted from them.
|
|
147
|
+
*/
|
|
148
|
+
export function parseProcStatCpuTotals(content) {
|
|
149
|
+
let aggregate = null;
|
|
150
|
+
let cpuCount = 0;
|
|
151
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
152
|
+
const fields = rawLine.trim().split(/\s+/u);
|
|
153
|
+
if (fields[0] === "cpu") {
|
|
154
|
+
const values = fields.slice(1, 9).map(Number);
|
|
155
|
+
if (values.length < 8 || values.some(value => !Number.isSafeInteger(value) || value < 0))
|
|
156
|
+
return null;
|
|
157
|
+
aggregate = values;
|
|
158
|
+
}
|
|
159
|
+
else if (/^cpu\d+$/u.test(fields[0] ?? "")) {
|
|
160
|
+
cpuCount += 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!aggregate || cpuCount === 0)
|
|
164
|
+
return null;
|
|
165
|
+
const [user, nice, system, idle, iowait, irq, softirq, steal] = aggregate;
|
|
166
|
+
const busyTicks = user + nice + system + irq + softirq + steal;
|
|
167
|
+
return { busyTicks, totalTicks: busyTicks + idle + iowait, cpuCount };
|
|
168
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { type HostRuntimeRequirements } from "./host-runtime-requirements.js";
|
|
1
2
|
export declare const hostRuntimeContractPath = ".forge/forge.runtime.yml";
|
|
3
|
+
export declare const hostRuntimeTestPostgresAdminEnvironment = "FORGE_TEST_POSTGRES_ADMIN_CONNECTION_STRING";
|
|
4
|
+
export declare const hostRuntimeLegacyTestPostgresEnvironment = "FORGE_TEST_POSTGRES_CONNECTION_STRING";
|
|
5
|
+
export declare const hostRuntimeTestPostgresProvisionerEnvironment = "FORGE_TEST_POSTGRES_PROVISIONER_CONNECTION_STRING";
|
|
2
6
|
export type RequestedHostConcurrency = "serial" | "parallel" | "disabled";
|
|
3
7
|
export type HostRuntimePortAdapter = "node" | "vite" | "next" | "aspnetcore";
|
|
4
8
|
export interface HostRuntimeLaunchConfig {
|
|
@@ -29,6 +33,8 @@ export interface HostRuntimeContract {
|
|
|
29
33
|
readonly browserProfile: "isolated";
|
|
30
34
|
readonly singletonResources: readonly string[];
|
|
31
35
|
};
|
|
36
|
+
/** Decision 0013 placement requirements; absent or null when the contract declares none. */
|
|
37
|
+
readonly requires?: HostRuntimeRequirements | null;
|
|
32
38
|
}
|
|
33
39
|
export interface LoadedHostRuntimeContract {
|
|
34
40
|
readonly contract: HostRuntimeContract;
|
|
@@ -41,7 +47,16 @@ export interface HostRuntimeDiscovery {
|
|
|
41
47
|
readonly summary: string;
|
|
42
48
|
readonly candidateFingerprint?: string | null;
|
|
43
49
|
}
|
|
44
|
-
|
|
50
|
+
/** Returns retained bytes (or retained absence) for one canonical discovery input. */
|
|
51
|
+
export type HostRuntimeSourceSnapshot = (target: string) => Promise<Buffer | null>;
|
|
52
|
+
export interface HostRuntimeDirectoryEntry {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly isDirectory: boolean;
|
|
55
|
+
readonly isFile: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Returns one identity-bound directory inventory for runtime discovery. */
|
|
58
|
+
export type HostRuntimeDirectorySnapshot = (target: string) => Promise<readonly HostRuntimeDirectoryEntry[]>;
|
|
59
|
+
export declare function loadHostRuntimeContract(worktreePath: string, snapshot?: HostRuntimeSourceSnapshot, directorySnapshot?: HostRuntimeDirectorySnapshot): Promise<LoadedHostRuntimeContract>;
|
|
45
60
|
export declare function defaultHostRuntimeContract(): HostRuntimeContract;
|
|
46
61
|
export declare function validateHostRuntimeContract(source: string): HostRuntimeContract;
|
|
47
62
|
export declare function hostPortEnvironment(config: HostRuntimePortConfig, hostIp: "127.0.0.1", hostPort: number): Readonly<Record<string, string>>;
|
|
@@ -2,55 +2,92 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isAlias, parseDocument, visit } from "yaml";
|
|
5
|
+
import { readCanonicalSourceFile } from "./canonical-source-file.js";
|
|
6
|
+
import { isGeneratedOutputDirectoryName } from "./generated-output-reset.js";
|
|
7
|
+
import { parseHostRuntimeRequirements } from "./host-runtime-requirements.js";
|
|
5
8
|
export const hostRuntimeContractPath = ".forge/forge.runtime.yml";
|
|
9
|
+
export const hostRuntimeTestPostgresAdminEnvironment = "FORGE_TEST_POSTGRES_ADMIN_CONNECTION_STRING";
|
|
10
|
+
export const hostRuntimeLegacyTestPostgresEnvironment = "FORGE_TEST_POSTGRES_CONNECTION_STRING";
|
|
11
|
+
// Optional superuser login for operator-run .NET fixtures. Never reaches attempt, validation or provider processes.
|
|
12
|
+
export const hostRuntimeTestPostgresProvisionerEnvironment = "FORGE_TEST_POSTGRES_PROVISIONER_CONNECTION_STRING";
|
|
6
13
|
const maximumContractBytes = 64 * 1024;
|
|
7
14
|
const maximumDepth = 12;
|
|
15
|
+
// Every discovery scan stops after this many directory entries. A monorepo needs a few
|
|
16
|
+
// thousand; the bound only keeps a pathological tree from stalling attempt preparation.
|
|
17
|
+
const maximumDiscoveryEntries = 20_000;
|
|
18
|
+
/**
|
|
19
|
+
* A discovery scan reached its entry budget before seeing the whole tree, so what it did not
|
|
20
|
+
* find may still exist. Discovery must not treat that as absence: a partial runtime (for
|
|
21
|
+
* example a web app without its API) would send the attempt's traffic to the wrong server.
|
|
22
|
+
*/
|
|
23
|
+
class IncompleteRuntimeDiscoveryError extends Error {
|
|
24
|
+
}
|
|
25
|
+
// Dependency, build and editor folders never hold an application entrypoint, and counting
|
|
26
|
+
// them would exhaust the budget and serialize a repository for no reason.
|
|
8
27
|
const ignoredDiscoveryDirectories = new Set([
|
|
9
28
|
".forge",
|
|
10
29
|
".forge-designer",
|
|
11
30
|
".git",
|
|
31
|
+
".gradle",
|
|
32
|
+
".idea",
|
|
12
33
|
".local",
|
|
34
|
+
".next",
|
|
35
|
+
".pnpm",
|
|
36
|
+
".turbo",
|
|
37
|
+
".venv",
|
|
38
|
+
".vs",
|
|
39
|
+
".vscode",
|
|
40
|
+
".yarn",
|
|
13
41
|
"bin",
|
|
42
|
+
"build",
|
|
14
43
|
"coverage",
|
|
15
44
|
"dist",
|
|
16
45
|
"node_modules",
|
|
17
46
|
"obj",
|
|
47
|
+
"target",
|
|
48
|
+
"vendor",
|
|
49
|
+
"venv",
|
|
18
50
|
]);
|
|
19
|
-
const topLevelKeys = new Set(["schemaVersion", "runtime"]);
|
|
51
|
+
const topLevelKeys = new Set(["schemaVersion", "runtime", "requires", "costHints"]);
|
|
20
52
|
const runtimeKeys = new Set(["hostConcurrency", "ports", "playwright", "browserProfile", "singletonResources"]);
|
|
21
53
|
const portKeys = new Set(["adapter", "launch", "env", "baseUrlEnv", "format"]);
|
|
22
54
|
const launchKeys = new Set(["command", "args", "workingDirectory", "environment"]);
|
|
23
55
|
const playwrightKeys = new Set(["config", "baseUrlPort", "workers"]);
|
|
24
|
-
export async function loadHostRuntimeContract(worktreePath) {
|
|
56
|
+
export async function loadHostRuntimeContract(worktreePath, snapshot, directorySnapshot) {
|
|
57
|
+
worktreePath = await fs.realpath(worktreePath);
|
|
25
58
|
const target = path.join(path.resolve(worktreePath), hostRuntimeContractPath);
|
|
26
|
-
let
|
|
59
|
+
let source;
|
|
27
60
|
try {
|
|
28
|
-
|
|
61
|
+
const captured = snapshot ? await snapshot(target) : await readCanonicalSourceFile(target, maximumContractBytes);
|
|
62
|
+
if (captured === null)
|
|
63
|
+
return await discoverHostRuntimeContract(worktreePath, snapshot, directorySnapshot);
|
|
64
|
+
source = captured;
|
|
29
65
|
}
|
|
30
66
|
catch (error) {
|
|
31
67
|
if (isFileNotFound(error))
|
|
32
|
-
return await discoverHostRuntimeContract(worktreePath);
|
|
68
|
+
return await discoverHostRuntimeContract(worktreePath, snapshot, directorySnapshot);
|
|
33
69
|
throw error;
|
|
34
70
|
}
|
|
35
|
-
if (!targetStat.isFile() || targetStat.size < 1 || targetStat.size > maximumContractBytes) {
|
|
36
|
-
throw new Error(`runtime_contract_invalid: forge.runtime.yml must be a regular 1-${maximumContractBytes} byte file.`);
|
|
37
|
-
}
|
|
38
|
-
const [realWorktree, realTarget] = await Promise.all([fs.realpath(worktreePath), fs.realpath(target)]);
|
|
39
|
-
const relative = path.relative(realWorktree, realTarget);
|
|
40
|
-
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
41
|
-
throw new Error("runtime_contract_invalid: forge.runtime.yml must remain inside the prepared worktree.");
|
|
42
|
-
}
|
|
43
71
|
return {
|
|
44
|
-
contract: validateHostRuntimeContract(
|
|
72
|
+
contract: validateHostRuntimeContract(source.toString("utf8")),
|
|
45
73
|
source: "project",
|
|
46
74
|
};
|
|
47
75
|
}
|
|
48
|
-
async function discoverHostRuntimeContract(worktreePath) {
|
|
76
|
+
async function discoverHostRuntimeContract(worktreePath, snapshot, directorySnapshot) {
|
|
49
77
|
const root = path.resolve(worktreePath);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
78
|
+
let nodeDiscovery;
|
|
79
|
+
let aspNetDiscovery;
|
|
80
|
+
try {
|
|
81
|
+
[nodeDiscovery, aspNetDiscovery] = await Promise.all([
|
|
82
|
+
discoverNodeRuntimes(root, snapshot, directorySnapshot),
|
|
83
|
+
discoverAspNetRuntimes(root, snapshot, directorySnapshot),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof IncompleteRuntimeDiscoveryError)
|
|
88
|
+
return incompleteRuntimeDiscovery();
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
54
91
|
if (nodeDiscovery.ambiguous || aspNetDiscovery.ambiguous) {
|
|
55
92
|
return ambiguousRuntimeDiscovery();
|
|
56
93
|
}
|
|
@@ -99,16 +136,16 @@ async function discoverHostRuntimeContract(worktreePath) {
|
|
|
99
136
|
},
|
|
100
137
|
};
|
|
101
138
|
}
|
|
102
|
-
async function discoverNodeRuntimes(root) {
|
|
139
|
+
async function discoverNodeRuntimes(root, snapshot, directorySnapshot) {
|
|
103
140
|
const manifests = [...new Set([
|
|
104
141
|
path.join(root, "package.json"),
|
|
105
|
-
...await findFiles(root, file => path.basename(file).toLowerCase() === "package.json", 4,
|
|
142
|
+
...await findFiles(root, file => path.basename(file).toLowerCase() === "package.json", 4, maximumDiscoveryEntries, directorySnapshot),
|
|
106
143
|
])];
|
|
107
|
-
const candidates = (await Promise.all(manifests.map(async (manifestPath) => await discoverNodeRuntime(root, manifestPath)))).filter((candidate) => candidate !== null);
|
|
144
|
+
const candidates = (await Promise.all(manifests.map(async (manifestPath) => await discoverNodeRuntime(root, manifestPath, snapshot, directorySnapshot)))).filter((candidate) => candidate !== null);
|
|
108
145
|
return { candidates: candidates.length === 1 ? candidates : [], ambiguous: candidates.length > 1 };
|
|
109
146
|
}
|
|
110
|
-
async function discoverNodeRuntime(root, manifestPath) {
|
|
111
|
-
const source = await readBoundedOptionalFile(manifestPath, 256 * 1024);
|
|
147
|
+
async function discoverNodeRuntime(root, manifestPath, snapshot, directorySnapshot) {
|
|
148
|
+
const source = await readBoundedOptionalFile(manifestPath, 256 * 1024, snapshot);
|
|
112
149
|
if (source === null)
|
|
113
150
|
return null;
|
|
114
151
|
let manifest;
|
|
@@ -130,15 +167,15 @@ async function discoverNodeRuntime(root, manifestPath) {
|
|
|
130
167
|
const next = Object.hasOwn(dependencies, "next") || /(^|\s)next(?:\s|$)/u.test(script);
|
|
131
168
|
if (vite === next)
|
|
132
169
|
return null;
|
|
133
|
-
const packageManager = await nearestPackageManager(root, path.dirname(manifestPath));
|
|
170
|
+
const packageManager = await nearestPackageManager(root, path.dirname(manifestPath), snapshot);
|
|
134
171
|
if (!packageManager)
|
|
135
172
|
return null;
|
|
136
173
|
const adapter = vite ? "vite" : "next";
|
|
137
174
|
const playwrightConfigs = [...new Set((await Promise.all([
|
|
138
175
|
...["playwright.config.ts", "playwright.config.js", "playwright.config.mjs", "playwright.config.cjs"]
|
|
139
176
|
.flatMap(file => [file, `e2e/${file}`, `tests/e2e/${file}`])
|
|
140
|
-
.map(async (candidate) => await optionalFileExists(path.join(root, candidate)) ? path.join(root, candidate) : null),
|
|
141
|
-
findFiles(root, file => /^playwright\.config\.(?:ts|js|mjs|cjs)$/iu.test(path.basename(file)), 4,
|
|
177
|
+
.map(async (candidate) => await optionalFileExists(path.join(root, candidate), snapshot) ? path.join(root, candidate) : null),
|
|
178
|
+
findFiles(root, file => /^playwright\.config\.(?:ts|js|mjs|cjs)$/iu.test(path.basename(file)), 4, maximumDiscoveryEntries, directorySnapshot),
|
|
142
179
|
])).flat().filter((value) => value !== null))]
|
|
143
180
|
.map(config => portableRelativePath(root, config));
|
|
144
181
|
const playwright = playwrightConfigs.length === 1
|
|
@@ -182,11 +219,13 @@ async function discoverNodeRuntime(root, manifestPath) {
|
|
|
182
219
|
}),
|
|
183
220
|
};
|
|
184
221
|
}
|
|
185
|
-
async function discoverAspNetRuntimes(root) {
|
|
186
|
-
|
|
222
|
+
async function discoverAspNetRuntimes(root, snapshot, directorySnapshot) {
|
|
223
|
+
// Deep enough for nested solutions (src/<area>/<Project>/<Project>.csproj); the entry budget,
|
|
224
|
+
// not the depth, bounds the scan, and a scan that exceeds it is reported as incomplete.
|
|
225
|
+
const projects = await findFiles(root, file => file.toLowerCase().endsWith(".csproj"), 6, maximumDiscoveryEntries, directorySnapshot);
|
|
187
226
|
const webProjects = [];
|
|
188
227
|
for (const projectPath of projects) {
|
|
189
|
-
const source = await readBoundedOptionalFile(projectPath, 512 * 1024);
|
|
228
|
+
const source = await readBoundedOptionalFile(projectPath, 512 * 1024, snapshot);
|
|
190
229
|
if (source && /<Project\s+Sdk=["']Microsoft\.NET\.Sdk\.Web["']/iu.test(source)) {
|
|
191
230
|
webProjects.push({ relativePath: path.relative(root, projectPath).replaceAll("\\", "/"), source });
|
|
192
231
|
}
|
|
@@ -194,7 +233,7 @@ async function discoverAspNetRuntimes(root) {
|
|
|
194
233
|
if (webProjects.length !== 1)
|
|
195
234
|
return { candidates: [], ambiguous: webProjects.length > 1 };
|
|
196
235
|
const project = webProjects[0];
|
|
197
|
-
const launchProfile = await discoverAspNetLaunchProfile(root, project.relativePath);
|
|
236
|
+
const launchProfile = await discoverAspNetLaunchProfile(root, project.relativePath, snapshot);
|
|
198
237
|
const contract = {
|
|
199
238
|
schemaVersion: 1,
|
|
200
239
|
runtime: {
|
|
@@ -277,6 +316,17 @@ function combineBrowserAndApiRuntime(browser, api) {
|
|
|
277
316
|
}),
|
|
278
317
|
};
|
|
279
318
|
}
|
|
319
|
+
function incompleteRuntimeDiscovery() {
|
|
320
|
+
return {
|
|
321
|
+
contract: defaultHostRuntimeContract(),
|
|
322
|
+
source: "default",
|
|
323
|
+
discovery: {
|
|
324
|
+
status: "ambiguous",
|
|
325
|
+
reasonCode: "runtime_discovery_incomplete",
|
|
326
|
+
summary: "Forge could not scan the whole repository within its discovery budget, so host application runs remain serialized.",
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
280
330
|
function ambiguousRuntimeDiscovery() {
|
|
281
331
|
return {
|
|
282
332
|
contract: defaultHostRuntimeContract(),
|
|
@@ -288,15 +338,15 @@ function ambiguousRuntimeDiscovery() {
|
|
|
288
338
|
},
|
|
289
339
|
};
|
|
290
340
|
}
|
|
291
|
-
async function nearestPackageManager(root, start) {
|
|
341
|
+
async function nearestPackageManager(root, start, snapshot) {
|
|
292
342
|
let directory = path.resolve(start);
|
|
293
343
|
const resolvedRoot = path.resolve(root);
|
|
294
344
|
while (directory === resolvedRoot || directory.startsWith(`${resolvedRoot}${path.sep}`)) {
|
|
295
345
|
const lockfiles = (await Promise.all([
|
|
296
|
-
optionalFileExists(path.join(directory, "pnpm-lock.yaml")).then(exists => exists ? "pnpm" : null),
|
|
297
|
-
optionalFileExists(path.join(directory, "yarn.lock")).then(exists => exists ? "yarn" : null),
|
|
298
|
-
optionalFileExists(path.join(directory, "package-lock.json")).then(exists => exists ? "npm" : null),
|
|
299
|
-
optionalFileExists(path.join(directory, "npm-shrinkwrap.json")).then(exists => exists ? "npm" : null),
|
|
346
|
+
optionalFileExists(path.join(directory, "pnpm-lock.yaml"), snapshot).then(exists => exists ? "pnpm" : null),
|
|
347
|
+
optionalFileExists(path.join(directory, "yarn.lock"), snapshot).then(exists => exists ? "yarn" : null),
|
|
348
|
+
optionalFileExists(path.join(directory, "package-lock.json"), snapshot).then(exists => exists ? "npm" : null),
|
|
349
|
+
optionalFileExists(path.join(directory, "npm-shrinkwrap.json"), snapshot).then(exists => exists ? "npm" : null),
|
|
300
350
|
])).filter((value) => value !== null);
|
|
301
351
|
const packageManagers = [...new Set(lockfiles)];
|
|
302
352
|
if (packageManagers.length > 1)
|
|
@@ -312,9 +362,9 @@ async function nearestPackageManager(root, start) {
|
|
|
312
362
|
function portableRelativePath(root, target) {
|
|
313
363
|
return path.relative(root, target).replaceAll("\\", "/");
|
|
314
364
|
}
|
|
315
|
-
async function discoverAspNetLaunchProfile(root, projectRelativePath) {
|
|
365
|
+
async function discoverAspNetLaunchProfile(root, projectRelativePath, snapshot) {
|
|
316
366
|
const target = path.join(root, path.dirname(projectRelativePath), "Properties", "launchSettings.json");
|
|
317
|
-
const source = await readBoundedOptionalFile(target, 512 * 1024);
|
|
367
|
+
const source = await readBoundedOptionalFile(target, 512 * 1024, snapshot);
|
|
318
368
|
if (!source)
|
|
319
369
|
return { name: null, source: null, environment: {} };
|
|
320
370
|
try {
|
|
@@ -339,7 +389,13 @@ async function discoverAspNetLaunchProfile(root, projectRelativePath) {
|
|
|
339
389
|
return { name: null, source, environment: {} };
|
|
340
390
|
}
|
|
341
391
|
}
|
|
392
|
+
// A project's "forge-attempt" profile configures its API for managed attempts. The
|
|
393
|
+
// attempt's pre-publication checks then run against the same settings the project's own
|
|
394
|
+
// e2e suite uses, instead of the developer's "http" profile.
|
|
395
|
+
const attemptLaunchProfileName = "forge-attempt";
|
|
342
396
|
function aspNetProfilePriority(name) {
|
|
397
|
+
if (name.toLowerCase() === attemptLaunchProfileName)
|
|
398
|
+
return -1;
|
|
343
399
|
if (name.toLowerCase() === "http")
|
|
344
400
|
return 0;
|
|
345
401
|
if (name.toLowerCase() === "https")
|
|
@@ -354,6 +410,7 @@ function safeAspNetLaunchEnvironment(name, value) {
|
|
|
354
410
|
return false;
|
|
355
411
|
const normalized = name.toUpperCase();
|
|
356
412
|
return !normalized.startsWith("FORGE_")
|
|
413
|
+
&& !isUnsafeDotnetEnvironmentName(name)
|
|
357
414
|
&& !new Set([
|
|
358
415
|
"ASPNETCORE_URLS",
|
|
359
416
|
"ASPNETCORE_HTTP_PORTS",
|
|
@@ -368,34 +425,53 @@ function safeAspNetLaunchEnvironment(name, value) {
|
|
|
368
425
|
"TMPDIR",
|
|
369
426
|
]).has(normalized);
|
|
370
427
|
}
|
|
371
|
-
async function findFiles(root, accepts, maximumDepth, maximumEntries) {
|
|
428
|
+
async function findFiles(root, accepts, maximumDepth, maximumEntries, snapshot) {
|
|
372
429
|
const results = [];
|
|
373
430
|
let examined = 0;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
431
|
+
const directories = [{ directory: root, depth: 0 }];
|
|
432
|
+
while (directories.length > 0) {
|
|
433
|
+
const current = directories.shift();
|
|
434
|
+
if (current.depth > maximumDepth)
|
|
435
|
+
continue;
|
|
436
|
+
const entries = snapshot
|
|
437
|
+
? await snapshot(current.directory)
|
|
438
|
+
: await fs.readdir(current.directory, { withFileTypes: true }).then(found => found.map(entry => ({
|
|
439
|
+
name: entry.name,
|
|
440
|
+
isDirectory: entry.isDirectory(),
|
|
441
|
+
isFile: entry.isFile(),
|
|
442
|
+
}))).catch((error) => {
|
|
443
|
+
// A directory removed since it was listed holds nothing; one that cannot be read
|
|
444
|
+
// (permissions, open-file limits) may hold the entrypoint discovery is looking for.
|
|
445
|
+
if (isFileNotFound(error))
|
|
446
|
+
return [];
|
|
447
|
+
throw new IncompleteRuntimeDiscoveryError();
|
|
448
|
+
});
|
|
449
|
+
const orderedEntries = [...entries].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
450
|
+
for (const entry of orderedEntries) {
|
|
451
|
+
if (entry.isDirectory
|
|
452
|
+
&& (ignoredDiscoveryDirectories.has(entry.name.toLowerCase()) || isGeneratedOutputDirectoryName(entry.name)))
|
|
382
453
|
continue;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
454
|
+
if (examined++ >= maximumEntries)
|
|
455
|
+
throw new IncompleteRuntimeDiscoveryError();
|
|
456
|
+
const target = path.join(current.directory, entry.name);
|
|
457
|
+
if (entry.isDirectory)
|
|
458
|
+
directories.push({ directory: target, depth: current.depth + 1 });
|
|
459
|
+
else if (entry.isFile && accepts(target))
|
|
387
460
|
results.push(target);
|
|
388
461
|
}
|
|
389
|
-
}
|
|
390
|
-
await visitDirectory(root, 0);
|
|
462
|
+
}
|
|
391
463
|
return results.sort((left, right) => left.localeCompare(right));
|
|
392
464
|
}
|
|
393
|
-
async function readBoundedOptionalFile(target, maximumBytes) {
|
|
465
|
+
async function readBoundedOptionalFile(target, maximumBytes, snapshot) {
|
|
466
|
+
if (snapshot) {
|
|
467
|
+
const source = await snapshot(target);
|
|
468
|
+
return source && source.length > 0 && source.length <= maximumBytes ? source.toString("utf8") : null;
|
|
469
|
+
}
|
|
394
470
|
try {
|
|
395
471
|
const stat = await fs.stat(target);
|
|
396
472
|
if (!stat.isFile() || stat.size < 1 || stat.size > maximumBytes)
|
|
397
473
|
return null;
|
|
398
|
-
return await
|
|
474
|
+
return (await readCanonicalSourceFile(target, maximumBytes)).toString("utf8");
|
|
399
475
|
}
|
|
400
476
|
catch (error) {
|
|
401
477
|
if (isFileNotFound(error))
|
|
@@ -403,7 +479,9 @@ async function readBoundedOptionalFile(target, maximumBytes) {
|
|
|
403
479
|
throw error;
|
|
404
480
|
}
|
|
405
481
|
}
|
|
406
|
-
async function optionalFileExists(target) {
|
|
482
|
+
async function optionalFileExists(target, snapshot) {
|
|
483
|
+
if (snapshot)
|
|
484
|
+
return await snapshot(target) !== null;
|
|
407
485
|
try {
|
|
408
486
|
return (await fs.stat(target)).isFile();
|
|
409
487
|
}
|
|
@@ -472,6 +550,7 @@ export function validateHostRuntimeContract(source) {
|
|
|
472
550
|
throw new Error("runtime_contract_invalid: runtime.browserProfile must be isolated.");
|
|
473
551
|
}
|
|
474
552
|
const ports = parsePorts(runtime.ports);
|
|
553
|
+
const requires = parseHostRuntimeRequirements(root.requires, root.costHints);
|
|
475
554
|
return {
|
|
476
555
|
schemaVersion: 1,
|
|
477
556
|
runtime: {
|
|
@@ -481,6 +560,7 @@ export function validateHostRuntimeContract(source) {
|
|
|
481
560
|
browserProfile,
|
|
482
561
|
singletonResources: parseSingletonResources(runtime.singletonResources),
|
|
483
562
|
},
|
|
563
|
+
...(requires ? { requires } : {}),
|
|
484
564
|
};
|
|
485
565
|
}
|
|
486
566
|
function parsePlaywright(value, ports) {
|
|
@@ -574,6 +654,7 @@ function parseLaunch(value, adapter, name) {
|
|
|
574
654
|
throw new Error(`runtime_contract_invalid: runtime.ports.${name}.launch.args must contain at most 128 strings.`);
|
|
575
655
|
}
|
|
576
656
|
const parsedArgs = args.map((argument, index) => boundedString(argument, 4096, `runtime.ports.${name}.launch.args[${index}]`));
|
|
657
|
+
rejectProjectAuthoredForgeArguments(parsedArgs, adapter, name);
|
|
577
658
|
const portableDirectory = launch.workingDirectory === undefined || launch.workingDirectory === null
|
|
578
659
|
? "."
|
|
579
660
|
: containedPortablePath(launch.workingDirectory, `runtime.ports.${name}.launch.workingDirectory`);
|
|
@@ -596,9 +677,46 @@ function parseLaunchEnvironment(value, portName) {
|
|
|
596
677
|
if (!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/u.test(name)) {
|
|
597
678
|
throw new Error(`runtime_contract_invalid: launch environment name '${name}' is invalid.`);
|
|
598
679
|
}
|
|
680
|
+
if (name.toLowerCase().startsWith("forge_") || isUnsafeDotnetEnvironmentName(name)) {
|
|
681
|
+
throw new Error(`runtime_contract_invalid: launch environment name '${name}' is host-owned or enables pre-startup code injection and cannot be project-authored.`);
|
|
682
|
+
}
|
|
599
683
|
return [name, boundedString(raw, 8192, `runtime.ports.${portName}.launch.environment.${name}`)];
|
|
600
684
|
}));
|
|
601
685
|
}
|
|
686
|
+
function isUnsafeDotnetEnvironmentName(name) {
|
|
687
|
+
const normalized = name.toUpperCase();
|
|
688
|
+
return normalized === "DOTNET_STARTUP_HOOKS"
|
|
689
|
+
|| normalized === "DOTNET_ADDITIONAL_DEPS"
|
|
690
|
+
|| normalized === "DOTNET_SHARED_STORE"
|
|
691
|
+
|| normalized === "DOTNET_HOST_PATH"
|
|
692
|
+
|| normalized === "MSBUILD_EXE_PATH"
|
|
693
|
+
|| normalized === "MSBUILDSDKSPATH"
|
|
694
|
+
|| normalized === "NUGET_PLUGIN_PATHS"
|
|
695
|
+
|| normalized === "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"
|
|
696
|
+
|| normalized === "ASPNETCORE_HOSTINGSTARTUPEXCLUDEASSEMBLIES"
|
|
697
|
+
|| normalized.startsWith("CUSTOMBEFOREMICROSOFTCOMMON")
|
|
698
|
+
|| normalized.startsWith("CUSTOMAFTERMICROSOFTCOMMON")
|
|
699
|
+
|| normalized.startsWith("DOTNET_ROOT")
|
|
700
|
+
|| normalized.startsWith("CORECLR_")
|
|
701
|
+
|| normalized.startsWith("COR_")
|
|
702
|
+
|| normalized.startsWith("COMPLUS_")
|
|
703
|
+
|| normalized.startsWith("LD_")
|
|
704
|
+
|| normalized.startsWith("DYLD_");
|
|
705
|
+
}
|
|
706
|
+
function rejectProjectAuthoredForgeArguments(args, adapter, portName) {
|
|
707
|
+
if (adapter !== "aspnetcore")
|
|
708
|
+
return;
|
|
709
|
+
const applicationArgumentIndex = args.indexOf("--");
|
|
710
|
+
if (applicationArgumentIndex < 0)
|
|
711
|
+
return;
|
|
712
|
+
const forbidden = args.slice(applicationArgumentIndex + 1).find(argument => {
|
|
713
|
+
const key = argument.split("=", 1)[0].replace(/^(?:--?|\/)/u, "");
|
|
714
|
+
return /^forge(?:[_:.-]|$)/iu.test(key);
|
|
715
|
+
});
|
|
716
|
+
if (forbidden) {
|
|
717
|
+
throw new Error(`runtime_contract_invalid: runtime.ports.${portName}.launch.args cannot override the host-owned FORGE_* namespace.`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
602
720
|
function containedPortablePath(value, label) {
|
|
603
721
|
const original = boundedString(value, 1024, label);
|
|
604
722
|
const portable = original.replaceAll("\\", "/");
|