Skip to content

Commit 90423f6

Browse files
committed
test(objectql, runtime): pins for the bare function read, the disabled holder and the release's runtime rows
Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 044e8f2 commit 90423f6

1 file changed

Lines changed: 134 additions & 4 deletions

File tree

‎packages/runtime/src/app-artifact-handlers.test.ts‎

Lines changed: 134 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,12 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu
656656
// or by beta and a package of another namespace too, as two namespaces may
657657
// hold one function name since #31700: a bare read of that name is refused
658658
// (409), so the teardown reads beta's own entry and never aborts on it.
659+
// [#32907] …or by beta and the platform (an owner-less registration): that
660+
// bare read is refused too since #32907, and the teardown still runs whole.
659661
it.each([
660662
['beta alone holds the name it keeps (CONTROL: the bare slot answers as before)', false],
661-
['another namespace\'s package holds the name beta keeps too', true],
663+
['another namespace\'s package holds the name beta keeps too', 'package'],
664+
['the platform holds the name beta keeps too (#32907: its bare read is refused, and the teardown never asks it)', 'platform'],
662665
] as const)('a re-bind that moves a function to another owner takes it off the owner the previous bind gave it, which keeps its other functions — %s', async (_case, sharedKept) => {
663666
const GAMMA = 'com.qa.bodies.gamma';
664667
const body = (ns: Ns, hooks: unknown[]) => ({
@@ -680,19 +683,26 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu
680683
const ql = engineFor(first, logger);
681684
bind(ql, first, logger);
682685
expect(ql.functionHoldersOf('qa_moving').packageHolders, 'precondition: only beta\'s hook names it').toEqual([BETA]);
683-
if (sharedKept) ql.registerFunction('qa_kept', stamp('gamma'), { packageId: appArtifactHandlerOwner(GAMMA) });
686+
if (sharedKept === 'package') ql.registerFunction('qa_kept', stamp('gamma'), { packageId: appArtifactHandlerOwner(GAMMA) });
687+
if (sharedKept === 'platform') ql.registerFunction('qa_kept', stamp('platform'));
684688

685689
// Now the top level names it too: one function two owners' hooks name, under the artifact's id.
686690
bind(ql, artifactWith([hookOn('alpha', 'qa_res_moving', 'qa_moving')]), logger);
687691

688692
expect(errors.map((e) => e.message), 'the teardown ran whole').toEqual([]);
689693
expect(ql.functionHoldersOf('qa_moving').packageHolders, 'held once, by the artifact\'s id').toEqual([ALPHA]);
690-
expect([...ql.functionHoldersOf('qa_kept').packageHolders].sort(), 'beta keeps the function only its hook names').toEqual(sharedKept ? [BETA, GAMMA] : [BETA]);
694+
expect([...ql.functionHoldersOf('qa_kept').packageHolders].sort(), 'beta keeps the function only its hook names').toEqual(sharedKept === 'package' ? [BETA, GAMMA] : [BETA]);
691695
expect(String(await insertInto(ql, 'beta')).split(';').filter(Boolean).sort()).toEqual(['kept', 'moving']);
692696
expect(await insertInto(ql, 'alpha')).toBe('moving;');
693-
if (sharedKept) {
697+
if (sharedKept === 'package') {
694698
expect(ql.functionHoldersOf('qa_kept').packageItem(GAMMA)?.packageId, 'the other holder keeps its own').toBe(appArtifactHandlerOwner(GAMMA));
695699
expect(() => ql.resolveFunctionEntry('qa_kept'), 'the bare read of a name two packages hold stays refused').toThrow(/com\.qa\.bodies\.beta[\s\S]*com\.qa\.bodies\.gamma|com\.qa\.bodies\.gamma[\s\S]*com\.qa\.bodies\.beta/);
700+
} else if (sharedKept === 'platform') {
701+
expect(ql.functionHoldersOf('qa_kept').platformItem?.(), 'the platform keeps its own').toBeDefined();
702+
let refused: any;
703+
try { ql.resolveFunctionEntry('qa_kept'); } catch (e) { refused = e; }
704+
expect([refused?.code, refused?.status], 'the bare read of a name the platform and beta hold is refused').toEqual(['RESOURCE_CONFLICT', 409]);
705+
expect(refused.refusal.candidates).toEqual([{ kind: 'package', packageId: BETA }, { kind: 'platform' }]);
696706
} else {
697707
expect(ql.resolveFunctionEntry('qa_kept')?.packageId).toBe(appArtifactHandlerOwner(BETA));
698708
}
@@ -873,6 +883,126 @@ describe('[ADR-0150 D4] a multi-package artifact binds each body\'s hooks and fu
873883
expect(kept?.code, 'CONTROL: beta still holds what it keeps').toBe('NAMESPACE_CONFLICT');
874884
expect(holdersNamed(kept)).toEqual([BETA]);
875885
});
886+
887+
// [#32910] The release's three runtime rows the registry-method pins did
888+
// not reach: a re-bind before the seal, the ordering of the move path,
889+
// and the owner-spelling order where the bare-id registration comes first.
890+
describe('[#32910] the release through a runtime re-bind: before the seal, the move path\'s ordering, and the other owner-spelling order', () => {
891+
const betaMovingHooks = [hookOn('beta', 'qa_beta_moving', 'qa_moving'), hookOn('beta', 'qa_beta_kept', 'qa_kept')];
892+
const fns = { qa_moving: stamp('moving'), qa_kept: stamp('kept') };
893+
894+
// N4: the release runs on a re-bind made before the cold-boot seal too,
895+
// so the seal finds no clash the re-bind left behind. Gamma (a
896+
// co-owner of beta's namespace) binds the name before the seal, so a
897+
// claim beta kept would be a clash for the seal to report.
898+
it.each([
899+
['a function moved to the artifact\'s own package', 'moved'],
900+
['a dropped body\'s function', 'dropped'],
901+
] as const)('a re-bind before the seal releases the old owner\'s claim on %s: the seal reports no clash', (_case, shape) => {
902+
const first = shape === 'moved'
903+
? movingArtifact(betaMovingHooks, [], fns)
904+
: movingArtifact([hookOn('beta', 'qa_beta_only', 'qa_moving')], [], { qa_moving: stamp('moving') });
905+
const { errors, logger } = recordingErrors();
906+
const ql = engineFor(first, logger);
907+
installGamma(ql);
908+
bind(ql, first, logger);
909+
bind(ql, shape === 'moved'
910+
? movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns)
911+
: { ...first, packages: [first.packages[0]], functions: { qa_alpha_own: stamp('alpha_own') } }, logger);
912+
if (shape === 'dropped') expect(gammaBinds(ql, 'qa_moving'), 'before the seal nothing is refused').toBeUndefined();
913+
914+
expect(errors.map((e) => e.message), 'every group bound').toEqual([]);
915+
expect(ql.functionHoldersOf('qa_moving').packageHolders).toEqual(shape === 'moved' ? [ALPHA] : [GAMMA]);
916+
expect(ql.registry.sealBareNameHolders(), 'beta holds no claim on it any more').toEqual([]);
917+
});
918+
919+
// D2-N1: what the old owner keeps is registered again BEFORE the
920+
// release asks the engine what it still holds. A function the previous
921+
// bind gave beta that the new bind neither moves nor gives back to it
922+
// is held again only by that registration, and nothing re-claims it:
923+
// the ordering alone keeps its claim.
924+
it('CONTROL — the move path releases after the old owner\'s kept functions are registered again: a function the new bind neither moves nor gives back keeps its claim', () => {
925+
const first = movingArtifact(
926+
[...betaMovingHooks, hookOn('beta', 'qa_beta_prev_hook', 'qa_prev')],
927+
[],
928+
{ ...fns, qa_prev: stamp('prev') },
929+
);
930+
const { errors, logger } = recordingErrors();
931+
const ql = engineFor(first, logger);
932+
installGamma(ql);
933+
bind(ql, first, logger);
934+
expect(ql.registry.sealBareNameHolders()).toEqual([]);
935+
936+
bind(ql, movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns), logger);
937+
938+
expect(errors.map((e) => e.message), 'every group bound').toEqual([]);
939+
expect(ql.functionHoldersOf('qa_moving').packageHolders).toEqual([ALPHA]);
940+
expect(ql.functionHoldersOf('qa_prev').packageHolders, 'beta keeps the function the new bind does not name').toEqual([BETA]);
941+
const prev = gammaBinds(ql, 'qa_prev');
942+
expect(prev?.code, 'beta keeps its claim on it').toBe('NAMESPACE_CONFLICT');
943+
expect(holdersNamed(prev)).toEqual([BETA]);
944+
});
945+
946+
// D2-N2: the bare-id registration FIRST, then the bind under
947+
// `app:<id>`: the engine's one holder entry for beta is the bind's, so
948+
// the removal by `app:<id>` takes the name off beta and the release
949+
// frees its claim. (The bare-id-last order is the two CONTROLs above.)
950+
it.each([
951+
['moved: the gaining owner\'s group binds', 'moved'],
952+
['dropped: a co-owner binds the name', 'dropped'],
953+
] as const)('the package\'s bare-id registration before the bind: the removal takes the holder entry the bind replaced it with, and the claim is released — %s', (_case, shape) => {
954+
const first = shape === 'moved'
955+
? movingArtifact([hookOn('beta', 'qa_beta_moving', 'qa_moving')], [], { qa_moving: stamp('moving') })
956+
: movingArtifact([hookOn('beta', 'qa_beta_only', 'qa_moving')], [], { qa_moving: stamp('moving') });
957+
const { errors, logger } = recordingErrors();
958+
const ql = engineFor(first, logger);
959+
installGamma(ql);
960+
// A host's own registration for beta, under the bare id, BEFORE the bind.
961+
ql.registerFunction('qa_moving', stamp('host'), { packageId: BETA });
962+
bind(ql, first, logger);
963+
expect(ql.functionHoldersOf('qa_moving').packageItem(BETA)?.packageId, 'precondition: the bind replaced beta\'s entry').toBe(appArtifactHandlerOwner(BETA));
964+
expect(ql.registry.sealBareNameHolders()).toEqual([]);
965+
966+
bind(ql, shape === 'moved'
967+
? movingArtifact([hookOn('beta', 'qa_beta_moving', 'qa_moving')], [hookOn('alpha', 'qa_res_moving', 'qa_moving')], { qa_moving: stamp('moving') })
968+
: { ...first, packages: [first.packages[0]], functions: { qa_alpha_own: stamp('alpha_own') } }, logger);
969+
970+
expect(errors.map((e) => e.message), 'every group bound').toEqual([]);
971+
if (shape === 'moved') {
972+
expect(ql.functionHoldersOf('qa_moving').packageHolders, 'held by the gaining owner alone').toEqual([ALPHA]);
973+
expect(holdersNamed(gammaBinds(ql, 'qa_moving'))).toEqual([ALPHA]);
974+
} else {
975+
expect(ql.functionHoldersOf('qa_moving').packageHolders, 'no holder is left').toEqual([]);
976+
expect(gammaBinds(ql, 'qa_moving'), 'no claim is left to refuse it').toBeUndefined();
977+
}
978+
});
979+
980+
// [#32933] The move path reads the bare slot of a kept name off the
981+
// holder set, never through the bare read, which answers nothing for
982+
// a disabled package: a disabled old owner keeps what it keeps under
983+
// the owner spelling it held it by, and its claim.
984+
it('CONTROL — a disabled old owner keeps a kept function under the spelling it held it by, and its claim', () => {
985+
const first = movingArtifact(
986+
[...betaMovingHooks, hookOn('beta', 'qa_beta_prev_hook', 'qa_prev')],
987+
[],
988+
{ ...fns, qa_prev: stamp('prev') },
989+
);
990+
const { errors, logger } = recordingErrors();
991+
const ql = engineFor(first, logger);
992+
installGamma(ql);
993+
bind(ql, first, logger);
994+
// A host's own registration for beta, under the bare id, after the bind: the slot it holds.
995+
ql.registerFunction('qa_prev', stamp('host'), { packageId: BETA });
996+
expect(ql.registry.sealBareNameHolders()).toEqual([]);
997+
ql.registry.disablePackage(BETA);
998+
999+
bind(ql, movingArtifact(betaMovingHooks, [hookOn('alpha', 'qa_res_moving', 'qa_moving')], fns), logger);
1000+
1001+
expect(errors.map((e) => e.message), 'every group bound').toEqual([]);
1002+
expect(ql.functionHoldersOf('qa_prev').packageItem(BETA)?.packageId, 'the bare-id spelling it held').toBe(BETA);
1003+
expect(holdersNamed(gammaBinds(ql, 'qa_prev')), 'its claim stays').toEqual([BETA]);
1004+
});
1005+
});
8761006
});
8771007

8781008
it('CONTROL — on a built artifact a body\'s hook binds the handler ref its runtime module serves at the top level; a residual hook binds under the artifact\'s id', async () => {

0 commit comments

Comments
 (0)