* @brief Dry-run a script then write it via the matching setCode endpoint. */
| 371 | * @brief Dry-run a script then write it via the matching setCode endpoint. |
| 372 | */ |
| 373 | API::CommandResponse API::Handlers::AssistantHandler::scriptApply(const QString& id, |
| 374 | const QJsonObject& params) |
| 375 | { |
| 376 | const auto kind = params.value(QStringLiteral("kind")).toString(); |
| 377 | const auto dryInner = dryRunCommandForKind(kind); |
| 378 | const auto setInner = setCodeCommandForKind(kind); |
| 379 | if (dryInner.isEmpty() || setInner.isEmpty()) |
| 380 | return unknownKindError( |
| 381 | id, |
| 382 | kind, |
| 383 | QStringLiteral("frame_parser, transform, painter (output_widget code is applied via " |
| 384 | "project.outputWidget.update; end_to_end is dry-run only)")); |
| 385 | |
| 386 | QJsonObject inner = params; |
| 387 | inner.remove(QStringLiteral("kind")); |
| 388 | |
| 389 | if (kind == QStringLiteral("transform") && !inner.contains(QStringLiteral("values"))) { |
| 390 | QJsonArray defaults; |
| 391 | defaults.append(0.0); |
| 392 | inner.insert(QStringLiteral("values"), defaults); |
| 393 | } |
| 394 | |
| 395 | QString effectiveDry = dryInner; |
| 396 | if (kind == QStringLiteral("frame_parser") && !inner.contains(QStringLiteral("inputBytes")) |
| 397 | && !inner.contains(QStringLiteral("inputBytesHex"))) |
| 398 | effectiveDry = QStringLiteral("project.frameParser.dryCompile"); |
| 399 | |
| 400 | QJsonArray steps; |
| 401 | const auto dryResp = forward(effectiveDry, QStringLiteral("inner"), inner); |
| 402 | steps.append(toStep(QStringLiteral("dryRun"), dryResp)); |
| 403 | |
| 404 | const bool reportedOk = !dryResp.result.contains(QStringLiteral("ok")) |
| 405 | || dryResp.result.value(QStringLiteral("ok")).toBool(true); |
| 406 | if (!dryResp.success || !reportedOk) { |
| 407 | QJsonObject data; |
| 408 | data[QStringLiteral("steps")] = steps; |
| 409 | return CommandResponse::makeError(id, |
| 410 | dryResp.success ? ErrorCode::ExecutionError |
| 411 | : dryResp.errorCode, |
| 412 | QStringLiteral("Dry-run failed; setCode skipped."), |
| 413 | data); |
| 414 | } |
| 415 | |
| 416 | QJsonObject setParams = inner; |
| 417 | setParams.remove(QStringLiteral("values")); |
| 418 | setParams.remove(QStringLiteral("inputBytes")); |
| 419 | setParams.remove(QStringLiteral("inputBytesHex")); |
| 420 | setParams.remove(Keys::DecoderMethod); |
| 421 | setParams.remove(Keys::FrameDetection); |
| 422 | setParams.remove(Keys::FrameStart); |
| 423 | setParams.remove(Keys::FrameEnd); |
| 424 | setParams.remove(Keys::HexadecimalDelimiters); |
| 425 | setParams.remove(Keys::ChecksumAlgorithm); |
| 426 | setParams.remove(QStringLiteral("operationMode")); |
| 427 | |
| 428 | const auto setResp = forward(setInner, QStringLiteral("inner"), setParams); |
| 429 | steps.append(toStep(QStringLiteral("setCode"), setResp)); |
| 430 | if (!setResp.success) { |
nothing calls this directly
no test coverage detected