Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c30e4e5
spec: tombstone view-held forms and the _views form translation tails
claude Dec 1, 2026
c94e22f
spec: keep the one-arm view item a discriminated union; ledgers follow
claude Dec 1, 2026
41518eb
spec: rewrite the view tests to the list-only answer
claude Dec 1, 2026
2c349f4
spec: expandViewContainer stays the raw expansion; add expandServedVi…
claude Dec 1, 2026
ced3490
rest: pin a stored container's form members as stored forms on both d…
claude Dec 1, 2026
d42ef2b
metadata-protocol, rest: a view read serves lists only; the form read…
claude Dec 1, 2026
240a1f5
spec: type getUiView's form answer as the form scaffold
claude Dec 1, 2026
3e79559
Merge origin/main into claude/project-thread-d63y4z
claude Dec 1, 2026
1a23b3c
docs(spec): the form-type-switch marker has two writers and a reader
claude Dec 1, 2026
35399e5
spec: the view item kind's variant ledger row follows the one-arm union
claude Dec 1, 2026
b2a4606
feat(runtime,cli)!: os serve refuses a database whose protocol-19 swi…
claude Dec 1, 2026
fb52fe6
spec: the form ledger, the translation ledger and the view prose foll…
claude Dec 1, 2026
7a58315
test(runtime): pin the no-ledger refusal and the declared order after…
claude Dec 1, 2026
07d7dcf
spec: tree-scoped absence pin for the view's retired form slots
claude Dec 1, 2026
3b17ebd
spec: the form-slot pin's scanner states its key-position rule once
claude Dec 1, 2026
ab69a2f
spec: the form-slot pin's neighbours hold the comment and string skips
claude Dec 1, 2026
5468184
test(cli): the switch record is what the served boot reads; the flush…
claude Dec 1, 2026
1bb1e92
test(cli): a switch birth marker the flush cannot write is handed to …
claude Dec 1, 2026
dfaf069
test(dogfood): the protocol-19 boot refusal is the way through, measu…
claude Dec 1, 2026
0d00ceb
test(cli): a real os serve boot refuses a database with no protocol-1…
claude Dec 1, 2026
390594f
Merge lane A boot guard into the lint lane base
claude Dec 1, 2026
4ed889b
feat(metadata-protocol,spec)!: a by-name `view` read serves lists onl…
claude Dec 1, 2026
3ef7c21
Merge lane A boot guard into the PR branch
claude Dec 1, 2026
2e3e0f3
test(rest): two addresses a stored old-shape body alone closes on a 1…
claude Dec 1, 2026
2deb87e
test(dogfood): five public-form fixtures author the form as a form item
claude Dec 1, 2026
65155e4
Merge lane C2 dogfood fixtures into the PR branch
claude Dec 1, 2026
fb66abb
feat(runtime,spec,plugin-auth): the protocol-19 boot refusal carries …
claude Dec 1, 2026
fff47a9
test(plugin-auth): the guard-ordering pin pays its dist-resolved load…
claude Dec 1, 2026
573b29b
Merge lane A follow-up (error code, auth start order) into the PR branch
claude Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 10 additions & 214 deletions content/docs/references/ui/view.mdx

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/audits/2026-07-unknown-key-strictness-ledger.counts/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `strict` column is the one the campaign schedules against; it counts both th

| Dir | Sites | strict | passthrough | catchall | strip |
|---|---|---|---|---|---|
| `ui/` | 233 | 223 | 6 | 0 | 4 |
| `ui/` | 231 | 221 | 6 | 0 | 4 |

## `ui/` — sites

Expand All @@ -45,25 +45,25 @@ classify and is not listed (it becomes reportable the day it grows its first sit
| `report.zod.ts` | 4 |
| `responsive.zod.ts` | 1 |
| `sharing.zod.ts` | 1 |
| `view.zod.ts` | 67 |
| `view.zod.ts` | 65 |
| `widget.zod.ts` | 1 |
| **total** | **233** |
| **total** | **231** |

## `ui/` — open

Per file, how many of its sites still silently discard unknown keys. The `Class`
column that decides the bucket split is hand-written in the ledger; the arithmetic
over it is here.

**4 strip of 233**, in 4 file(s).
**4 strip of 231**, in 4 file(s).

| File | Strip | Sites |
|---|---|---|
| `action-params.zod.ts` | 1 | 1 |
| `app.zod.ts` | 1 | 20 |
| `view.zod.ts` | 1 | 67 |
| `view.zod.ts` | 1 | 65 |
| `widget.zod.ts` | 1 | 1 |
| **total** | **4** | **233** |
| **total** | **4** | **231** |

| Bucket | Sites |
|---|---|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,32 @@ import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import Database from 'better-sqlite3';
import { ORGANIZATION_OWNERSHIP_MIGRATION_ID, ORGANIZATION_OWNERSHIP_SHAPE_GENERATION } from '@objectstack/spec/system';
import { assertOrganizationOwnershipMigrated, isOrganizationOwnershipBootRefusal } from '@objectstack/runtime';
import {
FORM_TYPE_SWITCH_MIGRATION_ID,
ORGANIZATION_OWNERSHIP_MIGRATION_ID,
ORGANIZATION_OWNERSHIP_SHAPE_GENERATION,
} from '@objectstack/spec/system';
import {
assertFormTypeSwitched,
assertOrganizationOwnershipMigrated,
isFormTypeSwitchBootRefusal,
isOrganizationOwnershipBootRefusal,
} from '@objectstack/runtime';
import { isExitSignal } from '../../utils/format.js';
import { bootSchemaStack } from '../../utils/schema-migrate.js';
import MigrateApply from './apply.js';

// Pay the first transform of the dist-resolved workspace deps the command
// reaches through dynamic `import()`s at MODULE LOAD, not inside a case.
import '@objectstack/objectql';
import '@objectstack/service-datasource';
import '@objectstack/driver-turso';
import '@objectstack/driver-sql';
import '@objectstack/platform-objects/plugin';
import '@objectstack/platform-objects/system';
import '@objectstack/plugin-security';
import '@objectstack/rest';
import '@objectstack/metadata-protocol';

const HERE = dirname(fileURLToPath(import.meta.url));
const CLI_ROOT = resolve(HERE, '..', '..', '..');
Expand Down Expand Up @@ -119,7 +136,10 @@ const markerRows = (file: string): Array<Record<string, unknown>> =>
* the data stack alone registers no `sys_migration`, and the guard is inert
* there — it would admit every file. Case (b)'s refusal is the control.
*/
async function guardVerdict(file: string): Promise<void> {
async function guardVerdict(
file: string,
judge: (engine: never) => Promise<void> = (engine) => assertOrganizationOwnershipMigrated(engine),
): Promise<void> {
const stack = await bootSchemaStack({
jsonOutput: false,
databaseUrl: `file:${file}`,
Expand All @@ -131,7 +151,7 @@ async function guardVerdict(file: string): Promise<void> {
});
try {
const engine = (stack.kernel as { getService: (name: string) => unknown }).getService('objectql');
await assertOrganizationOwnershipMigrated(engine as never);
await judge(engine as never);
} finally {
await stack.shutdown();
}
Expand Down Expand Up @@ -239,3 +259,47 @@ describe('os migrate apply writes the organization-ownership birth marker on a d
expect(markerRows(file)).toEqual(before);
}, CASE_TIMEOUT_MS);
});

/**
* [ADR-0159 D7; ruling record 7308112533] The same flush writes the
* protocol-19 switch's BIRTH MARKER, on the same counts: a database `os
* migrate apply` created from empty stores no form, so its switch is recorded
* at birth and the served boot's guard (`assertFormTypeSwitched`, read as
* above on a boot that creates nothing) admits it. A database the apply did
* not create gets none, though the flush creates a table in it, and the guard
* still refuses it, naming the switch command.
*/
describe('os migrate apply writes the protocol-19 switch birth marker on a database it created from empty', () => {
const switchRows = (file: string): Array<Record<string, unknown>> =>
withDb(file, (db) => db.prepare('SELECT * FROM sys_migration WHERE id = ?').all(FORM_TYPE_SWITCH_MIGRATION_ID) as Array<Record<string, unknown>>);
const switchVerdict = (file: string) => guardVerdict(file, (engine) => assertFormTypeSwitched(engine));

it('an empty file: one verified birth row naming protocol 19, no ceremony claimed, and the guard admits it', async () => {
expect(freshApply.exitCode, JSON.stringify(freshApply.payload).slice(0, 400)).toBe(0);
const rows = switchRows(freshDb);
expect(rows).toHaveLength(1);
expect(rows[0].verified_at).not.toBeNull();
expect(rows[0].applied_at).toBeNull();
expect(Number(rows[0].blocking)).toBe(0);
expect(JSON.parse(String(rows[0].details)).birth).toMatchObject({ protocol: 19 });

await expect(switchVerdict(freshDb)).resolves.toBeUndefined();
}, CASE_TIMEOUT_MS);

it('a database the apply did not create: no birth marker, though the flush creates a table, and the guard refuses it', async () => {
const file = copyOfFresh((db) => {
db.prepare('DELETE FROM sys_migration WHERE id = ?').run(FORM_TYPE_SWITCH_MIGRATION_ID);
db.exec(`DROP TABLE ${DROPPED_TABLE}`);
});

const { payload, exitCode } = await runJson(applyArgv(file));
expect(exitCode, JSON.stringify(payload).slice(0, 400)).toBe(0);
expect(payload.created).toEqual([expect.objectContaining({ table: DROPPED_TABLE, kind: 'create_table' })]);

expect(switchRows(file)).toEqual([]);
const refusal = await switchVerdict(file).then(() => null, (error: unknown) => error);
expect(isFormTypeSwitchBootRefusal(refusal), String(refusal)).toBe(true);
expect((refusal as { reason?: string }).reason).toBe('absent');
expect((refusal as Error).message).toContain("'os migrate protocol --to 19 --apply --yes'");
}, CASE_TIMEOUT_MS);
});
78 changes: 73 additions & 5 deletions packages/cli/src/commands/migrate/protocol.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* ## The fixture
*
* A compiled artifact (`dist/objectstack.json`) whose package ships an object
* and a linked public form in an old shape (`formViews.contact`), over a
* database an older release left behind with, bound to no package:
* and a linked public form as a `form` item (the only shape a protocol-19
* artifact loads: the stack is refused at boot with `view.formViews` in it),
* over a database an older release left behind with, bound to no package:
*
* - a `viewKind: 'form'` row of the package's form that switches it off
* (moves into the package's pair as a declared override);
Expand All @@ -20,6 +21,14 @@
* preview writes nothing; `--apply` over a held deployment writes nothing
* either (no row, no pair, no marker); `--apply` over a deployment that can
* switch moves the row and records the verified `sys_migration` marker.
*
* ## The marker is what the served boot reads
*
* `os serve`'s protocol-19 guard (`assertFormTypeSwitched`,
* `@objectstack/runtime`) is asked here on a boot that creates nothing, so its
* verdict is the marker's alone: it refuses the database before the switch,
* still refuses it after a held `--apply`, and admits it once the command has
* recorded the switch.
*/

import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach, vi } from 'vitest';
Expand All @@ -28,6 +37,7 @@ import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { SqlDriver } from '@objectstack/driver-sql';
import { assertFormTypeSwitched, isFormTypeSwitchBootRefusal } from '@objectstack/runtime';
import { isExitSignal } from '../../utils/format.js';
import { bootSchemaStack } from '../../utils/schema-migrate.js';
import MigrateProtocol from './protocol.js';
Expand Down Expand Up @@ -56,12 +66,17 @@ const FORM = `${OBJECT}.contact`;
const BROKEN = `${OBJECT}.broken`;
const CREATE = `${OBJECT}.create`;
const SLUG = 'contact-m37111';
const formBody = (enabled: boolean) => ({
/** A form's own content: what a `form` item carries at its top level. */
const formContent = (enabled: boolean) => ({
type: 'simple',
sections: [{ fields: ['name'] }],
data: { provider: 'object', object: OBJECT },
sharing: { publicLink: `/forms/${SLUG}`, enabled, allowAnonymous: true },
});
/** The same content as an older release stored it, under a `viewKind: 'form'` row's `config`. */
const formBody = (enabled: boolean) => ({
...formContent(enabled),
data: { provider: 'object', object: OBJECT },
});
const ARTIFACT = {
manifest: { id: PKG, name: 'm37111', version: '2.3.0', type: 'app', namespace: 'm37111' },
objects: [{
Expand All @@ -70,7 +85,8 @@ const ARTIFACT = {
sharingModel: 'private',
fields: { name: { name: 'name', label: 'Name', type: 'text' } },
}],
views: [{ object: OBJECT, list: { type: 'grid', columns: ['name'], data: { provider: 'object', object: OBJECT } }, formViews: { contact: formBody(true) } }],
views: [{ object: OBJECT, list: { type: 'grid', columns: ['name'], data: { provider: 'object', object: OBJECT } } }],
forms: [{ name: FORM, object: OBJECT, label: 'Contact us', ...formContent(true) }],
};

interface SeedRow { type: string; name: string; state: string; body: Record<string, unknown>; packageId?: string }
Expand Down Expand Up @@ -218,6 +234,29 @@ async function switchMarker(dbFile: string): Promise<any> {
}
}

/**
* The served boot's verdict on `dbFile`, as `os serve`'s guard reaches it, from
* a boot that holds its DDL back: it creates nothing, so the guard cannot read
* the store as created from empty and decides on the marker alone. `null` when
* the database would be served, the refusal when it would not.
*/
async function guardRefusal(dbFile: string): Promise<unknown> {
const stack = await bootSchemaStack({
jsonOutput: false,
databaseUrl: `file:${dbFile}`,
deferSchemaDdl: true,
readOnlyProbe: true,
composeHostStack: true,
projectRoot: dir,
});
try {
const engine = (stack.kernel as { getService: (name: string) => unknown }).getService('objectql');
return await assertFormTypeSwitched(engine as never).then(() => null, (error: unknown) => error);
} finally {
await stack.shutdown();
}
}

describe('os migrate protocol --to 19', () => {
it('previews by default: lists the move, says it can switch, writes nothing, exits 0', async () => {
const db = caseDb(templateDb);
Expand Down Expand Up @@ -250,10 +289,17 @@ describe('os migrate protocol --to 19', () => {
expect(applied.payload.refusal).toContain('Nothing was written');
expect(await storeSnapshot(db)).toBe(before);
expect(await switchMarker(db)).toBeUndefined();
// A held switch records nothing, so the served boot still refuses this database.
const refusal = await guardRefusal(db);
expect(isFormTypeSwitchBootRefusal(refusal), String(refusal)).toBe(true);
}, CASE_TIMEOUT_MS);

it('--apply on a deployment that can switch moves the row, checks again, and records the verified switch marker', async () => {
const db = caseDb(templateDb);
// Before the switch the served boot refuses this database, naming this command.
const before = await guardRefusal(db);
expect(isFormTypeSwitchBootRefusal(before), String(before)).toBe(true);
expect((before as Error).message).toContain("'os migrate protocol --to 19 --apply --yes'");
const { payload, exitCode } = await runJson(['--to', '19', '--apply', '--yes', '--database-url', `file:${db}`, '--json']);
expect(payload.error, JSON.stringify(payload).slice(0, 600)).toBeUndefined();
expect(exitCode).toBe(0);
Expand All @@ -270,14 +316,36 @@ describe('os migrate protocol --to 19', () => {
const marker = await switchMarker(db);
expect(marker?.verified_at).toBeTruthy();
expect(marker?.blocking).toBe(0);
// The ceremony ran here: the record says so.
expect(marker?.applied_at).toBeTruthy();
expect(JSON.parse(marker.details).ceremony.removed[0].form).toBe(CREATE);
// The record is what the served boot reads: it admits the database now.
expect(await guardRefusal(db)).toBeNull();
// A second run finds nothing to move, and re-verifies.
const again = await runJson(['--to', '19', '--apply', '--yes', '--database-url', `file:${db}`, '--json']);
expect(again.exitCode).toBe(0);
expect(again.payload.ceremony.written).toEqual([]);
expect(again.payload.ceremony.removed).toEqual([]);
}, CASE_TIMEOUT_MS);

it('a database with no sys_metadata table stores no form: --apply records the switch on the census alone, and claims no ceremony', async () => {
// A file that does not exist yet: no table at all, the marker's included.
const db = join(dir, 'cases', 'no-tables.db');
mkdirSync(dirname(db), { recursive: true });
const { payload, exitCode } = await runJson(['--to', '19', '--apply', '--yes', '--database-url', `file:${db}`, '--json']);
expect(payload.error, JSON.stringify(payload).slice(0, 600)).toBeUndefined();
expect(exitCode).toBe(0);
expect(payload).toMatchObject({ switched: true, canSwitch: true });
expect(payload.counts).toMatchObject({ keep: 0, move: 0, remove: 0, hold: 0 });
expect(payload.ceremony).toMatchObject({ written: [], removed: [], rowsChanged: [] });
const marker = await switchMarker(db);
expect(marker?.verified_at).toBeTruthy();
expect(marker?.blocking).toBe(0);
// `applied_at` says the ceremony ran, and here it was never asked.
expect(marker?.applied_at).toBeNull();
expect(await guardRefusal(db)).toBeNull();
}, CASE_TIMEOUT_MS);

it('refuses a major it does not switch to', async () => {
const db = caseDb(emptyDb);
const { exitCode } = await runJson(['--to', '18', '--database-url', `file:${db}`, '--json']);
Expand Down
26 changes: 22 additions & 4 deletions packages/cli/src/commands/migrate/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,22 @@ async function confirm(question: string): Promise<boolean> {
*
* ⛔ No write precedes the switch verdict: a held precheck writes no form row,
* no pair and no marker; a database whose driver cannot roll back a
* transaction is refused before the ceremony is asked. The marker is the
* switch's record; no boot reads it in this release.
* transaction is refused before the ceremony is asked.
*
* The marker is the switch's record, and the served boot reads it: `os serve`
* refuses to start on a database without it and names this command
* (`FormTypeSwitchBootGuardPlugin`, `@objectstack/runtime`). A database a
* protocol-19 boot created from empty carries it from birth, so a new project
* never runs this command.
*
* ## A database with no `sys_metadata` table
*
* It stores no metadata row, so no form in any shape: there is no ceremony to
* run. Step 1 is skipped, the census of steps 2 and 3 is the empty one, and
* the marker is recorded verified with `applied_at` left unset, because this
* run moved nothing. Where the marker's own table is not there either, the
* run performs the DDL its boot held back before it writes the row: the one
* DDL this command ever performs, and only after the verdict.
*
* ## The refusal
*
Expand Down Expand Up @@ -208,7 +222,9 @@ export default class MigrateProtocol extends Command {
composeHostStack: true,
composeAuthGatedSecurity: true,
serveFlags: { dev: flags.dev === true, ...(flags.preset ? { preset: flags.preset } : {}) },
// The switch writes metadata rows and one `sys_migration` row, never DDL.
// The boot holds its DDL back: the switch writes metadata rows and one
// `sys_migration` row. Its only DDL is the flush below, after the
// verdict, on a database that has no table for that row yet.
deferSchemaDdl: true,
...(apply ? {} : { readOnlyProbe: true }),
});
Expand Down Expand Up @@ -369,7 +385,9 @@ export default class MigrateProtocol extends Command {
passed: true,
blocking: 0,
advisory: 0,
applied: true,
// `applied_at` says the ceremony ran. With no `sys_metadata` table it
// was never asked: the row is the census's verdict alone.
applied: !noMetadataTable,
details: { protocol: to, counts: after.precheck.counts, ceremony: ceremonyJson(result) },
});
if (typeof flagEngine.invalidateDataMigrationFlags === 'function') flagEngine.invalidateDataMigrationFlags();
Expand Down
Loading
Loading