Skip to content

Commit 0e5473f

Browse files
committed
test: parse the server spec version as SemVer and key the objectui skill claim on the spec major
Claude-Session: https://claude.ai/code/session_01L6bhgV6i8jfWwSXjpWJrjA Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2fd0411 commit 0e5473f

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎packages/runtime/src/domains/mcp-authoring.test.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
// paid here, during collection, never inside a clocked case.
3939
import { MetadataManager } from '@objectstack/metadata';
4040
import { canonicalMetaUrlType } from '@objectstack/spec/shared';
41-
import { DEFAULT_METADATA_TYPE_REGISTRY, getMetadataCreateSeed, getMetadataTypeSchema } from '@objectstack/spec/kernel';
41+
import { DEFAULT_METADATA_TYPE_REGISTRY, getMetadataCreateSeed, getMetadataTypeSchema, SEMVER_2_0_0_VERSION_PATTERN } from '@objectstack/spec/kernel';
4242
import { z } from 'zod';
4343
import { PLATFORM_PROVIDED_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES } from '@objectstack/spec/system';
4444
import { handleMcpRequest } from './mcp.js';
@@ -944,7 +944,15 @@ describe('save_metadata_draft saves a draft and answers with its publish verdict
944944
/** [#34774] `clientSpecVersion` on the save (#34659 ruling D4 = A). */
945945
describe('[#34774] save_metadata_draft judges the client\'s declared spec version', () => {
946946
const SERVER = (createRequire(import.meta.url)('@objectstack/spec/package.json') as { version: string }).version;
947-
const [major, minor] = SERVER.split('.').map(Number);
947+
// Parsed with the SemVer 2.0.0 grammar the door itself judges with, never a
948+
// `split('.')`: on a prerelease line (`19.0.0-next.0`) the third dot-field is
949+
// `0-next`, and a patch read from it is NaN. The prerelease is DROPPED from
950+
// every version built below: each case is about major and minor, and a plain
951+
// release triple is the one shape every case means. The prerelease itself is
952+
// exercised by its own case, declared verbatim.
953+
const parsed = SEMVER_2_0_0_VERSION_PATTERN.exec(SERVER);
954+
if (!parsed) throw new Error(`@objectstack/spec resolves to ${SERVER}, which is not a SemVer 2.0.0 version`);
955+
const [major, minor, patch] = parsed.slice(1, 4).map(Number);
948956
const SAVE = { type: 'flow', name: 'lead_intake', item: FLOW_DRAFT, package: 'com.acme.crm' };
949957
const writes = (calls: unknown[]) => calls.filter((c: any) => ['saveMetaItem', 'draftPublishJudgement'].includes(c[0]));
950958
const save = async (clientSpecVersion?: unknown) => {
@@ -959,11 +967,21 @@ describe('[#34774] save_metadata_draft judges the client\'s declared spec versio
959967
expect(without.tool.parameters.properties.clientSpecVersion).toMatchObject({ type: 'string' });
960968
expect(without.tool.parameters.required).toEqual(['type', 'name', 'item']);
961969
expect(Object.keys(without.body)).toEqual(['saved', 'verdict', 'review']);
962-
const same = await save(`${major}.${minor}.${Number(SERVER.split('.')[2]) + 1}`);
970+
const same = await save(`${major}.${minor}.${patch + 1}`);
963971
expect(same.result.output.value).toBe(without.result.output.value);
964972
expect(same.writes).toEqual(without.writes);
965973
});
966974

975+
it('a prerelease of the same major and minor saves as before, and so does the server\'s own version verbatim', async () => {
976+
const without = await save();
977+
for (const declared of [SERVER, `${major}.${minor}.0-next.0`]) {
978+
const { result, writes: written } = await save(declared);
979+
expect(result.isError, declared).toBeUndefined();
980+
expect(result.output.value, declared).toBe(without.result.output.value);
981+
expect(written, declared).toEqual(without.writes);
982+
}
983+
});
984+
967985
it('done when: a client declaring the previous major is refused with the command to run, and nothing is written', async () => {
968986
for (const declared of [`${major - 1}.${minor}.0`, `${major + 1}.0.0`]) {
969987
const { body, writes: written } = await save(declared);

‎ui/scripts/__tests__/doc-version-claims.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url';
66

77
import { rootWorkflowsDir } from './helpers/root-ci';
88
import { labelPath, skillBundleBase, skillsWalk } from '../skill-bundle-root.mjs';
9+
import { workspaceRoot } from '../workspace-root.mjs';
910

1011
/**
1112
* objectui#3697: nothing in this repository looks at a version literal written
@@ -1046,6 +1047,17 @@ const PEER_19 = 'react' + TICK + ' ^19.0.0';
10461047
const PEER_RESTATEMENT_OK =
10471048
'Restates this package peerDependencies.react verbatim; asserted against the manifest by the peer-line assertion below (objectui#3717), no longer by a human reading it.';
10481049

1050+
/**
1051+
* The major of `@objectstack/spec` this tree builds, read from that package's own
1052+
* manifest. The objectui skill's `compatibility:` pin states it, and the version step
1053+
* rewrites the pin together with the manifest, so its KNOWN_CLAIMS row is keyed on this
1054+
* value rather than on a literal major that the next release would leave stale.
1055+
*/
1056+
const SPEC_MAJOR = Number.parseInt(
1057+
(JSON.parse(fs.readFileSync(path.join(workspaceRoot(), 'packages/spec/package.json'), 'utf8')) as { version: string }).version,
1058+
10,
1059+
);
1060+
10491061
const KNOWN_CLAIMS: KnownClaim[] = [
10501062
// --- content/docs ------------------------------------------------------------
10511063
{
@@ -1159,7 +1171,7 @@ const KNOWN_CLAIMS: KnownClaim[] = [
11591171
// the measurement and for why two of these blocks anchor and one does not.
11601172
{
11611173
file: 'skills/objectui/SKILL.md',
1162-
claim: '@objectstack/spec 18.x',
1174+
claim: `@objectstack/spec ${SPEC_MAJOR}.x`,
11631175
kind: 'anchored',
11641176
why: 'The `compatibility:` pin of the frontmatter. The bundle moved into the objectstack monorepo\'s published `skills/` catalog at the cutover (decision C, objectstack#25803), and that catalog REQUIRES the pin: the repo root\'s `scripts/check-skill-compatibility-version.mjs` reds a skill that declares none and reds this one when its major differs from `packages/spec/package.json`, whose `--fix` derives it. That gate is the anchor, run outside this tree, so no field here can name it. The sentence this replaced stated no version for the reason this file exists; it now states one that a gate re-derives.',
11651177
},

0 commit comments

Comments
 (0)