Skip to content

Commit 79774af

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-7l0dag
2 parents c62af5d + 14208f2 commit 79774af

14 files changed

Lines changed: 586 additions & 37 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): `list_actions` no longer offers `revoke_api_key` as runnable to a caller signed in with an API key. The action is marked `unavailable` with the API-key management guard's own `PERMISSION_DENIED` and sentence, the refusal `run_action` gives (#28943)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The forward's credential marker (`apiForwardCredentialRefusal`) only asked whether the target's door reads the caller's credential. The data door reads an API key, so `sys_api_key`'s Revoke was listed as runnable to an `osk_` caller. The row's per-object gate (`@objectstack/core` `apiKeyManagementCredentialRefusal`) then refused the write with `403 PERMISSION_DENIED`. The marker now also asks that guard about the data-door request a forward makes (the object, and the operation its method and path name). The guard is the one source: the listing's `unavailable` entry carries the guard's code and sentence, and the REST action door and MCP `run_action` answer that same refusal before forwarding instead of after. The guard's refusal is unchanged, and so are reads of `sys_api_key`, every other object, and the session caller's listing and run.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'create-objectstack': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
fix(scaffold): a scaffolded namespace is at most 13 characters, so a fresh project from a long name validates with no `namespace-no-customization-pair` warning (#28992)
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
`npx create-objectstack` and `os init` derive `manifest.namespace` from the project name. They truncated it at 20 characters, the manifest grammar's limit, while a namespace longer than 13 has no paired customization namespace (ADR-0146 D3). So `qa-console-first-paint` scaffolded the namespace `qa_console_first_pai`, and the project's first `os validate` warned about it and about the object names it prefixes, none of which the author wrote.
12+
13+
Both scaffolders now cap the namespace at `MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH` (13): `qa-console-first-paint` gets `qa_console_fi`, and every object name and file the scaffold derives from the namespace follows it. A truncated namespace never ends in `_`. `os init` reads the constant from `@objectstack/spec/kernel`; `create-objectstack`, which does not depend on the spec at runtime, keeps its own copy, pinned equal to the spec constant by a test. Project names whose namespace already fit are scaffolded exactly as before.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
fix(core): a row action's `${ctx.recordId}` and `${ctx.record.*}` target holes read the row it was opened on
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A `type: 'url'` action shown in a list view's row menu (`locations: ['list_item']`) interpolated `${ctx.recordId}` and `${ctx.record.*}` to empty, so a target such as `/apps/APP/OBJECT/record/${ctx.recordId}/page/PAGE` opened `/apps/APP/OBJECT/record/page/PAGE`. The same action in the record header worked. The row menu dispatches the clicked row under `params._rowRecord` through the page's action runner, and the runner built the `ctx` scope from its own context, which on a list page names no record.
11+
12+
Now a dispatch that carries a row binds `ctx.record` to that row and `ctx.recordId` to its `id` for target interpolation: `type: 'url'` targets, `type: 'api'` targets and the `onSuccess.navigate` hop. The row wins over a page-level record, so a related-list row on a record page reads the child row. This is the rule the runner already applied to a row action's copy templates. `${ctx.selection.ids}` and `${ctx.selection.count}` are unchanged: they stay the grid's checked selection, which opening a row menu does not change.

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { Args, Command, Flags } from '@oclif/core';
4-
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
4+
import { MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH, PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
55
import chalk from 'chalk';
66
import fs from 'fs';
77
import path from 'path';
@@ -67,18 +67,26 @@ function pkgVersion(): string {
6767
*
6868
* npm names allow hyphens/dots/scopes (e.g. `@acme/my-app`); identifiers don't.
6969
* We strip the scope, replace separators with `_`, lowercase, prefix a leading
70-
* digit, truncate to 20, and pad short names so the result always satisfies
71-
* the regex. Reserved names get a `_app` suffix.
70+
* digit, truncate, and pad short names so the result always satisfies the
71+
* regex. Reserved names get a `_app` suffix.
72+
*
73+
* The cap is `MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH` (13), not the grammar's
74+
* 20: a longer namespace has no paired customization namespace (ADR-0146 D3),
75+
* so `os validate` on the fresh project would warn
76+
* `namespace-no-customization-pair` about objects its author never wrote.
77+
* `create-objectstack`'s `sanitizeNamespace()` restates the same rule, pinned
78+
* to the same constant, so both scaffolders agree.
7279
*/
7380
export function sanitizeNamespace(name: string): string {
81+
const max = MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH;
7482
let s = name.replace(/^@[^/]+\//, ''); // drop npm scope
7583
s = s.toLowerCase().replace(/[^a-z0-9]+/g, '_'); // separators → _
7684
s = s.replace(/^_+|_+$/g, ''); // trim underscores
7785
if (!s) s = 'app';
7886
if (/^[0-9]/.test(s)) s = 'a' + s; // must start with a letter
79-
if (s.length < 2) s = (s + '_app').slice(0, 20);
80-
if (s.length > 20) s = s.slice(0, 20).replace(/_+$/, '');
81-
if (['base', 'system', 'sys'].includes(s)) s = (s + '_app').slice(0, 20);
87+
if (s.length < 2) s = (s + '_app').slice(0, max);
88+
if (s.length > max) s = s.slice(0, max).replace(/_+$/, '');
89+
if (['base', 'system', 'sys'].includes(s)) s = (s + '_app').slice(0, max);
8290
return s;
8391
}
8492

‎packages/cli/test/init.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { describe, it, expect } from 'vitest';
4-
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
4+
import { PROTOCOL_MAJOR, customizationNamespace } from '@objectstack/spec/kernel';
55
import fs from 'fs';
66
import os from 'os';
77
import path from 'path';
@@ -404,6 +404,26 @@ describe('sanitizeNamespace', () => {
404404
expect(sanitizeNamespace(input)).toMatch(NS_RE);
405405
}
406406
});
407+
408+
// A namespace too long for a paired customization namespace (ADR-0146 D3)
409+
// makes `os validate` warn `namespace-no-customization-pair` on the fresh
410+
// scaffold, about objects its author never wrote.
411+
it.each([
412+
['qa-console-first-paint', 'qa_console_fi'],
413+
['abcdefghijkl-mnop', 'abcdefghijkl'], // the 13th character is `_`: dropped
414+
['@acme/very-long-project-name', 'very_long_pro'],
415+
['1234567890123456', 'a123456789012'],
416+
['abcdefghijklm', 'abcdefghijklm'],
417+
])('caps %s at the customization-pair limit → %s', (input, expected) => {
418+
expect(sanitizeNamespace(input)).toBe(expected);
419+
});
420+
421+
it('always produces a namespace that has a customization pair', () => {
422+
for (const input of ['my-app', '123app', 'sys', 'a', '', 'qa-console-first-paint', 'really-long-name-truncated-here', 'abcdefghijkl-mnop']) {
423+
const ns = sanitizeNamespace(input);
424+
expect(customizationNamespace(ns), ns).toEqual({ ok: true, value: `${ns}_custom` });
425+
}
426+
});
407427
});
408428

409429
describe('scaffold rendering — round-trip', () => {

‎packages/create-objectstack/src/index.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { syncObjectStackDeps } from './pkg-utils.js';
7474
import { copyDir } from './template-copy.js';
7575
import {
7676
deriveManifestId,
77+
sanitizeNamespace,
7778
readTemplateNamespace,
7879
rewriteObjectNamePrefix,
7980
findStaleNamespacePrefixes,
@@ -107,23 +108,6 @@ function toTitleCase(str: string): string {
107108
return str.replace(/[-_]/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
108109
}
109110

110-
/**
111-
* Convert an npm package name into a valid ObjectStack namespace identifier
112-
* (regex `^[a-z][a-z0-9_]{1,19}$`, reserved: base/system/sys). Mirrors the
113-
* implementation in `@objectstack/cli` so both scaffolders agree.
114-
*/
115-
export function sanitizeNamespace(name: string): string {
116-
let s = name.replace(/^@[^/]+\//, '');
117-
s = s.toLowerCase().replace(/[^a-z0-9]+/g, '_');
118-
s = s.replace(/^_+|_+$/g, '');
119-
if (!s) s = 'app';
120-
if (/^[0-9]/.test(s)) s = 'a' + s;
121-
if (s.length < 2) s = (s + '_app').slice(0, 20);
122-
if (s.length > 20) s = s.slice(0, 20).replace(/_+$/, '');
123-
if (['base', 'system', 'sys'].includes(s)) s = (s + '_app').slice(0, 20);
124-
return s;
125-
}
126-
127111
function readCliVersion(): string {
128112
try {
129113
const pkgPath = path.resolve(__dirname, '..', 'package.json');

‎packages/create-objectstack/src/rewrite-identity.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,43 @@ export function deriveManifestId(projectName: string): string {
116116
return `${SCAFFOLD_ID_PREFIX}${s}`;
117117
}
118118

119+
/**
120+
* The longest namespace a scaffold emits: the longest base namespace that
121+
* still has a paired customization namespace (`<namespace>_custom`, ADR-0146
122+
* D3). A longer one passes the manifest grammar (20 characters) but has no
123+
* pair, so `os validate` on the fresh project warns
124+
* `namespace-no-customization-pair` about objects its author never wrote.
125+
*
126+
* It is `MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH` from
127+
* `@objectstack/spec/kernel`, restated because this package cannot import it:
128+
* the spec is a devDependency here, so a value import would be bundled into
129+
* the published scaffolder (`check:undeclared-dep-imports`), and making it a
130+
* runtime dependency would put zod into a two-dependency `npx` entry point.
131+
* `scaffold-namespace-cap.test.ts` pins the two equal, so they cannot drift.
132+
*/
133+
export const SCAFFOLD_NAMESPACE_MAX_LENGTH = 13;
134+
135+
/**
136+
* Convert an npm package name into a valid ObjectStack namespace identifier
137+
* (regex `^[a-z][a-z0-9_]{1,19}$`, reserved: base/system/sys) that is at most
138+
* {@link SCAFFOLD_NAMESPACE_MAX_LENGTH} characters, so it has a paired
139+
* customization namespace. A longer name is truncated, with no trailing `_`.
140+
* Mirrors `sanitizeNamespace()` in `@objectstack/cli`'s `init` command, so
141+
* both scaffolders agree.
142+
*/
143+
export function sanitizeNamespace(name: string): string {
144+
const max = SCAFFOLD_NAMESPACE_MAX_LENGTH;
145+
let s = name.replace(/^@[^/]+\//, '');
146+
s = s.toLowerCase().replace(/[^a-z0-9]+/g, '_');
147+
s = s.replace(/^_+|_+$/g, '');
148+
if (!s) s = 'app';
149+
if (/^[0-9]/.test(s)) s = 'a' + s;
150+
if (s.length < 2) s = (s + '_app').slice(0, max);
151+
if (s.length > max) s = s.slice(0, max).replace(/_+$/, '');
152+
if (['base', 'system', 'sys'].includes(s)) s = (s + '_app').slice(0, max);
153+
return s;
154+
}
155+
119156
/** Every `*.ts` file under `dir`, recursively. Missing dir → empty. */
120157
function tsFiles(dir: string, out: string[] = []): string[] {
121158
if (!fs.existsSync(dir)) return out;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license.
2+
//
3+
// `sanitizeNamespace()` emits a namespace that has a paired customization
4+
// namespace (ADR-0146 D3), judged by the spec's own `customizationNamespace`,
5+
// and its cap is pinned equal to the spec constant it restates.
6+
7+
import { describe, it, expect } from 'vitest';
8+
import {
9+
MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH,
10+
ManifestSchema,
11+
customizationNamespace,
12+
} from '@objectstack/spec/kernel';
13+
import { SCAFFOLD_NAMESPACE_MAX_LENGTH, sanitizeNamespace } from './rewrite-identity.js';
14+
15+
/** Names a scaffolder is handed: short, exact-fit, long, scoped, odd. */
16+
const NAMES = [
17+
'', 'x', 'a', '1', 'my-app', 'crm', 'base', 'system', 'sys', 'Base', '@acme/sys',
18+
'abcdefghijklm', 'abcdefghijklmn', 'qa-console-first-paint', 'abcdefghijkl-mnop',
19+
'abcdefghijk--lmnop', '1234567890123456', '9-lives', '@acme/very-long-project-name',
20+
'My Cool App!!', '__leading', 'trailing__', 'a.b.c.d.e.f.g.h.i', 'ünïcödé-name',
21+
'abcdefghijklmnopqrstuvwxyz', 'twelve-chars', 'thirteen-char',
22+
];
23+
24+
describe('the scaffold namespace cap', () => {
25+
it('is the spec constant it restates', () => {
26+
expect(SCAFFOLD_NAMESPACE_MAX_LENGTH).toBe(MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH);
27+
});
28+
29+
it.each(NAMES)('%j sanitizes to a namespace the manifest accepts and that has a customization pair', (name) => {
30+
const ns = sanitizeNamespace(name);
31+
expect(ManifestSchema.shape.namespace.safeParse(ns).success, ns).toBe(true);
32+
expect(['base', 'system', 'sys']).not.toContain(ns);
33+
expect(customizationNamespace(ns), ns).toEqual({ ok: true, value: `${ns}_custom` });
34+
});
35+
});
36+
37+
describe('sanitizeNamespace', () => {
38+
it.each([
39+
['qa-console-first-paint', 'qa_console_fi'],
40+
// The 13th character is `_`: dropped, never left trailing.
41+
['abcdefghijkl-mnop', 'abcdefghijkl'],
42+
['@acme/very-long-project-name', 'very_long_pro'],
43+
['1234567890123456', 'a123456789012'],
44+
['abcdefghijklmn', 'abcdefghijklm'],
45+
])('truncates %j to %j', (name, expected) => {
46+
expect(sanitizeNamespace(name)).toBe(expected);
47+
});
48+
49+
// Names that already fit are scaffolded exactly as before.
50+
it.each([
51+
['my-app', 'my_app'],
52+
['crm', 'crm'],
53+
['abcdefghijklm', 'abcdefghijklm'],
54+
['thirteen-char', 'thirteen_char'],
55+
['', 'app'],
56+
['x', 'x_app'],
57+
['9-lives', 'a9_lives'],
58+
['sys', 'sys_app'],
59+
['system', 'system_app'],
60+
['@acme/my-app', 'my_app'],
61+
])('keeps %j as %j', (name, expected) => {
62+
expect(sanitizeNamespace(name)).toBe(expected);
63+
});
64+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license.
2+
//
3+
// A scaffold's namespace has a paired customization namespace, so the first
4+
// `os validate` on a fresh project prints no `namespace-no-customization-pair`
5+
// warning about objects its author never wrote.
6+
//
7+
// The rule (ADR-0146 D3, `@objectstack/lint`'s `validateCustomizationNamespace`)
8+
// warns when `customizationNamespace(manifest.namespace)` answers
9+
// `base_namespace_too_long`. The verdict here is that same helper's, read from
10+
// the spec, so the scaffold is judged by the function the ensure door creates
11+
// the pair with, never by a number restated in this file.
12+
//
13+
// Drives the real CLI end to end via `tsx`: index.ts calls `program.parse()` on
14+
// import (the pattern of scaffold-namespace-extends-template.test.ts).
15+
16+
import { describe, it, expect, afterEach } from 'vitest';
17+
import { spawnSync } from 'node:child_process';
18+
import fs from 'node:fs';
19+
import os from 'node:os';
20+
import path from 'node:path';
21+
import { fileURLToPath } from 'node:url';
22+
import { customizationNamespace, validateObjectNamespacePrefix } from '@objectstack/spec/kernel';
23+
import { readTemplateNamespace } from './rewrite-identity.js';
24+
25+
const HERE = path.dirname(fileURLToPath(import.meta.url));
26+
const PKG_ROOT = path.resolve(HERE, '..');
27+
const REPO_ROOT = path.resolve(PKG_ROOT, '..', '..');
28+
const TSX = path.join(REPO_ROOT, 'node_modules', '.bin', 'tsx');
29+
const INDEX_TS = path.join(PKG_ROOT, 'src', 'index.ts');
30+
31+
/** Every `name: '…'` literal in the `*.ts` files under `dir`. */
32+
function nameLiterals(dir: string): string[] {
33+
const names: string[] = [];
34+
for (const rel of fs.readdirSync(dir, { recursive: true, encoding: 'utf8' })) {
35+
if (!rel.endsWith('.ts')) continue;
36+
const text = fs.readFileSync(path.join(dir, rel), 'utf8');
37+
for (const m of text.matchAll(/\bname:\s*(['"`])([a-z0-9_]+)\1/g)) names.push(m[2]);
38+
}
39+
return names.sort();
40+
}
41+
42+
let tmp: string | undefined;
43+
afterEach(() => {
44+
if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
45+
tmp = undefined;
46+
});
47+
48+
describe('a scaffold from a long project name', () => {
49+
it('`qa-console-first-paint` gets a namespace with a customization pair, and every object follows it', () => {
50+
const project = 'qa-console-first-paint';
51+
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'create-objectstack-ns-pair-'));
52+
const run = spawnSync(TSX, [INDEX_TS, project, '--skip-install', '--skip-skills'], {
53+
cwd: tmp,
54+
encoding: 'utf8',
55+
});
56+
expect(run.status, `${run.stdout}\n${run.stderr}`).toBe(0);
57+
58+
const projectDir = path.join(tmp, project);
59+
const namespace = readTemplateNamespace(projectDir);
60+
expect(namespace).toBe('qa_console_fi');
61+
expect(customizationNamespace(namespace)).toEqual({ ok: true, value: 'qa_console_fi_custom' });
62+
63+
// The config's `namespace:` literal is the same value the manifest carries.
64+
const config = fs.readFileSync(path.join(projectDir, 'objectstack.config.ts'), 'utf8');
65+
expect(/\bnamespace:\s*'([^']+)'/.exec(config)?.[1]).toBe(namespace);
66+
67+
// Every object the scaffold ships sits under the shortened namespace.
68+
const objects = nameLiterals(path.join(projectDir, 'src')).filter((n) => /_/.test(n));
69+
expect(objects.length).toBeGreaterThan(0);
70+
for (const name of objects.filter((n) => n.startsWith('qa_'))) {
71+
expect(validateObjectNamespacePrefix(name, namespace as string), name).toBeNull();
72+
}
73+
expect(objects.some((n) => n.startsWith(`${namespace}_`))).toBe(true);
74+
}, 30_000);
75+
});

0 commit comments

Comments
 (0)