Skip to content

Commit ffe0516

Browse files
committed
wip(types): pin the review links and guard server packages; changeset (#36895)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzhpykmQZe1yMupC2CU
1 parent 166725c commit ffe0516

7 files changed

Lines changed: 224 additions & 4 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/types': patch
3+
'@objectstack/runtime': patch
4+
'@objectstack/cli': patch
5+
'@object-ui/app-shell': patch
6+
'@object-ui/console': patch
7+
---
8+
9+
refactor(studio): every Studio address comes from one builder; no address changes
10+
11+
Clause-②: no
12+
Metadata-protocol: none
13+
14+
Studio redesign groundwork (#36895, epic #36890). Every place that produced a `/studio...` URL now calls one builder, so a later change can move an item type to its metadata address in one place. Every address is byte-for-byte what it was: no link, bookmark or redirect changes.
15+
16+
- **Console.** `studioAddress.ts` in `@object-ui/app-shell` builds every Studio address: the landing, a package, a pillar, an item (`studioItemPath`), the "All metadata" area, and the draft review links. `studioAddressTable.ts` lists every address family, every `?surface=` spelling and every query parameter, with what each becomes on the metadata address. The retired `/interfaces` redirect keeps exactly the parameters that table marks. New exports from `@object-ui/app-shell`: `STUDIO_ROOT_PATH`, `STUDIO_HOME_PILLAR`, `studioLandingPath`, `studioPackagePath`. Existing exports keep their names and values.
17+
- **Server.** `studioChangesReviewRoute` and `studioItemReviewRoute`, new in `@objectstack/types`, build the review links that `os meta register` prints and that the MCP authoring tools return after a draft save. The text an AI is handed is unchanged.
18+
- **Guards.** A test under `ui/` refuses a hand-built Studio address in any ui source. A test in `@objectstack/types` refuses one in any server package, and holds the review links quoted by the `objectstack-mcp-build` skill's evals equal to what the builder returns.
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36895 — no server package builds a Studio address by hand, and
5+
* the review links the `objectstack-mcp-build` skill's evals quote are the
6+
* ones this package builds.
7+
*
8+
* ── Why ──────────────────────────────────────────────────────────────────────
9+
*
10+
* The Studio redesign (epic #36890) moves Studio's addresses one item type at
11+
* a time. A `/studio/...` string written out in a server package would keep
12+
* the old address after the move, and an AI handed it would send a person to
13+
* the wrong page. `studio-review-routes.ts` is the one place a server spells
14+
* one; the Console's builder (`studioAddress.ts` in the app-shell package)
15+
* is held by the same kind of pin in the ui workspace.
16+
*
17+
* ── What it judges ───────────────────────────────────────────────────────────
18+
*
19+
* 1. Every `.ts` source under `packages/` (tests, declaration files and build
20+
* output excepted), parsed: a string or template literal that starts with
21+
* `/studio` (then its end, `/`, `?` or `#`) is a hand-built address. Prose
22+
* in comments is free.
23+
* 2. The eval file of the published skill (it is governed: it is read, never
24+
* edited here): every Studio address it quotes equals what
25+
* `studioChangesReviewRoute` / `studioItemReviewRoute` return for the
26+
* package, type and name the address names, so the two cannot drift.
27+
*
28+
* ── Controls ─────────────────────────────────────────────────────────────────
29+
*
30+
* The walk must reach the two server producers, the matcher must fire on the
31+
* one allowed file, and the eval file must yield its quoted addresses (seven
32+
* on the commit this landed: five Changes links, two item reviews). Zero in
33+
* any of them means the instrument is broken, not that the tree is clean.
34+
*
35+
* The radius: `packages/**` `.ts` (already this package's declared glob, the
36+
* extension boundary is the one `driver-error-classification.callers.test.ts`
37+
* records) plus the one eval file, declared beside it.
38+
*/
39+
40+
import { describe, expect, it } from 'vitest';
41+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
42+
import { dirname, join, relative, resolve, sep } from 'node:path';
43+
import ts from 'typescript';
44+
import { studioChangesReviewRoute, studioItemReviewRoute } from './studio-review-routes.js';
45+
46+
/**
47+
* This package is CJS-typed, so `import.meta` is not available: walk up from
48+
* the CWD to this package's own manifest (`driver-error-classification.callers.test.ts`
49+
* says why), then reach the repo root by arithmetic.
50+
*/
51+
function findUp(marker: (dir: string) => boolean, what: string): string {
52+
let dir = process.cwd();
53+
for (;;) {
54+
if (marker(dir)) return dir;
55+
const parent = dirname(dir);
56+
if (parent === dir) throw new Error(`could not locate ${what} walking up from ${process.cwd()}`);
57+
dir = parent;
58+
}
59+
}
60+
61+
const PACKAGE_ROOT = findUp((dir) => {
62+
const manifest = join(dir, 'package.json');
63+
if (!existsSync(manifest)) return false;
64+
const { name } = JSON.parse(readFileSync(manifest, 'utf8')) as { name?: string };
65+
return name === '@objectstack/types';
66+
}, 'the @objectstack/types package root');
67+
68+
const REPO_ROOT = resolve(PACKAGE_ROOT, '../..');
69+
70+
const SCANNED_TREE = join(REPO_ROOT, 'packages');
71+
72+
/** The skill eval whose quoted review links must equal the builder's. */
73+
const EVAL_FILE = join(REPO_ROOT, 'skills/objectstack-mcp-build/evals/draft-door-procedure.json');
74+
75+
/** The one server file that spells a Studio address. */
76+
const ALLOWED = 'packages/types/src/studio-review-routes.ts';
77+
78+
const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '.turbo', '.next', '__tests__']);
79+
80+
const SOURCE_FILE = (name: string): boolean =>
81+
name.endsWith('.ts') && !name.endsWith('.d.ts') && !/\.(?:test|spec)\.ts$/.test(name);
82+
83+
const STUDIO_LITERAL = /^\/studio(?:$|[/?#])/;
84+
85+
function sourceFilesUnder(root: string): string[] {
86+
const out: string[] = [];
87+
const walk = (dir: string): void => {
88+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
89+
if (entry.isDirectory()) {
90+
if (!SKIP_DIRS.has(entry.name)) walk(join(dir, entry.name));
91+
continue;
92+
}
93+
if (entry.isFile() && SOURCE_FILE(entry.name)) out.push(join(dir, entry.name));
94+
}
95+
};
96+
walk(root);
97+
return out;
98+
}
99+
100+
function handBuiltStudioAddresses(fileName: string, text: string): string[] {
101+
if (!text.includes('/studio')) return [];
102+
const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
103+
const hits: string[] = [];
104+
const visit = (node: ts.Node): void => {
105+
const literalText =
106+
ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)
107+
? node.text
108+
: ts.isTemplateExpression(node)
109+
? node.head.text
110+
: null;
111+
if (literalText !== null && STUDIO_LITERAL.test(literalText)) {
112+
const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));
113+
hits.push(`${line + 1}: ${node.getText(source).replace(/\s+/g, ' ').slice(0, 120)}`);
114+
}
115+
ts.forEachChild(node, visit);
116+
};
117+
visit(source);
118+
return hits;
119+
}
120+
121+
/** Every Studio address quoted in a text, up to the first quote, space, backtick or paren. */
122+
function quotedStudioAddresses(text: string): string[] {
123+
return [...text.matchAll(/\/studio\/[^\s"'`)]+/g)].map((m) => m[0]);
124+
}
125+
126+
/** What the builder returns for the package, type and name an address names. */
127+
function rebuilt(address: string): string | null {
128+
const changes = /^\/studio\/([^/?#]+)\/data\?changes=review$/.exec(address);
129+
if (changes) return studioChangesReviewRoute(decodeURIComponent(changes[1]));
130+
const item = /^\/studio\/([^/?#]+)\/metadata\/([^/?#]+)\/([^/?#]+)\?review=1$/.exec(address);
131+
if (item) {
132+
return studioItemReviewRoute(decodeURIComponent(item[1]), decodeURIComponent(item[2]), decodeURIComponent(item[3]));
133+
}
134+
return null;
135+
}
136+
137+
describe('no server package builds a Studio address by hand (objectstack#36895)', () => {
138+
it('the matcher sees each spelling and spares prose and look-alikes', () => {
139+
const scan = (text: string) => handBuiltStudioAddresses('x.ts', text);
140+
expect(scan("const a = '/studio';")).toHaveLength(1);
141+
expect(scan('const b = `/studio/${pkg}/data?changes=review`;')).toHaveLength(1);
142+
expect(scan("const c = 'see (/studio/x)';")).toEqual([]);
143+
expect(scan("const d = '/api/v1/studio/runtime-config';")).toEqual([]);
144+
expect(scan('// links to /studio/crm/data\nconst e = 1;')).toEqual([]);
145+
expect(scan("const f = '/studios';")).toEqual([]);
146+
});
147+
148+
it('only the shared module spells one', () => {
149+
const files = sourceFilesUnder(SCANNED_TREE);
150+
const rel = (file: string) => relative(REPO_ROOT, file).split(sep).join('/');
151+
const names = new Set(files.map(rel));
152+
// Controls: the walk reaches both server producers, and the matcher fires
153+
// on the allowed module.
154+
expect(names.has('packages/runtime/src/domains/mcp-authoring.ts')).toBe(true);
155+
expect(names.has('packages/cli/src/commands/meta/register.ts')).toBe(true);
156+
expect(handBuiltStudioAddresses(ALLOWED, readFileSync(join(REPO_ROOT, ALLOWED), 'utf8')).length).toBe(2);
157+
158+
const offenders = files
159+
.filter((file) => rel(file) !== ALLOWED)
160+
.flatMap((file) => handBuiltStudioAddresses(file, readFileSync(file, 'utf8')).map((hit) => `${rel(file)}:${hit}`));
161+
expect(offenders).toEqual([]);
162+
});
163+
164+
it("the skill evals quote the builder's review links, byte for byte", () => {
165+
const quoted = quotedStudioAddresses(readFileSync(EVAL_FILE, 'utf8'));
166+
// Control: the eval file still quotes its review links.
167+
expect(quoted.length).toBeGreaterThanOrEqual(7);
168+
for (const address of quoted) expect(rebuilt(address), address).toBe(address);
169+
});
170+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import { describe, expect, it } from 'vitest';
4+
import { studioChangesReviewRoute, studioItemReviewRoute } from './studio-review-routes.js';
5+
6+
/**
7+
* objectstack#36895 — the server's draft review links, byte for byte as the CLI
8+
* and the MCP authoring tools spelled them before this module existed. The
9+
* Console's `studioChangesReviewPath` / `studioItemReviewPath` are pinned to
10+
* the same literals in the Console's app-shell package (`studioAddress.test.ts`).
11+
*/
12+
describe('the Studio review links a server hands out (objectstack#36895)', () => {
13+
it("a package's Changes drawer on its Studio home", () => {
14+
expect(studioChangesReviewRoute('com.acme.crm')).toBe('/studio/com.acme.crm/data?changes=review');
15+
expect(studioChangesReviewRoute('a b/c')).toBe('/studio/a%20b%2Fc/data?changes=review');
16+
});
17+
18+
it("an item's draft review in the All metadata area", () => {
19+
expect(studioItemReviewRoute('com.acme.crm', 'flow', 'crm_lead_created_notify')).toBe(
20+
'/studio/com.acme.crm/metadata/flow/crm_lead_created_notify?review=1',
21+
);
22+
expect(studioItemReviewRoute('p q', 'object', 'a/b')).toBe('/studio/p%20q/metadata/object/a%2Fb?review=1');
23+
});
24+
});

‎packages/types/src/studio-review-routes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* shared spelling lives here.
99
*
1010
* The Console builds the same two addresses with `studioChangesReviewPath`
11-
* and `studioItemReviewPath` (`ui/packages/app-shell`, `studioAddress.ts`),
11+
* and `studioItemReviewPath` (`studioAddress.ts` in the Console's app-shell package),
1212
* which does not depend on this package; both sides are pinned to the same
1313
* literals, and to the literals the `objectstack-mcp-build` skill's evals
1414
* quote (`studio-review-routes.test.ts`).
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[
2-
"src/driver-error-classification.callers.test.ts"
2+
"src/driver-error-classification.callers.test.ts",
3+
"src/studio-review-routes.callers.test.ts"
34
]

‎scripts/cross-package-test-inputs.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,13 @@ export const CROSS_PACKAGE_TEST_INPUTS = {
405405
// to a workspace-root marker file, so it names no root-level path and this
406406
// entry adds no new top-level root for `check-ci-filter-parity.mjs` to want
407407
// in ci.yml's `crosspkg:` filter. Its own header records that trade.
408-
globs: ['packages/**/*.ts'],
408+
//
409+
// src/studio-review-routes.callers.test.ts (#36895) walks the same `.ts`
410+
// population for hand-built Studio addresses, and reads the one skill eval
411+
// that quotes the server's draft review links, to hold each quoted link
412+
// equal to what this package builds. That file sits under the published
413+
// skills root, which ci.yml's `crosspkg:` filter already covers whole.
414+
globs: ['packages/**/*.ts', 'skills/objectstack-mcp-build/evals/draft-door-procedure.json'],
409415
},
410416
'@objectstack/organizations': {
411417
// src/no-framework-dependents.pin.test.ts is ADR-0132 D3's mechanical half.

‎turbo.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@
829829
"!coverage/**",
830830
"!.turbo/**",
831831
"!**/node_modules/**",
832-
"$TURBO_ROOT$/packages/**/*.ts"
832+
"$TURBO_ROOT$/packages/**/*.ts",
833+
"$TURBO_ROOT$/skills/objectstack-mcp-build/evals/draft-door-procedure.json"
833834
]
834835
},
835836
"@objectstack/runtime#test:repo": {

0 commit comments

Comments
 (0)