@empire-builder-kit/nx 1.0.0-rc.46 → 1.0.0-rc.47

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 (174) hide show
  1. package/generators.json +11 -1
  2. package/package.json +3 -3
  3. package/src/aws-authority/stage-authority.d.ts +30 -2
  4. package/src/aws-authority/stage-authority.js +220 -25
  5. package/src/developer-agent/generator-planning.js +99 -6
  6. package/src/developer-agent/model.d.ts +7 -3
  7. package/src/developer-agent/model.js +1 -0
  8. package/src/developer-agent/operation-registry.d.ts +1 -0
  9. package/src/developer-agent/operation-registry.js +43 -2
  10. package/src/developer-agent/planning.js +5 -2
  11. package/src/developer-agent/preview-changes.js +10 -0
  12. package/src/developer-agent/validation.js +7 -3
  13. package/src/developer-agent/workspace-inspection.js +51 -4
  14. package/src/executors/deployment-plan/deployment-plan.js +3 -0
  15. package/src/executors/dev-doctor/dev-doctor.d.ts +25 -3
  16. package/src/executors/dev-doctor/dev-doctor.js +136 -49
  17. package/src/executors/dev-setup/dev-setup.d.ts +18 -1
  18. package/src/executors/dev-setup/dev-setup.js +320 -196
  19. package/src/executors/foundation-preflight/foundation-preflight.js +9 -1
  20. package/src/executors/foundation-remove-preflight/foundation-remove-preflight.js +2 -2
  21. package/src/executors/infrastructure-plan/infrastructure-plan.js +10 -3
  22. package/src/executors/local-deploy/local-deploy.d.ts +15 -0
  23. package/src/executors/local-deploy/local-deploy.js +96 -14
  24. package/src/executors/sst-lifecycle/logging-preflight.js +12 -1
  25. package/src/executors/sst-lifecycle/run-sst-command.js +51 -5
  26. package/src/foundation/cost-estimate.js +1 -1
  27. package/src/foundation/identity-domain-parent-ready.d.ts +91 -0
  28. package/src/foundation/identity-domain-parent-ready.js +333 -0
  29. package/src/foundation/identity-domain.d.ts +94 -0
  30. package/src/foundation/identity-domain.js +115 -0
  31. package/src/foundation/index.d.ts +2 -0
  32. package/src/foundation/index.js +7 -0
  33. package/src/foundation/preflight.js +17 -1
  34. package/src/foundation/root-site-readiness.d.ts +27 -0
  35. package/src/foundation/root-site-readiness.js +78 -0
  36. package/src/foundation/root-site.d.ts +81 -0
  37. package/src/foundation/root-site.js +268 -0
  38. package/src/generators/framework-prerequisites.d.ts +2 -0
  39. package/src/generators/framework-prerequisites.js +34 -0
  40. package/src/generators/function/function-registration.d.ts +24 -0
  41. package/src/generators/function/function-registration.js +66 -0
  42. package/src/generators/function/function.d.ts +16 -1
  43. package/src/generators/function/function.js +101 -18
  44. package/src/generators/function/schema.d.ts +1 -0
  45. package/src/generators/function/schema.json +6 -0
  46. package/src/generators/function-access/function-access.d.ts +14 -0
  47. package/src/generators/function-access/function-access.js +141 -0
  48. package/src/generators/function-access/schema.d.ts +6 -0
  49. package/src/generators/function-access/schema.json +25 -0
  50. package/src/generators/post-generation-install.d.ts +1 -1
  51. package/src/generators/post-generation-install.js +1 -1
  52. package/src/generators/preset/dependency-overrides.d.ts +1 -1
  53. package/src/generators/preset/dependency-overrides.js +1 -1
  54. package/src/generators/preset/workspace-files-adopter-skills.js +14 -0
  55. package/src/generators/preset/workspace-files-developer-agent.js +17 -11
  56. package/src/generators/preset/workspace-files-stage-authority.js +58 -1
  57. package/src/generators/preset/workspace-files-thin-deploy.d.ts +11 -0
  58. package/src/generators/preset/workspace-files-thin-deploy.js +47 -4
  59. package/src/generators/preset/workspace-files-thin-docs.js +33 -5
  60. package/src/generators/preset/workspace-files.js +207 -13
  61. package/src/generators/repository-policy/repository-policy.js +2 -1
  62. package/src/generators/repository-policy/schema.d.ts +2 -0
  63. package/src/generators/repository-policy/schema.json +7 -2
  64. package/src/generators/site/built-in-site-documentation-files.d.ts +2 -0
  65. package/src/generators/site/built-in-site-documentation-files.js +92 -0
  66. package/src/generators/site/built-in-site-files.d.ts +8 -0
  67. package/src/generators/site/built-in-site-files.js +40 -0
  68. package/src/generators/site/built-in-site-infrastructure-files.d.ts +2 -0
  69. package/src/generators/site/built-in-site-infrastructure-files.js +275 -0
  70. package/src/generators/site/built-in-site-plan.d.ts +19 -0
  71. package/src/generators/site/built-in-site-plan.js +65 -0
  72. package/src/generators/site/built-in-site-project-files.d.ts +3 -0
  73. package/src/generators/site/built-in-site-project-files.js +258 -0
  74. package/src/generators/site/built-in-site-script-files.d.ts +2 -0
  75. package/src/generators/site/built-in-site-script-files.js +306 -0
  76. package/src/generators/site/built-in-site-shared.d.ts +9 -0
  77. package/src/generators/site/built-in-site-shared.js +21 -0
  78. package/src/generators/site/built-in-site-smoke-files.d.ts +2 -0
  79. package/src/generators/site/built-in-site-smoke-files.js +37 -0
  80. package/src/generators/site/built-in-site-sst-config-files.d.ts +2 -0
  81. package/src/generators/site/built-in-site-sst-config-files.js +39 -0
  82. package/src/generators/site/built-in-site-web-files.d.ts +2 -0
  83. package/src/generators/site/built-in-site-web-files.js +284 -0
  84. package/src/generators/site/schema.d.ts +4 -0
  85. package/src/generators/site/schema.json +20 -0
  86. package/src/generators/site/site.d.ts +13 -0
  87. package/src/generators/site/site.js +221 -0
  88. package/src/generators/slice/built-in-plan-alarm-identity.d.ts +9 -0
  89. package/src/generators/slice/built-in-plan-alarm-identity.js +8 -1
  90. package/src/generators/slice/built-in-plan-api-contract-files.js +18 -0
  91. package/src/generators/slice/built-in-plan-async-work-files.js +18 -0
  92. package/src/generators/slice/built-in-plan-data-files.js +116 -11
  93. package/src/generators/slice/built-in-plan-foundation-files.d.ts +12 -0
  94. package/src/generators/slice/built-in-plan-foundation-files.js +114 -5
  95. package/src/generators/slice/built-in-plan-frontend-files.js +2 -271
  96. package/src/generators/slice/built-in-plan-frontend-header-proof.d.ts +6 -0
  97. package/src/generators/slice/built-in-plan-frontend-header-proof.js +282 -0
  98. package/src/generators/slice/built-in-plan-infrastructure-files.js +151 -237
  99. package/src/generators/slice/built-in-plan-key-value-cleanup.js +4 -3
  100. package/src/generators/slice/built-in-plan-log-group-helpers.d.ts +29 -0
  101. package/src/generators/slice/built-in-plan-log-group-helpers.js +130 -0
  102. package/src/generators/slice/built-in-plan-metadata-files.js +21 -4
  103. package/src/generators/slice/built-in-plan-next-build-authority.d.ts +5 -0
  104. package/src/generators/slice/built-in-plan-next-build-authority.js +124 -0
  105. package/src/generators/slice/built-in-plan-operations-files.d.ts +6 -0
  106. package/src/generators/slice/built-in-plan-operations-files.js +107 -219
  107. package/src/generators/slice/built-in-plan-performance-files.js +6 -1
  108. package/src/generators/slice/built-in-plan-reliability-files.js +12 -8
  109. package/src/generators/slice/built-in-plan-shared.d.ts +1 -1
  110. package/src/generators/slice/built-in-plan-shared.js +1 -1
  111. package/src/generators/slice/built-in-plan-sst-config.d.ts +49 -0
  112. package/src/generators/slice/built-in-plan-sst-config.js +160 -0
  113. package/src/generators/slice/built-in-plan-testing-files.js +92 -49
  114. package/src/generators/slice/built-in-plan-verification-files.js +15 -4
  115. package/src/generators/slice/built-in-plan-web-files.js +65 -0
  116. package/src/generators/slice/deployed-smoke-diagnostics.d.ts +35 -0
  117. package/src/generators/slice/deployed-smoke-diagnostics.js +189 -0
  118. package/src/generators/slice/deployed-smoke-readiness.d.ts +7 -0
  119. package/src/generators/slice/deployed-smoke-readiness.js +118 -23
  120. package/src/generators/slice/persistence-contract.js +2 -2
  121. package/src/generators/slice/pnpm-launch-script.d.ts +13 -0
  122. package/src/generators/slice/pnpm-launch-script.js +28 -0
  123. package/src/generators/slice/slice.js +27 -0
  124. package/src/generators/upgrade/custom-domain-notice.d.ts +19 -0
  125. package/src/generators/upgrade/custom-domain-notice.js +38 -0
  126. package/src/generators/upgrade/external-blueprint-compositions.d.ts +84 -0
  127. package/src/generators/upgrade/external-blueprint-compositions.js +478 -0
  128. package/src/generators/upgrade/framework-package-upgrade.d.ts +58 -0
  129. package/src/generators/upgrade/framework-package-upgrade.js +78 -0
  130. package/src/generators/upgrade/function-authentication-notice.d.ts +29 -0
  131. package/src/generators/upgrade/function-authentication-notice.js +74 -0
  132. package/src/generators/upgrade/schema.json +2 -2
  133. package/src/generators/upgrade/upgrade-plan.d.ts +52 -0
  134. package/src/generators/upgrade/upgrade-plan.js +406 -0
  135. package/src/generators/upgrade/upgrade.d.ts +1 -35
  136. package/src/generators/upgrade/upgrade.js +259 -593
  137. package/src/generators/workload/workload.js +60 -4
  138. package/src/git-policy/github-bootstrap.d.ts +6 -5
  139. package/src/git-policy/github-bootstrap.js +6 -4
  140. package/src/local-dev/fleet-process.d.ts +9 -2
  141. package/src/local-dev/fleet-process.js +27 -7
  142. package/src/local-dev/gateway-daemon.d.ts +1 -1
  143. package/src/local-dev/gateway-daemon.js +6 -4
  144. package/src/local-dev/portless.d.ts +5 -0
  145. package/src/local-dev/portless.js +5 -0
  146. package/src/local-dev/process-group.d.ts +10 -0
  147. package/src/local-dev/process-group.js +33 -0
  148. package/src/local-dev/tls.js +31 -2
  149. package/src/local-dev/trust-store.d.ts +42 -0
  150. package/src/local-dev/trust-store.js +87 -0
  151. package/src/ownership/composition.d.ts +7 -0
  152. package/src/ownership/composition.js +64 -56
  153. package/src/ownership/index.d.ts +1 -0
  154. package/src/ownership/index.js +1 -0
  155. package/src/ownership/record.d.ts +19 -0
  156. package/src/ownership/record.js +26 -2
  157. package/src/ownership/site-record.d.ts +18 -0
  158. package/src/ownership/site-record.js +105 -0
  159. package/src/repository-policy/deployment-plan.d.ts +3 -0
  160. package/src/repository-policy/deployment-plan.js +33 -4
  161. package/src/repository-policy/index.d.ts +1 -0
  162. package/src/repository-policy/index.js +1 -0
  163. package/src/repository-policy/policy.d.ts +13 -1
  164. package/src/repository-policy/policy.js +55 -1
  165. package/src/repository-policy/public-dns.d.ts +65 -0
  166. package/src/repository-policy/public-dns.js +168 -0
  167. package/src/schemas/generated-ownership-v2.json +6 -0
  168. package/src/schemas/repository-policy-v1.json +67 -1
  169. package/src/supply-chain/blueprint-trust-git.js +24 -0
  170. package/src/supply-chain/blueprint-verification-authority.js +21 -3
  171. package/src/supply-chain/generated-blueprint-trust-command.js +15 -0
  172. package/src/work-markers/work-markers.js +4 -1
  173. package/src/workspace-deployment/ownership.d.ts +15 -0
  174. package/src/workspace-deployment/ownership.js +19 -3
@@ -20,6 +20,7 @@ const tool_versions_js_1 = require("../preset/tool-versions.js");
20
20
  const workspace_files_js_1 = require("../preset/workspace-files.js");
21
21
  const built_in_plan_js_1 = require("../slice/built-in-plan.js");
22
22
  const built_in_plan_shared_js_1 = require("../slice/built-in-plan-shared.js");
23
+ const external_blueprint_compositions_js_1 = require("../upgrade/external-blueprint-compositions.js");
23
24
  const frozen_container_js_1 = require("./frozen-container.js");
24
25
  const performance_registration_js_1 = require("./performance-registration.js");
25
26
  const reliability_registration_js_1 = require("./reliability-registration.js");
@@ -311,6 +312,7 @@ ${kind !== 'service' || ownsProtectedLoadAdapter
311
312
  : ''}${kind === 'service' && ownsProtectedLoadAdapter
312
313
  ? ` performanceIngress: {
313
314
  api: any;
315
+ apiPathPrefix: string;
314
316
  originProof: any;
315
317
  router: any;
316
318
  } | undefined,
@@ -527,6 +529,16 @@ ${kind !== 'service' || ownsProtectedLoadAdapter
527
529
  connectionAttempts: 1,
528
530
  connectionTimeout: '3 seconds',
529
531
  readTimeout: '30 seconds',
532
+ // API Gateway strips a custom-domain API's /<slice> mapping path
533
+ // before route matching, so the edge adds it once more.
534
+ ...(performanceIngress.apiPathPrefix
535
+ ? {
536
+ rewrite: {
537
+ regex: '^/',
538
+ to: performanceIngress.apiPathPrefix + '/',
539
+ },
540
+ }
541
+ : {}),
530
542
  },
531
543
  );
532
544
  performanceIngress.router.route(
@@ -536,6 +548,16 @@ ${kind !== 'service' || ownsProtectedLoadAdapter
536
548
  connectionAttempts: 1,
537
549
  connectionTimeout: '3 seconds',
538
550
  readTimeout: '30 seconds',
551
+ // API Gateway strips a custom-domain API's /<slice> mapping path
552
+ // before route matching, so the edge adds it once more.
553
+ ...(performanceIngress.apiPathPrefix
554
+ ? {
555
+ rewrite: {
556
+ regex: '^/',
557
+ to: performanceIngress.apiPathPrefix + '/',
558
+ },
559
+ }
560
+ : {}),
539
561
  },
540
562
  );
541
563
  }
@@ -1055,6 +1077,24 @@ describe('${workload} ${kind} outage behavior', () => {
1055
1077
  project: `@${slice}/${kind}-${workload}`,
1056
1078
  };
1057
1079
  }
1080
+ /**
1081
+ * Every `apiPathPrefix: publicDomain ? '/<slice>' : '',` member of a Slice's
1082
+ * infra/product.ts, on one line or wrapped across several.
1083
+ */
1084
+ function apiPathPrefixMember(slice) {
1085
+ const name = slice.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
1086
+ return new RegExp(`apiPathPrefix:\\s*publicDomain\\s*\\?\\s*'/${name}'\\s*:\\s*''\\s*,`, 'gu');
1087
+ }
1088
+ /**
1089
+ * Every ` const api = new sst.aws.ApiGatewayV2('<Pascal>Api', {` opening of
1090
+ * a Slice's infra/product.ts, on one line or wrapped. Prettier puts the
1091
+ * call's arguments on their own lines once the PascalCase name is 34
1092
+ * characters or more, at the generated workspace's 80-column print width.
1093
+ */
1094
+ function sliceApiOpening(slice) {
1095
+ const name = pascal(slice).replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
1096
+ return new RegExp(` const api = new sst\\.aws\\.ApiGatewayV2\\(\\s*'${name}Api',\\s*\\{`, 'gu');
1097
+ }
1058
1098
  async function executeWorkloadGenerator(tree, options, kind) {
1059
1099
  const slice = name(options.slice, 'Product Slice name');
1060
1100
  const workload = name(options.name, kind === 'service' ? 'Service name' : 'Job name');
@@ -1159,6 +1199,18 @@ async function executeWorkloadGenerator(tree, options, kind) {
1159
1199
  sliceRoot,
1160
1200
  workspace,
1161
1201
  });
1202
+ // The Service that owns the protected-load adapter types its ingress with
1203
+ // the API mapping path; a managed product.ts from before that member would
1204
+ // not typecheck against it. Prettier wraps the member's ternary for a long
1205
+ // Slice name, so the match allows any whitespace between its tokens. On a
1206
+ // Slice the upgrade refuses, the message says so and why, instead of
1207
+ // sending the adopter into that refusal.
1208
+ if (kind === 'service' &&
1209
+ performanceRegistration.ownsProtectedLoadAdapter &&
1210
+ (tree.read(productPath, 'utf8') ?? '').match(apiPathPrefixMember(slice))
1211
+ ?.length !== 1) {
1212
+ throw new Error((0, external_blueprint_compositions_js_1.upgradeSliceFirst)(tree, sliceRoot, `Product Slice ${slice} has no managed API mapping path for its protected-load ingress in ${productPath}`));
1213
+ }
1162
1214
  const reliabilityRegistration = (0, reliability_registration_js_1.planWorkloadReliabilityRegistration)(tree, {
1163
1215
  feature,
1164
1216
  kind,
@@ -1208,11 +1260,15 @@ async function executeWorkloadGenerator(tree, options, kind) {
1208
1260
  const source = tree.read(productPath, 'utf8');
1209
1261
  if (source === null)
1210
1262
  throw new Error('Product Slice API source is missing; no workload files changed.');
1211
- const anchor = ` const api = new sst.aws.ApiGatewayV2('${pascal(slice)}Api', {`;
1212
- if (source.split(anchor).length !== 2)
1263
+ const opening = sliceApiOpening(slice);
1264
+ if (source.match(opening)?.length !== 1)
1213
1265
  throw new Error('Product Slice API composition is not recognized; no workload files changed.');
1214
- tree.write(productPath, source.replace(anchor, anchor +
1215
- '\n ...(performanceDeploymentAuthority ? { vpc: foundation.vpc } : {}),'));
1266
+ tree.write(productPath, source.replace(opening, (text) => {
1267
+ // One level deeper than the line that holds the opening brace.
1268
+ const braceLine = text.slice(text.lastIndexOf('\n') + 1);
1269
+ const indent = /^ */u.exec(braceLine)?.[0] ?? '';
1270
+ return `${text}\n${indent} ...(performanceDeploymentAuthority ? { vpc: foundation.vpc } : {}),`;
1271
+ }));
1216
1272
  }
1217
1273
  tree.write(foundationPath, (0, built_in_plan_foundation_files_js_1.renderSliceFoundationFiles)(slice, pascal(slice), foundationRequirement.capabilities)['infra/foundation.ts']);
1218
1274
  const infraRelative = `../${plural}/${workload}/infra.js`;
@@ -16,12 +16,13 @@ export declare const EBK_STAGING_PROMOTION_PULL_ROLE_SECRET = "AWS_STAGING_PROMO
16
16
  export declare const EBK_PROTECTED_ENVIRONMENT_SECRETS: readonly ["AWS_ASYNC_RECOVERY_ROLE_ARN", "AWS_ECR_INSPECTOR_EVIDENCE_ROLE_ARN", "AWS_DEPLOY_ROLE_ARN", "AWS_STAGING_PROMOTION_PULL_ROLE_ARN"];
17
17
  export declare const EBK_PROTECTED_ENVIRONMENT_VARIABLES: readonly ["AWS_EXPECTED_ACCOUNT_ID", "AWS_REGION", "AWS_STAGING_PROMOTION_EXPECTED_ACCOUNT_ID", "AWS_STAGING_PROMOTION_REGION", "EBK_ALLOW_PRODUCTION_REMOVE", "EBK_FLEET_ORIGIN"];
18
18
  /**
19
- * Non-secret stage environment variables an operator may set to request a
20
- * machine credential generation or its retirement on a workflow deploy. They
21
- * are never required, and a repository- or organization-scoped copy would
22
- * silently apply to every stage, so only the stage environment may hold them.
19
+ * Non-secret stage environment variables an operator may set on a workflow
20
+ * deploy to request a database credential generation, a machine credential
21
+ * generation, or the machine generation's retirement. They are never
22
+ * required, and a repository- or organization-scoped copy would silently
23
+ * apply to every stage, so only the stage environment may hold them.
23
24
  */
24
- export declare const EBK_OPTIONAL_STAGE_ENVIRONMENT_VARIABLES: readonly ["EBK_MACHINE_CREDENTIAL_GENERATION", "EBK_MACHINE_RETIRE_PREVIOUS_GENERATION"];
25
+ export declare const EBK_OPTIONAL_STAGE_ENVIRONMENT_VARIABLES: readonly ["EBK_DATABASE_CREDENTIAL_GENERATION", "EBK_MACHINE_CREDENTIAL_GENERATION", "EBK_MACHINE_RETIRE_PREVIOUS_GENERATION"];
25
26
  export declare const EBK_CODE_OWNER_PLACEHOLDER: "@REPLACE_WITH_GITHUB_CODE_OWNER";
26
27
  type GitHubEnvironmentStage = 'development' | 'production' | 'staging';
27
28
  type GitHubAuxiliaryEnvironment = 'async-recovery' | 'ecr-inspector';
@@ -34,12 +34,14 @@ exports.EBK_PROTECTED_ENVIRONMENT_VARIABLES = [
34
34
  'EBK_FLEET_ORIGIN',
35
35
  ];
36
36
  /**
37
- * Non-secret stage environment variables an operator may set to request a
38
- * machine credential generation or its retirement on a workflow deploy. They
39
- * are never required, and a repository- or organization-scoped copy would
40
- * silently apply to every stage, so only the stage environment may hold them.
37
+ * Non-secret stage environment variables an operator may set on a workflow
38
+ * deploy to request a database credential generation, a machine credential
39
+ * generation, or the machine generation's retirement. They are never
40
+ * required, and a repository- or organization-scoped copy would silently
41
+ * apply to every stage, so only the stage environment may hold them.
41
42
  */
42
43
  exports.EBK_OPTIONAL_STAGE_ENVIRONMENT_VARIABLES = [
44
+ 'EBK_DATABASE_CREDENTIAL_GENERATION',
43
45
  'EBK_MACHINE_CREDENTIAL_GENERATION',
44
46
  'EBK_MACHINE_RETIRE_PREVIOUS_GENERATION',
45
47
  ];
@@ -1,4 +1,4 @@
1
- import { type ChildProcess } from 'node:child_process';
1
+ import { type ChildProcess, type SpawnOptions } from 'node:child_process';
2
2
  import type { LocalDevAdapter } from './contracts.js';
3
3
  import type { FleetLogStore } from './fleet-logs.js';
4
4
  import type { FleetProcessIdentity } from './fleet-lock.js';
@@ -70,7 +70,14 @@ export declare function planFleetRestart(completedRestartAttempts: number, maxRe
70
70
  restart: true;
71
71
  };
72
72
  export declare function assertOwnedGroupAbsent(pid: number, deadline?: number): Promise<void>;
73
- export declare function terminateOwnedChild(child: ChildProcess, ownedIdentity?: FleetProcessIdentity): Promise<void>;
73
+ /** Seams that let every host exercise the native Windows tree kill. */
74
+ export interface OwnedChildTerminationEffects {
75
+ /** The environment that names SystemRoot; defaults to this process's. */
76
+ environment?: NodeJS.ProcessEnv;
77
+ platform?: NodeJS.Platform;
78
+ spawn?: (command: string, arguments_: readonly string[], options: SpawnOptions) => ChildProcess;
79
+ }
80
+ export declare function terminateOwnedChild(child: ChildProcess, ownedIdentity?: FleetProcessIdentity, effects?: OwnedChildTerminationEffects): Promise<void>;
74
81
  export declare const FLEET_RUNNER_STOP_MESSAGE = "ebk-fleet-runner-stop";
75
82
  export declare const FLEET_RUNNER_QUIESCE_MESSAGE = "ebk-fleet-runner-quiesce";
76
83
  export declare const FLEET_RUNNER_QUIESCED_MESSAGE = "ebk-fleet-runner-quiesced";
@@ -67,8 +67,10 @@ async function waitForOwnedExit(exited, timeoutMs) {
67
67
  }
68
68
  }
69
69
  async function assertOwnedGroupAbsent(pid, deadline = Date.now() + 1_000) {
70
- // Native Windows retains its existing taskkill contract. This POSIX proof
71
- // is not a claim that Windows orphan trees can be inspected after exit.
70
+ // Windows has no process group to probe once its leader exits, and taskkill
71
+ // /t cannot reach descendants through an exited parent. terminateOwnedChild
72
+ // proves the leader's own exit; descendant absence stays unproved, part of
73
+ // the accepted native-Windows Fleet deferral.
72
74
  if (process.platform === 'win32')
73
75
  return;
74
76
  while ((0, process_group_js_1.exactOwnedProcessGroupExists)(pid)) {
@@ -77,7 +79,7 @@ async function assertOwnedGroupAbsent(pid, deadline = Date.now() + 1_000) {
77
79
  await new Promise((resolve) => setTimeout(resolve, 25));
78
80
  }
79
81
  }
80
- async function terminateOwnedChild(child, ownedIdentity) {
82
+ async function terminateOwnedChild(child, ownedIdentity, effects = {}) {
81
83
  if (!child.pid)
82
84
  throw new errors_js_1.LocalDevContractError('cleanup-incomplete', 'Owned child PID is unavailable.');
83
85
  if (child.exitCode !== null || child.signalCode !== null) {
@@ -86,13 +88,31 @@ async function terminateOwnedChild(child, ownedIdentity) {
86
88
  }
87
89
  const deadline = Date.now() + process_group_js_1.OWNED_PROCESS_SIGNAL_GRACE_MS + process_group_js_1.OWNED_PROCESS_KILL_WAIT_MS;
88
90
  const exited = new Promise((resolvePromise) => child.once('exit', () => resolvePromise()));
89
- if (process.platform === 'win32' && child.pid) {
90
- const killer = (0, node_child_process_1.spawn)('taskkill', ['/pid', String(child.pid), '/t', '/f'], {
91
+ if ((effects.platform ?? process.platform) === 'win32' && child.pid) {
92
+ // A bare name would resolve through the adopter checkout before PATH, so
93
+ // without the canonical system binary nothing is signaled.
94
+ let taskkill;
95
+ try {
96
+ taskkill = (0, process_group_js_1.exactWindowsTaskkill)(effects.environment ?? process.env);
97
+ }
98
+ catch (error) {
99
+ throw new errors_js_1.LocalDevContractError('cleanup-incomplete', `Owned child process tree was not signaled; ownership is retained. ${error instanceof Error ? error.message : String(error)}`);
100
+ }
101
+ // taskkill /f only requests termination, and its status proves nothing
102
+ // either way: /t also fails when a member exits during its walk. Only the
103
+ // leader's own exit is proof. Node's open handle keeps its PID from reuse.
104
+ const killer = (effects.spawn ?? node_child_process_1.spawn)(taskkill.executable, ['/pid', String(child.pid), '/t', '/f'], {
105
+ env: { SystemRoot: taskkill.systemRoot },
106
+ shell: false,
91
107
  stdio: 'ignore',
92
108
  windowsHide: true,
93
109
  });
94
- await new Promise((resolvePromise) => killer.once('exit', () => resolvePromise()));
95
- await waitForOwnedExit(exited, 2_000);
110
+ const requested = await new Promise((resolvePromise) => {
111
+ killer.once('error', (error) => resolvePromise(error.message));
112
+ killer.once('exit', (code, signal) => resolvePromise(`taskkill ${describeExit({ code, signal })}`));
113
+ });
114
+ if (!(await waitForOwnedExit(exited, Math.max(0, deadline - Date.now()))))
115
+ throw new errors_js_1.LocalDevContractError('cleanup-incomplete', `Owned child did not exit after ${requested}; ownership is retained.`);
96
116
  return;
97
117
  }
98
118
  const identity = ownedIdentity ?? (0, process_identity_js_1.captureProcessIdentity)(child.pid);
@@ -1,4 +1,4 @@
1
1
  export declare function runGatewayDaemon(options: {
2
2
  appData: string;
3
- port?: number;
3
+ port: number;
4
4
  }): Promise<void>;
@@ -4,6 +4,8 @@ exports.runGatewayDaemon = runGatewayDaemon;
4
4
  const node_fs_1 = require("node:fs");
5
5
  const gateway_js_1 = require("./gateway.js");
6
6
  const tls_js_1 = require("./tls.js");
7
+ // Started only by ebk dev setup --portless, which always passes the port of
8
+ // its selected forwarding model; there is no default port to bind.
7
9
  async function runGatewayDaemon(options) {
8
10
  const paths = (0, tls_js_1.localTlsPaths)(options.appData);
9
11
  if (process.platform !== 'win32')
@@ -13,7 +15,7 @@ async function runGatewayDaemon(options) {
13
15
  cert: (0, node_fs_1.readFileSync)(paths.leafCertificate),
14
16
  key: (0, node_fs_1.readFileSync)(paths.leafKey),
15
17
  });
16
- await gateway.listen(options.port ?? 443, paths.gatewaySocket);
18
+ await gateway.listen(options.port, paths.gatewaySocket);
17
19
  (0, node_fs_1.writeFileSync)(paths.gatewayPid, `${process.pid}\n`, { mode: 0o600 });
18
20
  const shutdown = async () => {
19
21
  await gateway.close().catch(() => undefined);
@@ -27,9 +29,9 @@ async function runGatewayDaemon(options) {
27
29
  }
28
30
  if (require.main === module) {
29
31
  const appData = process.argv[2];
30
- const port = Number(process.argv[3] ?? '443');
31
- if (!appData || !Number.isInteger(port)) {
32
- throw new Error('Usage: gateway-daemon <app-data> [port]');
32
+ const port = Number(process.argv[3]);
33
+ if (!appData || !process.argv[3] || !Number.isInteger(port)) {
34
+ throw new Error('Usage: gateway-daemon <app-data> <port>');
33
35
  }
34
36
  void runGatewayDaemon({ appData, port }).catch((error) => {
35
37
  process.stderr.write(`${error instanceof Error ? error.stack : String(error)}\n`);
@@ -11,5 +11,10 @@ export interface PortlessForwardPlan {
11
11
  platform: NodeJS.Platform;
12
12
  remove: PrivilegedCommand[];
13
13
  }
14
+ /**
15
+ * The forwarding model for the explicit `ebk dev setup --portless` opt-in.
16
+ * Plain setup never computes this plan, starts the gateway daemon, or binds a
17
+ * port; on Windows the daemon binds 443 directly only under this opt-in.
18
+ */
14
19
  export declare function createPortlessForwardPlan(targetPlatform?: NodeJS.Platform): PortlessForwardPlan;
15
20
  export declare function applyPrivilegedCommands(commands: readonly PrivilegedCommand[]): void;
@@ -5,6 +5,11 @@ exports.createPortlessForwardPlan = createPortlessForwardPlan;
5
5
  exports.applyPrivilegedCommands = applyPrivilegedCommands;
6
6
  const node_child_process_1 = require("node:child_process");
7
7
  exports.EBK_GATEWAY_INTERNAL_PORT = 54443;
8
+ /**
9
+ * The forwarding model for the explicit `ebk dev setup --portless` opt-in.
10
+ * Plain setup never computes this plan, starts the gateway daemon, or binds a
11
+ * port; on Windows the daemon binds 443 directly only under this opt-in.
12
+ */
8
13
  function createPortlessForwardPlan(targetPlatform = process.platform) {
9
14
  if (targetPlatform === 'win32') {
10
15
  return {
@@ -2,3 +2,13 @@ export declare const OWNED_PROCESS_SIGNAL_GRACE_MS = 10000;
2
2
  export declare const OWNED_PROCESS_KILL_WAIT_MS = 5000;
3
3
  /** Read-only existence check for an already-proved owned POSIX group. */
4
4
  export declare function exactOwnedProcessGroupExists(pid: number): boolean;
5
+ export interface ExactWindowsTaskkill {
6
+ executable: string;
7
+ systemRoot: string;
8
+ }
9
+ /** The canonical `%SystemRoot%\System32\taskkill.exe`, never a bare-name
10
+ * lookup: on Windows libuv searches the current directory (an adopter
11
+ * checkout) before PATH. Spawn it with `env: { SystemRoot }` and
12
+ * `shell: false`. The governed SST executor keeps its own copy of this check
13
+ * in run-sst-command.ts, where its spec pins the source text. */
14
+ export declare function exactWindowsTaskkill(environment: NodeJS.ProcessEnv): ExactWindowsTaskkill;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OWNED_PROCESS_KILL_WAIT_MS = exports.OWNED_PROCESS_SIGNAL_GRACE_MS = void 0;
4
4
  exports.exactOwnedProcessGroupExists = exactOwnedProcessGroupExists;
5
+ exports.exactWindowsTaskkill = exactWindowsTaskkill;
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = require("node:path");
5
8
  // The fleet owner must allow its SST child the same bounded settlement window.
6
9
  exports.OWNED_PROCESS_SIGNAL_GRACE_MS = 10_000;
7
10
  exports.OWNED_PROCESS_KILL_WAIT_MS = 5_000;
@@ -26,4 +29,34 @@ function exactOwnedProcessGroupExists(pid) {
26
29
  throw error;
27
30
  }
28
31
  }
32
+ /** The canonical `%SystemRoot%\System32\taskkill.exe`, never a bare-name
33
+ * lookup: on Windows libuv searches the current directory (an adopter
34
+ * checkout) before PATH. Spawn it with `env: { SystemRoot }` and
35
+ * `shell: false`. The governed SST executor keeps its own copy of this check
36
+ * in run-sst-command.ts, where its spec pins the source text. */
37
+ function exactWindowsTaskkill(environment) {
38
+ const values = new Set(Object.entries(environment)
39
+ .filter(([name, value]) => name.toLowerCase() === 'systemroot' &&
40
+ typeof value === 'string' &&
41
+ value.length > 0)
42
+ .map(([, value]) => value));
43
+ if (values.size !== 1) {
44
+ throw new Error('Windows process-tree termination requires exact SystemRoot.');
45
+ }
46
+ const systemRoot = values.values().next().value;
47
+ if (typeof systemRoot !== 'string' ||
48
+ !(0, node_path_1.isAbsolute)(systemRoot) ||
49
+ /[\0\r\n"]/u.test(systemRoot)) {
50
+ throw new Error('Windows process-tree termination has an unsafe SystemRoot.');
51
+ }
52
+ const requested = (0, node_path_1.join)(systemRoot, 'System32', 'taskkill.exe');
53
+ const metadata = (0, node_fs_1.lstatSync)(requested);
54
+ const canonical = (0, node_fs_1.realpathSync)(requested);
55
+ if (metadata.isSymbolicLink() ||
56
+ !metadata.isFile() ||
57
+ canonical.toLowerCase() !== requested.toLowerCase()) {
58
+ throw new Error('Windows taskkill authority is not exact.');
59
+ }
60
+ return { executable: canonical, systemRoot };
61
+ }
29
62
  //# sourceMappingURL=process-group.js.map
@@ -61,7 +61,11 @@ function createLocalIpcPath(base, identity) {
61
61
  .update((0, node_path_1.resolve)(base))
62
62
  .digest('hex')
63
63
  .slice(0, 16);
64
- const directory = (0, node_path_1.join)('/tmp', `ebk-${uid}-${baseDigest}`);
64
+ const directory = (0, node_path_1.join)(localIpcFallbackRoot(uid), `ebk-${uid}-${baseDigest}`);
65
+ const socket = (0, node_path_1.join)(directory, `.ebk-${digest}.sock`);
66
+ if (Buffer.byteLength(socket) > 95) {
67
+ throw new Error('Local IPC fallback root is too long for a socket path.');
68
+ }
65
69
  if ((0, node_fs_1.existsSync)(directory)) {
66
70
  const status = (0, node_fs_1.lstatSync)(directory);
67
71
  if (status.isSymbolicLink() ||
@@ -81,7 +85,32 @@ function createLocalIpcPath(base, identity) {
81
85
  (status.mode & 0o777) !== 0o700) {
82
86
  throw new Error('Local IPC directory is not current-user private.');
83
87
  }
84
- return (0, node_path_1.join)(directory, `.ebk-${digest}.sock`);
88
+ return socket;
89
+ }
90
+ /**
91
+ * Parent of the short per-base IPC directories. The framework's own test
92
+ * runners set `EBK_LOCAL_IPC_FALLBACK_ROOT` to a private per-run directory
93
+ * they remove afterwards, so long temporary bases still take this fallback
94
+ * without leaving one `/tmp` directory per base. An override must already be
95
+ * a current-user private directory; anything else fails closed.
96
+ */
97
+ function localIpcFallbackRoot(uid) {
98
+ const override = process.env.EBK_LOCAL_IPC_FALLBACK_ROOT;
99
+ if (override === undefined)
100
+ return '/tmp';
101
+ if (!(0, node_path_1.isAbsolute)(override)) {
102
+ throw new Error('Local IPC fallback root must be an absolute path.');
103
+ }
104
+ const root = (0, node_path_1.resolve)(override);
105
+ const status = (0, node_fs_1.lstatSync)(root, { throwIfNoEntry: false });
106
+ if (!status ||
107
+ status.isSymbolicLink() ||
108
+ !status.isDirectory() ||
109
+ status.uid !== uid ||
110
+ (status.mode & 0o777) !== 0o700) {
111
+ throw new Error('Local IPC fallback root is not current-user private.');
112
+ }
113
+ return root;
85
114
  }
86
115
  function openssl(args, cwd) {
87
116
  (0, node_child_process_1.execFileSync)('openssl', args, { cwd, stdio: 'pipe' });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Operating-system trust-store plumbing shared by `ebk dev setup --trust` and
3
+ * `ebk dev doctor`. Every command goes through an injectable runner so the
4
+ * unit proofs assert exact argv without touching a real trust store.
5
+ */
6
+ export declare const EBK_LOCAL_ROOT_LABEL = "Empire Builder Kit Local Root";
7
+ export interface TrustCommandResult {
8
+ readonly error?: NodeJS.ErrnoException;
9
+ readonly status: number | null;
10
+ readonly stderr: string;
11
+ readonly stdout: string;
12
+ }
13
+ export interface TrustCommandOptions {
14
+ readonly env?: NodeJS.ProcessEnv;
15
+ /**
16
+ * Inherit the terminal so the operating system can show its own consent or
17
+ * credential prompt, which the human answers.
18
+ */
19
+ readonly interactive?: boolean;
20
+ readonly timeoutMs?: number;
21
+ }
22
+ export type TrustCommandRunner = (command: string, args: readonly string[], options?: TrustCommandOptions) => TrustCommandResult;
23
+ export declare const runTrustCommand: TrustCommandRunner;
24
+ export declare function trustCommandSucceeded(result: TrustCommandResult): boolean;
25
+ export declare function trustCommandMissing(result: TrustCommandResult): boolean;
26
+ /** Uppercase hexadecimal SHA-1, the key macOS and Windows use for trust. */
27
+ export declare function certificateSha1(certificatePath: string): string;
28
+ export declare function macosLoginKeychain(homeDirectory: string): string;
29
+ /**
30
+ * The same effect check on setup readback and in doctor: the exact leaf and
31
+ * intermediate must evaluate for TLS server use and the exact host through the
32
+ * user's effective trust settings.
33
+ */
34
+ export declare function macosVerifyCertArguments(leafCertificatePath: string, intermediateCertificatePath: string, hostname: string): string[];
35
+ /**
36
+ * The NSS shared database Chromium reads on Linux. Since M146 Chromium
37
+ * defaults to `$HOME/.local/share/pki/nssdb`, but an existing legacy
38
+ * `$HOME/.pki/nssdb` takes precedence
39
+ * (chromium/src docs/linux/cert_management.md).
40
+ */
41
+ export declare function chromiumNssDatabase(homeDirectory: string, pathExists?: (path: string) => boolean): string;
42
+ export declare function shellQuote(value: string): string;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runTrustCommand = exports.EBK_LOCAL_ROOT_LABEL = void 0;
4
+ exports.trustCommandSucceeded = trustCommandSucceeded;
5
+ exports.trustCommandMissing = trustCommandMissing;
6
+ exports.certificateSha1 = certificateSha1;
7
+ exports.macosLoginKeychain = macosLoginKeychain;
8
+ exports.macosVerifyCertArguments = macosVerifyCertArguments;
9
+ exports.chromiumNssDatabase = chromiumNssDatabase;
10
+ exports.shellQuote = shellQuote;
11
+ const node_child_process_1 = require("node:child_process");
12
+ const node_crypto_1 = require("node:crypto");
13
+ const node_fs_1 = require("node:fs");
14
+ const node_path_1 = require("node:path");
15
+ /**
16
+ * Operating-system trust-store plumbing shared by `ebk dev setup --trust` and
17
+ * `ebk dev doctor`. Every command goes through an injectable runner so the
18
+ * unit proofs assert exact argv without touching a real trust store.
19
+ */
20
+ exports.EBK_LOCAL_ROOT_LABEL = 'Empire Builder Kit Local Root';
21
+ const runTrustCommand = (command, args, options = {}) => {
22
+ const result = (0, node_child_process_1.spawnSync)(command, [...args], {
23
+ encoding: 'utf8',
24
+ ...(options.env ? { env: options.env } : {}),
25
+ stdio: options.interactive ? 'inherit' : ['ignore', 'pipe', 'pipe'],
26
+ ...(options.timeoutMs ? { timeout: options.timeoutMs } : {}),
27
+ windowsHide: true,
28
+ });
29
+ return {
30
+ ...(result.error
31
+ ? { error: result.error }
32
+ : undefined),
33
+ status: result.status,
34
+ stderr: typeof result.stderr === 'string' ? result.stderr : '',
35
+ stdout: typeof result.stdout === 'string' ? result.stdout : '',
36
+ };
37
+ };
38
+ exports.runTrustCommand = runTrustCommand;
39
+ function trustCommandSucceeded(result) {
40
+ return !result.error && result.status === 0;
41
+ }
42
+ function trustCommandMissing(result) {
43
+ return result.error?.code === 'ENOENT';
44
+ }
45
+ /** Uppercase hexadecimal SHA-1, the key macOS and Windows use for trust. */
46
+ function certificateSha1(certificatePath) {
47
+ return new node_crypto_1.X509Certificate((0, node_fs_1.readFileSync)(certificatePath)).fingerprint.replace(/:/g, '');
48
+ }
49
+ function macosLoginKeychain(homeDirectory) {
50
+ return (0, node_path_1.join)(homeDirectory, 'Library', 'Keychains', 'login.keychain-db');
51
+ }
52
+ /**
53
+ * The same effect check on setup readback and in doctor: the exact leaf and
54
+ * intermediate must evaluate for TLS server use and the exact host through the
55
+ * user's effective trust settings.
56
+ */
57
+ function macosVerifyCertArguments(leafCertificatePath, intermediateCertificatePath, hostname) {
58
+ return [
59
+ 'verify-cert',
60
+ '-L',
61
+ '-q',
62
+ '-c',
63
+ leafCertificatePath,
64
+ '-c',
65
+ intermediateCertificatePath,
66
+ '-p',
67
+ 'ssl',
68
+ '-n',
69
+ hostname,
70
+ ];
71
+ }
72
+ /**
73
+ * The NSS shared database Chromium reads on Linux. Since M146 Chromium
74
+ * defaults to `$HOME/.local/share/pki/nssdb`, but an existing legacy
75
+ * `$HOME/.pki/nssdb` takes precedence
76
+ * (chromium/src docs/linux/cert_management.md).
77
+ */
78
+ function chromiumNssDatabase(homeDirectory, pathExists = node_fs_1.existsSync) {
79
+ const legacy = (0, node_path_1.join)(homeDirectory, '.pki', 'nssdb');
80
+ return pathExists(legacy)
81
+ ? legacy
82
+ : (0, node_path_1.join)(homeDirectory, '.local', 'share', 'pki', 'nssdb');
83
+ }
84
+ function shellQuote(value) {
85
+ return `'${value.replace(/'/g, `'\\''`)}'`;
86
+ }
87
+ //# sourceMappingURL=trust-store.js.map
@@ -6,6 +6,12 @@ export interface CompositionOwnedPath {
6
6
  path: string;
7
7
  }
8
8
  export interface RecordCompositionOwnershipOptions {
9
+ /**
10
+ * Lets this call change a recorded Function's access. Only the generator
11
+ * that rewrites the Function's managed infrastructure in the same run may
12
+ * set it; every other writer keeps a Function's recorded access.
13
+ */
14
+ allowAccessChange?: boolean;
9
15
  compositions: GeneratedCompositionOwnership[];
10
16
  foundation?: GeneratedOwnershipRecord['foundation'];
11
17
  paths: CompositionOwnedPath[];
@@ -17,4 +23,5 @@ export declare function restampProductSliceOwnership(tree: Tree, slice: string,
17
23
  }): void;
18
24
  export declare function restampFoundationOwnership(tree: Tree): void;
19
25
  export declare function restampWorkspaceOwnership(tree: Tree): void;
26
+ export declare function restampSiteOwnership(tree: Tree): void;
20
27
  export declare function recordCompositionOwnership(tree: Tree, options: RecordCompositionOwnershipOptions): void;