Skip to content

Commit 6654919

Browse files
committed
feat(cli): --confirm-upgrade on os package install and os deploy; changeset (wip)
Claude-Session: https://claude.ai/code/session_017ihL2dvnT51fbSebUyE3zW Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 60be366 commit 6654919

3 files changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/cloud-connection': patch
4+
'@objectstack/cli': patch
5+
---
6+
7+
feat(cloud-connection)!: a managed upgrade that renames or retypes a stored field is refused until it is declared or confirmed
8+
9+
Clause-②: yes (narrowing) — a managed re-install through install-local that installed before is refused `409 SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` when its package upgrade plan lists an undeclared suspected rename or a `needs_confirm` / `destructive` type change, and `501 NOT_IMPLEMENTED` when it declares a field rename (`renamedFrom`) this runtime cannot carry yet. The widening half: the error-code ledger registers `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` under `@objectstack/cloud-connection`, install-local takes `confirmSchemaUpgrade`, and `os package install` and `os deploy` take `--confirm-upgrade`.
10+
Metadata-protocol: none
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped and no export is removed: the refusal judges two package bodies at the install door, so there is nothing for a migration to rewrite and no tombstone. The way through is a token the refusal itself prints. -->
13+
14+
**BREAKING** accept-set narrowing at the install-local door (`POST /api/v1/marketplace/install-local`, `@objectstack/cloud-connection`) for a managed re-install over an installed package.
15+
16+
Before any write, after the access upgrade check, the door compares the installed version (its ledger entry) with the incoming one through `comparePackageVersions` (`@objectstack/metadata-core`), the comparison the dry run and `os diff` read:
17+
18+
- **A suspected rename** (in one object, a stored field removed while a stored field is added, with no `renamedFrom` linking them) or **a type change** the drift categories call `needs_confirm` (both columns stored) or `destructive` (the new type stores no column) answers `409 SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`. `error.details.findings` names each with a one-line `describe` (and, when the runtime's `manifest` service answers `planUpgrade`, the rows the installed column holds); `error.details.findingSet` is the token. The same request with `"confirmSchemaUpgrade": "<findingSet>"` installs, as the additive schema sync leaves the fields, and the ledger entry records `schemaUpgradeConfirmation` (the token, who, when). A token from another finding set is refused again with the fresh one. A type change riding on a declared rename is judged on its own.
19+
- **A declared rename** (`renamedFrom` on a field of the new version) answers `501 NOT_IMPLEMENTED`, naming each rename: this runtime cannot yet move a renamed field's values to its new key, and no token answers it.
20+
- A `safe` type change (the installed field had no stored column), a removed field or object and a seed dataset change are refused by nothing; `dryRun: true` reports them.
21+
22+
A first install, an `unmanaged` install and a re-install whose plan lists none of these answer as before.
23+
24+
**Migration.** A package author whose upgrade is refused either declares the rename on the new field — `renamedFrom: ['<old key>']` — and rebuilds, or confirms the findings as listed: `os package install <artifact> --confirm-upgrade <findingSet>` (`os deploy --confirm-upgrade <findingSet>` against a self-hosted runtime), or `"confirmSchemaUpgrade": "<findingSet>"` in the install-local body. A host that calls install-local itself reads `error.details.findingSet` off the 409 and sends it back. Preview the refusal first with `os package install <artifact> --dry-run`.

‎packages/cli/test/deploy.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,23 @@ describe('os deploy — a self-hosted runtime as the active target (os environme
575575
expect(sent[1].body.confirmAccessUpgrade).toBe('fs_123');
576576
});
577577

578+
it("the schema upgrade refusal's retry names os deploy --confirm-upgrade, and the token passes through", async () => {
579+
const schemaRefusal = refused(409, 'SCHEMA_UPGRADE_CONFIRMATION_REQUIRED', 'confirm', {
580+
findings: [{ describe: 'acme_lead.company (text) is removed while acme_lead.account_name (text) is added' }],
581+
findingSet: 'schema-upgrade:abc',
582+
});
583+
let sent = stubRuntime({ install: schemaRefusal });
584+
expect(await deploy()).toBe(1);
585+
expect(sent).toHaveLength(2);
586+
expect(text()).toContain('os deploy --confirm-upgrade schema-upgrade:abc');
587+
588+
vi.unstubAllGlobals();
589+
sent = stubRuntime({});
590+
expect(await deploy(['--confirm-upgrade', 'schema-upgrade:abc']), text()).toBeUndefined();
591+
expect(sent[0].body.confirmSchemaUpgrade).toBeUndefined();
592+
expect(sent[1].body.confirmSchemaUpgrade).toBe('schema-upgrade:abc');
593+
});
594+
578595
it('a package the running kernel could not load is not called live: exit 1', async () => {
579596
stubRuntime({ install: ok({ ...INSTALLED, hotLoaded: false, hotLoadError: 'boom' }) });
580597

@@ -600,4 +617,13 @@ describe('os deploy — a self-hosted runtime as the active target (os environme
600617
expect(sent).toHaveLength(0);
601618
expect(compileForDeploy).not.toHaveBeenCalled();
602619
});
620+
621+
it('--confirm-upgrade is refused when the target is ObjectOS Cloud, before anything is sent', async () => {
622+
await writeFile(join(home, '.objectstack', 'cloud.json'), JSON.stringify({ url: CLOUD_PLANE, token: 'cloud_tok', createdAt: 'now' }));
623+
const sent = stubRuntime({});
624+
625+
expect(await deploy(['--confirm-upgrade', 'schema-upgrade:abc'])).toBe(1);
626+
expect(sent).toHaveLength(0);
627+
expect(compileForDeploy).not.toHaveBeenCalled();
628+
});
603629
});

‎packages/cli/test/package-install-dry-run.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,62 @@ describe('os package install --dry-run (#30884)', () => {
141141
expect(out).toContain('does not support a dry run: it ignored `--dry-run` and INSTALLED com.acme.crm@latest');
142142
});
143143
});
144+
145+
/**
146+
* [epic cloud#3652 Q3, #30884] `os package install --confirm-upgrade <token>`
147+
* — the install-local body's `confirmSchemaUpgrade`, and how the command
148+
* renders the runtime's `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` refusal: every
149+
* finding, both ways forward, the exact retry with the token, exit 1.
150+
*/
151+
describe('os package install --confirm-upgrade (epic cloud#3652 Q3)', () => {
152+
const TOKEN = 'schema-upgrade:0123456789abcdef0123456789abcdef';
153+
const INSTALLED = {
154+
manifestId: 'com.acme.crm', version: '2.0.0', versionId: 'ver_2', installedAt: '2026-11-07T00:00:00.000Z',
155+
hotLoaded: true, storageDir: '/srv/runtime/.objectstack/installed-packages',
156+
};
157+
158+
afterEach(() => {
159+
vi.unstubAllGlobals();
160+
vi.restoreAllMocks();
161+
});
162+
163+
it('sends the token verbatim as `confirmSchemaUpgrade`, and no such key without the flag', async () => {
164+
let { sent } = stubRuntime({ ok: true, status: 200, body: { success: true, data: INSTALLED } });
165+
await runInstall(['--confirm-upgrade', TOKEN]);
166+
expect(sent[0]).toMatchObject({ packageId: 'com.acme.crm', confirmSchemaUpgrade: TOKEN });
167+
168+
vi.unstubAllGlobals();
169+
vi.restoreAllMocks();
170+
({ sent } = stubRuntime({ ok: true, status: 200, body: { success: true, data: INSTALLED } }));
171+
await runInstall([]);
172+
expect(sent[0]).not.toHaveProperty('confirmSchemaUpgrade');
173+
});
174+
175+
it('renders the refusal: every finding, renamedFrom or the token, and exits 1', async () => {
176+
stubRuntime({
177+
ok: false,
178+
status: 409,
179+
body: {
180+
success: false,
181+
error: {
182+
code: 'SCHEMA_UPGRADE_CONFIRMATION_REQUIRED',
183+
message: 'Upgrading "com.acme.crm" would change stored fields in a way the schema sync does not carry',
184+
details: {
185+
manifestId: 'com.acme.crm',
186+
findingSet: TOKEN,
187+
findings: [
188+
{ kind: 'suspected_rename', describe: 'acme_lead.company (text) is removed while acme_lead.account_name (text) is added' },
189+
{ kind: 'type_change', describe: 'acme_deal.amount changes type text → number (needs_confirm)' },
190+
],
191+
},
192+
},
193+
},
194+
});
195+
const { out, exit } = await runInstall([]);
196+
expect(exit).toBe(1);
197+
expect(out).toContain('acme_lead.company (text) is removed while acme_lead.account_name (text) is added');
198+
expect(out).toContain('acme_deal.amount changes type text → number (needs_confirm)');
199+
expect(out).toContain('`renamedFrom`');
200+
expect(out).toContain(`os package install com.acme.crm --confirm-upgrade ${TOKEN}`);
201+
});
202+
});

0 commit comments

Comments
 (0)