Skip to content

Commit 838bc02

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/issue-23282-version-pr-pre-layout
2 parents 88be631 + 5c9bfb0 commit 838bc02

23 files changed

Lines changed: 2130 additions & 1367 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/plugin-security': patch
3+
---
4+
5+
fix(plugin-security): the position write-through and the row-only position backfill are deleted, and the boot reference report stops reading position rows (ADR-0131 D3, C3 stage 7b)
6+
7+
Clause-②: no
8+
9+
Stage 8 stopped registering the `sys_position` row object, the `sys_position` data-door write-through and the row-only position backfill. This change deletes the modules behind them, `position-write-through` and `position-environment-backfill`. A position is written through the metadata door alone (`PUT /api/v1/meta/position/:name`). No export of the package's entry changes.
10+
11+
What a deployment observes:
12+
13+
- **The boot reference report reads no `sys_position` row.** It still lists, per organization, every position assignment and permission-set grant whose name the security catalog does not resolve, and every grant that names no permission set. It no longer has the two position-row lines ("position(s) … have sys_position rows and no definition" and "position name(s) are carried by more than one sys_position row"). No composition provisions that table any more, so those lines could not fire. Legacy position rows are converted and reported by the upgrade ceremony (ADR-0131 D10).
14+
- The Setup-create refusal for a position name the catalog already holds (`409 UNIQUE_VIOLATION`, raised by the deleted write-through) goes with its module. A `sys_position` data-door create cannot reach the engine any more, so nothing raised it.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/cli': minor
3+
---
4+
5+
feat(cli): `os migrate organization-ownership --apply` — the v18 organization-ownership ceremony's apply step and post-check (ADR-0131 D10, ceremony items 2 to 4)
6+
7+
Clause-②: yes (widening)
8+
9+
The command that planned the ceremony now performs it. Without `--apply` nothing changes: the read-only plan, written to a file. With `--apply`:
10+
11+
- **The backup comes first.** It is the operator's act: pass `--backup-taken`, or answer yes at the prompt. A non-interactive run without the flag is refused before the database is opened.
12+
- **The fates run in order**, each step stopping the run where it meets a blocker:
13+
1. **Attribution** — every NULL `organization_id` row the plan derives an owner for takes it (a parent, subject or holder anchor; under `single`, the Default Organization). A row with no derivable owner is never assigned one: it stays NULL and is listed by id.
14+
2. **Authored catalog rows** — permission sets and positions an organization authored in Setup become environment metadata through the metadata door (under `single`; under a wall they are reported), with each position's binding rows carried into its `permissionSets`.
15+
3. **The verified id→name rewrite** — every `sys_user_permission_set` grant names its set in `permission_set`, then every grant is verified to name a set the security catalog resolves. `permission_set_id` stays.
16+
4. **Mirror deletion** — only after that verification, read again just before the first delete: the seeded catalog copies (per organization and NULL residue), the binding rows, seeded capabilities and seeded templates. Authored, customized and organization-stamped rows stay.
17+
5. **Column drops** — `organization_id` leaves the deployment-level objects through the schema-drift ceremony (`os migrate apply`'s machinery), never a hand `ALTER`. A table whose rows still need another step keeps its column, and the run says why.
18+
- **Idempotent and resumable.** Every write is conditioned on the state it changes, and each finished step is checkpointed in `sys_migration` (row `adr-0131-organization-ownership`); a run interrupted mid-step resumes at that step and never re-derives an owner already written.
19+
- **The post-check** re-reads the plan and reports, per table, what remains. The ledger row records `applied_at` once every step has finished and `verified_at` when the post-check also reads zero discrepancies. Exit code 1 while the ceremony is unfinished or the post-check finds a discrepancy.
20+
- A JSON report is written beside the plan (`organization-ownership-apply-TIMESTAMP.json`, or `--out`); an existing file is never overwritten.
21+
22+
```bash
23+
os migrate organization-ownership --out plan.json # read the plan first
24+
os migrate organization-ownership --apply --backup-taken # then perform it
25+
```

‎content/docs/permissions/system-context.mdx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ that silently does not happen.
109109
| 9b | The master-detail write check the `security` service serves (`checkControlledByParentWrite`, ADR-0055) answers `allow` | plugin-security | Get: `allow` for any record, with no master judged — the write path's own first exit, so a gate composing it admits exactly what the record's own system-context update would. Lose: nothing a caller reaches today: its two consumers, the `sys_attachment` and `sys_comment` parent gates, return before they ask for a system session | `packages/plugins/plugin-security/src/security-plugin.ts#checkControlledByParentWrite` |
110110
| 10 | Anonymous-deny treats the caller as authenticated | core | Get: passes the 401 seam with no `userId` | `packages/core/src/security/anonymous-deny.ts#shouldDenyAnonymous` |
111111
| 11 | Permission-set projection middleware skipped | plugin-security | Lose: projection of permission-set-derived columns | `packages/plugins/plugin-security/src/permission-set-projection.ts#createPermissionSetWriteThrough` |
112-
| 11b | Position write-through skipped — a `sys_position` write is not mirrored into the environment ledger | plugin-security | Get: the package door writes rows for definitions that already have their home, untouched (no boot seeder writes a `sys_position` row, ADR-0131 D2). Lose: a system-written row has no environment definition, so the security catalog read does not resolve it until a data-door edit, or the one-time row-only position backfill, gives it one | `packages/plugins/plugin-security/src/position-write-through.ts#createPositionWriteThrough` |
113112
| 12 | Session-resolution middleware skipped | plugin-auth | Get: no session lookup attempted | `packages/plugins/plugin-auth/src/auth-plugin.ts#start` |
114113
| 13 | Per-request performance timings disclosed | observability | Get: timing headers a normal caller cannot pull | `packages/observability/src/perf-timing.ts#isPerfDisclosurePrincipal` |
115114
| 15 | MCP stdio bridge skips the object API-exposure gate | mcp | Get: the bridge reaches objects whose `apiEnabled` / `apiMethods` would refuse an external caller | `packages/mcp/src/stdio-data-bridge.ts#enforceApiExposure` |

‎content/docs/permissions/tenant-audit-census.mdx‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ what moved this page's population from 225 to 227; nothing about the two sites
8383
changed, only whether this instrument could see them.
8484

8585
**The expensive failure direction is a keyword.** Sites whose receiver the author
86-
typed `any` have no type to read, and there are 42 of them — just under a fifth
86+
typed `any` have no type to read, and there are 40 of them — just under a fifth
8787
of the population, concentrated in exactly the seed and bootstrap paths this
8888
control exists for. Scoring an unreadable receiver as "not an engine" would have
8989
dropped every one of them silently, with a clean exit and a smaller number that
@@ -122,7 +122,7 @@ are reported as `undecidable` rather than assumed either way.
122122

123123
The same holds twice over for the context. An options argument spelled as a
124124
literal can be read; one spelled `options`, `{ ...opts }`, or handed through a
125-
forwarding shim cannot, and **53 of the 228 sites are spelled that way**. A
125+
forwarding shim cannot, and **53 of the 225 sites are spelled that way**. A
126126
context resolved from an inline literal or a local `const` can be tested for
127127
`isSystem`; one arriving from a helper call cannot.
128128

@@ -187,10 +187,10 @@ reproduce them. Where it disagrees, it disagrees on the page:
187187

188188
| carried figure | where it survives | this census |
189189
| :--- | :--- | ---: |
190-
| 175 write call sites | quoted in the merged changeset | **228** |
190+
| 175 write call sites | quoted in the merged changeset | **225** |
191191
| 24 carrying no tenant context | quoted in the merged changeset | **2** provable and tenancy-enabled; **32** more whose options argument is unreadable |
192-
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **155 of 228** decidable, **73** undecidable |
193-
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 123 decidably elevated, 0 decidably not, 97 undecidable |
192+
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **153 of 225** decidable, **72** undecidable |
193+
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 120 decidably elevated, 0 decidably not, 97 undecidable |
194194
| 141 and 132, two independent re-derivations | the card that filed this work | — |
195195

196196
**The differences are not reconciled, and deliberately so.** The old census's
@@ -200,18 +200,18 @@ be stated is what this instrument counts, which is written above and re-runnable
200200
at any commit.
201201

202202
Two structural facts do plausibly widen this reading against any hand or regex
203-
one, and both are counted in the generated tables below: the 42 sites reached
204-
through an erased (`any`) receiver, and the 52 that name their object through a
203+
one, and both are counted in the generated tables below: the 40 sites reached
204+
through an erased (`any`) receiver, and the 50 that name their object through a
205205
`const` rather than inline. An instrument that read either the way a person does
206206
would report a smaller number and would not say so.
207207

208208
The fourth row is the one worth flagging to anyone citing it. **The 135 / 77%
209209
figure has no surviving corroboration anywhere in the tree.** This census reads
210-
123 of 228 (54%) as decidably elevated, with 97 more whose elevation is a
210+
120 of 225 (53%) as decidably elevated, with 97 more whose elevation is a
211211
run-time fact — so the claim is neither confirmed nor refuted, and the honest
212212
answer is that a static reading cannot settle it.
213213

214-
⇒ **Cite `2 / 228`, and say what it is**: the sites whose options argument was
214+
⇒ **Cite `2 / 225`, and say what it is**: the sites whose options argument was
215215
READ and holds no tenant context, against a decidably tenancy-enabled object.
216216
That is the control's provable yield surface. ⛔ Do not cite it as "the sites
217217
without tenant context" — **32 further sites** have an options argument this
@@ -223,31 +223,31 @@ cannot read, and they are neither in nor out.
223223

224224
| what | count |
225225
| :--- | ---: |
226-
| write call sites on the application surface | **228** |
227-
| …whose object name is statically decidable | 155 |
228-
| …whose object name is chosen at run time | 73 |
226+
| write call sites on the application surface | **225** |
227+
| …whose object name is statically decidable | 153 |
228+
| …whose object name is chosen at run time | 72 |
229229
| …against an object with tenancy ENABLED | 151 |
230230
| …against an object that declares tenancy off | 1 |
231-
| threading a tenant context | 167 |
231+
| threading a tenant context | 164 |
232232
| PROVABLY carrying none (options read, no context key) | **8** |
233233
| …of those, against a decidably tenancy-enabled object | **2** |
234234
| options argument UNREADABLE — may or may not carry one | 53 |
235235
| …of those, against a decidably tenancy-enabled object | 32 |
236-
| threading a decidably ELEVATED (`isSystem`) context | 123 |
236+
| threading a decidably ELEVATED (`isSystem`) context | 120 |
237237
| threading a context that is decidably NOT elevated | 0 |
238238
| threading a context whose elevation is a run-time fact | 97 |
239239

240240
| how the instrument reached the site | count |
241241
| :--- | ---: |
242-
| receiver carried a readable engine type | 186 |
242+
| receiver carried a readable engine type | 185 |
243243
| receiver erased, placed by the object NAME | 27 |
244244
| receiver erased, placed by an `object: string` PARAMETER | 7 |
245-
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 8 |
245+
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 6 |
246246

247247
| object name spelled inline | 103 |
248-
| object name spelled through a `const` | 52 |
248+
| object name spelled through a `const` | 50 |
249249
| object name is an `object: string` parameter | 9 |
250-
| object name is some other run-time expression | 64 |
250+
| object name is some other run-time expression | 63 |
251251

252252
### Subtractions the census could NOT defend — enforced
253253

@@ -297,12 +297,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
297297
their values are not compared. The reasoning, and the measurement behind it,
298298
are in `scripts/check-tenant-audit-census.mjs`.
299299

300-
Measured on 2026-10-13 at `7c01d30c9`.
300+
Measured on 2026-10-13 at `66949b772`.
301301

302302
| corpus scale (not enforced) | count |
303303
| :--- | ---: |
304-
| tracked non-test sources scanned | 650 |
305-
| engine-shaped types recognised | 73 |
304+
| tracked non-test sources scanned | 648 |
305+
| engine-shaped types recognised | 72 |
306306
| declared objects in the registry | 116 |
307307
| same-named calls subtracted as non-engine | 160 |
308308

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts.md‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ silent, and `node scripts/tenant-audit-census.mjs --write` is the resolution.
3333

3434
| Measure | Value |
3535
|---|---:|
36-
| Write call sites | 228 |
37-
| Object name statically decidable | 155 |
38-
| Object name chosen at run time | 73 |
36+
| Write call sites | 225 |
37+
| Object name statically decidable | 153 |
38+
| Object name chosen at run time | 72 |
3939
| Against a tenancy-enabled object | 151 |
4040
| Against an object declaring tenancy off | 1 |
41-
| Threading a tenant context | 167 |
41+
| Threading a tenant context | 164 |
4242
| Provably carrying none | 8 |
4343
| …and decidably tenancy-enabled | 2 |
4444
| Options argument unreadable | 53 |
4545
| …and decidably tenancy-enabled | 32 |
46-
| Threading a decidably elevated context | 123 |
46+
| Threading a decidably elevated context | 120 |
4747
| Threading a decidably non-elevated context | 0 |
4848
| Threading a context of undecidable elevation | 97 |
4949

@@ -90,12 +90,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
9090
their values are not compared. The reasoning, and the measurement behind it,
9191
are in `scripts/check-tenant-audit-census.mjs`.
9292

93-
Measured on 2026-10-13 at `7c01d30c9`.
93+
Measured on 2026-10-13 at `66949b772`.
9494

9595
| corpus scale (not enforced) | count |
9696
| :--- | ---: |
97-
| tracked non-test sources scanned | 650 |
98-
| engine-shaped types recognised | 73 |
97+
| tracked non-test sources scanned | 648 |
98+
| engine-shaped types recognised | 72 |
9999
| declared objects in the registry | 116 |
100100
| same-named calls subtracted as non-engine | 160 |
101101

@@ -164,9 +164,6 @@ Measured on 2026-10-13 at `7c01d30c9`.
164164
| `packages/plugins/plugin-security/src/permission-set-projection.ts` | `insert` | `object` | undecidable | context, elevation undecidable | 1 |
165165
| `packages/plugins/plugin-security/src/permission-set-projection.ts` | `update` | `object` | undecidable | context, elevation undecidable | 1 |
166166
| `packages/plugins/plugin-security/src/permission-set-projection.ts` | `delete` | `sys_permission_set` | undeclared-name | elevated | 1 |
167-
| `packages/plugins/plugin-security/src/position-environment-backfill.ts` | `insert` | `DATA_MIGRATION_FLAG_OBJECT` | undecidable | elevated | 1 |
168-
| `packages/plugins/plugin-security/src/position-write-through.ts` | `delete` | `sys_position` | undeclared-name | elevated | 1 |
169-
| `packages/plugins/plugin-security/src/position-write-through.ts` | `update` | `sys_position` | undeclared-name | elevated | 1 |
170167
| `packages/plugins/plugin-security/src/suggested-audience-bindings.ts` | `delete` | `sys_audience_binding_suggestion` | enabled | context, elevation undecidable | 1 |
171168
| `packages/plugins/plugin-security/src/suggested-audience-bindings.ts` | `insert` | `sys_audience_binding_suggestion` | enabled | context, elevation undecidable | 1 |
172169
| `packages/plugins/plugin-security/src/suggested-audience-bindings.ts` | `update` | `sys_audience_binding_suggestion` | enabled | context, elevation undecidable | 3 |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `os migrate organization-ownership --apply` asks about the backup before it
5+
* opens the database (ADR-0131 D10 ceremony item 2): without `--backup-taken`
6+
* a non-interactive run is refused, and the boot never happens. The flag means
7+
* nothing without `--apply`, and is refused there too.
8+
*/
9+
10+
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
11+
import { fileURLToPath } from 'node:url';
12+
13+
const boot = vi.hoisted(() => vi.fn(async () => {
14+
throw new Error('the database was opened');
15+
}));
16+
vi.mock('../../utils/schema-migrate.js', () => ({ bootSchemaStack: boot }));
17+
18+
type Command = (typeof import('./organization-ownership.js'))['default'];
19+
let MigrateOrganizationOwnership: Command;
20+
21+
// The command's module graph is large, and oclif reads the package's config on
22+
// the first run: both are paid outside the 5 s default (CASE_TIMEOUT_MS).
23+
beforeAll(async () => {
24+
({ default: MigrateOrganizationOwnership } = await import('./organization-ownership.js'));
25+
}, 60_000);
26+
27+
const CASE_TIMEOUT_MS = 60_000;
28+
29+
const CLI_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
30+
31+
async function runJson(argv: string[]): Promise<{ payload: Record<string, unknown>; exitCode: unknown }> {
32+
const chunks: string[] = [];
33+
const savedExit = process.exitCode;
34+
vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => {
35+
chunks.push(String(chunk));
36+
const cb = rest.find((a) => typeof a === 'function') as (() => void) | undefined;
37+
if (cb) cb();
38+
return true;
39+
}) as typeof process.stdout.write);
40+
vi.spyOn(process.stderr, 'write').mockImplementation((() => true) as typeof process.stderr.write);
41+
try {
42+
await MigrateOrganizationOwnership.run(argv, { root: CLI_ROOT });
43+
} catch (error) {
44+
if ((error as { oclif?: unknown }).oclif === undefined) throw error;
45+
}
46+
const exitCode = process.exitCode;
47+
process.exitCode = savedExit;
48+
vi.restoreAllMocks();
49+
return { payload: JSON.parse(chunks.join('').trim()) as Record<string, unknown>, exitCode };
50+
}
51+
52+
afterEach(() => {
53+
boot.mockClear();
54+
});
55+
56+
describe('os migrate organization-ownership --apply — the backup precondition', () => {
57+
it('refuses a non-interactive --apply without --backup-taken, before the boot', async () => {
58+
const { payload, exitCode } = await runJson(['--apply', '--json']);
59+
expect(payload).toMatchObject({ error: 'apply_refused', reason: 'backup-unacknowledged' });
60+
expect(exitCode).toBe(1);
61+
expect(boot).not.toHaveBeenCalled();
62+
}, CASE_TIMEOUT_MS);
63+
64+
it('refuses --backup-taken without --apply, before the boot', async () => {
65+
const { payload, exitCode } = await runJson(['--backup-taken', '--json']);
66+
expect(payload).toMatchObject({ error: 'plan_refused', reason: 'flag-without-apply' });
67+
expect(exitCode).toBe(1);
68+
expect(boot).not.toHaveBeenCalled();
69+
}, CASE_TIMEOUT_MS);
70+
71+
it('with --backup-taken, goes on to the boot', async () => {
72+
const { payload } = await runJson(['--apply', '--backup-taken', '--json']);
73+
expect(payload).toMatchObject({ error: 'boot_failed', reason: 'boot-failed' });
74+
expect(boot).toHaveBeenCalledTimes(1);
75+
expect(boot.mock.calls[0]).toEqual([expect.objectContaining({ deferSchemaDdl: true, composeHostStack: true })]);
76+
}, CASE_TIMEOUT_MS);
77+
});

0 commit comments

Comments
 (0)