Skip to content

Commit b107953

Browse files
committed
test(service-storage): pin the sweep's package-entry exports through the operator step itself
Dropping one of the four exports from the entry left every test and every derived export gate green (measured), so this case imports the sweep and its report types from ./index.js, asserts the entry hands out the very functions this file drives, and runs plan, apply and a second run through the entry against a stored public row. Claude-Session: https://claude.ai/code/session_01VZqqwTj2wsihZEbfT6yyYN Co-authored-by: Claude <noreply@anthropic.com>
1 parent 15e5891 commit b107953

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

‎packages/services/service-storage/src/backfill-sys-file-public-scope.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
// of a stored `public` row is refused, while reads and scope-free updates
2323
// of that row are unaffected;
2424
// - the rollback's precondition: on this release the inverse write
25-
// (`user` → `public`) is refused by the engine.
25+
// (`user` → `public`) is refused by the engine;
26+
// - the operator step as the changeset writes it: the four functions and
27+
// their report types come from the package entry (`./index.ts`), because a
28+
// deployment runs the published package, never a source checkout.
2629

2730
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2831
import { ObjectQL } from '@objectstack/objectql';
@@ -37,6 +40,16 @@ import {
3740
planSysFilePublicScopeBackfill,
3841
runSysFilePublicScopeBackfill,
3942
} from './backfill-sys-file-public-scope.js';
43+
// The operator step imports the sweep from the PACKAGE, not from this module:
44+
// the published `dist` is built from `./index.ts`, so the pin below reads the
45+
// entry itself, values and report types both.
46+
import * as packageEntry from './index.js';
47+
import type {
48+
PlannedSysFileScopeRow as EntryPlannedRow,
49+
SysFilePublicScopeBackfillEngine as EntryEngine,
50+
SysFilePublicScopeBackfillOptions as EntryOptions,
51+
SysFilePublicScopeBackfillReport as EntryReport,
52+
} from './index.js';
4053

4154
const SYSTEM = { context: { isSystem: true } };
4255

@@ -247,4 +260,28 @@ describe('sys_file public-scope backfill (#22443 ruling B) — a real ObjectQL o
247260
});
248261
expect((await sysFile('f_pub'))?.scope).toBe(REWRITTEN_SYS_FILE_SCOPE);
249262
});
263+
264+
it('the operator step as the changeset writes it: the sweep imported from the package entry plans, applies, and then writes zero', async () => {
265+
// The entry exports the very functions this file drives, not copies of them.
266+
expect(packageEntry.planSysFilePublicScopeBackfill).toBe(planSysFilePublicScopeBackfill);
267+
expect(packageEntry.applySysFilePublicScopeBackfill).toBe(applySysFilePublicScopeBackfill);
268+
expect(packageEntry.runSysFilePublicScopeBackfill).toBe(runSysFilePublicScopeBackfill);
269+
expect(packageEntry.formatSysFilePublicScopeBackfillReport).toBe(formatSysFilePublicScopeBackfillReport);
270+
271+
await sql.create('sys_file', legacyPublicRow('f_pub'));
272+
const operatorEngine = engine as unknown as EntryEngine;
273+
const options: EntryOptions = { pageSize: 50 };
274+
275+
const plan: EntryReport = await packageEntry.planSysFilePublicScopeBackfill(operatorEngine, options);
276+
const planned: EntryPlannedRow[] = plan.rows;
277+
expect(planned).toEqual([{ id: 'f_pub', key: 'public/f_pub.png', from: 'public', to: 'user' }]);
278+
expect(packageEntry.formatSysFilePublicScopeBackfillReport(plan)).toContain('DRY RUN');
279+
280+
const applied: EntryReport = await packageEntry.applySysFilePublicScopeBackfill(operatorEngine, plan, options);
281+
expect(applied).toMatchObject({ dryRun: false, scanned: 1, written: 1, failures: [] });
282+
expect((await sysFile('f_pub'))?.scope).toBe(REWRITTEN_SYS_FILE_SCOPE);
283+
284+
const again: EntryReport = await packageEntry.runSysFilePublicScopeBackfill(operatorEngine, { ...options, dryRun: false });
285+
expect(again).toMatchObject({ scanned: 0, planned: 0, written: 0 });
286+
});
250287
});

0 commit comments

Comments
 (0)