@tsplc/build 0.5.8 → 0.5.10
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/dist/cli.js +507 -450
- package/dist/cli.js.map +14 -13
- package/dist/images.js +18 -3
- package/dist/images.js.map +4 -4
- package/dist/index.js +548 -443
- package/dist/index.js.map +14 -13
- package/docker/Dockerfile +3 -0
- package/docker/runner.ts +9 -1
- package/package.json +4 -4
- package/python/codesys_online.py +50 -11
- package/python/worker.py +1 -0
- package/src/controller-online.ts +118 -28
- package/src/controller-protocol.ts +49 -7
- package/src/controller-session.ts +179 -40
- package/src/docker-context.ts +31 -4
- package/src/host/codesys-worker.ts +8 -2
- package/src/images.ts +7 -1
- package/src/index.ts +8 -0
- package/src/online-change-check.ts +208 -0
- package/src/st/declarations.ts +107 -1
package/docker/Dockerfile
CHANGED
|
@@ -188,6 +188,9 @@ COPY docker/entrypoint.sh docker/runner.ts docker/config.ts ./docker/
|
|
|
188
188
|
RUN chmod +x docker/entrypoint.sh
|
|
189
189
|
ENV WINEPREFIX=/tmp/codesys-wine HOME=/tmp/codesys-home WINEARCH=win64 \
|
|
190
190
|
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--disable-gpu
|
|
191
|
+
# The CODESYS engineering this image installs, which a controller baseline is matched on.
|
|
192
|
+
ARG TSPLC_ENGINEERING=
|
|
193
|
+
ENV TSPLC_ENGINEERING=${TSPLC_ENGINEERING}
|
|
191
194
|
WORKDIR /workspace
|
|
192
195
|
ENTRYPOINT ["/opt/codesys-build/docker/entrypoint.sh"]
|
|
193
196
|
CMD ["--help"]
|
package/docker/runner.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
|
-
import { tcpPort } from "@tsplc/config/build";
|
|
6
|
+
import { sha256Digest, tcpPort } from "@tsplc/config/build";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { buildFiles, publishBuild } from "../src/artifacts";
|
|
9
9
|
import { buildInContainer } from "../src/build";
|
|
@@ -119,9 +119,15 @@ if (!values.job) {
|
|
|
119
119
|
process.exit(code);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// The image's build records the CODESYS engineering it installs; older images record none.
|
|
123
|
+
const engineering =
|
|
124
|
+
sha256Digest.or(z.literal("")).parse(process.env.TSPLC_ENGINEERING ?? "") ||
|
|
125
|
+
null;
|
|
126
|
+
|
|
122
127
|
if (operation === "login") {
|
|
123
128
|
await serveControllerLogin(config, {
|
|
124
129
|
imageId: imageIdSchema.parse(values["image-id"]),
|
|
130
|
+
engineering,
|
|
125
131
|
port: portSchema.parse(values.port),
|
|
126
132
|
});
|
|
127
133
|
process.exit(0);
|
|
@@ -130,6 +136,7 @@ if (operation === "login") {
|
|
|
130
136
|
if (operation === "warm") {
|
|
131
137
|
await serveWarmController(config, {
|
|
132
138
|
imageId: imageIdSchema.parse(values["image-id"]),
|
|
139
|
+
engineering,
|
|
133
140
|
port: portSchema.parse(values.port),
|
|
134
141
|
loadConfig: async (path) =>
|
|
135
142
|
resolveContainerConfig(JSON.parse(await readFile(path, "utf8")), path),
|
|
@@ -145,6 +152,7 @@ if (operation !== "build") {
|
|
|
145
152
|
.parse(JSON.parse(values.read ?? "[]"));
|
|
146
153
|
await runControllerSession(config, operation, {
|
|
147
154
|
imageId,
|
|
155
|
+
engineering,
|
|
148
156
|
operationId,
|
|
149
157
|
scratch: containerScratch,
|
|
150
158
|
read,
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "git+https://github.com/rip-technologies/tsplc.git",
|
|
16
16
|
"directory": "packages/build"
|
|
17
17
|
},
|
|
18
|
-
"version": "0.5.
|
|
18
|
+
"version": "0.5.10",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"zod": "4.3.6",
|
|
57
|
-
"@tsplc/config": "0.5.
|
|
58
|
-
"@tsplc/typegen": "0.5.
|
|
59
|
-
"@tsplc/iec": "0.5.
|
|
57
|
+
"@tsplc/config": "0.5.10",
|
|
58
|
+
"@tsplc/typegen": "0.5.10",
|
|
59
|
+
"@tsplc/iec": "0.5.10"
|
|
60
60
|
},
|
|
61
61
|
"bin": {
|
|
62
62
|
"tsplc-build": "./dist/cli.js"
|
package/python/codesys_online.py
CHANGED
|
@@ -5,7 +5,7 @@ import io
|
|
|
5
5
|
import json
|
|
6
6
|
import os
|
|
7
7
|
import re
|
|
8
|
-
from build import (CompilerError, clear_diagnostics,
|
|
8
|
+
from build import (CompilerError, clear_diagnostics, import_source, keep_device_tree,
|
|
9
9
|
open_template, reported_errors, write_progress)
|
|
10
10
|
from hardware import update_device_tree, verify_pinned
|
|
11
11
|
from System import Activator, AppDomain, Array, Enum, Environment, Object
|
|
@@ -35,13 +35,42 @@ def fail_on_download_errors(engine):
|
|
|
35
35
|
raise CompilerError(errors)
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
def download_required(message):
|
|
39
|
-
"""A refusal only a full download resolves; the worker marks its reply so callers can offer one
|
|
38
|
+
def download_required(message, messages=()):
|
|
39
|
+
"""A refusal only a full download resolves; the worker marks its reply so callers can offer one,
|
|
40
|
+
and passes on `messages`, CODESYS's reasons in its own words."""
|
|
40
41
|
error = RuntimeError(message)
|
|
41
42
|
error.download_required = True
|
|
43
|
+
error.messages = list(messages)
|
|
42
44
|
return error
|
|
43
45
|
|
|
44
46
|
|
|
47
|
+
CANNOT_APPLY = 'CODESYS cannot apply this source as an online change; use an explicit download'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def refusal_with_reasons(diagnostics):
|
|
51
|
+
reasons = [item['text'] for item in diagnostics]
|
|
52
|
+
return download_required('\n'.join([CANNOT_APPLY + ':'] + reasons), reasons)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def fail_on_online_change_errors(engine):
|
|
56
|
+
"""CODESYS reports its advice that no online change is possible as an error of the incremental
|
|
57
|
+
build. That advice is a refusal only a full download resolves, and it says why; any other error
|
|
58
|
+
is the source's, and still fails the operation."""
|
|
59
|
+
errors = reported_errors(engine)
|
|
60
|
+
others = [error for error in errors if not error['text'].startswith(NO_ONLINE_CHANGE)]
|
|
61
|
+
if others:
|
|
62
|
+
raise CompilerError(others)
|
|
63
|
+
if errors:
|
|
64
|
+
raise refusal_with_reasons(errors)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def fail_on_online_code_errors(engine):
|
|
68
|
+
"""The source built, so what generating its online-change code reports is about the change."""
|
|
69
|
+
errors = reported_errors(engine)
|
|
70
|
+
if errors:
|
|
71
|
+
raise refusal_with_reasons(errors)
|
|
72
|
+
|
|
73
|
+
|
|
45
74
|
def core_application(online_application):
|
|
46
75
|
# The shipped scripting wrapper omits Keep from its login switch. Its core
|
|
47
76
|
# application provides a session-only login, which never compiles/downloads.
|
|
@@ -239,7 +268,7 @@ def generate_online_code(application):
|
|
|
239
268
|
prop = environment.GetProperty('LanguageModelMgr', BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
|
|
240
269
|
manager = prop.GetValue(None, None)
|
|
241
270
|
if not manager.GenerateCode(application.guid, True, False):
|
|
242
|
-
raise
|
|
271
|
+
raise download_required('CODESYS cannot generate an online change for this source; use an explicit download')
|
|
243
272
|
|
|
244
273
|
|
|
245
274
|
def consolidated_manager():
|
|
@@ -450,7 +479,8 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
450
479
|
"""`log` is CODESYS's output, where it writes the prompts it answers. `prepared` is a project a
|
|
451
480
|
warm worker opened ahead; an online change of that project uses it. A request to finish later
|
|
452
481
|
replies once the controller runs the application, and hands `keep` the open project and its newly
|
|
453
|
-
generated tree, for `finish_online` to save.
|
|
482
|
+
generated tree, for `finish_online` to save. A review goes the online change's way up to CODESYS's
|
|
483
|
+
verdict, refusing as it would, and then logs out, having transferred nothing."""
|
|
454
484
|
progress = request_progress(request)
|
|
455
485
|
progress('Starting; processor count {0}'.format(Environment.ProcessorCount))
|
|
456
486
|
if request.get('finishLater') and keep is None:
|
|
@@ -460,6 +490,7 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
460
490
|
prepared.close()
|
|
461
491
|
return restore_previous(engine, request, log, progress)
|
|
462
492
|
previous = request.get('baseline')
|
|
493
|
+
changes_online = request['operation'] in ('online-change', 'review')
|
|
463
494
|
project, complete_tree = open_operation_project(engine, request, prepared, progress)
|
|
464
495
|
application = project.active_application
|
|
465
496
|
online_app = None
|
|
@@ -484,6 +515,8 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
484
515
|
online_app = engine.online.create_online_application(application)
|
|
485
516
|
core = core_application(online_app)
|
|
486
517
|
if not previous or str(application.guid) != previous['applicationGuid']:
|
|
518
|
+
if changes_online:
|
|
519
|
+
raise download_required('Online change requires the saved downloaded application; use an explicit download')
|
|
487
520
|
raise RuntimeError('Online change requires the saved downloaded application')
|
|
488
521
|
progress('Checking downloaded controller identity and state')
|
|
489
522
|
session_login(core)
|
|
@@ -496,7 +529,7 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
496
529
|
raise download_required('Downloaded compiler reference differs from the controller; use an explicit download')
|
|
497
530
|
progress('Downloaded compiler reference loaded')
|
|
498
531
|
state = controller_state(core)
|
|
499
|
-
if
|
|
532
|
+
if changes_online and state != 'run':
|
|
500
533
|
raise RuntimeError('Online change requires a running application')
|
|
501
534
|
if request['operation'] == 'inspect':
|
|
502
535
|
return {'applicationGuid': str(application.guid), 'controllerIds': observed,
|
|
@@ -528,7 +561,7 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
528
561
|
# whether a source edit can be applied as an online change.
|
|
529
562
|
progress('Building application incrementally for online change')
|
|
530
563
|
application.build()
|
|
531
|
-
|
|
564
|
+
fail_on_online_change_errors(engine)
|
|
532
565
|
if request['operation'] == 'download':
|
|
533
566
|
online_app = engine.online.create_online_application(application)
|
|
534
567
|
core = core_application(online_app)
|
|
@@ -549,12 +582,18 @@ def run_online(engine, request, log, prepared=None, keep=None):
|
|
|
549
582
|
if controller_ids(core) != previous['controllerIds']:
|
|
550
583
|
raise RuntimeError('Controller application changed before the online change')
|
|
551
584
|
expected = controller_ids(core)
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
585
|
+
changed = not application.is_uptodate
|
|
586
|
+
if changed and not application.is_online_change_possible:
|
|
587
|
+
raise download_required(CANNOT_APPLY + '. CODESYS gave no reason; the usual causes are a '
|
|
588
|
+
'changed task configuration, a variable whose type changed, or a changed device.')
|
|
589
|
+
if request['operation'] == 'review':
|
|
590
|
+
progress('CODESYS can apply this as an online change; the review transferred nothing')
|
|
591
|
+
core.Logout()
|
|
592
|
+
return {}
|
|
593
|
+
if changed:
|
|
555
594
|
progress('Generating online-change code')
|
|
556
595
|
generate_online_code(application)
|
|
557
|
-
|
|
596
|
+
fail_on_online_code_errors(engine)
|
|
558
597
|
expected = context_ids(consolidated_manager().GetCompileContext(application.guid))
|
|
559
598
|
mode = loaded_type('_3S.CoDeSys.Core.Online.BootProjectTransferMode')
|
|
560
599
|
enter_phase(request, u'transfer')
|
package/python/worker.py
CHANGED
|
@@ -147,6 +147,7 @@ def serve(engine, directory):
|
|
|
147
147
|
response["diagnostics"] = error.diagnostics
|
|
148
148
|
if getattr(error, "download_required", False):
|
|
149
149
|
response["downloadRequired"] = True
|
|
150
|
+
response["messages"] = getattr(error, "messages", [])
|
|
150
151
|
write_json(engine, os.path.join(directory, command["id"] + ".json"), response)
|
|
151
152
|
if command["action"] == "stop":
|
|
152
153
|
return
|
package/src/controller-online.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
imageIdSchema,
|
|
19
19
|
type LoginCommand,
|
|
20
20
|
loginResultSchema,
|
|
21
|
-
|
|
21
|
+
reviewReplySchema,
|
|
22
22
|
rollbackSchema,
|
|
23
23
|
sameBaseline,
|
|
24
24
|
TransferFailedError,
|
|
@@ -39,6 +39,10 @@ import {
|
|
|
39
39
|
writeOperationRequest,
|
|
40
40
|
} from "./docker-run";
|
|
41
41
|
import { builderImage } from "./images";
|
|
42
|
+
import {
|
|
43
|
+
type OnlineChangeFinding,
|
|
44
|
+
onlineChangeFindingSchema,
|
|
45
|
+
} from "./online-change-check";
|
|
42
46
|
|
|
43
47
|
/** Where an operation reads the controller user's environment variables from; this process's environment by default. */
|
|
44
48
|
export interface CredentialSource {
|
|
@@ -109,6 +113,7 @@ const checkReceipt = (
|
|
|
109
113
|
if (
|
|
110
114
|
result.operationId !== expected.operationId ||
|
|
111
115
|
result.operation !== expected.operation ||
|
|
116
|
+
result.imageId !== expected.imageId ||
|
|
112
117
|
!sameBaseline(result, expected)
|
|
113
118
|
) {
|
|
114
119
|
throw new Error(
|
|
@@ -204,6 +209,8 @@ const loginReplySchema = z.discriminatedUnion("ok", [
|
|
|
204
209
|
ok: z.literal(false),
|
|
205
210
|
error: z.string(),
|
|
206
211
|
downloadRequired: z.literal(true).optional(),
|
|
212
|
+
findings: z.array(onlineChangeFindingSchema).optional(),
|
|
213
|
+
messages: z.array(z.string()).optional(),
|
|
207
214
|
rollback: rollbackSchema.optional(),
|
|
208
215
|
}),
|
|
209
216
|
]);
|
|
@@ -275,7 +282,10 @@ const callContainer = async (
|
|
|
275
282
|
}
|
|
276
283
|
// Builder images from before `downloadRequired` existed only end such a refusal with these words.
|
|
277
284
|
throw reply.downloadRequired || reply.error.endsWith(explicitDownload)
|
|
278
|
-
? new DownloadRequiredError(reply.error
|
|
285
|
+
? new DownloadRequiredError(reply.error, {
|
|
286
|
+
findings: reply.findings,
|
|
287
|
+
messages: reply.messages,
|
|
288
|
+
})
|
|
279
289
|
: new Error(reply.error);
|
|
280
290
|
}
|
|
281
291
|
return reply.result;
|
|
@@ -539,23 +549,26 @@ export const startWarmController = async (
|
|
|
539
549
|
);
|
|
540
550
|
};
|
|
541
551
|
|
|
552
|
+
/** What a warm operation takes beside its config: the controller user and where its progress goes. */
|
|
553
|
+
interface WarmOptions {
|
|
554
|
+
credentials?: ControllerCredentials;
|
|
555
|
+
/** Receives each step CODESYS reports while the operation runs. */
|
|
556
|
+
onProgress?: (message: string) => void;
|
|
557
|
+
}
|
|
558
|
+
|
|
542
559
|
/**
|
|
543
|
-
*
|
|
560
|
+
* Runs `operation` in warm builder container `name`, which keeps CODESYS running between
|
|
544
561
|
* operations so each skips starting the container, Wine and CODESYS. The first operation, or one
|
|
545
|
-
* with a new image, tsPLC installation, target or Docker settings, starts it. Credentials go to
|
|
546
|
-
* operation only.
|
|
562
|
+
* with a new image, tsPLC installation, target or Docker settings, starts it. Credentials go to
|
|
563
|
+
* CODESYS for this operation only. Returns the container's result, unchecked, and what it was run
|
|
564
|
+
* against; a refusal only a download resolves throws a `DownloadRequiredError` with its reasons.
|
|
547
565
|
*/
|
|
548
|
-
|
|
566
|
+
const warmOperation = async (
|
|
549
567
|
config: ResolvedConfig,
|
|
550
568
|
name: string,
|
|
551
|
-
operation:
|
|
552
|
-
options: {
|
|
553
|
-
|
|
554
|
-
credentials?: ControllerCredentials;
|
|
555
|
-
/** Receives each step CODESYS reports while this operation runs. */
|
|
556
|
-
onProgress?: (message: string) => void;
|
|
557
|
-
} = {},
|
|
558
|
-
): Promise<ControllerResult> => {
|
|
569
|
+
operation: z.input<typeof warmOperationSchema>["operation"],
|
|
570
|
+
options: WarmOptions & { initializeUser: boolean },
|
|
571
|
+
) => {
|
|
559
572
|
const report = options.onProgress ?? (() => {});
|
|
560
573
|
const connection = await controllerConnection(config);
|
|
561
574
|
const operationId = randomUUID();
|
|
@@ -585,7 +598,7 @@ export const updateWarmController = async (
|
|
|
585
598
|
operation,
|
|
586
599
|
operationId,
|
|
587
600
|
request,
|
|
588
|
-
initializeUser: options.initializeUser
|
|
601
|
+
initializeUser: options.initializeUser,
|
|
589
602
|
credentials: options.credentials,
|
|
590
603
|
} satisfies z.input<typeof warmOperationSchema>).catch((error: unknown) => {
|
|
591
604
|
const message = `${failureReason(error)}. Inspect ${diagnostics} for diagnostics`;
|
|
@@ -593,23 +606,100 @@ export const updateWarmController = async (
|
|
|
593
606
|
if (rollback) {
|
|
594
607
|
throw new TransferFailedError(message, rollback, { cause: error });
|
|
595
608
|
}
|
|
596
|
-
throw
|
|
597
|
-
? new DownloadRequiredError(message, {
|
|
609
|
+
throw error instanceof DownloadRequiredError
|
|
610
|
+
? new DownloadRequiredError(message, {
|
|
611
|
+
cause: error,
|
|
612
|
+
findings: error.findings,
|
|
613
|
+
messages: error.messages,
|
|
614
|
+
})
|
|
598
615
|
: new Error(message, { cause: error });
|
|
599
616
|
});
|
|
600
|
-
return
|
|
601
|
-
controllerResultSchema.parse(result),
|
|
602
|
-
{
|
|
603
|
-
operationId,
|
|
604
|
-
operation,
|
|
605
|
-
imageId: connection.imageId,
|
|
606
|
-
templateHash: connection.templateHash,
|
|
607
|
-
target: connection.target,
|
|
608
|
-
},
|
|
609
|
-
diagnostics,
|
|
610
|
-
);
|
|
617
|
+
return { result, connection, operationId, diagnostics };
|
|
611
618
|
} finally {
|
|
612
619
|
await stopFollowing();
|
|
613
620
|
await rm(directory, { recursive: true, force: true });
|
|
614
621
|
}
|
|
615
622
|
};
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* What an online change to `config`'s sources would do, found without applying it: tsPLC's check
|
|
626
|
+
* of the sources against the committed download, then CODESYS's own verdict from an incremental
|
|
627
|
+
* build against the controller's downloaded reference. The controller and its baseline are left
|
|
628
|
+
* as they were.
|
|
629
|
+
*/
|
|
630
|
+
export interface OnlineChangeReview {
|
|
631
|
+
/** Whether CODESYS can apply the sources as an online change. */
|
|
632
|
+
possible: boolean;
|
|
633
|
+
/** tsPLC's findings: what it refuses, and what the change restarts. */
|
|
634
|
+
findings: OnlineChangeFinding[];
|
|
635
|
+
/**
|
|
636
|
+
* Why it can't, beside the findings: CODESYS's reasons in its own words when it gave them, else
|
|
637
|
+
* the refusal itself, such as a committed download this change can't follow. Empty when it can,
|
|
638
|
+
* or when the findings say why.
|
|
639
|
+
*/
|
|
640
|
+
messages: string[];
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Reviews an online change in warm builder container `name`: everything `updateWarmController`
|
|
645
|
+
* does up to CODESYS's verdict, which logs in to the controller and out again. Nothing is
|
|
646
|
+
* transferred to the controller and no download baseline is committed.
|
|
647
|
+
*/
|
|
648
|
+
export const reviewWarmController = async (
|
|
649
|
+
config: ResolvedConfig,
|
|
650
|
+
name: string,
|
|
651
|
+
options: WarmOptions,
|
|
652
|
+
): Promise<OnlineChangeReview> => {
|
|
653
|
+
try {
|
|
654
|
+
const { result } = await warmOperation(config, name, "review", {
|
|
655
|
+
...options,
|
|
656
|
+
initializeUser: false,
|
|
657
|
+
});
|
|
658
|
+
return {
|
|
659
|
+
possible: true,
|
|
660
|
+
findings: reviewReplySchema.parse(result).findings,
|
|
661
|
+
messages: [],
|
|
662
|
+
};
|
|
663
|
+
} catch (error) {
|
|
664
|
+
if (!(error instanceof DownloadRequiredError)) {
|
|
665
|
+
throw error;
|
|
666
|
+
}
|
|
667
|
+
const explained =
|
|
668
|
+
error.messages.length > 0 ||
|
|
669
|
+
error.findings.some((finding) => finding.refuses);
|
|
670
|
+
return {
|
|
671
|
+
possible: false,
|
|
672
|
+
findings: error.findings,
|
|
673
|
+
messages: explained ? error.messages : [failureReason(error.cause)],
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* A download or online change in warm builder container `name` (see `warmOperation`). A download
|
|
680
|
+
* that fails mid-transfer throws a `TransferFailedError` naming its rollback.
|
|
681
|
+
*/
|
|
682
|
+
export const updateWarmController = async (
|
|
683
|
+
config: ResolvedConfig,
|
|
684
|
+
name: string,
|
|
685
|
+
operation: "download" | "online-change",
|
|
686
|
+
options: WarmOptions & { initializeUser?: boolean } = {},
|
|
687
|
+
): Promise<ControllerResult> => {
|
|
688
|
+
const { result, connection, operationId, diagnostics } = await warmOperation(
|
|
689
|
+
config,
|
|
690
|
+
name,
|
|
691
|
+
operation,
|
|
692
|
+
{ ...options, initializeUser: options.initializeUser ?? false },
|
|
693
|
+
);
|
|
694
|
+
return checkReceipt(
|
|
695
|
+
controllerResultSchema.parse(result),
|
|
696
|
+
{
|
|
697
|
+
operationId,
|
|
698
|
+
operation,
|
|
699
|
+
imageId: connection.imageId,
|
|
700
|
+
templateHash: connection.templateHash,
|
|
701
|
+
target: connection.target,
|
|
702
|
+
},
|
|
703
|
+
diagnostics,
|
|
704
|
+
);
|
|
705
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// What the host and the builder container exchange for controller operations: the receipt,
|
|
2
|
-
// the target a baseline is bound to, warm and login commands, and how failures
|
|
2
|
+
// the target a baseline is bound to, warm and login commands, a review's reply, and how failures
|
|
3
|
+
// are worded.
|
|
3
4
|
import {
|
|
4
5
|
controllerSchema,
|
|
5
6
|
type ResolvedConfig,
|
|
@@ -8,6 +9,10 @@ import {
|
|
|
8
9
|
} from "@tsplc/config/build";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
import { deviceTreeStructure } from "./device-tree";
|
|
12
|
+
import {
|
|
13
|
+
type OnlineChangeFinding,
|
|
14
|
+
onlineChangeFindingSchema,
|
|
15
|
+
} from "./online-change-check";
|
|
11
16
|
|
|
12
17
|
export const imageIdSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
13
18
|
const endpointSchema = z.strictObject({
|
|
@@ -19,6 +24,8 @@ export const controllerResultSchema = z.strictObject({
|
|
|
19
24
|
operationId: z.uuid(),
|
|
20
25
|
operation: z.enum(["download", "online-change", "inspect"]),
|
|
21
26
|
imageId: imageIdSchema,
|
|
27
|
+
/** The builder image's CODESYS engineering, when the image records it. */
|
|
28
|
+
engineering: sha256Digest.optional(),
|
|
22
29
|
templateHash: sha256Digest,
|
|
23
30
|
target: z.strictObject({
|
|
24
31
|
network: z.string().nonempty(),
|
|
@@ -44,9 +51,12 @@ export const controllerCredentialsSchema = z.strictObject({
|
|
|
44
51
|
});
|
|
45
52
|
export type ControllerCredentials = z.infer<typeof controllerCredentialsSchema>;
|
|
46
53
|
|
|
47
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* One operation for the warm builder container; `request` is the container path of its config. A
|
|
56
|
+
* `review` goes an online change's way up to CODESYS's verdict and changes nothing.
|
|
57
|
+
*/
|
|
48
58
|
export const warmOperationSchema = z.strictObject({
|
|
49
|
-
operation: z.enum(["download", "online-change"]),
|
|
59
|
+
operation: z.enum(["download", "online-change", "review"]),
|
|
50
60
|
operationId: z.uuid(),
|
|
51
61
|
request: z.string().nonempty(),
|
|
52
62
|
initializeUser: z.boolean(),
|
|
@@ -94,26 +104,58 @@ export const controllerTarget = (
|
|
|
94
104
|
|
|
95
105
|
export type Baseline = Pick<
|
|
96
106
|
ControllerResult,
|
|
97
|
-
"imageId" | "templateHash" | "target"
|
|
107
|
+
"imageId" | "engineering" | "templateHash" | "target"
|
|
98
108
|
>;
|
|
99
109
|
|
|
100
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Whether two controller states were made by builders that compile alike: images with the same
|
|
112
|
+
* CODESYS engineering, or the same image when either doesn't record its engineering.
|
|
113
|
+
*/
|
|
114
|
+
const sameBuilder = (state: Baseline, expected: Baseline) =>
|
|
115
|
+
state.engineering && expected.engineering
|
|
116
|
+
? state.engineering === expected.engineering
|
|
117
|
+
: state.imageId === expected.imageId;
|
|
118
|
+
|
|
119
|
+
/** Whether two controller states share a builder, template and target, so one can follow the other. */
|
|
101
120
|
export const sameBaseline = (state: Baseline, expected: Baseline) =>
|
|
102
|
-
state
|
|
121
|
+
sameBuilder(state, expected) &&
|
|
103
122
|
state.templateHash === expected.templateHash &&
|
|
104
123
|
JSON.stringify(state.target) === JSON.stringify(expected.target);
|
|
105
124
|
|
|
106
125
|
/** Ends the message of every refusal that only a full download resolves. */
|
|
107
126
|
export const explicitDownload = "use an explicit download";
|
|
108
127
|
|
|
128
|
+
/** Why only a full download will do: tsPLC's findings and CODESYS's reasons, in its own words. */
|
|
129
|
+
export interface DownloadReasons {
|
|
130
|
+
findings: OnlineChangeFinding[];
|
|
131
|
+
messages: string[];
|
|
132
|
+
}
|
|
133
|
+
|
|
109
134
|
/**
|
|
110
135
|
* A refusal that only a full download resolves, so callers can offer one instead of failing.
|
|
111
|
-
* Worker and container replies carry it as `downloadRequired: true
|
|
136
|
+
* Worker and container replies carry it as `downloadRequired: true`, with the reasons they have.
|
|
112
137
|
*/
|
|
113
138
|
export class DownloadRequiredError extends Error {
|
|
114
139
|
readonly downloadRequired = true;
|
|
140
|
+
/** tsPLC's findings about the change, refusals and restarts, when its check ran. */
|
|
141
|
+
readonly findings: OnlineChangeFinding[];
|
|
142
|
+
/** CODESYS's reasons, when it gave them. */
|
|
143
|
+
readonly messages: string[];
|
|
144
|
+
constructor(
|
|
145
|
+
message: string,
|
|
146
|
+
options: ErrorOptions & Partial<DownloadReasons> = {},
|
|
147
|
+
) {
|
|
148
|
+
super(message, options);
|
|
149
|
+
this.findings = options.findings ?? [];
|
|
150
|
+
this.messages = options.messages ?? [];
|
|
151
|
+
}
|
|
115
152
|
}
|
|
116
153
|
|
|
154
|
+
/** What a warm container replies once a review finds CODESYS can apply the change. */
|
|
155
|
+
export const reviewReplySchema = z.strictObject({
|
|
156
|
+
findings: z.array(onlineChangeFindingSchema),
|
|
157
|
+
});
|
|
158
|
+
|
|
117
159
|
/**
|
|
118
160
|
* What became of the controller after a download failed mid-transfer: it still ran the previous
|
|
119
161
|
* application (`intact`), runs it again from the last committed download (`restored`), or may hold
|