@friggframework/devtools 2.0.0--canary.731.1c0b281.0 → 2.0.0--canary.730.f2ba24a.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.
- package/infrastructure/README.md +5 -32
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -3
- package/infrastructure/__tests__/postgres-config.test.js +0 -3
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -3
- package/infrastructure/__tests__/scoped-environment.test.js +0 -3
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
- package/infrastructure/__tests__/template-generation.test.js +0 -3
- package/infrastructure/app-definition-schema-contract.test.js +0 -5
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +6 -22
- package/infrastructure/domains/database/migration-builder.js +2 -21
- package/infrastructure/domains/database/migration-builder.test.js +6 -61
- package/infrastructure/domains/integration/integration-builder.js +0 -2
- package/infrastructure/domains/integration/integration-builder.test.js +6 -22
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -13
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +4 -51
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
- package/infrastructure/infrastructure-composer.js +1 -12
- package/infrastructure/infrastructure-composer.test.js +0 -71
- package/infrastructure/scripts/build-prisma-layer.js +50 -136
- package/infrastructure/scripts/build-prisma-layer.test.js +0 -100
- package/package.json +7 -7
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
- package/infrastructure/domains/database/migration-engines.js +0 -93
- package/infrastructure/domains/database/migration-engines.test.js +0 -142
- package/infrastructure/domains/shared/lambda-architectures.js +0 -113
- package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
|
@@ -8,20 +8,13 @@ const {
|
|
|
8
8
|
nestedNodeModulesExcludes,
|
|
9
9
|
} = require('./nested-node-modules');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
it('excludes every nested node_modules by default', () => {
|
|
13
|
-
expect(nestedNodeModulesExcludes({}, true)).toEqual([
|
|
14
|
-
'node_modules/**/node_modules/**',
|
|
15
|
-
]);
|
|
16
|
-
expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
|
|
17
|
-
});
|
|
11
|
+
const OPT_OUT = { lambda: { keepNestedNodeModules: false } };
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const excludes = nestedNodeModulesExcludes(appDefinition, true);
|
|
13
|
+
describe('nestedNodeModulesExcludes', () => {
|
|
14
|
+
it('keeps nested node_modules by default, except Frigg, AWS SDK and Prisma copies', () => {
|
|
15
|
+
const excludes = nestedNodeModulesExcludes({}, true);
|
|
23
16
|
|
|
24
|
-
expect(excludes).not.toContain(
|
|
17
|
+
expect(excludes).not.toContain(ALL_NESTED_NODE_MODULES);
|
|
25
18
|
expect(excludes).toEqual([
|
|
26
19
|
'node_modules/**/node_modules/@friggframework/**',
|
|
27
20
|
'node_modules/**/node_modules/aws-sdk/**',
|
|
@@ -32,30 +25,31 @@ describe('nestedNodeModulesExcludes', () => {
|
|
|
32
25
|
});
|
|
33
26
|
|
|
34
27
|
it('keeps nested Prisma copies when the app bundles Prisma instead of using the layer', () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const excludes = nestedNodeModulesExcludes(appDefinition, false);
|
|
38
|
-
|
|
39
|
-
expect(excludes).toEqual([
|
|
28
|
+
expect(nestedNodeModulesExcludes({}, false)).toEqual([
|
|
40
29
|
'node_modules/**/node_modules/@friggframework/**',
|
|
41
30
|
'node_modules/**/node_modules/aws-sdk/**',
|
|
42
31
|
'node_modules/**/node_modules/@aws-sdk/**',
|
|
43
32
|
]);
|
|
44
33
|
});
|
|
34
|
+
|
|
35
|
+
it('excludes every nested node_modules when the app opts out', () => {
|
|
36
|
+
expect(nestedNodeModulesExcludes(OPT_OUT, true)).toEqual([
|
|
37
|
+
'node_modules/**/node_modules/**',
|
|
38
|
+
]);
|
|
39
|
+
expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**');
|
|
40
|
+
});
|
|
45
41
|
});
|
|
46
42
|
|
|
47
43
|
describe('keepsNestedNodeModules', () => {
|
|
48
|
-
it('is only
|
|
49
|
-
expect(
|
|
50
|
-
keepsNestedNodeModules({ lambda: { keepNestedNodeModules: true } })
|
|
51
|
-
).toBe(true);
|
|
44
|
+
it('is only disabled by the boolean false', () => {
|
|
45
|
+
expect(keepsNestedNodeModules(OPT_OUT)).toBe(false);
|
|
52
46
|
expect(
|
|
53
47
|
keepsNestedNodeModules({
|
|
54
|
-
lambda: { keepNestedNodeModules:
|
|
48
|
+
lambda: { keepNestedNodeModules: true },
|
|
55
49
|
})
|
|
56
|
-
).toBe(
|
|
57
|
-
expect(keepsNestedNodeModules({ lambda: {} })).toBe(
|
|
58
|
-
expect(keepsNestedNodeModules({})).toBe(
|
|
59
|
-
expect(keepsNestedNodeModules()).toBe(
|
|
50
|
+
).toBe(true);
|
|
51
|
+
expect(keepsNestedNodeModules({ lambda: {} })).toBe(true);
|
|
52
|
+
expect(keepsNestedNodeModules({})).toBe(true);
|
|
53
|
+
expect(keepsNestedNodeModules()).toBe(true);
|
|
60
54
|
});
|
|
61
55
|
});
|
|
@@ -9,11 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const fs = require('fs');
|
|
12
|
-
const {
|
|
13
|
-
buildPrismaLayer,
|
|
14
|
-
layerBuildInputs,
|
|
15
|
-
} = require('../../../scripts/build-prisma-layer');
|
|
16
|
-
const { resolveLambdaArchitecture } = require('../lambda-architectures');
|
|
12
|
+
const { buildPrismaLayer } = require('../../../scripts/build-prisma-layer');
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Check if a process is still running
|
|
@@ -30,48 +26,6 @@ function isProcessRunning(pid) {
|
|
|
30
26
|
}
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
const LEGACY_MARKER_TARGET = 'rhel-openssl-3.0.x';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The inputs a completion marker records. A marker written before the
|
|
37
|
-
* marker became JSON recorded nothing, and every layer then held the rhel
|
|
38
|
-
* engine; its versions are unknown, so it never matches and the layer is
|
|
39
|
-
* rebuilt once.
|
|
40
|
-
* @param {string} markerText
|
|
41
|
-
* @returns {{ prismaBinaryTarget: string, clientPackages: string[]|null, coreVersion: string|null, prismaClientVersion: string|null }}
|
|
42
|
-
*/
|
|
43
|
-
function parseLayerMarker(markerText) {
|
|
44
|
-
try {
|
|
45
|
-
const marker = JSON.parse(markerText);
|
|
46
|
-
return {
|
|
47
|
-
prismaBinaryTarget: marker.prismaBinaryTarget,
|
|
48
|
-
clientPackages: marker.clientPackages,
|
|
49
|
-
coreVersion: marker.coreVersion,
|
|
50
|
-
prismaClientVersion: marker.prismaClientVersion,
|
|
51
|
-
};
|
|
52
|
-
} catch {
|
|
53
|
-
// A marker written before the JSON format is plain text: treat it as a legacy build
|
|
54
|
-
return {
|
|
55
|
-
prismaBinaryTarget: LEGACY_MARKER_TARGET,
|
|
56
|
-
clientPackages: null,
|
|
57
|
-
coreVersion: null,
|
|
58
|
-
prismaClientVersion: null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function sameLayerInputs(a, b) {
|
|
64
|
-
return (
|
|
65
|
-
a.prismaBinaryTarget === b.prismaBinaryTarget &&
|
|
66
|
-
a.coreVersion === b.coreVersion &&
|
|
67
|
-
a.prismaClientVersion === b.prismaClientVersion &&
|
|
68
|
-
Array.isArray(a.clientPackages) &&
|
|
69
|
-
Array.isArray(b.clientPackages) &&
|
|
70
|
-
a.clientPackages.length === b.clientPackages.length &&
|
|
71
|
-
a.clientPackages.every((pkg, i) => pkg === b.clientPackages[i])
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
29
|
/**
|
|
76
30
|
* Ensure Prisma Lambda Layer exists
|
|
77
31
|
*
|
|
@@ -80,38 +34,23 @@ function sameLayerInputs(a, b) {
|
|
|
80
34
|
* Prisma CLI is bundled separately in the dbMigrate function.
|
|
81
35
|
*
|
|
82
36
|
* Domain Concept: Build Completion State & Process Locking
|
|
83
|
-
* - Uses .build-complete marker file to track successful builds
|
|
84
|
-
* the inputs the layer was built from, and a built layer is reused only
|
|
85
|
-
* when they match the requested ones
|
|
37
|
+
* - Uses .build-complete marker file to track successful builds
|
|
86
38
|
* - Uses .build-lock PID file to prevent concurrent builds
|
|
87
39
|
* - Waits for active builds to complete before starting new one
|
|
88
40
|
* - Cleans stale locks and incomplete builds before retry
|
|
89
41
|
*
|
|
90
|
-
* @param {Object}
|
|
91
|
-
* @param {Object} options.databaseConfig - Database configuration from app definition
|
|
92
|
-
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
42
|
+
* @param {Object} databaseConfig - Database configuration from app definition
|
|
93
43
|
* @returns {Promise<void>}
|
|
94
44
|
* @throws {Error} If layer build fails
|
|
95
45
|
*/
|
|
96
|
-
async function ensurePrismaLayerExists({
|
|
97
|
-
databaseConfig = {},
|
|
98
|
-
prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
|
|
99
|
-
} = {}) {
|
|
46
|
+
async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
100
47
|
const projectRoot = process.cwd();
|
|
101
48
|
const layerPath = path.join(projectRoot, 'layers/prisma');
|
|
102
49
|
const completionMarkerPath = path.join(layerPath, '.build-complete');
|
|
103
50
|
const lockFilePath = path.join(layerPath, '.build-lock');
|
|
104
|
-
const inputs = layerBuildInputs({ databaseConfig, prismaBinaryTarget });
|
|
105
|
-
|
|
106
|
-
const builtLayerMatches = () =>
|
|
107
|
-
fs.existsSync(completionMarkerPath) &&
|
|
108
|
-
sameLayerInputs(
|
|
109
|
-
parseLayerMarker(fs.readFileSync(completionMarkerPath, 'utf-8')),
|
|
110
|
-
inputs
|
|
111
|
-
);
|
|
112
51
|
|
|
113
52
|
// Check if build is complete (marker exists)
|
|
114
|
-
if (
|
|
53
|
+
if (fs.existsSync(completionMarkerPath)) {
|
|
115
54
|
console.log('✓ Prisma Lambda Layer already exists at', layerPath);
|
|
116
55
|
return;
|
|
117
56
|
}
|
|
@@ -129,13 +68,8 @@ async function ensurePrismaLayerExists({
|
|
|
129
68
|
|
|
130
69
|
// Check if build completed
|
|
131
70
|
if (fs.existsSync(completionMarkerPath)) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
console.log('⚠ Concurrent build completed for other inputs - rebuilding');
|
|
137
|
-
fs.rmSync(lockFilePath, { force: true });
|
|
138
|
-
break;
|
|
71
|
+
console.log('✓ Concurrent build completed successfully');
|
|
72
|
+
return;
|
|
139
73
|
}
|
|
140
74
|
|
|
141
75
|
// Check if process died
|
|
@@ -147,16 +81,14 @@ async function ensurePrismaLayerExists({
|
|
|
147
81
|
}
|
|
148
82
|
|
|
149
83
|
// Timeout - check one final time
|
|
150
|
-
if (
|
|
84
|
+
if (fs.existsSync(completionMarkerPath)) {
|
|
151
85
|
console.log('✓ Concurrent build completed');
|
|
152
86
|
return;
|
|
153
87
|
}
|
|
154
88
|
|
|
155
89
|
// Still locked after 60s - remove stale lock
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
fs.rmSync(lockFilePath, { force: true });
|
|
159
|
-
}
|
|
90
|
+
console.log('⚠ Build timeout - removing stale lock and rebuilding');
|
|
91
|
+
fs.rmSync(lockFilePath, { force: true });
|
|
160
92
|
} else {
|
|
161
93
|
// Stale lock file (process not running)
|
|
162
94
|
console.log(`⚠ Stale lock file detected (PID ${lockPid} not running) - cleaning up`);
|
|
@@ -167,8 +99,6 @@ async function ensurePrismaLayerExists({
|
|
|
167
99
|
// Check if incomplete build exists (directory without marker)
|
|
168
100
|
if (fs.existsSync(layerPath) && !fs.existsSync(completionMarkerPath)) {
|
|
169
101
|
console.log('⚠ Incomplete Prisma layer detected - will be cleaned by buildPrismaLayer()');
|
|
170
|
-
} else if (fs.existsSync(completionMarkerPath)) {
|
|
171
|
-
console.log(`⚠ Built Prisma layer does not match ${JSON.stringify(inputs)} - rebuilding`);
|
|
172
102
|
}
|
|
173
103
|
|
|
174
104
|
// Build layer
|
|
@@ -189,21 +119,12 @@ async function ensurePrismaLayerExists({
|
|
|
189
119
|
|
|
190
120
|
try {
|
|
191
121
|
// Build layer WITHOUT CLI (runtime only for minimal size)
|
|
192
|
-
await buildPrismaLayer(
|
|
122
|
+
await buildPrismaLayer(databaseConfig);
|
|
193
123
|
|
|
194
124
|
// Create completion marker
|
|
195
125
|
fs.writeFileSync(
|
|
196
126
|
completionMarkerPath,
|
|
197
|
-
|
|
198
|
-
{
|
|
199
|
-
...inputs,
|
|
200
|
-
builtAt: new Date().toISOString(),
|
|
201
|
-
node: process.version,
|
|
202
|
-
platform: process.platform,
|
|
203
|
-
},
|
|
204
|
-
null,
|
|
205
|
-
2
|
|
206
|
-
)
|
|
127
|
+
`Build completed: ${new Date().toISOString()}\nNode: ${process.version}\nPlatform: ${process.platform}\n`
|
|
207
128
|
);
|
|
208
129
|
|
|
209
130
|
console.log('✓ Prisma Lambda Layer built successfully (~10-15MB)\n');
|
|
@@ -234,6 +155,5 @@ async function ensurePrismaLayerExists({
|
|
|
234
155
|
|
|
235
156
|
module.exports = {
|
|
236
157
|
ensurePrismaLayerExists,
|
|
237
|
-
parseLayerMarker,
|
|
238
158
|
};
|
|
239
159
|
|
|
@@ -12,19 +12,9 @@ const { ensurePrismaLayerExists } = require('./prisma-layer-manager');
|
|
|
12
12
|
jest.mock('fs');
|
|
13
13
|
jest.mock('../../../scripts/build-prisma-layer', () => ({
|
|
14
14
|
buildPrismaLayer: jest.fn(),
|
|
15
|
-
layerBuildInputs: jest.fn(),
|
|
16
15
|
}));
|
|
17
16
|
|
|
18
|
-
const { buildPrismaLayer
|
|
19
|
-
|
|
20
|
-
const inputsFor = ({ prismaBinaryTarget = 'rhel-openssl-3.0.x' } = {}) => ({
|
|
21
|
-
prismaBinaryTarget,
|
|
22
|
-
clientPackages: ['generated/prisma-postgresql'],
|
|
23
|
-
coreVersion: '2.0.0-next.120',
|
|
24
|
-
prismaClientVersion: '6.19.3',
|
|
25
|
-
});
|
|
26
|
-
const markerFor = (overrides = {}) =>
|
|
27
|
-
JSON.stringify({ ...inputsFor(), ...overrides });
|
|
17
|
+
const { buildPrismaLayer } = require('../../../scripts/build-prisma-layer');
|
|
28
18
|
|
|
29
19
|
// Helper to mock fs methods for different scenarios
|
|
30
20
|
const mockFs = {
|
|
@@ -60,8 +50,6 @@ describe('Prisma Layer Manager', () => {
|
|
|
60
50
|
originalCwd = process.cwd;
|
|
61
51
|
process.cwd = jest.fn().mockReturnValue('/project');
|
|
62
52
|
jest.clearAllMocks();
|
|
63
|
-
layerBuildInputs.mockImplementation(inputsFor);
|
|
64
|
-
fs.readFileSync = jest.fn((p) => (p.endsWith('.build-lock') ? '99999' : markerFor()));
|
|
65
53
|
});
|
|
66
54
|
|
|
67
55
|
afterEach(() => {
|
|
@@ -99,27 +87,9 @@ describe('Prisma Layer Manager', () => {
|
|
|
99
87
|
postgres: { enable: true },
|
|
100
88
|
};
|
|
101
89
|
|
|
102
|
-
await ensurePrismaLayerExists(
|
|
103
|
-
|
|
104
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
105
|
-
databaseConfig,
|
|
106
|
-
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should pass the Prisma binary target of the deployed architecture to buildPrismaLayer', async () => {
|
|
111
|
-
fs.existsSync = jest.fn().mockReturnValue(false);
|
|
112
|
-
buildPrismaLayer.mockResolvedValue();
|
|
113
|
-
|
|
114
|
-
await ensurePrismaLayerExists({
|
|
115
|
-
databaseConfig: {},
|
|
116
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
117
|
-
});
|
|
90
|
+
await ensurePrismaLayerExists(databaseConfig);
|
|
118
91
|
|
|
119
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith(
|
|
120
|
-
databaseConfig: {},
|
|
121
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
122
|
-
});
|
|
92
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith(databaseConfig);
|
|
123
93
|
});
|
|
124
94
|
|
|
125
95
|
it('should handle build errors and rethrow', async () => {
|
|
@@ -135,10 +105,7 @@ describe('Prisma Layer Manager', () => {
|
|
|
135
105
|
|
|
136
106
|
await ensurePrismaLayerExists();
|
|
137
107
|
|
|
138
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
139
|
-
databaseConfig: {},
|
|
140
|
-
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
141
|
-
});
|
|
108
|
+
expect(buildPrismaLayer).toHaveBeenCalledWith({});
|
|
142
109
|
});
|
|
143
110
|
|
|
144
111
|
it('should use correct layer path relative to project root', async () => {
|
|
@@ -156,7 +123,6 @@ describe('Prisma Layer Manager', () => {
|
|
|
156
123
|
|
|
157
124
|
it('should log success when layer already exists', async () => {
|
|
158
125
|
fs.existsSync = jest.fn().mockReturnValue(true);
|
|
159
|
-
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
160
126
|
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
161
127
|
|
|
162
128
|
await ensurePrismaLayerExists();
|
|
@@ -203,120 +169,6 @@ describe('Prisma Layer Manager', () => {
|
|
|
203
169
|
consoleErrorSpy.mockRestore();
|
|
204
170
|
});
|
|
205
171
|
|
|
206
|
-
describe('layer cache keyed by its inputs', () => {
|
|
207
|
-
const existingMarker = () => {
|
|
208
|
-
fs.existsSync = jest.fn((p) => p.endsWith('.build-complete') || p.endsWith('layers/prisma'));
|
|
209
|
-
fs.writeFileSync = jest.fn();
|
|
210
|
-
fs.rmSync = jest.fn();
|
|
211
|
-
buildPrismaLayer.mockResolvedValue();
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
it('reuses the layer when the marker records the same target, clients and versions', async () => {
|
|
215
|
-
existingMarker();
|
|
216
|
-
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
217
|
-
|
|
218
|
-
await ensurePrismaLayerExists({ prismaBinaryTarget: 'rhel-openssl-3.0.x' });
|
|
219
|
-
|
|
220
|
-
expect(buildPrismaLayer).not.toHaveBeenCalled();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('rebuilds when the deployed architecture changes the target', async () => {
|
|
224
|
-
existingMarker();
|
|
225
|
-
fs.readFileSync = jest.fn().mockReturnValue(markerFor());
|
|
226
|
-
|
|
227
|
-
await ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
228
|
-
|
|
229
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
230
|
-
databaseConfig: {},
|
|
231
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('rebuilds when the installed core version changes', async () => {
|
|
236
|
-
existingMarker();
|
|
237
|
-
fs.readFileSync = jest.fn().mockReturnValue(markerFor({ coreVersion: '2.0.0-next.105' }));
|
|
238
|
-
|
|
239
|
-
await ensurePrismaLayerExists();
|
|
240
|
-
|
|
241
|
-
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('rebuilds when the client set changes', async () => {
|
|
245
|
-
existingMarker();
|
|
246
|
-
fs.readFileSync = jest.fn().mockReturnValue(
|
|
247
|
-
markerFor({ clientPackages: ['generated/prisma-postgresql', 'generated/prisma-mongodb'] })
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
await ensurePrismaLayerExists();
|
|
251
|
-
|
|
252
|
-
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('rebuilds over a legacy plain-text marker, which records no target or versions', async () => {
|
|
256
|
-
existingMarker();
|
|
257
|
-
fs.readFileSync = jest.fn().mockReturnValue(
|
|
258
|
-
'Build completed: 2026-01-01T00:00:00.000Z\nNode: v22.0.0\nPlatform: darwin\n'
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
await ensurePrismaLayerExists();
|
|
262
|
-
|
|
263
|
-
expect(buildPrismaLayer).toHaveBeenCalledTimes(1);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('writes the inputs into the marker after a build', async () => {
|
|
267
|
-
mockFs.noBuild();
|
|
268
|
-
buildPrismaLayer.mockResolvedValue();
|
|
269
|
-
|
|
270
|
-
await ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
271
|
-
|
|
272
|
-
const [, written] = fs.writeFileSync.mock.calls.find(
|
|
273
|
-
([p]) => p === '/project/layers/prisma/.build-complete'
|
|
274
|
-
);
|
|
275
|
-
expect(JSON.parse(written)).toEqual(
|
|
276
|
-
expect.objectContaining(inputsFor({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' }))
|
|
277
|
-
);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('rebuilds after waiting on a concurrent build that finished for the other target', async () => {
|
|
281
|
-
jest.useFakeTimers();
|
|
282
|
-
let completionMarkerExists = false;
|
|
283
|
-
fs.existsSync = jest.fn((p) => {
|
|
284
|
-
if (p.endsWith('.build-complete')) return completionMarkerExists;
|
|
285
|
-
if (p.endsWith('.build-lock')) return !completionMarkerExists;
|
|
286
|
-
if (p.endsWith('layers/prisma')) return true;
|
|
287
|
-
return false;
|
|
288
|
-
});
|
|
289
|
-
fs.readFileSync = jest.fn((p) =>
|
|
290
|
-
p.endsWith('.build-lock') ? '12345' : markerFor({ prismaBinaryTarget: 'rhel-openssl-3.0.x' })
|
|
291
|
-
);
|
|
292
|
-
fs.writeFileSync = jest.fn();
|
|
293
|
-
fs.mkdirSync = jest.fn();
|
|
294
|
-
fs.rmSync = jest.fn();
|
|
295
|
-
buildPrismaLayer.mockResolvedValue();
|
|
296
|
-
const originalKill = process.kill;
|
|
297
|
-
let polls = 0;
|
|
298
|
-
process.kill = jest.fn(() => {
|
|
299
|
-
if (++polls >= 3) completionMarkerExists = true;
|
|
300
|
-
return true;
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const promise = ensurePrismaLayerExists({ prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' });
|
|
304
|
-
for (let i = 0; i < 5; i++) {
|
|
305
|
-
jest.advanceTimersByTime(1000);
|
|
306
|
-
await Promise.resolve();
|
|
307
|
-
}
|
|
308
|
-
await promise;
|
|
309
|
-
|
|
310
|
-
expect(buildPrismaLayer).toHaveBeenCalledWith({
|
|
311
|
-
databaseConfig: {},
|
|
312
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
process.kill = originalKill;
|
|
316
|
-
jest.useRealTimers();
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
172
|
describe('Concurrent Build Protection', () => {
|
|
321
173
|
it('should skip build if completion marker exists (TDD)', async () => {
|
|
322
174
|
mockFs.completedBuild();
|
|
@@ -339,9 +191,7 @@ describe('Prisma Layer Manager', () => {
|
|
|
339
191
|
if (path.endsWith('layers/prisma')) return true;
|
|
340
192
|
return false;
|
|
341
193
|
});
|
|
342
|
-
fs.readFileSync = jest.fn((
|
|
343
|
-
p.endsWith('.build-lock') ? activePid.toString() : markerFor()
|
|
344
|
-
);
|
|
194
|
+
fs.readFileSync = jest.fn().mockReturnValue(activePid.toString());
|
|
345
195
|
fs.writeFileSync = jest.fn();
|
|
346
196
|
fs.rmSync = jest.fn();
|
|
347
197
|
|
|
@@ -555,9 +405,7 @@ describe('Prisma Layer Manager', () => {
|
|
|
555
405
|
if (path.endsWith('layers/prisma')) return true;
|
|
556
406
|
return false;
|
|
557
407
|
});
|
|
558
|
-
fs.readFileSync = jest.fn((
|
|
559
|
-
p.endsWith('.build-lock') ? '12345' : markerFor()
|
|
560
|
-
);
|
|
408
|
+
fs.readFileSync = jest.fn().mockReturnValue('12345');
|
|
561
409
|
fs.writeFileSync = jest.fn();
|
|
562
410
|
fs.rmSync = jest.fn();
|
|
563
411
|
|
|
@@ -61,8 +61,6 @@ function applySsmPreloadNodeOptions(appDefinition, functions, providerEnvironmen
|
|
|
61
61
|
const { modifyHandlerPaths } = require('./domains/shared/utilities/handler-path-resolver');
|
|
62
62
|
const { createBaseDefinition } = require('./domains/shared/utilities/base-definition-factory');
|
|
63
63
|
const { ensurePrismaLayerExists } = require('./domains/shared/utilities/prisma-layer-manager');
|
|
64
|
-
const { resolveLambdaArchitecture } = require('./domains/shared/lambda-architectures');
|
|
65
|
-
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
66
64
|
const { validateAndCleanPlugins, validatePackagingConfiguration } = require('./domains/shared/validation/plugin-validator');
|
|
67
65
|
|
|
68
66
|
/**
|
|
@@ -76,23 +74,14 @@ const composeServerlessDefinition = async (AppDefinition) => {
|
|
|
76
74
|
|
|
77
75
|
// Determine if deployment should use Prisma Lambda Layer (default: true)
|
|
78
76
|
const usePrismaLayer = AppDefinition.usePrismaLambdaLayer !== false;
|
|
79
|
-
const { prismaBinaryTarget } = resolveLambdaArchitecture(AppDefinition);
|
|
80
77
|
|
|
81
78
|
// Ensure Prisma layer exists only when configured to use it
|
|
82
79
|
if (usePrismaLayer) {
|
|
83
|
-
await ensurePrismaLayerExists({
|
|
84
|
-
databaseConfig: AppDefinition.database || {},
|
|
85
|
-
prismaBinaryTarget,
|
|
86
|
-
});
|
|
80
|
+
await ensurePrismaLayerExists(AppDefinition.database || {});
|
|
87
81
|
} else {
|
|
88
82
|
console.log('📦 Skipping Prisma Lambda Layer (usePrismaLambdaLayer=false - bundling Prisma with functions)');
|
|
89
83
|
}
|
|
90
84
|
|
|
91
|
-
// The migration worker ships its own Prisma CLI engines (layer or not)
|
|
92
|
-
if (new MigrationBuilder().shouldExecute(AppDefinition)) {
|
|
93
|
-
await ensureMigrationEngines({ prismaBinaryTarget });
|
|
94
|
-
}
|
|
95
|
-
|
|
96
85
|
// Create orchestrator with all domain builders
|
|
97
86
|
const orchestrator = new BuilderOrchestrator([
|
|
98
87
|
new VpcBuilder(),
|
|
@@ -40,9 +40,6 @@ jest.mock('./domains/shared/resource-discovery', () => {
|
|
|
40
40
|
jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
|
|
41
41
|
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
42
42
|
}));
|
|
43
|
-
jest.mock('./domains/database/migration-engines', () => ({
|
|
44
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
45
|
-
}));
|
|
46
43
|
|
|
47
44
|
const { gatherDiscoveredResources } = require('./domains/shared/resource-discovery');
|
|
48
45
|
|
|
@@ -1477,74 +1474,6 @@ describe('composeServerlessDefinition', () => {
|
|
|
1477
1474
|
});
|
|
1478
1475
|
});
|
|
1479
1476
|
|
|
1480
|
-
describe('Lambda architecture (architecture)', () => {
|
|
1481
|
-
const appDefinition = (architecture) => ({
|
|
1482
|
-
name: 'arch-app',
|
|
1483
|
-
integrations: [{ Definition: { name: 'crm' } }],
|
|
1484
|
-
...(architecture && { architecture }),
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
beforeEach(() => {
|
|
1488
|
-
process.argv = ['node', 'test'];
|
|
1489
|
-
gatherDiscoveredResources.mockResolvedValue(createDiscoveryResponse());
|
|
1490
|
-
});
|
|
1491
|
-
|
|
1492
|
-
it('an explicit x86_64 only adds provider.architecture and the layer compatibleArchitectures to the unset template', async () => {
|
|
1493
|
-
const unset = await composeServerlessDefinition(appDefinition());
|
|
1494
|
-
const explicit = await composeServerlessDefinition(appDefinition('x86_64'));
|
|
1495
|
-
|
|
1496
|
-
expect(explicit.provider.architecture).toBe('x86_64');
|
|
1497
|
-
expect(explicit.layers.prisma.compatibleArchitectures).toEqual(['x86_64']);
|
|
1498
|
-
|
|
1499
|
-
delete explicit.provider.architecture;
|
|
1500
|
-
delete explicit.layers.prisma.compatibleArchitectures;
|
|
1501
|
-
expect(explicit).toEqual(unset);
|
|
1502
|
-
});
|
|
1503
|
-
|
|
1504
|
-
it('fetches the migration worker engines for the deployed architecture before packaging', async () => {
|
|
1505
|
-
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
1506
|
-
|
|
1507
|
-
await composeServerlessDefinition(appDefinition('arm64'));
|
|
1508
|
-
|
|
1509
|
-
expect(ensureMigrationEngines).toHaveBeenCalledWith({
|
|
1510
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
1511
|
-
});
|
|
1512
|
-
});
|
|
1513
|
-
|
|
1514
|
-
it('fetches no migration engines when there is no migration worker (PostgreSQL disabled)', async () => {
|
|
1515
|
-
const { ensureMigrationEngines } = require('./domains/database/migration-engines');
|
|
1516
|
-
ensureMigrationEngines.mockClear();
|
|
1517
|
-
|
|
1518
|
-
await composeServerlessDefinition({
|
|
1519
|
-
...appDefinition('arm64'),
|
|
1520
|
-
database: { postgres: { enable: false }, mongoDB: { enable: true } },
|
|
1521
|
-
});
|
|
1522
|
-
|
|
1523
|
-
expect(ensureMigrationEngines).not.toHaveBeenCalled();
|
|
1524
|
-
});
|
|
1525
|
-
|
|
1526
|
-
it('builds the Prisma layer for the engine of the deployed architecture', async () => {
|
|
1527
|
-
const { ensurePrismaLayerExists } = require('./domains/shared/utilities/prisma-layer-manager');
|
|
1528
|
-
|
|
1529
|
-
await composeServerlessDefinition(appDefinition('arm64'));
|
|
1530
|
-
|
|
1531
|
-
expect(ensurePrismaLayerExists).toHaveBeenCalledWith({
|
|
1532
|
-
databaseConfig: {},
|
|
1533
|
-
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
1534
|
-
});
|
|
1535
|
-
});
|
|
1536
|
-
|
|
1537
|
-
it('arm64 sets provider.architecture, which osls applies to every function, and the layer compatibleArchitectures', async () => {
|
|
1538
|
-
const result = await composeServerlessDefinition(appDefinition('arm64'));
|
|
1539
|
-
|
|
1540
|
-
expect(result.provider.architecture).toBe('arm64');
|
|
1541
|
-
expect(result.layers.prisma.compatibleArchitectures).toEqual(['arm64']);
|
|
1542
|
-
for (const fn of Object.values(result.functions)) {
|
|
1543
|
-
expect(fn.architecture).toBeUndefined();
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
});
|
|
1547
|
-
|
|
1548
1477
|
describe('applySsmPreloadNodeOptions', () => {
|
|
1549
1478
|
const appDefinition = {
|
|
1550
1479
|
ssm: { enable: true },
|