From 282cb9e97b07205f6e895a92220812587119440d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 02:52:20 +0000 Subject: [PATCH 1/2] feat(spec): a package-id segment may open with a digit; the refusal states the rule MANIFEST_ID_PATTERN widens to admit a digit-led segment (com.163.crm, com.example.2app); a segment still may not open with a hyphen and underscores stay refused. manifestIdRefusal and the id TSDoc now state the rule the pattern enforces. Consumer pins that asserted a digit-led segment is refused flip to accepted rows (metadata-protocol, cloud-connection, cli publish), and texts quoting the old rule or the old sentence follow (migration entry, cli docs, pending changesets). Claude-Session: https://claude.ai/code/session_01QcAS3qiYYZNezaxZxaUdMV Co-authored-by: Claude --- .../19417-install-door-parses-manifest-id.md | 6 +- ...ol-install-primitive-parses-manifest-id.md | 5 +- .changeset/19576-install-local-id-gate.md | 6 +- .../19870-manifest-id-digit-led-segment.md | 19 ++++ content/docs/deployment/cli.mdx | 30 +++--- packages/cli/src/commands/package/publish.ts | 15 +-- .../test/package-publish-manifest-id.test.ts | 53 +++++++---- .../marketplace-install-local-id-gate.test.ts | 6 +- .../src/protocol.install-manifest-id.test.ts | 10 +- packages/spec/src/kernel/manifest.test.ts | 95 ++++++++++++++----- packages/spec/src/kernel/manifest.zod.ts | 28 ++++-- .../18.manifest-id-reverse-domain-required.ts | 6 +- 12 files changed, 192 insertions(+), 87 deletions(-) create mode 100644 .changeset/19870-manifest-id-digit-led-segment.md diff --git a/.changeset/19417-install-door-parses-manifest-id.md b/.changeset/19417-install-door-parses-manifest-id.md index c4b1c6c4390..cb17648bfbb 100644 --- a/.changeset/19417-install-door-parses-manifest-id.md +++ b/.changeset/19417-install-door-parses-manifest-id.md @@ -34,9 +34,9 @@ verifies its candidate against the pattern before offering it. Posting ```text Invalid package id 'pkg-a' on `manifest.id`. Expected reverse-domain notation -('com.steedos.crm', 'org.apache.superset') — lowercase dot-separated segments; -hyphens allowed inside a segment, underscores are not. Did you mean -'com.example.pkg-a'? +('com.steedos.crm', 'org.apache.superset') — lowercase dot-separated segments +of letters, digits and inner hyphens; a segment may not open with a hyphen; +underscores are not admitted. Did you mean 'com.example.pkg-a'? ``` **What is not affected.** Boot-time and in-process installs reach diff --git a/.changeset/19417-protocol-install-primitive-parses-manifest-id.md b/.changeset/19417-protocol-install-primitive-parses-manifest-id.md index 26f4f5c6726..a84a714d7d2 100644 --- a/.changeset/19417-protocol-install-primitive-parses-manifest-id.md +++ b/.changeset/19417-protocol-install-primitive-parses-manifest-id.md @@ -42,8 +42,9 @@ offering it. Installing `id: 'com.example.my_erp'` now throws, with: ```text Invalid package id 'com.example.my_erp' on `manifest.id`. Expected reverse-domain notation ('com.steedos.crm', 'org.apache.superset') — lowercase -dot-separated segments; hyphens allowed inside a segment, underscores are not. -Did you mean 'com.example.my-erp'? +dot-separated segments of letters, digits and inner hyphens; a segment may not +open with a hyphen; underscores are not admitted. Did you mean +'com.example.my-erp'? ``` **The duplicate door refuses BEFORE it mints anything.** `duplicatePackage` diff --git a/.changeset/19576-install-local-id-gate.md b/.changeset/19576-install-local-id-gate.md index 90b8ec0db3a..df6719782d3 100644 --- a/.changeset/19576-install-local-id-gate.md +++ b/.changeset/19576-install-local-id-gate.md @@ -31,9 +31,9 @@ now answers, in `error.message`: ```text Invalid package id 'late-app' on `manifest.id`. Expected reverse-domain notation -('com.steedos.crm', 'org.apache.superset') — lowercase dot-separated segments; -hyphens allowed inside a segment, underscores are not. Did you mean -'com.example.late-app'? +('com.steedos.crm', 'org.apache.superset') — lowercase dot-separated segments +of letters, digits and inner hyphens; a segment may not open with a hyphen; +underscores are not admitted. Did you mean 'com.example.late-app'? ``` **`manifest.name` is no longer read as an id.** `ManifestSchema` declares `id`; diff --git a/.changeset/19870-manifest-id-digit-led-segment.md b/.changeset/19870-manifest-id-digit-led-segment.md new file mode 100644 index 00000000000..3b18c2dc7ed --- /dev/null +++ b/.changeset/19870-manifest-id-digit-led-segment.md @@ -0,0 +1,19 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec): a package-id segment may open with a digit, and the refusal states the rule the pattern enforces (#19870) + +Clause-②: yes (widening) — the accept set of `ManifestSchema.id` and `PackageSchema.manifestId` (one shared constant, `MANIFEST_ID_PATTERN`) grows by the ids that carry a digit-led segment. Nothing previously admitted is refused, no key is added, removed or renamed, and no export moves. + +**The rule, as the pattern now enforces it:** two or more lowercase dot-separated segments of letters, digits and inner hyphens. A segment may open with a letter or a digit — never with a hyphen — and underscores are not admitted. `com.163.crm`, `com.example.2app` and `local.2024-app` are package ids now; `com.example.-app`, `com.example.my_app` and `Com.Example.App` stay refused. + +**Why the leading-letter clause went.** The package id is a registry key (`manifest_id`), a runtime package-map key and a grant-source key — never a table name, a JS identifier, a filesystem path or a hostname — and a DNS label may itself open with a digit. The clause had no downstream reason, so the refusal sentence could not state one: an author who followed the sentence could write `com.example.2app`, satisfy every clause it listed, and still be refused. + +**The refusal sentence** is now `… Expected reverse-domain notation ('com.steedos.crm', 'org.apache.superset') — lowercase dot-separated segments of letters, digits and inner hyphens; a segment may not open with a hyphen; underscores are not admitted.` It was `… — lowercase dot-separated segments; hyphens allowed inside a segment, underscores are not.` The doors that surface it verbatim (`POST /api/v1/packages`, the protocol install and duplicate primitives, `POST /api/v1/marketplace/install-local`, `os package publish`) follow it with no change of their own. A digit-led bare word now gets the prefixed repair (`2fa` → `Did you mean 'com.example.2fa'?`), where it used to get none. + +**What moves with it.** `os package publish` derives `local.` from `manifest.name` or the artifact filename when no id is declared; a slug is lowercase letters, digits and inner hyphens, so a derived id now always parses — a manifest named `2024 App` publishes as `local.2024-app` instead of being refused. A declared `manifest.id` is still used or refused, never replaced by a derived one. + +**What does not move.** `manifest.namespace` — the physical object-name prefix (`crm` → `crm_account`) — keeps its own leading-letter rule, for the SQL-identifier reason. A namespace derived from a package id still strips a leading digit run from its last segment (`com.163.crm` → `crm`; `com.example.123` derives none, and the author declares `namespace`). + +**If you relied on the refusal:** nothing you stored changes. A consumer that assumed a package id opens each segment with a letter should stop assuming it; parse it through `PackageSchema.shape.manifestId` or `ManifestSchema.shape.id` rather than a copy of the pattern. diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index e91a6bc46b8..d1a971d0fdb 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -1900,7 +1900,7 @@ when both files' `url`s agree. | `artifact` (positional) | — | Path to the compiled artifact (default `dist/objectstack.json`) | | `-s, --server ` | `OS_CLOUD_URL` | Control-plane URL. Default `https://cloud.objectos.ai`, or the URL recorded by `os cloud login` | | `-t, --token ` | `OS_CLOUD_API_KEY` | Bearer token; `$OS_TOKEN` and `~/.objectstack/cloud.json` are the fallbacks | -| `--manifest-id ` | `OS_PACKAGE_MANIFEST_ID` | Reverse-domain package id. Default: `artifact.manifest.id`, else `local.` + a slug of `manifest.name`, else `local.` + a slug of the artifact filename. A derived default is **not guaranteed usable** — see below | +| `--manifest-id ` | `OS_PACKAGE_MANIFEST_ID` | Reverse-domain package id. Default: `artifact.manifest.id`, else `local.` + a slug of `manifest.name`, else `local.` + a slug of the artifact filename. A declared `manifest.id` is used or refused, never replaced by a derived one — see below | | `-v, --version ` | — | Version to publish. Default: `artifact.manifest.version`, else `0.0.0-dev.` + a timestamp | | `--display-name ` | — | Name shown in the Marketplace (default `artifact.manifest.name`) | | `--description ` | — | Short package description | @@ -1922,19 +1922,21 @@ when both files' `url`s agree. | `-n, --note ` | — | Release notes | | `--timeout ` | `OS_CLOUD_TIMEOUT_MS` | HTTP timeout in milliseconds, default `120000`. `0` disables it | -**The derived `local.` id is a candidate, not a guaranteed default.** A derived -id is held to exactly the rule an explicit one is — `PackageSchema.manifestId`, -the schema for the very column publish writes — and slugifying has no -letter-first rule, so a manifest named `2024 App` derives `local.2024-app`, -which that schema rejects. `os package publish` then **refuses before any -network call**, quoting the schema and naming which of the three sources above -the id came from, rather than normalising it into a different permanent -identifier or forwarding one the control plane would reject: `manifest_id` is -immutable once published, so an id nobody wrote cannot be renamed afterwards. -The remedy is the one the refusal prints for that source — pass -`--manifest-id`, set `manifestId` in `objectstack.manifest.json`, or declare -`manifest.id` in `objectstack.config.ts` and rebuild. A declared -`manifest.id` is used or refused, never silently replaced by a derived one. +**Every id is held to one rule, whichever source it came from.** An explicit, +declared or derived id is parsed against `PackageSchema.manifestId` — the schema +for the very column publish writes: lowercase dot-separated segments of letters, +digits and inner hyphens, a segment never opening with a hyphen, no +underscores. A slug is lowercase letters, digits and inner hyphens, so a +derived `local.` id always satisfies it — a manifest named `2024 App` derives +`local.2024-app` — and it is published exactly as derived, never normalised +into a different identifier: `manifest_id` is immutable once published, so an +id nobody wrote cannot be renamed afterwards. A declared `manifest.id` is used +or refused, never silently replaced by a derived one: an id that fails the rule +is **refused before any network call**, quoting the schema and naming which of +the three sources above the id came from. The remedy is the one the refusal +prints for that source — pass `--manifest-id`, set `manifestId` in +`objectstack.manifest.json`, or fix `manifest.id` in `objectstack.config.ts` +and rebuild. **`objectstack.manifest.json` supplies the listing fields.** When that file is present in the working directory, publish reads `manifestId`, `displayName`, diff --git a/packages/cli/src/commands/package/publish.ts b/packages/cli/src/commands/package/publish.ts index 1ee543724d7..108707de077 100644 --- a/packages/cli/src/commands/package/publish.ts +++ b/packages/cli/src/commands/package/publish.ts @@ -41,8 +41,8 @@ import { readErrorMessage } from '../../utils/response-envelope.js'; * The one rule for a manifest id is `PackageSchema.manifestId` — the schema for * the very column this command publishes into (`sys_package.manifest_id`). * Imported, never transcribed: a second, hand-copied rule here is what let this - * preflight admit six shapes the control plane refuses (`com.acme.repair_desk`, - * `COM.ACME.CRM`, `9foo.bar`, `com..acme`, `com.acme.` and — on the explicit + * preflight admit shapes the control plane refuses (`com.acme.repair_desk`, + * `COM.ACME.CRM`, `com..acme`, `com.acme.` and — on the explicit * `--manifest-id` path — a bare `crm`), while telling the user the contract was * `a-z0-9._-`. `CreatePackageRequestSchema` in `cloud/package.zod.ts` reaches * for the same declaration the same way. @@ -144,11 +144,12 @@ export interface DerivedManifestId { * * ## Steps 2 and 3 are the CLI's own invention * - * They are **not** guaranteed valid: `slugify` has no letter-first rule, so a - * manifest named `2024 App` derives `local.2024-app`, which the schema rejects. - * That is refused at the same gate with the source named, rather than - * normalised — minting a different permanent identifier than the inputs imply - * is worse than saying what is wrong. + * `slugify` emits lowercase letters, digits and inner hyphens and never opens + * with a hyphen — one legal segment under the declaration, which lets a segment + * open with a digit — so a manifest named `2024 App` derives `local.2024-app` + * and it parses. The derived id still passes through the same gate as every + * other source, and it is never normalised: minting a different permanent + * identifier than the inputs imply is worse than saying what is wrong. */ export function deriveManifestId(artifact: any, artifactPath: string): DerivedManifestId { const explicit = artifact?.manifest?.id; diff --git a/packages/cli/test/package-publish-manifest-id.test.ts b/packages/cli/test/package-publish-manifest-id.test.ts index 2eb353ebf49..631d00d9b26 100644 --- a/packages/cli/test/package-publish-manifest-id.test.ts +++ b/packages/cli/test/package-publish-manifest-id.test.ts @@ -21,7 +21,7 @@ * -> tested against the local rule AND `explicit.includes('.')`. * * That extra dot condition is why a bare `crm` was already blocked on the - * derive path while the explicit path let it through: five of the six shapes + * derive path while the explicit path let it through: four of the five shapes * below held on both paths, `crm` on only one. After the fix both paths ask the * same schema, and the dot condition is gone because the schema subsumes it * (its pattern needs at least two segments). @@ -70,15 +70,19 @@ const PUBLISH_SRC = resolve(HERE, '../src/commands/package/publish.ts'); const MANIFEST_ID = PackageSchema.shape.manifestId; /** - * The six shapes the retired local rule admitted, with the pre-fix reading of - * WHICH path admitted each — triage's correction to the card, kept here because - * it is the reason every case below is asserted per path rather than once. + * The shapes the retired local rule admitted and the declaration refuses, with + * the pre-fix reading of WHICH path admitted each — triage's correction to the + * card, kept here because it is the reason every case below is asserted per + * path rather than once. + * + * `9foo.bar` (a digit-first segment) was a sixth row until the declaration let a + * segment open with a digit; the two now agree that it is an id, so it sits + * with the accepted cases below. */ const RELAXATIONS: ReadonlyArray<{ id: string; why: string; admittedOnDerivePathBefore: boolean }> = [ { id: 'crm', why: 'single segment', admittedOnDerivePathBefore: false }, { id: 'com.acme.repair_desk', why: 'underscore', admittedOnDerivePathBefore: true }, { id: 'COM.ACME.CRM', why: 'upper case', admittedOnDerivePathBefore: true }, - { id: '9foo.bar', why: 'digit-first segment', admittedOnDerivePathBefore: true }, { id: 'com..acme', why: 'empty segment', admittedOnDerivePathBefore: true }, { id: 'com.acme.', why: 'trailing dot', admittedOnDerivePathBefore: true }, ]; @@ -166,6 +170,9 @@ describe('os package publish — the manifest-id rule is the spec manifest-id ru ['local.acme-crm', true], ['a.b', true], ['com.acme.crm-2', true], + ['9foo.bar', true], + ['com.163.crm', true], + ['local.2024-app', true], ...RELAXATIONS.map(({ id }) => [id, false] as const), ['', false], ['com.acme.crm ', false], @@ -319,32 +326,44 @@ describe('os package publish — the manifest-id rule is the spec manifest-id ru }); // ------------------------------------------------------------------------- - // The producer half — the CLI also MAKES ids, and slugify has no - // letter-first rule (the filer's addendum). + // The producer half — the CLI also MAKES ids. `slugify` emits lowercase + // letters, digits and inner hyphens and never opens with a hyphen: exactly + // one legal segment, now that a segment may open with a digit. So a derived + // `local.` id parses, and it is published AS DERIVED. // ------------------------------------------------------------------------- - describe('a derived id the schema rejects is refused, not published and not rewritten', () => { - it("refuses the digit-first id derived from a manifest named '2024 App'", async () => { + describe('a derived id is published as derived, never rewritten', () => { + it("publishes the digit-first id derived from a manifest named '2024 App'", async () => { + // Refused while every segment had to open with a letter; the same bytes + // now reach the wire unchanged. const derived = deriveManifestId({ manifest: { name: '2024 App' } }, '/nowhere/objectstack.json'); expect(derived).toEqual({ id: 'local.2024-app', source: 'artifact-manifest-name' }); - expect(isManifestId(derived.id)).toBe(false); + expect(isManifestId(derived.id)).toBe(true); const path = await artifactAt({ name: '2024 App', version: '1.2.0' }); const calls = stubCloud(); const { exitCode, output } = await runPublish([path]); - expect(exitCode).toBe(1); - expect(calls).toEqual([]); - expect(output).toContain("Invalid manifest-id 'local.2024-app'"); - // The refusal says where the id came from and how to set one, because - // the user never typed this string. - expect(output).toContain('derived from the compiled artifact'); - expect(output).toContain('--manifest-id'); + expect(exitCode ?? 0).toBe(0); + expect(calls).toHaveLength(2); + expect(calls[0].url).toBe('http://cloud.test/api/v1/cloud/packages'); + expect(calls[0].body.manifest_id).toBe('local.2024-app'); + expect(output).not.toContain('Invalid manifest-id'); // It is NOT normalised into some other permanent identifier: manifestId // is immutable once published. expect(output).not.toContain('local.a2024-app'); }); + it('every slug the derivation can produce is a legal id, from the name or from the filename', () => { + const names = ['2024 App', '9', '--x--', 'ünïcödé', 'Acme CRM', `${'a'.repeat(63)} tail`]; + for (const name of names) { + const fromName = deriveManifestId({ manifest: { name } }, '/nowhere/objectstack.json'); + expect(isManifestId(fromName.id), `${JSON.stringify(name)} -> ${fromName.id}`).toBe(true); + const fromFile = deriveManifestId({ manifest: {} }, `/nowhere/${name}.json`); + expect(isManifestId(fromFile.id), `${JSON.stringify(name)}.json -> ${fromFile.id}`).toBe(true); + } + }); + it('publishes when the same derivation lands on a legal id', async () => { const path = await artifactAt({ name: 'Acme CRM', version: '1.2.0' }); const calls = stubCloud(); diff --git a/packages/cloud-connection/src/marketplace-install-local-id-gate.test.ts b/packages/cloud-connection/src/marketplace-install-local-id-gate.test.ts index ed76d08b71e..8ac225be33a 100644 --- a/packages/cloud-connection/src/marketplace-install-local-id-gate.test.ts +++ b/packages/cloud-connection/src/marketplace-install-local-id-gate.test.ts @@ -148,7 +148,7 @@ afterEach(() => { const REFUSED_STRINGS: ReadonlyArray = [ ['a bare word (the card\'s probe)', 'late-app'], ['an underscore inside a segment', 'com.example.my_erp'], - ['a digit-initial segment', 'com.1acme.crm'], + ['a hyphen-initial segment', 'com.-acme.crm'], ['upper case', 'Com.Acme.Crm'], ['a whitespace-padded conforming id (the RAW value is parsed)', ' com.acme.crm '], ['the empty string', ''], @@ -222,7 +222,9 @@ describe('install-local parses the inline manifest\'s `id` through its declarati expectNothingWritten(h); }); - for (const id of ['com.example.crm', 'com.example.my-erp', 'org.apache.superset']) { + // `com.1acme.crm` was a REFUSED row until the declaration let a segment + // open with a digit; it installs now, keyed and filed by the id as written. + for (const id of ['com.example.crm', 'com.example.my-erp', 'org.apache.superset', 'com.1acme.crm']) { it(`lit control — '${id}' still installs, keyed by the id as written`, async () => { const h = await mount(dir); const res = await h.routes.get(`POST ${ROUTE}`)!( diff --git a/packages/metadata-protocol/src/protocol.install-manifest-id.test.ts b/packages/metadata-protocol/src/protocol.install-manifest-id.test.ts index e9672690124..0f6822adc4c 100644 --- a/packages/metadata-protocol/src/protocol.install-manifest-id.test.ts +++ b/packages/metadata-protocol/src/protocol.install-manifest-id.test.ts @@ -43,11 +43,15 @@ const REFUSED = [ ['a bare word — no reverse-domain prefix at all', 'pkg-a'], ['an underscore inside a segment', 'com.example.my_erp'], ['the empty string', ''], - ['a segment opening with a digit', 'com.4example.crm'], + ['a segment opening with a hyphen', 'com.-example.crm'], ] as const; -/** Ids the declaration admits — the lit controls. */ -const ADMITTED = ['com.example.crm', 'com.example.my-erp', 'org.apache.superset'] as const; +/** + * Ids the declaration admits — the lit controls. `com.4example.crm` was a + * REFUSED row until the declaration let a segment open with a digit; it is + * here so this door is held to the widened rule, not only the spec schema. + */ +const ADMITTED = ['com.example.crm', 'com.example.my-erp', 'org.apache.superset', 'com.4example.crm'] as const; function makeImpl() { const registryCalls: Array<{ manifest: any }> = []; diff --git a/packages/spec/src/kernel/manifest.test.ts b/packages/spec/src/kernel/manifest.test.ts index 649449de1c5..6f7b7d89afb 100644 --- a/packages/spec/src/kernel/manifest.test.ts +++ b/packages/spec/src/kernel/manifest.test.ts @@ -3,6 +3,7 @@ import { ManifestSchema, MANIFEST_ID_PATTERN, MANIFEST_ID_EXAMPLES, + manifestIdRefusal, type ObjectStackManifest, } from './manifest.zod'; import { PackageSchema } from '../marketplace/package.zod'; @@ -563,39 +564,73 @@ describe('dead-container retirement (#11332, ADR-0049 — tombstoned, not delete describe('manifest.id — reverse-domain identifier', () => { const legal = (id: string) => ({ id, version: '1.0.0', type: 'app' as const, name: 'X' }); - it('the examples the TSDoc and the refusal show are themselves legal', () => { - // The refusal shows these two ids to an author who is already stuck. An - // example that fails its own rule teaches exactly the wrong thing, so the - // list is held against the pattern rather than trusted. - for (const example of MANIFEST_ID_EXAMPLES) { - expect(MANIFEST_ID_PATTERN.test(example), `${example} must match the pattern`).toBe(true); - expect(ManifestSchema.safeParse(legal(example)).success).toBe(true); - } - }); - - it.each([ + // ONE table, judged at BOTH doors that share `MANIFEST_ID_PATTERN` — the + // `ManifestSchema.id` rows below and the `PackageSchema.manifestId` test at + // the end of this block read these same two lists. + // + // A segment may open with a digit: DNS labels may (`com.163.crm` is a real + // company's reverse domain), and the id is never a table name, a JS + // identifier or a path, so the leading-letter clause carried no reason and + // the refusal sentence could not state one. `manifest.namespace` — the + // physical SQL prefix — keeps ITS leading-letter rule; see the block below. + const ACCEPTED = [ 'com.acme.crm', 'com.example.my-app', 'org.apache.superset', 'app.example.hr', 'a.b', 'com.example.app2', - ])('accepts %s', (id) => { - expect(ManifestSchema.safeParse(legal(id)).success).toBe(true); - }); + 'com.example.2app', + 'com.163.crm', + ] as const; - it.each([ + const REFUSED = [ ['blank', 'a bare word carries no dot'], ['com', 'one segment is not reverse domain'], ['com.', 'a trailing dot leaves an empty segment'], ['.com.app', 'a leading dot leaves an empty segment'], ['com.example.my_app', 'underscores are not admitted'], ['Com.Example.App', 'uppercase is not admitted'], - ['com.example.-app', 'a segment must open with a letter'], - ['com.example.2app', 'a segment must open with a letter, not a digit'], + ['com.example.-app', 'a segment may not open with a hyphen'], ['com example.app', 'spaces are not admitted'], - ])('refuses %s (%s)', (id) => { - expect(ManifestSchema.safeParse(legal(id)).success).toBe(false); + ] as const; + + it('the examples the TSDoc and the refusal show are themselves legal', () => { + // The refusal shows these two ids to an author who is already stuck. An + // example that fails its own rule teaches exactly the wrong thing, so the + // list is held against the pattern rather than trusted. + for (const example of MANIFEST_ID_EXAMPLES) { + expect(MANIFEST_ID_PATTERN.test(example), `${example} must match the pattern`).toBe(true); + expect(ManifestSchema.safeParse(legal(example)).success).toBe(true); + } + }); + + it.each(ACCEPTED)('accepts %s, and parses it to itself', (id) => { + const r = ManifestSchema.safeParse(legal(id)); + expect(r.success).toBe(true); + // The id is an identity: an accepted value is kept byte for byte, never + // normalised into a different package's name. + expect(r.success && r.data.id).toBe(id); + }); + + it.each(REFUSED)('refuses %s (%s)', (id) => { + const r = ManifestSchema.safeParse(legal(id)); + expect(r.success).toBe(false); + const issue = r.success ? undefined : r.error.issues.find((i) => i.path[0] === 'id'); + expect(issue?.code).toBe('invalid_format'); + expect(issue?.message).toBe(manifestIdRefusal('manifest.id', id)); + }); + + it('the refusal sentence states the rule the pattern enforces — digits admitted, a leading hyphen not', () => { + // The defect this holds shut: the sentence listed clauses + // `com.example.2app` satisfied, and the pattern refused it anyway. The + // sentence and the pattern now say the same rule, so what the sentence + // admits the pattern admits. + const msg = manifestIdRefusal('manifest.id', 'com.example.-app'); + expect(msg).toContain('letters, digits and inner hyphens'); + expect(msg).toContain('a segment may not open with a hyphen'); + expect(msg).toContain('underscores are not admitted'); + expect(msg).not.toMatch(/start(s|ing)? with a letter|open(s|ing)? with a letter/); }); it('a namespace is never an id — the two rules contradict on the underscore', () => { @@ -649,8 +684,14 @@ describe('manifest.id — reverse-domain identifier', () => { expect(msg).not.toContain('Did you mean'); }); + it('suggests the prefixed form for a digit-led bare word, since a segment may open with a digit', () => { + // Until the leading-letter clause went, `com.example.2fa` failed the + // pattern and the refusal offered nothing; it is now the repair. + expect(refusalFor('2fa')).toContain("Did you mean 'com.example.2fa'?"); + }); + it('every suggestion it makes is itself accepted by the schema', () => { - for (const input of ['blank', 'my_app', 'com.dogfood.flow_fixture', 'support_desk']) { + for (const input of ['blank', 'my_app', 'com.dogfood.flow_fixture', 'support_desk', '2fa']) { const suggested = /Did you mean '([^']+)'\?/.exec(refusalFor(input))?.[1]; expect(suggested, `${input} should get a suggestion`).toBeTruthy(); expect(ManifestSchema.safeParse(legal(suggested as string)).success).toBe(true); @@ -659,17 +700,21 @@ describe('manifest.id — reverse-domain identifier', () => { }); it('PackageSchema.manifestId enforces the SAME declaration — the two cannot drift', () => { - // The point of the shared constant: one verdict, two surfaces. A future - // edit to either regex literal would have to break this table to pass. - const cases = ['com.acme.crm', 'org.apache.superset', 'blank', 'com.example.my_app', 'Com.App', 'a.b']; + // The point of the shared constant: one verdict, two surfaces, judged on + // the SAME table the `manifest.id` rows above read. The expected verdict + // comes from the table, never from the pattern, so a future edit to either + // regex literal would have to break this table to pass. + const cases: ReadonlyArray = [ + ...ACCEPTED.map((id) => [id, false] as const), + ...REFUSED.map(([id]) => [id, true] as const), + ]; // Judged per FIELD, not on whole-object success: the two schemas require // different neighbours, so an overall verdict would be measuring those. const fieldRefused = (schema: typeof ManifestSchema | typeof PackageSchema, key: string, value: unknown) => { const r = schema.safeParse({ [key]: value } as never); return r.success ? false : r.error.issues.some((i) => i.path[0] === key); }; - for (const id of cases) { - const refused = !MANIFEST_ID_PATTERN.test(id); + for (const [id, refused] of cases) { expect(fieldRefused(ManifestSchema, 'id', id), `manifest.id verdict for ${id}`).toBe(refused); expect(fieldRefused(PackageSchema, 'manifestId', id), `manifestId verdict for ${id}`).toBe(refused); } diff --git a/packages/spec/src/kernel/manifest.zod.ts b/packages/spec/src/kernel/manifest.zod.ts index 285e94098c0..f0913fae938 100644 --- a/packages/spec/src/kernel/manifest.zod.ts +++ b/packages/spec/src/kernel/manifest.zod.ts @@ -255,12 +255,21 @@ export type PluginIntegrity = z.input; * Both sites now reference this constant, which is what makes a future drift a * one-line edit rather than a silent divergence. * - * Reads as: a lowercase segment, then one or more dot-separated lowercase - * segments. Each segment starts with a letter and may carry digits and hyphens. - * ⛔ Underscores are NOT admitted — `manifest.namespace` allows them and this - * key does not, so a namespace is never a legal id by itself. + * Reads as: two or more lowercase dot-separated segments of letters, digits and + * inner hyphens. A segment may open with a letter or a digit (`com.163.crm`, + * `com.example.2app`), never with a hyphen. ⛔ Underscores are NOT admitted — + * `manifest.namespace` allows them and this key does not, so a namespace is + * never a legal id by itself. + * + * A digit may open a segment because nothing downstream needs it not to: the id + * is a registry key (`manifest_id`), a runtime package-map key and a + * grant-source key — never a table name, a JS identifier, a filesystem path or + * a hostname — and DNS labels themselves may open with a digit. The physical + * prefix is `manifest.namespace`, which keeps its own leading-letter rule for + * the SQL-identifier reason; `deriveNamespaceFromPackageId` strips a leading + * digit run when it derives one from an id. */ -export const MANIFEST_ID_PATTERN = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/; +export const MANIFEST_ID_PATTERN = /^[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*)+$/; /** * The example ids the refusal shows an author, and the same two the TSDoc on @@ -294,8 +303,8 @@ export function manifestIdRefusal(key: string, input: unknown): string { const examples = MANIFEST_ID_EXAMPLES.map((e) => `'${e}'`).join(', '); const base = `Invalid package id '${received}' on \`${key}\`. Expected reverse-domain notation ` - + `(${examples}) — lowercase dot-separated segments; hyphens allowed inside a segment, ` - + 'underscores are not.'; + + `(${examples}) — lowercase dot-separated segments of letters, digits and inner hyphens; ` + + 'a segment may not open with a hyphen; underscores are not admitted.'; // Two mechanical repairs, tried in order, and only ever OFFERED once the // candidate has been checked against the pattern itself: @@ -338,7 +347,10 @@ export const ManifestSchema = strictObject({ * is why the rule holds for a private app exactly as for a listed one. * * Enforced by {@link MANIFEST_ID_PATTERN}, the single declaration this key - * shares with `PackageSchema.manifestId` (`../marketplace/package.zod.ts`). + * shares with `PackageSchema.manifestId` (`../marketplace/package.zod.ts`): + * two or more lowercase dot-separated segments of letters, digits and inner + * hyphens. A segment may open with a letter or a digit (`com.163.crm`), never + * with a hyphen; underscores are not admitted. * ⛔ `manifest.namespace` is NOT an id: it admits underscores and carries no * dot, so it fails this rule by construction. * diff --git a/packages/spec/src/migrations/entries/semantic/18.manifest-id-reverse-domain-required.ts b/packages/spec/src/migrations/entries/semantic/18.manifest-id-reverse-domain-required.ts index fcacf972ba2..1cfec67d445 100644 --- a/packages/spec/src/migrations/entries/semantic/18.manifest-id-reverse-domain-required.ts +++ b/packages/spec/src/migrations/entries/semantic/18.manifest-id-reverse-domain-required.ts @@ -15,9 +15,9 @@ export const entry: SemanticMigration = { + 'and the `id:` key of a package manifest — and its registry face ' + '`PackageSchema.manifestId` (`marketplace/package.zod.ts`)', replacement: 'a reverse-domain identifier matching `MANIFEST_ID_PATTERN` ' - + '(`kernel/manifest.zod.ts`): dot-separated lowercase segments, each opening with a ' - + 'letter, digits and hyphens allowed inside a segment — `com.acme.crm`, ' - + '`org.apache.superset`. ⛔ Underscores are not admitted, so `manifest.namespace` is ' + + '(`kernel/manifest.zod.ts`): two or more lowercase dot-separated segments of letters, ' + + 'digits and inner hyphens, each opening with a letter or a digit, never a hyphen — ' + + '`com.acme.crm`, `org.apache.superset`. ⛔ Underscores are not admitted, so `manifest.namespace` is ' + 'never a legal id and never a legal last segment of one: `com.acme.my_app` becomes ' + '`com.acme.my-app`. A bare word gains a prefix: `blank` becomes `com.example.blank`. ' + 'The refusal carries the repaired value it has already checked against the pattern, so ' From a97a38db05143feadc46fe4d661b6db870cc2301 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 03:00:47 +0000 Subject: [PATCH 2/2] chore(spec): regenerate the migration registry; the transcription control names the widened pattern Claude-Session: https://claude.ai/code/session_01QcAS3qiYYZNezaxZxaUdMV Co-authored-by: Claude --- packages/cli/test/package-publish-manifest-id.test.ts | 2 +- packages/spec/src/migrations/registry.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/test/package-publish-manifest-id.test.ts b/packages/cli/test/package-publish-manifest-id.test.ts index 631d00d9b26..78521206b6e 100644 --- a/packages/cli/test/package-publish-manifest-id.test.ts +++ b/packages/cli/test/package-publish-manifest-id.test.ts @@ -439,7 +439,7 @@ describe('publish.ts keeps no local copy of the manifest-id rule', () => { expect(manifestIdShapedLiterals(RETIRED_LOCAL_RULE)).toHaveLength(1); // …and on a transcription of the schema's own pattern, the shape a // "fix" that re-types the regex would take. - expect(manifestIdShapedLiterals('const X = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/;')).toHaveLength(1); + expect(manifestIdShapedLiterals('const X = /^[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$/;')).toHaveLength(1); }); it('finds none in the command source', () => { diff --git a/packages/spec/src/migrations/registry.ts b/packages/spec/src/migrations/registry.ts index c92e1d2c3ba..bea76e1a968 100644 --- a/packages/spec/src/migrations/registry.ts +++ b/packages/spec/src/migrations/registry.ts @@ -10283,9 +10283,9 @@ const step18: MigrationStep = { + 'and the `id:` key of a package manifest — and its registry face ' + '`PackageSchema.manifestId` (`marketplace/package.zod.ts`)', replacement: 'a reverse-domain identifier matching `MANIFEST_ID_PATTERN` ' - + '(`kernel/manifest.zod.ts`): dot-separated lowercase segments, each opening with a ' - + 'letter, digits and hyphens allowed inside a segment — `com.acme.crm`, ' - + '`org.apache.superset`. ⛔ Underscores are not admitted, so `manifest.namespace` is ' + + '(`kernel/manifest.zod.ts`): two or more lowercase dot-separated segments of letters, ' + + 'digits and inner hyphens, each opening with a letter or a digit, never a hyphen — ' + + '`com.acme.crm`, `org.apache.superset`. ⛔ Underscores are not admitted, so `manifest.namespace` is ' + 'never a legal id and never a legal last segment of one: `com.acme.my_app` becomes ' + '`com.acme.my-app`. A bare word gains a prefix: `blank` becomes `com.example.blank`. ' + 'The refusal carries the repaired value it has already checked against the pattern, so '