Skip to content

Commit 0531281

Browse files
committed
Merge origin/main into claude/project-thread-x004t9
Claude-Session: https://claude.ai/code/session_01QciHBvFJXnhZqXmdqpDtpz Co-authored-by: Claude <noreply@anthropic.com>
2 parents 2e11452 + 46255b1 commit 0531281

32 files changed

Lines changed: 1203 additions & 99 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(app-shell,console): one app opens under one address — a name-alias route moves onto the package id
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
An app with a package id answered under two address families in one session. ADR-0048 keys `/apps/<segment>` on the package id, and every sidebar entry builds on it, but the app's `name` still resolves as an alias, and a page opened on the alias built every link of its own (list rows, record pages, related lists) on the alias. Landing on `/apps/clm/…` therefore opened contracts under the name and obligations and the approvals inbox under `/apps/app.objectstack.hotclm/…`.
12+
13+
- **`@object-ui/app-shell`:** a route under `/apps/<name>/…` whose app carries a package id is rewritten, with `replace`, to the same path under `/apps/<package id>/…`, keeping the query string, hash and history state. Old name-based bookmarks and shared links keep opening, now on the one address. The top-bar logo and every Home affordance (`resolveDeclaredHomePath`) name the declared app by its package id. An app without a package id, an app whose name is its package id, and every app after the first of a package that ships several (the package id opens the first) keep their name as their address.
14+
- **`@object-ui/console`:** the `/` landing (`resolveLandingPath`) names the landing app by the same address, so post-login and the logo agree and no redirect hop follows.
15+
16+
What to do: nothing. Links that name an app by its name keep working; they now arrive on its package-id address.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/plugin-security': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(metadata-protocol)!: a permission set that grants a hierarchy scope is refused on publish, and warned on a draft save, when the runtime mounts no hierarchy resolver; explain names the absent resolver (#26188)
8+
9+
Clause-②: yes (narrowing: on a runtime with no hierarchy resolver, publishing a permission set whose grant uses `own_and_reports`, `unit` or `unit_and_below` is refused, where it used to answer 200; widened: `@objectstack/spec/security` gains the export `findHierarchyScopeGrants`, and `@objectstack/plugin-security`'s `ExplainEngineDeps` gains the optional member `hierarchyResolverMounted`)
10+
Metadata-protocol: none
11+
Ruling-ref: #26059 ruling Q3 / Q4 (`6416233738`), items 9a and 9b of the item reading (`6415971852`)
12+
13+
`own_and_reports`, `unit` and `unit_and_below` are enforced only by the enterprise hierarchy resolver (capability `hierarchy-security`, ADR-0057). Without it the open sharing service evaluates them as `own`. `defineStack` already refuses such a grant unless the stack declares `requires: ['hierarchy-security']`, but a runtime save of the same permission set answered 200 with no word, and explain then told a manager that a subordinate's record was outside their unit.
14+
15+
What changes:
16+
17+
- The runtime authoring gate reads whether a hierarchy resolver is mounted (the kernel service `hierarchy-scope-resolver`) on every metadata write. When none is, a permission set whose `readScope` or `writeScope` is a hierarchy depth is refused on publish: a direct active save, the per-item publish of a draft, the package batch publish and a restore to such a version all answer 422 `INVALID_METADATA`, with one `issues[]` entry per grant under the rule `hierarchy-scope-capability-required`. The entry is located at the grant and names the `hierarchy-security` requirement.
18+
- A draft save of the same body still succeeds. Its answer carries the same finding, at `severity: 'warning'`, in `advisories`.
19+
- With a resolver mounted, nothing changes. A host with no service registry (the CLI) judges nothing here; `defineStack` is that host's door.
20+
- `explainAccess`: on a deployment with no resolver, the depth layer's record cell for a hierarchy read depth now reads "Hierarchy resolver absent — requires enterprise; depth evaluated as 'own'." instead of saying the owner is outside the caller's read depth.
21+
- `@objectstack/spec/security` exports `findHierarchyScopeGrants`, the one list of hierarchy depths and the one finding sentence. `defineStack`'s refusal reads it too, and its message is unchanged.
22+
23+
**BREAKING** for a runtime with no hierarchy resolver that publishes hierarchy-scope grants at runtime.
24+
25+
- **Before.** The publish answered 200 and the grant was enforced as owner-only.
26+
- **Now.** The publish answers 422 `INVALID_METADATA` with the rule `hierarchy-scope-capability-required`. A draft save warns.
27+
- **Fix.** Set the grant's `readScope` / `writeScope` to `own` or `org`, or run the permission set on a runtime that mounts the enterprise hierarchy resolver (`hierarchy-security`). Rows already stored are read as before.
28+
29+
<!-- adr-0087: not-required (no-migration-prescription) a run-time narrowing at the metadata publish door, conditional on a deployment fact (no hierarchy resolver mounted). No authorable key, spelling or stored shape moves: the permission-set schema parses exactly as before, `defineStack` already refused the same grant, and no stored row is read, rewritten or converted. The repair is the author's choice between a non-hierarchy depth and an enterprise runtime, which no ledger entry can derive. The other categories are closed on facts: the packages publish (not unpublished); no ADR-0087 id covers this verdict (not already-registered); the one spec export is added, not moved, renamed or removed; and nothing a stored artifact carries changes type, so no conversion has a source to rewrite. -->

‎packages/metadata-protocol/src/protocol-authoring-gate.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface AuthoringGateHost {
7272
readonly engine: ObjectStackProtocolImplementation['engine'];
7373
externalBindingSaveRefusal: ObjectStackProtocolImplementation['externalBindingSaveRefusal'];
7474
foldStoredCollection: ObjectStackProtocolImplementation['foldStoredCollection'];
75+
hierarchyResolverMounted: ObjectStackProtocolImplementation['hierarchyResolverMounted'];
7576
isArtifactBacked: ObjectStackProtocolImplementation['isArtifactBacked'];
7677
orgWallEnforced: ObjectStackProtocolImplementation['orgWallEnforced'];
7778
refuseRestoredBodyTheSaveDoorRefuses: ObjectStackProtocolImplementation['refuseRestoredBodyTheSaveDoorRefuses'];
@@ -168,7 +169,7 @@ export async function runAuthoringGate(
168169

169170
/** The body of `ObjectStackProtocolImplementation#assertRuntimeAuthoringRules`; the method's docblock there is its contract. */
170171
export async function assertRuntimeAuthoringRules(
171-
this: Pick<AuthoringGateHost, 'authoringChannel' | 'engine' | 'foldStoredCollection' | 'orgWallEnforced' | 'resolveSduiManifest' | 'resolveWritePackageScope' | 'rlsMembershipResolverKeys' | 'tenancyPostureInForce'>,
172+
this: Pick<AuthoringGateHost, 'authoringChannel' | 'engine' | 'foldStoredCollection' | 'hierarchyResolverMounted' | 'orgWallEnforced' | 'resolveSduiManifest' | 'resolveWritePackageScope' | 'rlsMembershipResolverKeys' | 'tenancyPostureInForce'>,
172173
evt: {
173174
type: string; name: string; state: 'draft' | 'active'; body: unknown; source?: string;
174175
/**
@@ -250,7 +251,21 @@ export async function assertRuntimeAuthoringRules(
250251
// proxy, which cost the ADR-0090 D11 object posture gate every
251252
// host-config deployment until #7674 finished the move.
252253
if (this.authoringChannel === 'package-author') return [];
253-
if (evt.state !== 'active') return [];
254+
if (evt.state !== 'active') {
255+
// [#26188] D1: no rule gates a draft. The one finding a draft does hear
256+
// is a hierarchy scope this runtime cannot enforce, as a warning on the
257+
// 2xx; it needs no collection read, so the draft keeps paying none.
258+
// A `migrate-stored` pass heals storage and hears nothing (see below).
259+
if (evt.source === 'migrate-stored') return [];
260+
const hierarchyResolverMounted = this.hierarchyResolverMounted();
261+
return evaluateRuntimeAuthoringGate({
262+
type: PLURAL_TO_SINGULAR[evt.type] ?? evt.type,
263+
name: evt.name,
264+
state: evt.state,
265+
body: evt.body,
266+
...(hierarchyResolverMounted !== undefined ? { hierarchyResolverMounted } : {}),
267+
}).advisories;
268+
}
254269
// `os migrate meta --stored --apply` rewrites rows that ALREADY EXIST
255270
// into the current dialect. It is not an author publishing anything —
256271
// it is the platform healing its own storage — and #4463 D4 is explicit
@@ -372,6 +387,10 @@ export async function assertRuntimeAuthoringRules(
372387
// gate stays pure.
373388
const rlsMembershipResolverKeys = this.rlsMembershipResolverKeys();
374389

390+
// [#26188] Is a hierarchy resolver mounted — a host fact of the same kind,
391+
// read here per publish and passed in so the gate stays pure.
392+
const hierarchyResolverMounted = this.hierarchyResolverMounted();
393+
375394
const verdict = evaluateRuntimeAuthoringGate({
376395
type: singular,
377396
name: evt.name,
@@ -398,6 +417,8 @@ export async function assertRuntimeAuthoringRules(
398417
// [#25234] The resolver's keys, read per publish; with them the
399418
// gate judges who owns each membership key.
400419
...(rlsMembershipResolverKeys !== undefined ? { rlsMembershipResolverKeys } : {}),
420+
// [#26188] With it the gate refuses a hierarchy scope no resolver enforces.
421+
...(hierarchyResolverMounted !== undefined ? { hierarchyResolverMounted } : {}),
401422
});
402423
if (verdict.error) throw verdict.error;
403424
return verdict.advisories;

‎packages/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts‎

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ import { ObjectStackProtocolImplementation } from './protocol.js';
5050
import type { MetadataAuthoringChannel } from './protocol.js';
5151
import { SDUI_MANIFEST_SERVICE } from './index.js';
5252
import { RLS_MEMBERSHIP_RESOLVER_SERVICE } from '@objectstack/spec/contracts';
53-
import { PUBLIC_FORM_INTAKE_UNAVAILABLE, stampHtmlPageRequires } from './runtime-authoring-gate.js';
53+
import {
54+
HIERARCHY_SCOPE_CAPABILITY_REQUIRED,
55+
HIERARCHY_SCOPE_RESOLVER_SERVICE,
56+
PUBLIC_FORM_INTAKE_UNAVAILABLE,
57+
stampHtmlPageRequires,
58+
} from './runtime-authoring-gate.js';
5459

5560
/** The issue's body. Zod-valid: `approvers[].value` is just a string to the schema. */
5661
const brokenApprovalFlow = () => ({
@@ -4720,3 +4725,88 @@ describe('runtime authoring gate on VIEW writes — a public form declaring a fi
47204725
expect(activeViewRows(rows)).toHaveLength(1);
47214726
});
47224727
});
4728+
4729+
// ─────────────────────────────────────────────────────────────────────────────
4730+
// #26188 — a HIERARCHY scope on a runtime with no hierarchy resolver. The door
4731+
// reads resolver presence per write (`HIERARCHY_SCOPE_RESOLVER_SERVICE`): with
4732+
// none, publishing the grant is refused and a draft save answers 200 carrying
4733+
// the same finding as a `warning` advisory; with one, nothing changes. The pure
4734+
// rows are `runtime-authoring-gate.hierarchy-scope.test.ts`.
4735+
// ─────────────────────────────────────────────────────────────────────────────
4736+
4737+
describe('runtime authoring gate on PERMISSION writes — hierarchy scope without a resolver (#26188)', () => {
4738+
let warn: ReturnType<typeof vi.spyOn>;
4739+
beforeEach(() => {
4740+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
4741+
delete process.env.OS_ALLOW_UNLINTED_METADATA_WRITES;
4742+
});
4743+
afterEach(() => {
4744+
warn.mockRestore();
4745+
delete process.env.OS_ALLOW_UNLINTED_METADATA_WRITES;
4746+
});
4747+
4748+
const managerSet = () => ({
4749+
name: 'sales_manager',
4750+
label: 'Sales Manager',
4751+
objects: { leave_request: { allowRead: true, readScope: 'unit_and_below' } },
4752+
});
4753+
const NO_RESOLVER = () => new Map<string, any>();
4754+
const RESOLVER = () => new Map<string, any>([[HIERARCHY_SCOPE_RESOLVER_SERVICE, { resolveOwnerIds: async () => [] }]]);
4755+
4756+
function permissionProtocol(services: () => Map<string, any>) {
4757+
const { engine, rows } = makeStubEngine();
4758+
const protocol = new ObjectStackProtocolImplementation(engine, services as any, 'env_test') as any;
4759+
return { protocol, rows };
4760+
}
4761+
const settle = (p: Promise<unknown>) =>
4762+
p.then((result) => ({ result: result as any, err: null as any }), (err) => ({ result: null as any, err }));
4763+
const rowsOf = (rows: Map<string, Row>, state: 'draft' | 'active') =>
4764+
Array.from(rows.values()).filter((r) => r.type === 'permission' && r.state === state);
4765+
const hierarchyFindings = (list: ReadonlyArray<{ rule: string }> | undefined) =>
4766+
(list ?? []).filter((i) => i.rule === HIERARCHY_SCOPE_CAPABILITY_REQUIRED);
4767+
4768+
it('no resolver, publish: refused 422 INVALID_METADATA naming the grant, and nothing is written', async () => {
4769+
const { protocol, rows } = permissionProtocol(NO_RESOLVER);
4770+
const { err } = await settle(protocol.saveMetaItem({ type: 'permission', name: 'sales_manager', item: managerSet() }));
4771+
expect({ code: err?.code, status: err?.status }).toEqual({ code: 'INVALID_METADATA', status: 422 });
4772+
const findings = hierarchyFindings(err.issues);
4773+
expect(findings).toEqual([expect.objectContaining({
4774+
severity: 'error',
4775+
path: 'permissions.sales_manager.objects.leave_request.readScope',
4776+
})]);
4777+
expect((findings[0] as any).message).toContain('`hierarchy-security`');
4778+
expect(rowsOf(rows, 'active')).toHaveLength(0);
4779+
});
4780+
4781+
it('no resolver, draft: saved (200) with the same finding as a warning advisory; publishing it is refused', async () => {
4782+
const { protocol, rows } = permissionProtocol(NO_RESOLVER);
4783+
const refused = await settle(protocol.saveMetaItem({ type: 'permission', name: 'sales_manager', item: managerSet() }));
4784+
const { result, err } = await settle(
4785+
protocol.saveMetaItem({ type: 'permission', name: 'sales_manager', item: managerSet(), mode: 'draft' }),
4786+
);
4787+
expect(err).toBeNull();
4788+
expect(result).toMatchObject({ success: true, state: 'draft' });
4789+
const published = hierarchyFindings(refused.err.issues)[0] as Record<string, unknown>;
4790+
expect(result.advisories).toEqual([{ ...published, severity: 'warning' }]);
4791+
expect(rowsOf(rows, 'draft')).toHaveLength(1);
4792+
4793+
const promoted = await settle(protocol.publishMetaItem({ type: 'permission', name: 'sales_manager' }));
4794+
expect({ code: promoted.err?.code, status: promoted.err?.status }).toEqual({ code: 'INVALID_METADATA', status: 422 });
4795+
expect(hierarchyFindings(promoted.err.issues)).toHaveLength(1);
4796+
expect(rowsOf(rows, 'active')).toHaveLength(0);
4797+
});
4798+
4799+
it('a resolver mounted: the same grant publishes, and neither door says anything about it', async () => {
4800+
const { protocol, rows } = permissionProtocol(RESOLVER);
4801+
const draft = await settle(
4802+
protocol.saveMetaItem({ type: 'permission', name: 'sales_manager', item: managerSet(), mode: 'draft' }),
4803+
);
4804+
expect(draft.err).toBeNull();
4805+
expect(hierarchyFindings(draft.result.advisories)).toEqual([]);
4806+
const live = await settle(protocol.saveMetaItem({ type: 'permission', name: 'sales_manager', item: managerSet() }));
4807+
expect(live.err).toBeNull();
4808+
expect(live.result).toMatchObject({ success: true, state: 'active' });
4809+
expect(hierarchyFindings(live.result.advisories)).toEqual([]);
4810+
expect(rowsOf(rows, 'active')).toHaveLength(1);
4811+
});
4812+
});

‎packages/metadata-protocol/src/protocol.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { stripUnauthorableProperties } from './unauthorable-nodes.js';
2727
// admits anything. See the module header for the predicate and its controls.
2828
import { markErasedAuthoringInput } from './erased-authoring-mark.js';
2929
import {
30+
HIERARCHY_SCOPE_RESOLVER_SERVICE,
3031
SDUI_MANIFEST_SERVICE,
3132
isUsableSduiManifest,
3233
stampHtmlPageRequires,
@@ -7146,6 +7147,7 @@ export class ObjectStackProtocolImplementation implements
71467147
get authoringChannel() { return readAuthoringChannel(); },
71477148
get engine() { return readEngine(); },
71487149
foldStoredCollection: (...a) => this.foldStoredCollection(...a),
7150+
hierarchyResolverMounted: (...a) => this.hierarchyResolverMounted(...a),
71497151
orgWallEnforced: (...a) => this.orgWallEnforced(...a),
71507152
resolveSduiManifest: (...a) => this.resolveSduiManifest(...a),
71517153
resolveWritePackageScope: (...a) => this.resolveWritePackageScope(...a),
@@ -7540,6 +7542,30 @@ export class ObjectStackProtocolImplementation implements
75407542
return keys as readonly string[];
75417543
}
75427544

7545+
/**
7546+
* [#26188] Is a hierarchy resolver mounted on this runtime — a service
7547+
* registered under `HIERARCHY_SCOPE_RESOLVER_SERVICE` (ADR-0057; the
7548+
* enterprise `hierarchy-security` capability registers one, the open edition
7549+
* none)? The input the runtime authoring gate refuses an unenforceable
7550+
* hierarchy scope with on publish, and warns on a draft save with.
7551+
*
7552+
* Read per write, as {@link rlsMembershipResolverKeys} reads its service, so a
7553+
* resolver registered after this protocol is assembled is seen by the next
7554+
* write; nothing is recorded. `undefined` — the CLI's reading, under which
7555+
* nothing is judged — when this host has no service registry or the lookup
7556+
* throws.
7557+
*/
7558+
private hierarchyResolverMounted(): boolean | undefined {
7559+
const registry = this.getServicesRegistry?.();
7560+
if (!registry) return undefined;
7561+
try {
7562+
const resolver = registry.get(HIERARCHY_SCOPE_RESOLVER_SERVICE);
7563+
return resolver !== undefined && resolver !== null;
7564+
} catch {
7565+
return undefined;
7566+
}
7567+
}
7568+
75437569
/**
75447570
* Run the registered projector for a just-persisted mutation (ADR-0094).
75457571
* Returns `undefined` when no projector is registered for the type;

0 commit comments

Comments
 (0)