Skip to content

feat(compat): the asset stage, S28, S29, S31 and S33 - #124

Merged
aRustyDev merged 10 commits into
mainfrom
feat/compat-assets
Nov 12, 2026
Merged

aRustyDev merged 10 commits into
mainfrom
feat/compat-assets

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Part of #44 (the asset stage: S28, S29, S31 and S33). Seven commits, in the order to read them, and a merge of main (#121 and #122 landed while this was open; only status.md conflicted, where main had also taken G-26, so this stage's row is G-27). The merged tree was checked again: 3,506 hermetic tests, clippy, and native-memory main at 59 of 59.

What

The four inventory rows the stock app's project creation needs to upload a cover, and the three routes around them that only Thrust has. The cover is the only kind of file built.

  • feat(core) the ADR-0047 lifecycle over an assets table (migration 0016) and BlobStore::head: create_asset, receive_upload, confirm_upload (looks at the object, as ADR-0047's confirmUpload says), attach_project_cover, open_asset, public_asset. The upload grant is a one-time token, kept as a SHA-256.
  • feat(compat) the routes. S28 answers the presigned-PUT shape the app already reads for R2 (method: "PUT", the signed headers) with an address of this API, PUT /api/assets/v2/upload/{asset}/{token}/, because the browser sends the upload with no cookies and no target has an object store it can reach. S33 is a 302 to .../object/, a route that asks who the caller is again. A cover is shown at /api/assets/v2/static/{asset}/. cover_image_url and cover_image_asset on a project now say so.
  • test(adapters) the Postgres SQL against a container: the table's columns and each constraint, the migration run twice, sixteen callers racing for one grant, and a model.
  • test(contract) the cover's journey and the upload's refusals on all four targets (EXPECT_MAIN 57 to 59).
  • fix(compat) five places the recording from the pin showed the routes answering otherwise (below).
  • test(compat) the recorder, ten fixtures, the Rust normaliser and the parity_ tests.
  • docs D-035, G-27, the plan row, the architecture page.

Deviations (D-035, pending your confirmation)

Read the D-035 row in DEVIATIONS.md first; it has the reasons and the pin lines. In short: the upload goes through this API; S29 looks at the object where the pin trusts the client; S33's redirect and the cover's address are Thrust's own routes; the other nine kinds of asset the pin makes, and an entity_identifier that names a project, are refused with a 400 and not made; a size or a name the pin turns into a 500 is a 400; cover_image_asset takes an uploaded cover the caller may attach (D-027 revised). One choice to look at: the app's project settings form sends entity_identifier: <project id>, which on the pin sets the cover when S29 is called. Here it is a loud 400, and a follow-up. Also pending: D-022, D-023, D-025 to D-029; this PR touches none of them.

What the recording showed that the source did not

S33 redirects with attachment and the static route with inline (research/0003 had them the other way). The pin does not look at the object on S29. A path with no asset id is {"error": "Page not found."}. S28 with no entity_identifier is 400. S31's asset_ids is judged as Python judges truthiness, and a text in it is Please provide valid detail, not a 404. All five are fixed in fix(compat).

Verified, and how

Run locally on this branch (final code):

  • cargo nextest run --profile ci --workspace: 3,506 passed. cargo test --doc: clean. cargo fmt --check, clippy --workspace --all-targets -- -D warnings and the wasm32 thrust-worker clippy: clean. check-deps.sh and check-placement.sh: pass.
  • The Postgres asset tests against a container (OrbStack): 5 passed.
  • scripts/contract.sh <target> main: 59 of 59 on native-memory, native-pg, worker-memory and worker-cf (the last with the Worker's R2 binding), after the contract commit; native-memory and worker-cf again on the final code.
  • The recorder: two recordings on fresh oracle stacks are byte-identical, the 56 fixtures before them did not move, and record.py --self-test passes (13 cases).

Controls (rule 8), each a bug planted and removed, in the commit messages: the core model with the project-access check dropped (it did not fail until I biased the strategy and added a coverage assertion; it now fails if a run misses any of 17 situations), a grant not spent and the newest asset as the cover; the same three in the Postgres SQL; S29 trusting the client against the contract journey; a wrong content type and a wrong target on S33's redirect against its parity row.

Not verified

  • CI has not run. The required check is gate.
  • Nothing has been run in a browser: serving the build and the journey are PR D.
  • No test ran against a real R2 bucket, only the Worker's local binding.
  • The Postgres model runs 24 cases (THRUST_MODEL_CASES raises it), and I ran it only at that default. The core model runs 256.

Known limits

  • On native-pg the native server's blob store is in memory, so a restart leaves cover rows whose bytes are gone. ADR-0080's disk adapter is not built. Documented in app.md and G-27.
  • Not built: deletion of an asset, the reaper of assets that were never uploaded (ADR-0047's Scheduler), the other nine kinds, an R2 presign (a follow-up issue, to file after you confirm its text).
  • stage2-contract.sh, the pass against a real deployment, still carries a main count (31) that was already out of step; I did not touch it.

🤖 Generated with Claude Code

aRustyDev and others added 8 commits November 11, 2026 17:42
ADR-0047's lifecycle for the one kind of file the stock app's project creation
uploads, a project's cover (issue #44, S28 to S33): create_asset makes a pending
asset with a one-time grant to upload its bytes, receive_upload spends the grant and
stores them, confirm_upload looks at the object before it marks the asset uploaded,
attach_project_cover gives an uploaded cover to the project it was made for, and
open_asset and public_asset say who may read one.

Ports and adapters: BlobStore gains head (size and type, no bytes), on the memory
store and on R2. Database gains five asset methods: insert_asset, asset,
mark_asset_uploaded, attach_project_cover, and the two that run before any scope
exists, as session does, because the token is the credential: take_upload_grant and
uploaded_asset. Migration 0016 makes the assets table, with CHECKs that make a bad
state unrepresentable (a grant is a token and an expiry together, an uploaded asset
has its time and no grant), and the foreign key from projects.cover_image_asset that
0012 left to this stage. The grant is stored as a SHA-256 digest like a session.

Rules that are Thrust's, not the pin's: the confirm looks at the object where the
pin trusts the client; the grant is one use and an hour; a cover can be named by a
project only if it is uploaded and either the caller's own and unattached or already
that project's (the pin takes the id of any asset, another workspace's included).
S31's pin rule is kept: the caller's own uploads, unattached or already in the
project, anything else left out in silence, and the oldest of several is the cover.

sanitize_filename is the pin's, line by line, with the pin's own examples as cases
and three properties (one safe segment, idempotent, a plain name kept).

Tests, on the memory adapters: the ADR's lifecycle as an example, the size and the
file type over their domains, the grant's hour with an injected clock, and a
model_ test that runs random sequences of create, upload, confirm, open and attach
against a reference model, step by step. It asserts that its sequences reached all 17
situations where a check is the only thing between a caller and a wrong answer, and
three planted bugs each turn it red (the project-access check dropped, a grant that
is not spent, the newest asset as the cover); the first of them passed the model
before the strategy was biased toward an owner attaching their own asset.

Not here: the compat routes, the fixtures, the Postgres adapter's own tests.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… is sent to

The asset stage's four inventory rows, over the use-cases of the last commit, and
what the stock app needs around them.

S28 answers the pin's presigned PUT shape for R2, `upload_data: {method: "PUT",
url, fields: {}, headers: {Content-Type, Content-Length}}`, which the app already
reads (generateFileUploadPayload, getFileUploadRequestOptions), with the address
Thrust's own: PUT /api/assets/v2/upload/{asset}/{token}/. The browser sends that
upload with no cookies, so the token in the address is the credential. The pin's
refusals are carried in its words: an entity type outside its ten (400), a workspace
logo by a non-admin (403), a file type outside the list (400), a size clamped to the
limit in silence. The other nine kinds the pin makes, an admin's workspace logo
among them, are refused with their own 400 rather than made and never read, and so
is an entity_identifier that names an existing project, which the pin would set the
cover of on S29: the app's project settings form sends one, and accepting it without
applying it would be a silent failure.

S29 is 204 as on the pin, after looking at the object. S31 is the pin's bulk rule.
S33 is 302 as on the pin, to .../object/, a route of the same workspace that asks
who the caller is again and sends the bytes as an attachment: a browser follows a
redirect with its cookies, where the pin's presigned URL needed none.
/api/assets/v2/static/{asset}/ is the address project.cover_image_url points at, for
anyone as on the pin's AllowAny, and serves the picture inline with its type pinned
and nosniff.

A project's cover_image_url is the asset's address when it has one, the text it holds
when not, and null when that is empty, as the pin's property has it; one helper now
makes it for the three shapes that carry it. cover_image_asset in a project's create
or patch was a field that named nothing; it now names an uploaded cover the caller may
attach (revising D-027), and a save that repeats the project's own cover is accepted
whoever uploaded it, or an innocuous save by another member would be refused.

Tests (tests/assets.rs, 21): every kind of caller against every row; the pin's
refusal bodies; an upload that is wrong in each way it can be, which spends the
address; a body over the limit, which does not; a project's asset read only by the
project's people; a project made or changed with a cover; and the stock app's whole
sequence, S28, the PUT, S29, S30, S31, S32, S34, and the picture. One of them found a
real bug in the upload route, whose read limit was one byte too generous, so a body
one byte over spent the token and answered 403 instead of 413.

Not here: the oracle fixtures and their parity_ tests, the contract tests on the four
targets, and the docs.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…stgres

The Postgres adapter's asset SQL had no test of its own; the core's model_ test
runs on the memory adapter. This adds, to the pg_adapter suite (a container, run
with --ignore-default-filter):

- the table's 15 columns written out, and each constraint of migration 0016 made to
  fire by name on a row that is otherwise good: the entity type, the state, a size
  of zero, a token digest of the wrong length, a grant that is not a token and an
  expiry together, an uploaded asset with no time (and a pending one with one), a
  user, a workspace and a project that do not exist, and a project of another
  workspace; and the project's cover as a foreign key (a missing asset refused, an
  existing one taken);
- the migration run twice on a database with an asset and a cover, which keeps them
  and the foreign key;
- sixteen callers racing for one upload grant, of whom exactly one wins;
- a model: random sequences of insert, get, mark, take, attach, public read and
  delete, with the answers checked against a reference written from the port's
  documentation and not from either adapter, every asset read back after every step,
  and the project's cover and its stamp. It asserts that its sequences reached all 14
  situations that matter (a grant spent, replayed, wrong, expired at its edge; a mark
  repeated; an attach that leaves some out or replaces the cover; a read of a deleted
  asset), and a second test that the strategy generates every kind of step.

Three bugs planted in the SQL one at a time each turn the model red: a grant that
never expires, the newest asset as the cover, and a deleted asset served publicly.
The model's first run said no sequence had marked an asset twice, because its asset
indices were drawn from all of usize against a list that grows; they now come from a
range of four, so steps land on the same asset.

The table's composite foreign key had the name Postgres gives the second foreign key
on workspace_id, assets_workspace_id_fkey1. It is now named, assets_workspace_project_fkey,
in the migration (which has not shipped), so that the test and a reader can rely on it.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…four targets

Two compat_ tests in the contract suite, which runs against a live server on
native-memory, native-pg, worker-memory and worker-cf (on the last the bytes go
through the Worker's R2 binding, so R2's head is exercised for real):

- a cover is uploaded, confirmed, attached and shown: S28, the browser's PUT with no
  session, S29 (which looks at the object), S33's 302 and the route it names, S30
  and S31, S34, and the picture at the address the project's cover_image_url names,
  for anyone and inline. Each step has its refusal beside it: the second use of the
  address, a stranger's confirm, attach and read, a read of an asset that is stored
  but not confirmed, an empty or unknown bulk list;
- an upload is refused unless it is the file the asset was made for: a type, a byte
  too many and a byte too few each refused and spending the address, an address of
  another asset, a token never made and an asset that does not exist all the same
  403, one byte over the 5 MiB limit a 413 that does not spend it, and the right
  upload still good after all of them.

EXPECT_MAIN is 59 (57 and these two). 59 of 59 on the four targets. Control: with S29
changed to trust the client where the pin does, as it was before this stage, the first
test fails and the guard reports 58 of 59.

stage2-contract.sh, the pass against a real Cloudflare deployment, is not touched: its
main count (31) was already out of step with this one before this change.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…seen to differ

Recording S28, S29, S31 and S33 from the pin showed five places where the routes
answered otherwise than it does, none of which the hermetic tests could see because
they were written from the pin's source:

- a path that holds no asset id is `{"error": "Page not found."}` on the asset routes
  (and the upload route), not the `{"detail": "Not found."}` the project routes give;
- S28 with no `entity_identifier`, or `false`, is 400 `{"error": "The payload is not
  valid"}` (the pin's default is False, which its database refuses), and one that is a
  text but no id is 400 `{"error": "Please provide valid detail"}`, whatever the kind;
  null and the empty text the app sends for a project not made yet are none. This
  comes before the refusal of a kind Thrust does not build, as it does on the pin;
- S31's `asset_ids` is judged as Python does: what is falsy (null, `[]`, `""`, `{}`,
  0, false) is "No asset ids provided", and anything else that is no list of ids, a
  text or a list with a text that is no id, is 400 `Please provide valid detail`,
  where it was a 404 for the ids that name nothing. The decorator still comes first,
  so a stranger is refused before either;
- S33's 302 carries `content-type: text/html; charset=utf-8`, as Django's redirect
  does.

The tests follow: the entity identifiers and the ids of a bulk are listed case by case,
with the decorator's precedence checked for each invalid one. The deviation number in
the comments is D-035.

The static route is X05 in the router's comments: the inventory does not list it, as
it did not list X04.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…eir parity_ tests

tools/compat-record records S28, S29, S31, S33 and the cover's own address (X05, the
inventory does not list it) from the pinned oracle, with its api set to
AWS_S3_UPLOAD_METHOD=put, which is the presigned PUT the stock app reads for R2
(oracle-assets.yml, merged by fresh-oracle.sh). The recorder does the browser's
upload as a precondition of S29 (it is not a Plane route and has no fixture), follows
each redirect to the store once to check what the URL names, and records the four
`-member` rows with the second account made a member by an invitation after every
fixture that needs it outside the workspace. Ten fixtures (S28, S29, S31, S34-after,
S33, X05 and four -member) hold 34, 11, 15, 4, 10, 8 and 2 x 4 exchanges: the refusals
of each route, every kind of asset, the types and sizes, a name with a directory and
a letter outside ASCII, an asset of the other workspace. They sit after X02 because
attaching a cover changes the project's answer, so none of the 56 fixtures before them
moved; two recordings on fresh stacks are byte-identical.

The normaliser, in both halves, learns the presigned URL (normalise.json
`presigned_url`, 4 new cases): the store's origin, the signature, the signing time,
the credential and the lifetime are replaced, the parameters sorted by name, and the
ids in the path (the workspace, the random part of the key) numbered; response
headers are now normalised before the response body, so that a Location's ids are
numbered in the same order in both. 13 cases pass in record.py --self-test and in
parity_normaliser_cases.

What the oracle showed that the pin's source did not: S33 is `attachment` and the
static route `inline` (the research note had them the other way), the pin does not
look at the object on S29, an unknown workspace is the decorator's 403 on every asset
route, a path that is no id is `{"error": "Page not found."}`, and S28 refuses a body
with no entity_identifier. Probed, not recorded: a size of 0 or a negative one gets a
200 on the pin, a non-number a 500.

The replay compares Thrust with these through the projection of D-035 (documented at
the head of the section in tests/common/mod.rs, like D-022's for the sign-in
redirects): the upload address and S33's Location are compared as placeholders when
they are what they should be (an address of this API that names the asset and holds a
token; the object route of the asset the request names); the nine kinds Thrust does
not build are the 400 it gives; the static route's 302 is a 200 with the type the URL
pins; and the ids the dropped parts numbered are taken out of the numbering. Three
exchanges in two rows exist only because the pin does not look at the object, and are
named in a table; a test requires each entry to be one the pin answers differently.

Controls: a changed upload method, content type, length or fields, a swapped refusal, a
changed pinned type and a member outside the project let in are each a divergence; the
renumbering is shown on a small case; and two bugs planted in S33's redirect, a wrong
content type and a wrong target route, each turn parity_s33_read_an_asset red.

Not here: the docs (the next commit).

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… and the architecture

DEVIATIONS.md: D-035 records the seven ways the asset stage differs from the pin and the
one thing it builds: the upload goes to this API at a one-time address because no target
has an object store the browser can reach, S29 looks at the object, S33's redirect and
the cover's address are Thrust's own routes, the other nine kinds and an entity
identifier that names a project are refused rather than made and never read, a size or a
name the pin turns into a 500 is a 400, a cover is named by an uploaded cover the caller
may attach, and S29's body, deletion and the reaper are not built. It is marked pending
the owner's confirmation, with the reason for each, the pin lines read, and the tests. D-027
is revised: `cover_image_asset` is no longer one of the relations that take no row.

docs/src/testing/status.md: G-26 for the asset rows (what is recorded, what is compared
through the projection and what is read from the source, what is not built, the limit on
the four targets, the controls), and G-20's mention of the cover image's asset updated.
.agents/plans/contrail/PLAN.md: M1's row no longer lists the asset stage or the import of
`apps/web` as left. docs/src/architecture/app.md: what is built of assets, and that on
`native-pg` a cover's row outlives its bytes across a restart because the native server's
blob store is in memory.

Refs: plane-byd.3
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
# Conflicts:
#	docs/src/testing/status.md
@aRustyDev
aRustyDev enabled auto-merge (squash) November 11, 2026 23:43
# Conflicts:
#	docs/src/testing/status.md
# Conflicts:
#	docs/src/architecture/app.md
@aRustyDev
aRustyDev merged commit 1d293f2 into main Nov 12, 2026
34 checks passed
@aRustyDev
aRustyDev deleted the feat/compat-assets branch November 12, 2026 00:23
aRustyDev added a commit that referenced this pull request Nov 12, 2026
Brings in the asset stage (#124). The three conflicts are the contract suite's
expected count (main 59 plus this change's one test is 60), the architecture
page's sentence about the compat crate, and DEVIATIONS D-028. The tree is the
one of the rebased commit that was tested: 1265 tests in the three Plane-shaped
crates, the contract suite's main pass 60 of 60 on native-memory, and clippy
clean over the workspace.

Refs: plane-byd.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 12, 2026
`EXPECT_MAIN` is 63: main's 60 (the compat tests of #124 and #127) and this
branch's three. The deployed-Worker count of `stage2-contract.sh` is 57 (the
six `oidc_` tests are skipped there), and the docs say so. The one conflict was
that line of `scripts/contract.sh`.

Measured on native-memory after the merge: the main pass 63 of 63, the sweeper
pass 3 of 3.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 12, 2026
`EXPECT_MAIN` is 65: main's 62 (the compat tests of #124, #127 and #130) and this
branch's three. The deployed-Worker count of `stage2-contract.sh` is 59 (the six
`oidc_` tests are skipped there), and the docs say so. The one conflict was that
line of `scripts/contract.sh`, as at the last merge.

Measured on native-memory after the merge: the main pass 65 of 65, the sweeper
pass 3 of 3.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 12, 2026
…truction, not by a random draw (#131)

`model_asset_methods_match_the_reference_against_postgres` ended with a check
that its 24 random sequences had, among them, reached every one of 14
"situations" (AGENTS.md rule 8: what the model must get to, or it proves less
than it seems to). Some situations need a chain of unlikely steps: a delete is
one step in twenty, and `mark-of-a-deleted-one` then needs a mark of that very
asset. The seed is random, so the check failed on a fair share of runs, each
time for a different situation: `mark-of-a-deleted-one`, `marked-again` and
`cover-replaced` in the three CI failures of one PR (#128, whose changes are
not in this crate), which passed on main's merge commits for #124 and #127.
Nothing the model compares was ever wrong in those runs.

The assertion was wrong, not the code, and it is replaced by a stronger one that
does not depend on chance (AGENTS.md rule 3): three pinned sequences, run first
through the same `run_case` against the same Postgres, reach every situation by
construction, and the test fails at once, naming the situation, if they do not.
The random sequences follow, as before, to look for what no one thought to pin;
what the run reached is printed (`ASSET-MODEL-OBSERVATION`) and no longer
asserted.

Measured (2026-11-11, a real Postgres container): the test passes six times in
a row (each run draws its own seed), and reaches all 14 situations in the pinned
sequences alone. Control: with the last step of the third sequence removed, it
fails with `no pinned sequence gets to "cover-replaced"`.

Refs: #44

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
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.

1 participant