Skip to content

fix(patchy): editing a shared fixture no longer wipes an unpublished patch's own rows - #364

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/322-fixture-owned-data
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/322-fixture-owned-data

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Stacked on #363 (branch fix/330-dev-stop).

Before a patch's first publish, editing a shared fixture (even a single row or a comment) wiped the patch's own local rows on the next patchy dev start. Only owned schema changes are supposed to reset local data.

The full-reset check compared the whole local stamp, and that stamp includes the hashes of the shared fixtures. It now compares only the owned-schema part. A fixture edit goes through the existing per-source refresh, which reseeds only the changed shared source. Identity changes, missing storage and real owned-schema changes still reset everything.

Closes #322

Test evidence:

  • New case in packages/patchy/src/devResources.test.ts, built from the issue's reproduction with real PGlite state in a temp dir. It failed before the fix (notes: []) and passes after it. The same case checks that an owned column retype still recreates local data.
  • pnpm typecheck and pnpm lint pass.
  • pnpm test: 953/954 passed. The one failure was a 5s timeout in packages/integrations/src/postgres/Runtime.test.ts while the full suite ran under load. That file passes on its own.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:cli Touches the cli area size:m 100-500 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed d89a9162f729aa7961cfdca76f6117e7ad6f9868 with git diff origin/fix/330-dev-stop...HEAD, against base 03a38b6e7109f19ef3a1bcde3602fc81a521e3db and issue #322. One pass, no subagents. No merge blockers found.

Standards

No merge-blocking method or YAGNI findings. The fix lifts the existing owned-schema hash into a local variable and compares that value directly. It preserves the persisted state format and reuses the existing per-source refresh path; there is no new abstraction or state framework. The regression test exercises real PGlite persistence and runtime handlers across separately scoped preparations.

Spec

No merge-blocking intent findings. The change implements the requested scope: "Use the owned schema portion for the unpublished full-reset decision." Shared fixture edits no longer trigger the whole-database reset, while owned-schema changes, identity changes and missing database storage retain their reset conditions. Published-baseline behavior is unchanged.

The new regression proves that a fixture row edit updates the shared contact without deleting the owned note, then proves that an owned column retype still resets the data. Failed-fixture recovery remains outside this change, as requested.

Verification: pnpm exec vitest run packages/patchy/src/devResources.test.ts passed all 4 tests. These tests use temporary directories. I did not run pnpm dev or the Patchy CLI against existing dev state. No wire contract, CLI output, migration or vocabulary changed; existing reset documentation remains applicable.

Summary: Standards 0 blockers; Spec 0 blockers. No worst issue on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed d89a916 against base 03a38b6 (stacked on #363) and issue #322. Separate passes covered standards, the issue, the reset method, YAGNI, and whether the new test can fail.

Standards

No documented-standard violations. The edit stays inside DevResources.prepare. It adds no service, error, layer, command, flag, or wire field, so the Effect service rules and ADR-0004 stay put. packages/patchy/README.md already says that before the first publish every schema change recreates local rows, and that sentence still describes the code.

The copied Prepared and binding setup matches the other it.live cases in this file. Leaving it inline matches that file.

Spec

The production change matches the scope in #322: "Use the owned schema portion for the unpublished full-reset decision. Retain the existing resets for real schema changes, identity changes and missing storage. Let changedSources refresh only affected shared sources. No new state framework is needed."

initialize now wipes an unpublished database when previousState.value.owned differs. Company id, patch id, a missing company/ directory, and an unreadable stamp still wipe. changedSources still drops and reseeds only the shared source whose fixture hash changed. The stamp shape is the same. Failed-fixture recovery is untouched.

The first assertion is the bug. A title edit in fixtures/shared-contacts.sql updates the contact and keeps the owned note. On the old condition changed is the whole stamp, the fixture body is inside that stamp, and initialize deletes company/ before PGlite opens, so notes comes back empty. A vitest run of this case passed (1 passed, 3 skipped).

A comment-only fixture edit takes that same path. shared[patchId] is a hash of the raw fixture string.

The second assertion does not lock "Retain the existing resets for real schema changes." Changing title from text to integer is NotAdditive (packages/primitives/src/Tables.ts, the kind check). make already drops that patch's schema when the diff is incompatible, even when initialize is false. Provision then builds the new table empty. The shared source is a different patch id, so its rows stay. notes: [] and contacts: ["Updated contact"] still hold if the owned comparison is removed.

An additive change is the case this condition owns. An optional column is compatible, so without initialize the note survives. The owned hash is what recreates those rows before the first publish. This test does not show that.

Method

This is the method the issue named. The owned digest was already manifest.tables, manifest.files, and baseline. The patch names that digest and compares it. changed still rewrites schema.json, so the next start does not treat the same fixture as new.

A fixture-only edit leaves owned equal. changedSources contains the source patch id. make drops p_refsource001 and reruns the fixture. The consumer schema is not in that set, so the note in p_localdev0000 stays.

An unpublished column retype does change owned, and initialize then deletes company/ and content/. That full reset is real. The assertion also passes through the incompatible-schema drop, so it cannot tell which path ran.

Identity change, missing company/, and a corrupt stamp still wipe. Once baseline is defined this arm is false. A first publish that changes patchId away from localdev0000 still wipes through the identity check. That is the old identity reset.

YAGNI

The production diff is the small version. No new type, helper, field, or branch. The comment on the condition should stay. It is what stops the next edit from comparing changed again.

The test is three prepare cycles, which is the size of the fixture claim. A shared harness would be more code than this bug needs. notes! matches the published test in the same file.

Swap the retype for an optional column and keep notes: []. That assertion fails when initialize does not run. Leave the fixture assertion as it is.

Summary: Standards 0 hard findings, no worst issue. Spec 1 partial, and that partial is the retype assertion, which does not isolate the owned-schema reset.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review follow-up, pushed as df13176.

Fixed:

  • The second assertion now proves the owned-schema reset (grok, Spec partial). A text to integer retype is refused as not additive, and make drops that schema on its own path, so the assertion passed with or without the owned-hash check. It now adds an optional body column, which is additive. The note is lost only if the unpublished full reset runs. I checked this by temporarily replacing the owned comparison with false: the test then failed with notes: ['Keep my local work']. With the real condition restored, all 4 tests in devResources.test.ts pass.

Kept as is:

  • Production change in devResources.ts. Both reviews found it matches patchy dev: changing shared fixture rows wipes unrelated unpublished patch data #322's scope with no new abstraction, so it is unchanged.
  • The comment on the initialize condition. grok recommended keeping it so a later edit does not go back to comparing the whole stamp.
  • The inline Prepared and binding setup in the test. It matches the other it.live cases in this file, and a shared harness would add more code than this bug needs.
  • No doc changes. packages/patchy/README.md, docs/product.md and the patchy-loop skill already say only schema changes recreate local data before the first publish.

pnpm typecheck and pnpm lint pass on df13176.

Base automatically changed from fix/330-dev-stop to main September 24, 2026 14:17
allisonmahmood and others added 2 commits September 24, 2026 16:17
…patch's own rows

Before the first publish, dev compared the whole stamp, including shared
fixture contents, to decide on a full local reset. Now only the owned schema
portion drives that reset; a fixture edit refreshes just its source.

Closes #322

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e change

A retype is refused as not additive and dropped on its own path, so it did not
prove the owned-hash reset. An added optional column only loses rows when that
reset runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/322-fixture-owned-data branch from df13176 to 483a491 Compare September 24, 2026 14:17
@allisonmahmood
allisonmahmood merged commit 3168fcd into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/322-fixture-owned-data branch September 24, 2026 14:25
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…ack (#365)

Stacked on #364 (branch fix/322-fixture-owned-data).

If you broke a shared-table fixture in `patchy dev` and then put the original back, that source's local rows stayed empty across every restart. Dev had already recreated the source when the fixture failed, but its stamp still recorded the last good fixture, so restoring those bytes looked like "nothing changed" and the INSERT never ran again.

Now dev removes the changed sources' entries from the stamp before it recreates them. A fixture that fails to seed counts as changed on the next start and gets another try. Other sources' entries and the patch's own rows stay as they are.

Test evidence:
- New `devResources.test.ts` case follows the ticket's steps against a published consumer with one owned row: seed, typo the column (`SharedFixtureInvalid`), restore, restart twice. Before the fix: `contacts: []`. After: the contact is back on both restarts and the owned row is kept. It also passes with the baseline removed (never-published path).
- `pnpm typecheck` and `pnpm lint` are clean. `pnpm test`: 952 passed, 3 hit 5s timeouts in untouched packages (`company-database`, `integrations/postgres`) while other test runs loaded the machine. All 3 pass when re-run alone.

Closes #318

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patchy dev: changing shared fixture rows wipes unrelated unpublished patch data

1 participant