Repository navigation
Expand file tree
/
Copy pathfederated-injected-column-readers.test.ts
More file actions
772 lines (744 loc) · 38 KB
/
Copy pathfederated-injected-column-readers.test.ts
File metadata and controls
772 lines (744 loc) · 38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* [#21918] The closing pin of the federated injected-anchor family: every
* engine reader of an injected column, each with its disposition toward a
* federated object, and a failure the day a reader appears without one.
*
* ## The family
*
* The registry injects the platform's columns into every object, ADR-0015
* `external` ones included (the #7865 ruling, direction B), and the platform
* provisions no storage for a federated object. Each engine reader that read
* one of those columns as real storage failed on a federated object, one at a
* time: the read path (#7738), the cascade scan on the tenant anchor (#21910),
* then the cascade scan on every other anchor (#21918). Each fix found the
* next face only when a door refused. This file turns the remaining faces
* into a table, so the next one is a review question instead of an outage.
*
* ## The mechanism: a source scan over named seams
*
* An engine reader reaches an injected column of an arbitrary registered
* object through a small, closed set of seams, and this file scans every
* non-test source of `@objectstack/objectql` for each use of one:
*
* 1. the federated decisions and the provenance they read:
* `isFederatedObject`, `isFederatedUnprovisionedInjectedColumn`,
* `resolveInjectedColumnProvenance`, `unprovisionedInjectedColumns`,
* `platformProvisionsStorage`;
* 2. the relation-carrier arbiters, which are how engine code finds a relation
* field, and so how it reaches an injected lookup: `referenceCarrierOf`,
* `referenceTargetOf`;
* 3. the tenant-column resolver, `resolveTenantFieldName`, and the constant
* it resolves to, `DEFAULT_TENANT_FIELD`;
* 4. every spelling of an injected column's NAME: a string literal, an object
* literal key, or a `SystemFieldName` member. The names are not listed
* here. They are `injectedSystemColumnDefs` (`@objectstack/spec/data`)
* answered for a federated document, the same table the registry spreads.
*
* Each use is keyed `<file>#<enclosing function> :: <seam>`, which survives line
* churn and moves only when the code that reads moves. Every key the scan finds
* must have a row in {@link READERS}, and every row must still be found. A row
* whose disposition says the site ASKS a federated predicate is checked against
* the source: the site's own function calls it, or calls the one same-file
* helper the row names, which calls it.
*
* Why a scan and not a registry the readers call into: a registry only lists
* the readers that remembered to register, which is the population that was
* never the problem. The failures in this family were readers that did not
* know the question existed. A scan finds them by the seam they cannot avoid.
*
* What it cannot see, stated rather than implied: a reader that reaches an
* injected column through none of these seams, such as a column name built
* from a template or read out of a field map without a carrier arbiter. Such a
* reader is also one no other check in this package can find, and it adds no
* hole this file pretends to close.
*
* ## The dispositions
*
* Closed, in {@link Disposition}. Only the first three say what the site does
* on a federated object by asking a predicate, and they are the ones checked
* against the source. The rest say why the seam is not a storage read of a
* federated object's injected column at all, and their `why` is the claim a
* reviewer checks.
*/
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'node:fs';
import { dirname, join, relative, sep } from 'node:path';
import ts from 'typescript';
import { injectedSystemColumnDefs, ObjectSchema } from '@objectstack/spec/data';
import { SystemFieldName } from '@objectstack/spec/system';
type Disposition =
/** Asks `isFederatedUnprovisionedInjectedColumn` and does not read the column on a federated object. */
| 'skips'
/** Asks `isFederatedObject` and issues no injected-column predicate against a federated object. */
| 'exempt'
/** Asks the provenance (`unprovisionedInjectedColumns`) and leaves unprovisioned columns out. */
| 'excludes'
/** A column VALUE read off a row in hand selects the TARGET object's rows by id. */
| 'target-by-id'
/** Reads the column's value off a row already in hand. No storage read. */
| 'row-value'
/** Lowers, validates or evaluates a predicate the caller or the author wrote. */
| 'caller-predicate'
/** Reads a relation an author's own declaration names (and infers from it). */
| 'author-declared'
/** The column is the declared lifecycle policy's own subject, not a partition of it. */
| 'policy-subject'
/** Stamps the column onto a record the caller writes. */
| 'writer'
/** Names the column without reading any row: a vocabulary, an injection, a sync route, refusal text. */
| 'not-a-read'
/** The predicate or resolver itself. */
| 'definition';
/** The dispositions whose claim is a call in the source, and the calls that satisfy it. */
const ASKS: Partial<Record<Disposition, readonly string[]>> = {
skips: ['isFederatedUnprovisionedInjectedColumn'],
exempt: ['isFederatedObject'],
excludes: ['unprovisionedInjectedColumns', 'resolveInjectedColumnProvenance'],
};
interface Row {
disposition: Disposition;
why: string;
/** For an ASKS disposition: the same-file function the site calls, which asks (across {@link ENGINE_SPLIT_FILES} for the engine). */
via?: string;
}
/**
* engine.ts and the modules `scripts/codemod-split-engine.mjs` (#29986) split
* out of it. A method there may keep its signature in engine.ts and its body in
* one of these, so a {@link Row.via} helper is looked up across the set.
*/
const ENGINE_SPLIT_FILES: ReadonlySet<string> = new Set([
'engine.ts',
'engine-actions.ts',
'engine-cascade-planning.ts',
'engine-compatibility-section.ts',
'engine-defaults-and-autonumbers.ts',
'engine-delete-and-aggregate.ts',
'engine-find.ts',
'engine-hooks-and-functions.ts',
'engine-insert.ts',
'engine-middleware-and-context.ts',
'engine-migration-state.ts',
'engine-references-and-master-detail.ts',
'engine-registration.ts',
'engine-secrets-and-routing.ts',
'engine-security-resolvers.ts',
'engine-summaries-and-expansion.ts',
'engine-top-level.ts',
'engine-transactions-section.ts',
]);
/** The calls that are seams by name. */
const SEAM_CALLS = new Set([
'isFederatedObject',
'isFederatedUnprovisionedInjectedColumn',
'resolveInjectedColumnProvenance',
'unprovisionedInjectedColumns',
'platformProvisionsStorage',
'referenceCarrierOf',
'referenceTargetOf',
'resolveTenantFieldName',
]);
const VOCABULARY = 'names the column in a name vocabulary; it reads no row';
const SYNC_ROUTE = 'routes a federated object to the DDL-free binding; it reads no row';
const PLATFORM_ROW = 'stamps a row of a platform table the engine itself writes';
const VALIDATION_RULE = "a validation rule's own relation path, which the author wrote";
const VALIDATION_FORMULA = "a validation rule's or a formula field's own relation path, which the author wrote";
const READERS: Record<string, Row> = {
// ── The readers this family fixed, and the one decision they ask ─────────
'engine-cascade-planning.ts#cascadeRelationBehavior :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: 'the dependents probe never filters a federated object on a column it does not provision (both phases of the cascade read relations here)',
},
'engine-cascade-planning.ts#planCascadeAtomicity :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: "the participant test is the scan's own, so the plan and the scan agree",
},
// [#29253] Both readers above find a relation's target through this one
// helper; each asks the skip itself, after the reference match (the two
// `isFederatedUnprovisionedInjectedColumn()` rows above).
'engine-top-level.ts#deleteWalkTargetOf :: referenceCarrierOf()': {
disposition: 'not-a-read',
why: 'answers the object a delete-walk relation names, from the field declaration; its callers cascadeRelationBehavior and planCascadeAtomicity skip after the reference match; it reads no row',
},
'engine-top-level.ts#deleteWalkTargetOf :: referenceTargetOf()': {
disposition: 'not-a-read',
why: "answers sys_user, the target a user field's type fixes, for the same two callers; it reads no row",
},
// [#24948] The organization-delete refusal reads the tenant column of every
// relation the cascade follows into `sys_organization`.
'engine-cascade-planning.ts#organizationOwnedRowCounts :: resolveTenantFieldName()': {
disposition: 'skips',
via: 'cascadeRelationBehavior',
why: "counts a tenant column only once the cascade's own relation reading admits it, so a federated object's unprovisioned injected column is never counted",
},
'engine-cascade-planning.ts#keepsOrganizationReference :: organization_id': {
disposition: 'not-a-read',
why: "names the attribution column a tenancy-disabled object keeps through an organization delete; the walk reads its relation through cascadeRelationBehavior; it reads no row",
},
'engine-cascade-planning.ts#keepsOrganizationReference :: resolveTenantFieldName()': {
disposition: 'not-a-read',
why: 'asks whether the object has a tenant column at all, on a relation the walk already read; it reads no row',
},
'engine-cascade-planning.ts#isTenantColumnSetNull :: resolveTenantFieldName()': {
disposition: 'not-a-read',
why: "compares a field name with the object's tenant column, on a relation its callers already read through cascadeRelationBehavior; it reads no row",
},
'engine-top-level.ts#<module> :: organization_id': {
disposition: 'not-a-read',
why: "names the field a write-wall verdict (WriteWallRowVerdict, #25062) refuses, in the verdict's type; the plugin that owns the wall decides it, and the engine reads no row",
},
'lifecycle/lifecycle-service.ts#tenantWindowsFor :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: 'a federated object whose organization_id is the injection has no tenant partition',
},
'lifecycle/lifecycle-service.ts#tenantWindowsFor :: organization_id': {
disposition: 'skips',
why:
'the column the partition predicates name, asked about before any partition is built; the reap and ' +
'archive passes name only the column this decision returns (#15207), so they hold no seam of their own',
},
'lifecycle/lifecycle-service.ts#tenantWindowsFor :: resolveInjectedColumnProvenance()': {
disposition: 'skips',
why:
"an object with no organization_id at all (provenance 'absent': no injection, no declaration), " +
'federated or local, has no tenant partition either',
},
// ── Readers that already asked whether the object is federated ──────────
'engine-driver-options.ts#buildDriverOptions :: isFederatedObject()': {
disposition: 'exempt',
why: 'the organization wall a read carries is withheld from a federated object',
},
'engine-driver-options.ts#buildDriverOptions :: resolveTenantFieldName()': {
disposition: 'exempt',
why: 'resolves the wall column only after the federated exemption',
},
// [#24197] The one-hop loader moved out of `resolvePredicateRelated` so
// validation predicates and formula fields share it; a formula's hop is read
// as the caller outright, so its federated answer is the caller's own read.
'engine-master-detail-related.ts#resolveOneHopRelated :: isFederatedObject()': {
disposition: 'exempt',
why: "a federated related object is read through the caller's own read, never through a wall",
},
'engine-master-detail-related.ts#resolveOneHopRelated :: referenceTargetOf()': {
disposition: 'exempt',
why: 'reads the related object by id; a federated one is routed through the caller',
},
'engine-master-detail-related.ts#resolveOneHopRelated :: resolveTenantFieldName()': {
disposition: 'exempt',
why: 'decides the routing beside the federated test, on the related object, never as a filter',
},
// [#24410] The formula read names each reference's target to judge, per
// formula, the related fields that target does not declare.
'engine-security-resolvers.ts#resolveFormulaRelated :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: "judges a formula's own hop against the target's declared field map; no row is read here",
},
// [#24468] The predicate read names each reference's target to judge, per
// validation rule, the related fields that target does not declare.
'engine-master-detail-related.ts#resolvePredicateRelated :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: "judges a validation rule's own hop against the target's declared field map; no row is read here",
},
'engine-middleware-and-context.ts#resolveSystemInsertOrganization :: isFederatedObject()': {
disposition: 'exempt',
why: 'a system insert into a federated object is never stamped with an organization',
},
'engine-middleware-and-context.ts#resolveSystemInsertOrganization :: resolveTenantFieldName()': {
disposition: 'exempt',
why: 'resolves the stamp column only after the federated exemption',
},
// ── Readers that read the provenance directly ───────────────────────────
'integrity/dangling-reference-audit.ts#auditableReferenceFields :: referenceTargetOf()': {
disposition: 'excludes',
why: 'the audit never counts an unprovisioned injected lookup as a reference',
},
'integrity/dangling-reference-audit.ts#auditableReferenceFields :: unprovisionedInjectedColumns()': {
disposition: 'excludes',
why: 'the provenance the exclusion reads',
},
'integrity/dangling-reference-audit.ts#organizationFieldOf :: resolveTenantFieldName()': {
disposition: 'excludes',
why: 'the audit partitions by organization only on a provisioned tenant column',
},
'integrity/dangling-reference-audit.ts#organizationFieldOf :: unprovisionedInjectedColumns()': {
disposition: 'excludes',
why: 'the provenance the exclusion reads',
},
'declared-read-columns.ts#selectedStoredColumns :: unprovisionedInjectedColumns()': {
disposition: 'excludes',
why: 'a read never answers an unprovisioned injected column as null: no storage stands behind it',
},
'declared-read-columns.ts#selectedStoredColumns :: isFederatedObject()': {
disposition: 'excludes',
why: 'a read never answers a platform timestamp a federated object does not declare as null: the platform builds no table for it',
},
// ── Seams that are not a storage read of a federated object's column ─────
'engine-referential-integrity.ts#assertReferencesResolve :: referenceTargetOf()': {
disposition: 'target-by-id',
why: "the id a caller wrote into a reference field is looked up on the TARGET object",
},
'engine-summaries-and-expansion.ts#expandRelatedRecords :: referenceTargetOf()': {
disposition: 'target-by-id',
why: 'the ids read off the rows in hand load the TARGET rows; a federated row carries none',
},
'credential-evaluation-guard.ts#judge :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: "names the object an expand entry the caller wrote is judged against, by its declared fields; it reads no row",
},
'internal-field-evaluation-guard.ts#judgeExpand :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: "names the object an expand entry the caller wrote is judged against, by its declared fields; it reads no row",
},
'record-title.ts#resolveRelatedTitleTarget :: referenceTargetOf()': {
disposition: 'target-by-id',
why: "resolves which object a related record's title is read from",
},
'engine-realtime-publish.ts#eventOrganizationId :: resolveTenantFieldName()': {
disposition: 'row-value',
why: 'reads the tenant column off the written row; a federated row has none, so the event omits it',
},
// [#30237] A recycle-bin entry belongs to the organization of the record it holds.
'recycle-bin/capture.ts#organizationOf :: resolveTenantFieldName()': {
disposition: 'row-value',
why: "reads the tenant column off the snapshotted root row; a federated row has none, so the entry takes the deleting context's organization",
},
'relation-filter-lowering.ts#admitRelationCondition :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: "lowers a relation condition the caller wrote; it names an injected column only when the caller did",
},
'validation/rule-validator.ts#addReferenceTraversals :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_FORMULA,
},
'validation/rule-validator.ts#referenceTraversalConflicts :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_FORMULA,
},
'validation/rule-validator.ts#readsAnOwnColumnItLacks :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_RULE,
},
'validation/rule-validator.ts#referentialClearRefusal :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_RULE,
},
'validation/rule-validator.ts#resolveTraversalScope :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_RULE,
},
'validation/rule-validator.ts#referenceReadThrough :: referenceTargetOf()': {
disposition: 'caller-predicate',
why: VALIDATION_RULE,
},
'engine-summaries-and-expansion.ts#buildSummaryIndex :: referenceCarrierOf()': {
disposition: 'author-declared',
why:
"infers the foreign key of a roll-up an author declared, from the child's first relation to the " +
'parent. Injected anchors point only at sys_organization, sys_business_unit and sys_user, so it can ' +
'meet one only for a roll-up declared on one of those over a federated child with no relationshipField',
},
'lifecycle/lifecycle-service.ts#reapObject :: created_at': {
disposition: 'policy-subject',
why:
'the age a declared retention reaps by. On a federated object the registry injects it, so a remote ' +
"without it refuses the filter and the sweep reports the object in its errors, loudly, every sweep",
},
'lifecycle/lifecycle-service.ts#archiveObject :: created_at': {
disposition: 'policy-subject',
why: "the age a declared archive selects by (when no ttl names another column), and the cold store's keep prune",
},
'plugin.ts#registerAuditHooks :: created_by': {
disposition: 'writer',
why: 'stamps the acting user onto a record the caller writes; it reads nothing',
},
'plugin.ts#registerAuditHooks :: updated_by': {
disposition: 'writer',
why: 'stamps the acting user onto a record the caller writes; it reads nothing',
},
'engine-compatibility-api.ts#syncObjectSchema :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
'engine-compatibility-api.ts#syncSchemas :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
'engine-secret-internal-fields.ts#encryptSecretFields :: created_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
'home-amount-recompute.ts#recomputeHomeAmounts :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: 'the recompute never selects an injected column a federated object does not provision',
},
'home-amount-recompute.ts#recomputeHomeAmounts :: organization_id': {
disposition: 'skips',
why: 'the recompute reads the organization a write converts a row under, and leaves the column out of its read on a federated object',
},
'home-amount-recompute.ts#recomputeHomeAmounts :: updated_at': {
disposition: 'skips',
why: 'the recompute reads the stamp its apply keeps, and leaves the column out of its read (and its write) on a federated object',
},
'record-currency-backfill.ts#resolveScope :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: 'the code backfill never selects an injected column a federated object does not provision',
},
'record-currency-backfill.ts#resolveScope :: organization_id': {
disposition: 'skips',
why: 'the code backfill reads the organization it counts and scopes a row by, and leaves the column out of its read on a federated object',
},
'stored-expression-backfill.ts#backfillStoredExpressions :: isFederatedUnprovisionedInjectedColumn()': {
disposition: 'skips',
why: 'the backfill never sends an injected column a federated object does not provision',
},
'stored-expression-backfill.ts#backfillStoredExpressions :: updated_at': {
disposition: 'skips',
why: 'the backfill keeps the stamp of the row it writes, and sends none on a federated object',
},
'engine-migration-state.ts#recordObservedDeviation :: updated_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
'engine-migration-state.ts#retractCreationAttestation :: updated_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
'plugin.ts#reconcileFederatedBindings :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
'plugin.ts#registerSchemasWithoutDdl :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
'plugin.ts#syncRegisteredSchemas :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
'declared-read-columns.ts#<module> :: created_at': { disposition: 'not-a-read', why: VOCABULARY },
'declared-read-columns.ts#<module> :: updated_at': { disposition: 'not-a-read', why: VOCABULARY },
'having-filter.ts#declaredReferenceNames :: created_at': { disposition: 'not-a-read', why: VOCABULARY },
'having-filter.ts#declaredReferenceNames :: updated_at': { disposition: 'not-a-read', why: VOCABULARY },
'no-operator-object-door.ts#<module> :: created_at': { disposition: 'not-a-read', why: VOCABULARY },
'no-operator-object-door.ts#<module> :: updated_at': { disposition: 'not-a-read', why: VOCABULARY },
'util.ts#convertIntrospectedSchemaToObjects :: created_at': {
disposition: 'not-a-read',
why: "drafts objects from a datasource's introspected tables, skipping the platform's own columns",
},
'util.ts#convertIntrospectedSchemaToObjects :: updated_at': {
disposition: 'not-a-read',
why: "drafts objects from a datasource's introspected tables, skipping the platform's own columns",
},
'no-operator-object-door.ts#relationWords :: referenceTargetOf()': {
disposition: 'not-a-read',
why: 'names the related object in refusal text',
},
'registry.ts#<module> :: organization_id': {
disposition: 'not-a-read',
why: 'the tenant index the registry declares on a provisioned tenant column',
},
'registry.ts#<module> :: owning_business_unit_id': {
disposition: 'not-a-read',
why: 'the name the injection writes the ADR-0117 D1 anchor under',
},
'registry.ts#<module> :: queue': {
disposition: 'not-a-read',
why: 'the name the injection writes the ADR-0142 D3 ownership-queue column under',
},
'assignment-rules.ts#<module> :: owner_id': { disposition: 'not-a-read', why: VOCABULARY },
'assignment-rules.ts#<module> :: queue': { disposition: 'not-a-read', why: VOCABULARY },
'assignment-rules.ts#carriesQueueColumn :: resolveInjectedColumnProvenance()': {
disposition: 'excludes',
why: 'an object whose queue column is unprovisioned (federated) evaluates no assignment rule',
},
'assignment-rules.ts#leastLoaded :: organization_id': {
disposition: 'excludes',
via: 'carriesQueueColumn',
why: "counts a member's load only on an object whose platform columns have storage behind them",
},
'assignment-rules.ts#roundRobin :: organization_id': {
disposition: 'not-a-read',
why: 'keys the sys_assignment_cursor row, a platform table the engine itself reads and writes',
},
'assignment-rules.ts#authoredRules :: organization_id': {
disposition: 'not-a-read',
why: "keys an organization's sys_assignment_rule rows, a platform table plugin-sharing owns",
},
'assignment-rules.ts#organizationMemberStanding :: organization_id': {
disposition: 'not-a-read',
why: 'keys the sys_member row a user target is a member by, a platform table',
},
'assignment-rules.ts#route :: queue': {
disposition: 'not-a-read',
why: 'names the queue in a log entry; the row written is the one in hand',
},
'assignment-rules.ts#ruleOf :: queue': {
disposition: 'not-a-read',
why: "compares an assignment target's kind, not the column; it reads no row",
},
'plugin.ts#assertOwnershipQueueServicePresent :: queue': {
disposition: 'not-a-read',
why: 'names the metadata type the boot refusal lists; it reads no row',
},
'registry.ts#declaresTenantIndex :: organization_id': {
disposition: 'not-a-read',
why: 'reads an index declaration, not a row',
},
'registry.ts#applyDeploymentTenancy :: organization_id': {
disposition: 'not-a-read',
why:
"drops the platform's own injected definition from a declared object's schema (ADR-0131 D7); " +
'it reads a definition, never a row',
},
'registry.ts#setDeploymentPlatformGlobalObjects :: organization_id': {
disposition: 'not-a-read',
why:
'tells an authored organization_id from the injection while re-planning registered schemas ' +
'(ADR-0131 D7); it reads definitions, never a row',
},
// [#24822] Whether a write's static-`readonly` passes spare the tenant column
// where the Layer 0 wall's seam declares it judges the write's organization,
// and the insert's and the update's subjects built from that one answer.
'engine-top-level.ts#staticReadonlySparesOrganization :: resolveInjectedColumnProvenance()': {
disposition: 'not-a-read',
why:
"asks whether the write's organization_id is the platform's injected column or the author's; " +
'it reads a registered definition, never storage',
},
'engine-top-level.ts#staticReadonlySparesOrganization :: organization_id': {
disposition: 'not-a-read',
why:
"asks whether the insert strip's subject holds the column; it reads a schema view, never storage",
},
'engine-top-level.ts#insertStaticReadonlySubject :: organization_id': {
disposition: 'not-a-read',
why:
"leaves the column out of an insert's static-readonly subject where the wall's seam judges it; " +
'it reads a schema view and the caller row in hand, never storage',
},
'engine-top-level.ts#updateStaticReadonlySubject :: organization_id': {
disposition: 'not-a-read',
why:
"leaves the column out of an update's static-readonly schema view where the wall's seam judges it; " +
'it reads a registered definition and the payload in hand, never storage',
},
'tenancy/system-write-organization.ts#<module> :: organization_id': {
disposition: 'not-a-read',
why: 'the declaration of the default tenant column name',
},
'tenancy/system-write-organization.ts#buildRefusalMessage :: organization_id': {
disposition: 'not-a-read',
why: 'names the column in refusal text',
},
'tenancy/system-write-organization.ts#resolveTenantFieldName :: organization_id': {
disposition: 'definition',
why: 'the tenant-column resolver every tenant reader above asks; it reads a schema, never a row',
},
'federated-object.ts#isFederatedUnprovisionedInjectedColumn :: isFederatedObject()': {
disposition: 'definition',
why: 'the general predicate',
},
'federated-object.ts#isFederatedUnprovisionedInjectedColumn :: resolveInjectedColumnProvenance()': {
disposition: 'definition',
why: 'the general predicate reads the registry provenance and names no column',
},
};
// ── The scan ─────────────────────────────────────────────────────────────
interface Scan {
/** Every seam use, keyed `<file>#<site> :: <seam>`. */
seams: Set<string>;
/** Every callee name each `<file>#<site>` calls. */
calls: Map<string, Set<string>>;
files: string[];
columns: ReadonlySet<string>;
}
/**
* The injected column names, read from the spec's own definition table for a
* federated document: the same table `applySystemFields` spreads, so a column
* the registry starts injecting tomorrow is scanned for tomorrow.
*/
function injectedColumnNames(): ReadonlySet<string> {
return new Set(Object.keys(injectedSystemColumnDefs({ name: 'probe', external: { remoteName: 'probe' }, fields: {} })));
}
/**
* The name a node gives the code inside it when it is a function-like
* container, or `undefined` when it is not. A node's site is the name of its
* NEAREST such ancestor, or `<module>` for top-level code. The walk below
* hands that name down as it descends, so each node's site costs nothing.
* The first version asked for every node by climbing to the root: O(nodes x
* depth) over 2.8 MB of source, about 1.5 s a scan and three scans a run.
* Under the CPU contention a Test Core shard runs at (four suites of three
* workers on four cores), two of those scans measured past vitest's 5 s
* default timeout.
*/
function containerName(p: ts.Node, sf: ts.SourceFile): string | undefined {
if (
(ts.isMethodDeclaration(p) || ts.isFunctionDeclaration(p) || ts.isGetAccessorDeclaration(p) || ts.isSetAccessorDeclaration(p)) &&
p.name
) {
return p.name.getText(sf);
}
if (ts.isConstructorDeclaration(p)) return 'constructor';
const fnInit = (init: ts.Expression | undefined) => !!init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init));
if (ts.isPropertyDeclaration(p) && fnInit(p.initializer)) return p.name.getText(sf);
if (
ts.isVariableDeclaration(p) &&
fnInit(p.initializer) &&
ts.isVariableDeclarationList(p.parent) &&
ts.isVariableStatement(p.parent.parent) &&
ts.isSourceFile(p.parent.parent.parent)
) {
return p.name.getText(sf);
}
return undefined;
}
function calleeName(call: ts.CallExpression): string | undefined {
const c = call.expression;
if (ts.isIdentifier(c)) return c.text;
if (ts.isPropertyAccessExpression(c)) return c.name.text;
return undefined;
}
/** The one scan this file makes: every test reads the same answer. */
let scanned: Scan | undefined;
/**
* Parsing the package source is the one costly step in this file, so a test
* that may be the first to call this declares {@link SCAN_BUDGET_MS} rather
* than borrowing vitest's 5 s default, which is a budget for a unit, not for a
* parse of the whole package on a shared runner.
*/
const SCAN_BUDGET_MS = 30_000;
function scanObjectqlSources(): Scan {
if (scanned) return scanned;
// Located from THIS test file's own path, as `engine-middleware-operation-vocabulary.test.ts`
// does: the package's build config targets CommonJS, where `import.meta` is TS1470.
const testPath = expect.getState().testPath;
if (!testPath) throw new Error('vitest reported no testPath, so the reader scan cannot locate src/.');
const srcDir = dirname(testPath);
const columns = injectedColumnNames();
const fieldNameOf = SystemFieldName as unknown as Record<string, string>;
const files: string[] = [];
const walk = (dir: string): void => {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) walk(path);
else if (path.endsWith('.ts') && !path.endsWith('.test.ts') && !path.endsWith('.d.ts')) files.push(path);
}
};
walk(srcDir);
const seams = new Set<string>();
const calls = new Map<string, Set<string>>();
for (const file of files) {
const rel = relative(srcDir, file).split(sep).join('/');
const sf = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true);
const visit = (n: ts.Node, siteName: string): void => {
const site = `${rel}#${siteName}`;
if (ts.isCallExpression(n)) {
const name = calleeName(n);
if (name) {
if (!calls.has(site)) calls.set(site, new Set());
calls.get(site)!.add(name);
if (SEAM_CALLS.has(name)) seams.add(`${site} :: ${name}()`);
}
}
if (
(ts.isStringLiteral(n) || ts.isNoSubstitutionTemplateLiteral(n)) &&
columns.has(n.text) &&
!ts.isImportDeclaration(n.parent) &&
!ts.isExportDeclaration(n.parent)
) {
seams.add(`${site} :: ${n.text}`);
}
if (ts.isIdentifier(n) && columns.has(n.text) && ts.isPropertyAssignment(n.parent) && n.parent.name === n) {
seams.add(`${site} :: ${n.text}`);
}
if (
ts.isPropertyAccessExpression(n) &&
ts.isIdentifier(n.expression) &&
n.expression.text === 'SystemFieldName' &&
columns.has(fieldNameOf[n.name.text])
) {
seams.add(`${site} :: ${fieldNameOf[n.name.text]}`);
}
if (
ts.isIdentifier(n) &&
n.text === 'DEFAULT_TENANT_FIELD' &&
!ts.isImportSpecifier(n.parent) &&
!ts.isExportSpecifier(n.parent) &&
!(ts.isVariableDeclaration(n.parent) && n.parent.name === n)
) {
seams.add(`${site} :: organization_id`);
}
const inner = containerName(n, sf) ?? siteName;
ts.forEachChild(n, (child) => visit(child, inner));
};
visit(sf, '<module>');
}
scanned = { seams, calls, files: files.map((f) => relative(srcDir, f).split(sep).join('/')), columns };
return scanned;
}
const siteKeyOf = (seamKey: string): string => seamKey.slice(0, seamKey.indexOf(' :: '));
describe('[#21918] every engine reader of an injected column has a disposition toward a federated object', () => {
it('scans the population it claims: the whole package source, for the injected columns the spec declares', () => {
const scan = scanObjectqlSources();
expect(scan.files).toEqual(
expect.arrayContaining(['engine.ts', 'federated-object.ts', 'lifecycle/lifecycle-service.ts', 'registry.ts']),
);
expect(scan.files.some((f) => f.endsWith('.test.ts'))).toBe(false);
// The column names come from the spec, so a vacuous answer would be empty or tenant-only.
expect([...scan.columns]).toEqual(
expect.arrayContaining(['organization_id', 'owning_business_unit_id', 'owner_id', 'created_by', 'updated_by']),
);
}, SCAN_BUDGET_MS);
it('has a row for every seam use in the source, and no row for a use that is gone', () => {
const scan = scanObjectqlSources();
const unlisted = [...scan.seams].filter((k) => !(k in READERS)).sort();
const stale = Object.keys(READERS).filter((k) => !scan.seams.has(k)).sort();
expect(
unlisted,
'An engine reader of an injected column has no disposition. Decide what it does on a federated object ' +
'(ADR-0015 `external`), whose injected columns the platform does not provision: ask ' +
'`isFederatedUnprovisionedInjectedColumn` and skip, or record why the seam reads no such column. Then add ' +
'its row to READERS in this file.',
).toEqual([]);
expect(stale, 'A READERS row names a seam use the source no longer has: delete or re-key the row.').toEqual([]);
}, SCAN_BUDGET_MS);
it('a disposition that says the site asks a federated predicate is true of the source', () => {
const scan = scanObjectqlSources();
for (const [key, row] of Object.entries(READERS)) {
const asks = ASKS[row.disposition];
if (!asks) {
expect(row.via, `${key}: only an asking disposition names a via`).toBeUndefined();
continue;
}
const site = siteKeyOf(key);
const own = scan.calls.get(site) ?? new Set<string>();
if (row.via) {
const file = site.slice(0, site.indexOf('#'));
// [#29986] engine.ts and the modules its codemod split wrote are one
// class: a host method's body may live in a sibling `engine-*.ts`
// module while engine.ts keeps a stub that calls it, so a via named
// from one of them resolves across all of them (ruling 6597555122 A).
const helperFiles = ENGINE_SPLIT_FILES.has(file) ? [...ENGINE_SPLIT_FILES] : [file];
const helper = new Set<string>(
helperFiles.flatMap((f) => [...(scan.calls.get(`${f}#${row.via}`) ?? [])]),
);
expect(own.has(row.via), `${key}: the site does not call ${row.via}`).toBe(true);
expect(asks.some((p) => helper.has(p)), `${key}: ${row.via} asks none of ${asks.join(', ')}`).toBe(true);
} else {
expect(asks.some((p) => own.has(p)), `${key}: the site asks none of ${asks.join(', ')}`).toBe(true);
}
}
}, SCAN_BUDGET_MS);
it('the sites that skip are exactly the cascade scan, its plan, the organization-delete count, the lifecycle tenant partition, the home-amount recompute, the record-currency backfill and the stored-expression backfill', () => {
const skipping = new Set(
Object.entries(READERS)
.filter(([, row]) => row.disposition === 'skips')
.map(([key]) => siteKeyOf(key)),
);
expect([...skipping].sort()).toEqual([
'engine-cascade-planning.ts#cascadeRelationBehavior',
'engine-cascade-planning.ts#organizationOwnedRowCounts',
'engine-cascade-planning.ts#planCascadeAtomicity',
'home-amount-recompute.ts#recomputeHomeAmounts',
'lifecycle/lifecycle-service.ts#tenantWindowsFor',
'record-currency-backfill.ts#resolveScope',
'stored-expression-backfill.ts#backfillStoredExpressions',
]);
});
it('records why the lifecycle passes are in scope: the spec accepts a lifecycle policy on a federated object', () => {
// The lifecycle rows above are readers only because this parse succeeds. If
// the spec ever refuses `lifecycle` beside `external`, this fails and the
// rows can be re-judged as unreachable.
const federated = {
name: 'ext_event',
label: 'External Event',
datasource: 'remote_ds',
external: { remoteName: 'events' },
fields: { expires_at: { type: 'datetime' as const, label: 'Expires At' } },
};
for (const lifecycle of [
{ class: 'telemetry', retention: { maxAge: '30d' } },
{ class: 'transient', ttl: { field: 'expires_at', expireAfter: '1d' } },
{ class: 'audit', retention: { maxAge: '90d' }, archive: { after: '90d', to: 'cold' } },
]) {
const parsed = ObjectSchema.safeParse({ ...federated, lifecycle });
expect(parsed.success, JSON.stringify(parsed.error?.issues ?? [])).toBe(true);
}
});
});