@friggframework/devtools 2.0.0--canary.657.f16d20b.0 → 2.0.0--canary.737.83b4e17.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 (104) hide show
  1. package/frigg-cli/README.md +115 -31
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  3. package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
  4. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  5. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  6. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +22 -5
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -551
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +4 -0
  32. package/frigg-cli/start-command/start-command.test.js +3 -0
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  40. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  41. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
  42. package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
  43. package/frigg-cli/validate-command/checks/config.js +504 -0
  44. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  45. package/frigg-cli/validate-command/format-report.js +58 -0
  46. package/frigg-cli/validate-command/index.js +107 -0
  47. package/frigg-cli/validate-command/load-app-definition.js +105 -0
  48. package/frigg-cli/validate-command/schema-issues.js +154 -0
  49. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  50. package/infrastructure/README.md +32 -5
  51. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
  52. package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
  53. package/infrastructure/__tests__/postgres-config.test.js +245 -836
  54. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
  55. package/infrastructure/__tests__/scoped-environment.test.js +3 -0
  56. package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
  57. package/infrastructure/__tests__/template-generation.test.js +39 -8
  58. package/infrastructure/app-definition-schema-contract.test.js +634 -0
  59. package/infrastructure/create-frigg-infrastructure.js +4 -1
  60. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  61. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
  62. package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -2
  63. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
  64. package/infrastructure/domains/database/aurora-builder.js +13 -2
  65. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  66. package/infrastructure/domains/database/migration-builder.js +21 -2
  67. package/infrastructure/domains/database/migration-builder.test.js +61 -6
  68. package/infrastructure/domains/database/migration-engines.js +93 -0
  69. package/infrastructure/domains/database/migration-engines.test.js +142 -0
  70. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  71. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  72. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  73. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  74. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  78. package/infrastructure/domains/integration/integration-builder.js +2 -0
  79. package/infrastructure/domains/integration/integration-builder.test.js +22 -39
  80. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  81. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  82. package/infrastructure/domains/scheduler/scheduler-builder.js +2 -19
  83. package/infrastructure/domains/scheduler/scheduler-builder.test.js +0 -99
  84. package/infrastructure/domains/security/iam-generator.js +112 -5
  85. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  86. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  87. package/infrastructure/domains/shared/environment-builder.js +31 -5
  88. package/infrastructure/domains/shared/environment-builder.test.js +93 -7
  89. package/infrastructure/domains/shared/lambda-architectures.js +113 -0
  90. package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
  91. package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -4
  92. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -17
  93. package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
  94. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
  95. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
  96. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
  97. package/infrastructure/infrastructure-composer.js +12 -1
  98. package/infrastructure/infrastructure-composer.test.js +339 -794
  99. package/infrastructure/scripts/build-prisma-layer.js +136 -50
  100. package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
  101. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  102. package/package.json +12 -10
  103. package/frigg-cli/index.test.js +0 -158
  104. package/infrastructure/integration.test.js +0 -381
@@ -313,4 +313,98 @@ describe('IAM Generator', () => {
313
313
  expect(yaml).toContain('CredentialsSecretArn:');
314
314
  });
315
315
  });
316
+
317
+ describe("scoping to the app's own resources", () => {
318
+ const yaml = require('js-yaml');
319
+ const policyResources = (template, policy) =>
320
+ template.Resources[
321
+ policy
322
+ ].Properties.PolicyDocument.Statement.flatMap((statement) =>
323
+ [].concat(statement.Resource)
324
+ ).map((r) => (typeof r === 'string' ? r : r['Fn::Sub']));
325
+
326
+ // `frigg deploy` names everything after the service (Definition.name):
327
+ // stack my-app-prod, functions my-app-prod-auth, role
328
+ // my-app-prod-us-east-1-lambdaRole, queues my-app-internal-error-queue-prod
329
+ // and my-app-prod-DbMigrationQueue, layer my-app-prisma-prod, and
330
+ // CloudFormation-named topics, alarms and buckets prefixed my-app-prod.
331
+ const generate = (appDefinition) => {
332
+ const summary = getFeatureSummary(appDefinition);
333
+ return yaml.load(
334
+ generateIAMCloudFormation({
335
+ appName: summary.appName,
336
+ serviceName: summary.serviceName,
337
+ features: summary.features,
338
+ })
339
+ );
340
+ };
341
+
342
+ it('reports the service name osls deploys under', () => {
343
+ expect(getFeatureSummary({ name: 'my-app' }).serviceName).toBe(
344
+ 'my-app'
345
+ );
346
+ expect(getFeatureSummary({}).serviceName).toBe('create-frigg-app');
347
+ });
348
+
349
+ it('lets an app whose name does not contain "frigg" deploy its stack and resources', () => {
350
+ const resources = policyResources(
351
+ generate({ name: 'my-app' }),
352
+ 'FriggCoreDeploymentPolicy'
353
+ );
354
+
355
+ for (const expected of [
356
+ 'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*',
357
+ 'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*',
358
+ 'arn:aws:iam::${AWS::AccountId}:role/*my-app*',
359
+ 'arn:aws:sqs:*:${AWS::AccountId}:*my-app*',
360
+ 'arn:aws:sns:*:${AWS::AccountId}:*my-app*',
361
+ 'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*',
362
+ 'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*:*',
363
+ 'arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:*my-app*',
364
+ 'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*',
365
+ 'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*:*',
366
+ 'arn:aws:s3:::*my-app*',
367
+ 'arn:aws:s3:::*my-app*/*',
368
+ ]) {
369
+ expect(resources).toContain(expected);
370
+ }
371
+ // Existing grants for frigg-named resources are kept.
372
+ expect(resources).toContain(
373
+ 'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
374
+ );
375
+ });
376
+
377
+ it('matches S3 bucket names in lower case', () => {
378
+ const resources = policyResources(
379
+ generate({ name: 'MyApp' }),
380
+ 'FriggCoreDeploymentPolicy'
381
+ );
382
+ expect(resources).toContain('arn:aws:s3:::*myapp*');
383
+ });
384
+
385
+ it('scopes the SSM parameter grant to the app too', () => {
386
+ const template = generate({
387
+ name: 'my-app',
388
+ ssm: { enable: true },
389
+ });
390
+ const resources = policyResources(template, 'FriggSSMPolicy');
391
+ expect(resources).toContain(
392
+ 'arn:aws:ssm:*:${AWS::AccountId}:parameter/*my-app*'
393
+ );
394
+ });
395
+
396
+ it('does not duplicate grants for an app named frigg', () => {
397
+ const resources = policyResources(
398
+ generate({ name: 'frigg' }),
399
+ 'FriggCoreDeploymentPolicy'
400
+ );
401
+ expect(
402
+ resources.filter(
403
+ (r) =>
404
+ r ===
405
+ 'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
406
+ )
407
+ ).toHaveLength(1);
408
+ });
409
+ });
316
410
  });
@@ -164,7 +164,7 @@ describe('CloudFormationDiscovery', () => {
164
164
  expect(result.routeTableId).toBe('rtb-123');
165
165
  expect(result.vpcEndpointSecurityGroupId).toBe('sg-vpce-123');
166
166
  expect(result.s3VpcEndpointId).toBe('vpce-s3-123');
167
- expect(result.dynamoDbVpcEndpointId).toBe('vpce-ddb-123');
167
+ expect(result.dynamodbVpcEndpointId).toBe('vpce-ddb-123');
168
168
  expect(result.kmsVpcEndpointId).toBe('vpce-kms-123');
169
169
  expect(result.secretsManagerVpcEndpointId).toBe('vpce-sm-123');
170
170
  });
@@ -190,6 +190,9 @@ describe('CloudFormationDiscovery', () => {
190
190
 
191
191
  expect(result).toEqual({
192
192
  fromCloudFormationStack: true,
193
+ // _extractFromResources() initialises the structured endpoint map whenever
194
+ // the stack has resources (37a354e8)
195
+ vpcEndpoints: {},
193
196
  stackName: 'test-stack',
194
197
  auroraClusterId: 'test-cluster',
195
198
  existingLogicalIds: ['FriggAuroraCluster'],
@@ -257,6 +260,9 @@ describe('CloudFormationDiscovery', () => {
257
260
 
258
261
  expect(result).toEqual({
259
262
  fromCloudFormationStack: true,
263
+ // _extractFromResources() initialises the structured endpoint map whenever
264
+ // the stack has resources (37a354e8)
265
+ vpcEndpoints: {},
260
266
  stackName: 'test-stack',
261
267
  migrationStatusBucket: 'test-migration-bucket',
262
268
  existingLogicalIds: ['FriggMigrationStatusBucket'],
@@ -285,6 +291,9 @@ describe('CloudFormationDiscovery', () => {
285
291
 
286
292
  expect(result).toEqual({
287
293
  fromCloudFormationStack: true,
294
+ // _extractFromResources() initialises the structured endpoint map whenever
295
+ // the stack has resources (37a354e8)
296
+ vpcEndpoints: {},
288
297
  stackName: 'test-stack',
289
298
  migrationQueueUrl:
290
299
  'https://sqs.us-east-1.amazonaws.com/123456789/test-queue',
@@ -313,6 +322,9 @@ describe('CloudFormationDiscovery', () => {
313
322
 
314
323
  expect(result).toEqual({
315
324
  fromCloudFormationStack: true,
325
+ // _extractFromResources() initialises the structured endpoint map whenever
326
+ // the stack has resources (37a354e8)
327
+ vpcEndpoints: {},
316
328
  stackName: 'test-stack',
317
329
  natGatewayId: 'nat-0123456789',
318
330
  existingLogicalIds: ['FriggNatGateway'],
@@ -340,6 +352,9 @@ describe('CloudFormationDiscovery', () => {
340
352
 
341
353
  expect(result).toEqual({
342
354
  fromCloudFormationStack: true,
355
+ // _extractFromResources() initialises the structured endpoint map whenever
356
+ // the stack has resources (37a354e8)
357
+ vpcEndpoints: {},
343
358
  stackName: 'test-stack',
344
359
  defaultVpcId: 'vpc-037ec55fe87aec1e7',
345
360
  existingLogicalIds: ['FriggVPC'],
@@ -378,6 +393,9 @@ describe('CloudFormationDiscovery', () => {
378
393
 
379
394
  expect(result).toEqual({
380
395
  fromCloudFormationStack: true,
396
+ // _extractFromResources() initialises the structured endpoint map whenever
397
+ // the stack has resources (37a354e8)
398
+ vpcEndpoints: {},
381
399
  stackName: 'test-stack',
382
400
  defaultVpcId: 'vpc-123', // VpcBuilder expects 'defaultVpcId'
383
401
  defaultKmsKeyId: 'arn:aws:kms:us-east-1:123456789:key/abc',
@@ -406,6 +424,9 @@ describe('CloudFormationDiscovery', () => {
406
424
 
407
425
  expect(result).toEqual({
408
426
  fromCloudFormationStack: true,
427
+ // _extractFromResources() initialises the structured endpoint map whenever
428
+ // the stack has resources (37a354e8)
429
+ vpcEndpoints: {},
409
430
  stackName: 'test-stack',
410
431
  });
411
432
  });
@@ -439,6 +460,11 @@ describe('CloudFormationDiscovery', () => {
439
460
  SecurityGroups: [{ VpcId: 'vpc-123' }],
440
461
  });
441
462
 
463
+ // Mock the VPC's default security group lookup (added in 37a354e8)
464
+ mockEC2Client.send.mockResolvedValueOnce({
465
+ SecurityGroups: [{ GroupId: 'sg-default-123' }],
466
+ });
467
+
442
468
  // Mock subnet query
443
469
  mockEC2Client.send.mockResolvedValueOnce({
444
470
  Subnets: [
@@ -469,9 +495,11 @@ describe('CloudFormationDiscovery', () => {
469
495
 
470
496
  const result = await cfDiscovery.discoverFromStack('test-stack');
471
497
 
498
+ expect(result.defaultVpcId).toBe('vpc-123');
499
+ expect(result.defaultSecurityGroupId).toBe('sg-default-123');
472
500
  expect(result.privateSubnetId1).toBe('subnet-private-1');
473
501
  expect(result.privateSubnetId2).toBe('subnet-private-2');
474
- expect(mockEC2Client.send).toHaveBeenCalledTimes(2);
502
+ expect(mockEC2Client.send).toHaveBeenCalledTimes(3);
475
503
  });
476
504
 
477
505
  it('should handle EC2 subnet query errors gracefully', async () => {
@@ -739,7 +767,7 @@ describe('CloudFormationDiscovery', () => {
739
767
  expect(result.vpcEndpoints.s3).toBe('vpce-0352ceac2124c14be');
740
768
  expect(result.vpcEndpoints.dynamodb).toBe('vpce-0b06c4f631199ea68');
741
769
  expect(result.s3VpcEndpointId).toBe('vpce-0352ceac2124c14be');
742
- expect(result.dynamoDbVpcEndpointId).toBe('vpce-0b06c4f631199ea68');
770
+ expect(result.dynamodbVpcEndpointId).toBe('vpce-0b06c4f631199ea68');
743
771
 
744
772
  // Verify NO VPC/KMS resources (they're external)
745
773
  expect(result.defaultVpcId).toBeUndefined();
@@ -776,7 +804,7 @@ describe('CloudFormationDiscovery', () => {
776
804
  expect(result.vpcEndpoints.s3).toBe('vpce-legacy-s3');
777
805
  expect(result.vpcEndpoints.dynamodb).toBe('vpce-legacy-ddb');
778
806
  expect(result.s3VpcEndpointId).toBe('vpce-legacy-s3');
779
- expect(result.dynamoDbVpcEndpointId).toBe('vpce-legacy-ddb');
807
+ expect(result.dynamodbVpcEndpointId).toBe('vpce-legacy-ddb');
780
808
  });
781
809
 
782
810
  it('should extract FriggLambdaSecurityGroup from stack', async () => {
@@ -807,7 +835,9 @@ describe('CloudFormationDiscovery', () => {
807
835
 
808
836
  // Lambda security group should be extracted
809
837
  expect(result.lambdaSecurityGroupId).toBe('sg-01002240c6a446202');
810
- expect(result.defaultSecurityGroupId).toBe('sg-01002240c6a446202');
838
+ // The Lambda SG must not masquerade as the VPC's default SG
839
+ // (defaultSecurityGroupId is only ever the VPC default; see 37a354e8).
840
+ expect(result.defaultSecurityGroupId).toBeUndefined();
811
841
  expect(result.existingLogicalIds).toContain(
812
842
  'FriggLambdaSecurityGroup'
813
843
  );
@@ -899,7 +929,7 @@ describe('CloudFormationDiscovery', () => {
899
929
 
900
930
  describe('existingLogicalIds tracking', () => {
901
931
  it('should track OLD VPC endpoint logical IDs (VPCEndpointS3 pattern) for backwards compatibility', async () => {
902
- // CRITICAL: Frontify production uses OLD naming convention
932
+ // CRITICAL: Older production stacks use the OLD naming convention
903
933
  const mockStack = {
904
934
  StackName: 'create-frigg-app-production',
905
935
  Outputs: [],
@@ -16,9 +16,12 @@ const {
16
16
  const { normalizeLogLevel } = require('./utilities/logging-config');
17
17
 
18
18
  // OTLP-family exporters read their endpoint/headers from these standard env
19
- // vars (ADR-011). When such an exporter is configured we auto-register them as
20
- // Serverless passthroughs so the deployed Lambda inherits them from the deploy
21
- // environment — no need for the adopter to also list them under `environment`.
19
+ // vars (ADR-011). When such an exporter is configured — or when the adopter
20
+ // opts into zero-code OTLP by setting OTEL_EXPORTER_OTLP_ENDPOINT (or marking
21
+ // it for SSM offload) with no Definition.telemetry.exporter — we auto-register
22
+ // them as Serverless passthroughs so the deployed Lambda inherits them from
23
+ // the deploy environment. An explicit exporter.type always wins: 'none' /
24
+ // 'console' do NOT register passthroughs even if the deploy shell has the env.
22
25
  //
23
26
  // NOTE (VPC egress): a Lambda in a private subnet needs a NAT gateway or a VPC
24
27
  // endpoint to reach an external OTLP backend (Honeycomb/Datadog). Without egress
@@ -29,9 +32,31 @@ const OTEL_PASSTHROUGH_VARS = [
29
32
  'OTEL_EXPORTER_OTLP_HEADERS',
30
33
  ];
31
34
 
35
+ function hasOtlpEndpointEnv() {
36
+ const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
37
+ return typeof endpoint === 'string' && endpoint.trim().length > 0;
38
+ }
39
+
40
+ /**
41
+ * Zero-code OTLP is active when Definition.telemetry.exporter is omitted and
42
+ * either the deploy shell has a non-empty OTEL_EXPORTER_OTLP_ENDPOINT or that
43
+ * key is declared for SSM offload (`environment: 'ssm'` / `ssm.parameters`).
44
+ */
45
+ function isZeroCodeOtlpActive(appDefinition) {
46
+ if (hasOtlpEndpointEnv()) return true;
47
+ return getOffloadedKeys(appDefinition).includes(
48
+ 'OTEL_EXPORTER_OTLP_ENDPOINT'
49
+ );
50
+ }
51
+
32
52
  function addTelemetryEnvPassthrough(appDefinition, envVars) {
33
53
  const exporterType = appDefinition?.telemetry?.exporter?.type;
34
- if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
54
+ if (exporterType !== undefined) {
55
+ // Explicit Definition.telemetry.exporter.type wins over the env var.
56
+ if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
57
+ } else if (!isZeroCodeOtlpActive(appDefinition)) {
58
+ return;
59
+ }
35
60
 
36
61
  // Skip offloaded keys here: baking '${env:KEY, ''}' resolves to '' at
37
62
  // deploy (the value lives only in SSM), and '' !== undefined then blocks
@@ -49,7 +74,8 @@ function addTelemetryEnvPassthrough(appDefinition, envVars) {
49
74
  // the core default, so it emits no env var.
50
75
  function addLoggingEnv(appDefinition, envVars) {
51
76
  const level = appDefinition?.logging?.level;
52
- const normalized = level === undefined ? undefined : normalizeLogLevel(level);
77
+ const normalized =
78
+ level === undefined ? undefined : normalizeLogLevel(level);
53
79
 
54
80
  // serverless-offline copies only AWS_* shell vars into handlers, so under
55
81
  // frigg start the shell level must travel through provider.environment.
@@ -10,6 +10,22 @@ const {
10
10
  } = require('./environment-builder');
11
11
 
12
12
  describe('Environment Builder', () => {
13
+ // Keep stage-default / empty-definition assertions deterministic even when
14
+ // a developer shell has OTEL_EXPORTER_OTLP_ENDPOINT set (zero-code path).
15
+ const originalOtelEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
16
+
17
+ beforeEach(() => {
18
+ delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
19
+ });
20
+
21
+ afterEach(() => {
22
+ if (originalOtelEndpoint === undefined) {
23
+ delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
24
+ } else {
25
+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT = originalOtelEndpoint;
26
+ }
27
+ });
28
+
13
29
  describe('getAppEnvironmentVars()', () => {
14
30
  it('should extract environment variables with value true', () => {
15
31
  const appDefinition = {
@@ -145,6 +161,44 @@ describe('Environment Builder', () => {
145
161
  getAppEnvironmentVars({}).OTEL_EXPORTER_OTLP_ENDPOINT
146
162
  ).toBeUndefined();
147
163
  });
164
+
165
+ it('zero-code: emits OTLP passthroughs when Definition omits exporter and the deploy env has the endpoint', () => {
166
+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
167
+ 'https://watchtower.example/api/v1/watchtower/otel';
168
+
169
+ const result = getAppEnvironmentVars({});
170
+
171
+ expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBe(
172
+ "${env:OTEL_EXPORTER_OTLP_ENDPOINT, ''}"
173
+ );
174
+ expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
175
+ "${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
176
+ );
177
+ });
178
+
179
+ it('zero-code: whitespace-only OTEL_EXPORTER_OTLP_ENDPOINT does not emit passthroughs', () => {
180
+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT = ' ';
181
+
182
+ const result = getAppEnvironmentVars({});
183
+
184
+ expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
185
+ expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
186
+ });
187
+
188
+ it.each(['none', 'console'])(
189
+ 'explicit exporter type "%s" wins over a set deploy-shell endpoint',
190
+ (type) => {
191
+ process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
192
+ 'https://watchtower.example/api/v1/watchtower/otel';
193
+
194
+ const result = getAppEnvironmentVars({
195
+ telemetry: { exporter: { type } },
196
+ });
197
+
198
+ expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
199
+ expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
200
+ }
201
+ );
148
202
  });
149
203
 
150
204
  describe('logging env (ADR-048)', () => {
@@ -217,7 +271,12 @@ describe('Environment Builder', () => {
217
271
  }
218
272
  };
219
273
 
220
- beforeEach(() => setEnv({ FRIGG_SKIP_AWS_DISCOVERY: 'true', FRIGG_LOG_LEVEL: undefined }));
274
+ beforeEach(() =>
275
+ setEnv({
276
+ FRIGG_SKIP_AWS_DISCOVERY: 'true',
277
+ FRIGG_LOG_LEVEL: undefined,
278
+ })
279
+ );
221
280
 
222
281
  afterEach(() => {
223
282
  for (const [key, value] of Object.entries(saved)) {
@@ -236,29 +295,39 @@ describe('Environment Builder', () => {
236
295
  setEnv({ FRIGG_LOG_LEVEL: 'error' });
237
296
 
238
297
  expect(
239
- getAppEnvironmentVars({ logging: { level: 'debug' } }).FRIGG_LOG_LEVEL
298
+ getAppEnvironmentVars({ logging: { level: 'debug' } })
299
+ .FRIGG_LOG_LEVEL
240
300
  ).toBe('error');
241
301
  });
242
302
 
243
303
  it('emits logging.level INFO, so the local DEBUG default does not replace it', () => {
244
304
  expect(
245
- getAppEnvironmentVars({ logging: { level: 'info' } }).FRIGG_LOG_LEVEL
305
+ getAppEnvironmentVars({ logging: { level: 'info' } })
306
+ .FRIGG_LOG_LEVEL
246
307
  ).toBe('INFO');
247
308
  });
248
309
 
249
310
  it('ignores an empty shell value', () => {
250
311
  setEnv({ FRIGG_LOG_LEVEL: ' ' });
251
312
 
252
- expect(getAppEnvironmentVars({})).not.toHaveProperty('FRIGG_LOG_LEVEL');
313
+ expect(getAppEnvironmentVars({})).not.toHaveProperty(
314
+ 'FRIGG_LOG_LEVEL'
315
+ );
253
316
  expect(
254
- getAppEnvironmentVars({ logging: { level: 'warn' } }).FRIGG_LOG_LEVEL
317
+ getAppEnvironmentVars({ logging: { level: 'warn' } })
318
+ .FRIGG_LOG_LEVEL
255
319
  ).toBe('WARN');
256
320
  });
257
321
 
258
322
  it('does not read the shell value outside frigg start', () => {
259
- setEnv({ FRIGG_SKIP_AWS_DISCOVERY: undefined, FRIGG_LOG_LEVEL: 'error' });
323
+ setEnv({
324
+ FRIGG_SKIP_AWS_DISCOVERY: undefined,
325
+ FRIGG_LOG_LEVEL: 'error',
326
+ });
260
327
 
261
- expect(getAppEnvironmentVars({})).not.toHaveProperty('FRIGG_LOG_LEVEL');
328
+ expect(getAppEnvironmentVars({})).not.toHaveProperty(
329
+ 'FRIGG_LOG_LEVEL'
330
+ );
262
331
  expect(
263
332
  getAppEnvironmentVars({ logging: { level: 'info' } })
264
333
  ).not.toHaveProperty('FRIGG_LOG_LEVEL');
@@ -466,6 +535,23 @@ describe('Environment Builder', () => {
466
535
 
467
536
  expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
468
537
  });
538
+
539
+ it('zero-code: omitted exporter + SSM-offloaded endpoint still passes through headers', () => {
540
+ delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
541
+ const appDefinition = {
542
+ ssm: { enable: true },
543
+ environment: {
544
+ OTEL_EXPORTER_OTLP_ENDPOINT: 'ssm',
545
+ },
546
+ };
547
+
548
+ const result = getAppEnvironmentVars(appDefinition);
549
+
550
+ expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
551
+ expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
552
+ "${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
553
+ );
554
+ });
469
555
  });
470
556
 
471
557
  describe('buildEnvironment()', () => {
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Lambda architectures and the Prisma engine each one runs.
3
+ *
4
+ * The registry keys are the AWS architecture names, so they go into
5
+ * `provider.architecture` and the layer `compatibleArchitectures` as they
6
+ * are. Every architecture-dependent value (layer build, layer cache key,
7
+ * migration worker engines, package excludes) reads from here.
8
+ */
9
+
10
+ const LAMBDA_ARCHITECTURES = {
11
+ x86_64: { prismaBinaryTarget: 'rhel-openssl-3.0.x' },
12
+ arm64: { prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' },
13
+ };
14
+
15
+ const DEFAULT_LAMBDA_ARCHITECTURE = 'x86_64';
16
+
17
+ /**
18
+ * @param {Object} appDefinition
19
+ * @returns {{ name: string, prismaBinaryTarget: string, explicit: boolean }}
20
+ * `explicit` is false when the app definition does not set `architecture`,
21
+ * so callers can leave the template unchanged for existing apps.
22
+ * @throws {Error} on an architecture the registry does not know
23
+ */
24
+ function resolveLambdaArchitecture(appDefinition = {}) {
25
+ const explicit = appDefinition.architecture !== undefined;
26
+ const name = explicit
27
+ ? appDefinition.architecture
28
+ : DEFAULT_LAMBDA_ARCHITECTURE;
29
+ const entry = LAMBDA_ARCHITECTURES[name];
30
+ if (!entry) {
31
+ throw new Error(
32
+ `Unknown Lambda architecture '${name}'. ` +
33
+ `Set architecture to one of: ${Object.keys(
34
+ LAMBDA_ARCHITECTURES
35
+ ).join(', ')}`
36
+ );
37
+ }
38
+ return { name, prismaBinaryTarget: entry.prismaBinaryTarget, explicit };
39
+ }
40
+
41
+ /** Where the migration worker's engines live, relative to the app root and to /var/task. */
42
+ const PRISMA_ENGINES_PACKAGE_DIR = 'node_modules/@prisma/engines';
43
+
44
+ /**
45
+ * The two engine files `prisma migrate` needs for a target, as
46
+ * @prisma/engines names them.
47
+ * @param {string} prismaBinaryTarget
48
+ * @returns {{ schemaEngine: string, queryEngineLibrary: string }}
49
+ */
50
+ function prismaEngineFileNames(prismaBinaryTarget) {
51
+ return {
52
+ schemaEngine: `schema-engine-${prismaBinaryTarget}`,
53
+ queryEngineLibrary: `libquery_engine-${prismaBinaryTarget}.so.node`,
54
+ };
55
+ }
56
+
57
+ const PRISMA_ENGINE_FILE_PREFIXES = [
58
+ 'libquery_engine-',
59
+ 'query-engine-',
60
+ 'query_engine-',
61
+ 'schema-engine-',
62
+ ];
63
+
64
+ const HOST_PLATFORM_ENGINE_TOKENS = [
65
+ 'darwin',
66
+ 'debian',
67
+ 'linux-musl',
68
+ 'windows',
69
+ ];
70
+
71
+ /**
72
+ * Package exclude patterns for every Prisma engine file the named
73
+ * architecture does not load: the deploy host's own platforms and the other
74
+ * Lambda architectures. Each pattern starts with an engine file prefix, so a
75
+ * runtime dependency that only has a platform word in its name is kept.
76
+ * @param {string} name - A registry key
77
+ * @returns {string[]}
78
+ */
79
+ function foreignPrismaEngineExcludes(name) {
80
+ const foreignTokens = [
81
+ ...HOST_PLATFORM_ENGINE_TOKENS,
82
+ ...Object.entries(LAMBDA_ARCHITECTURES)
83
+ .filter(([other]) => other !== name)
84
+ .map(([, { prismaBinaryTarget }]) => prismaBinaryTarget),
85
+ ];
86
+ return PRISMA_ENGINE_FILE_PREFIXES.flatMap((prefix) =>
87
+ foreignTokens.map((token) => `**/${prefix}${token}*`)
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Package exclude patterns for a function that bundles Prisma itself. With
93
+ * the Prisma layer on, the layer carries the engines and nothing is added.
94
+ * @param {Object} appDefinition
95
+ * @param {boolean} usePrismaLayer
96
+ * @returns {string[]}
97
+ */
98
+ function bundledPrismaEngineExcludes(appDefinition, usePrismaLayer) {
99
+ return usePrismaLayer
100
+ ? []
101
+ : foreignPrismaEngineExcludes(resolveLambdaArchitecture(appDefinition).name);
102
+ }
103
+
104
+ module.exports = {
105
+ LAMBDA_ARCHITECTURES,
106
+ DEFAULT_LAMBDA_ARCHITECTURE,
107
+ resolveLambdaArchitecture,
108
+ PRISMA_ENGINE_FILE_PREFIXES,
109
+ PRISMA_ENGINES_PACKAGE_DIR,
110
+ prismaEngineFileNames,
111
+ foreignPrismaEngineExcludes,
112
+ bundledPrismaEngineExcludes,
113
+ };