Skip to content

Commit 6bc3df3

Browse files
committed
fix(cli): os lint leaves the platform-requested guest_portal permission set alone
The public form doors' submit context requests the permission set named exactly `guest_portal` (packages/rest/src/form-routes.ts), and the result masker resolves a set registered under that name. Renaming it to `<namespace>_guest_portal`, as `naming/namespace-prefix` suggested, would leave the masker with nothing to find. `PLATFORM_REQUESTED_BARE_NAMES` names that one spelling in `permissions`, so phase 3 (#30806) can reuse it. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyadQ5Zhih2y1GNTQm
1 parent 0e88208 commit 6bc3df3

3 files changed

Lines changed: 60 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): `os lint`'s `naming/namespace-prefix` no longer asks a package to rename the `guest_portal` permission set
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The public form doors' submit context requests the permission set named exactly `guest_portal`, and the result masker resolves a set registered under that name. A package that declares it is plugging into that door. Renaming it to `<namespace>_guest_portal`, which the warning used to suggest, would leave the masker with nothing to find. `os lint` now leaves that one name alone in `permissions`. The same spelling in any other collection, or any other permission set name, is still judged.

‎packages/cli/src/commands/lint.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ function getViewLabel(view: any, viewPath: string): { label?: unknown; path: str
222222
* package's item OF THE SAME NAME, so its name is the base's and is not
223223
* judged. A package that declares no namespace has nothing to prefix with and
224224
* is not judged: the object rule's posture, which does not invent a prefix on
225-
* the author's behalf either.
225+
* the author's behalf either. A name the PLATFORM requests by its bare
226+
* spelling ({@link PLATFORM_REQUESTED_BARE_NAMES}) is not judged either: a
227+
* package declares it to plug into that door, and the prefixed spelling would
228+
* unplug it.
226229
*
227230
* ## The duplicate finding, which stays
228231
*
@@ -277,7 +280,12 @@ function namespacePrefixIssues(stack: any, pathPrefix = ''): LintIssue[] {
277280
const name = item?.name;
278281
if (typeof name !== 'string' || !name) continue;
279282

280-
if (ns && !isOverrideDeclaration(item) && !carriesPackageNamespace(name, ns)) {
283+
if (
284+
ns
285+
&& !isOverrideDeclaration(item)
286+
&& !carriesPackageNamespace(name, ns)
287+
&& !isPlatformRequestedBareName(key, name)
288+
) {
281289
const renamed = `${ns}_${name}`;
282290
issues.push({
283291
severity: 'warning',
@@ -347,6 +355,30 @@ export const NAME_JUDGED_ELSEWHERE: Readonly<Record<string, string>> = Object.fr
347355
docs: 'refused as an error by the doc lint (`docs/namespace-prefix`, ADR-0046)',
348356
});
349357

358+
/**
359+
* Bare names the PLATFORM requests by spelling, per collection: a package
360+
* declares one to plug into the door that asks for it, so it must keep the
361+
* bare spelling, and `naming/namespace-prefix` does not judge it. Exported so
362+
* the phase-3 refusal (#30806) reads the same list.
363+
*
364+
* - `permissions` → `guest_portal`: the public form doors' submit context
365+
* requests the permission set of exactly this name
366+
* (`permissions: ['guest_portal']`, packages/rest/src/form-routes.ts:653),
367+
* and the grant's result masker resolves a set registered under it.
368+
* ADR-0138's ledger keeps that name ("fate: keep") and cites
369+
* `examples/app-crm/src/security/sales-positions.ts#GuestPortalProfile` as
370+
* its reference declaration; `crm_guest_portal` would reach nothing.
371+
*/
372+
export const PLATFORM_REQUESTED_BARE_NAMES: Readonly<Record<string, readonly string[]>> = Object.freeze({
373+
permissions: Object.freeze(['guest_portal']),
374+
});
375+
376+
/** Whether `name` in collection `key` is one {@link PLATFORM_REQUESTED_BARE_NAMES} lists. */
377+
function isPlatformRequestedBareName(key: string, name: string): boolean {
378+
return Object.prototype.hasOwnProperty.call(PLATFORM_REQUESTED_BARE_NAMES, key)
379+
&& PLATFORM_REQUESTED_BARE_NAMES[key].includes(name);
380+
}
381+
350382
/**
351383
* The types the duplicate finding judges, and the key each occupies at runtime.
352384
*

‎packages/cli/test/lint-namespace-prefix.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';
44
import { normalizeStackInput } from '@objectstack/spec';
55
import { PLURAL_TO_SINGULAR } from '@objectstack/spec/shared';
66
import { ActionSchema } from '@objectstack/spec/ui';
7-
import { lintConfig, NAME_JUDGED_ELSEWHERE } from '../src/commands/lint';
7+
import { lintConfig, NAME_JUDGED_ELSEWHERE, PLATFORM_REQUESTED_BARE_NAMES } from '../src/commands/lint';
88

99
const RULE = 'naming/namespace-prefix';
1010
const prefixIssues = (config: any) => lintConfig(config).filter((i) => i.rule === RULE);
@@ -105,6 +105,21 @@ describe('lint — every package-authored name carries the package namespace (ru
105105
} as any).map((i) => i.fix)).toEqual(['crm_billing.refund']);
106106
});
107107

108+
it('a name the platform requests by its bare spelling (`guest_portal`, the form doors\' permission set)', () => {
109+
expect(PLATFORM_REQUESTED_BARE_NAMES).toEqual({ permissions: ['guest_portal'] });
110+
expect(prefixIssues({
111+
manifest: { namespace: 'crm' },
112+
permissions: [{ name: 'guest_portal', objects: {} }],
113+
})).toEqual([]);
114+
// Its twins: the same spelling in ANOTHER collection, and a near-miss in
115+
// the same one, are still bare.
116+
expect(bareIssues({
117+
manifest: { namespace: 'crm' },
118+
flows: [{ name: 'guest_portal' }],
119+
permissions: [{ name: 'guest_portal_plus', objects: {} }],
120+
} as any).map((i) => i.fix).sort()).toEqual(['crm_guest_portal', 'crm_guest_portal_plus']);
121+
});
122+
108123
it('objects — the object prefix is `defineStack`\'s error, not repeated here', () => {
109124
expect(prefixIssues({
110125
manifest: { namespace: 'crm' },

0 commit comments

Comments
 (0)