@joomengine/joomla-mcp 0.7.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/CHANGELOG.md +73 -0
- package/LICENSE +349 -0
- package/README.md +279 -0
- package/SECURITY.md +39 -0
- package/config/live-test.default.json +1206 -0
- package/config/sites.example.json +53 -0
- package/config/sites.single-site-readonly.example.json +24 -0
- package/dist/application/joomla-service.d.ts +72 -0
- package/dist/application/joomla-service.d.ts.map +1 -0
- package/dist/application/joomla-service.js +484 -0
- package/dist/application/joomla-service.js.map +1 -0
- package/dist/application/joomla-write-service.d.ts +109 -0
- package/dist/application/joomla-write-service.d.ts.map +1 -0
- package/dist/application/joomla-write-service.js +628 -0
- package/dist/application/joomla-write-service.js.map +1 -0
- package/dist/application/site-registry.d.ts +17 -0
- package/dist/application/site-registry.d.ts.map +1 -0
- package/dist/application/site-registry.js +31 -0
- package/dist/application/site-registry.js.map +1 -0
- package/dist/audit/audit-sink.d.ts +24 -0
- package/dist/audit/audit-sink.d.ts.map +1 -0
- package/dist/audit/audit-sink.js +10 -0
- package/dist/audit/audit-sink.js.map +1 -0
- package/dist/bin/joomla-mcp-http.d.ts +3 -0
- package/dist/bin/joomla-mcp-http.d.ts.map +1 -0
- package/dist/bin/joomla-mcp-http.js +65 -0
- package/dist/bin/joomla-mcp-http.js.map +1 -0
- package/dist/bin/joomla-mcp-live-test.d.ts +3 -0
- package/dist/bin/joomla-mcp-live-test.d.ts.map +1 -0
- package/dist/bin/joomla-mcp-live-test.js +10 -0
- package/dist/bin/joomla-mcp-live-test.js.map +1 -0
- package/dist/bin/joomla-mcp.d.ts +3 -0
- package/dist/bin/joomla-mcp.d.ts.map +1 -0
- package/dist/bin/joomla-mcp.js +18 -0
- package/dist/bin/joomla-mcp.js.map +1 -0
- package/dist/catalog/action-catalog.d.ts +35 -0
- package/dist/catalog/action-catalog.d.ts.map +1 -0
- package/dist/catalog/action-catalog.js +525 -0
- package/dist/catalog/action-catalog.js.map +1 -0
- package/dist/catalog/action-gates.d.ts +10 -0
- package/dist/catalog/action-gates.d.ts.map +1 -0
- package/dist/catalog/action-gates.js +18 -0
- package/dist/catalog/action-gates.js.map +1 -0
- package/dist/catalog/cli-command-targets.d.ts +20 -0
- package/dist/catalog/cli-command-targets.d.ts.map +1 -0
- package/dist/catalog/cli-command-targets.js +60 -0
- package/dist/catalog/cli-command-targets.js.map +1 -0
- package/dist/catalog/companion-actions.d.ts +30 -0
- package/dist/catalog/companion-actions.d.ts.map +1 -0
- package/dist/catalog/companion-actions.js +374 -0
- package/dist/catalog/companion-actions.js.map +1 -0
- package/dist/catalog/core.d.ts +17 -0
- package/dist/catalog/core.d.ts.map +1 -0
- package/dist/catalog/core.js +115 -0
- package/dist/catalog/core.js.map +1 -0
- package/dist/catalog/crud-bases.d.ts +8 -0
- package/dist/catalog/crud-bases.d.ts.map +1 -0
- package/dist/catalog/crud-bases.js +203 -0
- package/dist/catalog/crud-bases.js.map +1 -0
- package/dist/catalog/crud-write-fields.d.ts +11 -0
- package/dist/catalog/crud-write-fields.d.ts.map +1 -0
- package/dist/catalog/crud-write-fields.js +110 -0
- package/dist/catalog/crud-write-fields.js.map +1 -0
- package/dist/catalog/index.d.ts +7 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +7 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/catalog/source-metadata.d.ts +8 -0
- package/dist/catalog/source-metadata.d.ts.map +1 -0
- package/dist/catalog/source-metadata.js +73 -0
- package/dist/catalog/source-metadata.js.map +1 -0
- package/dist/catalog/special-reads.d.ts +4 -0
- package/dist/catalog/special-reads.d.ts.map +1 -0
- package/dist/catalog/special-reads.js +243 -0
- package/dist/catalog/special-reads.js.map +1 -0
- package/dist/catalog/special-writes.d.ts +8 -0
- package/dist/catalog/special-writes.d.ts.map +1 -0
- package/dist/catalog/special-writes.js +370 -0
- package/dist/catalog/special-writes.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +156 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +171 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +169 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/contracts/action-catalog.d.ts +134 -0
- package/dist/contracts/action-catalog.d.ts.map +1 -0
- package/dist/contracts/action-catalog.js +2 -0
- package/dist/contracts/action-catalog.js.map +1 -0
- package/dist/contracts/bounded-query.d.ts +27 -0
- package/dist/contracts/bounded-query.d.ts.map +1 -0
- package/dist/contracts/bounded-query.js +59 -0
- package/dist/contracts/bounded-query.js.map +1 -0
- package/dist/contracts/route-resolution.d.ts +3 -0
- package/dist/contracts/route-resolution.d.ts.map +1 -0
- package/dist/contracts/route-resolution.js +71 -0
- package/dist/contracts/route-resolution.js.map +1 -0
- package/dist/http/access-limits.d.ts +24 -0
- package/dist/http/access-limits.d.ts.map +1 -0
- package/dist/http/access-limits.js +86 -0
- package/dist/http/access-limits.js.map +1 -0
- package/dist/http/audit.d.ts +19 -0
- package/dist/http/audit.d.ts.map +1 -0
- package/dist/http/audit.js +10 -0
- package/dist/http/audit.js.map +1 -0
- package/dist/http/auth.d.ts +33 -0
- package/dist/http/auth.d.ts.map +1 -0
- package/dist/http/auth.js +123 -0
- package/dist/http/auth.js.map +1 -0
- package/dist/http/index.d.ts +6 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +6 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/remote-http.d.ts +47 -0
- package/dist/http/remote-http.d.ts.map +1 -0
- package/dist/http/remote-http.js +552 -0
- package/dist/http/remote-http.js.map +1 -0
- package/dist/http/request-policy.d.ts +19 -0
- package/dist/http/request-policy.d.ts.map +1 -0
- package/dist/http/request-policy.js +137 -0
- package/dist/http/request-policy.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/api/joomla-api-client.d.ts +26 -0
- package/dist/infrastructure/api/joomla-api-client.d.ts.map +1 -0
- package/dist/infrastructure/api/joomla-api-client.js +139 -0
- package/dist/infrastructure/api/joomla-api-client.js.map +1 -0
- package/dist/infrastructure/cli/joomla-cli-client.d.ts +30 -0
- package/dist/infrastructure/cli/joomla-cli-client.d.ts.map +1 -0
- package/dist/infrastructure/cli/joomla-cli-client.js +163 -0
- package/dist/infrastructure/cli/joomla-cli-client.js.map +1 -0
- package/dist/infrastructure/index.d.ts +3 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +3 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/library.d.ts +33 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +22 -0
- package/dist/library.js.map +1 -0
- package/dist/live-test/catalog.d.ts +4 -0
- package/dist/live-test/catalog.d.ts.map +1 -0
- package/dist/live-test/catalog.js +62 -0
- package/dist/live-test/catalog.js.map +1 -0
- package/dist/live-test/cli.d.ts +2 -0
- package/dist/live-test/cli.d.ts.map +1 -0
- package/dist/live-test/cli.js +305 -0
- package/dist/live-test/cli.js.map +1 -0
- package/dist/live-test/console-report.d.ts +3 -0
- package/dist/live-test/console-report.d.ts.map +1 -0
- package/dist/live-test/console-report.js +75 -0
- package/dist/live-test/console-report.js.map +1 -0
- package/dist/live-test/fixtures.d.ts +22 -0
- package/dist/live-test/fixtures.d.ts.map +1 -0
- package/dist/live-test/fixtures.js +371 -0
- package/dist/live-test/fixtures.js.map +1 -0
- package/dist/live-test/index.d.ts +9 -0
- package/dist/live-test/index.d.ts.map +1 -0
- package/dist/live-test/index.js +8 -0
- package/dist/live-test/index.js.map +1 -0
- package/dist/live-test/known-limitations.d.ts +13 -0
- package/dist/live-test/known-limitations.d.ts.map +1 -0
- package/dist/live-test/known-limitations.js +186 -0
- package/dist/live-test/known-limitations.js.map +1 -0
- package/dist/live-test/progress.d.ts +60 -0
- package/dist/live-test/progress.d.ts.map +1 -0
- package/dist/live-test/progress.js +141 -0
- package/dist/live-test/progress.js.map +1 -0
- package/dist/live-test/reporting.d.ts +7 -0
- package/dist/live-test/reporting.d.ts.map +1 -0
- package/dist/live-test/reporting.js +181 -0
- package/dist/live-test/reporting.js.map +1 -0
- package/dist/live-test/runner.d.ts +19 -0
- package/dist/live-test/runner.d.ts.map +1 -0
- package/dist/live-test/runner.js +2680 -0
- package/dist/live-test/runner.js.map +1 -0
- package/dist/live-test/scenario-config.d.ts +82 -0
- package/dist/live-test/scenario-config.d.ts.map +1 -0
- package/dist/live-test/scenario-config.js +384 -0
- package/dist/live-test/scenario-config.js.map +1 -0
- package/dist/live-test/transports.d.ts +13 -0
- package/dist/live-test/transports.d.ts.map +1 -0
- package/dist/live-test/transports.js +162 -0
- package/dist/live-test/transports.js.map +1 -0
- package/dist/live-test/types.d.ts +140 -0
- package/dist/live-test/types.d.ts.map +1 -0
- package/dist/live-test/types.js +10 -0
- package/dist/live-test/types.js.map +1 -0
- package/dist/mcp/create-server.d.ts +36 -0
- package/dist/mcp/create-server.d.ts.map +1 -0
- package/dist/mcp/create-server.js +472 -0
- package/dist/mcp/create-server.js.map +1 -0
- package/dist/security/confirmation-service.d.ts +51 -0
- package/dist/security/confirmation-service.d.ts.map +1 -0
- package/dist/security/confirmation-service.js +153 -0
- package/dist/security/confirmation-service.js.map +1 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +4 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/jwks-jwt-verifier.d.ts +15 -0
- package/dist/security/jwks-jwt-verifier.d.ts.map +1 -0
- package/dist/security/jwks-jwt-verifier.js +196 -0
- package/dist/security/jwks-jwt-verifier.js.map +1 -0
- package/dist/security/permission-grant-service.d.ts +55 -0
- package/dist/security/permission-grant-service.d.ts.map +1 -0
- package/dist/security/permission-grant-service.js +321 -0
- package/dist/security/permission-grant-service.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/docs/API_ACTIONS.md +350 -0
- package/docs/ARCHITECTURE.md +114 -0
- package/docs/CLI.md +99 -0
- package/docs/CLIENTS.md +269 -0
- package/docs/COVERAGE.md +182 -0
- package/docs/DEPLOYMENT.md +272 -0
- package/docs/FIXTURES.md +210 -0
- package/docs/LIBRARY.md +246 -0
- package/docs/LIVE_TESTING.md +409 -0
- package/docs/OPERATIONS.md +138 -0
- package/docs/PHP_COMPANION.md +221 -0
- package/docs/RECONNAISSANCE.md +104 -0
- package/docs/RELEASING.md +233 -0
- package/docs/REMOTE_HTTP.md +126 -0
- package/docs/SECURITY.md +138 -0
- package/docs/SINGLE_SITE.md +223 -0
- package/docs/TESTING.md +160 -0
- package/docs/TROUBLESHOOTING.md +98 -0
- package/docs/USAGE.md +208 -0
- package/examples/embedded-host/README.md +33 -0
- package/examples/embedded-host/http.mjs +68 -0
- package/examples/embedded-host/package.json +13 -0
- package/examples/embedded-host/stdio.mjs +24 -0
- package/package.json +119 -0
|
@@ -0,0 +1,2680 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { hostname as operatingSystemHostname, platform, arch } from 'node:os';
|
|
3
|
+
import { joomlaCrudBases } from '../catalog/crud-bases.js';
|
|
4
|
+
import { loadConfiguration } from '../config/load.js';
|
|
5
|
+
import { JOOMLA_MCP_VERSION } from '../version.js';
|
|
6
|
+
import { liveScenarioCatalog } from './catalog.js';
|
|
7
|
+
import { crudFixtureDefinitions, crudFixtureOrder, } from './fixtures.js';
|
|
8
|
+
import { configurationFingerprint, statusCounts, writeLiveTestReports, } from './reporting.js';
|
|
9
|
+
import { expandLiveScenarioValue, loadLiveScenarioConfiguration, orderedLiveScenarioRecords, resolveLiveScenarioValue, scenarioActionSelected, } from './scenario-config.js';
|
|
10
|
+
import { progressHeartbeat, safeProgressReport, withProgressOperation, } from './progress.js';
|
|
11
|
+
import { knownUpstreamLimitation, verifiedDeletionLimitation, verifiedPartialMutationLimitation, } from './known-limitations.js';
|
|
12
|
+
import { createHttpLiveSession, createStdioLiveSession, LiveMcpToolError, } from './transports.js';
|
|
13
|
+
const fixtureMediaPath = 'local-images:/joomla-mcp-live-prerequisite.png';
|
|
14
|
+
const fixturePrivacyEmail = 'fixture@example.invalid';
|
|
15
|
+
const fixturePrivacyConsentSubject = 'Joomla MCP live prerequisite consent';
|
|
16
|
+
const fixtureAdministratorOverride = Object.freeze({
|
|
17
|
+
language: 'en-GB',
|
|
18
|
+
constant: 'JOOMLA_MCP_LIVE_PREREQUISITE_ADMINISTRATOR',
|
|
19
|
+
value: 'Joomla MCP live prerequisite administrator',
|
|
20
|
+
});
|
|
21
|
+
const fixtureSiteOverride = Object.freeze({
|
|
22
|
+
language: 'en-GB',
|
|
23
|
+
constant: 'JOOMLA_MCP_LIVE_PREREQUISITE_SITE',
|
|
24
|
+
value: 'Joomla MCP live prerequisite site',
|
|
25
|
+
});
|
|
26
|
+
class BlockedError extends Error {
|
|
27
|
+
dependencyIds;
|
|
28
|
+
rootCauseId;
|
|
29
|
+
constructor(message, dependencyIds = [], rootCauseId) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'BlockedError';
|
|
32
|
+
this.dependencyIds = dependencyIds;
|
|
33
|
+
if (rootCauseId !== undefined)
|
|
34
|
+
this.rootCauseId = rootCauseId;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function runLiveTest(options, dependencies = {}) {
|
|
38
|
+
const startedAtMs = Date.now();
|
|
39
|
+
const startedAt = new Date(startedAtMs).toISOString();
|
|
40
|
+
const runId = `jmcp-${startedAt.replace(/[-:.TZ]/gu, '').slice(0, 14)}-${safeSegment(options.seed).slice(0, 12)}`;
|
|
41
|
+
const scenarioConfiguration = options.scenarioFile === undefined
|
|
42
|
+
? undefined
|
|
43
|
+
: await loadLiveScenarioConfiguration(options.scenarioFile);
|
|
44
|
+
const progress = scenarioConfiguration?.progress.enabled === false
|
|
45
|
+
? undefined
|
|
46
|
+
: dependencies.progress;
|
|
47
|
+
const heartbeatSeconds = dependencies.heartbeatSeconds ??
|
|
48
|
+
heartbeatSecondsFromEnvironment(scenarioConfiguration?.progress.heartbeatSeconds ?? 30);
|
|
49
|
+
safeProgressReport(progress, {
|
|
50
|
+
kind: 'run-start',
|
|
51
|
+
timestamp: startedAt,
|
|
52
|
+
runId,
|
|
53
|
+
message: `Starting ${scenarioConfiguration?.name ?? 'legacy catalogue'} live validation.`,
|
|
54
|
+
});
|
|
55
|
+
const configuration = await loadConfiguration(options.configurationFile);
|
|
56
|
+
const siteId = options.site ?? configuration.defaultSite;
|
|
57
|
+
const site = configuration.sites.get(siteId);
|
|
58
|
+
if (site === undefined)
|
|
59
|
+
throw new Error(`Configured Joomla site ${siteId} does not exist.`);
|
|
60
|
+
validateSelection(options, site);
|
|
61
|
+
const hostname = targetHostname(site);
|
|
62
|
+
const catalogue = liveScenarioCatalog();
|
|
63
|
+
const selected = catalogue.filter((scenario) => (scenarioConfiguration === undefined || scenarioActionSelected(scenario.id, scenarioConfiguration)) &&
|
|
64
|
+
(options.families.length === 0 ||
|
|
65
|
+
options.families.includes(scenario.domain) ||
|
|
66
|
+
options.families.some((family) => scenario.id.startsWith(`${family}.`))));
|
|
67
|
+
const attempts = [];
|
|
68
|
+
const latestAttemptByScenario = new Map();
|
|
69
|
+
const sessions = [];
|
|
70
|
+
const transportDiagnostics = [];
|
|
71
|
+
const retained = [];
|
|
72
|
+
const retentionLane = `${options.mcpTransports[0]}-${options.joomlaPaths[0]}`;
|
|
73
|
+
let activeTransport = options.mcpTransports[0];
|
|
74
|
+
let activeJoomlaPath = options.joomlaPaths[0];
|
|
75
|
+
let sequence = 0;
|
|
76
|
+
const reproduction = (scenario, mcpTransport, joomlaPath) => {
|
|
77
|
+
const argumentsList = [
|
|
78
|
+
'npx joomla-mcp-live-test',
|
|
79
|
+
'--config', options.configurationFile,
|
|
80
|
+
'--site', siteId,
|
|
81
|
+
'--profile', options.profile,
|
|
82
|
+
'--joomla-path', joomlaPath,
|
|
83
|
+
'--mcp-transport', mcpTransport,
|
|
84
|
+
'--families', scenario.domain,
|
|
85
|
+
'--seed', options.seed,
|
|
86
|
+
'--output', options.outputDirectory,
|
|
87
|
+
'--non-interactive',
|
|
88
|
+
...(isMutatingProfile(options.profile) ? ['--confirm-mutations'] : []),
|
|
89
|
+
...(options.disposable ? ['--disposable'] : []),
|
|
90
|
+
...(options.scenarioFile === undefined ? [] : ['--scenario', options.scenarioFile]),
|
|
91
|
+
];
|
|
92
|
+
return argumentsList.map(shellArgument).join(' ');
|
|
93
|
+
};
|
|
94
|
+
const recordAttempt = async (session, joomlaPath, scenario, phase, request, execute, cleanup = false) => {
|
|
95
|
+
const attemptStarted = Date.now();
|
|
96
|
+
const id = `${String(++sequence).padStart(4, '0')}-${safeSegment(session.kind)}-${safeSegment(joomlaPath)}-${safeSegment(scenario.id)}-${safeSegment(phase)}`;
|
|
97
|
+
safeProgressReport(progress, {
|
|
98
|
+
kind: 'attempt-start',
|
|
99
|
+
timestamp: new Date(attemptStarted).toISOString(),
|
|
100
|
+
attemptId: id,
|
|
101
|
+
scenarioId: scenario.id,
|
|
102
|
+
phase,
|
|
103
|
+
transport: session.kind,
|
|
104
|
+
joomlaPath,
|
|
105
|
+
elapsedMs: 0,
|
|
106
|
+
});
|
|
107
|
+
const heartbeat = progressHeartbeat(progress, {
|
|
108
|
+
attemptId: id,
|
|
109
|
+
scenarioId: scenario.id,
|
|
110
|
+
phase,
|
|
111
|
+
transport: session.kind,
|
|
112
|
+
joomlaPath,
|
|
113
|
+
}, attemptStarted, heartbeatSeconds);
|
|
114
|
+
try {
|
|
115
|
+
const outcome = await execute();
|
|
116
|
+
const durationMs = Date.now() - attemptStarted;
|
|
117
|
+
const attempt = Object.freeze({
|
|
118
|
+
id,
|
|
119
|
+
scenarioId: scenario.id,
|
|
120
|
+
title: scenario.title,
|
|
121
|
+
domain: scenario.domain,
|
|
122
|
+
risk: scenario.risk,
|
|
123
|
+
toolset: scenario.toolset,
|
|
124
|
+
operation: scenario.operation,
|
|
125
|
+
mcpTransport: session.kind,
|
|
126
|
+
joomlaPath,
|
|
127
|
+
phase,
|
|
128
|
+
status: outcome.status ?? 'PASS',
|
|
129
|
+
startedAt: new Date(attemptStarted).toISOString(),
|
|
130
|
+
durationMs,
|
|
131
|
+
request,
|
|
132
|
+
...(outcome.response === undefined ? {} : { response: outcome.response }),
|
|
133
|
+
...(outcome.expected === undefined ? {} : { expected: outcome.expected }),
|
|
134
|
+
...(outcome.actual === undefined ? {} : { actual: outcome.actual }),
|
|
135
|
+
...(outcome.reason === undefined ? {} : { reason: outcome.reason }),
|
|
136
|
+
...(outcome.knownLimitation === undefined
|
|
137
|
+
? {}
|
|
138
|
+
: {
|
|
139
|
+
failureCode: outcome.knownLimitation.code,
|
|
140
|
+
knownLimitation: outcome.knownLimitation,
|
|
141
|
+
}),
|
|
142
|
+
reproduction: reproduction(scenario, session.kind, joomlaPath),
|
|
143
|
+
...(scenario.source === undefined ? {} : { source: scenario.source }),
|
|
144
|
+
...(cleanup ? { cleanup: true } : {}),
|
|
145
|
+
});
|
|
146
|
+
attempts.push(attempt);
|
|
147
|
+
latestAttemptByScenario.set(scenario.id, id);
|
|
148
|
+
safeProgressReport(progress, {
|
|
149
|
+
kind: 'attempt-result',
|
|
150
|
+
timestamp: new Date().toISOString(),
|
|
151
|
+
attemptId: id,
|
|
152
|
+
scenarioId: scenario.id,
|
|
153
|
+
phase,
|
|
154
|
+
transport: session.kind,
|
|
155
|
+
joomlaPath,
|
|
156
|
+
elapsedMs: durationMs,
|
|
157
|
+
status: attempt.status,
|
|
158
|
+
...(attempt.reason === undefined ? {} : { reason: attempt.reason }),
|
|
159
|
+
});
|
|
160
|
+
return outcome;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const blocked = error instanceof BlockedError;
|
|
164
|
+
const knownLimitation = blocked
|
|
165
|
+
? undefined
|
|
166
|
+
: knownUpstreamLimitation({
|
|
167
|
+
options,
|
|
168
|
+
joomlaPath,
|
|
169
|
+
scenarioId: scenario.id,
|
|
170
|
+
phase,
|
|
171
|
+
error: errorMessage(error),
|
|
172
|
+
});
|
|
173
|
+
const status = knownLimitation !== undefined
|
|
174
|
+
? 'KNOWN_UPSTREAM_LIMITATION'
|
|
175
|
+
: blocked
|
|
176
|
+
? 'BLOCKED_BY_PREREQUISITE'
|
|
177
|
+
: cleanup
|
|
178
|
+
? 'CLEANUP_FAILED'
|
|
179
|
+
: 'FAIL';
|
|
180
|
+
const rootCauseId = blocked
|
|
181
|
+
? error.rootCauseId ??
|
|
182
|
+
error.dependencyIds.map((dependency) => latestAttemptByScenario.get(dependency)).find((value) => value !== undefined)
|
|
183
|
+
: undefined;
|
|
184
|
+
const durationMs = Date.now() - attemptStarted;
|
|
185
|
+
const attempt = Object.freeze({
|
|
186
|
+
id,
|
|
187
|
+
scenarioId: scenario.id,
|
|
188
|
+
title: scenario.title,
|
|
189
|
+
domain: scenario.domain,
|
|
190
|
+
risk: scenario.risk,
|
|
191
|
+
toolset: scenario.toolset,
|
|
192
|
+
operation: scenario.operation,
|
|
193
|
+
mcpTransport: session.kind,
|
|
194
|
+
joomlaPath,
|
|
195
|
+
phase,
|
|
196
|
+
status,
|
|
197
|
+
startedAt: new Date(attemptStarted).toISOString(),
|
|
198
|
+
durationMs,
|
|
199
|
+
request,
|
|
200
|
+
actual: errorResult(error),
|
|
201
|
+
reason: errorMessage(error),
|
|
202
|
+
failureCode: knownLimitation?.code ??
|
|
203
|
+
(blocked ? 'prerequisite_unavailable' : classifyError(error)),
|
|
204
|
+
...(error instanceof Error && error.stack !== undefined ? { stack: error.stack } : {}),
|
|
205
|
+
...(blocked && error.dependencyIds.length > 0 ? { dependencyIds: error.dependencyIds } : {}),
|
|
206
|
+
...(rootCauseId === undefined ? {} : { rootCauseId }),
|
|
207
|
+
...(knownLimitation === undefined ? {} : { knownLimitation }),
|
|
208
|
+
reproduction: reproduction(scenario, session.kind, joomlaPath),
|
|
209
|
+
...(scenario.source === undefined ? {} : { source: scenario.source }),
|
|
210
|
+
...(cleanup ? { cleanup: true } : {}),
|
|
211
|
+
});
|
|
212
|
+
attempts.push(attempt);
|
|
213
|
+
latestAttemptByScenario.set(scenario.id, id);
|
|
214
|
+
safeProgressReport(progress, {
|
|
215
|
+
kind: 'attempt-result',
|
|
216
|
+
timestamp: new Date().toISOString(),
|
|
217
|
+
attemptId: id,
|
|
218
|
+
scenarioId: scenario.id,
|
|
219
|
+
phase,
|
|
220
|
+
transport: session.kind,
|
|
221
|
+
joomlaPath,
|
|
222
|
+
elapsedMs: durationMs,
|
|
223
|
+
status,
|
|
224
|
+
reason: attempt.reason,
|
|
225
|
+
});
|
|
226
|
+
if (options.failFast &&
|
|
227
|
+
status !== 'BLOCKED_BY_PREREQUISITE' &&
|
|
228
|
+
status !== 'KNOWN_UPSTREAM_LIMITATION') {
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
return knownLimitation === undefined
|
|
232
|
+
? undefined
|
|
233
|
+
: {
|
|
234
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
235
|
+
reason: knownLimitation.explanation,
|
|
236
|
+
knownLimitation,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
if (heartbeat !== undefined)
|
|
241
|
+
clearInterval(heartbeat);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
try {
|
|
245
|
+
for (const kind of options.mcpTransports) {
|
|
246
|
+
activeTransport = kind;
|
|
247
|
+
safeProgressReport(progress, {
|
|
248
|
+
kind: 'session-start',
|
|
249
|
+
timestamp: new Date().toISOString(),
|
|
250
|
+
transport: kind,
|
|
251
|
+
message: 'Connecting MCP transport.',
|
|
252
|
+
});
|
|
253
|
+
const session = await withProgressOperation(progress, {
|
|
254
|
+
operationId: `connect-${kind}`,
|
|
255
|
+
operation: 'Connect and initialize MCP transport',
|
|
256
|
+
transport: kind,
|
|
257
|
+
}, heartbeatSeconds, async () => kind === 'stdio'
|
|
258
|
+
? await createStdioLiveSession({
|
|
259
|
+
configurationFile: options.configurationFile,
|
|
260
|
+
...(options.stdioCommand === undefined ? {} : { command: options.stdioCommand }),
|
|
261
|
+
...(options.stdioArguments === undefined ? {} : { arguments: options.stdioArguments }),
|
|
262
|
+
})
|
|
263
|
+
: await createHttpLiveSession(configuration));
|
|
264
|
+
sessions.push(session);
|
|
265
|
+
safeProgressReport(progress, {
|
|
266
|
+
kind: 'session-ready',
|
|
267
|
+
timestamp: new Date().toISOString(),
|
|
268
|
+
transport: kind,
|
|
269
|
+
message: 'MCP transport is ready.',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
for (const session of sessions) {
|
|
273
|
+
activeTransport = session.kind;
|
|
274
|
+
await withProgressOperation(progress, {
|
|
275
|
+
operationId: `discovery-${session.kind}`,
|
|
276
|
+
operation: 'Verify sites, capabilities, and action discovery through MCP',
|
|
277
|
+
transport: session.kind,
|
|
278
|
+
}, heartbeatSeconds, async () => verifyDiscovery(session, siteId));
|
|
279
|
+
if (isMutatingProfile(options.profile)) {
|
|
280
|
+
await withProgressOperation(progress, {
|
|
281
|
+
operationId: `permissions-${session.kind}`,
|
|
282
|
+
operation: 'Request and approve the live-test write permission grant',
|
|
283
|
+
transport: session.kind,
|
|
284
|
+
}, heartbeatSeconds, async () => grantPermissions(session, siteId, selected, options));
|
|
285
|
+
}
|
|
286
|
+
for (const joomlaPath of options.joomlaPaths) {
|
|
287
|
+
activeJoomlaPath = joomlaPath;
|
|
288
|
+
safeProgressReport(progress, {
|
|
289
|
+
kind: 'lane-start',
|
|
290
|
+
timestamp: new Date().toISOString(),
|
|
291
|
+
transport: session.kind,
|
|
292
|
+
joomlaPath,
|
|
293
|
+
message: 'Starting Joomla execution lane.',
|
|
294
|
+
});
|
|
295
|
+
const state = {
|
|
296
|
+
lane: `${session.kind}-${joomlaPath}`,
|
|
297
|
+
records: new Map(),
|
|
298
|
+
references: new Map(),
|
|
299
|
+
reads: new Map(),
|
|
300
|
+
created: [],
|
|
301
|
+
namedRecords: new Map(),
|
|
302
|
+
};
|
|
303
|
+
if (options.profile === 'read') {
|
|
304
|
+
await runReadProfile(session, joomlaPath, siteId, site, selected, state, recordAttempt);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
if (scenarioConfiguration === undefined) {
|
|
308
|
+
await runCrudProfile(session, joomlaPath, siteId, site, selected, state, recordAttempt, options);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
await runConfiguredCrudProfile(session, joomlaPath, siteId, site, selected, state, recordAttempt, options, scenarioConfiguration);
|
|
312
|
+
}
|
|
313
|
+
if (options.profile === 'full') {
|
|
314
|
+
await runSpecialProfile(session, joomlaPath, siteId, site, selected, state, recordAttempt, options);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (scenarioConfiguration !== undefined) {
|
|
318
|
+
if (options.cleanup) {
|
|
319
|
+
await cleanupConfiguredRecords(session, joomlaPath, siteId, state, recordAttempt, options, scenarioConfiguration);
|
|
320
|
+
}
|
|
321
|
+
retained.push(...state.created);
|
|
322
|
+
}
|
|
323
|
+
else if (options.cleanup || (options.retainDemo && state.lane !== retentionLane)) {
|
|
324
|
+
await cleanupRecords(session, joomlaPath, siteId, state, recordAttempt, options);
|
|
325
|
+
retained.push(...state.created);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
retained.push(...state.created);
|
|
329
|
+
}
|
|
330
|
+
safeProgressReport(progress, {
|
|
331
|
+
kind: 'lane-complete',
|
|
332
|
+
timestamp: new Date().toISOString(),
|
|
333
|
+
transport: session.kind,
|
|
334
|
+
joomlaPath,
|
|
335
|
+
message: `Completed lane with ${state.created.length} retained records.`,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
for (const session of sessions) {
|
|
340
|
+
if (!options.joomlaPaths.includes('api'))
|
|
341
|
+
continue;
|
|
342
|
+
for (const scenario of selected.filter((candidate) => candidate.sourceOnlyReason !== undefined)) {
|
|
343
|
+
const id = `${String(++sequence).padStart(4, '0')}-${session.kind}-api-${safeSegment(scenario.id)}-source-gate`;
|
|
344
|
+
safeProgressReport(progress, {
|
|
345
|
+
kind: 'attempt-start',
|
|
346
|
+
timestamp: new Date().toISOString(),
|
|
347
|
+
attemptId: id,
|
|
348
|
+
scenarioId: scenario.id,
|
|
349
|
+
phase: 'source-gate',
|
|
350
|
+
transport: session.kind,
|
|
351
|
+
joomlaPath: 'api',
|
|
352
|
+
elapsedMs: 0,
|
|
353
|
+
});
|
|
354
|
+
attempts.push(Object.freeze({
|
|
355
|
+
id,
|
|
356
|
+
scenarioId: scenario.id,
|
|
357
|
+
title: scenario.title,
|
|
358
|
+
domain: scenario.domain,
|
|
359
|
+
risk: scenario.risk,
|
|
360
|
+
toolset: scenario.toolset,
|
|
361
|
+
operation: scenario.operation,
|
|
362
|
+
mcpTransport: session.kind,
|
|
363
|
+
joomlaPath: 'api',
|
|
364
|
+
phase: 'source-gate',
|
|
365
|
+
status: 'SOURCE_ONLY_GATED',
|
|
366
|
+
startedAt: new Date().toISOString(),
|
|
367
|
+
durationMs: 0,
|
|
368
|
+
reason: scenario.sourceOnlyReason,
|
|
369
|
+
expected: 'MCP rejects the source-catalogued action before transport dispatch.',
|
|
370
|
+
reproduction: reproduction(scenario, session.kind, 'api'),
|
|
371
|
+
...(scenario.source === undefined ? {} : { source: scenario.source }),
|
|
372
|
+
}));
|
|
373
|
+
safeProgressReport(progress, {
|
|
374
|
+
kind: 'attempt-result',
|
|
375
|
+
timestamp: new Date().toISOString(),
|
|
376
|
+
attemptId: id,
|
|
377
|
+
scenarioId: scenario.id,
|
|
378
|
+
phase: 'source-gate',
|
|
379
|
+
transport: session.kind,
|
|
380
|
+
joomlaPath: 'api',
|
|
381
|
+
elapsedMs: 0,
|
|
382
|
+
status: 'SOURCE_ONLY_GATED',
|
|
383
|
+
reason: scenario.sourceOnlyReason,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
const reason = errorMessage(error);
|
|
390
|
+
const lastAttempt = attempts.at(-1);
|
|
391
|
+
const alreadyRecorded = (lastAttempt?.status === 'FAIL' || lastAttempt?.status === 'CLEANUP_FAILED') &&
|
|
392
|
+
lastAttempt.reason === reason;
|
|
393
|
+
if (!alreadyRecorded) {
|
|
394
|
+
const scenario = {
|
|
395
|
+
id: 'live-test.harness',
|
|
396
|
+
title: 'Live-test harness execution',
|
|
397
|
+
domain: 'system',
|
|
398
|
+
risk: 'read',
|
|
399
|
+
toolset: 'discovery',
|
|
400
|
+
operation: 'execute',
|
|
401
|
+
joomlaPaths: [activeJoomlaPath],
|
|
402
|
+
};
|
|
403
|
+
const attemptStarted = Date.now();
|
|
404
|
+
attempts.push(Object.freeze({
|
|
405
|
+
id: `${String(++sequence).padStart(4, '0')}-${safeSegment(activeTransport)}-${safeSegment(activeJoomlaPath)}-live-test-harness-fatal`,
|
|
406
|
+
scenarioId: scenario.id,
|
|
407
|
+
title: scenario.title,
|
|
408
|
+
domain: scenario.domain,
|
|
409
|
+
risk: scenario.risk,
|
|
410
|
+
toolset: scenario.toolset,
|
|
411
|
+
operation: scenario.operation,
|
|
412
|
+
mcpTransport: activeTransport,
|
|
413
|
+
joomlaPath: activeJoomlaPath,
|
|
414
|
+
phase: 'harness',
|
|
415
|
+
status: 'FAIL',
|
|
416
|
+
startedAt: new Date(attemptStarted).toISOString(),
|
|
417
|
+
durationMs: Date.now() - attemptStarted,
|
|
418
|
+
request: {
|
|
419
|
+
profile: options.profile,
|
|
420
|
+
joomlaPath: activeJoomlaPath,
|
|
421
|
+
mcpTransport: activeTransport,
|
|
422
|
+
},
|
|
423
|
+
actual: errorResult(error),
|
|
424
|
+
reason,
|
|
425
|
+
failureCode: classifyError(error),
|
|
426
|
+
...(error instanceof Error && error.stack !== undefined ? { stack: error.stack } : {}),
|
|
427
|
+
reproduction: reproduction(scenario, activeTransport, activeJoomlaPath),
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
finally {
|
|
432
|
+
transportDiagnostics.push(...sessions.map((session) => session.diagnostics()));
|
|
433
|
+
await Promise.allSettled(sessions.map(async (session) => {
|
|
434
|
+
await withProgressOperation(progress, {
|
|
435
|
+
operationId: `close-${session.kind}`,
|
|
436
|
+
operation: 'Close MCP transport',
|
|
437
|
+
transport: session.kind,
|
|
438
|
+
}, heartbeatSeconds, async () => session.close());
|
|
439
|
+
safeProgressReport(progress, {
|
|
440
|
+
kind: 'session-close',
|
|
441
|
+
timestamp: new Date().toISOString(),
|
|
442
|
+
transport: session.kind,
|
|
443
|
+
message: 'MCP transport closed.',
|
|
444
|
+
});
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
const completedAtMs = Date.now();
|
|
448
|
+
const counts = statusCounts(attempts);
|
|
449
|
+
const exitCode = liveTestExitCode(options, counts);
|
|
450
|
+
const summary = Object.freeze({
|
|
451
|
+
schema: 'joomengine.joomla-mcp.live-test/v1',
|
|
452
|
+
runId,
|
|
453
|
+
site: siteId,
|
|
454
|
+
hostname,
|
|
455
|
+
startedAt,
|
|
456
|
+
completedAt: new Date(completedAtMs).toISOString(),
|
|
457
|
+
durationMs: completedAtMs - startedAtMs,
|
|
458
|
+
selection: Object.freeze({
|
|
459
|
+
profile: options.profile,
|
|
460
|
+
joomlaPaths: Object.freeze([...options.joomlaPaths]),
|
|
461
|
+
mcpTransports: Object.freeze([...options.mcpTransports]),
|
|
462
|
+
families: Object.freeze([...options.families]),
|
|
463
|
+
}),
|
|
464
|
+
...(scenarioConfiguration === undefined || options.scenarioFile === undefined
|
|
465
|
+
? {}
|
|
466
|
+
: {
|
|
467
|
+
scenario: Object.freeze({
|
|
468
|
+
name: scenarioConfiguration.name,
|
|
469
|
+
file: options.scenarioFile,
|
|
470
|
+
fingerprint: configurationFingerprint(scenarioConfiguration),
|
|
471
|
+
cleanup: options.cleanup ? 'always' : 'never',
|
|
472
|
+
}),
|
|
473
|
+
}),
|
|
474
|
+
environment: Object.freeze({
|
|
475
|
+
packageVersion: JOOMLA_MCP_VERSION,
|
|
476
|
+
nodeVersion: process.version,
|
|
477
|
+
platform: platform(),
|
|
478
|
+
architecture: arch(),
|
|
479
|
+
repositoryCommit: options.repositoryCommit ?? process.env['GITHUB_SHA'] ?? 'local',
|
|
480
|
+
seed: options.seed,
|
|
481
|
+
configurationFingerprint: configurationFingerprint(configurationForFingerprint(configuration, siteId)),
|
|
482
|
+
fixtureDigests: Object.freeze({ ...(options.fixtureDigests ?? {}) }),
|
|
483
|
+
transportDiagnostics: Object.freeze(transportDiagnostics),
|
|
484
|
+
}),
|
|
485
|
+
catalogue: Object.freeze({
|
|
486
|
+
total: catalogue.length,
|
|
487
|
+
selected: selected.length,
|
|
488
|
+
sourceOnly: selected.filter((scenario) => scenario.sourceOnlyReason !== undefined).length,
|
|
489
|
+
}),
|
|
490
|
+
counts,
|
|
491
|
+
attempts: Object.freeze(attempts),
|
|
492
|
+
retainedRecords: Object.freeze(retained),
|
|
493
|
+
exitCode,
|
|
494
|
+
});
|
|
495
|
+
safeProgressReport(progress, {
|
|
496
|
+
kind: 'report-start',
|
|
497
|
+
timestamp: new Date().toISOString(),
|
|
498
|
+
message: `Writing evidence to ${options.outputDirectory}.`,
|
|
499
|
+
});
|
|
500
|
+
await withProgressOperation(progress, {
|
|
501
|
+
operationId: 'write-evidence',
|
|
502
|
+
operation: `Write live-test evidence to ${options.outputDirectory}`,
|
|
503
|
+
}, heartbeatSeconds, async () => writeLiveTestReports(options.outputDirectory, summary));
|
|
504
|
+
safeProgressReport(progress, {
|
|
505
|
+
kind: 'report-complete',
|
|
506
|
+
timestamp: new Date().toISOString(),
|
|
507
|
+
message: `Evidence written to ${options.outputDirectory}.`,
|
|
508
|
+
});
|
|
509
|
+
safeProgressReport(progress, {
|
|
510
|
+
kind: 'run-complete',
|
|
511
|
+
timestamp: new Date().toISOString(),
|
|
512
|
+
runId,
|
|
513
|
+
message: `Live validation ${exitCode === 0 ? 'passed' : 'failed'} with ${attempts.length} attempts.`,
|
|
514
|
+
});
|
|
515
|
+
return summary;
|
|
516
|
+
}
|
|
517
|
+
async function verifyDiscovery(session, site) {
|
|
518
|
+
await session.call({ name: 'joomla_sites_list', arguments: {} });
|
|
519
|
+
await session.call({ name: 'joomla_capabilities', arguments: { site } });
|
|
520
|
+
await session.call({
|
|
521
|
+
name: 'joomla_actions_search',
|
|
522
|
+
arguments: { site, includeSensitive: true, includeWrites: true },
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
async function grantPermissions(session, site, scenarios, options) {
|
|
526
|
+
if (!options.confirmMutations) {
|
|
527
|
+
throw new Error('Mutation profiles require explicit mutation confirmation.');
|
|
528
|
+
}
|
|
529
|
+
const toolsets = [...new Set(scenarios
|
|
530
|
+
.filter((scenario) => scenario.risk === 'write' || scenario.risk === 'destructive' || scenario.risk === 'high')
|
|
531
|
+
.map((scenario) => scenario.toolset)
|
|
532
|
+
.filter((toolset) => toolset.endsWith('.write') || toolset.endsWith('.admin') || toolset === 'core-update'))];
|
|
533
|
+
if (toolsets.length === 0)
|
|
534
|
+
return;
|
|
535
|
+
const requested = asRecord(await session.call({
|
|
536
|
+
name: 'joomla_permission_request',
|
|
537
|
+
arguments: {
|
|
538
|
+
site,
|
|
539
|
+
toolsets,
|
|
540
|
+
duration: '30-minutes',
|
|
541
|
+
reason: `Run approved Joomla MCP live validation profile ${options.profile}.`,
|
|
542
|
+
},
|
|
543
|
+
}));
|
|
544
|
+
const requestId = requested['requestId'];
|
|
545
|
+
const acknowledgement = requested['acknowledgement'];
|
|
546
|
+
if (typeof requestId !== 'string' || typeof acknowledgement !== 'string') {
|
|
547
|
+
throw new Error('Permission request did not return an approval contract.');
|
|
548
|
+
}
|
|
549
|
+
await session.call({
|
|
550
|
+
name: 'joomla_permission_approve',
|
|
551
|
+
arguments: { requestId, acknowledgement },
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
export function liveTestExitCode(options, counts) {
|
|
555
|
+
const requiresCompletePrerequisites = options.profile === 'full' &&
|
|
556
|
+
options.disposable &&
|
|
557
|
+
options.families.length === 0;
|
|
558
|
+
return (counts.FAIL +
|
|
559
|
+
counts.CLEANUP_FAILED +
|
|
560
|
+
(requiresCompletePrerequisites ? counts.BLOCKED_BY_PREREQUISITE : 0) >
|
|
561
|
+
0)
|
|
562
|
+
? 1
|
|
563
|
+
: 0;
|
|
564
|
+
}
|
|
565
|
+
async function runReadProfile(session, path, site, siteConfiguration, scenarios, state, record) {
|
|
566
|
+
const reads = scenarios
|
|
567
|
+
.filter((candidate) => isRead(candidate) && candidate.joomlaPaths.includes(path))
|
|
568
|
+
.sort((left, right) => readPriority(left.id) - readPriority(right.id) || left.id.localeCompare(right.id));
|
|
569
|
+
for (const scenario of reads) {
|
|
570
|
+
if (scenario.id.startsWith('joomla-update.') && siteConfiguration.api?.updateToken === undefined) {
|
|
571
|
+
await record(session, path, scenario, 'read', {}, async () => {
|
|
572
|
+
throw new BlockedError('Joomla Update actions require a separately configured X-JUpdate-Token.', ['site.api.updateToken']);
|
|
573
|
+
});
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const input = await prepareScenarioInput(session, path, scenario, 'read', { action: scenario.id }, record, () => readInput(scenario.id, state));
|
|
577
|
+
if (input === undefined)
|
|
578
|
+
continue;
|
|
579
|
+
const request = { site, action: scenario.id, input, transport: path };
|
|
580
|
+
const outcome = await record(session, path, scenario, 'read', request, async () => {
|
|
581
|
+
const response = await callRead(session, site, scenario.id, input, path);
|
|
582
|
+
validateReadResult(scenario.id, input, response);
|
|
583
|
+
state.reads.set(scenario.id, response);
|
|
584
|
+
rememberReference(scenario.id, response, state);
|
|
585
|
+
return { response };
|
|
586
|
+
});
|
|
587
|
+
if (outcome === undefined)
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
async function runCrudProfile(session, path, site, siteConfiguration, selected, state, record, options) {
|
|
592
|
+
const scenarioById = new Map(selected.map((scenario) => [scenario.id, scenario]));
|
|
593
|
+
const context = {
|
|
594
|
+
lane: state.lane,
|
|
595
|
+
seed: options.seed,
|
|
596
|
+
get: (baseId) => state.records.get(baseId),
|
|
597
|
+
reference: (baseId) => state.references.get(baseId),
|
|
598
|
+
actor: () => state.references.get('authenticated.actor') ?? state.references.get('users.users'),
|
|
599
|
+
};
|
|
600
|
+
for (const baseId of crudFixtureOrder) {
|
|
601
|
+
const listScenario = scenarioById.get(`${baseId}.list`);
|
|
602
|
+
if (listScenario !== undefined && listScenario.joomlaPaths.includes(path)) {
|
|
603
|
+
const input = { offset: 0, limit: 20 };
|
|
604
|
+
const outcome = await record(session, path, listScenario, 'list-before', input, async () => {
|
|
605
|
+
const response = await callRead(session, site, listScenario.id, input, path);
|
|
606
|
+
const first = firstEntity(response);
|
|
607
|
+
if (first !== undefined)
|
|
608
|
+
state.references.set(baseId, first);
|
|
609
|
+
state.reads.set(listScenario.id, response);
|
|
610
|
+
return { response };
|
|
611
|
+
});
|
|
612
|
+
if (outcome === undefined && options.failFast)
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const definition = crudFixtureDefinitions.get(baseId);
|
|
616
|
+
if (definition === undefined)
|
|
617
|
+
continue;
|
|
618
|
+
const missingDependency = definition.dependencies.find((dependency) => state.records.get(dependency) === undefined);
|
|
619
|
+
if (missingDependency !== undefined) {
|
|
620
|
+
for (const operation of ['create', 'get', 'update', 'delete']) {
|
|
621
|
+
const scenario = scenarioById.get(`${baseId}.${operation}`);
|
|
622
|
+
if (scenario === undefined || !scenario.joomlaPaths.includes(path))
|
|
623
|
+
continue;
|
|
624
|
+
const blocked = new BlockedError(`CRUD family ${baseId} requires a successfully created ${missingDependency} fixture.`, [`${missingDependency}.create`]);
|
|
625
|
+
await record(session, path, scenario, operation, {}, async () => { throw blocked; });
|
|
626
|
+
}
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
const createScenario = scenarioById.get(`${baseId}.create`);
|
|
630
|
+
if (createScenario !== undefined && createScenario.joomlaPaths.includes(path)) {
|
|
631
|
+
for (const purpose of ['showcase', 'deletion']) {
|
|
632
|
+
const input = await prepareScenarioInput(session, path, createScenario, `create-${purpose}`, { purpose }, record, () => ({ data: createFixtureData(baseId, definition.create(context, purpose), purpose) }));
|
|
633
|
+
if (input === undefined) {
|
|
634
|
+
if (purpose === 'showcase')
|
|
635
|
+
break;
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
const outcome = await record(session, path, createScenario, `create-${purpose}`, input, async () => {
|
|
639
|
+
const submitted = asRecord(input['data']);
|
|
640
|
+
let response;
|
|
641
|
+
let knownLimitation;
|
|
642
|
+
try {
|
|
643
|
+
response = await callWrite(session, site, createScenario.id, input, path);
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
knownLimitation = verifiedPartialMutationLimitation({
|
|
647
|
+
options,
|
|
648
|
+
joomlaPath: path,
|
|
649
|
+
scenarioId: createScenario.id,
|
|
650
|
+
phase: `create-${purpose}`,
|
|
651
|
+
error: errorMessage(error),
|
|
652
|
+
});
|
|
653
|
+
if (knownLimitation === undefined || createScenario.id !== 'messages.messages.create') {
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
656
|
+
const verification = await callRead(session, site, 'messages.messages.list', { offset: 0, limit: 100 }, path);
|
|
657
|
+
const subject = submitted['subject'];
|
|
658
|
+
const recovered = collectEntities(verification).find((entity) => looselyEqual(entity.attributes['subject'], subject));
|
|
659
|
+
if (recovered === undefined)
|
|
660
|
+
throw error;
|
|
661
|
+
response = {
|
|
662
|
+
upstreamError: errorResult(error),
|
|
663
|
+
recoveryVerification: verification,
|
|
664
|
+
result: recovered,
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
const entity = entityFromMutation(response, submitted);
|
|
668
|
+
if (entity === undefined) {
|
|
669
|
+
throw new Error(`Create action ${createScenario.id} returned no positive resource identifier.`);
|
|
670
|
+
}
|
|
671
|
+
rememberCrudCreate(baseId, purpose, entity, state);
|
|
672
|
+
return {
|
|
673
|
+
response,
|
|
674
|
+
expected: { created: true, purpose },
|
|
675
|
+
actual: { id: entity.id },
|
|
676
|
+
...(knownLimitation === undefined
|
|
677
|
+
? {}
|
|
678
|
+
: {
|
|
679
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
680
|
+
reason: knownLimitation.explanation,
|
|
681
|
+
knownLimitation,
|
|
682
|
+
}),
|
|
683
|
+
};
|
|
684
|
+
});
|
|
685
|
+
if (outcome?.status === 'KNOWN_UPSTREAM_LIMITATION' &&
|
|
686
|
+
path === 'api' &&
|
|
687
|
+
(baseId === 'modules.site' || baseId === 'modules.administrator')) {
|
|
688
|
+
await record(session, 'cli', createScenario, `create-${purpose}-api-prerequisite`, input, async () => {
|
|
689
|
+
if (siteConfiguration.cli === undefined) {
|
|
690
|
+
throw new Error(`${createScenario.id} requires the companion CLI to provision an API-readable fixture after the reviewed Joomla API create defect.`);
|
|
691
|
+
}
|
|
692
|
+
const submitted = asRecord(input['data']);
|
|
693
|
+
const response = await callWrite(session, site, createScenario.id, input, 'cli');
|
|
694
|
+
const entity = entityFromMutation(response, submitted);
|
|
695
|
+
if (entity === undefined) {
|
|
696
|
+
throw new Error(`Companion prerequisite creation for ${createScenario.id} returned no positive resource identifier.`);
|
|
697
|
+
}
|
|
698
|
+
rememberCrudCreate(baseId, purpose, entity, state);
|
|
699
|
+
return {
|
|
700
|
+
response,
|
|
701
|
+
expected: {
|
|
702
|
+
created: true,
|
|
703
|
+
purpose,
|
|
704
|
+
prerequisiteFor: `${createScenario.id} API get/update/delete`,
|
|
705
|
+
},
|
|
706
|
+
actual: { id: entity.id },
|
|
707
|
+
};
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
if (outcome === undefined && purpose === 'showcase')
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const showcase = state.records.get(baseId);
|
|
715
|
+
if (showcase === undefined) {
|
|
716
|
+
for (const [operation, phase] of [
|
|
717
|
+
['get', 'read-back-created'],
|
|
718
|
+
['update', 'update-showcase'],
|
|
719
|
+
['delete', 'delete-candidate'],
|
|
720
|
+
]) {
|
|
721
|
+
const scenario = scenarioById.get(`${baseId}.${operation}`);
|
|
722
|
+
if (scenario === undefined || !scenario.joomlaPaths.includes(path))
|
|
723
|
+
continue;
|
|
724
|
+
const blocked = new BlockedError(`${scenario.id} requires a successfully created ${baseId} showcase fixture.`, [`${baseId}.create`]);
|
|
725
|
+
await record(session, path, scenario, phase, {}, async () => { throw blocked; });
|
|
726
|
+
}
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
const getScenario = scenarioById.get(`${baseId}.get`);
|
|
730
|
+
if (getScenario !== undefined && getScenario.joomlaPaths.includes(path)) {
|
|
731
|
+
const input = await prepareScenarioInput(session, path, getScenario, 'read-back-created', { id: showcase.id }, record, () => ({ id: numericId(showcase.id) }));
|
|
732
|
+
if (input !== undefined) {
|
|
733
|
+
await record(session, path, getScenario, 'read-back-created', input, async () => {
|
|
734
|
+
const response = await callRead(session, site, getScenario.id, input, path);
|
|
735
|
+
const actual = firstEntity(response);
|
|
736
|
+
assertEntityId(actual, showcase.id, getScenario.id);
|
|
737
|
+
return { response, expected: { id: showcase.id }, actual };
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const updateScenario = scenarioById.get(`${baseId}.update`);
|
|
742
|
+
if (updateScenario !== undefined && updateScenario.joomlaPaths.includes(path)) {
|
|
743
|
+
let changes = {};
|
|
744
|
+
const input = await prepareScenarioInput(session, path, updateScenario, 'update-showcase', { id: showcase.id }, record, () => {
|
|
745
|
+
changes = definition.update(context, showcase);
|
|
746
|
+
return { id: numericId(showcase.id), data: changes };
|
|
747
|
+
});
|
|
748
|
+
if (input === undefined)
|
|
749
|
+
continue;
|
|
750
|
+
const outcome = await record(session, path, updateScenario, 'update-showcase', input, async () => {
|
|
751
|
+
try {
|
|
752
|
+
const response = await callWrite(session, site, updateScenario.id, input, path);
|
|
753
|
+
return { response, expected: changes };
|
|
754
|
+
}
|
|
755
|
+
catch (error) {
|
|
756
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
757
|
+
options,
|
|
758
|
+
joomlaPath: path,
|
|
759
|
+
scenarioId: updateScenario.id,
|
|
760
|
+
phase: 'update-showcase',
|
|
761
|
+
error: errorMessage(error),
|
|
762
|
+
});
|
|
763
|
+
if (knownLimitation === undefined || updateScenario.id !== 'languages.content.update') {
|
|
764
|
+
throw error;
|
|
765
|
+
}
|
|
766
|
+
if (getScenario === undefined || !getScenario.joomlaPaths.includes(path))
|
|
767
|
+
throw error;
|
|
768
|
+
const verification = await callRead(session, site, getScenario.id, { id: numericId(showcase.id) }, path);
|
|
769
|
+
assertChangedFields(verification, changes, baseId);
|
|
770
|
+
return {
|
|
771
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
772
|
+
response: { upstreamError: errorResult(error), verification },
|
|
773
|
+
expected: changes,
|
|
774
|
+
actual: firstEntity(verification)?.attributes,
|
|
775
|
+
reason: knownLimitation.explanation,
|
|
776
|
+
knownLimitation,
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
if (outcome !== undefined && getScenario !== undefined && getScenario.joomlaPaths.includes(path)) {
|
|
781
|
+
const readInputValue = await prepareScenarioInput(session, path, getScenario, 'read-back-updated', { id: showcase.id }, record, () => ({ id: numericId(showcase.id) }));
|
|
782
|
+
if (readInputValue !== undefined) {
|
|
783
|
+
await record(session, path, getScenario, 'read-back-updated', readInputValue, async () => {
|
|
784
|
+
const response = await callRead(session, site, getScenario.id, readInputValue, path);
|
|
785
|
+
const entity = firstEntity(response);
|
|
786
|
+
assertEntityId(entity, showcase.id, getScenario.id);
|
|
787
|
+
try {
|
|
788
|
+
const attributes = assertChangedFields(response, changes, baseId);
|
|
789
|
+
state.records.set(baseId, entity);
|
|
790
|
+
return { response, expected: changes, actual: attributes };
|
|
791
|
+
}
|
|
792
|
+
catch (error) {
|
|
793
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
794
|
+
options,
|
|
795
|
+
joomlaPath: path,
|
|
796
|
+
scenarioId: getScenario.id,
|
|
797
|
+
phase: 'read-back-updated',
|
|
798
|
+
error: errorMessage(error),
|
|
799
|
+
});
|
|
800
|
+
if (knownLimitation === undefined || baseId !== 'messages.messages')
|
|
801
|
+
throw error;
|
|
802
|
+
const recovery = await inspectMessageReplacement(session, path, site, showcase.id, changes, options.cleanup);
|
|
803
|
+
if (recovery === undefined)
|
|
804
|
+
throw error;
|
|
805
|
+
if (!recovery.replacementRemoved) {
|
|
806
|
+
rememberUnexpectedReplacement(state, baseId, recovery.replacement);
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
810
|
+
response: {
|
|
811
|
+
originalReadBack: response,
|
|
812
|
+
...recovery,
|
|
813
|
+
},
|
|
814
|
+
expected: changes,
|
|
815
|
+
actual: {
|
|
816
|
+
original: entity?.attributes,
|
|
817
|
+
replacement: recovery.replacement,
|
|
818
|
+
replacementRemoved: recovery.replacementRemoved,
|
|
819
|
+
},
|
|
820
|
+
reason: knownLimitation.explanation,
|
|
821
|
+
knownLimitation,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const deletion = state.records.get(`${baseId}#deletion`);
|
|
829
|
+
const deleteScenario = scenarioById.get(`${baseId}.delete`);
|
|
830
|
+
if (deletion !== undefined &&
|
|
831
|
+
deleteScenario !== undefined &&
|
|
832
|
+
deleteScenario.joomlaPaths.includes(path) &&
|
|
833
|
+
(options.disposable || deleteScenario.risk !== 'destructive')) {
|
|
834
|
+
const input = await prepareScenarioInput(session, path, deleteScenario, 'delete-candidate', { id: deletion.id }, record, () => ({ id: numericId(deletion.id) }));
|
|
835
|
+
if (input === undefined)
|
|
836
|
+
continue;
|
|
837
|
+
const outcome = await record(session, path, deleteScenario, 'delete-candidate', input, async () => {
|
|
838
|
+
const response = await callWrite(session, site, deleteScenario.id, input, path);
|
|
839
|
+
return { response, expected: { deletedOrTrashed: deletion.id } };
|
|
840
|
+
});
|
|
841
|
+
if (outcome !== undefined && getScenario !== undefined && getScenario.joomlaPaths.includes(path)) {
|
|
842
|
+
if (await verifyDeletion(session, path, site, getScenario, deletion, record, options)) {
|
|
843
|
+
removeRetainedRecord(state, baseId, deletion.id);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
else if (deletion !== undefined && deleteScenario !== undefined && deleteScenario.joomlaPaths.includes(path)) {
|
|
848
|
+
await addExpectedDenial(session, path, deleteScenario, 'delete-candidate', `Destructive action ${deleteScenario.id} requires --disposable.`, record);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
async function runConfiguredCrudProfile(session, path, site, siteConfiguration, selected, state, record, options, configuration) {
|
|
853
|
+
const scenarioById = new Map(selected.map((scenario) => [scenario.id, scenario]));
|
|
854
|
+
const context = {
|
|
855
|
+
lane: state.lane,
|
|
856
|
+
seed: options.seed,
|
|
857
|
+
get: (baseId) => state.records.get(baseId),
|
|
858
|
+
reference: (baseId) => state.references.get(baseId),
|
|
859
|
+
actor: () => state.references.get('authenticated.actor'),
|
|
860
|
+
};
|
|
861
|
+
await resolveAuthenticatedActor(session, path, site, selected, state, record, configuration);
|
|
862
|
+
for (const configured of orderedLiveScenarioRecords(configuration)) {
|
|
863
|
+
const { baseId, reference, definition: configuredRecord } = configured;
|
|
864
|
+
const fixture = crudFixtureDefinitions.get(baseId);
|
|
865
|
+
if (fixture === undefined)
|
|
866
|
+
continue;
|
|
867
|
+
const createScenario = scenarioById.get(`${baseId}.create`);
|
|
868
|
+
const getScenario = scenarioById.get(`${baseId}.get`);
|
|
869
|
+
const listScenario = scenarioById.get(`${baseId}.list`);
|
|
870
|
+
const updateScenario = scenarioById.get(`${baseId}.update`);
|
|
871
|
+
if (createScenario === undefined || !createScenario.joomlaPaths.includes(path))
|
|
872
|
+
continue;
|
|
873
|
+
const missingDependency = configured.dependencyReferences.find((dependency) => !state.namedRecords.has(dependency));
|
|
874
|
+
if (missingDependency !== undefined) {
|
|
875
|
+
await record(session, path, createScenario, `create-${configuredRecord.key}`, {
|
|
876
|
+
resource: reference,
|
|
877
|
+
}, async () => {
|
|
878
|
+
throw new BlockedError(`Configured resource ${reference} requires successfully verified ${missingDependency}.`, [missingDependency]);
|
|
879
|
+
});
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
let submitted;
|
|
883
|
+
try {
|
|
884
|
+
const generated = configuredRecord.generate
|
|
885
|
+
? fixture.create(context, `configured-${configuredRecord.key}`)
|
|
886
|
+
: {};
|
|
887
|
+
const configuredData = configuredRecord.data === undefined
|
|
888
|
+
? {}
|
|
889
|
+
: asRecord(resolveLiveScenarioValue(expandLiveScenarioValue(configuredRecord.data, {
|
|
890
|
+
scenario: configuration.name,
|
|
891
|
+
seed: options.seed,
|
|
892
|
+
lane: state.lane,
|
|
893
|
+
}), state.namedRecords));
|
|
894
|
+
submitted = Object.freeze({ ...generated, ...configuredData });
|
|
895
|
+
}
|
|
896
|
+
catch (error) {
|
|
897
|
+
await record(session, path, createScenario, `prepare-${configuredRecord.key}`, {
|
|
898
|
+
resource: reference,
|
|
899
|
+
}, async () => { throw error; });
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
if (listScenario !== undefined && listScenario.joomlaPaths.includes(path)) {
|
|
903
|
+
await record(session, path, listScenario, `collision-check-${configuredRecord.key}`, { resource: reference, selector: scenarioIdentity(submitted) }, async () => {
|
|
904
|
+
const existing = await findConfiguredEntityInCollection(session, site, listScenario.id, path, scenarioIdentity(submitted));
|
|
905
|
+
if (existing.entity !== undefined) {
|
|
906
|
+
throw new Error(`Configured resource ${reference} collides with existing Joomla resource ${existing.entity.id}.`);
|
|
907
|
+
}
|
|
908
|
+
return {
|
|
909
|
+
response: existing.pages,
|
|
910
|
+
expected: { collision: false },
|
|
911
|
+
actual: { collision: false },
|
|
912
|
+
};
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
const input = { data: submitted };
|
|
916
|
+
let provisional;
|
|
917
|
+
let createResponse;
|
|
918
|
+
const outcome = await record(session, path, createScenario, `create-${configuredRecord.key}`, input, async () => {
|
|
919
|
+
let response;
|
|
920
|
+
let knownLimitation;
|
|
921
|
+
try {
|
|
922
|
+
response = await callWrite(session, site, createScenario.id, input, path);
|
|
923
|
+
}
|
|
924
|
+
catch (error) {
|
|
925
|
+
knownLimitation = verifiedPartialMutationLimitation({
|
|
926
|
+
options,
|
|
927
|
+
joomlaPath: path,
|
|
928
|
+
scenarioId: createScenario.id,
|
|
929
|
+
phase: `create-${configuredRecord.key}`,
|
|
930
|
+
error: errorMessage(error),
|
|
931
|
+
});
|
|
932
|
+
if (knownLimitation === undefined || createScenario.id !== 'messages.messages.create') {
|
|
933
|
+
throw error;
|
|
934
|
+
}
|
|
935
|
+
const verification = await callRead(session, site, 'messages.messages.list', { offset: 0, limit: 100 }, path);
|
|
936
|
+
const subject = submitted['subject'];
|
|
937
|
+
const recovered = collectEntities(verification).find((entity) => looselyEqual(entity.attributes['subject'], subject));
|
|
938
|
+
if (recovered === undefined)
|
|
939
|
+
throw error;
|
|
940
|
+
response = {
|
|
941
|
+
upstreamError: errorResult(error),
|
|
942
|
+
recoveryVerification: verification,
|
|
943
|
+
result: recovered,
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
createResponse = response;
|
|
947
|
+
provisional = entityFromMutation(response, submitted);
|
|
948
|
+
if (provisional === undefined) {
|
|
949
|
+
throw new Error(`Create action ${createScenario.id} returned no candidate ID for ${reference}; ` +
|
|
950
|
+
'the mutation response is not accepted as persistence proof.');
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
response,
|
|
954
|
+
expected: { candidateId: 'positive', resource: reference },
|
|
955
|
+
actual: { candidateId: provisional.id },
|
|
956
|
+
...(knownLimitation === undefined
|
|
957
|
+
? {}
|
|
958
|
+
: {
|
|
959
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
960
|
+
reason: knownLimitation.explanation,
|
|
961
|
+
knownLimitation,
|
|
962
|
+
}),
|
|
963
|
+
};
|
|
964
|
+
});
|
|
965
|
+
if (outcome?.status === 'KNOWN_UPSTREAM_LIMITATION' &&
|
|
966
|
+
path === 'api' &&
|
|
967
|
+
(baseId === 'modules.site' || baseId === 'modules.administrator')) {
|
|
968
|
+
await record(session, 'cli', createScenario, `create-${configuredRecord.key}-api-prerequisite`, input, async () => {
|
|
969
|
+
if (siteConfiguration.cli === undefined) {
|
|
970
|
+
throw new BlockedError(`${createScenario.id} needs the companion CLI to provision an API-readable fixture ` +
|
|
971
|
+
'after Joomla API module creation fails.', ['site.cli']);
|
|
972
|
+
}
|
|
973
|
+
createResponse = await callWrite(session, site, createScenario.id, input, 'cli');
|
|
974
|
+
provisional = entityFromMutation(createResponse, submitted);
|
|
975
|
+
if (provisional === undefined) {
|
|
976
|
+
throw new Error(`Companion prerequisite creation for ${reference} returned no candidate ID.`);
|
|
977
|
+
}
|
|
978
|
+
return {
|
|
979
|
+
response: createResponse,
|
|
980
|
+
expected: { candidateId: 'positive', resource: reference },
|
|
981
|
+
actual: { candidateId: provisional.id },
|
|
982
|
+
};
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
if (provisional === undefined || getScenario === undefined || listScenario === undefined) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
const createExpectation = Object.freeze({
|
|
989
|
+
...submitted,
|
|
990
|
+
...(configuredRecord.verify === undefined
|
|
991
|
+
? {}
|
|
992
|
+
: asRecord(resolveLiveScenarioValue(expandLiveScenarioValue(configuredRecord.verify, {
|
|
993
|
+
scenario: configuration.name,
|
|
994
|
+
seed: options.seed,
|
|
995
|
+
lane: state.lane,
|
|
996
|
+
}), state.namedRecords))),
|
|
997
|
+
});
|
|
998
|
+
const verified = await verifyConfiguredResource(session, path, site, baseId, reference, configuredRecord.key, provisional.id, createExpectation, state, getScenario, listScenario, record, options);
|
|
999
|
+
if (verified === undefined)
|
|
1000
|
+
continue;
|
|
1001
|
+
state.namedRecords.set(reference, verified);
|
|
1002
|
+
if (!state.records.has(baseId))
|
|
1003
|
+
state.records.set(baseId, verified);
|
|
1004
|
+
state.created.push({
|
|
1005
|
+
lane: state.lane,
|
|
1006
|
+
family: baseId,
|
|
1007
|
+
id: verified.id,
|
|
1008
|
+
label: `${reference}: ${verified.label}`,
|
|
1009
|
+
});
|
|
1010
|
+
const updates = configuredRecord.updates.length > 0
|
|
1011
|
+
? configuredRecord.updates
|
|
1012
|
+
: configuredRecord.generate
|
|
1013
|
+
? [{
|
|
1014
|
+
name: 'generated-update',
|
|
1015
|
+
data: fixture.update(context, verified, `configured-${configuredRecord.key}-updated`),
|
|
1016
|
+
}]
|
|
1017
|
+
: [];
|
|
1018
|
+
let current = verified;
|
|
1019
|
+
for (const configuredUpdate of updates) {
|
|
1020
|
+
if (updateScenario === undefined || !updateScenario.joomlaPaths.includes(path))
|
|
1021
|
+
break;
|
|
1022
|
+
let changes;
|
|
1023
|
+
try {
|
|
1024
|
+
changes = asRecord(resolveLiveScenarioValue(expandLiveScenarioValue(configuredUpdate.data, {
|
|
1025
|
+
scenario: configuration.name,
|
|
1026
|
+
seed: options.seed,
|
|
1027
|
+
lane: state.lane,
|
|
1028
|
+
}), state.namedRecords));
|
|
1029
|
+
}
|
|
1030
|
+
catch (error) {
|
|
1031
|
+
await record(session, path, updateScenario, `prepare-${configuredRecord.key}-${configuredUpdate.name}`, {
|
|
1032
|
+
resource: reference,
|
|
1033
|
+
}, async () => { throw error; });
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
const updateInput = { id: numericId(current.id), data: changes };
|
|
1037
|
+
const updated = await record(session, path, updateScenario, `update-${configuredRecord.key}-${safeSegment(configuredUpdate.name)}`, updateInput, async () => {
|
|
1038
|
+
try {
|
|
1039
|
+
return {
|
|
1040
|
+
response: await callWrite(session, site, updateScenario.id, updateInput, path),
|
|
1041
|
+
expected: changes,
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
catch (error) {
|
|
1045
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
1046
|
+
options,
|
|
1047
|
+
joomlaPath: path,
|
|
1048
|
+
scenarioId: updateScenario.id,
|
|
1049
|
+
phase: `update-${configuredRecord.key}-${safeSegment(configuredUpdate.name)}`,
|
|
1050
|
+
error: errorMessage(error),
|
|
1051
|
+
});
|
|
1052
|
+
if (knownLimitation === undefined)
|
|
1053
|
+
throw error;
|
|
1054
|
+
return {
|
|
1055
|
+
response: { upstreamError: errorResult(error) },
|
|
1056
|
+
expected: changes,
|
|
1057
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
1058
|
+
reason: knownLimitation.explanation,
|
|
1059
|
+
knownLimitation,
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
if (updated === undefined)
|
|
1064
|
+
continue;
|
|
1065
|
+
const verifiedUpdate = await verifyConfiguredResource(session, path, site, baseId, reference, configuredRecord.key, current.id, changes, state, getScenario, listScenario, record, options, `updated-${safeSegment(configuredUpdate.name)}`);
|
|
1066
|
+
if (verifiedUpdate !== undefined) {
|
|
1067
|
+
current = verifiedUpdate;
|
|
1068
|
+
state.namedRecords.set(reference, current);
|
|
1069
|
+
if (state.records.get(baseId)?.id === current.id)
|
|
1070
|
+
state.records.set(baseId, current);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (!options.cleanup)
|
|
1075
|
+
return;
|
|
1076
|
+
for (const configured of [...orderedLiveScenarioRecords(configuration)].reverse()) {
|
|
1077
|
+
if (!configured.definition.deleteAfterVerify)
|
|
1078
|
+
continue;
|
|
1079
|
+
const entity = state.namedRecords.get(configured.reference);
|
|
1080
|
+
if (entity === undefined)
|
|
1081
|
+
continue;
|
|
1082
|
+
const deleteScenario = scenarioById.get(`${configured.baseId}.delete`);
|
|
1083
|
+
const getScenario = scenarioById.get(`${configured.baseId}.get`);
|
|
1084
|
+
if (deleteScenario === undefined ||
|
|
1085
|
+
getScenario === undefined ||
|
|
1086
|
+
!deleteScenario.joomlaPaths.includes(path) ||
|
|
1087
|
+
!getScenario.joomlaPaths.includes(path)) {
|
|
1088
|
+
continue;
|
|
1089
|
+
}
|
|
1090
|
+
const deleted = await deleteConfiguredResource(session, path, site, configured.baseId, configured.reference, entity, deleteScenario, getScenario, record, options, false);
|
|
1091
|
+
if (deleted) {
|
|
1092
|
+
state.namedRecords.delete(configured.reference);
|
|
1093
|
+
removeRetainedRecord(state, configured.baseId, entity.id);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
async function resolveAuthenticatedActor(session, path, site, selected, state, record, configuration) {
|
|
1098
|
+
if (configuration.resources['messages.messages'] === undefined)
|
|
1099
|
+
return;
|
|
1100
|
+
const listScenario = selected.find((scenario) => scenario.id === 'users.users.list');
|
|
1101
|
+
if (listScenario === undefined || !listScenario.joomlaPaths.includes(path))
|
|
1102
|
+
return;
|
|
1103
|
+
const username = configuration.target.actorUsernames?.[path];
|
|
1104
|
+
await record(session, path, listScenario, 'resolve-authenticated-actor', { username }, async () => {
|
|
1105
|
+
if (username === undefined) {
|
|
1106
|
+
throw new Error(`Private-message verification requires target.actorUsernames.${path} ` +
|
|
1107
|
+
'to name the Joomla account authenticated on this path.');
|
|
1108
|
+
}
|
|
1109
|
+
const limit = 100;
|
|
1110
|
+
for (let offset = 0; offset <= 10_000; offset += limit) {
|
|
1111
|
+
const response = await callRead(session, site, listScenario.id, { offset, limit }, path);
|
|
1112
|
+
const entities = collectEntities(response);
|
|
1113
|
+
const actor = entities.find((entity) => entity.attributes['username'] === username);
|
|
1114
|
+
if (actor !== undefined) {
|
|
1115
|
+
state.references.set('authenticated.actor', actor);
|
|
1116
|
+
return {
|
|
1117
|
+
response: {
|
|
1118
|
+
id: actor.id,
|
|
1119
|
+
username: actor.attributes['username'],
|
|
1120
|
+
pagesRead: (offset / limit) + 1,
|
|
1121
|
+
},
|
|
1122
|
+
expected: {
|
|
1123
|
+
username,
|
|
1124
|
+
purpose: 'Private messages must target the authenticated recipient.',
|
|
1125
|
+
},
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
if (entities.length < limit)
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
throw new Error(`Authenticated Joomla actor ${username} was not found by users.users.list on ${path}.`);
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
export async function inspectMessageReplacement(session, path, site, originalId, changes, cleanup) {
|
|
1135
|
+
const collection = await callRead(session, site, 'messages.messages.list', { offset: 0, limit: 100 }, path);
|
|
1136
|
+
const replacement = collectEntities(collection).find((candidate) => !looselyEqual(candidate.id, originalId) &&
|
|
1137
|
+
entityMatchesFields(candidate, changes));
|
|
1138
|
+
if (replacement === undefined)
|
|
1139
|
+
return undefined;
|
|
1140
|
+
if (!cleanup) {
|
|
1141
|
+
return {
|
|
1142
|
+
replacement,
|
|
1143
|
+
replacementVerification: collection,
|
|
1144
|
+
replacementRemoved: false,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
const replacementCleanup = await callWrite(session, site, 'messages.messages.delete', { id: numericId(replacement.id) }, path);
|
|
1148
|
+
const cleanupVerification = await callRead(session, site, 'messages.messages.list', { offset: 0, limit: 100 }, path);
|
|
1149
|
+
if (collectEntities(cleanupVerification).some((candidate) => looselyEqual(candidate.id, replacement.id))) {
|
|
1150
|
+
throw new Error(`Joomla created replacement message ${replacement.id} during PATCH and its cleanup did not remove it.`);
|
|
1151
|
+
}
|
|
1152
|
+
return {
|
|
1153
|
+
replacement,
|
|
1154
|
+
replacementVerification: collection,
|
|
1155
|
+
replacementRemoved: true,
|
|
1156
|
+
replacementCleanup,
|
|
1157
|
+
cleanupVerification,
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function rememberUnexpectedReplacement(state, family, replacement) {
|
|
1161
|
+
if (state.created.some((candidate) => candidate.family === family && looselyEqual(candidate.id, replacement.id))) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
state.created.push({
|
|
1165
|
+
lane: state.lane,
|
|
1166
|
+
family,
|
|
1167
|
+
id: replacement.id,
|
|
1168
|
+
label: `Joomla PATCH replacement: ${replacement.label}`,
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
async function verifyConfiguredResource(session, creatingPath, site, baseId, reference, key, id, expected, state, getScenario, listScenario, record, options, phasePrefix = 'created') {
|
|
1172
|
+
let primary;
|
|
1173
|
+
let creatingPathReadBack;
|
|
1174
|
+
let creatingPathCollectionKnownLimitation = false;
|
|
1175
|
+
let verifiedByAlternateCollection = false;
|
|
1176
|
+
const paths = [
|
|
1177
|
+
creatingPath,
|
|
1178
|
+
...options.joomlaPaths.filter((candidate) => candidate !== creatingPath),
|
|
1179
|
+
];
|
|
1180
|
+
for (const verificationPath of paths) {
|
|
1181
|
+
if (!getScenario.joomlaPaths.includes(verificationPath) ||
|
|
1182
|
+
!listScenario.joomlaPaths.includes(verificationPath)) {
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
const getInput = { id: numericId(id) };
|
|
1186
|
+
let readBack;
|
|
1187
|
+
let messageReplacementHandled = false;
|
|
1188
|
+
const getOutcome = await record(session, verificationPath, getScenario, `verify-${phasePrefix}-get-${key}`, getInput, async () => {
|
|
1189
|
+
const response = await callRead(session, site, getScenario.id, getInput, verificationPath);
|
|
1190
|
+
readBack = firstEntity(response);
|
|
1191
|
+
assertEntityId(readBack, id, getScenario.id);
|
|
1192
|
+
try {
|
|
1193
|
+
const attributes = assertChangedFields(response, expected, baseId);
|
|
1194
|
+
return {
|
|
1195
|
+
response,
|
|
1196
|
+
expected: visibleExpectation(expected),
|
|
1197
|
+
actual: attributes,
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
catch (error) {
|
|
1201
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
1202
|
+
options,
|
|
1203
|
+
joomlaPath: verificationPath,
|
|
1204
|
+
scenarioId: getScenario.id,
|
|
1205
|
+
phase: `verify-${phasePrefix}-get-${key}`,
|
|
1206
|
+
error: errorMessage(error),
|
|
1207
|
+
});
|
|
1208
|
+
if (knownLimitation === undefined || baseId !== 'messages.messages')
|
|
1209
|
+
throw error;
|
|
1210
|
+
const recovery = await inspectMessageReplacement(session, verificationPath, site, id, expected, options.cleanup);
|
|
1211
|
+
if (recovery === undefined)
|
|
1212
|
+
throw error;
|
|
1213
|
+
if (!recovery.replacementRemoved) {
|
|
1214
|
+
rememberUnexpectedReplacement(state, baseId, recovery.replacement);
|
|
1215
|
+
}
|
|
1216
|
+
messageReplacementHandled = true;
|
|
1217
|
+
return {
|
|
1218
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
1219
|
+
response: { originalReadBack: response, ...recovery },
|
|
1220
|
+
expected: visibleExpectation(expected),
|
|
1221
|
+
actual: {
|
|
1222
|
+
original: readBack?.attributes,
|
|
1223
|
+
replacement: recovery.replacement,
|
|
1224
|
+
replacementRemoved: recovery.replacementRemoved,
|
|
1225
|
+
},
|
|
1226
|
+
reason: knownLimitation.explanation,
|
|
1227
|
+
knownLimitation,
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
if (messageReplacementHandled)
|
|
1232
|
+
return undefined;
|
|
1233
|
+
if (getOutcome === undefined || readBack === undefined)
|
|
1234
|
+
continue;
|
|
1235
|
+
if (verificationPath === creatingPath)
|
|
1236
|
+
creatingPathReadBack = readBack;
|
|
1237
|
+
const identity = scenarioIdentity({ ...expected, ...readBack.attributes });
|
|
1238
|
+
let listed;
|
|
1239
|
+
const listOutcome = await record(session, verificationPath, listScenario, `verify-${phasePrefix}-visible-${key}`, { id, selector: identity }, async () => {
|
|
1240
|
+
const collection = await findConfiguredEntityInCollection(session, site, listScenario.id, verificationPath, identity, id);
|
|
1241
|
+
listed = collection.entity;
|
|
1242
|
+
if (listed === undefined) {
|
|
1243
|
+
throw new Error(`${reference} (${id}) is readable by item ID but is absent from ${listScenario.id}; ` +
|
|
1244
|
+
'it is not certified as visible in Joomla collection/GUI models.');
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
response: collection.pages,
|
|
1248
|
+
expected: { id, visible: true, fields: visibleExpectation(expected) },
|
|
1249
|
+
actual: { id: listed.id, visible: true, fields: listed.attributes },
|
|
1250
|
+
};
|
|
1251
|
+
});
|
|
1252
|
+
if (listOutcome === undefined)
|
|
1253
|
+
continue;
|
|
1254
|
+
if (listed === undefined) {
|
|
1255
|
+
if (verificationPath === creatingPath &&
|
|
1256
|
+
listOutcome.status === 'KNOWN_UPSTREAM_LIMITATION') {
|
|
1257
|
+
creatingPathCollectionKnownLimitation = true;
|
|
1258
|
+
}
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
if (verificationPath === creatingPath) {
|
|
1262
|
+
primary = Object.freeze({
|
|
1263
|
+
id: readBack.id,
|
|
1264
|
+
attributes: Object.freeze({ ...readBack.attributes }),
|
|
1265
|
+
label: readBack.label,
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
else if (creatingPathReadBack !== undefined &&
|
|
1269
|
+
creatingPathCollectionKnownLimitation) {
|
|
1270
|
+
verifiedByAlternateCollection = true;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
return primary ?? (verifiedByAlternateCollection && creatingPathReadBack !== undefined
|
|
1274
|
+
? Object.freeze({
|
|
1275
|
+
id: creatingPathReadBack.id,
|
|
1276
|
+
attributes: Object.freeze({ ...creatingPathReadBack.attributes }),
|
|
1277
|
+
label: creatingPathReadBack.label,
|
|
1278
|
+
})
|
|
1279
|
+
: undefined);
|
|
1280
|
+
}
|
|
1281
|
+
async function findConfiguredEntityInCollection(session, site, action, path, identity, requiredId) {
|
|
1282
|
+
const pages = [];
|
|
1283
|
+
const limit = 100;
|
|
1284
|
+
for (let offset = 0; offset < 2_000; offset += limit) {
|
|
1285
|
+
const response = await callRead(session, site, action, { offset, limit }, path);
|
|
1286
|
+
pages.push(response);
|
|
1287
|
+
const entities = collectEntities(response);
|
|
1288
|
+
const matches = entities.filter((entity) => (requiredId === undefined || looselyEqual(entity.id, requiredId)) &&
|
|
1289
|
+
entityMatchesFields(entity, identity));
|
|
1290
|
+
if (matches.length > 1) {
|
|
1291
|
+
throw new Error(`${action} returned multiple records for selector ${JSON.stringify(visibleExpectation(identity))}.`);
|
|
1292
|
+
}
|
|
1293
|
+
if (matches.length === 1)
|
|
1294
|
+
return { entity: matches[0], pages };
|
|
1295
|
+
if (entities.length < limit)
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
return { pages };
|
|
1299
|
+
}
|
|
1300
|
+
function scenarioIdentity(attributes) {
|
|
1301
|
+
for (const key of ['alias', 'username', 'menutype']) {
|
|
1302
|
+
if (attributes[key] !== undefined)
|
|
1303
|
+
return Object.freeze({ [key]: attributes[key] });
|
|
1304
|
+
}
|
|
1305
|
+
for (const key of ['title', 'name', 'subject', 'lang_code', 'email', 'old_url', 'link']) {
|
|
1306
|
+
if (attributes[key] !== undefined)
|
|
1307
|
+
return Object.freeze({ [key]: attributes[key] });
|
|
1308
|
+
}
|
|
1309
|
+
throw new Error('Configured resource has no stable alias, username, email, menutype, title, name, subject, or language code.');
|
|
1310
|
+
}
|
|
1311
|
+
function visibleExpectation(value) {
|
|
1312
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !/password|password2|secret|token|acknowledgement|confirmation/iu.test(key)));
|
|
1313
|
+
}
|
|
1314
|
+
async function cleanupConfiguredRecords(session, path, site, state, record, options, configuration) {
|
|
1315
|
+
for (const configured of [...orderedLiveScenarioRecords(configuration)].reverse()) {
|
|
1316
|
+
const entity = state.namedRecords.get(configured.reference);
|
|
1317
|
+
if (entity === undefined)
|
|
1318
|
+
continue;
|
|
1319
|
+
const deleteScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${configured.baseId}.delete`);
|
|
1320
|
+
const getScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${configured.baseId}.get`);
|
|
1321
|
+
if (deleteScenario === undefined ||
|
|
1322
|
+
getScenario === undefined ||
|
|
1323
|
+
!deleteScenario.joomlaPaths.includes(path) ||
|
|
1324
|
+
!getScenario.joomlaPaths.includes(path)) {
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
const deleted = await deleteConfiguredResource(session, path, site, configured.baseId, configured.reference, entity, deleteScenario, getScenario, record, options, true);
|
|
1328
|
+
if (deleted) {
|
|
1329
|
+
state.namedRecords.delete(configured.reference);
|
|
1330
|
+
removeRetainedRecord(state, configured.baseId, entity.id);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
async function deleteConfiguredResource(session, path, site, baseId, reference, entity, deleteScenario, getScenario, record, options, cleanup) {
|
|
1335
|
+
const trash = deleteSemantics(baseId) === 'permanent'
|
|
1336
|
+
? undefined
|
|
1337
|
+
: trashData(baseId, entity.attributes);
|
|
1338
|
+
if (trash !== undefined) {
|
|
1339
|
+
const updateScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${baseId}.update`);
|
|
1340
|
+
if (updateScenario !== undefined && updateScenario.joomlaPaths.includes(path)) {
|
|
1341
|
+
const trashInput = { id: numericId(entity.id), data: trash };
|
|
1342
|
+
const phase = `${cleanup ? 'cleanup' : 'delete'}-trash-${safeSegment(reference)}`;
|
|
1343
|
+
const trashed = await record(session, path, updateScenario, phase, trashInput, async () => {
|
|
1344
|
+
try {
|
|
1345
|
+
return {
|
|
1346
|
+
response: await callWrite(session, site, updateScenario.id, trashInput, path),
|
|
1347
|
+
expected: trash,
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
catch (error) {
|
|
1351
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
1352
|
+
options,
|
|
1353
|
+
joomlaPath: path,
|
|
1354
|
+
scenarioId: updateScenario.id,
|
|
1355
|
+
phase,
|
|
1356
|
+
error: errorMessage(error),
|
|
1357
|
+
});
|
|
1358
|
+
if (knownLimitation === undefined)
|
|
1359
|
+
throw error;
|
|
1360
|
+
const verification = await callRead(session, site, getScenario.id, { id: numericId(entity.id) }, path);
|
|
1361
|
+
const attributes = assertChangedFields(verification, trash, baseId);
|
|
1362
|
+
return {
|
|
1363
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
1364
|
+
response: { upstreamError: errorResult(error), verification },
|
|
1365
|
+
expected: trash,
|
|
1366
|
+
actual: attributes,
|
|
1367
|
+
reason: knownLimitation.explanation,
|
|
1368
|
+
knownLimitation,
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
}, cleanup);
|
|
1372
|
+
if (trashed === undefined)
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
const input = { id: numericId(entity.id) };
|
|
1377
|
+
const outcome = await record(session, path, deleteScenario, `${cleanup ? 'cleanup' : 'delete'}-${safeSegment(reference)}`, input, async () => ({
|
|
1378
|
+
response: await callWrite(session, site, deleteScenario.id, input, path),
|
|
1379
|
+
expected: { removed: entity.id, resource: reference },
|
|
1380
|
+
}), cleanup);
|
|
1381
|
+
return outcome !== undefined &&
|
|
1382
|
+
await verifyDeletion(session, path, site, getScenario, entity, record, options, cleanup);
|
|
1383
|
+
}
|
|
1384
|
+
function createFixtureData(baseId, data, purpose) {
|
|
1385
|
+
if (purpose !== 'deletion' || deleteSemantics(baseId) === 'permanent')
|
|
1386
|
+
return data;
|
|
1387
|
+
const trash = trashData(baseId, data);
|
|
1388
|
+
return trash === undefined ? data : Object.freeze({ ...data, ...trash });
|
|
1389
|
+
}
|
|
1390
|
+
function rememberCrudCreate(baseId, purpose, entity, state) {
|
|
1391
|
+
if (purpose === 'showcase') {
|
|
1392
|
+
state.records.set(baseId, entity);
|
|
1393
|
+
}
|
|
1394
|
+
else {
|
|
1395
|
+
state.records.set(`${baseId}#deletion`, entity);
|
|
1396
|
+
}
|
|
1397
|
+
state.created.push({
|
|
1398
|
+
lane: state.lane,
|
|
1399
|
+
family: baseId,
|
|
1400
|
+
id: entity.id,
|
|
1401
|
+
label: `${entity.label}${purpose === 'deletion' ? ' [deletion candidate]' : ''}`,
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
function deleteSemantics(baseId) {
|
|
1405
|
+
return joomlaCrudBases.find((base) => base.id === baseId)?.deleteSemantics ?? 'resource-model-defined';
|
|
1406
|
+
}
|
|
1407
|
+
function trashData(baseId, attributes) {
|
|
1408
|
+
if (baseId === 'contacts.contacts')
|
|
1409
|
+
return Object.freeze({ published: -2 });
|
|
1410
|
+
if (baseId === 'modules.site' || baseId === 'modules.administrator') {
|
|
1411
|
+
const params = asRecord(attributes['params']);
|
|
1412
|
+
return Object.freeze({
|
|
1413
|
+
...selectAttributes(attributes, [
|
|
1414
|
+
'title', 'content', 'module', 'position', 'showtitle', 'access',
|
|
1415
|
+
'language', 'assigned',
|
|
1416
|
+
]),
|
|
1417
|
+
published: -2,
|
|
1418
|
+
params: {
|
|
1419
|
+
...params,
|
|
1420
|
+
layout: typeof params['layout'] === 'string' && params['layout'].length > 0
|
|
1421
|
+
? params['layout']
|
|
1422
|
+
: '_:default',
|
|
1423
|
+
},
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
if (baseId === 'menus.site-items' || baseId === 'menus.administrator-items') {
|
|
1427
|
+
return Object.freeze({
|
|
1428
|
+
...selectAttributes(attributes, [
|
|
1429
|
+
'menutype', 'title', 'alias', 'note', 'link', 'type', 'parent_id',
|
|
1430
|
+
'browserNav', 'access', 'img', 'template_style_id', 'params', 'home',
|
|
1431
|
+
'language', 'ordering',
|
|
1432
|
+
]),
|
|
1433
|
+
published: -2,
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
if (baseId === 'languages.content') {
|
|
1437
|
+
return Object.freeze({
|
|
1438
|
+
...selectAttributes(attributes, [
|
|
1439
|
+
'lang_code', 'title', 'title_native', 'sef', 'image', 'description',
|
|
1440
|
+
'metadesc', 'sitename', 'access', 'ordering',
|
|
1441
|
+
]),
|
|
1442
|
+
published: -2,
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
if (Object.hasOwn(attributes, 'published'))
|
|
1446
|
+
return Object.freeze({ published: -2 });
|
|
1447
|
+
if (Object.hasOwn(attributes, 'state'))
|
|
1448
|
+
return Object.freeze({ state: -2 });
|
|
1449
|
+
return undefined;
|
|
1450
|
+
}
|
|
1451
|
+
async function runSpecialProfile(session, path, siteId, site, selected, state, record, options) {
|
|
1452
|
+
const crudIds = new Set(joomlaCrudBases.flatMap((base) => ['list', 'get', 'create', 'update', 'delete'].map((operation) => `${base.id}.${operation}`)));
|
|
1453
|
+
const special = selected.filter((scenario) => !crudIds.has(scenario.id) &&
|
|
1454
|
+
scenario.sourceOnlyReason === undefined &&
|
|
1455
|
+
scenario.joomlaPaths.includes(path));
|
|
1456
|
+
for (const scenario of special.filter(isRead)
|
|
1457
|
+
.sort((left, right) => readPriority(left.id) - readPriority(right.id) || left.id.localeCompare(right.id))) {
|
|
1458
|
+
if (scenario.id.startsWith('joomla-update.') && site.api?.updateToken === undefined) {
|
|
1459
|
+
await record(session, path, scenario, 'read', {}, async () => {
|
|
1460
|
+
throw new BlockedError('Joomla Update actions require a separately configured X-JUpdate-Token.', ['site.api.updateToken']);
|
|
1461
|
+
});
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
const input = await prepareScenarioInput(session, path, scenario, 'read', { action: scenario.id }, record, () => readInput(scenario.id, state));
|
|
1465
|
+
if (input === undefined)
|
|
1466
|
+
continue;
|
|
1467
|
+
await record(session, path, scenario, 'read', input, async () => {
|
|
1468
|
+
const response = await callRead(session, siteId, scenario.id, input, path);
|
|
1469
|
+
validateReadResult(scenario.id, input, response);
|
|
1470
|
+
state.reads.set(scenario.id, response);
|
|
1471
|
+
return { response };
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
for (const scenario of special.filter((candidate) => !isRead(candidate))
|
|
1475
|
+
.sort((left, right) => specialWritePriority(left.id) - specialWritePriority(right.id) ||
|
|
1476
|
+
left.id.localeCompare(right.id))) {
|
|
1477
|
+
if (scenario.id.startsWith('joomla-update.') && site.api?.updateToken === undefined) {
|
|
1478
|
+
await record(session, path, scenario, 'write', {}, async () => {
|
|
1479
|
+
throw new BlockedError('Joomla Update actions require a separately configured X-JUpdate-Token.', ['site.api.updateToken']);
|
|
1480
|
+
});
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
if ((scenario.risk === 'destructive' || scenario.risk === 'high') && !options.disposable) {
|
|
1484
|
+
await addExpectedDenial(session, path, scenario, 'write', `High-risk action ${scenario.id} requires --disposable.`, record);
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
const input = await prepareScenarioInput(session, path, scenario, 'write', { action: scenario.id }, record, () => specialWriteInput(scenario.id, state, options.seed));
|
|
1488
|
+
if (input === undefined)
|
|
1489
|
+
continue;
|
|
1490
|
+
const outcome = await record(session, path, scenario, 'write', input, async () => {
|
|
1491
|
+
const response = await executeSpecialWrite(session, path, siteId, scenario, input, state, options.seed);
|
|
1492
|
+
if (scenario.id === 'languages.overrides.site.create' ||
|
|
1493
|
+
scenario.id === 'languages.overrides.administrator.create') {
|
|
1494
|
+
const data = asRecord(input['data']);
|
|
1495
|
+
assertLanguageOverride(response, String(data['key'] ?? ''), String(data['override'] ?? ''), scenario.id);
|
|
1496
|
+
rememberSpecialWrite(scenario.id, input, response, state);
|
|
1497
|
+
return {
|
|
1498
|
+
response,
|
|
1499
|
+
expected: { id: data['key'], value: data['override'] },
|
|
1500
|
+
actual: firstEntity(response),
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
rememberSpecialWrite(scenario.id, input, response, state);
|
|
1504
|
+
return { response };
|
|
1505
|
+
});
|
|
1506
|
+
if (outcome !== undefined && outcome.status !== 'KNOWN_UPSTREAM_LIMITATION') {
|
|
1507
|
+
await runSpecialReadBack(session, path, siteId, scenario, input, outcome.response, selected, record);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
async function runSpecialReadBack(session, path, site, writeScenario, writeInput, writeResponse, selected, record) {
|
|
1512
|
+
if (writeScenario.id === 'privacy.requests.create') {
|
|
1513
|
+
const created = firstEntity(writeResponse);
|
|
1514
|
+
if (created === undefined)
|
|
1515
|
+
return;
|
|
1516
|
+
const getScenario = selected.find((scenario) => scenario.id === 'privacy.requests.get');
|
|
1517
|
+
if (getScenario !== undefined && getScenario.joomlaPaths.includes(path)) {
|
|
1518
|
+
const input = { id: numericId(created.id) };
|
|
1519
|
+
await record(session, path, getScenario, 'read-back-created', input, async () => {
|
|
1520
|
+
const response = await callRead(session, site, getScenario.id, input, path);
|
|
1521
|
+
const actual = firstEntity(response);
|
|
1522
|
+
assertEntityId(actual, created.id, getScenario.id);
|
|
1523
|
+
const expectedEmail = asRecord(writeInput['data'])['email'];
|
|
1524
|
+
if (!looselyEqual(actual?.attributes['email'], expectedEmail)) {
|
|
1525
|
+
throw new Error('Created privacy request did not return the submitted email address.');
|
|
1526
|
+
}
|
|
1527
|
+
return { response, expected: { id: created.id, email: expectedEmail }, actual };
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
const exportScenario = selected.find((scenario) => scenario.id === 'privacy.requests.export');
|
|
1531
|
+
if (exportScenario !== undefined && exportScenario.joomlaPaths.includes(path)) {
|
|
1532
|
+
const input = { id: numericId(created.id) };
|
|
1533
|
+
await record(session, path, exportScenario, 'read-back-pending', input, async () => {
|
|
1534
|
+
try {
|
|
1535
|
+
return { response: await callRead(session, site, exportScenario.id, input, path) };
|
|
1536
|
+
}
|
|
1537
|
+
catch (error) {
|
|
1538
|
+
if (!isJoomlaHttpError(error, 404))
|
|
1539
|
+
throw error;
|
|
1540
|
+
return {
|
|
1541
|
+
status: 'EXPECTED_DENIAL',
|
|
1542
|
+
response: errorResult(error),
|
|
1543
|
+
expected: 'Joomla denies export until the newly created privacy request is confirmed and processed.',
|
|
1544
|
+
reason: 'The newly created privacy request is pending, so Joomla correctly returned HTTP 404 instead of exporting data.',
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (writeScenario.id === 'languages.overrides.site.create' ||
|
|
1552
|
+
writeScenario.id === 'languages.overrides.administrator.create') {
|
|
1553
|
+
const getScenario = selected.find((scenario) => scenario.id === writeScenario.id.replace('.create', '.get'));
|
|
1554
|
+
if (getScenario === undefined || !getScenario.joomlaPaths.includes(path))
|
|
1555
|
+
return;
|
|
1556
|
+
const data = asRecord(writeInput['data']);
|
|
1557
|
+
const input = { language: writeInput['language'], constant: data['key'] };
|
|
1558
|
+
await record(session, path, getScenario, 'read-back-created', input, async () => {
|
|
1559
|
+
const response = await callRead(session, site, getScenario.id, input, path);
|
|
1560
|
+
assertLanguageOverride(response, String(data['key'] ?? ''), String(data['override'] ?? ''), getScenario.id);
|
|
1561
|
+
return {
|
|
1562
|
+
response,
|
|
1563
|
+
expected: { id: data['key'], value: data['override'] },
|
|
1564
|
+
actual: firstEntity(response),
|
|
1565
|
+
};
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
async function cleanupRecords(session, path, site, state, record, options) {
|
|
1570
|
+
for (const baseId of [...crudFixtureOrder].reverse()) {
|
|
1571
|
+
const entity = state.records.get(baseId);
|
|
1572
|
+
if (entity === undefined)
|
|
1573
|
+
continue;
|
|
1574
|
+
const scenario = liveScenarioCatalog().find((candidate) => candidate.id === `${baseId}.delete`);
|
|
1575
|
+
if (scenario === undefined || !scenario.joomlaPaths.includes(path))
|
|
1576
|
+
continue;
|
|
1577
|
+
const trash = deleteSemantics(baseId) === 'permanent'
|
|
1578
|
+
? undefined
|
|
1579
|
+
: trashData(baseId, entity.attributes);
|
|
1580
|
+
if (trash !== undefined) {
|
|
1581
|
+
const updateScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${baseId}.update`);
|
|
1582
|
+
if (updateScenario !== undefined && updateScenario.joomlaPaths.includes(path)) {
|
|
1583
|
+
const trashInput = { id: numericId(entity.id), data: trash };
|
|
1584
|
+
const trashed = await record(session, path, updateScenario, 'cleanup-trash-showcase', trashInput, async () => {
|
|
1585
|
+
try {
|
|
1586
|
+
return {
|
|
1587
|
+
response: await callWrite(session, site, updateScenario.id, trashInput, path),
|
|
1588
|
+
expected: trash,
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
catch (error) {
|
|
1592
|
+
const knownLimitation = verifiedPartialMutationLimitation({
|
|
1593
|
+
options,
|
|
1594
|
+
joomlaPath: path,
|
|
1595
|
+
scenarioId: updateScenario.id,
|
|
1596
|
+
phase: 'cleanup-trash-showcase',
|
|
1597
|
+
error: errorMessage(error),
|
|
1598
|
+
});
|
|
1599
|
+
if (knownLimitation === undefined || updateScenario.id !== 'languages.content.update') {
|
|
1600
|
+
throw error;
|
|
1601
|
+
}
|
|
1602
|
+
const getScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${baseId}.get`);
|
|
1603
|
+
if (getScenario === undefined || !getScenario.joomlaPaths.includes(path))
|
|
1604
|
+
throw error;
|
|
1605
|
+
const verification = await callRead(session, site, getScenario.id, { id: numericId(entity.id) }, path);
|
|
1606
|
+
assertChangedFields(verification, trash, baseId);
|
|
1607
|
+
return {
|
|
1608
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
1609
|
+
response: { upstreamError: errorResult(error), verification },
|
|
1610
|
+
expected: trash,
|
|
1611
|
+
actual: firstEntity(verification)?.attributes,
|
|
1612
|
+
reason: knownLimitation.explanation,
|
|
1613
|
+
knownLimitation,
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
}, true);
|
|
1617
|
+
if (trashed === undefined)
|
|
1618
|
+
continue;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
const input = await prepareScenarioInput(session, path, scenario, 'cleanup-showcase', { id: entity.id }, record, () => ({ id: numericId(entity.id) }), true);
|
|
1622
|
+
if (input === undefined)
|
|
1623
|
+
continue;
|
|
1624
|
+
const outcome = await record(session, path, scenario, 'cleanup-showcase', input, async () => ({
|
|
1625
|
+
response: await callWrite(session, site, scenario.id, input, path),
|
|
1626
|
+
expected: { removed: entity.id },
|
|
1627
|
+
}), true);
|
|
1628
|
+
if (outcome !== undefined) {
|
|
1629
|
+
const getScenario = liveScenarioCatalog().find((candidate) => candidate.id === `${baseId}.get`);
|
|
1630
|
+
const verified = getScenario !== undefined && getScenario.joomlaPaths.includes(path)
|
|
1631
|
+
? await verifyDeletion(session, path, site, getScenario, entity, record, options, true)
|
|
1632
|
+
: true;
|
|
1633
|
+
if (verified)
|
|
1634
|
+
removeRetainedRecord(state, baseId, entity.id);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
async function verifyDeletion(session, path, site, getScenario, entity, record, options, cleanup = false) {
|
|
1639
|
+
const request = { id: entity.id };
|
|
1640
|
+
const outcome = await record(session, path, getScenario, 'verify-deleted', request, async () => {
|
|
1641
|
+
const input = { id: numericId(entity.id) };
|
|
1642
|
+
try {
|
|
1643
|
+
const response = await callRead(session, site, getScenario.id, input, path);
|
|
1644
|
+
const found = firstEntity(response);
|
|
1645
|
+
const state = found?.attributes['state'] ?? found?.attributes['published'];
|
|
1646
|
+
if (found !== undefined && state !== -2 && state !== '-2') {
|
|
1647
|
+
throw new Error(`Deleted candidate ${entity.id} remains readable and is not in Joomla trash state.`);
|
|
1648
|
+
}
|
|
1649
|
+
return {
|
|
1650
|
+
response,
|
|
1651
|
+
expected: { absentOrTrashState: -2 },
|
|
1652
|
+
actual: found === undefined ? { absent: true } : found.attributes,
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
catch (error) {
|
|
1656
|
+
if (error instanceof LiveMcpToolError && /(?:404|not found|does not exist)/iu.test(error.message)) {
|
|
1657
|
+
return { expected: { absent: true }, actual: { denied: error.message } };
|
|
1658
|
+
}
|
|
1659
|
+
const knownLimitation = verifiedDeletionLimitation({
|
|
1660
|
+
options,
|
|
1661
|
+
joomlaPath: path,
|
|
1662
|
+
scenarioId: getScenario.id,
|
|
1663
|
+
phase: 'verify-deleted',
|
|
1664
|
+
error: errorMessage(error),
|
|
1665
|
+
});
|
|
1666
|
+
if (knownLimitation !== undefined) {
|
|
1667
|
+
const listAction = getScenario.id.replace(/\.get$/u, '.list');
|
|
1668
|
+
const verification = await callRead(session, site, listAction, { offset: 0, limit: 100 }, path);
|
|
1669
|
+
const found = collectEntities(verification).find((candidate) => looselyEqual(candidate.id, entity.id));
|
|
1670
|
+
const state = found?.attributes['state'] ?? found?.attributes['published'];
|
|
1671
|
+
if (found !== undefined && state !== -2 && state !== '-2') {
|
|
1672
|
+
throw new Error(`${getScenario.id} returned its reviewed post-delete error, but ${entity.id} remains in the active collection.`);
|
|
1673
|
+
}
|
|
1674
|
+
return {
|
|
1675
|
+
status: 'KNOWN_UPSTREAM_LIMITATION',
|
|
1676
|
+
response: { upstreamError: errorResult(error), collectionVerification: verification },
|
|
1677
|
+
expected: { absentOrTrashState: -2 },
|
|
1678
|
+
actual: found === undefined ? { absent: true } : found.attributes,
|
|
1679
|
+
reason: knownLimitation.explanation,
|
|
1680
|
+
knownLimitation,
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
throw error;
|
|
1684
|
+
}
|
|
1685
|
+
}, cleanup);
|
|
1686
|
+
return outcome !== undefined;
|
|
1687
|
+
}
|
|
1688
|
+
async function prepareScenarioInput(session, path, scenario, phase, requestHint, record, prepare, cleanup = false) {
|
|
1689
|
+
try {
|
|
1690
|
+
const input = prepare();
|
|
1691
|
+
if (input instanceof BlockedError) {
|
|
1692
|
+
await record(session, path, scenario, phase, requestHint, async () => { throw input; }, cleanup);
|
|
1693
|
+
return undefined;
|
|
1694
|
+
}
|
|
1695
|
+
return input;
|
|
1696
|
+
}
|
|
1697
|
+
catch (error) {
|
|
1698
|
+
await record(session, path, scenario, phase, requestHint, async () => { throw error; }, cleanup);
|
|
1699
|
+
return undefined;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
async function callRead(session, site, action, input, path) {
|
|
1703
|
+
return session.call({
|
|
1704
|
+
name: 'joomla_action_read',
|
|
1705
|
+
arguments: { site, action, input, transport: path },
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
async function callWrite(session, site, action, input, path) {
|
|
1709
|
+
const dryRunRequest = {
|
|
1710
|
+
site,
|
|
1711
|
+
action,
|
|
1712
|
+
input,
|
|
1713
|
+
transport: path,
|
|
1714
|
+
idempotencyKey: randomUUID(),
|
|
1715
|
+
dryRun: true,
|
|
1716
|
+
};
|
|
1717
|
+
const preview = await session.call({ name: 'joomla_action_write_plan', arguments: dryRunRequest });
|
|
1718
|
+
const executable = asRecord(await session.call({
|
|
1719
|
+
name: 'joomla_action_write_plan',
|
|
1720
|
+
arguments: { ...dryRunRequest, idempotencyKey: randomUUID(), dryRun: false },
|
|
1721
|
+
}));
|
|
1722
|
+
const confirmationToken = executable['confirmationToken'];
|
|
1723
|
+
if (typeof confirmationToken !== 'string') {
|
|
1724
|
+
throw new Error(`Executable plan for ${action} returned no confirmation token.`);
|
|
1725
|
+
}
|
|
1726
|
+
const applied = await session.call({
|
|
1727
|
+
name: 'joomla_write_apply',
|
|
1728
|
+
arguments: { confirmationToken },
|
|
1729
|
+
});
|
|
1730
|
+
return { preview, plan: executable, applied };
|
|
1731
|
+
}
|
|
1732
|
+
function readInput(actionId, state) {
|
|
1733
|
+
if ([
|
|
1734
|
+
'configuration.application.get',
|
|
1735
|
+
'configuration.get_safe',
|
|
1736
|
+
'site.state.get',
|
|
1737
|
+
'system.info',
|
|
1738
|
+
'core.update.status',
|
|
1739
|
+
].includes(actionId))
|
|
1740
|
+
return {};
|
|
1741
|
+
if (actionId === 'media.directory.list')
|
|
1742
|
+
return { path: 'local-images:', offset: 0, limit: 20 };
|
|
1743
|
+
if ([
|
|
1744
|
+
'menus.administrator-item-types.list',
|
|
1745
|
+
'menus.site-item-types.list',
|
|
1746
|
+
'modules.administrator-types.list',
|
|
1747
|
+
'modules.site-types.list',
|
|
1748
|
+
].includes(actionId))
|
|
1749
|
+
return {};
|
|
1750
|
+
if (actionId.endsWith('.list')) {
|
|
1751
|
+
if (actionId.startsWith('languages.overrides.'))
|
|
1752
|
+
return { language: 'en-GB', offset: 0, limit: 20 };
|
|
1753
|
+
if (actionId.includes('-history.')) {
|
|
1754
|
+
const base = historyBase(actionId);
|
|
1755
|
+
const record = base === undefined ? undefined : state.records.get(base);
|
|
1756
|
+
return record === undefined
|
|
1757
|
+
? new BlockedError(`${actionId} requires a created ${base ?? 'content'} record.`, base === undefined ? [] : [`${base}.create`])
|
|
1758
|
+
: { id: numericId(record.id), offset: 0, limit: 20 };
|
|
1759
|
+
}
|
|
1760
|
+
return { offset: 0, limit: 20 };
|
|
1761
|
+
}
|
|
1762
|
+
if (actionId.endsWith('.get')) {
|
|
1763
|
+
const baseId = actionId.slice(0, -'.get'.length);
|
|
1764
|
+
const record = state.records.get(baseId) ?? state.references.get(baseId);
|
|
1765
|
+
if (record !== undefined)
|
|
1766
|
+
return { id: numericId(record.id) };
|
|
1767
|
+
if (actionId === 'media.adapters.get') {
|
|
1768
|
+
const adapter = firstEntity(state.reads.get('media.adapters.list'));
|
|
1769
|
+
const id = adapter?.id;
|
|
1770
|
+
return id === undefined
|
|
1771
|
+
? new BlockedError('No media adapter was returned by media.adapters.list.', ['media.adapters.list'])
|
|
1772
|
+
: { adapter: String(id) };
|
|
1773
|
+
}
|
|
1774
|
+
if (actionId === 'media.files.get') {
|
|
1775
|
+
return { path: fixtureMediaPath };
|
|
1776
|
+
}
|
|
1777
|
+
if (actionId === 'plugins.plugins.get') {
|
|
1778
|
+
return idFromRead(state, 'plugins.plugins.list');
|
|
1779
|
+
}
|
|
1780
|
+
if (actionId === 'privacy.requests.get') {
|
|
1781
|
+
return idFromMatchingRead(state, 'privacy.requests.list', 'email', fixturePrivacyEmail);
|
|
1782
|
+
}
|
|
1783
|
+
if (actionId === 'privacy.consents.get') {
|
|
1784
|
+
return idFromMatchingRead(state, 'privacy.consents.list', 'subject', fixturePrivacyConsentSubject);
|
|
1785
|
+
}
|
|
1786
|
+
if (actionId.startsWith('languages.overrides.')) {
|
|
1787
|
+
const fixture = actionId.startsWith('languages.overrides.site.')
|
|
1788
|
+
? fixtureSiteOverride
|
|
1789
|
+
: fixtureAdministratorOverride;
|
|
1790
|
+
return { language: fixture.language, constant: fixture.constant };
|
|
1791
|
+
}
|
|
1792
|
+
return new BlockedError(`${actionId} requires an existing catalogue record.`, [`${baseId}.list`]);
|
|
1793
|
+
}
|
|
1794
|
+
if (actionId === 'privacy.requests.export') {
|
|
1795
|
+
return idFromMatchingRead(state, 'privacy.requests.list', 'email', fixturePrivacyEmail);
|
|
1796
|
+
}
|
|
1797
|
+
if (actionId.endsWith('.export'))
|
|
1798
|
+
return idFromRead(state, actionId.replace('.export', '.list'));
|
|
1799
|
+
if (actionId === 'joomla-update.healthcheck' || actionId === 'joomla-update.status')
|
|
1800
|
+
return {};
|
|
1801
|
+
return {};
|
|
1802
|
+
}
|
|
1803
|
+
function validateReadResult(actionId, input, response) {
|
|
1804
|
+
if (actionId === 'media.files.get') {
|
|
1805
|
+
const expectedPath = String(input['path'] ?? '');
|
|
1806
|
+
const actualPath = findDeepValue(response, 'path');
|
|
1807
|
+
if (typeof actualPath !== 'string' ||
|
|
1808
|
+
normalizeCreatedMediaPath(actualPath) !== normalizeCreatedMediaPath(expectedPath)) {
|
|
1809
|
+
throw new Error(`media.files.get did not return prerequisite media path ${expectedPath}.`);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
if (actionId === 'privacy.requests.get' || actionId === 'privacy.consents.get') {
|
|
1813
|
+
const entity = firstEntity(response);
|
|
1814
|
+
assertEntityId(entity, Number(input['id']), actionId);
|
|
1815
|
+
const attribute = actionId === 'privacy.requests.get' ? 'email' : 'subject';
|
|
1816
|
+
const expected = actionId === 'privacy.requests.get'
|
|
1817
|
+
? fixturePrivacyEmail
|
|
1818
|
+
: fixturePrivacyConsentSubject;
|
|
1819
|
+
if (!looselyEqual(entity?.attributes[attribute], expected)) {
|
|
1820
|
+
throw new Error(`${actionId} did not return the deterministic fixture ${attribute}.`);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
if (actionId === 'languages.overrides.site.get' ||
|
|
1824
|
+
actionId === 'languages.overrides.administrator.get') {
|
|
1825
|
+
const fixture = actionId === 'languages.overrides.site.get'
|
|
1826
|
+
? fixtureSiteOverride
|
|
1827
|
+
: fixtureAdministratorOverride;
|
|
1828
|
+
assertLanguageOverride(response, fixture.constant, fixture.value, actionId);
|
|
1829
|
+
}
|
|
1830
|
+
if (actionId === 'joomla-update.healthcheck') {
|
|
1831
|
+
const version = findDeepValue(response, 'cms_version');
|
|
1832
|
+
if (typeof version !== 'string' || version.length === 0) {
|
|
1833
|
+
throw new Error('Joomla Update healthcheck did not return cms_version.');
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
if (actionId === 'joomla-update.status') {
|
|
1837
|
+
const availableUpdate = findDeepValue(response, 'availableUpdate');
|
|
1838
|
+
if (typeof availableUpdate !== 'string' || availableUpdate.length === 0) {
|
|
1839
|
+
throw new Error('Joomla Update status did not return a concrete availableUpdate.');
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
function requiredJoomlaUpdateVersion(state) {
|
|
1844
|
+
const version = findDeepValue(state.reads.get('joomla-update.status'), 'availableUpdate');
|
|
1845
|
+
if (typeof version !== 'string' || version.length === 0) {
|
|
1846
|
+
throw new Error('Joomla Update prepare requires the version returned by joomla-update.status.');
|
|
1847
|
+
}
|
|
1848
|
+
return version;
|
|
1849
|
+
}
|
|
1850
|
+
function requiredCurrentJoomlaVersion(state) {
|
|
1851
|
+
const healthcheckVersion = findDeepValue(state.reads.get('joomla-update.healthcheck'), 'cms_version');
|
|
1852
|
+
if (typeof healthcheckVersion === 'string' && healthcheckVersion.length > 0) {
|
|
1853
|
+
return healthcheckVersion;
|
|
1854
|
+
}
|
|
1855
|
+
const systemVersion = findDeepValue(state.reads.get('system.info'), 'joomlaVersion');
|
|
1856
|
+
if (typeof systemVersion === 'string' && systemVersion.length > 0)
|
|
1857
|
+
return systemVersion;
|
|
1858
|
+
throw new Error('Joomla Update actions require the current Joomla version returned by healthcheck or system.info.');
|
|
1859
|
+
}
|
|
1860
|
+
function requiredJoomlaUpdateFile(state) {
|
|
1861
|
+
const filename = state.reads.get('live.joomla-update.filename');
|
|
1862
|
+
if (typeof filename !== 'string' || filename.length === 0) {
|
|
1863
|
+
throw new Error('Joomla Update finalize requires the filename returned by joomla-update.prepare.');
|
|
1864
|
+
}
|
|
1865
|
+
return filename;
|
|
1866
|
+
}
|
|
1867
|
+
function specialWriteInput(actionId, state, seed) {
|
|
1868
|
+
const safeSeed = safeSegment(seed).toUpperCase().replaceAll('-', '_').slice(0, 24);
|
|
1869
|
+
if (actionId.includes('-history.')) {
|
|
1870
|
+
const readId = actionId.replace(/\.(?:keep|delete)$/u, '.list');
|
|
1871
|
+
return idFromRead(state, readId);
|
|
1872
|
+
}
|
|
1873
|
+
if (actionId === 'contacts.form.submit') {
|
|
1874
|
+
const contact = state.records.get('contacts.contacts');
|
|
1875
|
+
return contact === undefined
|
|
1876
|
+
? new BlockedError('Contact form submission requires a created contact.', ['contacts.contacts.create'])
|
|
1877
|
+
: {
|
|
1878
|
+
id: numericId(contact.id),
|
|
1879
|
+
data: {
|
|
1880
|
+
contact_name: 'Joomla MCP live test',
|
|
1881
|
+
contact_email: `live-${safeSegment(seed)}@example.invalid`,
|
|
1882
|
+
contact_subject: `Joomla MCP live ${seed}`,
|
|
1883
|
+
contact_message: `Disposable live validation message for ${seed}.`,
|
|
1884
|
+
contact_email_copy: false,
|
|
1885
|
+
},
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
if (actionId === 'media.files.create') {
|
|
1889
|
+
const directory = `joomla-mcp-live-${safeSegment(seed)}-${safeSegment(state.lane)}`;
|
|
1890
|
+
return {
|
|
1891
|
+
data: {
|
|
1892
|
+
path: `local-images:${directory}/fixture.png`,
|
|
1893
|
+
content: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=',
|
|
1894
|
+
override: false,
|
|
1895
|
+
},
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
if (actionId === 'media.files.update') {
|
|
1899
|
+
const path = state.reads.get('live.media.path');
|
|
1900
|
+
return typeof path !== 'string'
|
|
1901
|
+
? new BlockedError('Media update requires a successful media.files.create.', ['media.files.create'])
|
|
1902
|
+
: {
|
|
1903
|
+
path: mediaUpdateRoutePath(path),
|
|
1904
|
+
data: {
|
|
1905
|
+
path: mediaAdapterSelector(path),
|
|
1906
|
+
content: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl2nWQAAAAASUVORK5CYII=',
|
|
1907
|
+
override: true,
|
|
1908
|
+
},
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
if (actionId === 'media.files.delete') {
|
|
1912
|
+
const path = state.reads.get('live.media.path');
|
|
1913
|
+
return typeof path !== 'string'
|
|
1914
|
+
? new BlockedError('Media delete requires a successful media.files.create.', ['media.files.create'])
|
|
1915
|
+
: { path };
|
|
1916
|
+
}
|
|
1917
|
+
if (actionId === 'configuration.application.update') {
|
|
1918
|
+
return { data: { sitename: `Joomla MCP Live ${seed}` } };
|
|
1919
|
+
}
|
|
1920
|
+
if (actionId === 'plugins.plugins.update') {
|
|
1921
|
+
const plugin = toggleCandidate(state.reads.get('plugins.plugins.list'));
|
|
1922
|
+
if (plugin === undefined)
|
|
1923
|
+
return new BlockedError('Plugin update requires plugins.plugins.list.', ['plugins.plugins.list']);
|
|
1924
|
+
const enabled = Number(plugin.attributes['enabled'] ?? 1);
|
|
1925
|
+
return { id: numericId(plugin.id), data: { enabled: enabled === 1 ? 0 : 1 } };
|
|
1926
|
+
}
|
|
1927
|
+
if (actionId === 'privacy.requests.create') {
|
|
1928
|
+
return {
|
|
1929
|
+
data: {
|
|
1930
|
+
email: `privacy-${safeSegment(seed)}-${safeSegment(state.lane)}@example.invalid`,
|
|
1931
|
+
request_type: 'export',
|
|
1932
|
+
},
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
if (actionId === 'languages.overrides.site.create' || actionId === 'languages.overrides.administrator.create') {
|
|
1936
|
+
const lane = safeSegment(state.lane).toUpperCase().replaceAll('-', '_');
|
|
1937
|
+
const constant = `JOOMLA_MCP_LIVE_${safeSeed}_${lane}`;
|
|
1938
|
+
return {
|
|
1939
|
+
language: 'en-GB',
|
|
1940
|
+
data: { id: '', key: constant, override: `Joomla MCP live ${seed}`, both: false },
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
if (actionId === 'languages.overrides.site.delete' || actionId === 'languages.overrides.administrator.delete') {
|
|
1944
|
+
const lane = safeSegment(state.lane).toUpperCase().replaceAll('-', '_');
|
|
1945
|
+
return { language: 'en-GB', constant: `JOOMLA_MCP_LIVE_${safeSeed}_${lane}` };
|
|
1946
|
+
}
|
|
1947
|
+
if (actionId === 'languages.overrides.search') {
|
|
1948
|
+
const lane = safeSegment(state.lane).toUpperCase().replaceAll('-', '_');
|
|
1949
|
+
return { data: { searchstring: `JOOMLA_MCP_LIVE_${safeSeed}_${lane}`, searchtype: 'constant' } };
|
|
1950
|
+
}
|
|
1951
|
+
if (actionId === 'languages.overrides.refresh')
|
|
1952
|
+
return {};
|
|
1953
|
+
if (actionId === 'joomla-update.prepare') {
|
|
1954
|
+
return { data: { targetVersion: requiredJoomlaUpdateVersion(state) } };
|
|
1955
|
+
}
|
|
1956
|
+
if (actionId === 'joomla-update.finalize') {
|
|
1957
|
+
return {
|
|
1958
|
+
data: {
|
|
1959
|
+
fromVersion: requiredCurrentJoomlaVersion(state),
|
|
1960
|
+
updateFileName: requiredJoomlaUpdateFile(state),
|
|
1961
|
+
},
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
if (actionId.startsWith('joomla-update.notification.')) {
|
|
1965
|
+
return {
|
|
1966
|
+
data: {
|
|
1967
|
+
fromVersion: requiredCurrentJoomlaVersion(state),
|
|
1968
|
+
toVersion: requiredJoomlaUpdateVersion(state),
|
|
1969
|
+
},
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
if (actionId === 'cache.clean')
|
|
1973
|
+
return { groups: ['_system'] };
|
|
1974
|
+
if (['cache.expired.purge', 'extensions.discovered.refresh', 'extensions.updates.refresh', 'sessions.metadata.gc'].includes(actionId))
|
|
1975
|
+
return {};
|
|
1976
|
+
if (actionId === 'site.state.set')
|
|
1977
|
+
return { offline: true };
|
|
1978
|
+
if (actionId === 'sessions.data.gc')
|
|
1979
|
+
return { application: 'site' };
|
|
1980
|
+
if (actionId === 'extensions.state.set') {
|
|
1981
|
+
const extension = toggleCandidate(state.reads.get('extensions.list'));
|
|
1982
|
+
if (extension === undefined)
|
|
1983
|
+
return new BlockedError('extensions.list did not return a usable item.', ['extensions.list']);
|
|
1984
|
+
const enabled = Number(extension.attributes['enabled'] ?? 1);
|
|
1985
|
+
return { id: numericId(extension.id), enabled: enabled !== 1 };
|
|
1986
|
+
}
|
|
1987
|
+
if (actionId === 'extensions.update-sites.state.set') {
|
|
1988
|
+
const updateSite = firstEntity(state.reads.get('extensions.update-sites.list'));
|
|
1989
|
+
if (updateSite === undefined) {
|
|
1990
|
+
return new BlockedError('extensions.update-sites.list did not return a usable item.', ['extensions.update-sites.list']);
|
|
1991
|
+
}
|
|
1992
|
+
const enabled = Number(updateSite.attributes['enabled'] ?? 1);
|
|
1993
|
+
return { id: numericId(updateSite.id), enabled: enabled !== 1 };
|
|
1994
|
+
}
|
|
1995
|
+
if (actionId === 'scheduler.tasks.state.set') {
|
|
1996
|
+
const task = firstEntity(state.reads.get('scheduler.tasks.list'));
|
|
1997
|
+
if (task === undefined)
|
|
1998
|
+
return new BlockedError('scheduler.tasks.list did not return a usable item.', ['scheduler.tasks.list']);
|
|
1999
|
+
const current = Number(task.attributes['state'] ?? 1);
|
|
2000
|
+
return { id: numericId(task.id), state: current === 1 ? 0 : 1 };
|
|
2001
|
+
}
|
|
2002
|
+
if (actionId === 'scheduler.tasks.run') {
|
|
2003
|
+
return firstCompanionId(state, 'scheduler.tasks.list');
|
|
2004
|
+
}
|
|
2005
|
+
if (actionId.endsWith('.state')) {
|
|
2006
|
+
const baseId = actionId.slice(0, -'.state'.length);
|
|
2007
|
+
const entity = state.records.get(baseId);
|
|
2008
|
+
return entity === undefined
|
|
2009
|
+
? new BlockedError(`${actionId} requires a created ${baseId} record.`, [`${baseId}.create`])
|
|
2010
|
+
: { id: numericId(entity.id), state: 0 };
|
|
2011
|
+
}
|
|
2012
|
+
return new BlockedError(`No deterministic live fixture is defined for special write ${actionId}.`);
|
|
2013
|
+
}
|
|
2014
|
+
function rememberSpecialWrite(actionId, input, response, state) {
|
|
2015
|
+
if (actionId === 'media.files.create') {
|
|
2016
|
+
const data = asRecord(input['data']);
|
|
2017
|
+
const responsePath = findDeepValue(asRecord(response)['applied'] ?? response, 'path');
|
|
2018
|
+
const mediaPath = typeof responsePath === 'string'
|
|
2019
|
+
? normalizeCreatedMediaPath(responsePath)
|
|
2020
|
+
: data['path'];
|
|
2021
|
+
if (typeof mediaPath === 'string') {
|
|
2022
|
+
const directoryPath = mediaDirectoryPath(mediaPath);
|
|
2023
|
+
state.reads.set('live.media.path', mediaPath);
|
|
2024
|
+
state.reads.set('live.media.directory', directoryPath);
|
|
2025
|
+
state.created.push({
|
|
2026
|
+
lane: state.lane,
|
|
2027
|
+
family: 'media.files',
|
|
2028
|
+
id: mediaPath,
|
|
2029
|
+
label: `Live-test media ${mediaPath}`,
|
|
2030
|
+
});
|
|
2031
|
+
state.created.push({
|
|
2032
|
+
lane: state.lane,
|
|
2033
|
+
family: 'media.directories',
|
|
2034
|
+
id: directoryPath,
|
|
2035
|
+
label: `Live-test media directory ${directoryPath}`,
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
if (actionId === 'media.files.delete' && typeof input['path'] === 'string') {
|
|
2040
|
+
removeRetainedRecord(state, 'media.files', input['path']);
|
|
2041
|
+
const directoryPath = state.reads.get('live.media.directory');
|
|
2042
|
+
if (typeof directoryPath === 'string') {
|
|
2043
|
+
removeRetainedRecord(state, 'media.directories', directoryPath);
|
|
2044
|
+
state.reads.delete('live.media.directory');
|
|
2045
|
+
}
|
|
2046
|
+
state.reads.delete('live.media.path');
|
|
2047
|
+
}
|
|
2048
|
+
if (actionId === 'languages.overrides.site.create' ||
|
|
2049
|
+
actionId === 'languages.overrides.administrator.create') {
|
|
2050
|
+
const constant = asRecord(input['data'])['key'];
|
|
2051
|
+
if (typeof constant === 'string') {
|
|
2052
|
+
state.created.push({
|
|
2053
|
+
lane: state.lane,
|
|
2054
|
+
family: actionId.startsWith('languages.overrides.site')
|
|
2055
|
+
? 'languages.overrides.site'
|
|
2056
|
+
: 'languages.overrides.administrator',
|
|
2057
|
+
id: constant,
|
|
2058
|
+
label: `${String(input['language'])} ${constant}`,
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
if ((actionId === 'languages.overrides.site.delete' ||
|
|
2063
|
+
actionId === 'languages.overrides.administrator.delete') &&
|
|
2064
|
+
typeof input['constant'] === 'string') {
|
|
2065
|
+
removeRetainedRecord(state, actionId.startsWith('languages.overrides.site')
|
|
2066
|
+
? 'languages.overrides.site'
|
|
2067
|
+
: 'languages.overrides.administrator', input['constant']);
|
|
2068
|
+
}
|
|
2069
|
+
if (actionId === 'privacy.requests.create')
|
|
2070
|
+
state.reads.set('privacy.requests.create', response);
|
|
2071
|
+
if (actionId === 'joomla-update.prepare') {
|
|
2072
|
+
const filename = findDeepValue(response, 'filename');
|
|
2073
|
+
if (typeof filename === 'string' && filename.length > 0) {
|
|
2074
|
+
state.reads.set('live.joomla-update.filename', filename);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
if (actionId === 'privacy.requests.create') {
|
|
2078
|
+
const entity = firstEntity(response);
|
|
2079
|
+
if (entity !== undefined) {
|
|
2080
|
+
state.created.push({
|
|
2081
|
+
lane: state.lane,
|
|
2082
|
+
family: 'privacy.requests',
|
|
2083
|
+
id: entity.id,
|
|
2084
|
+
label: `Privacy request generated by live test ${state.lane}`,
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
async function executeSpecialWrite(session, path, site, scenario, input, state, seed) {
|
|
2090
|
+
let directoryCreation;
|
|
2091
|
+
if (scenario.id === 'media.files.create') {
|
|
2092
|
+
const filePath = asRecord(input['data'])['path'];
|
|
2093
|
+
if (typeof filePath !== 'string') {
|
|
2094
|
+
throw new Error('Media fixture creation requires a deterministic file path.');
|
|
2095
|
+
}
|
|
2096
|
+
const directoryPath = mediaDirectoryPath(filePath);
|
|
2097
|
+
directoryCreation = await callWrite(session, site, scenario.id, { data: { path: directoryPath, override: false } }, path);
|
|
2098
|
+
try {
|
|
2099
|
+
const applied = await callWrite(session, site, scenario.id, input, path);
|
|
2100
|
+
const verification = await callRead(session, site, 'media.files.get', { path: filePath }, path);
|
|
2101
|
+
return { applied, directoryCreation, verification };
|
|
2102
|
+
}
|
|
2103
|
+
catch (error) {
|
|
2104
|
+
try {
|
|
2105
|
+
await callWrite(session, site, 'media.files.delete', { path: directoryPath }, path);
|
|
2106
|
+
}
|
|
2107
|
+
catch {
|
|
2108
|
+
// Preserve the file-creation failure as the primary diagnostic.
|
|
2109
|
+
}
|
|
2110
|
+
throw error;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
const applied = await callWrite(session, site, scenario.id, input, path);
|
|
2114
|
+
if (scenario.id === 'joomla-update.prepare') {
|
|
2115
|
+
const filename = findDeepValue(applied, 'filename');
|
|
2116
|
+
const filesize = Number(findDeepValue(applied, 'filesize'));
|
|
2117
|
+
if (typeof filename !== 'string' || filename.length === 0 || !Number.isFinite(filesize) || filesize < 1) {
|
|
2118
|
+
throw new Error('Joomla Update prepare did not return a non-empty filename and positive file size.');
|
|
2119
|
+
}
|
|
2120
|
+
return applied;
|
|
2121
|
+
}
|
|
2122
|
+
if (scenario.id === 'joomla-update.finalize' ||
|
|
2123
|
+
scenario.id === 'joomla-update.notification.failed' ||
|
|
2124
|
+
scenario.id === 'joomla-update.notification.success') {
|
|
2125
|
+
const success = findDeepValue(applied, 'success');
|
|
2126
|
+
if (success !== true && success !== 1 && success !== '1') {
|
|
2127
|
+
throw new Error(`${scenario.id} returned success=${String(success)}: ${JSON.stringify(findDeepValue(applied, 'errors') ?? [])}`);
|
|
2128
|
+
}
|
|
2129
|
+
return applied;
|
|
2130
|
+
}
|
|
2131
|
+
if (scenario.id === 'configuration.application.update') {
|
|
2132
|
+
const verification = await callRead(session, site, 'configuration.application.get', {}, path);
|
|
2133
|
+
const current = findDeepValue(state.reads.get('configuration.application.get'), 'sitename');
|
|
2134
|
+
if (typeof current !== 'string' || current.length === 0) {
|
|
2135
|
+
throw new Error('Application configuration read did not expose the original safe sitename for restoration.');
|
|
2136
|
+
}
|
|
2137
|
+
const restored = await callWrite(session, site, scenario.id, { data: { sitename: current } }, path);
|
|
2138
|
+
return { applied, verification, restoration: restored };
|
|
2139
|
+
}
|
|
2140
|
+
if (scenario.id.endsWith('-history.keep')) {
|
|
2141
|
+
const restored = await callWrite(session, site, scenario.id, input, path);
|
|
2142
|
+
return { applied, restoration: restored };
|
|
2143
|
+
}
|
|
2144
|
+
if (scenario.id === 'plugins.plugins.update') {
|
|
2145
|
+
const plugin = toggleCandidate(state.reads.get('plugins.plugins.list'));
|
|
2146
|
+
if (plugin === undefined)
|
|
2147
|
+
throw new Error('Plugin state disappeared before restoration.');
|
|
2148
|
+
const verification = await callRead(session, site, 'plugins.plugins.get', { id: numericId(plugin.id) }, path);
|
|
2149
|
+
const originalEnabled = Number(plugin.attributes['enabled'] ?? 1);
|
|
2150
|
+
const restored = await callWrite(session, site, scenario.id, { id: numericId(plugin.id), data: { enabled: originalEnabled === 1 ? 1 : 0 } }, path);
|
|
2151
|
+
return { applied, verification, restoration: restored };
|
|
2152
|
+
}
|
|
2153
|
+
if (scenario.id === 'site.state.set') {
|
|
2154
|
+
const verification = await callRead(session, site, 'site.state.get', {}, path);
|
|
2155
|
+
const restored = await callWrite(session, site, scenario.id, { offline: false }, path);
|
|
2156
|
+
return { applied, verification, restoration: restored };
|
|
2157
|
+
}
|
|
2158
|
+
if (scenario.id === 'extensions.state.set') {
|
|
2159
|
+
return restoreBooleanCompanionState(session, path, site, scenario.id, input, applied, toggleCandidate(state.reads.get('extensions.list'))?.attributes['enabled']);
|
|
2160
|
+
}
|
|
2161
|
+
if (scenario.id === 'extensions.update-sites.state.set') {
|
|
2162
|
+
return restoreBooleanCompanionState(session, path, site, scenario.id, input, applied, firstEntity(state.reads.get('extensions.update-sites.list'))?.attributes['enabled']);
|
|
2163
|
+
}
|
|
2164
|
+
if (scenario.id === 'scheduler.tasks.state.set') {
|
|
2165
|
+
const current = firstEntity(state.reads.get('scheduler.tasks.list'))?.attributes['state'];
|
|
2166
|
+
const restored = await callWrite(session, site, scenario.id, {
|
|
2167
|
+
id: input['id'],
|
|
2168
|
+
state: Number(current ?? 1),
|
|
2169
|
+
}, path);
|
|
2170
|
+
return { applied, restoration: restored };
|
|
2171
|
+
}
|
|
2172
|
+
if (scenario.id.endsWith('.state')) {
|
|
2173
|
+
const baseId = scenario.id.slice(0, -'.state'.length);
|
|
2174
|
+
const entity = state.records.get(baseId);
|
|
2175
|
+
if (entity === undefined)
|
|
2176
|
+
throw new Error(`State restoration lost fixture ${baseId}.`);
|
|
2177
|
+
const readAction = `${baseId}.get`;
|
|
2178
|
+
const verification = await callRead(session, site, readAction, { id: numericId(entity.id) }, path);
|
|
2179
|
+
const originalState = Number(entity.attributes['state'] ?? entity.attributes['published'] ?? 1);
|
|
2180
|
+
const restored = await callWrite(session, site, scenario.id, {
|
|
2181
|
+
id: numericId(entity.id),
|
|
2182
|
+
state: originalState,
|
|
2183
|
+
}, path);
|
|
2184
|
+
return { applied, verification, restoration: restored };
|
|
2185
|
+
}
|
|
2186
|
+
if (scenario.id === 'media.files.update') {
|
|
2187
|
+
const canonicalPath = state.reads.get('live.media.path');
|
|
2188
|
+
const verification = typeof canonicalPath === 'string'
|
|
2189
|
+
? await callRead(session, site, 'media.files.get', { path: canonicalPath }, path)
|
|
2190
|
+
: undefined;
|
|
2191
|
+
return { applied, verification };
|
|
2192
|
+
}
|
|
2193
|
+
if (scenario.id === 'media.files.delete') {
|
|
2194
|
+
await assertMediaAbsent(session, site, input['path'], path);
|
|
2195
|
+
const directoryPath = state.reads.get('live.media.directory');
|
|
2196
|
+
let directoryDeletion;
|
|
2197
|
+
if (typeof directoryPath === 'string') {
|
|
2198
|
+
directoryDeletion = await callWrite(session, site, scenario.id, { path: directoryPath }, path);
|
|
2199
|
+
await assertMediaAbsent(session, site, directoryPath, path);
|
|
2200
|
+
}
|
|
2201
|
+
return {
|
|
2202
|
+
applied,
|
|
2203
|
+
...(directoryDeletion === undefined ? {} : { directoryDeletion }),
|
|
2204
|
+
verification: { absent: true, directoryAbsent: directoryDeletion !== undefined },
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
void seed;
|
|
2208
|
+
return applied;
|
|
2209
|
+
}
|
|
2210
|
+
async function restoreBooleanCompanionState(session, path, site, action, input, applied, original) {
|
|
2211
|
+
const restored = await callWrite(session, site, action, {
|
|
2212
|
+
id: input['id'],
|
|
2213
|
+
enabled: Number(original ?? 1) === 1,
|
|
2214
|
+
}, path);
|
|
2215
|
+
return { applied, restoration: restored };
|
|
2216
|
+
}
|
|
2217
|
+
async function addExpectedDenial(session, path, scenario, phase, reason, record) {
|
|
2218
|
+
await record(session, path, scenario, phase, {}, async () => ({
|
|
2219
|
+
status: 'EXPECTED_DENIAL',
|
|
2220
|
+
reason,
|
|
2221
|
+
expected: 'No mutation is dispatched without an explicitly disposable target.',
|
|
2222
|
+
}));
|
|
2223
|
+
}
|
|
2224
|
+
function rememberReference(actionId, response, state) {
|
|
2225
|
+
if (!actionId.endsWith('.list'))
|
|
2226
|
+
return;
|
|
2227
|
+
const baseId = actionId.slice(0, -'.list'.length);
|
|
2228
|
+
const entity = firstEntity(response);
|
|
2229
|
+
if (entity !== undefined)
|
|
2230
|
+
state.references.set(baseId, entity);
|
|
2231
|
+
}
|
|
2232
|
+
function removeRetainedRecord(state, family, id) {
|
|
2233
|
+
const index = state.created.findIndex((candidate) => candidate.family === family && String(candidate.id) === String(id));
|
|
2234
|
+
if (index >= 0)
|
|
2235
|
+
state.created.splice(index, 1);
|
|
2236
|
+
}
|
|
2237
|
+
function idFromRead(state, readAction) {
|
|
2238
|
+
const entity = firstEntity(state.reads.get(readAction));
|
|
2239
|
+
return entity === undefined
|
|
2240
|
+
? new BlockedError(`${readAction} did not return a usable item.`, [readAction])
|
|
2241
|
+
: { id: numericId(entity.id) };
|
|
2242
|
+
}
|
|
2243
|
+
function idFromMatchingRead(state, readAction, attribute, expected) {
|
|
2244
|
+
const entity = collectEntities(state.reads.get(readAction)).find((candidate) => looselyEqual(candidate.attributes[attribute], expected));
|
|
2245
|
+
return entity === undefined
|
|
2246
|
+
? new BlockedError(`${readAction} did not return the fixture record with ${attribute}=${expected}.`, [readAction])
|
|
2247
|
+
: { id: numericId(entity.id) };
|
|
2248
|
+
}
|
|
2249
|
+
function firstCompanionId(state, readAction, extra = {}) {
|
|
2250
|
+
const entity = firstEntity(state.reads.get(readAction));
|
|
2251
|
+
return entity === undefined
|
|
2252
|
+
? new BlockedError(`${readAction} did not return a usable item.`, [readAction])
|
|
2253
|
+
: { id: numericId(entity.id), ...extra };
|
|
2254
|
+
}
|
|
2255
|
+
function historyBase(actionId) {
|
|
2256
|
+
if (actionId.startsWith('content.article-history.'))
|
|
2257
|
+
return 'content.articles';
|
|
2258
|
+
if (actionId.startsWith('contacts.contact-history.'))
|
|
2259
|
+
return 'contacts.contacts';
|
|
2260
|
+
if (actionId.startsWith('banners.banner-history.'))
|
|
2261
|
+
return 'banners.banners';
|
|
2262
|
+
return undefined;
|
|
2263
|
+
}
|
|
2264
|
+
function firstEntity(value) {
|
|
2265
|
+
const candidate = findEntity(value);
|
|
2266
|
+
if (candidate === undefined)
|
|
2267
|
+
return undefined;
|
|
2268
|
+
const id = candidate['id'] ?? candidate['lang_id'] ?? candidate['message_id'] ??
|
|
2269
|
+
candidate['update_site_id'] ?? candidate['updateSiteId'] ??
|
|
2270
|
+
candidate['extension_id'] ?? candidate['extensionId'];
|
|
2271
|
+
if (typeof id !== 'string' && typeof id !== 'number')
|
|
2272
|
+
return undefined;
|
|
2273
|
+
const attributes = resourceAttributes(candidate);
|
|
2274
|
+
const labelValue = attributes['title'] ?? attributes['name'] ?? attributes['subject'] ?? attributes['username'] ?? id;
|
|
2275
|
+
return Object.freeze({ id, attributes: Object.freeze(attributes), label: String(labelValue) });
|
|
2276
|
+
}
|
|
2277
|
+
function toggleCandidate(value) {
|
|
2278
|
+
return collectEntities(value).find((entity) => Number(entity.attributes['enabled'] ?? entity.attributes['state'] ?? 1) === 0 &&
|
|
2279
|
+
!/token|authentication|joomla.?mcp/iu.test(String(entity.attributes['element'] ?? entity.attributes['name'] ?? entity.label)));
|
|
2280
|
+
}
|
|
2281
|
+
function collectEntities(value) {
|
|
2282
|
+
const output = [];
|
|
2283
|
+
const visit = (candidate, depth) => {
|
|
2284
|
+
if (depth > 12)
|
|
2285
|
+
return;
|
|
2286
|
+
if (Array.isArray(candidate)) {
|
|
2287
|
+
for (const entry of candidate)
|
|
2288
|
+
visit(entry, depth + 1);
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
const record = asRecord(candidate);
|
|
2292
|
+
const id = record['id'] ?? record['lang_id'] ?? record['message_id'] ??
|
|
2293
|
+
record['update_site_id'] ?? record['updateSiteId'] ??
|
|
2294
|
+
record['extension_id'] ?? record['extensionId'];
|
|
2295
|
+
if ((typeof id === 'string' || typeof id === 'number') && isResourceEntityRecord(record)) {
|
|
2296
|
+
const attributes = resourceAttributes(record);
|
|
2297
|
+
output.push({
|
|
2298
|
+
id,
|
|
2299
|
+
attributes,
|
|
2300
|
+
label: String(attributes['title'] ?? attributes['name'] ?? attributes['element'] ?? id),
|
|
2301
|
+
});
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
for (const key of ['applied', 'verification', 'mutation', 'result', 'data', 'item', 'items', 'records']) {
|
|
2305
|
+
if (record[key] !== undefined)
|
|
2306
|
+
visit(record[key], depth + 1);
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
visit(value, 0);
|
|
2310
|
+
return output;
|
|
2311
|
+
}
|
|
2312
|
+
function findEntity(value, depth = 0) {
|
|
2313
|
+
if (depth > 12)
|
|
2314
|
+
return undefined;
|
|
2315
|
+
if (Array.isArray(value)) {
|
|
2316
|
+
for (const entry of value) {
|
|
2317
|
+
const found = findEntity(entry, depth + 1);
|
|
2318
|
+
if (found !== undefined)
|
|
2319
|
+
return found;
|
|
2320
|
+
}
|
|
2321
|
+
return undefined;
|
|
2322
|
+
}
|
|
2323
|
+
const record = asRecord(value);
|
|
2324
|
+
if ((typeof record['id'] === 'string' || typeof record['id'] === 'number' ||
|
|
2325
|
+
typeof record['lang_id'] === 'number' || typeof record['message_id'] === 'number' ||
|
|
2326
|
+
typeof record['update_site_id'] === 'number' || typeof record['update_site_id'] === 'string' ||
|
|
2327
|
+
typeof record['updateSiteId'] === 'number' || typeof record['updateSiteId'] === 'string' ||
|
|
2328
|
+
typeof record['extension_id'] === 'number' || typeof record['extension_id'] === 'string' ||
|
|
2329
|
+
typeof record['extensionId'] === 'number' || typeof record['extensionId'] === 'string') &&
|
|
2330
|
+
isResourceEntityRecord(record)) {
|
|
2331
|
+
return record;
|
|
2332
|
+
}
|
|
2333
|
+
for (const key of ['applied', 'verification', 'mutation', 'result', 'data', 'item', 'items', 'records', 'commands']) {
|
|
2334
|
+
if (record[key] !== undefined) {
|
|
2335
|
+
const found = findEntity(record[key], depth + 1);
|
|
2336
|
+
if (found !== undefined)
|
|
2337
|
+
return found;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
return undefined;
|
|
2341
|
+
}
|
|
2342
|
+
export function entityFromMutation(response, submitted) {
|
|
2343
|
+
const entity = firstEntity(response);
|
|
2344
|
+
if (entity === undefined)
|
|
2345
|
+
return undefined;
|
|
2346
|
+
return Object.freeze({
|
|
2347
|
+
id: entity.id,
|
|
2348
|
+
attributes: Object.freeze({ ...submitted, ...entity.attributes }),
|
|
2349
|
+
label: String(entity.attributes['title'] ??
|
|
2350
|
+
entity.attributes['name'] ??
|
|
2351
|
+
entity.attributes['subject'] ??
|
|
2352
|
+
submitted['title'] ??
|
|
2353
|
+
submitted['name'] ??
|
|
2354
|
+
submitted['subject'] ??
|
|
2355
|
+
entity.id),
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
function isResourceEntityRecord(record) {
|
|
2359
|
+
return !('idempotencyKey' in record) &&
|
|
2360
|
+
record['protocol'] !== 'joomla-mcp/1' &&
|
|
2361
|
+
record['schema'] !== 'joomengine.joomla-mcp.live-test/v1';
|
|
2362
|
+
}
|
|
2363
|
+
function assertEntityId(entity, expected, action) {
|
|
2364
|
+
if (entity === undefined || String(entity.id) !== String(expected)) {
|
|
2365
|
+
throw new Error(`${action} returned resource ${String(entity?.id ?? 'none')}; expected ${String(expected)}.`);
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
function assertLanguageOverride(response, expectedConstant, expectedValue, action) {
|
|
2369
|
+
const entity = firstEntity(response);
|
|
2370
|
+
if (entity === undefined ||
|
|
2371
|
+
String(entity.id) !== expectedConstant ||
|
|
2372
|
+
String(entity.attributes['value'] ?? '') !== expectedValue) {
|
|
2373
|
+
throw new Error(`${action} did not return language override ${expectedConstant} with the submitted value.`);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
function assertChangedFields(response, changes, baseId) {
|
|
2377
|
+
const attributes = firstEntity(response)?.attributes ?? {};
|
|
2378
|
+
const mismatches = [];
|
|
2379
|
+
for (const [key, expected] of Object.entries(changes)) {
|
|
2380
|
+
if (key === 'password' || key === 'password2')
|
|
2381
|
+
continue;
|
|
2382
|
+
if (baseId === 'content.articles' &&
|
|
2383
|
+
(key === 'introtext' || key === 'fulltext' || key === 'articletext') &&
|
|
2384
|
+
typeof attributes['text'] === 'string') {
|
|
2385
|
+
const actualText = normalizeComparableText(attributes['text']);
|
|
2386
|
+
const expectedText = normalizeComparableText(expected);
|
|
2387
|
+
const matched = key === 'introtext'
|
|
2388
|
+
? actualText.startsWith(expectedText)
|
|
2389
|
+
: key === 'fulltext'
|
|
2390
|
+
? actualText.endsWith(expectedText)
|
|
2391
|
+
: actualText === expectedText;
|
|
2392
|
+
if (!matched)
|
|
2393
|
+
mismatches.push(fieldMismatch(key, expected, attributes['text']));
|
|
2394
|
+
continue;
|
|
2395
|
+
}
|
|
2396
|
+
if (!Object.hasOwn(attributes, key))
|
|
2397
|
+
continue;
|
|
2398
|
+
if (!looselyEqual(attributes[key], expected)) {
|
|
2399
|
+
mismatches.push(fieldMismatch(key, expected, attributes[key]));
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
if (mismatches.length > 0) {
|
|
2403
|
+
throw new Error(`Persisted ${baseId} field mismatch: ${mismatches.slice(0, 8).join('; ')}.`);
|
|
2404
|
+
}
|
|
2405
|
+
return attributes;
|
|
2406
|
+
}
|
|
2407
|
+
function entityMatchesFields(entity, changes) {
|
|
2408
|
+
return Object.entries(changes)
|
|
2409
|
+
.filter(([key]) => key !== 'password' && key !== 'password2')
|
|
2410
|
+
.every(([key, value]) => looselyEqual(entity.attributes[key], value));
|
|
2411
|
+
}
|
|
2412
|
+
function selectAttributes(attributes, fields) {
|
|
2413
|
+
return Object.fromEntries(fields
|
|
2414
|
+
.filter((field) => attributes[field] !== undefined)
|
|
2415
|
+
.map((field) => [field, attributes[field]]));
|
|
2416
|
+
}
|
|
2417
|
+
export function normalizeCreatedMediaPath(path) {
|
|
2418
|
+
return path.replace(/^([A-Za-z0-9][A-Za-z0-9._-]*):\/\.\/(?=.)/u, '$1:/');
|
|
2419
|
+
}
|
|
2420
|
+
export function mediaUpdateRoutePath(path) {
|
|
2421
|
+
const separator = path.indexOf(':');
|
|
2422
|
+
const relative = separator < 0 ? path : path.slice(separator + 1);
|
|
2423
|
+
return relative.replace(/^\/+/u, '');
|
|
2424
|
+
}
|
|
2425
|
+
export function mediaAdapterSelector(path) {
|
|
2426
|
+
const separator = path.indexOf(':');
|
|
2427
|
+
if (separator <= 0) {
|
|
2428
|
+
throw new Error(`Media fixture path must identify its adapter: ${path}`);
|
|
2429
|
+
}
|
|
2430
|
+
return `${path.slice(0, separator)}:`;
|
|
2431
|
+
}
|
|
2432
|
+
export function mediaDirectoryPath(path) {
|
|
2433
|
+
const separator = path.indexOf(':');
|
|
2434
|
+
const prefix = separator < 0 ? '' : path.slice(0, separator + 1);
|
|
2435
|
+
const relative = (separator < 0 ? path : path.slice(separator + 1)).replace(/^\/+/u, '');
|
|
2436
|
+
const directory = relative.slice(0, Math.max(0, relative.lastIndexOf('/')));
|
|
2437
|
+
if (directory.length === 0) {
|
|
2438
|
+
throw new Error(`Media fixture path must include a directory: ${path}`);
|
|
2439
|
+
}
|
|
2440
|
+
return `${prefix}${directory}`;
|
|
2441
|
+
}
|
|
2442
|
+
async function assertMediaAbsent(session, site, mediaPath, path) {
|
|
2443
|
+
try {
|
|
2444
|
+
await callRead(session, site, 'media.files.get', { path: mediaPath }, path);
|
|
2445
|
+
throw new Error(`Deleted media path ${String(mediaPath)} remains readable.`);
|
|
2446
|
+
}
|
|
2447
|
+
catch (error) {
|
|
2448
|
+
if (!(error instanceof LiveMcpToolError) || !/(?:404|not found|does not exist)/iu.test(error.message)) {
|
|
2449
|
+
throw error;
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
function looselyEqual(actual, expected) {
|
|
2454
|
+
if (JSON.stringify(actual) === JSON.stringify(expected))
|
|
2455
|
+
return true;
|
|
2456
|
+
if (Array.isArray(expected)) {
|
|
2457
|
+
const actualValues = Array.isArray(actual)
|
|
2458
|
+
? actual
|
|
2459
|
+
: isPlainRecord(actual)
|
|
2460
|
+
? Object.values(actual)
|
|
2461
|
+
: [];
|
|
2462
|
+
return JSON.stringify(actualValues.map(String).sort()) ===
|
|
2463
|
+
JSON.stringify(expected.map(String).sort());
|
|
2464
|
+
}
|
|
2465
|
+
if (isPlainRecord(expected)) {
|
|
2466
|
+
const decoded = typeof actual === 'string' ? parseJsonRecord(actual) : actual;
|
|
2467
|
+
if (!isPlainRecord(decoded))
|
|
2468
|
+
return false;
|
|
2469
|
+
return Object.entries(expected).every(([key, value]) => Object.hasOwn(decoded, key) && looselyEqual(decoded[key], value));
|
|
2470
|
+
}
|
|
2471
|
+
if (typeof expected === 'number' || typeof expected === 'boolean')
|
|
2472
|
+
return String(actual) === String(Number(expected));
|
|
2473
|
+
return String(actual ?? '') === String(expected ?? '');
|
|
2474
|
+
}
|
|
2475
|
+
function resourceAttributes(record) {
|
|
2476
|
+
const attributesValue = asRecord(record['attributes']);
|
|
2477
|
+
const attributes = Object.keys(attributesValue).length > 0
|
|
2478
|
+
? { ...attributesValue }
|
|
2479
|
+
: Object.fromEntries(Object.entries(record).filter(([key]) => key !== 'id' && key !== 'relationships'));
|
|
2480
|
+
const relationships = asRecord(record['relationships']);
|
|
2481
|
+
const relationFields = {
|
|
2482
|
+
category: 'catid',
|
|
2483
|
+
client: 'cid',
|
|
2484
|
+
};
|
|
2485
|
+
for (const [name, relationship] of Object.entries(relationships)) {
|
|
2486
|
+
const field = relationFields[name];
|
|
2487
|
+
if (field === undefined || Object.hasOwn(attributes, field))
|
|
2488
|
+
continue;
|
|
2489
|
+
const data = asRecord(relationship)['data'];
|
|
2490
|
+
if (Array.isArray(data)) {
|
|
2491
|
+
attributes[field] = data
|
|
2492
|
+
.map((entry) => asRecord(entry)['id'])
|
|
2493
|
+
.filter((id) => typeof id === 'string' || typeof id === 'number');
|
|
2494
|
+
}
|
|
2495
|
+
else {
|
|
2496
|
+
const id = asRecord(data)['id'];
|
|
2497
|
+
if (typeof id === 'string' || typeof id === 'number')
|
|
2498
|
+
attributes[field] = id;
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
return Object.freeze(attributes);
|
|
2502
|
+
}
|
|
2503
|
+
function normalizeComparableText(value) {
|
|
2504
|
+
return String(value ?? '').replace(/\s+/gu, ' ').trim();
|
|
2505
|
+
}
|
|
2506
|
+
function fieldMismatch(key, expected, actual) {
|
|
2507
|
+
return `${key} expected=${JSON.stringify(expected)} actual=${JSON.stringify(actual)}`;
|
|
2508
|
+
}
|
|
2509
|
+
function isPlainRecord(value) {
|
|
2510
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2511
|
+
}
|
|
2512
|
+
function parseJsonRecord(value) {
|
|
2513
|
+
try {
|
|
2514
|
+
return JSON.parse(value);
|
|
2515
|
+
}
|
|
2516
|
+
catch {
|
|
2517
|
+
return value;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
function validateSelection(options, site) {
|
|
2521
|
+
if (options.joomlaPaths.length === 0 || options.mcpTransports.length === 0) {
|
|
2522
|
+
throw new Error('At least one Joomla path and one MCP transport are required.');
|
|
2523
|
+
}
|
|
2524
|
+
if (options.joomlaPaths.includes('api') && site.api === undefined) {
|
|
2525
|
+
throw new Error(`Site ${site.id} does not configure the Joomla API path.`);
|
|
2526
|
+
}
|
|
2527
|
+
if (options.joomlaPaths.includes('cli') && site.cli === undefined) {
|
|
2528
|
+
throw new Error(`Site ${site.id} does not configure the companion CLI path.`);
|
|
2529
|
+
}
|
|
2530
|
+
if (options.nonInteractive && isMutatingProfile(options.profile) && !options.confirmMutations) {
|
|
2531
|
+
throw new Error('Non-interactive mutation profiles require --confirm-mutations.');
|
|
2532
|
+
}
|
|
2533
|
+
if (options.profile === 'full' && options.nonInteractive && !options.disposable) {
|
|
2534
|
+
throw new Error('The non-interactive full profile requires --disposable.');
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
function isRead(scenario) {
|
|
2538
|
+
return scenario.risk === 'read' || scenario.risk === 'sensitive-read';
|
|
2539
|
+
}
|
|
2540
|
+
function isMutatingProfile(profile) {
|
|
2541
|
+
return profile === 'crud' || profile === 'full';
|
|
2542
|
+
}
|
|
2543
|
+
function targetHostname(site) {
|
|
2544
|
+
if (site.api !== undefined)
|
|
2545
|
+
return new URL(site.api.baseUrl).hostname;
|
|
2546
|
+
return operatingSystemHostname();
|
|
2547
|
+
}
|
|
2548
|
+
function configurationForFingerprint(configuration, siteId) {
|
|
2549
|
+
const site = configuration.sites.get(siteId);
|
|
2550
|
+
return {
|
|
2551
|
+
defaultSite: configuration.defaultSite,
|
|
2552
|
+
selectedSite: siteId,
|
|
2553
|
+
toolsets: site === undefined ? [] : [...site.toolsets].sort(),
|
|
2554
|
+
api: site?.api === undefined ? false : {
|
|
2555
|
+
baseUrl: site.api.baseUrl,
|
|
2556
|
+
timeoutMs: site.api.timeoutMs,
|
|
2557
|
+
maxResponseBytes: site.api.maxResponseBytes,
|
|
2558
|
+
maxPageSize: site.api.maxPageSize,
|
|
2559
|
+
updateTokenConfigured: site.api.updateToken !== undefined,
|
|
2560
|
+
},
|
|
2561
|
+
cli: site?.cli === undefined ? false : {
|
|
2562
|
+
root: site.cli.root,
|
|
2563
|
+
phpBinary: site.cli.phpBinary,
|
|
2564
|
+
timeoutMs: site.cli.timeoutMs,
|
|
2565
|
+
maxOutputBytes: site.cli.maxOutputBytes,
|
|
2566
|
+
},
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
function numericId(value) {
|
|
2570
|
+
const id = Number(value);
|
|
2571
|
+
if (!Number.isSafeInteger(id) || id < 1)
|
|
2572
|
+
throw new Error(`Expected a positive Joomla resource id; received ${String(value)}.`);
|
|
2573
|
+
return id;
|
|
2574
|
+
}
|
|
2575
|
+
function asRecord(value) {
|
|
2576
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
2577
|
+
? value
|
|
2578
|
+
: {};
|
|
2579
|
+
}
|
|
2580
|
+
function errorMessage(error) {
|
|
2581
|
+
return error instanceof Error ? error.message : String(error);
|
|
2582
|
+
}
|
|
2583
|
+
function errorResult(error) {
|
|
2584
|
+
return error instanceof LiveMcpToolError ? error.result : { message: errorMessage(error) };
|
|
2585
|
+
}
|
|
2586
|
+
function classifyError(error) {
|
|
2587
|
+
const message = errorMessage(error);
|
|
2588
|
+
const http = /HTTP\s+(\d{3})/iu.exec(message)?.[1];
|
|
2589
|
+
if (http !== undefined)
|
|
2590
|
+
return `joomla_http_${http}`;
|
|
2591
|
+
if (/timeout/iu.test(message))
|
|
2592
|
+
return 'timeout';
|
|
2593
|
+
if (/MCP tool/iu.test(message))
|
|
2594
|
+
return 'mcp_tool_error';
|
|
2595
|
+
if (/companion/iu.test(message))
|
|
2596
|
+
return 'companion_error';
|
|
2597
|
+
if (/postcondition|expected|returned resource/iu.test(message))
|
|
2598
|
+
return 'postcondition_failed';
|
|
2599
|
+
return 'unexpected_error';
|
|
2600
|
+
}
|
|
2601
|
+
function isJoomlaHttpError(error, status) {
|
|
2602
|
+
return error instanceof LiveMcpToolError &&
|
|
2603
|
+
new RegExp(`Joomla API returned HTTP ${status}(?:\\D|$)`, 'iu').test(error.message);
|
|
2604
|
+
}
|
|
2605
|
+
function findDeepValue(value, key, depth = 0) {
|
|
2606
|
+
if (depth > 12)
|
|
2607
|
+
return undefined;
|
|
2608
|
+
if (Array.isArray(value)) {
|
|
2609
|
+
for (const entry of value) {
|
|
2610
|
+
const found = findDeepValue(entry, key, depth + 1);
|
|
2611
|
+
if (found !== undefined)
|
|
2612
|
+
return found;
|
|
2613
|
+
}
|
|
2614
|
+
return undefined;
|
|
2615
|
+
}
|
|
2616
|
+
const record = asRecord(value);
|
|
2617
|
+
if (record[key] !== undefined)
|
|
2618
|
+
return record[key];
|
|
2619
|
+
for (const entry of Object.values(record)) {
|
|
2620
|
+
const found = findDeepValue(entry, key, depth + 1);
|
|
2621
|
+
if (found !== undefined)
|
|
2622
|
+
return found;
|
|
2623
|
+
}
|
|
2624
|
+
return undefined;
|
|
2625
|
+
}
|
|
2626
|
+
function safeSegment(value) {
|
|
2627
|
+
return value.replace(/[^A-Za-z0-9._-]+/gu, '-').replace(/^-|-$/gu, '') || 'value';
|
|
2628
|
+
}
|
|
2629
|
+
function heartbeatSecondsFromEnvironment(fallbackSeconds) {
|
|
2630
|
+
const configured = process.env['JOOMLA_MCP_LIVE_HEARTBEAT_MS'];
|
|
2631
|
+
if (configured === undefined)
|
|
2632
|
+
return fallbackSeconds;
|
|
2633
|
+
const milliseconds = Number(configured);
|
|
2634
|
+
if (!Number.isFinite(milliseconds) || milliseconds < 5_000 || milliseconds > 300_000) {
|
|
2635
|
+
return fallbackSeconds;
|
|
2636
|
+
}
|
|
2637
|
+
return milliseconds / 1_000;
|
|
2638
|
+
}
|
|
2639
|
+
function readPriority(actionId) {
|
|
2640
|
+
if (actionId.endsWith('.list'))
|
|
2641
|
+
return 0;
|
|
2642
|
+
if (actionId.endsWith('.get'))
|
|
2643
|
+
return 1;
|
|
2644
|
+
if (actionId.endsWith('.export'))
|
|
2645
|
+
return 2;
|
|
2646
|
+
return 0;
|
|
2647
|
+
}
|
|
2648
|
+
export function specialWritePriority(actionId) {
|
|
2649
|
+
if (actionId.endsWith('-history.keep'))
|
|
2650
|
+
return 10;
|
|
2651
|
+
if (actionId.endsWith('-history.delete'))
|
|
2652
|
+
return 20;
|
|
2653
|
+
if (actionId === 'media.files.create')
|
|
2654
|
+
return 10;
|
|
2655
|
+
if (actionId === 'media.files.update')
|
|
2656
|
+
return 20;
|
|
2657
|
+
if (actionId === 'media.files.delete')
|
|
2658
|
+
return 30;
|
|
2659
|
+
if (actionId === 'scheduler.tasks.state.set')
|
|
2660
|
+
return 10;
|
|
2661
|
+
if (actionId === 'scheduler.tasks.run')
|
|
2662
|
+
return 20;
|
|
2663
|
+
if (actionId === 'joomla-update.prepare')
|
|
2664
|
+
return 10;
|
|
2665
|
+
if (actionId.startsWith('joomla-update.notification.'))
|
|
2666
|
+
return 20;
|
|
2667
|
+
if (actionId === 'joomla-update.finalize')
|
|
2668
|
+
return 30;
|
|
2669
|
+
if (actionId.endsWith('.create'))
|
|
2670
|
+
return 10;
|
|
2671
|
+
if (actionId.endsWith('.update'))
|
|
2672
|
+
return 20;
|
|
2673
|
+
if (actionId.endsWith('.delete'))
|
|
2674
|
+
return 30;
|
|
2675
|
+
return 15;
|
|
2676
|
+
}
|
|
2677
|
+
function shellArgument(value) {
|
|
2678
|
+
return /^[A-Za-z0-9_./:@=-]+$/u.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
|
|
2679
|
+
}
|
|
2680
|
+
//# sourceMappingURL=runner.js.map
|