@geek-fun/serverlessinsight 0.8.2 → 0.8.3

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 (119) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +14 -0
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
  3. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
  4. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
  5. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -0
  6. package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
  7. package/README.md +26 -18
  8. package/README.zh-CN.md +19 -6
  9. package/dist/package.json +3 -1
  10. package/dist/src/commands/deploy.js +87 -4
  11. package/dist/src/commands/destroy.js +61 -10
  12. package/dist/src/commands/forceUnlock.js +8 -0
  13. package/dist/src/commands/index.js +34 -2
  14. package/dist/src/commands/login.js +195 -0
  15. package/dist/src/commands/logout.js +17 -0
  16. package/dist/src/commands/show.js +15 -7
  17. package/dist/src/commands/whoami.js +20 -0
  18. package/dist/src/common/aliyunClient/apigwOperations.js +327 -30
  19. package/dist/src/common/aliyunClient/esOperations.js +43 -29
  20. package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
  21. package/dist/src/common/aliyunClient/ossOperations.js +165 -13
  22. package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
  23. package/dist/src/common/aliyunClient/slsOperations.js +56 -26
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
  25. package/dist/src/common/apiClient.js +102 -0
  26. package/dist/src/common/constants.js +9 -4
  27. package/dist/src/common/credentialStore.js +94 -0
  28. package/dist/src/common/credentials.js +2 -0
  29. package/dist/src/common/eventQueue.js +208 -0
  30. package/dist/src/common/hashUtils.js +87 -11
  31. package/dist/src/common/imsClient.js +1 -0
  32. package/dist/src/common/index.js +3 -0
  33. package/dist/src/common/lockManager.js +61 -54
  34. package/dist/src/common/logger.js +2 -0
  35. package/dist/src/common/polling.js +54 -0
  36. package/dist/src/common/reportResourceEvent.js +8 -0
  37. package/dist/src/common/runtimeMapper.js +11 -12
  38. package/dist/src/common/stateBackend/index.js +10 -1
  39. package/dist/src/common/stateBackend/localStateBackend.js +4 -1
  40. package/dist/src/common/stateBackend/remoteStateBackend.js +6 -3
  41. package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
  42. package/dist/src/common/stateManager.js +135 -13
  43. package/dist/src/common/tencentClient/cosOperations.js +180 -3
  44. package/dist/src/common/tencentClient/esOperations.js +110 -46
  45. package/dist/src/common/tencentClient/index.js +22 -1
  46. package/dist/src/common/tencentClient/scfOperations.js +255 -133
  47. package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
  48. package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
  49. package/dist/src/common/triggerMapper.js +36 -0
  50. package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
  51. package/dist/src/common/volcengineClient/iamOperations.js +58 -48
  52. package/dist/src/common/volcengineClient/index.js +46 -21
  53. package/dist/src/common/volcengineClient/stsOperations.js +32 -0
  54. package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
  55. package/dist/src/common/volcengineClient/tosOperations.js +78 -19
  56. package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
  57. package/dist/src/lang/en.js +84 -0
  58. package/dist/src/lang/zh-CN.js +84 -0
  59. package/dist/src/parser/eventParser.js +2 -0
  60. package/dist/src/parser/functionParser.js +96 -65
  61. package/dist/src/parser/index.js +7 -4
  62. package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
  63. package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
  64. package/dist/src/stack/aliyunStack/apigwResource.js +216 -124
  65. package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
  66. package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
  67. package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
  68. package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
  69. package/dist/src/stack/aliyunStack/deployer.js +2 -2
  70. package/dist/src/stack/aliyunStack/destroyer.js +2 -2
  71. package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
  72. package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
  73. package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
  74. package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
  75. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  76. package/dist/src/stack/aliyunStack/ossResource.js +267 -219
  77. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
  78. package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
  79. package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
  80. package/dist/src/stack/alreadyExists.js +26 -0
  81. package/dist/src/stack/ownershipTag.js +40 -0
  82. package/dist/src/stack/rfsStack/index.js +3 -1
  83. package/dist/src/stack/scfStack/cosExecutor.js +39 -1
  84. package/dist/src/stack/scfStack/cosPlanner.js +11 -1
  85. package/dist/src/stack/scfStack/cosResource.js +167 -64
  86. package/dist/src/stack/scfStack/deployer.js +2 -2
  87. package/dist/src/stack/scfStack/destroyer.js +2 -2
  88. package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
  89. package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
  90. package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
  91. package/dist/src/stack/scfStack/scfExecutor.js +39 -1
  92. package/dist/src/stack/scfStack/scfPlanner.js +12 -2
  93. package/dist/src/stack/scfStack/scfResource.js +484 -14
  94. package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
  95. package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
  96. package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
  97. package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
  98. package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
  99. package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
  100. package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
  101. package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
  102. package/dist/src/stack/volcengineStack/deployer.js +49 -14
  103. package/dist/src/stack/volcengineStack/destroyer.js +1 -1
  104. package/dist/src/stack/volcengineStack/index.js +1 -2
  105. package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
  106. package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
  107. package/dist/src/stack/volcengineStack/tosResource.js +82 -27
  108. package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
  109. package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
  110. package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
  111. package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
  112. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
  113. package/dist/src/types/domains/backend.js +1 -0
  114. package/dist/src/types/domains/state.js +29 -1
  115. package/dist/src/validator/eventSchema.js +10 -0
  116. package/dist/src/validator/functionSchema.js +37 -12
  117. package/dist/src/validator/iacSchema.js +1 -0
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +3 -1
@@ -11,8 +11,8 @@ const tdsqlcPlanner_1 = require("./tdsqlcPlanner");
11
11
  const tdsqlcExecutor_1 = require("./tdsqlcExecutor");
12
12
  const esServerlessPlanner_1 = require("./esServerlessPlanner");
13
13
  const esServerlessExecutor_1 = require("./esServerlessExecutor");
14
- const createSaveStateFn = (backend, app, service, stage) => (state) => {
15
- backend.saveState(state, app, service, stage);
14
+ const createSaveStateFn = (backend, app, service, stage) => async (state) => {
15
+ await backend.saveState(state, app, service, stage);
16
16
  };
17
17
  const handlePartialFailure = (failure) => {
18
18
  const error = failure.error;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeEsPlan = void 0;
4
+ const types_1 = require("../../types");
4
5
  const esServerlessResource_1 = require("./esServerlessResource");
5
6
  const common_1 = require("../../common");
7
+ const reportResourceEvent_1 = require("../../common/reportResourceEvent");
6
8
  const stateManager_1 = require("../../common/stateManager");
7
9
  const lang_1 = require("../../lang");
8
10
  const executeCreateAction = async (context, database, currentState) => {
@@ -87,13 +89,26 @@ const executeEsPlan = async (context, plan, databases, initialState, onStateChan
87
89
  const successfulItems = [];
88
90
  let currentState = initialState;
89
91
  for (const item of plan.items) {
92
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
93
+ type: 'resource_pre',
94
+ logicalId: item.logicalId,
95
+ resourceType: item.resourceType,
96
+ action: item.action,
97
+ ...(item.drifted ? { message: 'resource drifted' } : {}),
98
+ });
99
+ const __siStartedAt = Date.now();
90
100
  try {
91
101
  const newState = await executeSingleItem(context, item, databasesMap, currentState);
92
102
  if (newState !== null) {
93
103
  currentState = newState;
94
104
  successfulItems.push(item);
105
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
106
+ type: 'resource_complete',
107
+ logicalId: item.logicalId,
108
+ durationMs: Date.now() - __siStartedAt,
109
+ });
95
110
  if (onStateChange) {
96
- onStateChange(currentState);
111
+ await onStateChange(currentState);
97
112
  common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
98
113
  action: item.action,
99
114
  resourceId: item.logicalId,
@@ -102,6 +117,29 @@ const executeEsPlan = async (context, plan, databases, initialState, onStateChan
102
117
  }
103
118
  }
104
119
  catch (error) {
120
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
121
+ type: 'resource_failed',
122
+ logicalId: item.logicalId,
123
+ severity: 'error',
124
+ durationMs: Date.now() - __siStartedAt,
125
+ error: {
126
+ message: error instanceof Error ? error.message : String(error),
127
+ },
128
+ });
129
+ if (error instanceof types_1.PartialResourceError) {
130
+ const updatedState = error.updatedState;
131
+ if (onStateChange) {
132
+ await onStateChange(updatedState);
133
+ }
134
+ return {
135
+ state: updatedState,
136
+ partialFailure: {
137
+ failedItem: item,
138
+ error: error.cause,
139
+ successfulItems,
140
+ },
141
+ };
142
+ }
105
143
  return {
106
144
  state: currentState,
107
145
  partialFailure: {
@@ -5,6 +5,7 @@ const tencentClient_1 = require("../../common/tencentClient");
5
5
  const esServerlessTypes_1 = require("./esServerlessTypes");
6
6
  const stateManager_1 = require("../../common/stateManager");
7
7
  const hashUtils_1 = require("../../common/hashUtils");
8
+ const ownershipTag_1 = require("../ownershipTag");
8
9
  const planEsDeletion = (logicalId, definition) => ({
9
10
  logicalId,
10
11
  action: 'delete',
@@ -29,7 +30,16 @@ const generateEsPlan = async (context, state, databases) => {
29
30
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
30
31
  const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
31
32
  const desiredDefinition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
32
- if (!currentState) {
33
+ if (!currentState || currentState.status === 'tainted') {
34
+ // No usable local state: probe the provider before planning create.
35
+ // If a same-named space already exists WITHOUT our ownership tag it may
36
+ // belong to another project — fail fast in the plan instead of letting
37
+ // the executor discover it mid-deploy.
38
+ const client = (0, tencentClient_1.createTencentClient)(context);
39
+ const remoteSpace = await client.es.getSpaceByName(config.SpaceName);
40
+ if (remoteSpace && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteSpace.Tags)) {
41
+ throw new Error(`ES space ${config.SpaceName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
42
+ }
33
43
  return {
34
44
  logicalId,
35
45
  action: 'create',
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteEsResource = exports.updateEsResource = exports.readEsResource = exports.createEsResource = void 0;
4
+ const types_1 = require("../../types");
4
5
  const tencentClient_1 = require("../../common/tencentClient");
5
6
  const esServerlessTypes_1 = require("./esServerlessTypes");
6
7
  const stateManager_1 = require("../../common/stateManager");
7
8
  const common_1 = require("../../common");
8
9
  const logger_1 = require("../../common/logger");
9
10
  const lang_1 = require("../../lang");
11
+ const ownershipTag_1 = require("../ownershipTag");
12
+ const alreadyExists_1 = require("../alreadyExists");
13
+ // CreateServerlessSpaceV2 reports a duplicate space name with this error code
14
+ // (腾讯云官方文档: 空间名已存在).
15
+ const ES_SPACE_NAME_EXISTS_CODE = 'InvalidParameter.SpaceNameExist';
10
16
  const buildEsSpaceFromProvider = (info, sid) => {
11
17
  return {
12
18
  sid,
@@ -18,40 +24,99 @@ const buildEsSpaceFromProvider = (info, sid) => {
18
24
  indexCount: info.IndexCount ?? null,
19
25
  kibanaUrl: info.KibanaUrl ?? null,
20
26
  kibanaPrivateUrl: info.KibanaPrivateUrl ?? null,
27
+ indexAccessUrl: info.IndexAccessUrl ?? null,
28
+ kibanaPublicAcl: info.KibanaPublicAcl
29
+ ? {
30
+ blackIpList: info.KibanaPublicAcl.BlackIpList ?? [],
31
+ whiteIpList: info.KibanaPublicAcl.WhiteIpList ?? [],
32
+ }
33
+ : {},
34
+ kibanaEmbedUrl: info.KibanaEmbedUrl ?? null,
35
+ diDataList: info.DiDataList ?? [],
36
+ vpcInfo: info.VpcInfo?.map((v) => ({
37
+ vpcId: v.VpcId ?? null,
38
+ subnetId: v.SubnetId ?? null,
39
+ vpcUid: v.VpcUid ?? null,
40
+ subnetUid: v.SubnetUid ?? null,
41
+ availableIpAddressCount: v.AvailableIpAddressCount ?? null,
42
+ })) ?? [],
43
+ region: info.Region ?? null,
44
+ zone: info.Zone ?? null,
45
+ enableKibanaPublicAccess: info.EnableKibanaPublicAccess ?? null,
46
+ enableKibanaPrivateAccess: info.EnableKibanaPrivateAccess ?? null,
47
+ appId: info.AppId ?? null,
48
+ kibanaLanguage: info.KibanaLanguage ?? null,
49
+ clusterType: info.ClusterType ?? null,
50
+ enableMcpAccess: info.EnableMcpAccess ?? null,
51
+ mcpAccess: info.McpAccess ?? null,
52
+ tags: info.Tags?.map((t) => ({
53
+ key: t.Key,
54
+ value: t.Value,
55
+ })) ?? [],
21
56
  };
22
57
  };
23
58
  const createEsResource = async (context, database, state) => {
24
59
  const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
25
60
  const client = (0, tencentClient_1.createTencentClient)(context);
26
- const spaceId = await client.es.createSpace({
27
- SpaceName: config.SpaceName,
28
- VpcInfo: config.VpcId && config.SubnetId
29
- ? [{ VpcId: config.VpcId, SubnetId: config.SubnetId }]
30
- : undefined,
31
- Zone: config.Zone,
32
- KibanaWhiteIpList: config.KibanaWhiteIpList,
33
- });
34
- // Refresh state from provider to get all attributes
35
- const spaceInfo = await client.es.getSpace(spaceId);
36
- if (!spaceInfo) {
37
- throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
38
- }
39
61
  const definition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
40
- const sid = (0, common_1.buildSid)('tencent', 'es', context.stage, spaceId);
41
- const resourceState = {
62
+ const logicalId = `databases.${database.key}`;
63
+ const taintedResourceState = {
42
64
  mode: 'managed',
43
65
  region: context.region,
44
66
  definition,
45
- instances: [buildEsSpaceFromProvider(spaceInfo, sid)],
67
+ instances: [],
46
68
  lastUpdated: new Date().toISOString(),
47
- metadata: {
48
- spaceName: database.name,
49
- spaceId,
50
- resourceType: 'TENCENT_ES_SERVERLESS',
51
- },
69
+ status: 'tainted',
52
70
  };
53
- const logicalId = `databases.${database.key}`;
54
- return (0, stateManager_1.setResource)(state, logicalId, resourceState);
71
+ const stateAfterDependents = (0, stateManager_1.setResource)(state, logicalId, taintedResourceState);
72
+ const buildResourceState = (info) => {
73
+ const sid = (0, common_1.buildSid)('tencent', 'es', context.stage, info.SpaceId);
74
+ return {
75
+ mode: 'managed',
76
+ region: context.region,
77
+ definition,
78
+ instances: [buildEsSpaceFromProvider(info, sid)],
79
+ lastUpdated: new Date().toISOString(),
80
+ metadata: {
81
+ spaceName: database.name,
82
+ spaceId: info.SpaceId,
83
+ resourceType: 'TENCENT_ES_SERVERLESS',
84
+ },
85
+ };
86
+ };
87
+ try {
88
+ const spaceId = await client.es.createSpace({
89
+ SpaceName: config.SpaceName,
90
+ VpcInfo: config.VpcId && config.SubnetId
91
+ ? [{ VpcId: config.VpcId, SubnetId: config.SubnetId }]
92
+ : undefined,
93
+ Zone: config.Zone,
94
+ KibanaWhiteIpList: config.KibanaWhiteIpList,
95
+ Tags: [{ Key: ownershipTag_1.OWNERSHIP_TAG_KEY, Value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
96
+ });
97
+ // Refresh state from provider to get all attributes
98
+ const spaceInfo = await client.es.getSpace(spaceId);
99
+ if (!spaceInfo) {
100
+ throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
101
+ }
102
+ return (0, stateManager_1.setResource)(state, logicalId, buildResourceState(spaceInfo));
103
+ }
104
+ catch (error) {
105
+ if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, [ES_SPACE_NAME_EXISTS_CODE])) {
106
+ // Idempotent adoption: a space with this name already exists in the
107
+ // provider. Adopt it ONLY if it carries our ownership tag (proves a
108
+ // previous run of THIS stack created it — e.g. state was reset). An
109
+ // untagged same-named space may belong to another project, so it must
110
+ // fail loudly rather than silently taking it over.
111
+ const probe = await client.es.getSpaceByName(config.SpaceName);
112
+ if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.Tags)) {
113
+ logger_1.logger.info(`ES space ${config.SpaceName} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
114
+ return (0, stateManager_1.setResource)(state, logicalId, buildResourceState(probe));
115
+ }
116
+ throw new types_1.PartialResourceError(stateAfterDependents, new Error(`ES space ${config.SpaceName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`));
117
+ }
118
+ throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
119
+ }
55
120
  };
56
121
  exports.createEsResource = createEsResource;
57
122
  const readEsResource = async (context, spaceId) => {
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeFunctionPlan = void 0;
4
+ const types_1 = require("../../types");
4
5
  const scfResource_1 = require("./scfResource");
5
6
  const common_1 = require("../../common");
7
+ const reportResourceEvent_1 = require("../../common/reportResourceEvent");
6
8
  const stateManager_1 = require("../../common/stateManager");
7
9
  const lang_1 = require("../../lang");
8
10
  const executeCreateAction = async (context, fn, currentState) => {
@@ -61,13 +63,26 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
61
63
  const successfulItems = [];
62
64
  let currentState = initialState;
63
65
  for (const item of plan.items) {
66
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
67
+ type: 'resource_pre',
68
+ logicalId: item.logicalId,
69
+ resourceType: item.resourceType,
70
+ action: item.action,
71
+ ...(item.drifted ? { message: 'resource drifted' } : {}),
72
+ });
73
+ const __siStartedAt = Date.now();
64
74
  try {
65
75
  const newState = await executeSingleItem(context, item, functionsMap, currentState);
66
76
  if (newState !== null) {
67
77
  currentState = newState;
68
78
  successfulItems.push(item);
79
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
80
+ type: 'resource_complete',
81
+ logicalId: item.logicalId,
82
+ durationMs: Date.now() - __siStartedAt,
83
+ });
69
84
  if (onStateChange) {
70
- onStateChange(currentState);
85
+ await onStateChange(currentState);
71
86
  common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
72
87
  action: item.action,
73
88
  resourceId: item.logicalId,
@@ -76,6 +91,29 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
76
91
  }
77
92
  }
78
93
  catch (error) {
94
+ (0, reportResourceEvent_1.reportResourceEvent)(context, {
95
+ type: 'resource_failed',
96
+ logicalId: item.logicalId,
97
+ severity: 'error',
98
+ durationMs: Date.now() - __siStartedAt,
99
+ error: {
100
+ message: error instanceof Error ? error.message : String(error),
101
+ },
102
+ });
103
+ if (error instanceof types_1.PartialResourceError) {
104
+ const updatedState = error.updatedState;
105
+ if (onStateChange) {
106
+ await onStateChange(updatedState);
107
+ }
108
+ return {
109
+ state: updatedState,
110
+ partialFailure: {
111
+ failedItem: item,
112
+ error: error.cause,
113
+ successfulItems,
114
+ },
115
+ };
116
+ }
79
117
  return {
80
118
  state: currentState,
81
119
  partialFailure: {
@@ -5,6 +5,7 @@ const tencentClient_1 = require("../../common/tencentClient");
5
5
  const scfTypes_1 = require("./scfTypes");
6
6
  const stateManager_1 = require("../../common/stateManager");
7
7
  const hashUtils_1 = require("../../common/hashUtils");
8
+ const ownershipTag_1 = require("../ownershipTag");
8
9
  const planFunctionDeletion = (logicalId, definition) => ({
9
10
  logicalId,
10
11
  action: 'delete',
@@ -25,9 +26,18 @@ const generateFunctionPlan = async (context, state, functions) => {
25
26
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
26
27
  const config = (0, scfTypes_1.functionToScfConfig)(fn);
27
28
  const codePath = fn.code.path;
28
- const desiredCodeHash = (0, hashUtils_1.computeFileHash)(codePath);
29
+ const desiredCodeHash = await (0, hashUtils_1.computeZipContentHash)(codePath);
29
30
  const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, desiredCodeHash, fn.iam);
30
- if (!currentState) {
31
+ if (!currentState || currentState.status === 'tainted') {
32
+ // No usable local state: probe the provider before planning create.
33
+ // If a same-named function already exists WITHOUT our ownership tag it
34
+ // may belong to another project — fail fast in the plan instead of
35
+ // letting the executor discover it mid-deploy.
36
+ const client = (0, tencentClient_1.createTencentClient)(context);
37
+ const remoteFunction = await client.scf.getFunction(fn.name);
38
+ if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.Tags)) {
39
+ throw new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
40
+ }
31
41
  return {
32
42
  logicalId,
33
43
  action: 'create',