Skip to content

Changed app installation writes to be planned before they're stored - #32083

Merged
jonatansberg merged 4 commits into
mainfrom
ber-4035-manifest-write-plans
Oct 29, 2026
Merged

jonatansberg merged 4 commits into
mainfrom
ber-4035-manifest-write-plans

Conversation

@kevinansfield

@kevinansfield kevinansfield commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

ref https://linear.app/ghost/issue/BER-4035/sanitize-app-provided-svg-icon

An approval and a re-check each worked out inside their write transaction what a decision stores, so nothing outside the transaction could tell whether a write would add a manifest row. #32022 has to fetch an app's icon before the transaction, and only for a write that adds a row. Without this, it would repeat that logic beside the approval, the review and the re-check, and keep all of them in step with the writes.

The write is now a plan, decided before anything is stored. approvalWrite and recheckWrite decide on the loaded manifest and turn that decision into a write: nothing, an existing row approved, or a new row that becomes the approved manifest or the pending one. A new row's write carries everything the row needs, the loaded manifest included, so work for that row can be added to the plan. One store carries out a write while the installation is unchanged, in place of storeApproval and storeRecheck.

The planners are pure functions beside decideOnManifest, each a switch over every decision kind, and store is a switch over every write kind, so a new kind of either fails the build. An approval's write can't be one that leaves its manifest pending, so the staff history can't record a manifest as approved while the installation is still suspended.

A use_pending decision now carries the ID of the pending manifest it matched, so an approval no longer needs a fallback for a pending manifest it can't find.

Nothing changes in what's stored.

Where the write is planned

Everything up to the plan is read and decided before the transaction opens. Inside it, store only checks the installation is unchanged and carries out the plan, so anything a new row needs can be prepared in between.

approve / recheckOnce
  pendingManifestOf                  # reads the pending manifest's ID and digest
  approvalWrite | recheckWrite       # pure: decideOnManifest, then the write it plans
  store(current, write)
    whileUnchanged                   # locks the installation, checks its revision
      addManifest(write.manifest)    # add_approved and add_pending only
      activate | suspend

What each decision writes

The decision kinds are the re-check's outcomes. An approval makes the reviewed manifest the approved one whatever changed, so it reuses the row that's already there when it can and otherwise adds an approval row.

Decision Approval writes Re-check writes
unchanged nothing nothing
use_pending approve_existing, the pending row nothing
apply add_approved, an approval row add_approved, an update row
resume approve_existing, the approved row, when nothing differs from it; otherwise add_approved, an approval row add_approved, a resume row
suspend add_approved, an approval row that needed approval add_pending, an update row that needs approval

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0b18db3 and aa92754.

Files selected for processing: 3
  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Recent review details
Context from checks skipped due to timeout: 17
  • GitHub Check: Build Docker Images
  • GitHub Check: Acceptance tests (Node 24.20.0, mysql8)
  • GitHub Check: Build Admin
  • GitHub Check: Build E2E Public App Assets
  • GitHub Check: Unit tests (Node 22.23.4)
  • GitHub Check: Acceptance tests (Node 22.23.4, mysql8)
  • GitHub Check: Stripe fixture checks
  • GitHub Check: Legacy tests (Node 22.23.4, mysql8)
  • GitHub Check: Legacy tests (Node 24.20.0, mysql8)
  • GitHub Check: Unit tests (Node 24.20.0)
  • GitHub Check: i18n
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: Check app version bump
  • GitHub Check: Check migration integrity
  • GitHub Check: Detect Tinybird changes
  • GitHub Check: Analyze (javascript-typescript)
Additional context used
Code guidelines: 6
ghost/core/server/services/README.md — auto-discovered
docs/practices/error-handling.md — configured
docs/codebase/jobs.md — configured
tools/README.md — configured
docs/contributing/testing.md — configured
docs/codebase/monorepo-structure.md — configured
Path-based instructions: 10
Review new or changed service boundaries for explicit dependency ownership, deterministic/idempotent initialisation, boot ordering, transaction and event semantics, cache coherence, and restart/multi-instance safety.

CodeRabbit configuration file

Files:

  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Review whether tests prove changed behaviour, meaningful error/edge paths, and externally observable contracts without coupling to implementation details.

CodeRabbit configuration file

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
Review lens: "where does this data become trusted?" Boundary data (HTTP input, external API/SDK responses, env/config, DB/filesystem reads, queue/webhook/event payloads) is `unknown` until validated — Zod by default.

CodeRabbit configuration file

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Prioritise concrete correctness, security, data-integrity, compatibility, and regression risks.

CodeRabbit configuration file

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Applicability reference: AGENTS.md: # AGENTS.md **Ghost Core:** use the [server map](docs/codebase/monorepo-structure.md#ghost-core) and read the [services guide](ghost/core/server/services/README.md) before Source excerpt...

CodeRabbit inference engine (ghost/core/server/services/README.md)

Files:

  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Source excerpt: Use that fallback when there is no safe, useful message.

CodeRabbit inference engine (docs/practices/error-handling.md)

Files:

  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Source excerpt: Jobs run in-process and share the main process's initialized services.

CodeRabbit inference engine (docs/codebase/jobs.md)

Files:

  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Applicability reference: AGENTS.md: # AGENTS.md **Repository tooling:** read the [tooling ownership guide](tools/README.md) Source excerpt: These rules apply to every directory named `scripts`, including new directories at...

CodeRabbit inference engine (tools/README.md)

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Applicability reference: AGENTS.md: # AGENTS.md Start with: [Testing](docs/contributing/testing.md) Source excerpt: Put tests as close as possible to the code and behavior under test: **Unit tests** cover a function, component, or package i...

CodeRabbit inference engine (docs/contributing/testing.md)

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
Applicability reference: AGENTS.md: # AGENTS.md Start with: [Monorepo structure](docs/codebase/monorepo-structure.md) AGENTS.md: # AGENTS.md **Ghost Core:** use the [server map](docs/codebase/monorepo-structure.md#ghost-core) Source excerpt...

CodeRabbit inference engine (docs/codebase/monorepo-structure.md)

Files:

  • ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts
  • ghost/core/server/services/app-installations/decide-on-manifest.ts
  • ghost/core/server/services/app-installations/service.ts
Additional comments: 3
ghost/core/server/services/app-installations/decide-on-manifest.ts: 1

37-41: LGTM!

Also applies to: 44-48, 78-156

ghost/test/unit/server/services/app-installations/decide-on-manifest.test.ts: 1

134-208: LGTM!

ghost/core/server/services/app-installations/service.ts: 1

322-322: LGTM!

Also applies to: 324-325, 328-329, 333-334, 336-336, 338-359

Walkthrough

Manifest decisions now use discriminated variants. Pending decisions include the matched manifest ID. New mapping functions produce typed write actions for approval and re-check flows. Both flows use shared storage, and pending manifests include their ID and digest. Unit tests cover pending-manifest reuse and approval and re-check write mappings.

Possibly related PRs

  • TryGhost/Ghost#32077: Adds the app-installations repository and moves persistence into it. This change updates the repository’s addManifest contract and uses planned writes.
  • TryGhost/Ghost#32022: Extends this change’s planned-write contract with PlannedRow and generic ManifestWrite values.
  • TryGhost/Ghost#31999: Creates the app-installation tables and defines fields used by the manifest rows written in this change.

Priority: Low

Change: Refactor

Merge Risk: Minimal · up to aa927

The refactor preserves the reviewed installation-write behavior. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 7
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: app-installation writes are planned before storage.
Description check Passed The description directly explains the write-planning changes, including approvalWrite, recheckWrite, shared store behavior, and transaction timing.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Type-Safe Boundaries Passed PASS. The PR changes internal planning and storage calls. Its database reads remain decoded with existing Zod schemas, including findDigest and whileUnchanged. LoadedManifest comes from the exis…
New Files Are Typescript Passed The authoritative PR diff contains four modified .ts files and no added files. It adds no .js, .jsx, .cjs, or .mjs source file, so the failure condition does not apply.
Tooling Ownership Passed PASS. The PR changes only four domain-service and unit-test files under ghost/core/server/services/app-installations and ghost/test/unit/server/services/app-installations. It adds no scripts, tool…
Full details: Type-Safe Boundaries

Explanation

PASS. The PR changes internal planning and storage calls. Its database reads remain decoded with existing Zod schemas, including findDigest and whileUnchanged. LoadedManifest comes from the existing validated manifest loader. The new AddedRow type uses z.infer<typeof AppInstallationManifestSource>. The production diff adds no any, unchecked as, @ts-ignore, or @ts-nocheck, and it does not duplicate a Zod-described shape.

Full details: Tooling Ownership

Explanation

PASS. The PR changes only four domain-service and unit-test files under ghost/core/server/services/app-installations and ghost/test/unit/server/services/app-installations. It adds no scripts, tools, shared configuration, or moved paths. The service README permits supporting implementation inside the owning service, and the test remains beside its owner. No tooling placement or execution issue is introduced.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit aa92754

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 1m 47s View ↗
nx run ghost:test:integration ✅ Succeeded 1m 50s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 3m 42s View ↗
nx run ghost:test:e2e ✅ Succeeded 3m 36s View ↗
nx run ghost:test:legacy ✅ Succeeded 2m 19s View ↗
nx run ghost:test:ci:unit ✅ Succeeded 1m 39s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 59s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 23s View ↗
Additional runs (6) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-29 08:50:07 UTC

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.58%. Comparing base (697ae21) to head (aa92754).

Files with missing lines Patch % Lines
.../core/server/services/app-installations/service.ts 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #32083      +/-   ##
==========================================
+ Coverage   85.53%   85.58%   +0.05%     
==========================================
  Files        1412     1412              
  Lines       52858    52866       +8     
  Branches     9073     9073              
==========================================
+ Hits        45211    45248      +37     
+ Misses       6557     6537      -20     
+ Partials     1090     1081       -9     
Flag Coverage Δ
e2e-tests 72.73% <92.30%> (+0.14%) ⬆️
unit-tests 68.26% <82.05%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

kevinansfield and others added 4 commits October 29, 2026 09:33
ref https://linear.app/ghost/issue/BER-4035/sanitize-app-provided-svg-icon

An approval and a re-check each worked out inside their write what a
decision stores, so nothing outside the transaction could tell whether a
write would add a manifest row. Work that has to happen before the
transaction for a new row only, such as fetching an app's icon, would have
had to repeat that logic beside each write and keep it in step.

- Added approvalWrite and recheckWrite, which turn a decision into the write
  it stores: nothing, an existing row approved, or a new row
  - Pure functions beside decideOnManifest, each a switch over every kind,
    so a new kind fails the build in both
- Replaced storeApproval and storeRecheck with one store that carries out
  a write
- A use_pending decision now carries the pending manifest it matched, so an
  approval no longer needs a fallback for a pending manifest it can't find
ref https://linear.app/ghost/issue/BER-4035/sanitize-app-provided-svg-icon

A write plan still needed the loaded manifest passed in beside it, and an
approval could plan a write that leaves its manifest pending, which the staff
history would then record as approved. Work for a new row, such as fetching
an app's icon, belongs on the plan itself.

- Changed approvalWrite and recheckWrite to decide on the manifests
  themselves, so both take the same inputs and the installation is passed once
- Split the add write into add_approved and add_pending, and typed an
  approval's write so it can't leave its manifest pending
- A new row's write carries the repository's AddedManifest, which now holds
  the loaded manifest, so store needs only the plan
- Restored the exhaustive check in store, so a new write kind fails the build
  at the switch
…row`

ref https://linear.app/ghost/issue/BER-4035/sanitize-app-provided-svg-icon

A write plan's new manifest row was called `manifest`, so reaching the
app's icon read `write.manifest.loaded.manifest.icon`: three different
things all called manifest. Calling it a row, as the glossary and schema
already do, leaves `manifest` meaning only the manifest itself.
ref https://linear.app/ghost/issue/BER-4035/sanitize-app-provided-svg-icon

Several comments described the code in roundabout phrasing ("let go of",
"what storing a decision writes, decided before anything is written") that
took a few reads to follow. They now say plainly what each write does and why
the plan exists, so future readers don't have to trace `activate` and the
transaction to work it out.
@jonatansberg
jonatansberg force-pushed the ber-4035-manifest-write-plans branch from 0b18db3 to aa92754 Compare October 29, 2026 08:42
@jonatansberg
jonatansberg merged commit 7d630e0 into main Oct 29, 2026
61 checks passed
@jonatansberg
jonatansberg deleted the ber-4035-manifest-write-plans branch October 29, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants