Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/32733-notify-channel-roster-malformed-member.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@objectstack/runtime': patch
'@objectstack/spec': patch
---

fix(runtime): a channel list with a member off the declared shape is not judged at the automation save doors, so it no longer refuses every channel

Clause-②: no
Metadata-protocol: none

The `/automation` write doors (`POST /api/v1/automation`, `PUT /api/v1/automation/NAME`, `POST /api/v1/automation/NAME/clone`) read the messaging service's `getKnownChannels()` to refuse a `notify` node naming a channel nothing registers. A reader that throws or answers no list was already not judged. A list whose members were not all `{ id: string }` (the declared shape) had those members dropped instead, so a reader answering bare channel ids left an empty roster and every named channel was refused `400 VALIDATION_FAILED`. Such a list is now an unreadable registry like the other two: not judged, and the save goes on as it did before the check existed. No first-party messaging service answers that shape; `MessagingService.getKnownChannels()` answers the declared one, and a flow naming an unknown channel on it is refused exactly as before.

The `notify-channel-unknown-refused` entry `os migrate meta` prints now lists every not-judged case the doors have (a save before `kernel:ready` has settled, and an unreadable channel reader, beside the four it named) and the paths a refusal names (`nodes.N.config.channels`, `nodes.N.config.channels.M` for a list member, a longer path inside a region body). Data text only.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const storeRefusal = () => Object.assign(new Error('flow/x failed spec validatio
* And whether the kernel's `kernel:ready` has settled (`hasBootPhaseSettled`).
*/
interface ChannelComposition {
messaging?: ReadonlyArray<{ id: string; configured: boolean }> | 'no-reader' | 'reader-throws' | 'reader-not-a-list';
messaging?:
| ReadonlyArray<{ id: string; configured: boolean }>
| 'no-reader' | 'reader-throws' | 'reader-not-a-list' | 'reader-bare-ids' | 'reader-one-bare-id';
/** `'throws'`: the kernel's boot-phase reader itself throws, so the check cannot finish. */
ready?: boolean | 'throws';
}
Expand Down Expand Up @@ -101,6 +103,10 @@ function boot({ protocol: mode = 'real', messaging, ready = false }: { protocol?
if (messaging === 'no-reader') services.messaging = { emit: async () => ({}) };
else if (messaging === 'reader-throws') services.messaging = { getKnownChannels: () => { throw new Error('registry unreadable'); } };
else if (messaging === 'reader-not-a-list') services.messaging = { getKnownChannels: () => ({ inbox: true }) };
else if (messaging === 'reader-bare-ids') services.messaging = { getKnownChannels: () => ['inbox', 'email'] };
else if (messaging === 'reader-one-bare-id') {
services.messaging = { getKnownChannels: () => [{ id: 'inbox', configured: true }, 'email'] };
}
else if (messaging) services.messaging = { getKnownChannels: () => messaging.map((entry) => ({ ...entry })) };
const resolve = (name: string): unknown => services[name];
const kernel = {
Expand Down Expand Up @@ -387,6 +393,18 @@ describe('a notify node naming a channel no plugin registers is refused at the s
}
});

it('a list with any member that is not a `{ id: string }` is unreadable, not judged: a channel it names is never refused', async () => {
// The reader knows `email`, spelled off the declared shape: dropping the
// member would leave a roster without it and refuse the node.
for (const messaging of ['reader-bare-ids', 'reader-one-bare-id'] as const) {
const h = boot({ messaging, ready: true });
const { response } = await h.dispatcher.handleAutomation('', 'POST', notifyFlowOf(NEW, 'email'), AUTHOR(), undefined);
expect(statusOf(response), messaging).toBe(200);
expect(h.saveMetaItem, messaging).toHaveBeenCalledTimes(1);
expect(h.held(NEW), messaging).toBeDefined();
}
});

it('a check that cannot finish undoes the registration before the error leaves: nothing registered-but-unsaved', async () => {
const h = boot({ messaging: STOCK_CHANNELS, ready: 'throws' });
const before = h.held(CUSTOMER);
Expand Down
19 changes: 11 additions & 8 deletions packages/runtime/src/domains/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2300,8 +2300,9 @@ function notifyChannelEntries(value: unknown): NotifyChannelEntry[] {
* delivers nothing whatever it names (it records a skipped step), and a
* messaging service with no `getKnownChannels()` (another implementation of
* the service) cannot be enumerated: neither is judged. Nor is a reader
* that throws or answers something other than a list: an unreadable
* registry gives no verdict, and the save goes on as before.
* that throws, answers something other than a list, or answers a list
* with any member that is not a `{ id: string }`: an unreadable registry
* gives no verdict, and the save goes on as before.
*
* Read per request and recorded nowhere: the answer is the registry as it
* stands at this save (AGENTS.md, "Startup registry reads").
Expand Down Expand Up @@ -2330,19 +2331,21 @@ async function refuseUnknownNotifyChannels(
// A reader that throws, or answers anything but a list, is a registry this
// door cannot read: not judged, like a service with no reader at all. The
// save goes on as it did before this check existed, and a delivery on an
// unknown channel still reports itself at run time. Members that are not a
// `{ id: string }` are not channels and are left out of the roster.
// unknown channel still reports itself at run time. So is a list with any
// member that is not a `{ id: string }` (the declared `NotifyChannelRegistry`
// shape): dropping such members would leave a roster that misses channels
// the reader does know, and refuse every name it carries.
let read: unknown;
try {
read = messaging.getKnownChannels();
} catch {
return undefined;
}
if (!Array.isArray(read)) return undefined;
const known = (read as unknown[]).filter(
(entry): entry is { id: string; configured: boolean } =>
!!entry && typeof entry === 'object' && typeof (entry as { id?: unknown }).id === 'string',
);
const isChannel = (entry: unknown): entry is { id: string; configured: boolean } =>
!!entry && typeof entry === 'object' && typeof (entry as { id?: unknown }).id === 'string';
if (!(read as unknown[]).every(isChannel)) return undefined;
const known = read as Array<{ id: string; configured: boolean }>;
const knownIds = known.map((entry) => entry.id);

const lines: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export const entry: SemanticMigration = {
'A channel is code a plugin registers with the messaging service, so a name nothing registers is a typo or a '
+ 'missing plugin. The automation write doors saved such a flow with 200; every delivery on that channel then '
+ 'failed at run time with "channel NAME not registered" and a step warning. The doors now refuse it 400 '
+ 'VALIDATION_FAILED at nodes.N.config.channels, naming the node and the channel with a did-you-mean and listing '
+ 'the registered channels. A channel whose transport is not configured yet (email with no email service) is '
+ 'known and still accepted. Not judged: a deployment with no messaging service, a flow a package ships, a flow '
+ 'stored through the metadata door, and a stored row re-registered at boot. There is no mechanical rewrite: '
+ 'only the author knows which channel was meant.',
+ 'VALIDATION_FAILED, naming the node and the channel at its path (nodes.N.config.channels, '
+ 'nodes.N.config.channels.M for a list member, a longer path inside a region body) with a did-you-mean and '
+ 'listing the registered channels. A channel whose transport is not configured yet (email with no email '
+ 'service) is known and still accepted. Not judged: a deployment with no messaging service, one whose channel '
+ 'reader throws, answers no list or answers a list with a member that is not a channel, a save before '
+ 'kernel:ready has settled, a flow a package ships, a flow stored through the metadata door, and a stored row '
+ 're-registered at boot. There is no mechanical rewrite: only the author knows which channel was meant.',
acceptanceCriteria:
'POST /api/v1/automation with the flow, every notify node naming registered channels, answers 200, and '
+ 'GET /api/v1/automation/NAME serves it.',
Expand Down
Loading