@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.
Files changed (124) hide show
  1. package/README.md +203 -83
  2. package/dist/bounded-test-policy.d.ts +10 -3
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +19 -25
  5. package/dist/cargo-closure-input.d.ts +12 -0
  6. package/dist/cargo-closure-input.d.ts.map +1 -1
  7. package/dist/cargo-closure-input.js +29 -7
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +42 -19
  10. package/dist/ensure-built-receipt.d.ts +34 -6
  11. package/dist/ensure-built-receipt.d.ts.map +1 -1
  12. package/dist/ensure-built-receipt.js +265 -159
  13. package/dist/ensure-built-witness.d.ts +27 -2
  14. package/dist/ensure-built-witness.d.ts.map +1 -1
  15. package/dist/ensure-built-witness.js +2176 -15
  16. package/dist/ensure-built.d.ts +99 -1
  17. package/dist/ensure-built.d.ts.map +1 -1
  18. package/dist/ensure-built.js +34 -53
  19. package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
  20. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/cpu-pool.js +43 -19
  22. package/dist/executors/bounded-exec/executor.d.ts +11 -2
  23. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/executor.js +139 -39
  25. package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
  26. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/ram-temp.js +27 -13
  28. package/dist/generators/bun-test-tracing/generator.js +2 -2
  29. package/dist/graph-input-contract.d.ts +98 -0
  30. package/dist/graph-input-contract.d.ts.map +1 -0
  31. package/dist/graph-input-contract.js +624 -0
  32. package/dist/index.d.ts +12 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +17 -3
  35. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  36. package/dist/managed-files/ci-workflow.js +5 -2
  37. package/dist/managed-files/publish-workflow.d.ts +11 -1
  38. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  39. package/dist/producer-receipts.d.ts +19 -0
  40. package/dist/producer-receipts.d.ts.map +1 -0
  41. package/dist/producer-receipts.js +921 -0
  42. package/dist/testing.d.ts +8 -0
  43. package/dist/testing.d.ts.map +1 -1
  44. package/dist/testing.js +58 -0
  45. package/managed/raw/patches/nx@23.2.1.patch +328 -50
  46. package/managed/raw/tooling/direnv/developer-links.ts +147 -21
  47. package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
  48. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
  49. package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
  50. package/managed/raw/tooling/direnv/repo-path +15 -2
  51. package/managed/raw/tooling/direnv/setup-environment.ts +179 -114
  52. package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
  53. package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
  54. package/nextest.toml +1 -1
  55. package/package.json +11 -6
  56. package/src/__tests__/fixture-nx-env.ts +7 -0
  57. package/src/__tests__/owned-installation.ts +174 -0
  58. package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
  59. package/src/bounded-test-policy.test.ts +36 -22
  60. package/src/bounded-test-policy.ts +19 -27
  61. package/src/bun-bootstrap.test.ts +1 -1
  62. package/src/cargo-closure-input.test.ts +60 -11
  63. package/src/cargo-closure-input.ts +28 -6
  64. package/src/cargo-resolve-cache.test.ts +140 -25
  65. package/src/cargo-source-hash.test.ts +78 -3
  66. package/src/cargo-source-hash.ts +48 -30
  67. package/src/cross-check-policy.test.ts +2 -2
  68. package/src/ensure-built-receipt.test.ts +111 -16
  69. package/src/ensure-built-receipt.ts +251 -149
  70. package/src/ensure-built-witness.test.ts +197 -13
  71. package/src/ensure-built-witness.ts +187 -15
  72. package/src/ensure-built.test.ts +156 -102
  73. package/src/ensure-built.ts +114 -64
  74. package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
  75. package/src/executors/bounded-exec/cpu-pool.ts +55 -17
  76. package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
  77. package/src/executors/bounded-exec/executor-host.test.ts +51 -41
  78. package/src/executors/bounded-exec/executor.test.ts +155 -35
  79. package/src/executors/bounded-exec/executor.ts +156 -45
  80. package/src/executors/bounded-exec/progress.test.ts +1 -1
  81. package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
  82. package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
  83. package/src/executors/bounded-exec/ram-temp.ts +32 -16
  84. package/src/executors/bounded-exec/verdict.test.ts +17 -12
  85. package/src/generators/bounded-test-targets/generator.test.ts +1 -3
  86. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  87. package/src/generators/bun-test-tracing/generator.ts +2 -2
  88. package/src/graph-input-contract.test.ts +371 -0
  89. package/src/graph-input-contract.ts +605 -0
  90. package/src/index.test.ts +3 -3
  91. package/src/index.ts +24 -3
  92. package/src/linked-snapshots.nx.test.ts +112 -30
  93. package/src/managed-files/ci-workflow.ts +5 -2
  94. package/src/managed-files/publish-workflow.ts +12 -1
  95. package/src/managed-files/repo-path.test.ts +44 -1
  96. package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
  97. package/src/nextest-code-bound.test.ts +23 -17
  98. package/src/nextest-partitions.test.ts +7 -1
  99. package/src/nx-cache-restore-mtime.test.ts +2 -2
  100. package/src/nx-daemon-claim.test.ts +5 -5
  101. package/src/nx-daemon-idle-cpu.test.ts +0 -1
  102. package/src/nx-daemon-idle-policy.test.ts +56 -0
  103. package/src/nx-daemon-ignore-files.test.ts +2 -2
  104. package/src/nx-daemon-validity.test.ts +31 -9
  105. package/src/nx-dot-input-policy.test.ts +5 -5
  106. package/src/nx-files-archive-racy.test.ts +1 -1
  107. package/src/nx-incomplete-run-summary.test.ts +1 -1
  108. package/src/nx-plugin-load-errors.test.ts +2 -2
  109. package/src/nx-project-graph-errors.test.ts +70 -0
  110. package/src/nx-skipped-task-exit.test.ts +2 -2
  111. package/src/nx-store-resolution.test.ts +7 -25
  112. package/src/nx-task-output-lease.test.ts +3 -3
  113. package/src/nx-use-local.test.ts +7 -5
  114. package/src/producer-receipts.test.ts +164 -0
  115. package/src/producer-receipts.ts +631 -0
  116. package/src/runtime-input.test.ts +1 -1
  117. package/src/serial-group-wiring.test.ts +4 -4
  118. package/src/task-results.test.ts +18 -16
  119. package/src/test-timings.test.ts +2 -2
  120. package/src/testing.test.ts +5 -5
  121. package/src/testing.ts +59 -0
  122. package/src/typecheck-test-policy.test.ts +1 -1
  123. package/src/typescript-resolution.test.ts +76 -0
  124. package/test-timings.json +5 -0
@@ -0,0 +1,164 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { createHash } from 'node:crypto';
3
+ import { mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import type { Task, TaskGraph } from 'nx/src/config/task-graph';
8
+ import type { TaskResults } from 'nx/src/tasks-runner/life-cycle';
9
+ import type { EnsureBuiltProducerReceipt } from './ensure-built.js';
10
+ import {
11
+ completedProducerTasks,
12
+ postTasksExecution,
13
+ preTasksExecution,
14
+ producerEnvironmentIdentity,
15
+ readProducerReceipt,
16
+ } from './producer-receipts.js';
17
+
18
+ const repoRoot = dirname(dirname(dirname(dirname(fileURLToPath(import.meta.url)))));
19
+
20
+ const task: Task = {
21
+ id: 'app:build',
22
+ target: { project: 'app', target: 'build' },
23
+ overrides: {},
24
+ outputs: ['dist'],
25
+ cache: false,
26
+ hash: 'actual-nx-hash',
27
+ hashDetails: { command: 'actual-command', nodes: { source: 'actual-source-identity' } },
28
+ };
29
+ const graph: TaskGraph = {
30
+ roots: [task.id],
31
+ tasks: { [task.id]: task },
32
+ dependencies: { [task.id]: [] },
33
+ continuousDependencies: {},
34
+ };
35
+ const inputs: EnsureBuiltProducerReceipt['inputs'] = [
36
+ {
37
+ taskId: task.id,
38
+ overrides: {},
39
+ declared: [],
40
+ expanded: {
41
+ files: [],
42
+ runtime: ['declared-version-recipe'],
43
+ environment: ['DECLARED_ENV'],
44
+ depOutputs: [],
45
+ external: [],
46
+ },
47
+ hashDetails: { command: 'actual-command', nodes: { 'env:DECLARED_ENV': 'producer-value-hash' } },
48
+ files: [],
49
+ },
50
+ ];
51
+
52
+ describe('actual producer completion evidence', () => {
53
+ it('accepts successful uncacheable prerequisites without looking for cache rows', () => {
54
+ const results: TaskResults = { [task.id]: { task, status: 'success', code: 0 } };
55
+ expect(completedProducerTasks(graph, results)).toEqual({ ok: true, value: [task] });
56
+ });
57
+ it('accepts actual Nx successful cache completion statuses, not invented hit receipts', () => {
58
+ const statuses: readonly TaskResults[string]['status'][] = [
59
+ 'local-cache',
60
+ 'local-cache-kept-existing',
61
+ 'remote-cache',
62
+ ];
63
+ for (const status of statuses) {
64
+ const cached: Task = { ...task, cache: true };
65
+ expect(
66
+ completedProducerTasks(
67
+ { ...graph, tasks: { [task.id]: cached } },
68
+ { [task.id]: { task: cached, status, code: 0 } },
69
+ ).ok,
70
+ ).toBe(true);
71
+ }
72
+ });
73
+ it('refuses missing, failed, stopped and skipped completion evidence', () => {
74
+ expect(completedProducerTasks(graph, {}).ok).toBe(false);
75
+ const statuses: readonly TaskResults[string]['status'][] = ['failure', 'stopped', 'skipped'];
76
+ for (const status of statuses)
77
+ expect(completedProducerTasks(graph, { [task.id]: { task, status, code: 0 } }).ok).toBe(false);
78
+ expect(completedProducerTasks(graph, { [task.id]: { task, status: 'success', code: 1 } }).ok).toBe(false);
79
+ });
80
+ it('refuses absent actual hash details, override changes, output changes and configuration changes', () => {
81
+ for (const changed of [
82
+ { ...task, hash: undefined },
83
+ { ...task, hashDetails: undefined },
84
+ { ...task, overrides: { configuration: 'other' } },
85
+ { ...task, outputs: ['different'] },
86
+ { ...task, target: { ...task.target, configuration: 'other' } },
87
+ ]) {
88
+ expect(completedProducerTasks(graph, { [task.id]: { task: changed, status: 'success', code: 0 } }).ok).toBe(
89
+ false,
90
+ );
91
+ }
92
+ });
93
+ it('labels producer Nx runtime/environment identity without reading a consumer environment', () => {
94
+ const identity = producerEnvironmentIdentity(inputs);
95
+ const saved = process.env.DECLARED_ENV;
96
+ process.env.DECLARED_ENV = 'different-consumer-value';
97
+ try {
98
+ expect(producerEnvironmentIdentity(inputs)).toBe(identity);
99
+ } finally {
100
+ if (saved === undefined) delete process.env.DECLARED_ENV;
101
+ else process.env.DECLARED_ENV = saved;
102
+ }
103
+ expect(
104
+ producerEnvironmentIdentity(
105
+ inputs.map((input) => ({
106
+ ...input,
107
+ hashDetails: { ...input.hashDetails, nodes: { 'env:DECLARED_ENV': 'different-actual-producer-hash' } },
108
+ })),
109
+ ),
110
+ ).not.toBe(identity);
111
+ });
112
+ it('disabled producer hooks perform no source, graph or publication work', async () => {
113
+ const context = { id: 'disabled-hook', workspaceRoot: '/not-a-workspace', nxJsonConfiguration: {}, argv: [] };
114
+ await preTasksExecution(undefined, context);
115
+ await postTasksExecution(undefined, { ...context, taskResults: {}, startTime: 10, endTime: 20 });
116
+ });
117
+ it('publishes a refusal beside a published receipt, never over it, and names it in the miss', async () => {
118
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'producer-refusal-')));
119
+ const inherited = process.env.NX_WORKSPACE_DATA_DIRECTORY;
120
+ delete process.env.NX_WORKSPACE_DATA_DIRECTORY;
121
+ try {
122
+ await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'refusal-fixture' }));
123
+ await writeFile(join(root, 'nx.json'), '{}');
124
+ await symlink(join(repoRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
125
+ const data = join(root, '.nx', 'workspace-data');
126
+ await mkdir(data, { recursive: true });
127
+ const name = createHash('sha256').update(JSON.stringify(task.id)).digest('hex');
128
+ const receiptPath = join(data, `producer-receipt-${name}.json`);
129
+ // What an earlier run published; this run's refusal is no evidence about it.
130
+ const published = JSON.stringify({ version: 1, disposition: 'published', receipt: 'an earlier run' });
131
+ await writeFile(receiptPath, published);
132
+ // A run whose pre-execution frame never bound (the sandboxed git failure's shape) refuses its target.
133
+ await postTasksExecution(
134
+ { producerReceipts: { targets: [task.id] } },
135
+ {
136
+ id: 'unbound-frame',
137
+ workspaceRoot: root,
138
+ nxJsonConfiguration: {},
139
+ argv: [],
140
+ taskResults: { [task.id]: { task, status: 'success', code: 0 } },
141
+ startTime: 10,
142
+ endTime: 20,
143
+ },
144
+ );
145
+ expect(await readFile(receiptPath, 'utf8')).toBe(published);
146
+ expect((await readdir(data)).sort()).toEqual([`producer-receipt-${name}.json`, `producer-refusal-${name}.json`]);
147
+ expect(readProducerReceipt(root, task.id)).toEqual({
148
+ ok: false,
149
+ detail:
150
+ "Missing/corrupt producer completion contract; the producer's latest run refused: No bound producer pre-execution frame",
151
+ });
152
+ // With no receipt at all, the miss still says why the latest run published none.
153
+ await rm(receiptPath);
154
+ const missing = readProducerReceipt(root, task.id);
155
+ expect(missing.ok ? 'hit' : missing.detail).toEndWith(
156
+ "; the producer's latest run refused: No bound producer pre-execution frame",
157
+ );
158
+ } finally {
159
+ if (inherited === undefined) delete process.env.NX_WORKSPACE_DATA_DIRECTORY;
160
+ else process.env.NX_WORKSPACE_DATA_DIRECTORY = inherited;
161
+ await rm(root, { recursive: true, force: true });
162
+ }
163
+ });
164
+ });