chainlesschain 0.143.0 → 0.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/sso-manager.js
CHANGED
|
@@ -1171,3 +1171,343 @@ export function getSsoManagerStatsV2() {
|
|
|
1171
1171
|
loginsByStatus,
|
|
1172
1172
|
};
|
|
1173
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
// =====================================================================
|
|
1176
|
+
// sso-manager V2 governance overlay (iter19)
|
|
1177
|
+
// =====================================================================
|
|
1178
|
+
export const SSOGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1179
|
+
PENDING: "pending",
|
|
1180
|
+
ACTIVE: "active",
|
|
1181
|
+
SUSPENDED: "suspended",
|
|
1182
|
+
ARCHIVED: "archived",
|
|
1183
|
+
});
|
|
1184
|
+
export const SSOGOV_LOGIN_LIFECYCLE_V2 = Object.freeze({
|
|
1185
|
+
QUEUED: "queued",
|
|
1186
|
+
AUTHENTICATING: "authenticating",
|
|
1187
|
+
AUTHENTICATED: "authenticated",
|
|
1188
|
+
FAILED: "failed",
|
|
1189
|
+
CANCELLED: "cancelled",
|
|
1190
|
+
});
|
|
1191
|
+
const _ssogovPTrans = new Map([
|
|
1192
|
+
[
|
|
1193
|
+
SSOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1194
|
+
new Set([
|
|
1195
|
+
SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1196
|
+
SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1197
|
+
]),
|
|
1198
|
+
],
|
|
1199
|
+
[
|
|
1200
|
+
SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1201
|
+
new Set([
|
|
1202
|
+
SSOGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1203
|
+
SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1204
|
+
]),
|
|
1205
|
+
],
|
|
1206
|
+
[
|
|
1207
|
+
SSOGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1208
|
+
new Set([
|
|
1209
|
+
SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1210
|
+
SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1211
|
+
]),
|
|
1212
|
+
],
|
|
1213
|
+
[SSOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1214
|
+
]);
|
|
1215
|
+
const _ssogovPTerminal = new Set([SSOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1216
|
+
const _ssogovJTrans = new Map([
|
|
1217
|
+
[
|
|
1218
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED,
|
|
1219
|
+
new Set([
|
|
1220
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING,
|
|
1221
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED,
|
|
1222
|
+
]),
|
|
1223
|
+
],
|
|
1224
|
+
[
|
|
1225
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING,
|
|
1226
|
+
new Set([
|
|
1227
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED,
|
|
1228
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.FAILED,
|
|
1229
|
+
SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED,
|
|
1230
|
+
]),
|
|
1231
|
+
],
|
|
1232
|
+
[SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED, new Set()],
|
|
1233
|
+
[SSOGOV_LOGIN_LIFECYCLE_V2.FAILED, new Set()],
|
|
1234
|
+
[SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1235
|
+
]);
|
|
1236
|
+
const _ssogovPsV2 = new Map();
|
|
1237
|
+
const _ssogovJsV2 = new Map();
|
|
1238
|
+
let _ssogovMaxActive = 8,
|
|
1239
|
+
_ssogovMaxPending = 30,
|
|
1240
|
+
_ssogovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1241
|
+
_ssogovStuckMs = 60 * 1000;
|
|
1242
|
+
function _ssogovPos(n, label) {
|
|
1243
|
+
const v = Math.floor(Number(n));
|
|
1244
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1245
|
+
throw new Error(`${label} must be positive integer`);
|
|
1246
|
+
return v;
|
|
1247
|
+
}
|
|
1248
|
+
function _ssogovCheckP(from, to) {
|
|
1249
|
+
const a = _ssogovPTrans.get(from);
|
|
1250
|
+
if (!a || !a.has(to))
|
|
1251
|
+
throw new Error(`invalid ssogov profile transition ${from} → ${to}`);
|
|
1252
|
+
}
|
|
1253
|
+
function _ssogovCheckJ(from, to) {
|
|
1254
|
+
const a = _ssogovJTrans.get(from);
|
|
1255
|
+
if (!a || !a.has(to))
|
|
1256
|
+
throw new Error(`invalid ssogov login transition ${from} → ${to}`);
|
|
1257
|
+
}
|
|
1258
|
+
function _ssogovCountActive(owner) {
|
|
1259
|
+
let c = 0;
|
|
1260
|
+
for (const p of _ssogovPsV2.values())
|
|
1261
|
+
if (p.owner === owner && p.status === SSOGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1262
|
+
c++;
|
|
1263
|
+
return c;
|
|
1264
|
+
}
|
|
1265
|
+
function _ssogovCountPending(profileId) {
|
|
1266
|
+
let c = 0;
|
|
1267
|
+
for (const j of _ssogovJsV2.values())
|
|
1268
|
+
if (
|
|
1269
|
+
j.profileId === profileId &&
|
|
1270
|
+
(j.status === SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED ||
|
|
1271
|
+
j.status === SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING)
|
|
1272
|
+
)
|
|
1273
|
+
c++;
|
|
1274
|
+
return c;
|
|
1275
|
+
}
|
|
1276
|
+
export function setMaxActiveSsogovProfilesPerOwnerV2(n) {
|
|
1277
|
+
_ssogovMaxActive = _ssogovPos(n, "maxActiveSsogovProfilesPerOwner");
|
|
1278
|
+
}
|
|
1279
|
+
export function getMaxActiveSsogovProfilesPerOwnerV2() {
|
|
1280
|
+
return _ssogovMaxActive;
|
|
1281
|
+
}
|
|
1282
|
+
export function setMaxPendingSsogovLoginsPerProfileV2(n) {
|
|
1283
|
+
_ssogovMaxPending = _ssogovPos(n, "maxPendingSsogovLoginsPerProfile");
|
|
1284
|
+
}
|
|
1285
|
+
export function getMaxPendingSsogovLoginsPerProfileV2() {
|
|
1286
|
+
return _ssogovMaxPending;
|
|
1287
|
+
}
|
|
1288
|
+
export function setSsogovProfileIdleMsV2(n) {
|
|
1289
|
+
_ssogovIdleMs = _ssogovPos(n, "ssogovProfileIdleMs");
|
|
1290
|
+
}
|
|
1291
|
+
export function getSsogovProfileIdleMsV2() {
|
|
1292
|
+
return _ssogovIdleMs;
|
|
1293
|
+
}
|
|
1294
|
+
export function setSsogovLoginStuckMsV2(n) {
|
|
1295
|
+
_ssogovStuckMs = _ssogovPos(n, "ssogovLoginStuckMs");
|
|
1296
|
+
}
|
|
1297
|
+
export function getSsogovLoginStuckMsV2() {
|
|
1298
|
+
return _ssogovStuckMs;
|
|
1299
|
+
}
|
|
1300
|
+
export function _resetStateSsoManagerGovV2() {
|
|
1301
|
+
_ssogovPsV2.clear();
|
|
1302
|
+
_ssogovJsV2.clear();
|
|
1303
|
+
_ssogovMaxActive = 8;
|
|
1304
|
+
_ssogovMaxPending = 30;
|
|
1305
|
+
_ssogovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1306
|
+
_ssogovStuckMs = 60 * 1000;
|
|
1307
|
+
}
|
|
1308
|
+
export function registerSsogovProfileV2({
|
|
1309
|
+
id,
|
|
1310
|
+
owner,
|
|
1311
|
+
protocol,
|
|
1312
|
+
metadata,
|
|
1313
|
+
} = {}) {
|
|
1314
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1315
|
+
if (_ssogovPsV2.has(id))
|
|
1316
|
+
throw new Error(`ssogov profile ${id} already exists`);
|
|
1317
|
+
const now = Date.now();
|
|
1318
|
+
const p = {
|
|
1319
|
+
id,
|
|
1320
|
+
owner,
|
|
1321
|
+
protocol: protocol || "oidc",
|
|
1322
|
+
status: SSOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1323
|
+
createdAt: now,
|
|
1324
|
+
updatedAt: now,
|
|
1325
|
+
lastTouchedAt: now,
|
|
1326
|
+
activatedAt: null,
|
|
1327
|
+
archivedAt: null,
|
|
1328
|
+
metadata: { ...(metadata || {}) },
|
|
1329
|
+
};
|
|
1330
|
+
_ssogovPsV2.set(id, p);
|
|
1331
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1332
|
+
}
|
|
1333
|
+
export function activateSsogovProfileV2(id) {
|
|
1334
|
+
const p = _ssogovPsV2.get(id);
|
|
1335
|
+
if (!p) throw new Error(`ssogov profile ${id} not found`);
|
|
1336
|
+
const isInitial = p.status === SSOGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1337
|
+
_ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1338
|
+
if (isInitial && _ssogovCountActive(p.owner) >= _ssogovMaxActive)
|
|
1339
|
+
throw new Error(`max active ssogov profiles for owner ${p.owner} reached`);
|
|
1340
|
+
const now = Date.now();
|
|
1341
|
+
p.status = SSOGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1342
|
+
p.updatedAt = now;
|
|
1343
|
+
p.lastTouchedAt = now;
|
|
1344
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1345
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1346
|
+
}
|
|
1347
|
+
export function suspendSsogovProfileV2(id) {
|
|
1348
|
+
const p = _ssogovPsV2.get(id);
|
|
1349
|
+
if (!p) throw new Error(`ssogov profile ${id} not found`);
|
|
1350
|
+
_ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1351
|
+
p.status = SSOGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1352
|
+
p.updatedAt = Date.now();
|
|
1353
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1354
|
+
}
|
|
1355
|
+
export function archiveSsogovProfileV2(id) {
|
|
1356
|
+
const p = _ssogovPsV2.get(id);
|
|
1357
|
+
if (!p) throw new Error(`ssogov profile ${id} not found`);
|
|
1358
|
+
_ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1359
|
+
const now = Date.now();
|
|
1360
|
+
p.status = SSOGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1361
|
+
p.updatedAt = now;
|
|
1362
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1363
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1364
|
+
}
|
|
1365
|
+
export function touchSsogovProfileV2(id) {
|
|
1366
|
+
const p = _ssogovPsV2.get(id);
|
|
1367
|
+
if (!p) throw new Error(`ssogov profile ${id} not found`);
|
|
1368
|
+
if (_ssogovPTerminal.has(p.status))
|
|
1369
|
+
throw new Error(`cannot touch terminal ssogov profile ${id}`);
|
|
1370
|
+
const now = Date.now();
|
|
1371
|
+
p.lastTouchedAt = now;
|
|
1372
|
+
p.updatedAt = now;
|
|
1373
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1374
|
+
}
|
|
1375
|
+
export function getSsogovProfileV2(id) {
|
|
1376
|
+
const p = _ssogovPsV2.get(id);
|
|
1377
|
+
if (!p) return null;
|
|
1378
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1379
|
+
}
|
|
1380
|
+
export function listSsogovProfilesV2() {
|
|
1381
|
+
return [..._ssogovPsV2.values()].map((p) => ({
|
|
1382
|
+
...p,
|
|
1383
|
+
metadata: { ...p.metadata },
|
|
1384
|
+
}));
|
|
1385
|
+
}
|
|
1386
|
+
export function createSsogovLoginV2({ id, profileId, subject, metadata } = {}) {
|
|
1387
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1388
|
+
if (_ssogovJsV2.has(id)) throw new Error(`ssogov login ${id} already exists`);
|
|
1389
|
+
if (!_ssogovPsV2.has(profileId))
|
|
1390
|
+
throw new Error(`ssogov profile ${profileId} not found`);
|
|
1391
|
+
if (_ssogovCountPending(profileId) >= _ssogovMaxPending)
|
|
1392
|
+
throw new Error(
|
|
1393
|
+
`max pending ssogov logins for profile ${profileId} reached`,
|
|
1394
|
+
);
|
|
1395
|
+
const now = Date.now();
|
|
1396
|
+
const j = {
|
|
1397
|
+
id,
|
|
1398
|
+
profileId,
|
|
1399
|
+
subject: subject || "",
|
|
1400
|
+
status: SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED,
|
|
1401
|
+
createdAt: now,
|
|
1402
|
+
updatedAt: now,
|
|
1403
|
+
startedAt: null,
|
|
1404
|
+
settledAt: null,
|
|
1405
|
+
metadata: { ...(metadata || {}) },
|
|
1406
|
+
};
|
|
1407
|
+
_ssogovJsV2.set(id, j);
|
|
1408
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1409
|
+
}
|
|
1410
|
+
export function authenticatingSsogovLoginV2(id) {
|
|
1411
|
+
const j = _ssogovJsV2.get(id);
|
|
1412
|
+
if (!j) throw new Error(`ssogov login ${id} not found`);
|
|
1413
|
+
_ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING);
|
|
1414
|
+
const now = Date.now();
|
|
1415
|
+
j.status = SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING;
|
|
1416
|
+
j.updatedAt = now;
|
|
1417
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1418
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1419
|
+
}
|
|
1420
|
+
export function completeLoginSsogovV2(id) {
|
|
1421
|
+
const j = _ssogovJsV2.get(id);
|
|
1422
|
+
if (!j) throw new Error(`ssogov login ${id} not found`);
|
|
1423
|
+
_ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED);
|
|
1424
|
+
const now = Date.now();
|
|
1425
|
+
j.status = SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED;
|
|
1426
|
+
j.updatedAt = now;
|
|
1427
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1428
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1429
|
+
}
|
|
1430
|
+
export function failSsogovLoginV2(id, reason) {
|
|
1431
|
+
const j = _ssogovJsV2.get(id);
|
|
1432
|
+
if (!j) throw new Error(`ssogov login ${id} not found`);
|
|
1433
|
+
_ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.FAILED);
|
|
1434
|
+
const now = Date.now();
|
|
1435
|
+
j.status = SSOGOV_LOGIN_LIFECYCLE_V2.FAILED;
|
|
1436
|
+
j.updatedAt = now;
|
|
1437
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1438
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1439
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1440
|
+
}
|
|
1441
|
+
export function cancelSsogovLoginV2(id, reason) {
|
|
1442
|
+
const j = _ssogovJsV2.get(id);
|
|
1443
|
+
if (!j) throw new Error(`ssogov login ${id} not found`);
|
|
1444
|
+
_ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED);
|
|
1445
|
+
const now = Date.now();
|
|
1446
|
+
j.status = SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED;
|
|
1447
|
+
j.updatedAt = now;
|
|
1448
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1449
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1450
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1451
|
+
}
|
|
1452
|
+
export function getSsogovLoginV2(id) {
|
|
1453
|
+
const j = _ssogovJsV2.get(id);
|
|
1454
|
+
if (!j) return null;
|
|
1455
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1456
|
+
}
|
|
1457
|
+
export function listSsogovLoginsV2() {
|
|
1458
|
+
return [..._ssogovJsV2.values()].map((j) => ({
|
|
1459
|
+
...j,
|
|
1460
|
+
metadata: { ...j.metadata },
|
|
1461
|
+
}));
|
|
1462
|
+
}
|
|
1463
|
+
export function autoSuspendIdleSsogovProfilesV2({ now } = {}) {
|
|
1464
|
+
const t = now ?? Date.now();
|
|
1465
|
+
const flipped = [];
|
|
1466
|
+
for (const p of _ssogovPsV2.values())
|
|
1467
|
+
if (
|
|
1468
|
+
p.status === SSOGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1469
|
+
t - p.lastTouchedAt >= _ssogovIdleMs
|
|
1470
|
+
) {
|
|
1471
|
+
p.status = SSOGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1472
|
+
p.updatedAt = t;
|
|
1473
|
+
flipped.push(p.id);
|
|
1474
|
+
}
|
|
1475
|
+
return { flipped, count: flipped.length };
|
|
1476
|
+
}
|
|
1477
|
+
export function autoFailStuckSsogovLoginsV2({ now } = {}) {
|
|
1478
|
+
const t = now ?? Date.now();
|
|
1479
|
+
const flipped = [];
|
|
1480
|
+
for (const j of _ssogovJsV2.values())
|
|
1481
|
+
if (
|
|
1482
|
+
j.status === SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING &&
|
|
1483
|
+
j.startedAt != null &&
|
|
1484
|
+
t - j.startedAt >= _ssogovStuckMs
|
|
1485
|
+
) {
|
|
1486
|
+
j.status = SSOGOV_LOGIN_LIFECYCLE_V2.FAILED;
|
|
1487
|
+
j.updatedAt = t;
|
|
1488
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1489
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1490
|
+
flipped.push(j.id);
|
|
1491
|
+
}
|
|
1492
|
+
return { flipped, count: flipped.length };
|
|
1493
|
+
}
|
|
1494
|
+
export function getSsoManagerGovStatsV2() {
|
|
1495
|
+
const profilesByStatus = {};
|
|
1496
|
+
for (const v of Object.values(SSOGOV_PROFILE_MATURITY_V2))
|
|
1497
|
+
profilesByStatus[v] = 0;
|
|
1498
|
+
for (const p of _ssogovPsV2.values()) profilesByStatus[p.status]++;
|
|
1499
|
+
const loginsByStatus = {};
|
|
1500
|
+
for (const v of Object.values(SSOGOV_LOGIN_LIFECYCLE_V2))
|
|
1501
|
+
loginsByStatus[v] = 0;
|
|
1502
|
+
for (const j of _ssogovJsV2.values()) loginsByStatus[j.status]++;
|
|
1503
|
+
return {
|
|
1504
|
+
totalSsogovProfilesV2: _ssogovPsV2.size,
|
|
1505
|
+
totalSsogovLoginsV2: _ssogovJsV2.size,
|
|
1506
|
+
maxActiveSsogovProfilesPerOwner: _ssogovMaxActive,
|
|
1507
|
+
maxPendingSsogovLoginsPerProfile: _ssogovMaxPending,
|
|
1508
|
+
ssogovProfileIdleMs: _ssogovIdleMs,
|
|
1509
|
+
ssogovLoginStuckMs: _ssogovStuckMs,
|
|
1510
|
+
profilesByStatus,
|
|
1511
|
+
loginsByStatus,
|
|
1512
|
+
};
|
|
1513
|
+
}
|
package/src/lib/stress-tester.js
CHANGED
|
@@ -711,3 +711,345 @@ export function getStressStatsV2() {
|
|
|
711
711
|
},
|
|
712
712
|
};
|
|
713
713
|
}
|
|
714
|
+
|
|
715
|
+
// =====================================================================
|
|
716
|
+
// stress-tester V2 governance overlay (iter16)
|
|
717
|
+
// =====================================================================
|
|
718
|
+
export const STRGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
719
|
+
PENDING: "pending",
|
|
720
|
+
ACTIVE: "active",
|
|
721
|
+
STALE: "stale",
|
|
722
|
+
ARCHIVED: "archived",
|
|
723
|
+
});
|
|
724
|
+
export const STRGOV_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
725
|
+
QUEUED: "queued",
|
|
726
|
+
RUNNING: "running",
|
|
727
|
+
COMPLETED: "completed",
|
|
728
|
+
FAILED: "failed",
|
|
729
|
+
CANCELLED: "cancelled",
|
|
730
|
+
});
|
|
731
|
+
const _strgovPTrans = new Map([
|
|
732
|
+
[
|
|
733
|
+
STRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
734
|
+
new Set([
|
|
735
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
736
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
737
|
+
]),
|
|
738
|
+
],
|
|
739
|
+
[
|
|
740
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
741
|
+
new Set([
|
|
742
|
+
STRGOV_PROFILE_MATURITY_V2.STALE,
|
|
743
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
744
|
+
]),
|
|
745
|
+
],
|
|
746
|
+
[
|
|
747
|
+
STRGOV_PROFILE_MATURITY_V2.STALE,
|
|
748
|
+
new Set([
|
|
749
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
750
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
751
|
+
]),
|
|
752
|
+
],
|
|
753
|
+
[STRGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
754
|
+
]);
|
|
755
|
+
const _strgovPTerminal = new Set([STRGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
756
|
+
const _strgovJTrans = new Map([
|
|
757
|
+
[
|
|
758
|
+
STRGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
759
|
+
new Set([
|
|
760
|
+
STRGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
761
|
+
STRGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
762
|
+
]),
|
|
763
|
+
],
|
|
764
|
+
[
|
|
765
|
+
STRGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
766
|
+
new Set([
|
|
767
|
+
STRGOV_RUN_LIFECYCLE_V2.COMPLETED,
|
|
768
|
+
STRGOV_RUN_LIFECYCLE_V2.FAILED,
|
|
769
|
+
STRGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
770
|
+
]),
|
|
771
|
+
],
|
|
772
|
+
[STRGOV_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
773
|
+
[STRGOV_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
774
|
+
[STRGOV_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
775
|
+
]);
|
|
776
|
+
const _strgovPsV2 = new Map();
|
|
777
|
+
const _strgovJsV2 = new Map();
|
|
778
|
+
let _strgovMaxActive = 5,
|
|
779
|
+
_strgovMaxPending = 10,
|
|
780
|
+
_strgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
781
|
+
_strgovStuckMs = 60 * 1000;
|
|
782
|
+
function _strgovPos(n, label) {
|
|
783
|
+
const v = Math.floor(Number(n));
|
|
784
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
785
|
+
throw new Error(`${label} must be positive integer`);
|
|
786
|
+
return v;
|
|
787
|
+
}
|
|
788
|
+
function _strgovCheckP(from, to) {
|
|
789
|
+
const a = _strgovPTrans.get(from);
|
|
790
|
+
if (!a || !a.has(to))
|
|
791
|
+
throw new Error(`invalid strgov profile transition ${from} → ${to}`);
|
|
792
|
+
}
|
|
793
|
+
function _strgovCheckJ(from, to) {
|
|
794
|
+
const a = _strgovJTrans.get(from);
|
|
795
|
+
if (!a || !a.has(to))
|
|
796
|
+
throw new Error(`invalid strgov run transition ${from} → ${to}`);
|
|
797
|
+
}
|
|
798
|
+
function _strgovCountActive(owner) {
|
|
799
|
+
let c = 0;
|
|
800
|
+
for (const p of _strgovPsV2.values())
|
|
801
|
+
if (p.owner === owner && p.status === STRGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
802
|
+
c++;
|
|
803
|
+
return c;
|
|
804
|
+
}
|
|
805
|
+
function _strgovCountPending(profileId) {
|
|
806
|
+
let c = 0;
|
|
807
|
+
for (const j of _strgovJsV2.values())
|
|
808
|
+
if (
|
|
809
|
+
j.profileId === profileId &&
|
|
810
|
+
(j.status === STRGOV_RUN_LIFECYCLE_V2.QUEUED ||
|
|
811
|
+
j.status === STRGOV_RUN_LIFECYCLE_V2.RUNNING)
|
|
812
|
+
)
|
|
813
|
+
c++;
|
|
814
|
+
return c;
|
|
815
|
+
}
|
|
816
|
+
export function setMaxActiveStrgovProfilesPerOwnerV2(n) {
|
|
817
|
+
_strgovMaxActive = _strgovPos(n, "maxActiveStrgovProfilesPerOwner");
|
|
818
|
+
}
|
|
819
|
+
export function getMaxActiveStrgovProfilesPerOwnerV2() {
|
|
820
|
+
return _strgovMaxActive;
|
|
821
|
+
}
|
|
822
|
+
export function setMaxPendingStrgovRunsPerProfileV2(n) {
|
|
823
|
+
_strgovMaxPending = _strgovPos(n, "maxPendingStrgovRunsPerProfile");
|
|
824
|
+
}
|
|
825
|
+
export function getMaxPendingStrgovRunsPerProfileV2() {
|
|
826
|
+
return _strgovMaxPending;
|
|
827
|
+
}
|
|
828
|
+
export function setStrgovProfileIdleMsV2(n) {
|
|
829
|
+
_strgovIdleMs = _strgovPos(n, "strgovProfileIdleMs");
|
|
830
|
+
}
|
|
831
|
+
export function getStrgovProfileIdleMsV2() {
|
|
832
|
+
return _strgovIdleMs;
|
|
833
|
+
}
|
|
834
|
+
export function setStrgovRunStuckMsV2(n) {
|
|
835
|
+
_strgovStuckMs = _strgovPos(n, "strgovRunStuckMs");
|
|
836
|
+
}
|
|
837
|
+
export function getStrgovRunStuckMsV2() {
|
|
838
|
+
return _strgovStuckMs;
|
|
839
|
+
}
|
|
840
|
+
export function _resetStateStressTesterV2() {
|
|
841
|
+
_strgovPsV2.clear();
|
|
842
|
+
_strgovJsV2.clear();
|
|
843
|
+
_strgovMaxActive = 5;
|
|
844
|
+
_strgovMaxPending = 10;
|
|
845
|
+
_strgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
846
|
+
_strgovStuckMs = 60 * 1000;
|
|
847
|
+
}
|
|
848
|
+
export function registerStrgovProfileV2({
|
|
849
|
+
id,
|
|
850
|
+
owner,
|
|
851
|
+
scenario,
|
|
852
|
+
metadata,
|
|
853
|
+
} = {}) {
|
|
854
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
855
|
+
if (_strgovPsV2.has(id))
|
|
856
|
+
throw new Error(`strgov profile ${id} already exists`);
|
|
857
|
+
const now = Date.now();
|
|
858
|
+
const p = {
|
|
859
|
+
id,
|
|
860
|
+
owner,
|
|
861
|
+
scenario: scenario || "ramp",
|
|
862
|
+
status: STRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
863
|
+
createdAt: now,
|
|
864
|
+
updatedAt: now,
|
|
865
|
+
lastTouchedAt: now,
|
|
866
|
+
activatedAt: null,
|
|
867
|
+
archivedAt: null,
|
|
868
|
+
metadata: { ...(metadata || {}) },
|
|
869
|
+
};
|
|
870
|
+
_strgovPsV2.set(id, p);
|
|
871
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
872
|
+
}
|
|
873
|
+
export function activateStrgovProfileV2(id) {
|
|
874
|
+
const p = _strgovPsV2.get(id);
|
|
875
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
876
|
+
const isInitial = p.status === STRGOV_PROFILE_MATURITY_V2.PENDING;
|
|
877
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
878
|
+
if (isInitial && _strgovCountActive(p.owner) >= _strgovMaxActive)
|
|
879
|
+
throw new Error(`max active strgov profiles for owner ${p.owner} reached`);
|
|
880
|
+
const now = Date.now();
|
|
881
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
882
|
+
p.updatedAt = now;
|
|
883
|
+
p.lastTouchedAt = now;
|
|
884
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
885
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
886
|
+
}
|
|
887
|
+
export function staleStrgovProfileV2(id) {
|
|
888
|
+
const p = _strgovPsV2.get(id);
|
|
889
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
890
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.STALE);
|
|
891
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.STALE;
|
|
892
|
+
p.updatedAt = Date.now();
|
|
893
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
894
|
+
}
|
|
895
|
+
export function archiveStrgovProfileV2(id) {
|
|
896
|
+
const p = _strgovPsV2.get(id);
|
|
897
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
898
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
899
|
+
const now = Date.now();
|
|
900
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
901
|
+
p.updatedAt = now;
|
|
902
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
903
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
904
|
+
}
|
|
905
|
+
export function touchStrgovProfileV2(id) {
|
|
906
|
+
const p = _strgovPsV2.get(id);
|
|
907
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
908
|
+
if (_strgovPTerminal.has(p.status))
|
|
909
|
+
throw new Error(`cannot touch terminal strgov profile ${id}`);
|
|
910
|
+
const now = Date.now();
|
|
911
|
+
p.lastTouchedAt = now;
|
|
912
|
+
p.updatedAt = now;
|
|
913
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
914
|
+
}
|
|
915
|
+
export function getStrgovProfileV2(id) {
|
|
916
|
+
const p = _strgovPsV2.get(id);
|
|
917
|
+
if (!p) return null;
|
|
918
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
919
|
+
}
|
|
920
|
+
export function listStrgovProfilesV2() {
|
|
921
|
+
return [..._strgovPsV2.values()].map((p) => ({
|
|
922
|
+
...p,
|
|
923
|
+
metadata: { ...p.metadata },
|
|
924
|
+
}));
|
|
925
|
+
}
|
|
926
|
+
export function createStrgovRunV2({
|
|
927
|
+
id,
|
|
928
|
+
profileId,
|
|
929
|
+
profileRef,
|
|
930
|
+
metadata,
|
|
931
|
+
} = {}) {
|
|
932
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
933
|
+
if (_strgovJsV2.has(id)) throw new Error(`strgov run ${id} already exists`);
|
|
934
|
+
if (!_strgovPsV2.has(profileId))
|
|
935
|
+
throw new Error(`strgov profile ${profileId} not found`);
|
|
936
|
+
if (_strgovCountPending(profileId) >= _strgovMaxPending)
|
|
937
|
+
throw new Error(`max pending strgov runs for profile ${profileId} reached`);
|
|
938
|
+
const now = Date.now();
|
|
939
|
+
const j = {
|
|
940
|
+
id,
|
|
941
|
+
profileId,
|
|
942
|
+
profileRef: profileRef || "",
|
|
943
|
+
status: STRGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
944
|
+
createdAt: now,
|
|
945
|
+
updatedAt: now,
|
|
946
|
+
startedAt: null,
|
|
947
|
+
settledAt: null,
|
|
948
|
+
metadata: { ...(metadata || {}) },
|
|
949
|
+
};
|
|
950
|
+
_strgovJsV2.set(id, j);
|
|
951
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
952
|
+
}
|
|
953
|
+
export function runningStrgovRunV2(id) {
|
|
954
|
+
const j = _strgovJsV2.get(id);
|
|
955
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
956
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.RUNNING);
|
|
957
|
+
const now = Date.now();
|
|
958
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.RUNNING;
|
|
959
|
+
j.updatedAt = now;
|
|
960
|
+
if (!j.startedAt) j.startedAt = now;
|
|
961
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
962
|
+
}
|
|
963
|
+
export function completeRunStrgovV2(id) {
|
|
964
|
+
const j = _strgovJsV2.get(id);
|
|
965
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
966
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.COMPLETED);
|
|
967
|
+
const now = Date.now();
|
|
968
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.COMPLETED;
|
|
969
|
+
j.updatedAt = now;
|
|
970
|
+
if (!j.settledAt) j.settledAt = now;
|
|
971
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
972
|
+
}
|
|
973
|
+
export function failStrgovRunV2(id, reason) {
|
|
974
|
+
const j = _strgovJsV2.get(id);
|
|
975
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
976
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.FAILED);
|
|
977
|
+
const now = Date.now();
|
|
978
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
979
|
+
j.updatedAt = now;
|
|
980
|
+
if (!j.settledAt) j.settledAt = now;
|
|
981
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
982
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
983
|
+
}
|
|
984
|
+
export function cancelStrgovRunV2(id, reason) {
|
|
985
|
+
const j = _strgovJsV2.get(id);
|
|
986
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
987
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.CANCELLED);
|
|
988
|
+
const now = Date.now();
|
|
989
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.CANCELLED;
|
|
990
|
+
j.updatedAt = now;
|
|
991
|
+
if (!j.settledAt) j.settledAt = now;
|
|
992
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
993
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
994
|
+
}
|
|
995
|
+
export function getStrgovRunV2(id) {
|
|
996
|
+
const j = _strgovJsV2.get(id);
|
|
997
|
+
if (!j) return null;
|
|
998
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
999
|
+
}
|
|
1000
|
+
export function listStrgovRunsV2() {
|
|
1001
|
+
return [..._strgovJsV2.values()].map((j) => ({
|
|
1002
|
+
...j,
|
|
1003
|
+
metadata: { ...j.metadata },
|
|
1004
|
+
}));
|
|
1005
|
+
}
|
|
1006
|
+
export function autoStaleIdleStrgovProfilesV2({ now } = {}) {
|
|
1007
|
+
const t = now ?? Date.now();
|
|
1008
|
+
const flipped = [];
|
|
1009
|
+
for (const p of _strgovPsV2.values())
|
|
1010
|
+
if (
|
|
1011
|
+
p.status === STRGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1012
|
+
t - p.lastTouchedAt >= _strgovIdleMs
|
|
1013
|
+
) {
|
|
1014
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.STALE;
|
|
1015
|
+
p.updatedAt = t;
|
|
1016
|
+
flipped.push(p.id);
|
|
1017
|
+
}
|
|
1018
|
+
return { flipped, count: flipped.length };
|
|
1019
|
+
}
|
|
1020
|
+
export function autoFailStuckStrgovRunsV2({ now } = {}) {
|
|
1021
|
+
const t = now ?? Date.now();
|
|
1022
|
+
const flipped = [];
|
|
1023
|
+
for (const j of _strgovJsV2.values())
|
|
1024
|
+
if (
|
|
1025
|
+
j.status === STRGOV_RUN_LIFECYCLE_V2.RUNNING &&
|
|
1026
|
+
j.startedAt != null &&
|
|
1027
|
+
t - j.startedAt >= _strgovStuckMs
|
|
1028
|
+
) {
|
|
1029
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
1030
|
+
j.updatedAt = t;
|
|
1031
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1032
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1033
|
+
flipped.push(j.id);
|
|
1034
|
+
}
|
|
1035
|
+
return { flipped, count: flipped.length };
|
|
1036
|
+
}
|
|
1037
|
+
export function getStressTesterGovStatsV2() {
|
|
1038
|
+
const profilesByStatus = {};
|
|
1039
|
+
for (const v of Object.values(STRGOV_PROFILE_MATURITY_V2))
|
|
1040
|
+
profilesByStatus[v] = 0;
|
|
1041
|
+
for (const p of _strgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1042
|
+
const runsByStatus = {};
|
|
1043
|
+
for (const v of Object.values(STRGOV_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
|
|
1044
|
+
for (const j of _strgovJsV2.values()) runsByStatus[j.status]++;
|
|
1045
|
+
return {
|
|
1046
|
+
totalStrgovProfilesV2: _strgovPsV2.size,
|
|
1047
|
+
totalStrgovRunsV2: _strgovJsV2.size,
|
|
1048
|
+
maxActiveStrgovProfilesPerOwner: _strgovMaxActive,
|
|
1049
|
+
maxPendingStrgovRunsPerProfile: _strgovMaxPending,
|
|
1050
|
+
strgovProfileIdleMs: _strgovIdleMs,
|
|
1051
|
+
strgovRunStuckMs: _strgovStuckMs,
|
|
1052
|
+
profilesByStatus,
|
|
1053
|
+
runsByStatus,
|
|
1054
|
+
};
|
|
1055
|
+
}
|