Skip to content

Commit 3b7219e

Browse files
os-zhuangclaude
andauthored
feat(metadata-core): export the schema upgrade verdict and its finding set token, so a host's install door forwards the platform's own verdict (#31529)
<!-- claude-projects-attribution: {"github_login":"os-zhuang"} --> _Requested by **Sam** · [project thread](https://claude.ai/code/project/chan_01GsBogozeZG5sdpAARrN7HP?thread=cmsg_01GsBogozeZG5sdpAARrN7HP1hxu6zzAV6eVFttJkDXKPW)_ Fixes #31526 ## What changes - **`@objectstack/metadata-core`** gains `src/package-upgrade-verdict.ts`, exported from the index next to `package-upgrade-plan.ts`. It contains: - `schemaUpgradeVerdict(packageId, plan)` → `{ findings, findingSet }`. These need confirming: - a suspected rename, always; - a type change in the `needs_confirm` or `destructive` drift category, including on a declared rename. These are not findings: a declared rename, a removed field or object, a `safe` type change, a seed change. - `installedRecordUnavailableVerdict(packageId, finding)`: the verdict for a door that has no installed side to compare. It returns one confirmable finding, never "no finding". The finding's sentence stays the door's own. - `schemaUpgradeFindingSet(packageId, findings)`: the token. It is `schema-upgrade:` followed by 32 hex characters of a SHA-256 over the package id and the findings' sorted identities. - Constants: `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`, `SCHEMA_UPGRADE_CONFIRMATION_STATUS`, `SCHEMA_UPGRADE_TOPIC`, `SCHEMA_UPGRADE_CONFIRMED_CATEGORIES`. - Types: `SchemaUpgradeFinding`, `SchemaUpgradeUnavailableFinding`, `SchemaUpgradeVerdict`. - **`@objectstack/cloud-connection`**: the install-local door now imports all of the above, and the moved code is verbatim. The door keeps only `ledgerRecordUnavailableVerdict`, its sentence for an install record that is unreadable or missing; that function now calls the exported `installedRecordUnavailableVerdict`. `createHash` and three type imports the door no longer uses are dropped. - **`@objectstack/spec`**: one `PROVENANCE_WAIVERS` entry, because the provenance gate attributes a constant to the package that defines it. `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` is now defined in metadata-core but stays registered under `@objectstack/cloud-connection`, whose door puts it on the wire. This follows the `UPDATE_ID_MISMATCH` shape. No ledger row is added or moved. ## Why cloud#3654 (epic cloud#3652, ruling Q3 「默认拒绝,需显式映射(推荐)」) has the hosted install door refuse an undeclared rename or a type change "with the framework's code and finding-set token". Its card forbids cloud from re-judging. Before this PR, the verdict and the token were private to `marketplace-install-local-plugin.ts`, so the hosted door could only copy the judgement or refuse nothing. With the export, both doors apply one rule and mint one token: the same pair of versions gets the same findings and the same token, whichever door installs it. The hosted consumer is cloud#3861. ## Verification Run in a worktree at `origin/main` `4cd48e27` plus this branch. The workspace dependencies' `dist/` were borrowed from a build of objectstack `3c380253` (27 commits behind main), and `metadata-core` was rebuilt from this branch. - `packages/metadata-core`: `vitest run src/package-upgrade-verdict.test.ts src/package-upgrade-plan.test.ts` gives 2 files, 27 tests passed. The new test file pins two token values, both computed with the door's original digest before the move, so the test pins byte identity: - `schema-upgrade:a168d8927e7a5afc25f947ee715fa848`: a one-field suspected rename on `com.acme.deals`; - `schema-upgrade:c29494e0b3b3e33a84adf0c2188baa37`: the empty set. - `packages/cloud-connection`: `vitest run` on the three install-local suites that exercise the gate (`marketplace-install-local-upgrade-plan`, `-corrupt-ledger`, `-declared-rename`) gives 3 files, 47 tests passed, unchanged. - `packages/spec`: `check:error-code-provenance` OK (11 waivers, all live). `src/api/error-code-ledger.test.ts` gives 26 tests passed. - `tsc --noEmit` is clean in `metadata-core` (both configs) and in `cloud-connection`. eslint is clean on the changed source files. - `check-changeset-fixed`, `check-empty-changeset`, `check-adr-0087-registration`, `check-changeset-no-major` and `check-doc-authoring` all pass. - Docs drift comment: the two pages it names (`data-modeling/fields.mdx` and `deployment/cli.mdx`) describe the install-local refusal and `renamedFrom`. Their behaviour is unchanged by a verbatim move, so neither needs an edit. Clause-②: yes (widening) Metadata-protocol: none This is widening only: `@objectstack/metadata-core` gains the exports listed above. No request, answer, key or error code changes on any door. The changeset is graded `patch`, since the protocol kind is none. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (`packages/spec` gains one data entry in `PROVENANCE_WAIVERS`.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the changed files) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: one ledger waiver entry. No schema, key or export changes. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [ ] The *Before Submitting* list in CONTRIBUTING.md is done. (A full `pnpm test` was not run in this container; CI carries it.) --- _Generated by [Claude Code](https://claude.ai/code/session_01QUs3BsJ2E2byCWsBstMjAJ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4d165ac commit 3b7219e

6 files changed

Lines changed: 346 additions & 178 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/metadata-core': patch
3+
'@objectstack/cloud-connection': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
feat(metadata-core): export the schema upgrade verdict and its finding set token, so a host's install door forwards the platform's own verdict
8+
9+
Clause-②: yes (widening) — `@objectstack/metadata-core` gains exports and nothing else: `schemaUpgradeVerdict`, `installedRecordUnavailableVerdict`, `schemaUpgradeFindingSet`, `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED`, `SCHEMA_UPGRADE_CONFIRMATION_STATUS`, `SCHEMA_UPGRADE_TOPIC`, `SCHEMA_UPGRADE_CONFIRMED_CATEGORIES` and the types `SchemaUpgradeFinding`, `SchemaUpgradeUnavailableFinding` and `SchemaUpgradeVerdict`. No request, answer, key or code changes on any door.
10+
Metadata-protocol: none
11+
12+
The verdict that decides which findings of a package upgrade plan stop a managed upgrade until the installer confirms them (a suspected rename; a type change in the `needs_confirm` or `destructive` drift category, on a declared rename too) and the token that confirmation must echo were private to the install-local door. They now live in `@objectstack/metadata-core` beside `comparePackageVersions`, and the install-local door imports them. A host that installs a package version from its own stored versions, such as the hosted control plane installing into an environment, applies the same rule and mints the same token, so the same pair of versions is refused with the same findings and the same token whichever door installs it.
13+
14+
- **`@objectstack/metadata-core`:** the exports above. `schemaUpgradeVerdict(packageId, plan)` answers `{ findings, findingSet }`; `installedRecordUnavailableVerdict(packageId, finding)` is the verdict of a door with no installed side to compare (one confirmable finding, never "no finding"), the finding's sentence being the door's own.
15+
- **`@objectstack/spec`:** one `PROVENANCE_WAIVERS` entry: `SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` is now defined in metadata-core and still registered under `@objectstack/cloud-connection`, the package whose door puts it on the wire (the `UPDATE_ID_MISMATCH` shape). No row is added or moved.
16+
- **`@objectstack/cloud-connection`:** the install-local door's `409 SCHEMA_UPGRADE_CONFIRMATION_REQUIRED` refusal, its findings, its sentences and its token are unchanged. The token for a given plan is byte-identical before and after, pinned by a test with values the door's own digest minted.

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 20 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,18 @@ import {
314314
// the one the dry run and `os diff` read — which step 2c′'s verdict reads.
315315
comparePackageVersions,
316316
type PackageUpgradeSide,
317-
type PackageUpgradePlan,
318-
type UpgradeDriftCategory,
317+
// [epic cloud#3652 Q3, #30884] The ONE schema upgrade verdict and its
318+
// token — the rule a host's install door applies too, so both doors refuse
319+
// the same pair of versions with the same findings and the same token.
320+
schemaUpgradeVerdict,
321+
installedRecordUnavailableVerdict,
322+
SCHEMA_UPGRADE_CONFIRMATION_REQUIRED,
323+
SCHEMA_UPGRADE_CONFIRMATION_STATUS,
324+
type SchemaUpgradeVerdict,
319325
} from '@objectstack/metadata-core';
320326
import { resolveCloudUrl } from './cloud-url.js';
321327
import { resolveMarketplacePublicBaseUrl } from './marketplace-public-url.js';
322328
import { join } from 'node:path';
323-
import { createHash } from 'node:crypto';
324329

325330
import {
326331
LocalManifestSource,
@@ -616,185 +621,26 @@ const ACCESS_UPGRADE_CONFIRMATION_STATUS = 409;
616621
const ACCESS_UPGRADE_CHECK_SERVICE = 'security.accessUpgradeCheck';
617622

618623
/**
619-
* [epic cloud#3652 Q3 「默认拒绝,需显式映射(推荐)」, #30884] The refusal of a
620-
* managed upgrade whose package upgrade plan carries a change the additive
621-
* schema sync would make silently: a stored field removed while one is added
622-
* with no `renamedFrom` linking them (if it is a rename, the new field starts
623-
* empty and the data stays in the old column), or a type change the drift
624-
* categories call `needs_confirm` or `destructive`. 409, before any write,
625-
* until the same request carries the finding set's token
626-
* (`confirmSchemaUpgrade`). Its own code, beside
627-
* {@link ACCESS_UPGRADE_CONFIRMATION_REQUIRED}: its findings and its token are
628-
* its own, so neither confirmation answers the other's question.
629-
*/
630-
const SCHEMA_UPGRADE_CONFIRMATION_REQUIRED = 'SCHEMA_UPGRADE_CONFIRMATION_REQUIRED';
631-
const SCHEMA_UPGRADE_CONFIRMATION_STATUS = 409;
632-
633-
/** The token's topic: a finding set token reads as what it confirms. */
634-
const SCHEMA_UPGRADE_TOPIC = 'schema-upgrade';
635-
636-
/**
637-
* The drift categories a type change must be confirmed under (ruling record
638-
* 6709061297, (ii)). A `safe` change — the installed field had no stored
639-
* column — loses nothing and is reported by the dry run, never refused.
640-
*/
641-
const SCHEMA_UPGRADE_CONFIRMED_CATEGORIES: ReadonlySet<UpgradeDriftCategory> = new Set(['needs_confirm', 'destructive']);
642-
643-
/**
644-
* One finding of the schema upgrade verdict, as the 409 (and the 501) name it
645-
* in `details.findings`: what the comparison found, one readable sentence,
646-
* and — when this runtime's `manifest` service answers `planUpgrade` — the
647-
* rows holding a value in the installed column (`null`: the reading failed).
648-
*/
649-
type SchemaUpgradeFinding =
650-
| {
651-
kind: 'suspected_rename';
652-
object: string;
653-
/** The removed (installed) key. */
654-
field: string;
655-
type?: string;
656-
candidates: Array<{ field: string; type?: string }>;
657-
describe: string;
658-
rows?: number | null;
659-
}
660-
| {
661-
kind: 'type_change';
662-
object: string;
663-
/** The key in the incoming version. */
664-
field: string;
665-
from: string;
666-
to: string;
667-
category: UpgradeDriftCategory;
668-
/** Set when the change rides on a declared rename: the installed key. */
669-
renamedFrom?: string;
670-
describe: string;
671-
rows?: number | null;
672-
}
673-
| {
674-
/** The ledger file exists and would not parse: no installed side to compare. */
675-
kind: 'installed_record_unreadable';
676-
/** The ledger file's basename. */
677-
file: string;
678-
/** The thrower's own words. */
679-
cause: string;
680-
describe: string;
681-
}
682-
| {
683-
/**
684-
* No installed body to compare: the ledger entry parses but carries no
685-
* package body, or the registry serves the package while the ledger
686-
* holds no record of it (an orphaned install) and its row carries none.
687-
*/
688-
kind: 'installed_record_missing';
689-
describe: string;
690-
};
691-
692-
/**
693-
* [epic cloud#3652 Q3, #30884] The verdict step 2c′ gives, read from the
694-
* pure comparison alone (ruling record 6709061297, C3): which declared renames
695-
* which findings need the installer's confirmation, and the token of that
696-
* finding set. Nothing here reads the
697-
* environment: whether an upgrade is refused is decided by the two package
698-
* bodies, never by a reading that could fail.
699-
*
700-
* - A declared rename (`renamedFrom`) is no finding: the column is carried
701-
* (#30885, {@link planInstallDeclaredRenames}), or the install is refused
702-
* before this verdict is asked (step 2c″).
703-
* - A suspected rename always needs confirming.
704-
* - A type change needs confirming when its category is `needs_confirm` or
705-
* `destructive` — on a declared rename too: a declared rename never stands
706-
* in for a type-change confirmation (scope note 6685166393).
707-
* - Removed fields, removed objects, `safe` type changes and seed changes are
708-
* reported by the dry run and refused by nothing.
709-
*
710-
* The token ({@link schemaUpgradeFindingSet}) is a digest of the package id
711-
* and the findings' identities (never of their sentences or readings),
712-
* order-free, so the same two versions always yield the same token and any
713-
* change to the finding set yields another.
714-
*/
715-
function schemaUpgradeVerdict(manifestId: string, plan: PackageUpgradePlan): {
716-
findings: SchemaUpgradeFinding[];
717-
findingSet: string;
718-
} {
719-
const findings: SchemaUpgradeFinding[] = [];
720-
for (const s of plan.suspectedRenames) {
721-
const candidates = s.candidates.map((c) => ({ field: c.field, ...(c.type !== undefined ? { type: c.type } : {}) }));
722-
const added = candidates.map((c) => `${s.object}.${c.field}${c.type ? ` (${c.type})` : ''}`).join(', ');
723-
findings.push({
724-
kind: 'suspected_rename',
725-
object: s.object,
726-
field: s.field,
727-
...(s.type !== undefined ? { type: s.type } : {}),
728-
candidates,
729-
describe: `${s.object}.${s.field}${s.type ? ` (${s.type})` : ''} is removed while ${added} `
730-
+ `${candidates.length === 1 ? 'is' : 'are'} added, and no \`renamedFrom\` links them: if this is a rename, `
731-
+ 'the new field starts empty and the data stays in the old column, which nothing reads any more.',
732-
});
733-
}
734-
for (const t of plan.typeChanges) {
735-
if (!SCHEMA_UPGRADE_CONFIRMED_CATEGORIES.has(t.category)) continue;
736-
const what = t.category === 'destructive'
737-
? 'the new type stores no column, so the values the existing column holds are no longer read'
738-
: 'the existing column keeps its type under the new declaration, and nothing converts the values it holds';
739-
findings.push({
740-
kind: 'type_change',
741-
object: t.object,
742-
field: t.field,
743-
from: t.from,
744-
to: t.to,
745-
category: t.category,
746-
...(t.renamedFrom !== undefined ? { renamedFrom: t.renamedFrom } : {}),
747-
describe: `${t.object}.${t.field}${t.renamedFrom !== undefined ? ` (renamed from ${t.renamedFrom})` : ''} `
748-
+ `changes type ${t.from} → ${t.to} (${t.category}): ${what}.`,
749-
});
750-
}
751-
return { findings, findingSet: schemaUpgradeFindingSet(manifestId, findings) };
752-
}
753-
754-
/**
755-
* The finding set's token: `schema-upgrade:` and 32 hex of a SHA-256 over the
756-
* package id and the findings' identities, string-sorted — never their
757-
* sentences or row counts. The package id is in the digest, so a token issued
758-
* for one package never confirms the same findings on another.
759-
*/
760-
function schemaUpgradeFindingSet(manifestId: string, findings: readonly SchemaUpgradeFinding[]): string {
761-
const identities = findings
762-
.map((f) => JSON.stringify(
763-
f.kind === 'suspected_rename'
764-
? [f.kind, f.object, f.field, f.type ?? null, f.candidates.map((c) => [c.field, c.type ?? null]).sort()]
765-
: f.kind === 'type_change'
766-
? [f.kind, f.object, f.field, f.from, f.to, f.category, f.renamedFrom ?? null]
767-
: f.kind === 'installed_record_unreadable'
768-
? [f.kind, f.file]
769-
: [f.kind],
770-
))
771-
.sort();
772-
const digest = createHash('sha256').update(JSON.stringify([manifestId, identities])).digest('hex').slice(0, 32);
773-
return `${SCHEMA_UPGRADE_TOPIC}:${digest}`;
774-
}
775-
776-
/**
777-
* [epic cloud#3652 Q3, #30884] The verdict when there is no installed side to
778-
* compare: the ledger file would not parse, its entry carries no package body,
779-
* or neither the ledger nor the registry (an orphaned install's row) holds
780-
* one. The upgrade's renames and type changes against the installed version
781-
* cannot be known, and a comparison that did not run is never taken for "no
782-
* finding" (2a, 2b and 2c answer the same way): the one finding names what is
783-
* missing, and its token admits the re-install — the re-install that rewrites
784-
* the record — confirmed and recorded, one round trip, never silently.
624+
* [epic cloud#3652 Q3, #30884] The verdict when the ledger holds no installed
625+
* side to compare: the ledger file would not parse, its entry carries no
626+
* package body, or neither the ledger nor the registry (an orphaned install's
627+
* row) holds one. The platform's rule ({@link installedRecordUnavailableVerdict},
628+
* `@objectstack/metadata-core`) makes it one confirmable finding, never "no
629+
* finding" (2a, 2b and 2c answer the same way); this door writes the finding's
630+
* sentence, naming the ledger file it could not read.
785631
*
786632
* A rename the incoming version declares is judged before this verdict
787633
* (step 2c″), on the physical table: with no installed record it is taken as
788634
* pending, so a transport that cannot carry it refuses, and an extension's
789635
* rename is refused, since whose earlier key it names cannot be told.
790636
*/
791-
function installedRecordUnavailableVerdict(
637+
function ledgerRecordUnavailableVerdict(
792638
manifestId: string,
793639
failure: { file: string; cause: unknown } | undefined,
794-
): { findings: SchemaUpgradeFinding[]; findingSet: string } {
640+
): SchemaUpgradeVerdict {
795641
const consequence = 'so this upgrade cannot be checked for fields it renames or retypes: confirming installs it '
796642
+ 'unchecked, and the install rewrites the record.';
797-
const finding: SchemaUpgradeFinding = failure
643+
return installedRecordUnavailableVerdict(manifestId, failure
798644
? {
799645
kind: 'installed_record_unreadable',
800646
file: failure.file,
@@ -806,11 +652,7 @@ function installedRecordUnavailableVerdict(
806652
kind: 'installed_record_missing',
807653
describe: `This runtime holds no package body of the installed "${manifestId}" (neither its install record `
808654
+ `nor the registry carries one), ${consequence}`,
809-
};
810-
return {
811-
findings: [finding],
812-
findingSet: schemaUpgradeFindingSet(manifestId, [finding]),
813-
};
655+
});
814656
}
815657

816658
/** One side of the comparison, a multi-package artifact folded as `planUpgrade` folds it. */
@@ -4344,7 +4186,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
43444186
// other, never "no finding".
43454187
const installed = this.installedPackageSide(ctx, manifestId, previous);
43464188
const verdict = installed === undefined
4347-
? installedRecordUnavailableVerdict(manifestId, previous.failure)
4189+
? ledgerRecordUnavailableVerdict(manifestId, previous.failure)
43484190
: schemaUpgradeVerdict(manifestId, comparePackageVersions(packageUpgradeSideOf(installed), packageUpgradeSideOf(converted)));
43494191
const { findingSet } = verdict;
43504192
if (verdict.findings.length === 0) return {};

‎packages/metadata-core/src/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ export * from './flow-cycle.js';
163163
// preview an installer reads and the comparison a door decides on are one.
164164
export * from './package-upgrade-plan.js';
165165

166+
// [epic cloud#3652 Q3] The schema upgrade verdict of a plan — which findings
167+
// stop a managed upgrade until confirmed, and the finding set's token — the
168+
// ONE rule the install-local door and a host's install door (the hosted
169+
// control plane) both apply, so a host forwards the platform's verdict.
170+
export * from './package-upgrade-verdict.js';
171+
166172
// [ADR-0146 D3 · ruling record 6691022506] The customization pair of a package,
167173
// looked up through the App that carries it — `pairOf(base)` /
168174
// `isPairOf(pair, base)`. Sunk here because its callers live in
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The schema upgrade verdict (epic cloud#3652 Q3): which plan findings need
5+
* the installer's confirmation, and the finding set's token — the one rule
6+
* the install-local door and a host's install door both apply.
7+
*/
8+
9+
import { describe, expect, it } from 'vitest';
10+
import { comparePackageVersions } from './package-upgrade-plan.js';
11+
import {
12+
installedRecordUnavailableVerdict,
13+
schemaUpgradeFindingSet,
14+
schemaUpgradeVerdict,
15+
SCHEMA_UPGRADE_CONFIRMATION_REQUIRED,
16+
SCHEMA_UPGRADE_CONFIRMATION_STATUS,
17+
} from './package-upgrade-verdict.js';
18+
19+
type Fields = Record<string, Record<string, unknown>>;
20+
21+
const side = (fields: Fields) => ({ objects: [{ name: 'acme_deal', fields }] });
22+
const verdictOf = (before: Fields, after: Fields, packageId = 'com.acme.deals') =>
23+
schemaUpgradeVerdict(packageId, comparePackageVersions(side(before), side(after)));
24+
25+
describe('which findings need confirming', () => {
26+
it('a suspected rename is one finding naming every candidate', () => {
27+
const verdict = verdictOf({ amount: { type: 'number' } }, { total: { type: 'number' } });
28+
expect(verdict.findings).toHaveLength(1);
29+
expect(verdict.findings[0]).toMatchObject({
30+
kind: 'suspected_rename', object: 'acme_deal', field: 'amount', type: 'number',
31+
candidates: [{ field: 'total', type: 'number' }],
32+
});
33+
expect(verdict.findingSet).toMatch(/^schema-upgrade:[0-9a-f]{32}$/);
34+
});
35+
36+
it('a declared rename is no finding', () => {
37+
const verdict = verdictOf({ amount: { type: 'number' } }, { total: { type: 'number', renamedFrom: ['amount'] } });
38+
expect(verdict.findings).toEqual([]);
39+
});
40+
41+
it('a declared rename that also changes a stored type still needs the type change confirmed', () => {
42+
const verdict = verdictOf({ amount: { type: 'number' } }, { total: { type: 'text', renamedFrom: ['amount'] } });
43+
expect(verdict.findings).toEqual([expect.objectContaining({
44+
kind: 'type_change', field: 'total', from: 'number', to: 'text', category: 'needs_confirm', renamedFrom: 'amount',
45+
})]);
46+
});
47+
48+
it('a safe type change, a removed field and an added field are refused by nothing', () => {
49+
// `formula` stores no column: retyping it to a stored type loses nothing.
50+
expect(verdictOf({ score: { type: 'formula' } }, { score: { type: 'number' } }).findings).toEqual([]);
51+
expect(verdictOf({ a: { type: 'text' }, b: { type: 'text' } }, { a: { type: 'text' } }).findings).toEqual([]);
52+
expect(verdictOf({ a: { type: 'text' } }, { a: { type: 'text' }, b: { type: 'text' } }).findings).toEqual([]);
53+
});
54+
});
55+
56+
describe('the finding set token', () => {
57+
it('is the same for the same two versions, whatever the declaration order', () => {
58+
const a = verdictOf({ x: { type: 'text' }, y: { type: 'text' } }, { p: { type: 'text' }, q: { type: 'text' } });
59+
const b = verdictOf({ y: { type: 'text' }, x: { type: 'text' } }, { q: { type: 'text' }, p: { type: 'text' } });
60+
expect(b.findingSet).toBe(a.findingSet);
61+
});
62+
63+
it('names the package: the same findings on another package carry another token', () => {
64+
const fields: [Fields, Fields] = [{ amount: { type: 'number' } }, { total: { type: 'number' } }];
65+
expect(verdictOf(...fields, 'com.acme.other').findingSet).not.toBe(verdictOf(...fields).findingSet);
66+
});
67+
68+
it('reads identities only: a sentence or a row count changes nothing', () => {
69+
const { findings, findingSet } = verdictOf({ amount: { type: 'number' } }, { total: { type: 'number' } });
70+
const read = findings.map((f) => ({ ...f, describe: 'another sentence', rows: 12 }));
71+
expect(schemaUpgradeFindingSet('com.acme.deals', read)).toBe(findingSet);
72+
});
73+
74+
it('is pinned byte for byte: a token a refusal handed out keeps confirming the findings it was issued for', () => {
75+
// These values were minted by the install-local door's own digest before
76+
// it moved here. A change to the digest's input or form invalidates every
77+
// token already handed out, on every door: it is a change of the token
78+
// contract, never a refactor.
79+
expect(verdictOf({ amount: { type: 'number' } }, { total: { type: 'number' } }).findingSet)
80+
.toBe('schema-upgrade:a168d8927e7a5afc25f947ee715fa848');
81+
expect(schemaUpgradeFindingSet('com.acme.deals', [])).toBe('schema-upgrade:c29494e0b3b3e33a84adf0c2188baa37');
82+
});
83+
});
84+
85+
describe('no installed side to compare', () => {
86+
it('is one confirmable finding, never no finding', () => {
87+
const verdict = installedRecordUnavailableVerdict('com.acme.deals', { kind: 'installed_record_missing', describe: 'none held' });
88+
expect(verdict.findings).toEqual([{ kind: 'installed_record_missing', describe: 'none held' }]);
89+
expect(verdict.findingSet).toBe(schemaUpgradeFindingSet('com.acme.deals', [{ kind: 'installed_record_missing', describe: '' }]));
90+
});
91+
});
92+
93+
it('answers with the ledger code at 409', () => {
94+
expect(SCHEMA_UPGRADE_CONFIRMATION_REQUIRED).toBe('SCHEMA_UPGRADE_CONFIRMATION_REQUIRED');
95+
expect(SCHEMA_UPGRADE_CONFIRMATION_STATUS).toBe(409);
96+
});

0 commit comments

Comments
 (0)