Skip to content

Commit 7d661aa

Browse files
committed
fix(cloud-connection): step 2c' asks, never installs blind, when the installed record cannot be read; pins and docs from review
Claude-Session: https://claude.ai/code/session_017ihL2dvnT51fbSebUyE3zW Co-Authored-By: Claude <noreply@anthropic.com>
1 parent db65090 commit 7d661aa

7 files changed

Lines changed: 242 additions & 46 deletions

File tree

‎content/docs/data-modeling/fields.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ Database indexes are declared at the object level in the object's `indexes[]` ar
478478
479479
| Property | Type | Default | Description |
480480
| :--- | :--- | :--- | :--- |
481-
| `renamedFrom` | `string[]` | — | Earlier keys of this field (snake_case), e.g. `renamedFrom: ['company']` on a field now keyed `account_name`: on a package upgrade from a version that has the old key and not this one, the platform carries the old column's data to this field instead of adding an empty column. Each entry once; never the field's own key, a key another field of the object still declares, or an old key another field also claims — each refused at parse. Read only at package upgrade, and declared ahead of the upgrade step that carries the data: until that step ships, no upgrade carries a column on this declaration |
481+
| `renamedFrom` | `string[]` | — | Earlier keys of this field (snake_case), e.g. `renamedFrom: ['company']` on a field now keyed `account_name`: on a package upgrade from a version that has the old key and not this one, the platform carries the old column's data to this field instead of adding an empty column. Each entry once; never the field's own key, a key another field of the object still declares, or an old key another field also claims — each refused at parse. Read only at package upgrade, and declared ahead of the upgrade step that carries the data: until that step ships, a managed upgrade that declares a rename is refused `501 NOT_IMPLEMENTED`, naming it, so it never installs as a silent empty column |
482482
483483
### Security
484484

‎content/docs/deployment/cli.mdx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,7 @@ write `-u URL` instead.
33933393
| `--password <password>` | `OS_RUNTIME_PASSWORD` | Account password on the target runtime |
33943394
| `--confirm-global-uniques` | — | Affirm this app's installation-wide `unique` constraints are genuinely platform-wide — see below |
33953395
| `--confirm-access-upgrade <token>` | — | Confirm an upgrade's access findings with the finding-set token the runtime's refusal printed — see below |
3396+
| `--confirm-upgrade <token>` | — | Confirm an upgrade's schema findings (a suspected rename, a type change that is not safe) with the finding-set token the runtime's refusal printed — see below |
33963397
| `--timeout <ms>` | `OS_CLOUD_TIMEOUT_MS` | HTTP timeout in milliseconds, default `120000`. `0` disables it |
33973398

33983399
**`--confirm-global-uniques` answers a stop; it does not force one past.**
@@ -3424,6 +3425,25 @@ and the upgrade stops again with the new set; the confirmation is recorded in
34243425
the install's ledger entry. Under `group` and `isolated` only the platform
34253426
operator reaches this check. A fresh install is never checked.
34263427

3428+
**`--confirm-upgrade <token>` confirms exactly the schema findings it names.**
3429+
Upgrading an installed package stops with `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`
3430+
when the new version would change a stored field in a way the schema sync does
3431+
not carry: a field removed while another is added with no `renamedFrom` linking
3432+
them (if it is a rename, the new field starts empty and the values stay in the
3433+
old column), or a type change that keeps or drops a stored column
3434+
(`needs_confirm` or `destructive`). It also stops when the runtime cannot read
3435+
its record of the installed version, since nothing could be compared. Nothing is
3436+
installed. The command prints each finding and the exact retry, carrying the
3437+
finding set's token. If a field was renamed, declare its old key in the new
3438+
field's `renamedFrom` and rebuild instead; a declared rename is refused with
3439+
`501 NOT_IMPLEMENTED` until the runtime can carry the column's values to the new
3440+
key. As with `--confirm-access-upgrade`, the token stops matching once the
3441+
findings change, and the confirmation is recorded in the install's ledger entry.
3442+
A type change on a field that had no stored column, a removed field and a seed
3443+
data change are never refused; `--dry-run` lists them. `os deploy` passes
3444+
`--confirm-upgrade` through to a self-hosted runtime. A fresh install is never
3445+
checked.
3446+
34273447
A `404` means the target runtime does not mount `MarketplaceInstallLocalPlugin`
34283448
(from `@objectstack/cloud-connection`). The endpoint is opt-in, so a runtime
34293449
composed without it will not accept installs.

‎packages/cli/src/commands/package/install.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,17 @@ export default class PackageInstall extends Command {
474474
// confirm exactly these findings.
475475
if (res.body?.error?.code === 'SCHEMA_UPGRADE_CONFIRMATION_REQUIRED') {
476476
const details = res.body.error.details ?? {};
477-
const findings: Array<{ describe?: string }> = Array.isArray(details.findings) ? details.findings : [];
478-
printError('Upgrade stopped — it would rename or retype stored fields without carrying their values');
477+
const findings: Array<{ kind?: string; describe?: string }> = Array.isArray(details.findings) ? details.findings : [];
478+
// A record of the installed version the runtime could not read is a
479+
// finding too (no comparison ran): there is no field to declare.
480+
const fieldFindings = findings.some((f) => f.kind === 'suspected_rename' || f.kind === 'type_change');
481+
printError(fieldFindings
482+
? 'Upgrade stopped — it would rename or retype stored fields without carrying their values'
483+
: 'Upgrade stopped — the runtime cannot compare it with the installed version');
479484
console.log('');
480485
for (const finding of findings) console.log(` • ${finding.describe ?? JSON.stringify(finding)}`);
481486
console.log('');
482-
console.log(" If a field was renamed, declare its old key in the new field's `renamedFrom` and rebuild.");
487+
if (fieldFindings) console.log(" If a field was renamed, declare its old key in the new field's `renamedFrom` and rebuild.");
483488
console.log(' To upgrade anyway, accepting each finding as listed, confirm exactly these findings:');
484489
console.log(` ${retry} --confirm-upgrade ${details.findingSet}`);
485490
this.exit(1);

‎packages/cloud-connection/src/marketplace-install-local-corrupt-ledger.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,45 @@ describe('handleList() — the wire shape it kept', () => {
343343
expect(Object.keys(payload.data).sort()).toEqual(['items', 'storageDir', 'total']);
344344
});
345345
});
346+
347+
/**
348+
* [epic cloud#3652 Q3, #30884] A managed re-install over a record that will
349+
* not parse: step 2c′ has no installed version to compare, and a comparison
350+
* that did not run is never taken for "no finding" — the 409 names the record
351+
* as its one finding, and that finding's token admits the re-install, which
352+
* rewrites the record and records the confirmation.
353+
*/
354+
describe('handleInstall() — step 2c′ over an unreadable record asks, never installs blind', () => {
355+
function makeInstallC(body: Record<string, unknown>) {
356+
const c = makeC();
357+
return { ...c, req: { ...c.req, json: async () => body } };
358+
}
359+
360+
it('answers 409 with installed_record_unreadable (file, cause), writes nothing; its token installs', async () => {
361+
writeCorruptEntryFor('app.test.crm');
362+
const { rawApp, ctx } = await boot();
363+
const install = rawApp.routes.get('POST /api/v1/marketplace/install-local')!;
364+
const upgrade = { ...GOOD_MANIFEST, version: '1.0.1' };
365+
const register = ctx.getService('manifest').register;
366+
register.mockClear(); // isolate from the boot's own registrations
367+
368+
const res = await install(makeInstallC({ manifest: upgrade }));
369+
370+
expect(res.status).toBe(409);
371+
expect(res.payload.error.code).toBe('SCHEMA_UPGRADE_CONFIRMATION_REQUIRED');
372+
const { details } = res.payload.error;
373+
expect(details.findings).toEqual([expect.objectContaining({
374+
kind: 'installed_record_unreadable', file: 'app.test.crm.json', cause: expect.stringMatching(/JSON/i),
375+
})]);
376+
expect(details.findingSet).toMatch(/^schema-upgrade:[0-9a-f]{32}$/);
377+
expect(register).not.toHaveBeenCalled();
378+
expect(new LocalManifestSource(dir).read('app.test.crm').failure).toBeDefined();
379+
380+
const confirmed = await install(makeInstallC({ manifest: upgrade, confirmSchemaUpgrade: details.findingSet }));
381+
382+
expect(confirmed.status).toBe(200);
383+
const entry = new LocalManifestSource(dir).read('app.test.crm').entry;
384+
expect(entry?.version).toBe('1.0.1');
385+
expect(entry?.schemaUpgradeConfirmation).toMatchObject({ findingSet: details.findingSet });
386+
});
387+
});

0 commit comments

Comments
 (0)