@smoothbricks/nx-plugin 0.4.28 → 0.4.29
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 +203 -83
- package/dist/bounded-test-policy.d.ts +10 -3
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +19 -25
- package/dist/cargo-closure-input.d.ts +12 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +34 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +265 -159
- package/dist/ensure-built-witness.d.ts +27 -2
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2176 -15
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +34 -53
- package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +43 -19
- package/dist/executors/bounded-exec/executor.d.ts +11 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +139 -39
- package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +27 -13
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +98 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +624 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +921 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +58 -0
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +147 -21
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -114
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +11 -6
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +174 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +19 -27
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.test.ts +60 -11
- package/src/cargo-closure-input.ts +28 -6
- package/src/cargo-resolve-cache.test.ts +140 -25
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +251 -149
- package/src/ensure-built-witness.test.ts +197 -13
- package/src/ensure-built-witness.ts +187 -15
- package/src/ensure-built.test.ts +156 -102
- package/src/ensure-built.ts +114 -64
- package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
- package/src/executors/bounded-exec/cpu-pool.ts +55 -17
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/executor-host.test.ts +51 -41
- package/src/executors/bounded-exec/executor.test.ts +155 -35
- package/src/executors/bounded-exec/executor.ts +156 -45
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
- package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
- package/src/executors/bounded-exec/ram-temp.ts +32 -16
- package/src/executors/bounded-exec/verdict.test.ts +17 -12
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +371 -0
- package/src/graph-input-contract.ts +605 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +5 -5
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +56 -0
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +31 -9
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +631 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +59 -0
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +5 -0
package/src/ensure-built.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type * as NxTaskHasher from 'nx/src/hasher/task-hasher';
|
|
|
25
25
|
import type * as NxNative from 'nx/src/native';
|
|
26
26
|
import type * as NxTransformObjects from 'nx/src/native/transform-objects';
|
|
27
27
|
import type * as NxExecutionHooks from 'nx/src/project-graph/plugins/tasks-execution-hooks';
|
|
28
|
+
import type * as NxProjectGraphRuntime from 'nx/src/project-graph/project-graph';
|
|
28
29
|
import type * as NxProjectRootMappings from 'nx/src/project-graph/utils/find-project-for-path';
|
|
29
30
|
import type * as NxCache from 'nx/src/tasks-runner/cache';
|
|
30
31
|
import type * as NxCreateTaskGraph from 'nx/src/tasks-runner/create-task-graph';
|
|
@@ -38,7 +39,7 @@ import type { NxArgs } from 'nx/src/utils/command-line-utils';
|
|
|
38
39
|
import type * as NxPackageJson from 'nx/src/utils/package-json';
|
|
39
40
|
import type * as NxPerfLogging from 'nx/src/utils/perf-logging';
|
|
40
41
|
import type * as NxWorkspaceRoot from 'nx/src/utils/workspace-root';
|
|
41
|
-
import { boundedReceiptRuntimes, type ProviderInputProof
|
|
42
|
+
import { boundedReceiptRuntimes, type ProviderInputProof } from './ensure-built-receipt.js';
|
|
42
43
|
import {
|
|
43
44
|
type ArtifactWitness,
|
|
44
45
|
type GraphWitness,
|
|
@@ -52,7 +53,9 @@ import {
|
|
|
52
53
|
workspaceSnapshot,
|
|
53
54
|
writeWitness,
|
|
54
55
|
} from './ensure-built-witness.js';
|
|
56
|
+
import { graphInputContractIdentity } from './graph-input-contract.js';
|
|
55
57
|
import { managedAssetsRoot } from './managed-assets.js';
|
|
58
|
+
import { readProducerReceipt } from './producer-receipts.js';
|
|
56
59
|
|
|
57
60
|
interface NxRuntimeModules {
|
|
58
61
|
readonly 'nx/src/config/nx-json': typeof NxConfiguration;
|
|
@@ -62,6 +65,7 @@ interface NxRuntimeModules {
|
|
|
62
65
|
readonly 'nx/src/native': typeof NxNative;
|
|
63
66
|
readonly 'nx/src/native/transform-objects': typeof NxTransformObjects;
|
|
64
67
|
readonly 'nx/src/project-graph/utils/find-project-for-path': typeof NxProjectRootMappings;
|
|
68
|
+
readonly 'nx/src/project-graph/project-graph': typeof NxProjectGraphRuntime;
|
|
65
69
|
readonly 'nx/src/utils/package-json': typeof NxPackageJson;
|
|
66
70
|
readonly 'nx/src/project-graph/plugins/tasks-execution-hooks': typeof NxExecutionHooks;
|
|
67
71
|
readonly 'nx/src/tasks-runner/cache': typeof NxCache;
|
|
@@ -79,7 +83,7 @@ type WorkspaceNxRequire = <Specifier extends keyof NxRuntimeModules>(
|
|
|
79
83
|
specifier: Specifier,
|
|
80
84
|
) => NxRuntimeModules[Specifier];
|
|
81
85
|
|
|
82
|
-
function createWorkspaceNxRequire(workspaceRoot: string): WorkspaceNxRequire {
|
|
86
|
+
export function createWorkspaceNxRequire(workspaceRoot: string): WorkspaceNxRequire {
|
|
83
87
|
const requireFromWorkspace = createRequire(join(workspaceRoot, 'package.json'));
|
|
84
88
|
return function requireNx<Specifier extends keyof NxRuntimeModules>(
|
|
85
89
|
specifier: Specifier,
|
|
@@ -186,6 +190,50 @@ export type EnsureBuiltOutputReceipt =
|
|
|
186
190
|
readonly sha256: string;
|
|
187
191
|
};
|
|
188
192
|
|
|
193
|
+
export type EnsureBuiltProducerExpandedInputs = {
|
|
194
|
+
readonly [Key in keyof NxNative.HashInputs]: readonly NxNative.HashInputs[Key][number][];
|
|
195
|
+
};
|
|
196
|
+
export interface EnsureBuiltProducerFileInput {
|
|
197
|
+
readonly path: string;
|
|
198
|
+
readonly mode: number;
|
|
199
|
+
readonly gitBlob: string;
|
|
200
|
+
readonly sha256: string;
|
|
201
|
+
}
|
|
202
|
+
export interface EnsureBuiltProducerTaskInputs {
|
|
203
|
+
readonly taskId: string;
|
|
204
|
+
readonly overrides: Readonly<Task['overrides']>;
|
|
205
|
+
readonly declared: readonly NonNullable<
|
|
206
|
+
NonNullable<ProjectGraphProjectNode['data']['targets']>[string]['inputs']
|
|
207
|
+
>[number][];
|
|
208
|
+
readonly expanded: EnsureBuiltProducerExpandedInputs;
|
|
209
|
+
readonly hashDetails: Readonly<NxNative.TaskHashDetails>;
|
|
210
|
+
readonly files: readonly EnsureBuiltProducerFileInput[];
|
|
211
|
+
}
|
|
212
|
+
export interface EnsureBuiltProducerTool {
|
|
213
|
+
readonly kind: 'module' | 'executable';
|
|
214
|
+
readonly name: string;
|
|
215
|
+
readonly from: string;
|
|
216
|
+
readonly path: string;
|
|
217
|
+
readonly physicalPath: string;
|
|
218
|
+
readonly missing: readonly string[];
|
|
219
|
+
readonly resolutions: readonly { readonly name: string; readonly from: string; readonly target: string | null }[];
|
|
220
|
+
/** Absolute node paths bind the physical closure, including package-owned build-volume aliases. */
|
|
221
|
+
readonly nodes: readonly EnsureBuiltOutputReceipt[];
|
|
222
|
+
readonly sha256: string;
|
|
223
|
+
}
|
|
224
|
+
export interface EnsureBuiltProducerReceipt {
|
|
225
|
+
readonly version: 1;
|
|
226
|
+
readonly target: string;
|
|
227
|
+
readonly argv: readonly string[];
|
|
228
|
+
readonly trackedTreeClean: true;
|
|
229
|
+
/** Declared runtime/environment identity from actual Nx completion hashes, never a consumer environment hash. */
|
|
230
|
+
readonly environmentIdentity: string;
|
|
231
|
+
readonly inputs: readonly EnsureBuiltProducerTaskInputs[];
|
|
232
|
+
readonly tools: readonly EnsureBuiltProducerTool[];
|
|
233
|
+
/** SHA-256 of the independently censused task/public-output records, never terminal output. */
|
|
234
|
+
readonly outputSha256: string;
|
|
235
|
+
readonly wallTimeMs: number;
|
|
236
|
+
}
|
|
189
237
|
/** Git provenance covers file inputs only; runtime/env identity remains Nx's current task hash. */
|
|
190
238
|
export interface EnsureBuiltReceipt {
|
|
191
239
|
readonly workspaceRoot: string;
|
|
@@ -193,6 +241,7 @@ export interface EnsureBuiltReceipt {
|
|
|
193
241
|
readonly headTree: string;
|
|
194
242
|
readonly fileInputProvenance: 'exact-file-inputs' | 'conservative-provider-source';
|
|
195
243
|
readonly runtimeEnvironmentProvenance: 'nx-task-hash-only';
|
|
244
|
+
readonly producer: EnsureBuiltProducerReceipt;
|
|
196
245
|
readonly tasks: readonly {
|
|
197
246
|
readonly id: string;
|
|
198
247
|
readonly hash: string;
|
|
@@ -683,7 +732,11 @@ type PreparedWorkspaceProbe =
|
|
|
683
732
|
| ReadyWorkspaceProbe
|
|
684
733
|
| { readonly kind: 'no-daemon'; readonly reason: Extract<MissReason, { kind: 'no-daemon' }> };
|
|
685
734
|
|
|
686
|
-
async function prepareWorkspaceProbe(
|
|
735
|
+
async function prepareWorkspaceProbe(
|
|
736
|
+
workspaceRoot: string,
|
|
737
|
+
selector: TargetSelector,
|
|
738
|
+
forceGraphRpc = false,
|
|
739
|
+
): Promise<PreparedWorkspaceProbe> {
|
|
687
740
|
const taskId = selectorTaskId(selector);
|
|
688
741
|
// This explicit fallback path loads no Nx. The build operation may run the
|
|
689
742
|
// checkout-local CLI; the read-only operation can only report the miss.
|
|
@@ -715,7 +768,7 @@ async function prepareWorkspaceProbe(workspaceRoot: string, selector: TargetSele
|
|
|
715
768
|
setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
|
|
716
769
|
|
|
717
770
|
performance.mark('ensureBuilt:graph:start');
|
|
718
|
-
const projectGraph = await currentProjectGraph(workspaceRoot, nxJson, requireNx);
|
|
771
|
+
const projectGraph = await currentProjectGraph(workspaceRoot, nxJson, requireNx, forceGraphRpc);
|
|
719
772
|
nxJson = readNxJson();
|
|
720
773
|
requireProject(projectGraph, selector.project);
|
|
721
774
|
const taskGraph = createTaskGraph(
|
|
@@ -783,64 +836,31 @@ async function buildPreparedTarget(
|
|
|
783
836
|
}
|
|
784
837
|
|
|
785
838
|
async function probeBuiltInWorkspace(workspaceRoot: string, selector: TargetSelector): Promise<EnsureBuiltProbeResult> {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
requireNx('nx/src/native').expandOutputs,
|
|
804
|
-
);
|
|
805
|
-
if (result.disposition === 'hit') {
|
|
806
|
-
const after = captureProbeSource(root, requireNx);
|
|
807
|
-
if (!snapshotsEqual(probeSource, after) || !nodesUnchanged(probeSource.nodes)) {
|
|
808
|
-
result = {
|
|
809
|
-
disposition: 'failed',
|
|
810
|
-
reason: {
|
|
811
|
-
kind: 'provider-proof',
|
|
812
|
-
taskId,
|
|
813
|
-
workspaceRoot: root,
|
|
814
|
-
detail: 'Provider source nodes or membership moved across Nx hashing/receipt capture',
|
|
815
|
-
},
|
|
816
|
-
exitCode: 1,
|
|
817
|
-
signal: null,
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
if (result.disposition === 'failed') {
|
|
822
|
-
process.stderr.write(`probeBuilt: ${result.reason.workspaceRoot}: ${result.reason.detail}\n`);
|
|
823
|
-
}
|
|
824
|
-
return result;
|
|
825
|
-
});
|
|
839
|
+
const taskId = selectorTaskId(selector);
|
|
840
|
+
const receipt = readProducerReceipt(workspaceRoot, taskId);
|
|
841
|
+
if (receipt.ok) return { disposition: 'hit', receipt: receipt.value };
|
|
842
|
+
// A failed publication proof asks Nx for the authoritative generation, but
|
|
843
|
+
// never hashes against the consumer environment or starts a provider runner.
|
|
844
|
+
const prepared = await prepareWorkspaceProbe(workspaceRoot, selector, true);
|
|
845
|
+
const detail =
|
|
846
|
+
prepared.kind === 'no-daemon'
|
|
847
|
+
? `${receipt.detail}; authoritative graph unavailable: ${describeMiss(prepared.reason)}`
|
|
848
|
+
: receipt.detail;
|
|
849
|
+
process.stderr.write(`probeBuilt: ${workspaceRoot}: ${taskId}: ${detail}\n`);
|
|
850
|
+
return {
|
|
851
|
+
disposition: 'failed',
|
|
852
|
+
reason: { kind: 'provider-proof', taskId, workspaceRoot, detail },
|
|
853
|
+
exitCode: 1,
|
|
854
|
+
signal: null,
|
|
855
|
+
};
|
|
826
856
|
}
|
|
827
857
|
|
|
828
|
-
function captureProbeSource(
|
|
829
|
-
workspaceRoot: string,
|
|
830
|
-
requireNx: WorkspaceNxRequire,
|
|
831
|
-
): ReturnType<typeof workspaceSnapshot> {
|
|
832
|
-
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
833
|
-
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
834
|
-
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
835
|
-
const previous = readGraphWitness(join(data, 'ensure-built-graph.json'));
|
|
836
|
-
return workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), previous?.snapshot);
|
|
837
|
-
}
|
|
838
858
|
/** Nx's native plan is the FILE selection oracle, not a second glob planner.
|
|
839
859
|
* Config identities skipped by the inspector are included explicitly. A
|
|
840
860
|
* runtime identity is bounded only by the owning toolchain recipe + a declared
|
|
841
861
|
* pin; opaque commands and unavailable native proof categorically refuse.
|
|
842
862
|
*/
|
|
843
|
-
function providerInputProof(
|
|
863
|
+
export function providerInputProof(
|
|
844
864
|
workspaceRoot: string,
|
|
845
865
|
nxJson: NxJsonConfiguration,
|
|
846
866
|
projectGraph: ProjectGraph,
|
|
@@ -886,6 +906,7 @@ function providerInputProof(
|
|
|
886
906
|
for (const dependency of projectGraph.dependencies[name] ?? []) includeProject(dependency.target);
|
|
887
907
|
}
|
|
888
908
|
let conservative = false;
|
|
909
|
+
let hasRuntime = false;
|
|
889
910
|
const projectConfigs = Object.fromEntries(
|
|
890
911
|
Object.entries(projectGraph.nodes).map(([name, node]) => [name, node.data]),
|
|
891
912
|
);
|
|
@@ -901,6 +922,7 @@ function providerInputProof(
|
|
|
901
922
|
};
|
|
902
923
|
}
|
|
903
924
|
for (const file of input.files) files.add(file);
|
|
925
|
+
hasRuntime ||= input.runtime.length > 0;
|
|
904
926
|
if (input.runtime.length > 0 || input.environment.length > 0) conservative = true;
|
|
905
927
|
const node = projectGraph.nodes[task.target.project];
|
|
906
928
|
if (node === undefined) throw new Error(`Lost project for receipt ${task.id}`);
|
|
@@ -933,11 +955,26 @@ function providerInputProof(
|
|
|
933
955
|
]) {
|
|
934
956
|
if (existsSync(join(workspaceRoot, path))) files.add(path);
|
|
935
957
|
}
|
|
936
|
-
const installation =
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
958
|
+
const installation = hasRuntime
|
|
959
|
+
? graphInstallationIdentity(
|
|
960
|
+
workspaceRoot,
|
|
961
|
+
nxJson,
|
|
962
|
+
requireNx('nx/src/utils/package-json').readModulePackageJson,
|
|
963
|
+
requireNx('nx/src/native').expandOutputs,
|
|
964
|
+
graphInputContractIdentity(
|
|
965
|
+
workspaceRoot,
|
|
966
|
+
nxJson,
|
|
967
|
+
workspaceSnapshot(
|
|
968
|
+
workspaceRoot,
|
|
969
|
+
new (requireNx('nx/src/native').WorkspaceContext)(
|
|
970
|
+
workspaceRoot,
|
|
971
|
+
requireNx('nx/src/utils/cache-directory').workspaceDataDirectoryForWorkspace(workspaceRoot),
|
|
972
|
+
),
|
|
973
|
+
undefined,
|
|
974
|
+
),
|
|
975
|
+
),
|
|
976
|
+
)
|
|
977
|
+
: null;
|
|
941
978
|
const runtimeSource = boundedReceiptRuntimes(inputs, [...directories], [...files], installation !== null);
|
|
942
979
|
return {
|
|
943
980
|
kind: conservative ? 'conservative-provider-source' : 'exact-file-inputs',
|
|
@@ -989,9 +1026,10 @@ async function currentProjectGraph(
|
|
|
989
1026
|
workspaceRoot: string,
|
|
990
1027
|
nxJson: NxJsonConfiguration,
|
|
991
1028
|
requireNx: WorkspaceNxRequire,
|
|
1029
|
+
forceGraphRpc: boolean,
|
|
992
1030
|
): Promise<ProjectGraph> {
|
|
993
1031
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
994
|
-
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
1032
|
+
const { WorkspaceContext, expandOutputs } = requireNx('nx/src/native');
|
|
995
1033
|
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
996
1034
|
const packageResolution = requireNx('nx/src/utils/package-json');
|
|
997
1035
|
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
@@ -1010,14 +1048,26 @@ async function currentProjectGraph(
|
|
|
1010
1048
|
await daemonClient.updateWorkspaceContext(created, updated, deleted);
|
|
1011
1049
|
}
|
|
1012
1050
|
performance.measure('ensureBuilt:inputs', 'ensureBuilt:inputs:start');
|
|
1013
|
-
const installation = graphInstallationIdentity(
|
|
1051
|
+
const installation = graphInstallationIdentity(
|
|
1052
|
+
workspaceRoot,
|
|
1053
|
+
nxJson,
|
|
1054
|
+
packageResolution.readModulePackageJson,
|
|
1055
|
+
expandOutputs,
|
|
1056
|
+
graphInputContractIdentity(workspaceRoot, nxJson, before),
|
|
1057
|
+
);
|
|
1014
1058
|
const cached = nodesUnchanged(before.nodes)
|
|
1015
1059
|
? reusableGraph(witness, workspaceRoot, environment, installation, before)
|
|
1016
1060
|
: null;
|
|
1017
|
-
if (cached !== null) return cached;
|
|
1061
|
+
if (!forceGraphRpc && cached !== null) return cached;
|
|
1018
1062
|
const { projectGraph } = await daemonClient.getProjectGraphAndSourceMaps();
|
|
1019
1063
|
const after = workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), before);
|
|
1020
|
-
const finalInstallation = graphInstallationIdentity(
|
|
1064
|
+
const finalInstallation = graphInstallationIdentity(
|
|
1065
|
+
workspaceRoot,
|
|
1066
|
+
nxJson,
|
|
1067
|
+
packageResolution.readModulePackageJson,
|
|
1068
|
+
expandOutputs,
|
|
1069
|
+
graphInputContractIdentity(workspaceRoot, nxJson, after),
|
|
1070
|
+
);
|
|
1021
1071
|
const stableGeneration = snapshotsEqual(before, after) && nodesUnchanged(before.nodes);
|
|
1022
1072
|
if (installation !== null && installation === finalInstallation && stableGeneration) {
|
|
1023
1073
|
const next: GraphWitness = { version: 1, workspaceRoot, environment, installation, snapshot: after, projectGraph };
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
CPU_POOL_ENV,
|
|
10
10
|
type CpuPool,
|
|
11
11
|
createCpuPool,
|
|
12
|
+
type HostWaits,
|
|
12
13
|
type InheritedCpuPool,
|
|
13
14
|
readInheritedCpuPool,
|
|
14
15
|
takeParentCpuTokens,
|
|
@@ -19,10 +20,49 @@ import { CPU_TOKENS_ENV, type TokenGrant } from './cpu-tokens.js';
|
|
|
19
20
|
type PoolReply =
|
|
20
21
|
| { ok: true; lease: 'queued' }
|
|
21
22
|
| { ok: true; lease: 'granted'; tokens: number; pool?: string }
|
|
23
|
+
| { ok: true; wait: 'held' }
|
|
22
24
|
| { ok: false; code: 'invalid-request'; error: string };
|
|
23
25
|
|
|
24
26
|
const parseReply = typia.json.createAssertParse<PoolReply>();
|
|
25
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A run's host waits as the pool reports them: how many are held now, every begin and end in order, and `reaches(n)`,
|
|
30
|
+
* which resolves once the count is `n` (the pool hears a close after its client does).
|
|
31
|
+
*/
|
|
32
|
+
interface CountedWaits extends HostWaits {
|
|
33
|
+
readonly held: () => number;
|
|
34
|
+
readonly events: ('begin' | 'end')[];
|
|
35
|
+
reaches(count: number): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function countedWaits(): CountedWaits {
|
|
39
|
+
const events: ('begin' | 'end')[] = [];
|
|
40
|
+
const watchers: { count: number; done: () => void }[] = [];
|
|
41
|
+
let held = 0;
|
|
42
|
+
const changed = (): void => {
|
|
43
|
+
for (const watcher of watchers.filter((each) => each.count === held)) {
|
|
44
|
+
watchers.splice(watchers.indexOf(watcher), 1);
|
|
45
|
+
watcher.done();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
held: () => held,
|
|
50
|
+
events,
|
|
51
|
+
reaches: (count) =>
|
|
52
|
+
count === held ? Promise.resolve() : new Promise<void>((done) => watchers.push({ count, done })),
|
|
53
|
+
begin: () => {
|
|
54
|
+
held += 1;
|
|
55
|
+
events.push('begin');
|
|
56
|
+
changed();
|
|
57
|
+
},
|
|
58
|
+
end: () => {
|
|
59
|
+
held -= 1;
|
|
60
|
+
events.push('end');
|
|
61
|
+
changed();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
26
66
|
type Granted = Extract<TokenGrant, { granted: true }>;
|
|
27
67
|
|
|
28
68
|
/** A raw child connection: its replies come one line at a time, and `closed` resolves when it ends. */
|
|
@@ -57,8 +97,12 @@ afterEach(async () => {
|
|
|
57
97
|
});
|
|
58
98
|
|
|
59
99
|
/** Make a pool of `tokens` and read its endpoint back through the same path a child uses. */
|
|
60
|
-
async function openPool(
|
|
61
|
-
|
|
100
|
+
async function openPool(
|
|
101
|
+
tokens: number,
|
|
102
|
+
closed: Promise<void> = NEVER,
|
|
103
|
+
waits: HostWaits = countedWaits(),
|
|
104
|
+
): Promise<Opened> {
|
|
105
|
+
const made = await createCpuPool(tokens, closed, waits);
|
|
62
106
|
if (!made.ok) {
|
|
63
107
|
throw new Error(made.error);
|
|
64
108
|
}
|
|
@@ -72,7 +116,7 @@ async function openPool(tokens: number, closed: Promise<void> = NEVER): Promise<
|
|
|
72
116
|
|
|
73
117
|
/** A granted lease for a child that the pool must admit: a refusal here is a test failure. */
|
|
74
118
|
async function takeOrThrow(parent: InheritedCpuPool, want: number): Promise<Granted> {
|
|
75
|
-
const grant = await takeParentCpuTokens(parent, want
|
|
119
|
+
const grant = await takeParentCpuTokens(parent, want);
|
|
76
120
|
if (!grant.granted) {
|
|
77
121
|
throw new Error(`the pool refused ${want} tokens: ${grant.reason}`);
|
|
78
122
|
}
|
|
@@ -80,11 +124,11 @@ async function takeOrThrow(parent: InheritedCpuPool, want: number): Promise<Gran
|
|
|
80
124
|
}
|
|
81
125
|
|
|
82
126
|
/**
|
|
83
|
-
* The count a child is granted for `want
|
|
127
|
+
* The count a child is granted for `want`. The grant is released and its close awaited before
|
|
84
128
|
* returning, so the next ask starts from the pool as this one left it.
|
|
85
129
|
*/
|
|
86
|
-
async function grantedFor(parent: InheritedCpuPool, want: number
|
|
87
|
-
const grant = await takeParentCpuTokens(parent, want
|
|
130
|
+
async function grantedFor(parent: InheritedCpuPool, want: number): Promise<number> {
|
|
131
|
+
const grant = await takeParentCpuTokens(parent, want);
|
|
88
132
|
if (!grant.granted) {
|
|
89
133
|
throw new Error(`the pool refused ${want} tokens: ${grant.reason}`);
|
|
90
134
|
}
|
|
@@ -182,7 +226,7 @@ describe('the parent-held CPU pool', () => {
|
|
|
182
226
|
const cargo = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 4, children: true }));
|
|
183
227
|
expect(await cargo.next()).toEqual(QUEUED);
|
|
184
228
|
const granted = await cargo.next();
|
|
185
|
-
if (!granted.ok || granted.lease !== 'granted' || granted.pool === undefined)
|
|
229
|
+
if (!granted.ok || !('lease' in granted) || granted.lease !== 'granted' || granted.pool === undefined)
|
|
186
230
|
throw new Error('no live child pool granted');
|
|
187
231
|
expect(granted.tokens).toBe(4);
|
|
188
232
|
expect(granted.pool).not.toBe(parent.socket);
|
|
@@ -296,23 +340,23 @@ describe('the parent-held CPU pool', () => {
|
|
|
296
340
|
holder.kill('SIGKILL');
|
|
297
341
|
await holder.exited;
|
|
298
342
|
}
|
|
299
|
-
}
|
|
343
|
+
});
|
|
300
344
|
|
|
301
345
|
it('treats a dead or non-socket endpoint as absent, and a malformed endpoint as no pool', async () => {
|
|
302
346
|
const { pool, parent } = await openPool(2);
|
|
303
347
|
expect(await pool.close()).toEqual({ ok: true });
|
|
304
|
-
expect(await takeParentCpuTokens(parent, 1
|
|
348
|
+
expect(await takeParentCpuTokens(parent, 1)).toMatchObject({ granted: false, cause: 'absent' });
|
|
305
349
|
|
|
306
350
|
const stale = await ownedSocketDirectory('cpu-stale-', 'p.sock');
|
|
307
351
|
directories.push(stale);
|
|
308
352
|
await writeFile(join(stale, 'p.sock'), 'not a socket');
|
|
309
|
-
expect(await takeParentCpuTokens({ socket: join(stale, 'p.sock'), tokens: 2 }, 1
|
|
353
|
+
expect(await takeParentCpuTokens({ socket: join(stale, 'p.sock'), tokens: 2 }, 1)).toMatchObject({
|
|
310
354
|
granted: false,
|
|
311
355
|
cause: 'absent',
|
|
312
356
|
});
|
|
313
357
|
|
|
314
358
|
expect(readInheritedCpuPool({ [CPU_POOL_ENV]: 'a\0b', [CPU_TOKENS_ENV]: '2' })).toBeNull();
|
|
315
|
-
expect(await takeParentCpuTokens({ socket: 'a\0b', tokens: 2 }, 1
|
|
359
|
+
expect(await takeParentCpuTokens({ socket: 'a\0b', tokens: 2 }, 1)).toMatchObject({
|
|
316
360
|
granted: false,
|
|
317
361
|
cause: 'other',
|
|
318
362
|
});
|
|
@@ -322,7 +366,7 @@ describe('the parent-held CPU pool', () => {
|
|
|
322
366
|
});
|
|
323
367
|
|
|
324
368
|
it('names the endpoint and count it holds, in private owned paths, and removes them on close', async () => {
|
|
325
|
-
const made = await createCpuPool(3, NEVER);
|
|
369
|
+
const made = await createCpuPool(3, NEVER, countedWaits());
|
|
326
370
|
if (!made.ok) {
|
|
327
371
|
throw new Error(made.error);
|
|
328
372
|
}
|
|
@@ -357,6 +401,49 @@ describe('the parent-held CPU pool', () => {
|
|
|
357
401
|
expect((await takeOrThrow(parent, 2)).tokens).toBe(2);
|
|
358
402
|
});
|
|
359
403
|
|
|
404
|
+
it("counts a descendant's host wait for as long as its connection holds it, through a child pool too", async () => {
|
|
405
|
+
const waits = countedWaits();
|
|
406
|
+
const { parent } = await openPool(4, NEVER, waits);
|
|
407
|
+
const held: PoolReply = { ok: true, wait: 'held' };
|
|
408
|
+
const direct = childOf(parent.socket, JSON.stringify({ op: 'host-wait' }));
|
|
409
|
+
expect(await direct.next()).toEqual(held);
|
|
410
|
+
expect(waits.held()).toBe(1);
|
|
411
|
+
// A wait holds no token: the whole pool is still there to grant.
|
|
412
|
+
expect(await grantedFor(parent, 4)).toBe(4);
|
|
413
|
+
|
|
414
|
+
// Cargo's launcher is served a child pool; the test it runs reports its waits there, to the same run.
|
|
415
|
+
const cargo = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2, children: true }));
|
|
416
|
+
expect(await cargo.next()).toEqual(QUEUED);
|
|
417
|
+
const granted = await cargo.next();
|
|
418
|
+
if (!granted.ok || !('lease' in granted) || granted.lease !== 'granted' || granted.pool === undefined) {
|
|
419
|
+
throw new Error(`no live child pool granted: ${JSON.stringify(granted)}`);
|
|
420
|
+
}
|
|
421
|
+
const nested = childOf(granted.pool, JSON.stringify({ op: 'host-wait' }));
|
|
422
|
+
expect(await nested.next()).toEqual(held);
|
|
423
|
+
expect(waits.held()).toBe(2);
|
|
424
|
+
|
|
425
|
+
direct.socket.destroy();
|
|
426
|
+
await direct.closed;
|
|
427
|
+
// The server sees the close after the client does; the count follows it.
|
|
428
|
+
await waits.reaches(1);
|
|
429
|
+
// The child pool's close ends the waits its children held.
|
|
430
|
+
cargo.socket.destroy();
|
|
431
|
+
await nested.closed;
|
|
432
|
+
await waits.reaches(0);
|
|
433
|
+
expect(waits.events).toEqual(['begin', 'begin', 'end', 'end']);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('ends a host wait whose holder writes past its one request', async () => {
|
|
437
|
+
const waits = countedWaits();
|
|
438
|
+
const { parent } = await openPool(1, NEVER, waits);
|
|
439
|
+
const waiter = childOf(parent.socket, JSON.stringify({ op: 'host-wait' }));
|
|
440
|
+
expect(await waiter.next()).toEqual({ ok: true, wait: 'held' });
|
|
441
|
+
waiter.socket.write(`${JSON.stringify({ op: 'host-wait' })}\n`);
|
|
442
|
+
await waiter.closed;
|
|
443
|
+
await waits.reaches(0);
|
|
444
|
+
expect(waits.events).toEqual(['begin', 'end']);
|
|
445
|
+
});
|
|
446
|
+
|
|
360
447
|
it('destroys a granted child that sends a second request, returning its tokens', async () => {
|
|
361
448
|
const { parent } = await openPool(2);
|
|
362
449
|
const first = childOf(parent.socket, JSON.stringify({ op: 'cpu-pool', want: 2 }));
|
|
@@ -380,47 +467,44 @@ describe('the parent-held CPU pool', () => {
|
|
|
380
467
|
const upstream = await openPool(4);
|
|
381
468
|
const lent = await takeOrThrow(upstream.parent, 2);
|
|
382
469
|
const sub = await openPool(lent.tokens, lent.closed);
|
|
383
|
-
const grandchild = await takeParentCpuTokens(sub.parent, 2
|
|
470
|
+
const grandchild = await takeParentCpuTokens(sub.parent, 2);
|
|
384
471
|
if (!grandchild.granted) {
|
|
385
472
|
throw new Error(`the sub-pool refused its grandchild: ${grandchild.reason}`);
|
|
386
473
|
}
|
|
387
|
-
|
|
474
|
+
// The grandchild asks its whole want and the sub-pool grants all it was lent.
|
|
475
|
+
expect(grandchild.tokens).toBe(2);
|
|
388
476
|
|
|
389
477
|
expect(await upstream.pool.close()).toEqual({ ok: true });
|
|
390
478
|
await lent.closed;
|
|
391
479
|
await grandchild.closed;
|
|
392
480
|
expect(await sub.pool.close()).toEqual({ ok: true });
|
|
393
481
|
expect(existsSync(dirname(sub.parent.socket))).toBe(false);
|
|
394
|
-
expect(await takeParentCpuTokens(sub.parent, 1
|
|
395
|
-
expect(await takeParentCpuTokens(upstream.parent, 1
|
|
482
|
+
expect(await takeParentCpuTokens(sub.parent, 1)).toMatchObject({ granted: false, cause: 'absent' });
|
|
483
|
+
expect(await takeParentCpuTokens(upstream.parent, 1)).toMatchObject({ granted: false, cause: 'absent' });
|
|
396
484
|
});
|
|
397
485
|
|
|
398
|
-
it('asks for
|
|
486
|
+
it('asks for its own want whatever count it inherited, and the grant follows that ask', async () => {
|
|
399
487
|
const cases = [
|
|
400
|
-
{ want: 1, inherited: 8,
|
|
401
|
-
{ want: 8, inherited: 2,
|
|
402
|
-
{ want: 8, inherited: 8,
|
|
403
|
-
{ want:
|
|
404
|
-
{ want: 8, inherited: 8, cores: 3, tokens: 2 },
|
|
405
|
-
{ want: 8, inherited: 8, cores: 1, tokens: 1 },
|
|
488
|
+
{ want: 1, inherited: 8, tokens: 1 },
|
|
489
|
+
{ want: 8, inherited: 2, tokens: 8 },
|
|
490
|
+
{ want: 8, inherited: 8, tokens: 8 },
|
|
491
|
+
{ want: 3, inherited: 1, tokens: 3 },
|
|
406
492
|
];
|
|
407
493
|
for (const check of cases) {
|
|
408
|
-
// A fresh full pool isolates
|
|
494
|
+
// A fresh full pool isolates each ask from delivery of the previous client's close event.
|
|
409
495
|
const { parent } = await openPool(8);
|
|
410
|
-
expect(await grantedFor({ socket: parent.socket, tokens: check.inherited }, check.want
|
|
411
|
-
check.tokens,
|
|
412
|
-
);
|
|
496
|
+
expect(await grantedFor({ socket: parent.socket, tokens: check.inherited }, check.want)).toBe(check.tokens);
|
|
413
497
|
}
|
|
414
498
|
});
|
|
415
499
|
|
|
416
500
|
it('never grants more than the live pool holds, even when the inherited count claims more', async () => {
|
|
417
501
|
const { parent } = await openPool(2);
|
|
418
|
-
// The child
|
|
419
|
-
expect(await grantedFor({ socket: parent.socket, tokens: 8 }, 8
|
|
502
|
+
// The child asks 8, but the live pool holds 2 and grants 2.
|
|
503
|
+
expect(await grantedFor({ socket: parent.socket, tokens: 8 }, 8)).toBe(2);
|
|
420
504
|
});
|
|
421
505
|
|
|
422
506
|
it('reports a teardown that cannot remove its directory, and reports the same outcome on every close', async () => {
|
|
423
|
-
const made = await createCpuPool(2, NEVER);
|
|
507
|
+
const made = await createCpuPool(2, NEVER, countedWaits());
|
|
424
508
|
if (!made.ok) {
|
|
425
509
|
throw new Error(made.error);
|
|
426
510
|
}
|
|
@@ -446,9 +530,9 @@ describe('the parent-held CPU pool', () => {
|
|
|
446
530
|
|
|
447
531
|
it('makes no pool when its grant closes during setup, and refuses a non-positive count', async () => {
|
|
448
532
|
const before = cpuPoolDirectories();
|
|
449
|
-
const made = await createCpuPool(2, Promise.resolve());
|
|
533
|
+
const made = await createCpuPool(2, Promise.resolve(), countedWaits());
|
|
450
534
|
expect(made.ok).toBe(false);
|
|
451
535
|
expect(cpuPoolDirectories()).toEqual(before);
|
|
452
|
-
await expect(createCpuPool(0, NEVER)).rejects.toBeInstanceOf(RangeError);
|
|
536
|
+
await expect(createCpuPool(0, NEVER, countedWaits())).rejects.toBeInstanceOf(RangeError);
|
|
453
537
|
});
|
|
454
538
|
});
|