Skip to content

Commit 743cc54

Browse files
committed
fix(objectql,cli): recompute skips a federated object's unprovisioned columns; pin the CLI double's update (#27193)
Claude-Session: https://claude.ai/code/session_01Utp6CXZRTkUQ6UjyMWfN2U Co-authored-by: Claude <noreply@anthropic.com>
1 parent 981b5b0 commit 743cc54

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎packages/cli/src/commands/migrate/recompute-home-amounts.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { probeMigrationTarget } from '../../utils/migrate-occupancy-gate.js';
2626
import { buildDataMigrationPlugins } from '../../utils/data-migration-plugins.js';
2727
import { isExitSignal } from '../../utils/format.js';
2828
import { recomputeHomeAmounts } from '@objectstack/objectql';
29+
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';
2930

3031
vi.mock('../../utils/schema-migrate.js', () => ({ bootSchemaStack: vi.fn() }));
3132
vi.mock('../../utils/migrate-occupancy-gate.js', () => ({
@@ -49,7 +50,10 @@ const RUN_TIMEOUT = 60_000;
4950
const engine = {
5051
getObject: () => ({ fields: {} }),
5152
find: async () => [],
52-
update: async () => ({}),
53+
update: async (data: Record<string, unknown>, options?: Record<string, unknown>) => {
54+
assertEngineUpdateDispatch(data, options);
55+
return {};
56+
},
5357
insert: async () => ({}),
5458
homeAmountReadsFor: () => ({}),
5559
getConfigs: () => ({ invoice: {}, sys_user: {} }),

‎packages/objectql/src/federated-injected-column-readers.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ const READERS: Record<string, Row> = {
365365
'engine-compatibility-api.ts#syncObjectSchema :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
366366
'engine-compatibility-api.ts#syncSchemas :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
367367
'engine-secret-internal-fields.ts#encryptSecretFields :: created_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
368+
'home-amount-recompute.ts#recomputeHomeAmounts :: isFederatedUnprovisionedInjectedColumn()': {
369+
disposition: 'skips',
370+
why: 'the recompute never selects an injected column a federated object does not provision',
371+
},
372+
'home-amount-recompute.ts#recomputeHomeAmounts :: organization_id': {
373+
disposition: 'skips',
374+
why: 'the recompute reads the organization a write converts a row under, and leaves the column out of its read on a federated object',
375+
},
376+
'home-amount-recompute.ts#recomputeHomeAmounts :: updated_at': {
377+
disposition: 'skips',
378+
why: 'the recompute reads the stamp its apply keeps, and leaves the column out of its read (and its write) on a federated object',
379+
},
368380
'engine-migration-state.ts#recordObservedDeviation :: updated_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
369381
'engine-migration-state.ts#retractCreationAttestation :: updated_at': { disposition: 'not-a-read', why: PLATFORM_ROW },
370382
'plugin.ts#reconcileFederatedBindings :: isFederatedObject()': { disposition: 'not-a-read', why: SYNC_ROUTE },
@@ -691,7 +703,7 @@ describe('[#21918] every engine reader of an injected column has a disposition t
691703
}
692704
}, SCAN_BUDGET_MS);
693705

694-
it('the sites that skip are exactly the cascade scan, its plan, the organization-delete count, and the lifecycle tenant partition', () => {
706+
it('the sites that skip are exactly the cascade scan, its plan, the organization-delete count, the lifecycle tenant partition, and the home-amount recompute', () => {
695707
const skipping = new Set(
696708
Object.entries(READERS)
697709
.filter(([, row]) => row.disposition === 'skips')
@@ -701,6 +713,7 @@ describe('[#21918] every engine reader of an injected column has a disposition t
701713
'engine-cascade-planning.ts#cascadeRelationBehavior',
702714
'engine-cascade-planning.ts#organizationOwnedRowCounts',
703715
'engine-cascade-planning.ts#planCascadeAtomicity',
716+
'home-amount-recompute.ts#recomputeHomeAmounts',
704717
'lifecycle/lifecycle-service.ts#tenantWindowsFor',
705718
]);
706719
});

‎packages/objectql/src/home-amount-recompute.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import {
9999
type HomeAmountServing,
100100
} from './home-amount-projection.js';
101101
import { isRecordCurrencyBlank } from './validation/record-currency-code.js';
102+
import { isFederatedUnprovisionedInjectedColumn } from './federated-object.js';
102103
import { VALIDATION_FAILED_CODE } from './validation/record-validator.js';
103104

104105
/** Why a stored amount was listed and not written. */
@@ -342,7 +343,8 @@ export async function recomputeHomeAmounts(
342343
const plan = resolvePlan(engine, options);
343344
const since = options.since ?? null;
344345
const maxListed = options.maxListed ?? DEFAULT_MAX_LISTED;
345-
const declared = engine.getObject(object)?.fields ?? {};
346+
const schema = engine.getObject(object);
347+
const declared = schema?.fields ?? {};
346348

347349
const report: HomeAmountRecomputeReport = {
348350
object,
@@ -377,7 +379,12 @@ export async function recomputeHomeAmounts(
377379
const organizations = new Map<string, HomeAmountRecomputeOrganization>();
378380

379381
const columns = new Set<string>(['id']);
380-
for (const name of ['organization_id', 'updated_at']) if (name in declared) columns.add(name);
382+
// The organization a write converts the row under, and the stamp the apply keeps. A federated
383+
// object's injected columns are not provisioned, so neither is read there: its rows convert
384+
// under the caller's organization, as its writes do, and the apply sends no stamp.
385+
for (const name of ['organization_id', 'updated_at']) {
386+
if (name in declared && !isFederatedUnprovisionedInjectedColumn(schema, name)) columns.add(name);
387+
}
381388
for (const e of plan) for (const name of [e.amountField, e.codeField, e.rateDateField, e.homeField, e.rateField]) columns.add(name);
382389

383390
// Seek by `id`: this run's claim is about EVERY stored row, which an offset walk cannot promise.

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"$comment": "GENERATED — the RETAINED ledger of check-engine-double-contract.mjs (#9680). Regenerate with `node scripts/check-engine-double-contract.mjs --write`; never hand-edit. Each row is one (file, verb) whose engine double routes through the producer's dispatch predicate. This is the OPPOSITE polarity to engine-double-contract.baseline.json: that ledger records DEBT and may only shrink, this one records COVERAGE and may only grow. A row that disappears is a pinned double that left the population — the blind spot #9680 measured, where deleting a double's delete() member took 319 pinned to 318 with the gate green. Read a removal in this file's diff as a coverage loss and check it was intended.",
33
"entries": [
4+
{
5+
"file": "packages/cli/src/commands/migrate/recompute-home-amounts.test.ts",
6+
"verb": "update",
7+
"pinned": 1
8+
},
49
{
510
"file": "packages/cli/src/commands/serve-datasource-secret-resolver.test.ts",
611
"verb": "delete",

0 commit comments

Comments
 (0)