M8-S1 — Your engine workbench from source
Section titled “M8-S1 — Your engine workbench from source”| Module | M8 — Extend the engine from source (source strand) |
| After this session you can | Run the platform from source, make and test a change in one service, and say when an engine change is justified instead of a documented extension point. |
| Time | 88 min with a facilitator · about 88 min on your own |
| Before you start | The strand’s prerequisite (below) met and its self-check passed. A source checkout of the platform’s three code bases that you may build and run, with the development tools installed (source-strand prework). Modules 2, 3 and 6, in particular M6-S4 (the extension map). |
| Go deeper | Run the platform from source · Running locally · How to extend the platform |
◆ Orientation (1 min) — The same need, the other way
Section titled “◆ Orientation (1 min) — The same need, the other way”Larkspur needs condition monitoring. The extension strand meets that need through documented extension points: a parameterised Function, an inbound feed and a webhook (M7-S1). You are on the source strand: you meet it inside the engine, by giving the platform a new kind of value, a Meter reading field type, that every builder can add to any entity, on the web and on the phone, with no code. Over four sessions you add the type to the engine (M8-S2), give it a web control the designer offers (M8-S3), render it on mobile or declare its fallback, and prove that a builder can use it without code (M8-S4).
First you need a workbench: the platform running from source on your machine, and the discipline to change engine code safely. That is this session. You also learn the judgement that matters more than any code: when an engine change is the right answer at all.
▤ Concept (10 min) — Three code bases, one convention, and when to change the engine
Section titled “▤ Concept (10 min) — Three code bases, one convention, and when to change the engine”The strand’s prerequisite, stated
Section titled “The strand’s prerequisite, stated”The source strand assumes more than the rest of ACM. Before this session you should:
- read and write TypeScript for Node.js services, including classes, decorators and dependency injection;
- read and write Angular components, including a form control that implements
ControlValueAccessor; - read and write Dart with Flutter, including exhaustive
switchstatements over enums; - have a source checkout of the platform that you are allowed to build and run, and the tools its
local-development guide lists installed and working: Node.js and
pnpmat the versions the workspace declares, Docker, the Flutter SDK withmelos, and a code editor.
The self-check. You took it when you chose your strand: the three questions on the
course page and the fuller check in M0-S1
(dependency injection, writeValue, Dart’s exhaustive switches). If any of the three ideas was new to
you, change to the extension strand now: M7 meets the same need and leads to the same certification.
The first practice segment below repeats the check in the context of this session.
Three code bases, joined by contracts
Section titled “Three code bases, joined by contracts”The platform you have studied from the outside is built from three code bases that are built, tested and released separately:
flowchart LR
subgraph BE["Services workspace (TypeScript, Node.js)"]
SH["Shared package<br/>enums, message classes"]
DS["Data service<br/>casters, validators"]
OT["Other services"]
end
subgraph WEB["Web front end (Angular)"]
WT["Shared types<br/>mirrored enums"]
PL["Plugins<br/>field controls"]
end
subgraph MOB["Mobile app (Flutter, Dart)"]
MD["Domain package<br/>mirrored enums"]
MW["Field widgets"]
end
SH -. "same numbers" .-> WT
SH -. "same numbers" .-> MD
DS -- "HTTP API: stored values" --> PL
DS -- "HTTP API: stored values" --> MW
What to notice: there is no shared code between the three, only shared contracts: the HTTP API’s value shapes, and enum values re-declared with the same numbers on each side. A change to one of those contracts is a change in all three code bases, released together.
- The services workspace holds the back-end services and their shared packages. It is one workspace driven by a task runner, so shared packages build before the services that use them; the root scripts build everything, start a minimal set of services or all of them, and run each service’s tests. Tests are per service; there is no single command that tests all three code bases.
- The web front end is one workspace holding the designer and the portal. Its field controls are plugins resolved by name at run time: the plugin system you met in M3-S5.
- The mobile app is a multi-package Flutter workspace managed with
melos. Its domain package is pure Dart and re-declares the platform’s enums so it can read the API’s values without importing anything from the other code bases.
You met the most important of these shared contracts in M2-S3: an enum value that is stored in records is a wire contract and is never renumbered.
The artifact-booter convention, in source
Section titled “The artifact-booter convention, in source”M2-S1 named the convention that makes much of the engine pluggable; now you work with it. A service does not keep a central list of its casters, validators, fetchers, exporters or message handlers. Instead, at start-up, a set of booters each scan one folder of the compiled service for files with one suffix, read a static field on each class they find, and register the class in the application’s dependency-injection container under a key made of a prefix and that field.
| To add | You create | The class declares | It is registered under |
|---|---|---|---|
| A field-type caster | a file ending .caster.ts in the data service’s casters folder | static castType (the field type’s enum value) | caster.<value> |
| An entity validator | a file ending .validator.ts in its validators folder | the entity name and phases | validator.… |
| A message handler | a file ending .handler.ts in a service’s handlers folder | the message it handles | its class name |
What to notice: adding most engine parts means creating one file with the right suffix and the right static field. There is no registry to edit, and a missing file fails quietly, which is why tests matter.
Two consequences shape how you work. First, the booters scan the compiled output, so a new file does nothing until the service is rebuilt. Second, a lookup for a type with nothing registered returns nothing rather than failing: for casters, the engine then stores the submitted value unchanged. A forgotten caster is not an error you will see; it is a value that silently skips its normalisation.
The bring-up
Section titled “The bring-up”Running the platform from source is the same topology you operated in ACDE, rearranged for one machine: the datastores and the message bus run as containers, the services run as native processes from the workspace, the web front end runs from its development server, and the gateway runs as a container in front of them. Four facts save hours:
- Configuration is generated, not copied. Installing the workspace creates your local configuration files from their examples and never overwrites them. Where the guide asks you to edit a tracked file to make a single-machine setup behave, that edit is local-only: it never goes into a commit.
- Order matters. The datastores first; then the services, with their bus queues bound; only then the first-time setup. The setup provisions the first tenant over the bus, and a message published before anyone is listening is dropped, which shows up later as endless space or domain errors.
- The host name is load-bearing. The platform finds the tenant and space from the address you use, exactly as in ACDE. Use the address the local configuration names, consistently, in the browser and in your API calls.
- Read the failure as progress. On the way up you typically see “connection refused”, then a space error, then a domain error, then a real answer. Each is a different layer answering, and each means the layer before it now works.
The first administrator is the one you name in the local migration configuration before the first run. The setup gives that account a one-time password-reset link instead of a password; on a workstation there is no mail server, so you read the link from your local identity database, as the lab shows. A practice environment also needs a valid license that includes administration; your platform team supplies the license values with the checkout, as an operator supplies them in ACDE M2-S1.
When an engine change is justified
Section titled “When an engine change is justified”The engine has documented recipes for its own extension: a new field type, a new view type, a new reaction action, a new bus message with its handler, a new service, a new migration, and a family of rules for keeping new code tenant-aware (carry the space on every message, never build a cache key by hand, never default to the root space). M8 uses the first and the tenant rules; you will recognise the others when you review someone’s engine change.
Knowing the recipes is the easy part. The judgement is whether to use one. An engine change is justified only when all four of these hold:
| Test | The question | Condition Monitoring as a field type |
|---|---|---|
| No documented point will do | Can configuration, a Function, the API, events or a webhook meet the need? (M6-S4) | Partly: M7 meets the alarm need without engine code. A value kind with its unit, checked on save and offered in the designer, is not something a Function can add. |
| It is general | Would every tenant benefit, not just one customer? | Yes: any maintenance, utility or laboratory solution records meter readings. |
| It will be carried | Will the platform’s engineering own it in every future release, or will you maintain a fork? | It must be accepted upstream; otherwise every platform upgrade becomes a merge. |
| You can change all three code bases | Can the team change, test and release the services, the web front end and the mobile app together? | Yes, on this strand; the mobile half may be a declared fallback. |
What to notice: the first test is the extension map from M6-S4, applied honestly; the other three are about ownership. A change that passes the first test but fails “it will be carried” is a fork, and a fork costs more at every upgrade than it saved at the start.
If any test fails, take the documented point, even if the engine change would be quicker today. That is why both strands exist: they are not two ways to do the same job, but two answers to two different situations.
▶ Guided demo (20 min) — The bring-up, step by step
Section titled “▶ Guided demo (20 min) — The bring-up, step by step”Starting state. Your checkout builds; Docker is running; nothing of the platform is started. Follow along in your own terminal, with a facilitator or alone: the lab starts from the platform this demo brings up. Check the expected result after each step before you go on.
-
Install the services workspace from its root. The install runs the local-configuration script.
Terminal window pnpm installExpected: for each local configuration file it creates, the install prints one
[setup:local] created …line; for files that already exist it prints nothing. -
Start the datastores and the bus as containers.
Terminal window docker compose up -d database rabbitmq redisExpected: three containers running (
docker compose ps). -
Build and start the minimal set of services, in their own terminal, and leave it running.
Terminal window pnpm build && pnpm start:mainExpected: each service logs that it is listening; the data service and the identity service report their bus connection.
-
Check that the bus queues have consumers before anything is provisioned.
Terminal window docker compose exec rabbitmq rabbitmqctl list_queues name consumers | grep -E "data-service-queue|users-service-queue"Expected: both queues listed with
1consumer. If either shows0, the first-time setup would be lost; wait for the service and check again. -
Run the first-time setup once the queues are bound.
Terminal window pnpm migrateExpected: the migration ends without errors, and the gateway answers a real response instead of a space error.
-
Start the web front end from its own workspace, in a third terminal.
Terminal window pnpm startExpected: the development server compiles and prints the local address of the portal.
Screenshot pending Three terminals side by side: the datastore containers running, the services' start-up logs, and the web development server's compiled message What to notice: the services and the web front end each own a terminal and keep running; the containers run in the background. Closing a terminal stops what it started.
✓ Practice (4 min) — Ready for the strand?
Section titled “✓ Practice (4 min) — Ready for the strand?”You add a new caster file to the data service’s casters folder and restart the service without
rebuilding. A record saved afterwards stores the raw value unchanged. Why?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
On a fresh machine, you run the first-time setup before starting the services. Everything seems to succeed, but the portal keeps answering with a space error. What happened?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
In Dart 3, the mobile app’s domain package gains a new value in an enum that several switch
statements cover, none with a default. What does that give you when you add a field type?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
⛏ Lab (47 min) — Bring it up, change it, catch it, revert it
Section titled “⛏ Lab (47 min) — Bring it up, change it, catch it, revert it”Goal. Your source workbench running with the Larkspur suite in it, and one complete change cycle in the data service: a test that states today’s behaviour, a change the test catches, and a clean revert.
Before you start. Your checkout on a clean working tree (git status shows nothing to commit) in
all three code bases. The Larkspur pack from the workbench. Work in
the services workspace unless a step says otherwise.
Bring it up
-
Name your own first administrator: in the data service’s local migration configuration (the
.env.migrationfile the install created), set the administrator’s email to your own address atexample.comand choose a user name. Save. This file is local and ignored by version control. -
Confirm the platform you brought up in the demo is still running: the portal’s sign-in page opens at the local address the web server printed. If you skipped the demo, do its six steps now.
-
Read your one-time password-reset link from the local identity database:
Terminal window docker compose exec database mongosh --quiet --eval \'const t=db.getSiblingDB("identity-users").resettokens.findOne(); print("/identity/reset-password/"+t.resetToken)'Open the printed path on your local platform address, set a password, and sign in. Expected: the portal’s welcome page.
-
Load the Larkspur suite into your workbench with the seed from the Larkspur pack, pointed at your local address:
Terminal window export BASE=<your local platform address>node larkspur-pack/seed/seed.mjs --base-url "$BASE"Expected: the seed reports the four modules and the people created. Open Administration › Applications › Modules and check that Asset Maintenance is there.
Run one service’s tests
-
Find where the data service keeps its unit tests and its casters:
Terminal window find services/data-service/src -path '*__tests__*' -name '*.ts' | headls services/data-service/src/castersExpected: a tests folder with unit and integration tests, and one caster file per field type that has one (number, text, date and others).
-
Run the data service’s tests once, to see a green baseline:
Terminal window pnpm --filter data-service test:unitExpected: the run ends with passing tests and no failures. Note how long it took. This is the unit suite: it needs the built service and no database. The plain
testscript also runs the integration tests, which start a MongoDB container and need Docker.
Make a change that a test catches
-
Write a unit test beside the others that states the Number caster’s current behaviour for garbage input: it returns
NaN. Name it for what it documents.import {expect} from '@loopback/testlab';import {NumberCaster} from '../../../casters/number.caster';describe('NumberCaster (documents current behaviour)', () => {it('turns unparseable input into NaN', () => {expect(Number.isNaN(new NumberCaster().cast('twelve'))).to.be.true();});}); -
Rebuild and run the tests. Expected: your new test passes, with the others.
-
Now change the behaviour: in the Number caster, return
nullwhen the result is not a finite number. -
Rebuild and run the tests again. Expected: your test fails, naming the case: the change was caught.
-
Read what you have learned: the caster’s silent
NaNis real behaviour that stored records may already contain, so changing it is a behaviour change for every tenant, not a fix. Write one sentence in your notes on what a change like this would need (a decision, a migration of stored values, release notes).
Revert cleanly
-
Restore the caster to its committed state:
Terminal window git restore services/data-service/src/casters/number.caster.ts -
Decide what to do with your test: keep it in a local branch as documentation, or delete it. Do not leave it untracked in the working tree.
-
Rebuild and run the tests a last time. Expected: green, as in step 6.
-
Confirm the working tree is clean, or contains only your deliberate local branch:
Terminal window git status -
Write two lines in your notes for M8-S2: the field type you will add must not repeat the Number caster’s silent failure, and the decision is visible in a test from the start.
Check.
- The portal opens on your local address and you are signed in as your own administrator.
- Asset Maintenance and the other Larkspur modules are in Modules.
- You ran the data service’s tests and saw them pass.
- Your test of the Number caster passed before your change and failed after it.
- The caster is restored and the tests pass again.
-
git statusshows no stray changes in the services workspace. - Your notes say what changing an existing caster’s behaviour would need.
Pass condition. A from-source platform with the Larkspur suite, and a recorded change cycle: a test passed, the change made it fail, the revert made it pass, and the working tree is clean.
If something goes wrong
| What you see | What to do |
|---|---|
EADDRINUSE for a metrics port when services start | Two services chose the same metrics port. Give each a distinct METRICS_PORT, as the local-development guide’s launcher does. |
| Endless space or domain errors after the setup | The setup ran before the queues had consumers. Restart the services, confirm both queues show 1, and run the setup again (it is safe to re-run). |
| The reset link opens a page that says the link is invalid | Use the same host as the portal, and the newest token: run the step 3 command again after any new setup run. |
The seed answers 401 | You are not signed in to the API: the seed signs in with LK_ADMIN_EMAIL and LK_ADMIN_PASSWORD; export them for your local administrator. |
| Tests fail before you changed anything | Your checkout is not on a released line, or a dependency is missing. Run the build again and record the failing test; do not start M8-S2 on a red baseline. |
git restore leaves the caster changed | You edited the compiled file in dist. Edit and restore the source under src, then rebuild. |
Model answer
What a finished lab looks like. Your terminal history shows the bring-up order: containers, then
services with both queues at 1 consumer, then the setup, then the web server. The seed’s summary
lists Supplier Management, Procurement, Asset Maintenance and Quality and Compliance.
The change cycle in your notes:
- Baseline: data service tests green.
- Test added: “NumberCaster turns unparseable input into NaN” — passes.
- Change: return
nullfor non-finite results — the new test fails, as it should. - Reverted with
git restore; rebuilt; green again; test kept on the local branchdoc/number-caster.
What a real change to an existing caster would need: a recorded decision (records may already hold
NaN), a migration or a read-time rule for the stored values, a note in the release, and agreement from
the platform’s engineering, because the behaviour belongs to every tenant.
For M8-S2: the Meter reading caster returns null for anything it cannot read as a finite value
with a unit, and its first test says so.
✓ Practice (5 min) — Engine change or not?
Section titled “✓ Practice (5 min) — Engine change or not?”Larkspur’s quality team wants supplier audit scores to be recalculated every night from three entities, with a formula they can change themselves. Is an engine change justified?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A partner proposes a new reaction action that sends work orders to one customer’s own maintenance system in its private format. The platform’s engineering team will not take it upstream. What does the four-test rule say?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
During the bring-up you edit a tracked configuration file so the gateway reaches your native services. What do you do with that edit?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Why did the lab ask you to write a test of the Number caster’s current behaviour before changing it?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
↺ Recap (1 min) — What you can now do
Section titled “↺ Recap (1 min) — What you can now do”You can run the platform from source: datastores and bus as containers, services native with their queues bound before the first-time setup, the web front end from its development server, your own first administrator, and the Larkspur suite seeded in. You have changed engine code under a test and reverted it cleanly. And you can apply the four tests that decide whether an engine change is justified at all.
Next. In M8-S2 you add the Meter reading field type to the engine: its value in the shared contract, its caster with tests, and the places downstream that must know it, in a tenant-safe way. You will use the change cycle from this lab for every step.