Skip to content

Commit 5d8c404

Browse files
committed
docs(changeset): the copy record's instance tie and its residuals; the extra uninstall cleanup outcome
Also pins on the real boot that the record keeps the base's package-store row and that a restart keeps its `created_at`. Claude-Session: https://claude.ai/code/session_01FEkQ5pQJCx8STEq28nr3Ej Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c1840d8 commit 5d8c404

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎.changeset/30808-unmanaged-copy-sample-data.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
feat(cloud-connection,metadata-protocol): an unmanaged install can copy the package's sample data, when asked (`seedSampleData: true`), owned by the installer and purged by its seed receipt
77

8-
Clause-②: yes (widening) — `POST /marketplace/install-local` accepts `seedSampleData` beside an unmanaged install, `POST /marketplace/install-local/:id/purge-sample-data` now reaches an unmanaged copy this door made (it answered 404 for every id without a ledger entry), and `importUnmanagedPackage` takes a door-stated `seedData`
8+
Clause-②: yes (widening) — `POST /marketplace/install-local` accepts `seedSampleData` beside an unmanaged install (and its answer may carry `copyRecord` when the door's record of the copy was not kept), `POST /marketplace/install-local/:id/purge-sample-data` now reaches an unmanaged copy this door made (it answered 404 for every id without a ledger entry), and `importUnmanagedPackage` takes a door-stated `seedData`
99
Metadata-protocol: none
1010

1111
- **`POST /marketplace/install-local` accepts `seedSampleData`** beside `installMode: 'unmanaged'`. It is off by default: without it an unmanaged copy loads no row, as before, and answers the same `seeded: { mode: 'skipped' }`. With `true`, the copy loads the package's `data` datasets once, inline, and answers `seeded: { mode: 'inline', inserted, updated, skipped, errors }` beside `copied`. Every row is owned by the person who installed it (`owner_id` and `created_by`). Rows the package wrote under different personas all collapse to that one owner, so per-role answers in the customer's environment differ from the gallery's per-persona transcripts. Lookups between the copied rows resolve in load order, exactly as on a managed install. `seedSampleData` that is not a boolean, or one sent with a managed install (which always loads its data), answers 400 `INVALID_REQUEST` before anything is written.
1212
- **The seed receipt.** The copy writes each dataset as a `seed` item of the new base (`<object>_seed`, then `<object>_seed_2` for a second dataset of the same object), in the environment's own metadata. Under `targetNamespace` only the dataset's `object` follows the rename; its records and `externalId` are copied verbatim, so the values a lookup or a purge matches never change. A dataset's `files` map is kept in the receipt verbatim and handed to the same loader a managed install uses; loading those bytes on a copy is not exercised by a test here. A dataset the copy cannot write (no `object`, no `records` array) is refused with 400 before any write, and a `seed` item the save door refuses rolls the whole copy back, as every other copied item does. A re-run is still refused with 409.
13-
- **The door's record of its copies.** The install-local door records each unmanaged copy it makes (with or without sample data) in its own storage directory, under `unmanaged-copies/` beside the install ledger, in the same act as the copy. The ledger never reads it as an install entry. The record is removed when the copy's base is uninstalled (through the protocol's uninstall cleanups), and it is lost with the ledger directory, as ledger entries are. A copy made before this release has no record.
14-
- **`POST /marketplace/install-local/:id/purge-sample-data` on a copy** reaches only a base in that record; every other writable base, a Studio-authored one included, keeps the 404. For a recorded copy it reads the receipt and deletes exactly the rows it names, matched by `externalId` (a row the person wrote survives). A copy made without the sample data answers 400 `NOTHING_TO_PURGE` saying no sample data was copied. A record or receipt that cannot be read answers 503 and deletes nothing. Purge before uninstalling the copy: an uninstall removes the receipt and the record with the base, and leaves the rows.
13+
- **The door's record of its copies.** The install-local door records each unmanaged copy it makes (with or without sample data) in its own storage directory, under `unmanaged-copies/` beside the install ledger, in the same act as the copy. The ledger never reads it as an install entry. The record is removed when the copy's base is uninstalled (through the protocol's uninstall cleanups), and it is lost with the ledger directory, as ledger entries are. A copy made before this release has no record. The record is tied to the base instance, not only to its id: it keeps the `version` and `created_at` of the base's row in the package store (`sys_packages`), and the purge answers 404 when that row is gone or carries another `created_at`, so a later base under the same id (a Studio duplicate also defaults to `<id>-copy`) never inherits the purge, even when the record outlived the copy. Two conditions stay open: a runtime with no `package` service persists no base row, so its record holds no instance and the purge's reach there is by id alone; and `created_at` has one-second resolution, so a base uninstalled and re-created under the same id within the same second shares it. When the record cannot be kept (its file cannot be written, or the package store does not answer with the new base's row), the install still answers 200 and says so in `copyRecord: { written: false, message }`; that copy is then out of the purge's reach. The answer carries no `copyRecord` when the record was kept.
14+
- **The uninstall answers carry one more cleanup outcome.** The door registers the uninstall cleanup `install-local:unmanaged-copy-record`, so every uninstall answer's `cleanups` list now includes its outcome (`{ name: 'install-local:unmanaged-copy-record', success: true, removed: 0 }` for a base that is no recorded copy): the install-local `DELETE`, the protocol's `deletePackage`, and `DELETE /packages/:id` (`persisted.cleanups`, and the partial-failure 400). The shape of those answers is unchanged.
15+
- **`POST /marketplace/install-local/:id/purge-sample-data` on a copy** reaches only a base in that record; every other writable base, a Studio-authored one included, keeps the 404. For a recorded copy it reads the receipt and deletes exactly the rows it names, matched by `externalId` (a row the person wrote survives). A copy made without the sample data answers 400 `NOTHING_TO_PURGE` saying no sample data was copied. A base that is no longer installed answers 404 before its record is read. A record that cannot be read answers 503 naming the local record file to repair; a receipt or a package-store row that cannot be read answers 503 asking for a retry. Neither deletes anything. Purge before uninstalling the copy: an uninstall removes the receipt and the record with the base, and leaves the rows.
1516
- **`importUnmanagedPackage`** (metadata-protocol) takes the door-stated `seedData: true`, read off before the request is parsed, like `actor`. The published `ImportUnmanagedPackageRequestSchema` is unchanged.
1617

1718
A boot never applies the receipt, so a restart after the copy or after the purge inserts no row, and a plain save of a copied `seed` item loads nothing. Drafted and published, a copied `seed` item behaves as every environment `seed` item does: create-only, matched by `externalId`. Published after a purge, it loads its rows again under the publish rule, not the installer's: the publish names no person, so those rows carry no `owner_id` or `created_by`.

‎packages/qa/dogfood/test/install-local-unmanaged-seed-copy.dogfood.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
// 4. a restart on the same database inserts no row (the receipt is not a
2222
// boot-time load);
2323
// 5. the purge deletes exactly the 28 copied rows and keeps a row the
24-
// person wrote; a second restart inserts none of them back.
24+
// person wrote; a second restart inserts none of them back;
25+
// 6. the door's record of the copy is tied to the base's row in the
26+
// package store (`version` and `created_at`), and a restart keeps that
27+
// row's `created_at`, so the purge in boot 2 still reaches the copy.
2528
//
2629
// Boots fixture stacks of its own (a database file across restarts), so it
2730
// stays out of `SHARED_SHOWCASE`.
2831

29-
import { mkdtempSync, rmSync } from 'node:fs';
32+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
3033
import { tmpdir } from 'node:os';
3134
import { join } from 'node:path';
3235

@@ -83,6 +86,7 @@ describe('dogfood: an unmanaged copy with its sample data (#30808)', () => {
8386
let dbDir: string;
8487

8588
let install: Answer;
89+
let record: any;
8690
let afterInstall: Record<string, number>;
8791
let owners = new Set<string>();
8892
let creators = new Set<string>();
@@ -111,6 +115,7 @@ describe('dogfood: an unmanaged copy with its sample data (#30808)', () => {
111115

112116
install = await json(await stack.apiAs(token, 'POST', ROUTE, installBody()));
113117
afterInstall = await countRows(ql);
118+
record = JSON.parse(readFileSync(join(storageDir, 'unmanaged-copies', `${BASE_ID}.json`), 'utf8'));
114119
for (const object of Object.keys(SEEDED)) {
115120
for (const row of rowsOf(await ql.find(object, { context: SYS }))) {
116121
owners.add(String(row.owner_id));
@@ -161,6 +166,12 @@ describe('dogfood: an unmanaged copy with its sample data (#30808)', () => {
161166
expect(seeds, JSON.stringify(install.body?.data?.copied)).toEqual(Object.keys(SEEDED).map((o) => `${o}_seed`).sort());
162167
});
163168

169+
it('the door\'s record of the copy is tied to the base\'s package-store row, and the answer carries no `copyRecord`', () => {
170+
expect(install.body?.data).not.toHaveProperty('copyRecord');
171+
expect(record).toMatchObject({ baseId: BASE_ID, seeded: true, instance: { version: expect.any(String), createdAt: expect.any(String) } });
172+
expect(record.instance.createdAt).not.toBe('');
173+
});
174+
164175
it('every copied row is owned by the person who installed it', () => {
165176
expect(typeof personId).toBe('string');
166177
expect([...owners]).toEqual([personId]);

0 commit comments

Comments
 (0)