@smoothbricks/nx-plugin 0.4.28 → 0.4.30

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.
Files changed (158) hide show
  1. package/README.md +277 -89
  2. package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
  3. package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-test-clocks.js +28 -0
  5. package/dist/bounded-test-policy.d.ts +8 -8
  6. package/dist/bounded-test-policy.d.ts.map +1 -1
  7. package/dist/bounded-test-policy.js +18 -30
  8. package/dist/cargo-closure-input.d.ts +23 -0
  9. package/dist/cargo-closure-input.d.ts.map +1 -1
  10. package/dist/cargo-closure-input.js +41 -9
  11. package/dist/cargo-source-hash.d.ts.map +1 -1
  12. package/dist/cargo-source-hash.js +42 -19
  13. package/dist/ensure-built-receipt.d.ts +40 -6
  14. package/dist/ensure-built-receipt.d.ts.map +1 -1
  15. package/dist/ensure-built-receipt.js +297 -159
  16. package/dist/ensure-built-witness.d.ts +65 -4
  17. package/dist/ensure-built-witness.d.ts.map +1 -1
  18. package/dist/ensure-built-witness.js +2237 -23
  19. package/dist/ensure-built.d.ts +99 -1
  20. package/dist/ensure-built.d.ts.map +1 -1
  21. package/dist/ensure-built.js +45 -56
  22. package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
  23. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/cpu-pool.js +51 -22
  25. package/dist/executors/bounded-exec/executor.d.ts +12 -3
  26. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/executor.js +174 -51
  28. package/dist/executors/bounded-exec/no-space.d.ts +8 -0
  29. package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
  30. package/dist/executors/bounded-exec/no-space.js +31 -0
  31. package/dist/executors/bounded-exec/ram-temp.d.ts +20 -11
  32. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  33. package/dist/executors/bounded-exec/ram-temp.js +42 -17
  34. package/dist/executors/bounded-exec/verdict.d.ts +34 -4
  35. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  36. package/dist/executors/bounded-exec/verdict.js +54 -3
  37. package/dist/generators/bun-test-tracing/generator.js +2 -2
  38. package/dist/graph-input-contract.d.ts +102 -0
  39. package/dist/graph-input-contract.d.ts.map +1 -0
  40. package/dist/graph-input-contract.js +637 -0
  41. package/dist/index.d.ts +12 -5
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +17 -3
  44. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  45. package/dist/managed-files/ci-workflow.js +5 -2
  46. package/dist/managed-files/publish-workflow.d.ts +11 -1
  47. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  48. package/dist/owned-installation.d.ts +14 -0
  49. package/dist/owned-installation.d.ts.map +1 -0
  50. package/dist/owned-installation.js +324 -0
  51. package/dist/producer-receipts.d.ts +19 -0
  52. package/dist/producer-receipts.d.ts.map +1 -0
  53. package/dist/producer-receipts.js +926 -0
  54. package/dist/test-backstop.d.ts +9 -0
  55. package/dist/test-backstop.d.ts.map +1 -0
  56. package/dist/test-backstop.js +10 -0
  57. package/dist/test-clock-policy.d.ts +30 -0
  58. package/dist/test-clock-policy.d.ts.map +1 -0
  59. package/dist/test-clock-policy.js +686 -0
  60. package/dist/testing.d.ts +8 -0
  61. package/dist/testing.d.ts.map +1 -1
  62. package/dist/testing.js +66 -1
  63. package/managed/raw/patches/nx@23.2.1.patch +328 -50
  64. package/managed/raw/tooling/direnv/developer-links.ts +148 -29
  65. package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
  66. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
  67. package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
  68. package/managed/raw/tooling/direnv/repo-path +15 -2
  69. package/managed/raw/tooling/direnv/setup-environment.ts +179 -115
  70. package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
  71. package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
  72. package/nextest.toml +1 -1
  73. package/package.json +25 -9
  74. package/src/__tests__/cargo-closure-fixture.ts +113 -0
  75. package/src/__tests__/counted-cargo.ts +8 -25
  76. package/src/__tests__/directory-change.ts +27 -0
  77. package/src/__tests__/fixture-nx-env.ts +7 -0
  78. package/src/__tests__/owned-installation.ts +14 -0
  79. package/src/__tests__/past-tick.ts +12 -0
  80. package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
  81. package/src/bin/smoo-nx-test-clocks.ts +29 -0
  82. package/src/bounded-test-policy.test.ts +36 -22
  83. package/src/bounded-test-policy.ts +18 -32
  84. package/src/bun-bootstrap.test.ts +1 -1
  85. package/src/cargo-closure-input.property.test.ts +50 -0
  86. package/src/cargo-closure-input.test.ts +73 -121
  87. package/src/cargo-closure-input.ts +47 -8
  88. package/src/cargo-closure-key.test.ts +239 -0
  89. package/src/cargo-resolve-cache.test.ts +168 -31
  90. package/src/cargo-source-hash.test.ts +78 -3
  91. package/src/cargo-source-hash.ts +48 -30
  92. package/src/cross-check-policy.test.ts +2 -2
  93. package/src/ensure-built-receipt.test.ts +111 -16
  94. package/src/ensure-built-receipt.ts +294 -149
  95. package/src/ensure-built-witness.test.ts +306 -13
  96. package/src/ensure-built-witness.ts +255 -24
  97. package/src/ensure-built.test.ts +228 -102
  98. package/src/ensure-built.ts +127 -66
  99. package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
  100. package/src/executors/bounded-exec/cpu-pool.ts +64 -20
  101. package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
  102. package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
  103. package/src/executors/bounded-exec/executor-host.test.ts +74 -52
  104. package/src/executors/bounded-exec/executor.test.ts +343 -97
  105. package/src/executors/bounded-exec/executor.ts +192 -56
  106. package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
  107. package/src/executors/bounded-exec/no-space.ts +40 -0
  108. package/src/executors/bounded-exec/progress.test.ts +1 -1
  109. package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
  110. package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
  111. package/src/executors/bounded-exec/ram-temp.ts +49 -20
  112. package/src/executors/bounded-exec/verdict.test.ts +127 -22
  113. package/src/executors/bounded-exec/verdict.ts +78 -3
  114. package/src/generators/bounded-test-targets/generator.test.ts +1 -3
  115. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  116. package/src/generators/bun-test-tracing/generator.ts +2 -2
  117. package/src/graph-input-contract.test.ts +379 -0
  118. package/src/graph-input-contract.ts +627 -0
  119. package/src/index.test.ts +3 -3
  120. package/src/index.ts +24 -3
  121. package/src/linked-snapshots.nx.test.ts +112 -30
  122. package/src/managed-files/ci-workflow.ts +5 -2
  123. package/src/managed-files/publish-workflow.ts +12 -1
  124. package/src/managed-files/repo-path.test.ts +44 -1
  125. package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
  126. package/src/nextest-code-bound.test.ts +23 -17
  127. package/src/nextest-extraction.test.ts +114 -4
  128. package/src/nextest-partitions.test.ts +7 -1
  129. package/src/nx-cache-restore-mtime.test.ts +2 -2
  130. package/src/nx-daemon-claim.test.ts +10 -8
  131. package/src/nx-daemon-idle-cpu.test.ts +0 -1
  132. package/src/nx-daemon-idle-policy.test.ts +61 -1
  133. package/src/nx-daemon-ignore-files.test.ts +2 -2
  134. package/src/nx-daemon-validity.test.ts +36 -22
  135. package/src/nx-dot-input-policy.test.ts +5 -5
  136. package/src/nx-files-archive-racy.test.ts +1 -1
  137. package/src/nx-incomplete-run-summary.test.ts +1 -1
  138. package/src/nx-plugin-load-errors.test.ts +2 -2
  139. package/src/nx-project-graph-errors.test.ts +70 -0
  140. package/src/nx-skipped-task-exit.test.ts +2 -2
  141. package/src/nx-store-resolution.test.ts +7 -25
  142. package/src/nx-task-output-lease.test.ts +3 -3
  143. package/src/nx-use-local.test.ts +7 -5
  144. package/src/owned-installation.ts +174 -0
  145. package/src/producer-receipts.test.ts +164 -0
  146. package/src/producer-receipts.ts +636 -0
  147. package/src/runtime-input.test.ts +1 -1
  148. package/src/serial-group-wiring.test.ts +4 -4
  149. package/src/task-results.test.ts +18 -16
  150. package/src/test-backstop.ts +11 -0
  151. package/src/test-clock-policy.test.ts +338 -0
  152. package/src/test-clock-policy.ts +708 -0
  153. package/src/test-timings.test.ts +2 -2
  154. package/src/testing.test.ts +5 -5
  155. package/src/testing.ts +67 -1
  156. package/src/typecheck-test-policy.test.ts +1 -1
  157. package/src/typescript-resolution.test.ts +76 -0
  158. package/test-timings.json +8 -0
@@ -32,7 +32,7 @@ import {
32
32
  keepDeveloperLinks,
33
33
  planDeclaredLinks,
34
34
  reportDeveloperLinks,
35
- reportUnavailableDeclaredLinks,
35
+ unreadableDeveloperLinks,
36
36
  } from './developer-links.ts';
37
37
  import {
38
38
  type DeferredSecret,
@@ -205,7 +205,8 @@ const POST_COMMIT_BLOCK = [
205
205
  // (cargoFetcher) live in smoo's user cache and count only while CARGO_HOME
206
206
  // names the directory they were fetched into, which no checkout-relative
207
207
  // change detection can see.
208
- // `--links` repairs stale install links (including external Nx aliases), then
208
+ // `--links` repairs stale install links (including external Nx aliases and
209
+ // store links whose install-cache entry is gone), then
209
210
  // points the packages `smoo.developerLinks` declares at their local checkouts.
210
211
  // devenv's smoo:developer-links task uses `--links --check` as its status:
211
212
  // links can change without any smoo:install input changing.
@@ -248,12 +249,20 @@ try {
248
249
  // A refused or unclaimed snapshot is current only when said: the exec that follows names its cause.
249
250
  const current =
250
251
  plan.changes.length === 0 && plan.unavailable.every((unavailable) => unavailable.kind === 'absent');
251
- process.exit(current && !hasStaleDeveloperLinks(projectRoot, ['nx']) ? 0 : 1);
252
+ process.exit(
253
+ current && !hasStaleDeveloperLinks(projectRoot, ['nx']) && danglingStoreLinks(projectRoot).length === 0 ? 0 : 1,
254
+ );
252
255
  }
253
256
  await withInstallLock(async () => {
254
257
  // Recheck under the install lock: another shell may already have repaired
255
258
  // the aliases. Use the same installer as smoo:install, never a second linker.
256
- if (hasStaleDeveloperLinks(projectRoot, ['nx'])) {
259
+ const store = danglingStoreLinks(projectRoot);
260
+ for (const link of store) {
261
+ console.error(
262
+ `! ${link} -> ${readlinkSync(link)}: that Bun install-cache entry no longer exists; reinstalling`,
263
+ );
264
+ }
265
+ if (store.length > 0 || hasStaleDeveloperLinks(projectRoot, ['nx'])) {
257
266
  const error = await installLocalDependencies([bunInstaller(bunInstallInputs())]);
258
267
  if (error !== undefined) reportSetupFailure(error);
259
268
  ensureTypeScriptApiPackage(projectRoot);
@@ -907,6 +916,9 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
907
916
  let actualPath = store;
908
917
  let expectedTarget = store;
909
918
  let operation: BunInstallIntegrityOperation = 'inspect isolated store';
919
+ // Developer links whose target this process may not read (developer-links.ts): the install
920
+ // did not make them and nothing here can read what they name, so they are not admitted here.
921
+ let unreadable: ReadonlySet<string> = new Set();
910
922
 
911
923
  const select = (candidate: string, symbolicLink: boolean): void => {
912
924
  actualPath = candidate;
@@ -920,6 +932,7 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
920
932
  realpathSync(candidate);
921
933
  };
922
934
  const manifest = (candidate: string, symbolicLink: boolean): void => {
935
+ if (unreadable.has(candidate)) return;
923
936
  select(candidate, symbolicLink);
924
937
  operation = 'read installed package manifest';
925
938
  JSON.parse(readFileSync(path.join(candidate, 'package.json'), 'utf8'));
@@ -952,6 +965,7 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
952
965
  // at. Same package and version alone is never reachability proof.
953
966
  const identityOf = (name: string): string | null => /^(.+@\d[^+]*)(\+.*)?$/.exec(name)?.[1] ?? null;
954
967
  try {
968
+ unreadable = new Set(unreadableDeveloperLinks(root));
955
969
  const state = lstatSync(store, { throwIfNoEntry: false });
956
970
  // A hoisted install has no isolated store to admit.
957
971
  if (state === undefined) return undefined;
@@ -964,112 +978,8 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
964
978
  const identity = identityOf(entry.name) ?? entry.name;
965
979
  identityCounts.set(identity, (identityCounts.get(identity) ?? 0) + 1);
966
980
  }
967
- // Every link in the installed tree that resolves into a store entry makes that entry live.
968
- const referenced = new Set<string>();
969
- const knownEntries = new Set(entries.filter((entry) => entry.name !== 'node_modules').map((entry) => entry.name));
970
- // Where each store entry actually lives: a link can reach an entry through its install
971
- // cache target (whose basename carries a cache suffix the entry name does not), so live
972
- // reachability is also containment inside an entry's real directory, not name matching.
973
- const entryReals = new Map<string, string>();
974
- for (const entry of entries) {
975
- if (entry.name === 'node_modules' || !(entry.isDirectory() || entry.isSymbolicLink())) continue;
976
- try {
977
- entryReals.set(entry.name, realpathSync(path.join(store, entry.name)));
978
- } catch {
979
- // A dangling entry has no real directory for a live alias to land inside.
980
- }
981
- }
982
- const scanLinks = (dir: string, owner: string | null): void => {
983
- let children: Dirent[];
984
- try {
985
- children = readdirSync(dir, { withFileTypes: true });
986
- } catch {
987
- return;
988
- }
989
- for (const child of children) {
990
- if (child.name.startsWith('.')) continue;
991
- const childPath = path.join(dir, child.name);
992
- if (child.name.startsWith('@')) {
993
- // A scope is a namespace, symlinked or not: traverse it, never treat it as a package.
994
- let isDirectory = false;
995
- try {
996
- isDirectory = statSync(childPath).isDirectory();
997
- } catch {
998
- isDirectory = false;
999
- }
1000
- if (isDirectory) {
1001
- scanLinks(childPath, owner);
1002
- continue;
1003
- }
1004
- }
1005
- if (!child.isSymbolicLink()) continue;
1006
- let target: string;
1007
- try {
1008
- target = readlinkSync(childPath);
1009
- } catch {
1010
- continue;
1011
- }
1012
- // The alias's canonical endpoint is what it actually reaches — through intermediate
1013
- // symlinks as well as its literal target — and is what select() already witnesses.
1014
- // A dangling alias has no endpoint; fall back to resolving its literal target
1015
- // against the physical parent, so a live reference to a broken entry still marks
1016
- // that entry referenced.
1017
- let physicalDir = path.dirname(childPath);
1018
- try {
1019
- physicalDir = realpathSync(physicalDir);
1020
- } catch {
1021
- // Keep the lexical parent; the segment mark below still applies.
1022
- }
1023
- let endpoint: string | null = null;
1024
- try {
1025
- endpoint = realpathSync(childPath);
1026
- } catch {
1027
- endpoint = null;
1028
- }
1029
- const resolved = endpoint ?? path.resolve(physicalDir, target);
1030
- if (endpoint !== null) {
1031
- // The canonical endpoint is authoritative: the entry whose real directory
1032
- // contains it is the live target, whatever any path segment happens to name.
1033
- for (const [name, real] of entryReals) {
1034
- if (name !== owner && (endpoint === real || endpoint.startsWith(`${real}${path.sep}`))) {
1035
- referenced.add(name);
1036
- break;
1037
- }
1038
- }
1039
- } else {
1040
- for (const segment of resolved.split(path.sep)) {
1041
- if (knownEntries.has(segment) && segment !== owner) {
1042
- referenced.add(segment);
1043
- break;
1044
- }
1045
- }
1046
- }
1047
- }
1048
- };
1049
- scanLinks(path.join(root, 'node_modules'), null);
1050
- scanLinks(path.join(store, 'node_modules'), null);
1051
- // Workspace members keep their own node_modules beside their manifests; links there are
1052
- // as live as root links, so the closure starts from them too. The enumeration is the one
1053
- // bunInstallInputs owns: both workspace forms, full glob patterns, exclusions.
1054
- const rootManifest = parseOrUndefined(() => JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')));
1055
- const workspaces = field(rootManifest, 'workspaces');
1056
- const memberPatterns = Array.isArray(workspaces)
1057
- ? stringList(workspaces)
1058
- : stringList(field(workspaces, 'packages'));
1059
- for (const manifestPath of workspaceFiles(memberPatterns, 'package.json')) {
1060
- scanLinks(path.join(root, path.dirname(manifestPath), 'node_modules'), null);
1061
- }
1062
- let grew = true;
1063
- while (grew) {
1064
- grew = false;
1065
- for (const entry of entries) {
1066
- if (entry.name === 'node_modules' || !(entry.isDirectory() || entry.isSymbolicLink())) continue;
1067
- if (!referenced.has(entry.name)) continue;
1068
- const before = referenced.size;
1069
- scanLinks(path.join(store, entry.name, 'node_modules'), entry.name);
1070
- if (referenced.size > before) grew = true;
1071
- }
1072
- }
981
+ const members = workspaceMemberModules(root);
982
+ const referenced = referencedStoreEntries(root, store, entries, members);
1073
983
  // Package aliases are what every consumer actually resolves: each package they name must
1074
984
  // resolve to a readable manifest, wherever it points — into the store, into the install
1075
985
  // cache, or at a workspace member. The same strict walk applies at the root and in every
@@ -1099,11 +1009,10 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
1099
1009
  }
1100
1010
  };
1101
1011
  walkPackageAliases(path.join(root, 'node_modules'));
1102
- for (const manifestPath of workspaceFiles(memberPatterns, 'package.json')) {
1103
- const memberModules = path.join(root, path.dirname(manifestPath), 'node_modules');
1012
+ for (const modules of members) {
1104
1013
  // A member with nothing installed has no aliases to validate; a present directory is
1105
1014
  // walked with the root's strictness.
1106
- if (existsSync(memberModules)) walkPackageAliases(memberModules);
1015
+ if (existsSync(modules)) walkPackageAliases(modules);
1107
1016
  }
1108
1017
  for (const entry of entries) {
1109
1018
  const candidate = path.join(store, entry.name);
@@ -1125,6 +1034,157 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
1125
1034
  }
1126
1035
  }
1127
1036
 
1037
+ /**
1038
+ * The store entries the installed tree reaches. Every link in the root's node_modules, the
1039
+ * store's own and each workspace member's that resolves into an entry makes that entry live,
1040
+ * and so does every link in a live entry's own node_modules, to a fixed point. Member links
1041
+ * are as live as root links.
1042
+ */
1043
+ function referencedStoreEntries(
1044
+ root: string,
1045
+ store: string,
1046
+ entries: readonly Dirent[],
1047
+ members: readonly string[],
1048
+ ): Set<string> {
1049
+ const referenced = new Set<string>();
1050
+ const knownEntries = new Set(entries.filter((entry) => entry.name !== 'node_modules').map((entry) => entry.name));
1051
+ // Where each store entry actually lives: a link can reach an entry through its install
1052
+ // cache target (whose basename carries a cache suffix the entry name does not), so live
1053
+ // reachability is also containment inside an entry's real directory, not name matching.
1054
+ const entryReals = new Map<string, string>();
1055
+ for (const entry of entries) {
1056
+ if (entry.name === 'node_modules' || !(entry.isDirectory() || entry.isSymbolicLink())) continue;
1057
+ try {
1058
+ entryReals.set(entry.name, realpathSync(path.join(store, entry.name)));
1059
+ } catch {
1060
+ // A dangling entry has no real directory for a live alias to land inside.
1061
+ }
1062
+ }
1063
+ const scanLinks = (dir: string, owner: string | null): void => {
1064
+ let children: Dirent[];
1065
+ try {
1066
+ children = readdirSync(dir, { withFileTypes: true });
1067
+ } catch {
1068
+ return;
1069
+ }
1070
+ for (const child of children) {
1071
+ if (child.name.startsWith('.')) continue;
1072
+ const childPath = path.join(dir, child.name);
1073
+ if (child.name.startsWith('@')) {
1074
+ // A scope is a namespace, symlinked or not: traverse it, never treat it as a package.
1075
+ let isDirectory = false;
1076
+ try {
1077
+ isDirectory = statSync(childPath).isDirectory();
1078
+ } catch {
1079
+ isDirectory = false;
1080
+ }
1081
+ if (isDirectory) {
1082
+ scanLinks(childPath, owner);
1083
+ continue;
1084
+ }
1085
+ }
1086
+ if (!child.isSymbolicLink()) continue;
1087
+ let target: string;
1088
+ try {
1089
+ target = readlinkSync(childPath);
1090
+ } catch {
1091
+ continue;
1092
+ }
1093
+ // The alias's canonical endpoint is what it actually reaches — through intermediate
1094
+ // symlinks as well as its literal target — and is what select() already witnesses.
1095
+ // A dangling alias has no endpoint; fall back to resolving its literal target
1096
+ // against the physical parent, so a live reference to a broken entry still marks
1097
+ // that entry referenced.
1098
+ let physicalDir = path.dirname(childPath);
1099
+ try {
1100
+ physicalDir = realpathSync(physicalDir);
1101
+ } catch {
1102
+ // Keep the lexical parent; the segment mark below still applies.
1103
+ }
1104
+ let endpoint: string | null = null;
1105
+ try {
1106
+ endpoint = realpathSync(childPath);
1107
+ } catch {
1108
+ endpoint = null;
1109
+ }
1110
+ const resolved = endpoint ?? path.resolve(physicalDir, target);
1111
+ if (endpoint !== null) {
1112
+ // The canonical endpoint is authoritative: the entry whose real directory
1113
+ // contains it is the live target, whatever any path segment happens to name.
1114
+ for (const [name, real] of entryReals) {
1115
+ if (name !== owner && (endpoint === real || endpoint.startsWith(`${real}${path.sep}`))) {
1116
+ referenced.add(name);
1117
+ break;
1118
+ }
1119
+ }
1120
+ } else {
1121
+ for (const segment of resolved.split(path.sep)) {
1122
+ if (knownEntries.has(segment) && segment !== owner) {
1123
+ referenced.add(segment);
1124
+ break;
1125
+ }
1126
+ }
1127
+ }
1128
+ }
1129
+ };
1130
+ scanLinks(path.join(root, 'node_modules'), null);
1131
+ scanLinks(path.join(store, 'node_modules'), null);
1132
+ for (const modules of members) scanLinks(modules, null);
1133
+ let grew = true;
1134
+ while (grew) {
1135
+ grew = false;
1136
+ for (const entry of entries) {
1137
+ if (entry.name === 'node_modules' || !(entry.isDirectory() || entry.isSymbolicLink())) continue;
1138
+ if (!referenced.has(entry.name)) continue;
1139
+ const before = referenced.size;
1140
+ scanLinks(path.join(store, entry.name, 'node_modules'), entry.name);
1141
+ if (referenced.size > before) grew = true;
1142
+ }
1143
+ }
1144
+ return referenced;
1145
+ }
1146
+
1147
+ /**
1148
+ * The node_modules directory of every workspace member, beside its manifest. The enumeration
1149
+ * is the one bunInstallInputs owns: both workspace forms, full glob patterns, exclusions.
1150
+ */
1151
+ function workspaceMemberModules(root: string): string[] {
1152
+ const rootManifest = parseOrUndefined(() => JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')));
1153
+ const workspaces = field(rootManifest, 'workspaces');
1154
+ const memberPatterns = Array.isArray(workspaces) ? stringList(workspaces) : stringList(field(workspaces, 'packages'));
1155
+ return workspaceFiles(memberPatterns, 'package.json').map((manifestPath) =>
1156
+ path.join(root, path.dirname(manifestPath), 'node_modules'),
1157
+ );
1158
+ }
1159
+
1160
+ /**
1161
+ * The store links the installed tree reaches whose target in Bun's install cache is gone. Under
1162
+ * `globalStore` each node_modules/.bun/<entry> is a link into that cache, and one that dangles
1163
+ * names a cache entry that no longer exists: the install is out of date, as it is while a
1164
+ * developer link dangles, and `bun install` links the entry again (measured, Bun 1.4.3). A
1165
+ * dangling variant nothing live reaches is superseded garbage the install leaves in place (see
1166
+ * verifyInstalledBunLinks), so it never makes the install stale: no install would change it.
1167
+ * The closure is walked only when some store link dangles.
1168
+ */
1169
+ function danglingStoreLinks(root: string): string[] {
1170
+ const store = path.join(root, 'node_modules', '.bun');
1171
+ let entries: Dirent[];
1172
+ try {
1173
+ entries = readdirSync(store, { withFileTypes: true }).filter((entry) => !entry.name.startsWith('.'));
1174
+ } catch (error) {
1175
+ // A hoisted install, or none yet, has no store to link from.
1176
+ if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR')) return [];
1177
+ throw error;
1178
+ }
1179
+ const dangling = entries.filter(
1180
+ (entry) =>
1181
+ entry.isSymbolicLink() && statSync(path.join(store, entry.name), { throwIfNoEntry: false }) === undefined,
1182
+ );
1183
+ if (dangling.length === 0) return [];
1184
+ const referenced = referencedStoreEntries(root, store, entries, workspaceMemberModules(root));
1185
+ return dangling.filter((entry) => referenced.has(entry.name)).map((entry) => path.join(store, entry.name));
1186
+ }
1187
+
1128
1188
  /**
1129
1189
  * `bun install`. Its result is location-independent: the isolated linker
1130
1190
  * links packages from the install cache by absolute path and workspace
@@ -1135,7 +1195,10 @@ function verifyInstalledBunLinks(root: string): BunInstallIntegrityError | undef
1135
1195
  * was pruned out from under node_modules. The native compiler binary ttsc
1136
1196
  * runs is witnessed the same way when the manifest declares it: a pruned
1137
1197
  * restore that kept the stamp and the API package but lost that binary
1138
- * otherwise reads as current and no install ever repairs it. A dangling developer target, or a live link to Nx, also invalidates a
1198
+ * otherwise reads as current and no install ever repairs it. A dangling
1199
+ * developer target, a live link to Nx, or a store link the installed tree
1200
+ * reaches whose install-cache entry is gone (danglingStoreLinks) also
1201
+ * invalidates a matching stamp.
1139
1202
  *
1140
1203
  * Frozen: shell entry installs what bun.lock records and never rewrites it. An unfrozen install migrated a
1141
1204
  * repository's lockfile format and re-resolved its ranges, a lockfile diff nobody asked for. A manifest that needs a
@@ -1150,7 +1213,8 @@ function bunInstaller(inputs: readonly string[]): Installer {
1150
1213
  findInstalledTypeScriptApiPackage(projectRoot) !== null &&
1151
1214
  (!declaresNativeTypeScript(projectRoot) ||
1152
1215
  existsSync(path.join(projectRoot, 'node_modules', '@typescript', 'native', 'bin', 'tsc'))) &&
1153
- !hasStaleDeveloperLinks(projectRoot, ['nx']),
1216
+ !hasStaleDeveloperLinks(projectRoot, ['nx']) &&
1217
+ danglingStoreLinks(projectRoot).length === 0,
1154
1218
  install: async ({ quiet }) => {
1155
1219
  await keepDeveloperLinks(
1156
1220
  projectRoot,
@@ -17,3 +17,12 @@ runs:
17
17
  key: ${{ runner.os }}-${{ runner.arch }}-node-v2-{{NODE_MODULES_CACHE_KEY}}
18
18
  restore-keys: |
19
19
  ${{ runner.os }}-${{ runner.arch }}-node-v2-
20
+
21
+ # The archive holds node_modules/.smoo-install, the stamp devenv's smoo:install watches, but not the
22
+ # workspace members' own node_modules links. A restored tree is a seed: only an install in this
23
+ # checkout may claim it current. A `!node_modules/.smoo-install` path cannot do this: actions/cache
24
+ # archives a listed directory whole and drops excludes inside it (actions/toolkit#713), so Publish
25
+ # run 39143439571 still restored the stamp and skipped the install.
26
+ - name: Drop the restored install stamp
27
+ shell: bash
28
+ run: rm -f node_modules/.smoo-install
@@ -159,6 +159,46 @@ runs:
159
159
  shell: bash
160
160
  run: echo "DEVENV_WORKDIR=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
161
161
 
162
+ # GitHub's hosted Ubuntu images promise only 14 GB free and fill the rest of
163
+ # the disk with toolchains a Nix-built shell never uses. The store can need
164
+ # more: the largest measured is 17.1 GB unpacked, and a restore or save also
165
+ # holds its 4.9 GB archive in RUNNER_TEMP. A 2-vCPU runner ran out of disk
166
+ # with about 15 GB of store on it, and nothing had printed free space.
167
+ # Delete those trees, most GiB per second first, until / has 32 GiB free.
168
+ # That is an estimate: the store at its peak with its archive, node_modules
169
+ # and build scratch, plus a few GiB of margin; the df lines record what a
170
+ # run really had. A runner that already has it deletes nothing, and the
171
+ # Android SDK, which alone takes minutes to delete, goes only when the rest
172
+ # was not enough.
173
+ # What goes stays gone for the rest of the job: a later actions/setup-*
174
+ # step downloads its runtime instead of finding it in the tool cache, a
175
+ # pwsh step loses the image's PowerShell modules (pwsh itself stays), and
176
+ # a step that runs the image's .NET, GHCup, Swift or Android SDK directly
177
+ # fails. Only a runner that started short of space deletes anything, so
178
+ # such a step would fail on some runs and pass on others.
179
+ # Synchronous on purpose: a background rm would race the store extraction
180
+ # for space and disk I/O. A failed delete warns and the job goes on: this
181
+ # is an optimisation, never a gate. Self-hosted machines keep everything.
182
+ - name: 🧹 Free runner disk
183
+ if: steps.runner-kind.outputs.host != 'true' && runner.os == 'Linux' && runner.environment == 'github-hosted'
184
+ shell: bash
185
+ run: |
186
+ want_kib=$((32 * 1024 * 1024))
187
+ free_kib() { df -k --output=avail / | tail -n 1 | tr -d ' '; }
188
+ df -h /
189
+ for dir in /usr/share/swift /usr/local/share/powershell /usr/local/.ghcup \
190
+ /usr/share/dotnet "${AGENT_TOOLSDIRECTORY:-}" /usr/local/lib/android; do
191
+ [ "$(free_kib)" -lt "$want_kib" ] || break
192
+ [ -n "$dir" ] && [ -d "$dir" ] || continue
193
+ start=$SECONDS
194
+ if sudo rm -rf "$dir"; then
195
+ echo "removed $dir in $((SECONDS - start)) s"
196
+ else
197
+ echo "::warning::could not remove $dir; going on without its space"
198
+ fi
199
+ done
200
+ df -h /
201
+
162
202
  # Devenv segment (own key): tooling/direnv/.devenv + .direnv — includes
163
203
  # nix-eval-cache.db. Independent of the store cache; restored on ephemeral
164
204
  # runners whether or not the store cache hit. Missing store paths are fine:
@@ -207,6 +247,20 @@ runs:
207
247
  # arrives inside /nix, so install-devenv's `nix profile add` of the locked
208
248
  # rev is a link rather than a download, and the devenv in play is the one
209
249
  # devenv.lock names instead of whichever run last populated the prefix.
250
+ #
251
+ # The key is two hashes: the pins (devenv.lock, devenv.yaml), then the files
252
+ # that choose and override packages on top of them (devenv.nix,
253
+ # devenv.smoo.nix, the nixpkgs overlay). The restore prefix ends after the
254
+ # pins, so a miss falls back only to a store saved from the same pins. Once
255
+ # nixpkgs or devenv moved, a store built from other pins is mostly dead
256
+ # weight that still costs its full unpacked size: measured, a pull request
257
+ # whose pins differed from the default branch's restored 7.55 GB, then
258
+ # fetched the same 1319 paths as a cold run, and the runner ran out of
259
+ # disk. The overlay is hashed itself because devenv.lock locks it as a
260
+ # relative path with no narHash: an overlay edit moved neither the lock nor
261
+ # the key, so every later run got an exact hit on a stale store that was
262
+ # never saved again. nix-v7 keeps the bare nix-v6- prefix of the old layout
263
+ # from restoring a store saved under this one.
210
264
  - name: 🧊 Cache Nix store
211
265
  id: nix-cache
212
266
  if: steps.runner-kind.outputs.host != 'true'
@@ -216,8 +270,9 @@ runs:
216
270
  /nix
217
271
  ~/.cache/nix
218
272
  # prettier-ignore
219
- primary-key: ${{ runner.os }}-${{ runner.arch }}-nix-v6-${{ hashFiles('tooling/direnv/devenv.yaml', 'tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/devenv.lock') }}
220
- restore-prefixes-first-match: ${{ runner.os }}-${{ runner.arch }}-nix-v6-
273
+ primary-key: ${{ runner.os }}-${{ runner.arch }}-nix-v7-${{ hashFiles('tooling/direnv/devenv.lock', 'tooling/direnv/devenv.yaml') }}-${{ hashFiles('tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/nixpkgs-overlay/**') }}
274
+ # prettier-ignore
275
+ restore-prefixes-first-match: ${{ runner.os }}-${{ runner.arch }}-nix-v7-${{ hashFiles('tooling/direnv/devenv.lock', 'tooling/direnv/devenv.yaml') }}-
221
276
  gc-max-store-size: 1G
222
277
 
223
278
  # cache-nix-action unpacks through sudo, so the directory it creates on the
@@ -245,11 +300,12 @@ runs:
245
300
  name: devenv
246
301
 
247
302
  # A host runner's devenv belongs to its image, so install-devenv accepts
248
- # whatever is on PATH there. On an ephemeral runner the devenv came out of a
249
- # cache this workflow wrote, so it is held to devenv.lock's rev: the store
250
- # cache restores ~/.nix-profile wholesale and a prefix match hands the job
251
- # the CLI of whichever run last populated the key, which outlived a lock bump
252
- # until the check existed.
303
+ # whatever is on PATH there. On an ephemeral runner it is held to
304
+ # devenv.lock's rev. The store cache once restored ~/.nix-profile, and a
305
+ # prefix match handed the job the CLI of whichever run last populated the
306
+ # key, which outlived a lock bump until the check existed. It now restores
307
+ # no profiles, and only a store saved from the same pins (devenv.lock,
308
+ # devenv.yaml).
253
309
  - name: 🧰 Install devenv
254
310
  shell: bash
255
311
  working-directory: ${{ env.DEVENV_WORKDIR }}/tooling/direnv
package/nextest.toml CHANGED
@@ -1,5 +1,5 @@
1
1
  # Injected by @smoothbricks/nx-plugin as `--config-file` on inferred cargo-test
2
- # package targets. `period` matches bun's `--timeout=30000`. A slow-timeout here
2
+ # package targets. A 30 s `period` names a slow test early. A slow-timeout here
3
3
  # only warns: nextest prints a `SLOW` line naming the test every period, and
4
4
  # never kills it. The run's no-progress bound (`idleTimeoutMs`, README "Bounded
5
5
  # Test Targets") ends a test that never returns, and names it from those lines.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.28",
3
+ "version": "0.4.30",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -38,6 +38,11 @@
38
38
  "import": "./dist/build-state-output-policy.js",
39
39
  "default": "./dist/build-state-output-policy.js"
40
40
  },
41
+ "./test-clock-policy": {
42
+ "types": "./dist/test-clock-policy.d.ts",
43
+ "import": "./dist/test-clock-policy.js",
44
+ "default": "./dist/test-clock-policy.js"
45
+ },
41
46
  "./test-walk-policy": {
42
47
  "types": "./dist/test-walk-policy.d.ts",
43
48
  "import": "./dist/test-walk-policy.js",
@@ -68,6 +73,11 @@
68
73
  "import": "./dist/test-timings.js",
69
74
  "default": "./dist/test-timings.js"
70
75
  },
76
+ "./graph-input-contract": {
77
+ "types": "./dist/graph-input-contract.d.ts",
78
+ "import": "./dist/graph-input-contract.js",
79
+ "default": "./dist/graph-input-contract.js"
80
+ },
71
81
  "./ensure-built": {
72
82
  "types": "./dist/ensure-built.d.ts",
73
83
  "import": "./dist/ensure-built.js",
@@ -78,6 +88,11 @@
78
88
  "import": "./dist/testing.js",
79
89
  "default": "./dist/testing.js"
80
90
  },
91
+ "./owned-installation": {
92
+ "types": "./dist/owned-installation.d.ts",
93
+ "import": "./dist/owned-installation.js",
94
+ "default": "./dist/owned-installation.js"
95
+ },
81
96
  "./cross-check-policy": {
82
97
  "types": "./dist/cross-check-policy.d.ts",
83
98
  "import": "./dist/cross-check-policy.js",
@@ -180,7 +195,8 @@
180
195
  "smoo-nx-nextest-extract": "./dist/bin/smoo-nx-nextest-extract.js",
181
196
  "smoo-nx-bound-failures": "./dist/bin/smoo-nx-bound-failures.js",
182
197
  "smoo-nx-failures": "./dist/bin/smoo-nx-failures.js",
183
- "smoo-nx-test-walks": "./dist/bin/smoo-nx-test-walks.js"
198
+ "smoo-nx-test-walks": "./dist/bin/smoo-nx-test-walks.js",
199
+ "smoo-nx-test-clocks": "./dist/bin/smoo-nx-test-clocks.js"
184
200
  },
185
201
  "generators": "./generators.json",
186
202
  "executors": "./executors.json",
@@ -203,7 +219,7 @@
203
219
  "test-shard1": {
204
220
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
205
221
  "options": {
206
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
222
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
207
223
  "cwd": "{projectRoot}",
208
224
  "idleTimeoutMs": 180000,
209
225
  "killAfterMs": 10000
@@ -212,7 +228,7 @@
212
228
  "test-shard2": {
213
229
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
214
230
  "options": {
215
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
231
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
216
232
  "cwd": "{projectRoot}",
217
233
  "idleTimeoutMs": 180000,
218
234
  "killAfterMs": 10000
@@ -221,7 +237,7 @@
221
237
  "test-shard3": {
222
238
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
223
239
  "options": {
224
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
240
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
225
241
  "cwd": "{projectRoot}",
226
242
  "idleTimeoutMs": 180000,
227
243
  "killAfterMs": 10000
@@ -230,7 +246,7 @@
230
246
  "test-shard4": {
231
247
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
232
248
  "options": {
233
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
249
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
234
250
  "cwd": "{projectRoot}",
235
251
  "idleTimeoutMs": 180000,
236
252
  "killAfterMs": 10000
@@ -247,7 +263,7 @@
247
263
  }
248
264
  ],
249
265
  "options": {
250
- "command": "bun test --timeout=30000 ./src/executors/bounded-exec/ram-temp-host.test.ts ./src/executors/bounded-exec/executor-host.test.ts",
266
+ "command": "bun test --timeout=0 ./src/executors/bounded-exec/ram-temp-host.test.ts ./src/executors/bounded-exec/executor-host.test.ts",
251
267
  "cwd": "{projectRoot}",
252
268
  "env": {
253
269
  "COWSHED_EXECUTABLE": "{workspaceRoot}/packages/cowshed/bin/cowshed"
@@ -296,8 +312,8 @@
296
312
  "yaml": "^2.9.0"
297
313
  },
298
314
  "devDependencies": {
299
- "@smoothbricks/lmao": "0.5.4",
300
- "@smoothbricks/validation": "0.1.10",
315
+ "@smoothbricks/lmao": "0.5.5",
316
+ "@smoothbricks/validation": "0.1.11",
301
317
  "fast-check": "^4.4.0"
302
318
  }
303
319
  }