@smoothbricks/nx-plugin 0.6.2 → 0.7.0

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 (177) hide show
  1. package/README.md +417 -171
  2. package/dist/.build-inputs.json +39 -28
  3. package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
  4. package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-go-test-build.js +79 -0
  6. package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
  7. package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-go-test-run.js +129 -0
  9. package/dist/bin/smoo-nx-publish.d.ts +3 -0
  10. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-publish.js +3 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +9 -8
  15. package/dist/cargo-retention-hook.d.ts +6 -2
  16. package/dist/cargo-retention-hook.d.ts.map +1 -1
  17. package/dist/cargo-retention-hook.js +13 -7
  18. package/dist/cargo-workspace.d.ts +10 -20
  19. package/dist/cargo-workspace.d.ts.map +1 -1
  20. package/dist/cargo-workspace.js +12 -22
  21. package/dist/cross-check-policy.d.ts +2 -2
  22. package/dist/cross-check-policy.js +2 -2
  23. package/dist/deploy-policy.d.ts +6 -0
  24. package/dist/deploy-policy.d.ts.map +1 -1
  25. package/dist/deploy-policy.js +11 -0
  26. package/dist/eslint-file-set.d.ts +4 -1
  27. package/dist/eslint-file-set.d.ts.map +1 -1
  28. package/dist/eslint-sources.d.ts +25 -0
  29. package/dist/eslint-sources.d.ts.map +1 -0
  30. package/dist/eslint-sources.js +99 -0
  31. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  32. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  33. package/dist/executors/all-verdicts/executor.js +48 -2
  34. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  35. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  36. package/dist/executors/all-verdicts/schema.js +7 -0
  37. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  38. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/bounds.js +100 -11
  40. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  41. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  42. package/dist/executors/bounded-exec/executor.js +289 -34
  43. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  44. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  45. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  46. package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
  47. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  48. package/dist/executors/bounded-exec/mbx-pool.js +145 -11
  49. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  50. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  51. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  52. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  53. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  54. package/dist/executors/bounded-exec/progress.js +151 -25
  55. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  56. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  57. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  58. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  59. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  60. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  62. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  63. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  64. package/dist/executors/bounded-exec/test-results.js +33 -0
  65. package/dist/executors/bounded-exec/verdict.d.ts +26 -2
  66. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  67. package/dist/executors/bounded-exec/verdict.js +108 -4
  68. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  69. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  70. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  71. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  72. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  73. package/dist/executors/wrangler-deploy/executor.js +43 -0
  74. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  75. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  76. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  77. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  78. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  79. package/dist/go-tests.d.ts +30 -0
  80. package/dist/go-tests.d.ts.map +1 -0
  81. package/dist/go-tests.js +43 -0
  82. package/dist/index.d.ts +12 -4
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +338 -295
  85. package/dist/managed-files/files.d.ts.map +1 -1
  86. package/dist/managed-files/files.js +5 -0
  87. package/dist/nx-publish.d.ts +24 -0
  88. package/dist/nx-publish.d.ts.map +1 -0
  89. package/dist/nx-publish.js +150 -0
  90. package/dist/process-group.js +2 -2
  91. package/dist/runtime-input-policy.d.ts +17 -3
  92. package/dist/runtime-input-policy.d.ts.map +1 -1
  93. package/dist/runtime-input-policy.js +4 -4
  94. package/dist/test-timings.d.ts +23 -4
  95. package/dist/test-timings.d.ts.map +1 -1
  96. package/dist/test-timings.js +72 -12
  97. package/dist/tool-bins.d.ts +6 -8
  98. package/dist/tool-bins.d.ts.map +1 -1
  99. package/dist/tool-bins.js +7 -5
  100. package/dist/version-actions.cjs +10 -11
  101. package/dist/version-actions.d.cts.map +1 -1
  102. package/dist/workspace-config-policy.d.ts.map +1 -1
  103. package/dist/workspace-config-policy.js +17 -22
  104. package/dist/workspace-index.d.ts +7 -0
  105. package/dist/workspace-index.d.ts.map +1 -1
  106. package/dist/workspace-index.js +11 -0
  107. package/dist/workspace-manifest.js +3 -3
  108. package/executors.json +7 -6
  109. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  110. package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
  111. package/managed/raw/tooling/devenv +1 -2
  112. package/managed/raw/tooling/direnv/developer-links.ts +124 -51
  113. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  114. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  115. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  116. package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
  117. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  118. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  119. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  120. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  121. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  122. package/package.json +277 -11
  123. package/runtime/nx-publish/.build-inputs.json +11 -0
  124. package/runtime/nx-publish/cache_adapter.js +45 -0
  125. package/runtime/nx-publish/nx_publish.js +60 -0
  126. package/runtime-input.sh +62 -26
  127. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  128. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  129. package/src/bin/smoo-nx-publish.ts +4 -0
  130. package/src/bounded-test-policy.ts +9 -8
  131. package/src/cargo-retention-hook.ts +16 -10
  132. package/src/cargo-workspace.ts +12 -24
  133. package/src/cross-check-policy.ts +2 -2
  134. package/src/deploy-policy.ts +11 -0
  135. package/src/eslint-file-set.ts +4 -1
  136. package/src/eslint-sources.ts +134 -0
  137. package/src/executors/all-verdicts/executor.ts +58 -3
  138. package/src/executors/all-verdicts/schema.json +4 -0
  139. package/src/executors/all-verdicts/schema.ts +14 -0
  140. package/src/executors/bounded-exec/bounds.ts +132 -15
  141. package/src/executors/bounded-exec/executor.ts +329 -34
  142. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  143. package/src/executors/bounded-exec/mbx-pool.ts +158 -17
  144. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  145. package/src/executors/bounded-exec/progress.ts +171 -18
  146. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  147. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  148. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  149. package/src/executors/bounded-exec/test-results.ts +39 -0
  150. package/src/executors/bounded-exec/verdict.ts +115 -5
  151. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  152. package/src/executors/wrangler-deploy/executor.ts +63 -0
  153. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  154. package/src/executors/wrangler-deploy/schema.json +16 -0
  155. package/src/executors/wrangler-deploy/schema.ts +4 -0
  156. package/src/go-tests.ts +67 -0
  157. package/src/index.ts +368 -323
  158. package/src/managed-files/files.ts +5 -0
  159. package/src/nx-publish.ts +157 -0
  160. package/src/process-group.ts +2 -2
  161. package/src/runtime-input-policy.ts +4 -4
  162. package/src/test-timings.ts +72 -14
  163. package/src/tool-bins.ts +13 -9
  164. package/src/version-actions.cts +10 -11
  165. package/src/workspace-config-policy.ts +20 -29
  166. package/src/workspace-index.ts +12 -0
  167. package/src/workspace-manifest.ts +3 -3
  168. package/test-timings.json +131 -125
  169. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  170. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  171. package/dist/executors/clean-outputs/executor.js +0 -83
  172. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  173. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  174. package/src/executors/clean-outputs/executor.ts +0 -131
  175. package/src/executors/clean-outputs/schema.json +0 -15
  176. package/src/executors/clean-outputs/schema.ts +0 -3
  177. /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ import { type SpawnSyncReturns, spawnSync } from 'node:child_process';
3
+ import { lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { join, relative, resolve } from 'node:path';
5
+ import { GO_TESTS_MANIFEST, type GoTestBinary, type GoTestsManifest } from '../go-tests.js';
6
+
7
+ // Builds a Go module's test binaries ahead of their run, so the build can be a cached target of its own: run in the
8
+ // module, it builds one `go test -c` binary for each package with test files among <package pattern>..., as `go list`
9
+ // resolves them, and writes <out-dir>/go-tests.json naming each binary's package and directory for
10
+ // smoo-nx-go-test-run. <out-dir> is replaced whole, so no binary of a package that lost its tests lingers; a directory
11
+ // that holds no such manifest is never replaced. Exit 2 on a usage error or such a directory; go's own status when go
12
+ // fails, its diagnostics already on stderr.
13
+ const usage = 'usage: smoo-nx-go-test-build <out-dir> <package pattern>...\n';
14
+ const words = process.argv.slice(2);
15
+ const [outWord, ...patterns] = words;
16
+ if (outWord === undefined || patterns.length === 0 || words.some((word) => word.startsWith('-'))) {
17
+ process.stderr.write(usage);
18
+ process.exit(2);
19
+ }
20
+ const out = resolve(outWord);
21
+ // One record per package with test files: its import path and directory, each NUL-terminated; go list ends the
22
+ // output of every package that printed one with a newline. No path holds a NUL, so the records split exactly.
23
+ const LISTED = '{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{"\\x00"}}{{.Dir}}{{"\\x00"}}{{end}}';
24
+
25
+ function refuse(reason: string): never {
26
+ process.stderr.write(`smoo-nx-go-test-build: ${reason}\n`);
27
+ process.exit(2);
28
+ }
29
+
30
+ function exists(path: string): boolean {
31
+ try {
32
+ lstatSync(path);
33
+ return true;
34
+ } catch (error) {
35
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return false;
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ /** `go args`; when it fails, this build ends with go's status after `cleanup`. */
41
+ function go(args: readonly string[], capture: boolean, cleanup: () => void): SpawnSyncReturns<string> {
42
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: go list resolves and go test -c compiles for as long as the module takes; the target that runs this build bounds it, or the operator's interrupt ends it
43
+ const ran = spawnSync('go', args, { stdio: ['ignore', capture ? 'pipe' : 'inherit', 'inherit'], encoding: 'utf8' });
44
+ if (ran.error !== undefined || ran.status !== 0) {
45
+ cleanup();
46
+ const ended = ran.error?.message ?? (ran.signal === null ? `exit ${ran.status}` : `killed by ${ran.signal}`);
47
+ process.stderr.write(`smoo-nx-go-test-build: go ${args.join(' ')} failed: ${ended}\n`);
48
+ process.exit(ran.status === null || ran.status === 0 ? 2 : ran.status);
49
+ }
50
+ return ran;
51
+ }
52
+
53
+ if (exists(out) && !exists(join(out, GO_TESTS_MANIFEST))) {
54
+ refuse(`${out} exists and holds no ${GO_TESTS_MANIFEST}; only a directory this tool built is replaced`);
55
+ }
56
+ const packages = go(['list', '-f', LISTED, ...patterns], true, () => {})
57
+ .stdout.split('\0\n')
58
+ .filter((record) => record !== '')
59
+ .map((record) => {
60
+ const [importPath, dir, ...rest] = record.split('\0');
61
+ if (importPath === undefined || dir === undefined || rest.length > 0) {
62
+ refuse(`go list printed a record that is no import path and directory: ${JSON.stringify(record)}`);
63
+ }
64
+ return { importPath, dir };
65
+ })
66
+ .sort((a, b) => (a.importPath < b.importPath ? -1 : a.importPath > b.importPath ? 1 : 0));
67
+
68
+ const staging = `${out}.building-${process.pid}`;
69
+ const dropStaging = () => rmSync(staging, { recursive: true, force: true });
70
+ dropStaging();
71
+ mkdirSync(staging, { recursive: true });
72
+ const tests: GoTestBinary[] = [];
73
+ for (const { importPath, dir } of packages) {
74
+ // Injective, so no two packages share a binary, and readable enough to name the package.
75
+ const binary = `${encodeURIComponent(importPath)}.test`;
76
+ go(['test', '-c', '-o', join(staging, binary), importPath], false, dropStaging);
77
+ tests.push({ binary, dir: relative(out, dir) || '.', importPath });
78
+ }
79
+ const manifest: GoTestsManifest = { version: 1, tests };
80
+ writeFileSync(join(staging, GO_TESTS_MANIFEST), `${JSON.stringify(manifest, null, 2)}\n`);
81
+ rmSync(out, { recursive: true, force: true });
82
+ renameSync(staging, out);
83
+ process.stdout.write(`smoo-nx-go-test-build: ${tests.length} test binaries in ${out}\n`);
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+ import { spawn, spawnSync } from 'node:child_process';
3
+ import { statSync } from 'node:fs';
4
+ import { availableParallelism } from 'node:os';
5
+ import type { Readable, Writable } from 'node:stream';
6
+ import { type GoTestBinary, readGoTestsManifest } from '../go-tests.js';
7
+
8
+ // Runs the test binaries smoo-nx-go-test-build listed in <go-tests.json> as `go test -json` runs a package's binary:
9
+ // in its package directory, under `go tool test2json -t -p <import path>`, with the flags go test gives it, up to -p
10
+ // binaries at once (default GOMAXPROCS, else one per core, as go test's -p). Each event line reaches stdout whole, so
11
+ // bounded-exec reads results, verdict and progress from it as from go test (GO_TEST_RUNNER); `-json` is accepted and
12
+ // implied. A manifest listing no binary is refused unless --allow-empty says none is expected, so a package pattern
13
+ // that matched no tests cannot pass. Exit 1 when any binary failed, 2 on a usage error or a manifest it cannot run.
14
+ const usage = 'usage: smoo-nx-go-test-run [-p=N] [-json] [--allow-empty] <go-tests.json>\n';
15
+ // What `go test -json` passes every test binary it runs, its default -timeout included.
16
+ const GO_TEST_BINARY_FLAGS = ['-test.v=test2json', '-test.paniconexit0', '-test.timeout=10m0s'];
17
+ const COUNT = /^[1-9]\d*$/;
18
+
19
+ function refuse(reason: string): never {
20
+ process.stderr.write(`smoo-nx-go-test-run: ${reason}\n`);
21
+ process.exit(2);
22
+ }
23
+
24
+ interface RunArguments {
25
+ readonly packages: number | null;
26
+ readonly allowEmpty: boolean;
27
+ readonly manifest: string;
28
+ }
29
+
30
+ function parseArguments(words: readonly string[]): RunArguments | null {
31
+ let packages: number | null = null;
32
+ let allowEmpty = false;
33
+ let manifest: string | null = null;
34
+ for (let at = 0; at < words.length; at += 1) {
35
+ const word = words[at] ?? '';
36
+ const flag = /^-p(?:=(.*))?$/.exec(word);
37
+ if (flag !== null) {
38
+ let value = flag[1];
39
+ if (value === undefined) {
40
+ at += 1;
41
+ value = words[at];
42
+ }
43
+ if (value === undefined || !COUNT.test(value)) return null;
44
+ packages = Number(value);
45
+ } else if (word === '--allow-empty') {
46
+ allowEmpty = true;
47
+ } else if (word === '-json' || word === '-json=true') {
48
+ // Implied: test2json writes nothing else.
49
+ } else if (word.startsWith('-') || word === '' || manifest !== null) {
50
+ return null;
51
+ } else {
52
+ manifest = word;
53
+ }
54
+ }
55
+ return manifest === null ? null : { packages, allowEmpty, manifest };
56
+ }
57
+
58
+ /** Every complete line `from` writes reaches `to` whole, so concurrent binaries' events never split a line. */
59
+ function forwardLines(from: Readable, to: Writable): void {
60
+ let pending: Buffer = Buffer.alloc(0);
61
+ from.on('data', (chunk: Buffer) => {
62
+ const bytes = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
63
+ const end = bytes.lastIndexOf(10);
64
+ if (end === -1) {
65
+ pending = bytes;
66
+ return;
67
+ }
68
+ to.write(bytes.subarray(0, end + 1));
69
+ pending = bytes.subarray(end + 1);
70
+ });
71
+ from.on('end', () => {
72
+ if (pending.length > 0) to.write(Buffer.concat([pending, Buffer.from('\n')]));
73
+ });
74
+ }
75
+
76
+ /** Null when the binary passed, else how it ended. */
77
+ function runBinary(test2json: string, test: GoTestBinary): Promise<string | null> {
78
+ // The plugin's lib target (ES2022) has no Promise.withResolvers.
79
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a test binary runs as long as its tests do; the bounded-exec run around this bin owns their progress bound and ends a hung one with its process group
80
+ return new Promise((resolve) => {
81
+ const child = spawn(test2json, ['-t', '-p', test.importPath, test.binary, ...GO_TEST_BINARY_FLAGS], {
82
+ cwd: test.dir,
83
+ stdio: ['ignore', 'pipe', 'pipe'],
84
+ });
85
+ forwardLines(child.stdout, process.stdout);
86
+ forwardLines(child.stderr, process.stderr);
87
+ child.on('error', (error) => resolve(`could not start: ${error.message}`));
88
+ child.on('close', (code, signal) =>
89
+ resolve(code === 0 ? null : signal === null ? `exit ${code}` : `killed by ${signal}`),
90
+ );
91
+ });
92
+ }
93
+
94
+ const parsed = parseArguments(process.argv.slice(2));
95
+ if (parsed === null) {
96
+ process.stderr.write(usage);
97
+ process.exit(2);
98
+ }
99
+ const read = readGoTestsManifest(parsed.manifest);
100
+ if (!read.ok) refuse(read.reason);
101
+ const tests = read.tests;
102
+ if (tests.length === 0) {
103
+ if (parsed.allowEmpty) process.exit(0);
104
+ refuse(
105
+ `${parsed.manifest} lists no test binaries, as when no package pattern matched a test; --allow-empty expects that`,
106
+ );
107
+ }
108
+ for (const test of tests) {
109
+ if (statSync(test.binary, { throwIfNoEntry: false })?.isFile() !== true) {
110
+ refuse(`${parsed.manifest} lists ${test.binary} for ${test.importPath}, which is no file; build it again`);
111
+ }
112
+ if (statSync(test.dir, { throwIfNoEntry: false })?.isDirectory() !== true) {
113
+ refuse(`${parsed.manifest} runs ${test.importPath} in ${test.dir}, which is no directory`);
114
+ }
115
+ }
116
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: go builds test2json into its cache on its first use, for as long as that compile takes; the bounded-exec run around this bin ends a hung one
117
+ const tool = spawnSync('go', ['tool', '-n', 'test2json'], { stdio: ['ignore', 'pipe', 'inherit'], encoding: 'utf8' });
118
+ if (tool.error !== undefined || tool.status !== 0) {
119
+ refuse(`go tool -n test2json named no test2json: ${tool.error?.message ?? `exit ${tool.status ?? tool.signal}`}`);
120
+ }
121
+ const test2json = tool.stdout.trim();
122
+ const inherited = process.env.GOMAXPROCS;
123
+ const packages =
124
+ parsed.packages ?? (inherited !== undefined && COUNT.test(inherited) ? Number(inherited) : availableParallelism());
125
+ const failures: string[] = [];
126
+ const queue = tests.values();
127
+ const worker = async (): Promise<void> => {
128
+ for (const test of queue) {
129
+ const failure = await runBinary(test2json, test);
130
+ if (failure !== null) failures.push(`${test.importPath} (${failure})`);
131
+ }
132
+ };
133
+ await Promise.all(Array.from({ length: Math.min(packages, tests.length) }, worker));
134
+ if (failures.length > 0) {
135
+ failures.sort();
136
+ process.stderr.write(
137
+ `smoo-nx-go-test-run: ${failures.length} of ${tests.length} test binaries failed: ${failures.join(', ')}\n`,
138
+ );
139
+ process.exitCode = 1;
140
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { runNxPublish } from '../nx-publish.js';
3
+
4
+ process.exitCode = await runNxPublish(process.argv.slice(2));
@@ -2,7 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { expandWildcardTargetConfiguration } from 'nx/src/tasks-runner/utils.js';
4
4
  import {
5
- CARGO_TEST_ARCHIVE_TARGET,
5
+ CARGO_TEST_BUILD_TARGET,
6
6
  CARGO_TEST_TARGET,
7
7
  listCargoWorkspacePackages,
8
8
  packageNameFromCargoTestTarget,
@@ -162,7 +162,7 @@ export function checkWorkspaceBoundedTestTargetPolicy(
162
162
  * package-local `nx.targets['cargo-test'].dependsOn` that omits the inferred
163
163
  * runner leg leaves a target that still "reaches" its dependencies while no
164
164
  * test binary is ever run. Reachability alone cannot see this, because
165
- * `cargo-test-archive` only compiles. (Inference itself no longer skips a
165
+ * `cargo-test-build` only compiles. (Inference itself no longer skips a
166
166
  * declared cargo key, so the executor and options survive the declaration —
167
167
  * see `index.ts`.)
168
168
  *
@@ -221,9 +221,9 @@ export function checkWorkspaceCargoTestReachabilityPolicy(
221
221
  /**
222
222
  * True when `target`, or something in its dependency closure, invokes cargo in a
223
223
  * mode that executes tests. Compile-only steps are deliberately excluded:
224
- * `cargo-test-archive` is `cargo nextest archive` and a `--no-run` build is
225
- * `cargo test --no-run`. Both prove the binaries build and nothing about them
226
- * running, and both say "test"/"nextest" in their command — a closure holding
224
+ * `cargo-test-build` is `cargo nextest list --list-type binaries-only`, a cross
225
+ * lane's archive is `cargo nextest archive` and a `--no-run` build is
226
+ * `cargo test --no-run`. Each proves the binaries build and nothing about them
227
227
  * only these is the silent green this check exists to catch.
228
228
  */
229
229
  function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string): boolean {
@@ -239,7 +239,8 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
239
239
  command !== undefined &&
240
240
  /\btest\b|\bnextest\b/.test(command) &&
241
241
  !command.includes('--no-run') &&
242
- !command.includes('nextest archive');
242
+ !command.includes('nextest archive') &&
243
+ !command.includes('nextest list');
243
244
  const reached =
244
245
  runs ||
245
246
  (project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
@@ -252,7 +253,7 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
252
253
  }
253
254
 
254
255
  /**
255
- * Per-crate nextest targets that `cargo-test` actually reaches. `cargo-test-archive`
256
+ * Per-crate nextest targets that `cargo-test` actually reaches. `cargo-test-build`
256
257
  * is excluded: it is not a runner. Members come from the same Cargo.toml walk
257
258
  * inference uses; the child list is the graph, not a hand-written crate list.
258
259
  */
@@ -453,7 +454,7 @@ function bunTestHasNoDeadline(command: string): boolean {
453
454
 
454
455
  function isTestLegTargetName(name: string): boolean {
455
456
  return (
456
- name !== CARGO_TEST_ARCHIVE_TARGET &&
457
+ name !== CARGO_TEST_BUILD_TARGET &&
457
458
  cargoCrossTestTripleFromArchiveTarget(name) === null &&
458
459
  isTestRunnerTargetName(name)
459
460
  );
@@ -1,13 +1,14 @@
1
1
  import { join, relative } from 'node:path';
2
2
  import {
3
- describeRetention,
4
3
  describeRetentionError,
4
+ describeRetentionStart,
5
5
  type Result,
6
6
  type RetentionError,
7
- type RetentionReport,
7
+ type RetentionStart,
8
8
  refusedAnywhere,
9
- retainCargoWorkspace,
9
+ startRetentionPass,
10
10
  } from '@smoothbricks/cargo-retain';
11
+ import { launchNodeCli } from '@smoothbricks/cargo-retain/launch-node';
11
12
  import { nodeLocks } from '@smoothbricks/cargo-retain/locks-node';
12
13
  import { logger, type ProjectGraph, readCachedProjectGraph } from 'nx/src/devkit-exports.js';
13
14
  import type { PostTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
@@ -51,8 +52,12 @@ export function mbxManagesTargets(environment: Readonly<NodeJS.ProcessEnv>): boo
51
52
 
52
53
  /**
53
54
  * After a run that executed a Cargo producer task ({@link CARGO_PRODUCER_METADATA}), check whether
54
- * each Cargo workspace is due for its daily maintenance. A successful receipt schedules only;
55
- * every due pass reads the current graph under Cargo's locks and is awaited by this Nx process.
55
+ * each Cargo workspace is due for its daily maintenance, and start each due pass in a process of its own
56
+ * (`startRetentionPass`). Nx awaits this hook, inside its daemon when one serves the run, so the pass never runs here:
57
+ * its unlinks are synchronous, and one freeing a large trash on a loaded volume held a daemon, and every client waiting
58
+ * on it, for more than thirty minutes. Here only the gate answers (not due, busy, refused); the started pass reads the
59
+ * current graph under Cargo's locks and records its outcome in the target's receipt, and neither this process nor its
60
+ * exit waits on it. A successful receipt schedules only.
56
61
  * Maintenance never fails the run it follows: every outcome, a refused or busy pass included, is only reported. In an
57
62
  * mbx project ({@link mbxManagesTargets}) it does nothing.
58
63
  */
@@ -80,9 +85,9 @@ export async function postTasksExecution(_options: unknown, context: PostTasksEx
80
85
  if (done.some((workspaceRoot) => !relative(workspaceRoot, root).startsWith('..'))) continue;
81
86
  const started = performance.now();
82
87
  const cpu = process.cpuUsage();
83
- let result: Result<RetentionReport, RetentionError>;
88
+ let result: Result<RetentionStart, RetentionError>;
84
89
  try {
85
- result = await retainCargoWorkspace(root, { apply: true, automatic: true, now: Date.now() }, nodeLocks);
90
+ result = await startRetentionPass(root, Date.now(), nodeLocks, launchNodeCli);
86
91
  } catch (error) {
87
92
  // Maintenance never fails the run it follows: say what escaped, then go on to the next workspace.
88
93
  const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
@@ -97,9 +102,10 @@ export async function postTasksExecution(_options: unknown, context: PostTasksEx
97
102
  logger.warn(`Cargo retention for ${root}: ${describeRetentionError(result.error)}`);
98
103
  continue;
99
104
  }
100
- done.push(result.value.workspaceRoot);
101
- const line = describeRetention(result.value);
102
- if (refusedAnywhere(result.value)) logger.warn(line);
105
+ const start = result.value;
106
+ done.push(start.kind === 'answered' ? start.report.workspaceRoot : start.workspaceRoot);
107
+ const line = describeRetentionStart(start);
108
+ if (start.kind === 'answered' && refusedAnywhere(start.report)) logger.warn(line);
103
109
  else logger.info(line);
104
110
  }
105
111
  }
@@ -267,7 +267,7 @@ async function deriveCargoPackageTestInputs(
267
267
  // hashes a `{projectRoot}` glob against only the files its project OWNS, and
268
268
  // a nested Nx project owns the crates under it. A repository-root cargo
269
269
  // workspace whose members live in `packages/*` would then hash none of its
270
- // members' sources, and its archive would cache-hit against edited crates
270
+ // members' sources, and its test build would cache-hit against edited crates
271
271
  // while every per-crate runner reran on the stale binaries.
272
272
  const inputRoot = posix.join('{workspaceRoot}', relative(workspaceRoot, absoluteProjectRoot).split(sep).join('/'));
273
273
  const loadManifest = (path: string): Promise<TomlTable> => {
@@ -578,24 +578,12 @@ function readTestShards(cratePackage: Record<string, unknown>, crateTomlPath: st
578
578
  export const CARGO_TEST_TARGET = 'cargo-test';
579
579
 
580
580
  /**
581
- * The one workspace-wide `cargo nextest archive` every per-crate runner
582
- * executes from. Named here beside the other cargo target names so the policy
583
- * that checks a workspace's test graph and the inference that builds it read
584
- * the same string.
581
+ * The one workspace-wide test build every per-crate runner executes from, in
582
+ * place. Named here beside the other cargo target names so the policy that
583
+ * checks a workspace's test graph and the inference that builds it read the
584
+ * same string.
585
585
  */
586
- export const CARGO_TEST_ARCHIVE_TARGET = 'cargo-test-archive';
587
-
588
- /**
589
- * Where that archive lands, relative to the cargo workspace root — the cwd both
590
- * the archive command and every runner already use. `cargo nextest archive`
591
- * does NOT create this parent directory and fails the whole build when it is
592
- * missing ("error writing to archive ... No such file or directory"), so the
593
- * target mkdir's it first.
594
- * The archive is an Nx-restored output, so it lives on the source volume, never
595
- * beneath Cargo's symlinked target directory (16_build_volumes.md).
596
- */
597
- export const CARGO_TEST_ARCHIVE_FILE = '.cache/nextest/archive.tar.zst';
598
-
586
+ export const CARGO_TEST_BUILD_TARGET = 'cargo-test-build';
599
587
  /**
600
588
  * One foreign target triple this cargo workspace also archives its tests for.
601
589
  */
@@ -717,14 +705,14 @@ export function cargoTestGroupTargetName(group: string): string {
717
705
  * crate collapse back to that crate, so a split crate counts as covered once.
718
706
  *
719
707
  * The workspace-wide `cargo-test-*` targets are not crates: reading them as one
720
- * would invent members named "compile" and "archive", and a serial group's runner
708
+ * would invent a member named "build", and a serial group's runner
721
709
  * would invent one named after its group. Each reports every crate's coverage
722
710
  * against a set that can never match.
723
711
  */
724
712
  export function packageNameFromCargoTestTarget(targetName: string): string | null {
725
713
  if (
726
714
  !targetName.startsWith('cargo-test-') ||
727
- targetName === CARGO_TEST_ARCHIVE_TARGET ||
715
+ targetName === CARGO_TEST_BUILD_TARGET ||
728
716
  targetName.startsWith(CARGO_TEST_GROUP_PREFIX)
729
717
  ) {
730
718
  return null;
@@ -1063,9 +1051,9 @@ export const PLUGIN_NEXTEST_CONFIG_PATH = 'node_modules/@smoothbricks/nx-plugin/
1063
1051
  * The plugin's own nextest settings, as a config layer BENEATH the repository's.
1064
1052
  *
1065
1053
  * `--config-file` replaces `<workspace>/.config/nextest.toml` outright, which
1066
- * made every plugin default unoverridable and — now that per-crate runs execute
1067
- * from an archive — left a repository no way to declare `archive.include` for a
1068
- * cdylib or fixture its tests need. `--tool-config-file` is nextest's mechanism
1054
+ * made every plugin default unoverridable and left a repository no way to
1055
+ * declare a setting of its own, such as the `archive.include` a cross lane needs
1056
+ * for a cdylib or fixture. `--tool-config-file` is nextest's mechanism
1069
1057
  * for exactly this: "lower than --config-file in priority but above the default
1070
1058
  * config shipped with nextest". Measured: with only this layer a 1s
1071
1059
  * slow-timeout terminates a 3s test; adding `.config/nextest.toml` with 10s
@@ -1073,7 +1061,7 @@ export const PLUGIN_NEXTEST_CONFIG_PATH = 'node_modules/@smoothbricks/nx-plugin/
1073
1061
  *
1074
1062
  * The path must be absolute, and an absolute path written into the command text
1075
1063
  * would differ per checkout and split one Nx cache entry per machine. `$PWD`
1076
- * resolves at exec time — both the archive (`nx:run-commands`) and the runners
1064
+ * resolves at exec time — both the test build (`nx:run-commands`) and the runners
1077
1065
  * (`bounded-exec`, which spawns with `shell: true`) go through a shell — so the
1078
1066
  * command text stays identical everywhere. Quoted, because a workspace path may
1079
1067
  * contain spaces.
@@ -242,8 +242,8 @@ export function cargoCrossTestTargetName(triple: string): string {
242
242
  }
243
243
 
244
244
  /**
245
- * One archive file per triple, beside the host-native
246
- * `CARGO_TEST_ARCHIVE_FILE`, relative to the cargo workspace root. Distinct
245
+ * One archive file per triple, relative to the cargo workspace root: the only
246
+ * test archives, since a same-platform run executes `cargo-test-build`'s binaries in place. Distinct
247
247
  * paths are what let both exist: each is a declared Nx output, so a single path
248
248
  * for two triples would let a restored cache serve one machine's binaries under
249
249
  * the other's name.
@@ -38,3 +38,14 @@ export function stageDeploysProject(tags: string[] | undefined, stage: Deploymen
38
38
  if (tags.includes(STAGING_DEPLOY_TAG)) return stage === 'staging';
39
39
  return tags.includes(STAGE_DEPLOY_TAG);
40
40
  }
41
+
42
+ /**
43
+ * The tag a deploy uploads its version under, from the artifact hash it deploys: `nx-` and that hash when it is
44
+ * decimal (Nx's own), or the first 32 digits of a hexadecimal hash of at least 32. `smoo wrangler deploy-stage` tags
45
+ * with it, and the wrangler-deploy hasher compares the stage's live tag with it. Null for any other hash.
46
+ */
47
+ export function deployVersionTag(artifactHash: string): string | null {
48
+ if (/^(?:0|[1-9][0-9]*)$/.test(artifactHash)) return `nx-${artifactHash}`;
49
+ const normalized = artifactHash.toLowerCase();
50
+ return /^[0-9a-f]{32,}$/.test(normalized) ? `nx-${normalized.slice(0, 32)}` : null;
51
+ }
@@ -1,6 +1,9 @@
1
1
  import typia from 'typia';
2
2
 
3
- /** The exact command and sources source-aware ESLint inference retains for cache inspectors. */
3
+ /**
4
+ * What source-aware ESLint inference retains for cache inspectors: the command, which names no file, and the sources
5
+ * the graph that wrote it resolved. The run reads the sources it lints when it starts.
6
+ */
4
7
  export interface EslintFileSet {
5
8
  readonly command: string;
6
9
  readonly files: readonly string[];
@@ -0,0 +1,134 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, isAbsolute, join, posix, relative, sep } from 'node:path';
3
+ import {
4
+ type ParsedCommandLine,
5
+ parseJsonConfigFileContent,
6
+ readConfigFile,
7
+ sys as typescriptSys,
8
+ WatchDirectoryFlags,
9
+ } from 'typescript';
10
+ import { ESLINT_SOURCES_TOKEN } from './executors/all-verdicts/schema.js';
11
+ import { shellWord } from './runtime-input.js';
12
+ import { isNonSourceDirectory } from './source-directories.js';
13
+ import { freshIndexedFiles } from './workspace-index.js';
14
+
15
+ /** The module kinds ESLint is handed. */
16
+ const SOURCE_KINDS = '{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
17
+
18
+ /** Every JavaScript and TypeScript module kind ESLint is handed, as one glob. */
19
+ export const ESLINT_SOURCES_GLOB = `**/*.${SOURCE_KINDS}`;
20
+
21
+ /** TypeScript's code for a declaration that selects no file: a test program of none, not a broken one. */
22
+ const NO_INPUTS_FOUND = 18003;
23
+
24
+ /** What ESLint lints for one project, and the lint inputs that key its verdict beyond the project's own files. */
25
+ export interface EslintSources {
26
+ /** The files ESLint is handed, workspace-relative and sorted. */
27
+ readonly files: readonly string[];
28
+ /**
29
+ * The test declaration, then a glob for each directory its include patterns walk and each other program file by
30
+ * name: a file the program gains later is keyed without the graph naming it.
31
+ */
32
+ readonly inputs: readonly string[];
33
+ }
34
+
35
+ /**
36
+ * Read a tsconfig with this plugin's own TypeScript. `@nx/js`'s readTsConfig does an
37
+ * undeclared `require('typescript')` resolved from its own location: where that lands on the
38
+ * TypeScript 7 native package (whose entry exports only its version), `sys` is undefined and
39
+ * graph construction dies reading `sys.readFile`. The plugin declares TypeScript 6, whose
40
+ * `sys` this uses, so the resolution is the one this package's manifest promises.
41
+ */
42
+ function readTestTsConfig(testConfig: string): ParsedCommandLine {
43
+ const readResult = readConfigFile(testConfig, typescriptSys.readFile);
44
+ return parseJsonConfigFileContent(readResult.config, typescriptSys, dirname(testConfig));
45
+ }
46
+
47
+ /** The workspace-relative POSIX path of `absolute`, or null when it lies outside the workspace. */
48
+ function insideWorkspace(workspaceRoot: string, absolute: string): string | null {
49
+ const path = relative(workspaceRoot, absolute).split(sep).join('/');
50
+ return path === '..' || path.startsWith('../') || isAbsolute(path) ? null : path;
51
+ }
52
+
53
+ /** A directory a test declaration's include patterns walk, workspace-relative ('' is the workspace root). */
54
+ interface WalkedDirectory {
55
+ readonly directory: string;
56
+ readonly recursive: boolean;
57
+ }
58
+
59
+ function walks({ directory, recursive }: WalkedDirectory, path: string): boolean {
60
+ const within = directory === '' ? path : path.startsWith(`${directory}/`) ? path.slice(directory.length + 1) : null;
61
+ return within !== null && (recursive || !within.includes('/'));
62
+ }
63
+
64
+ function walkedInput({ directory, recursive }: WalkedDirectory): string {
65
+ return `{workspaceRoot}/${directory === '' ? '' : `${directory}/`}${recursive ? '**/' : ''}*.${SOURCE_KINDS}`;
66
+ }
67
+
68
+ /**
69
+ * What ESLint lints for `projectRoot`, out of `indexed`, the JavaScript and TypeScript modules of an Nx workspace file
70
+ * index (.gitignore and .nxignore applied): its `src` files, and the files its `tsconfig.test.json` declares wherever
71
+ * they live. Only an indexed module counts: an ignored one is build output a fresh checkout lacks, and a JSON file is
72
+ * not ESLint's. Which index `indexed` comes from is the caller's: the graph's to describe a project, the filesystem's
73
+ * now to run ESLint on it.
74
+ */
75
+ export function eslintSources(workspaceRoot: string, projectRoot: string, indexed: ReadonlySet<string>): EslintSources {
76
+ const files = new Set<string>();
77
+ const sourcePrefix = projectRoot === '.' ? 'src/' : `${posix.normalize(projectRoot)}/src/`;
78
+ for (const path of indexed) {
79
+ if (
80
+ path.startsWith(sourcePrefix) &&
81
+ !path.slice(sourcePrefix.length).split('/').slice(0, -1).some(isNonSourceDirectory)
82
+ ) {
83
+ files.add(path);
84
+ }
85
+ }
86
+ const inputs: string[] = [];
87
+ const testConfig = join(workspaceRoot, projectRoot, 'tsconfig.test.json');
88
+ if (existsSync(testConfig)) {
89
+ // A test program can live anywhere the declaration selects, not just src.
90
+ // Use the compiler's file set and the existing declaration-chain hasher,
91
+ // so inherited includes and files outside this project keep their keys.
92
+ const program = readTestTsConfig(testConfig);
93
+ const errors = program.errors.filter(({ code }) => code !== NO_INPUTS_FOUND);
94
+ if (errors.length > 0) {
95
+ throw new Error(
96
+ `${testConfig}: ${errors.map(({ code, messageText }) => `TS${code}: ${JSON.stringify(messageText)}`).join('; ')}`,
97
+ );
98
+ }
99
+ inputs.push('{projectRoot}/tsconfig.test.json');
100
+ // The directories the include patterns walk are keyed as globs, so a file added to one is keyed the moment it
101
+ // exists, and the compiler's own set of walked directories says which they are.
102
+ const walked: WalkedDirectory[] = [];
103
+ for (const [absolute, flags] of Object.entries(program.wildcardDirectories ?? {})) {
104
+ const directory = insideWorkspace(workspaceRoot, absolute);
105
+ if (directory !== null && !directory.split('/').some(isNonSourceDirectory)) {
106
+ walked.push({ directory, recursive: (flags & WatchDirectoryFlags.Recursive) !== 0 });
107
+ }
108
+ }
109
+ inputs.push(...walked.map(walkedInput).sort());
110
+ const named: string[] = [];
111
+ for (const absolute of program.fileNames) {
112
+ const path = insideWorkspace(workspaceRoot, absolute);
113
+ if (path === null) {
114
+ throw new Error(`${testConfig}: test source ${absolute} is outside the workspace and cannot be hashed`);
115
+ }
116
+ if (!indexed.has(path) || path.split('/').some(isNonSourceDirectory)) continue;
117
+ files.add(path);
118
+ if (!walked.some((entry) => walks(entry, path))) named.push(`{workspaceRoot}/${path}`);
119
+ }
120
+ inputs.push(...named.sort());
121
+ }
122
+ return { files: [...files].sort(), inputs: [...new Set(inputs)] };
123
+ }
124
+
125
+ /** What ESLint lints for `projectRoot` as the filesystem holds it now, through a fresh workspace file index. */
126
+ export function freshEslintSources(workspaceRoot: string, projectRoot: string): EslintSources {
127
+ return eslintSources(workspaceRoot, projectRoot, new Set(freshIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB])));
128
+ }
129
+
130
+ /** `command` with each {@link ESLINT_SOURCES_TOKEN} replaced by the shell words of `files`. */
131
+ export function expandEslintSources(command: string, files: readonly string[]): string {
132
+ const words = files.map((file) => shellWord(file)).join(' ');
133
+ return command.replaceAll(ESLINT_SOURCES_TOKEN, () => words);
134
+ }