|
10 | 10 | * fingerprint-suppressed across `metadata:reloaded` re-runs, and that a |
11 | 11 | * failing declaration source degrades to a debug line instead of throwing — |
12 | 12 | * a diagnostic must never be the reason a kernel fails to boot. |
| 13 | + * |
| 14 | + * The second describe block pins the router's registry rung. The measured |
| 15 | + * defect: on the in-process boot (`new AppPlugin(...)` then |
| 16 | + * `kernel.bootstrap()`), `meta.loadMany('action')` answers `[]` while |
| 17 | + * `registry.getItem('action', name)` answers the declaration, so every |
| 18 | + * object-LESS `defineAction` was named as a "registered handler with NO |
| 19 | + * declaration ... REFUSED at dispatch" in the same boot in which the router |
| 20 | + * resolved it at rung 2 and dispatched it. Pinned here: the two boots (the |
| 21 | + * registry holds it, the plane does not), both call forms (object-bound and |
| 22 | + * object-less), a positive control that must stay reported, the ownership |
| 23 | + * test that keeps the rung from clearing a foreign declaration, and the |
| 24 | + * second warning holding its exact wording while the first changes. |
13 | 25 | */ |
14 | 26 |
|
15 | 27 | import { describe, it, expect, vi } from 'vitest'; |
@@ -120,3 +132,169 @@ describe('runActionGovernanceInventory (ADR-0110 D5)', () => { |
120 | 132 | ); |
121 | 133 | }); |
122 | 134 | }); |
| 135 | + |
| 136 | +describe('runActionGovernanceInventory — the router registry rung (#14123)', () => { |
| 137 | + /** `registry.getItem('action', name)`, as the plugin injects it. */ |
| 138 | + const registryOf = (items: Record<string, any>) => (name: string) => items[name]; |
| 139 | + |
| 140 | + const applyAction = { name: 'duly_catalog_apply', type: 'script', locations: [] }; |
| 141 | + |
| 142 | + it('clears an object-LESS declaration the registry holds and the plane does not', async () => { |
| 143 | + const logger = makeLogger(); |
| 144 | + await runActionGovernanceInventory({ |
| 145 | + registered: [{ objectName: 'global', actionName: 'duly_catalog_apply' }], |
| 146 | + objects: [], // no object embeds it |
| 147 | + loadStandaloneActions: async () => [], // in-process boot: the plane is empty |
| 148 | + lookupRegistryAction: registryOf({ duly_catalog_apply: applyAction }), |
| 149 | + logger, |
| 150 | + }); |
| 151 | + |
| 152 | + expect(logger.warn).not.toHaveBeenCalled(); |
| 153 | + }); |
| 154 | + |
| 155 | + it('clears an object-BOUND declaration the registry holds and the plane does not', async () => { |
| 156 | + const logger = makeLogger(); |
| 157 | + await runActionGovernanceInventory({ |
| 158 | + registered: [{ objectName: 'todo_task', actionName: 'archive_task' }], |
| 159 | + objects: [{ name: 'todo_task', actions: [] }], |
| 160 | + loadStandaloneActions: async () => [], |
| 161 | + lookupRegistryAction: registryOf({ |
| 162 | + archive_task: { name: 'archive_task', objectName: 'todo_task', type: 'script' }, |
| 163 | + }), |
| 164 | + logger, |
| 165 | + }); |
| 166 | + |
| 167 | + expect(logger.warn).not.toHaveBeenCalled(); |
| 168 | + }); |
| 169 | + |
| 170 | + it('POSITIVE CONTROL — a handler no source declares is still named', async () => { |
| 171 | + const logger = makeLogger(); |
| 172 | + await runActionGovernanceInventory({ |
| 173 | + registered: [ |
| 174 | + { objectName: 'global', actionName: 'duly_catalog_apply' }, |
| 175 | + { objectName: 'global', actionName: 'ghostProbe' }, |
| 176 | + { objectName: 'todo_task', actionName: 'ghostBound' }, |
| 177 | + ], |
| 178 | + objects: [{ name: 'todo_task', actions: [] }], |
| 179 | + loadStandaloneActions: async () => [], |
| 180 | + lookupRegistryAction: registryOf({ duly_catalog_apply: applyAction }), |
| 181 | + logger, |
| 182 | + }); |
| 183 | + |
| 184 | + expect(logger.warn).toHaveBeenCalledTimes(1); |
| 185 | + expect(logger.warn).toHaveBeenCalledWith( |
| 186 | + expect.stringMatching(/registered handlers with NO declaration/), |
| 187 | + expect.objectContaining({ count: 2, handlers: ['global:ghostProbe', 'todo_task:ghostBound'] }), |
| 188 | + ); |
| 189 | + }); |
| 190 | + |
| 191 | + it('applies the router ownership test — a foreign object-bound item does not cover the route', async () => { |
| 192 | + const logger = makeLogger(); |
| 193 | + await runActionGovernanceInventory({ |
| 194 | + registered: [{ objectName: 'todo_task', actionName: 'archive_task' }], |
| 195 | + objects: [{ name: 'todo_task', actions: [] }], |
| 196 | + lookupRegistryAction: registryOf({ |
| 197 | + archive_task: { name: 'archive_task', objectName: 'crm_lead', type: 'script' }, |
| 198 | + }), |
| 199 | + logger, |
| 200 | + }); |
| 201 | + |
| 202 | + expect(logger.warn).toHaveBeenCalledWith( |
| 203 | + expect.stringMatching(/registered handlers with NO declaration/), |
| 204 | + expect.objectContaining({ handlers: ['todo_task:archive_task'] }), |
| 205 | + ); |
| 206 | + }); |
| 207 | + |
| 208 | + it('stops asserting a dispatch outcome it did not check, and names the sources it did read', async () => { |
| 209 | + const logger = makeLogger(); |
| 210 | + await runActionGovernanceInventory({ |
| 211 | + registered: [{ objectName: 'global', actionName: 'ghostProbe' }], |
| 212 | + objects: [], |
| 213 | + logger, |
| 214 | + }); |
| 215 | + |
| 216 | + const [message] = logger.warn.mock.calls[0]; |
| 217 | + expect(message).not.toMatch(/REFUSED at dispatch/); |
| 218 | + expect(message).not.toMatch(/there is no opt-out/); |
| 219 | + expect(message).not.toMatch(/drop the registration/); |
| 220 | + expect(message).toMatch(/it did not dispatch/); |
| 221 | + expect(message).toMatch(/object-embedded `actions\[\]`/); |
| 222 | + expect(message).toMatch(/the engine registry standalone `action` items/); |
| 223 | + expect(message).toMatch(/the metadata service `action` rows/); |
| 224 | + }); |
| 225 | + |
| 226 | + it('leaves the OTHER warning byte-identical — a registry item is not folded into the declaration set', async () => { |
| 227 | + const logger = makeLogger(); |
| 228 | + await runActionGovernanceInventory({ |
| 229 | + registered: [], |
| 230 | + objects: todoObjects, |
| 231 | + lookupRegistryAction: registryOf({ |
| 232 | + // A registry-only script declaration with no handler anywhere. It must |
| 233 | + // not join `unboundDeclarations`: the router never enumerates the |
| 234 | + // registry, so neither does this audit. |
| 235 | + orphan_action: { name: 'orphan_action', type: 'script', target: 'orphanHandler' }, |
| 236 | + }), |
| 237 | + logger, |
| 238 | + }); |
| 239 | + |
| 240 | + expect(logger.warn).toHaveBeenCalledTimes(1); |
| 241 | + expect(logger.warn).toHaveBeenCalledWith( |
| 242 | + '[action-governance] declared script actions with NO handler — a button wired to ' |
| 243 | + + 'nothing (ADR-0078); add a `body`, or register a handler under the declared `target`', |
| 244 | + { count: 1, actions: ['todo_task:complete_task'] }, |
| 245 | + ); |
| 246 | + }); |
| 247 | + |
| 248 | + it('keeps the handler when the registry lookup throws — and never throws itself', async () => { |
| 249 | + const logger = makeLogger(); |
| 250 | + await expect(runActionGovernanceInventory({ |
| 251 | + registered: [{ objectName: 'global', actionName: 'duly_catalog_apply' }], |
| 252 | + objects: [], |
| 253 | + lookupRegistryAction: () => { throw new Error('registry unreadable'); }, |
| 254 | + logger, |
| 255 | + })).resolves.toBeDefined(); |
| 256 | + |
| 257 | + expect(logger.warn).toHaveBeenCalledWith( |
| 258 | + expect.stringMatching(/registered handlers with NO declaration/), |
| 259 | + expect.objectContaining({ handlers: ['global:duly_catalog_apply'] }), |
| 260 | + ); |
| 261 | + }); |
| 262 | + |
| 263 | + it('fingerprints the FILTERED set, so a rung-cleared boot reports and remembers nothing', async () => { |
| 264 | + const logger = makeLogger(); |
| 265 | + const fp = await runActionGovernanceInventory({ |
| 266 | + registered: [{ objectName: 'global', actionName: 'duly_catalog_apply' }], |
| 267 | + objects: [], |
| 268 | + lookupRegistryAction: registryOf({ duly_catalog_apply: applyAction }), |
| 269 | + logger, |
| 270 | + }); |
| 271 | + |
| 272 | + expect(fp).toBe(''); |
| 273 | + expect(logger.warn).not.toHaveBeenCalled(); |
| 274 | + |
| 275 | + // The declaration disappears on a later reload: the finding is new, so it reports. |
| 276 | + await runActionGovernanceInventory({ |
| 277 | + registered: [{ objectName: 'global', actionName: 'duly_catalog_apply' }], |
| 278 | + objects: [], |
| 279 | + lookupRegistryAction: registryOf({}), |
| 280 | + logger, |
| 281 | + lastFingerprint: fp, |
| 282 | + }); |
| 283 | + |
| 284 | + expect(logger.warn).toHaveBeenCalledTimes(1); |
| 285 | + }); |
| 286 | + |
| 287 | + it('is unchanged when no rung is injected — two sources, and the finding stands', async () => { |
| 288 | + const logger = makeLogger(); |
| 289 | + await runActionGovernanceInventory({ |
| 290 | + registered: [{ objectName: 'global', actionName: 'duly_catalog_apply' }], |
| 291 | + objects: [], |
| 292 | + logger, |
| 293 | + }); |
| 294 | + |
| 295 | + expect(logger.warn).toHaveBeenCalledWith( |
| 296 | + expect.stringMatching(/registered handlers with NO declaration/), |
| 297 | + expect.objectContaining({ handlers: ['global:duly_catalog_apply'] }), |
| 298 | + ); |
| 299 | + }); |
| 300 | +}); |
0 commit comments