25 Commits
Author SHA1 Message Date
William Dunn 56c3c833bb file-formats: let the codec decide whether JXL reads (#2278)
Every workspace gate with `--all-features` has been failing since #2135 taught
craft-image-codecs to read JPEG XL behind a `jxl` feature. The capability test
asserted that JXL read is `Unsupported`, full stop. With that codec feature on,
`capabilities()` forwards the codec's own answer of `Available`. The assertion
then fails.

This crate cannot read that feature through `cfg!`. The feature belongs to a
dependency. A workspace build turns it on without this crate selecting
anything. An equality against either value is therefore wrong in some build.

The test now asks the codec the same question the code asks it. It compares
the two answers. A build whose codec reads JXL must report `Available`. One whose codec
does not must report `Unsupported`. The mapping has to exist either way. A missing
codec therefore fails an assertion of its own. The comparison is never quietly
skipped. Without `raster-codecs` there is no codec to ask. The answer is
`Unsupported`.

Verified at 1.100.0 on Linux. `cargo test -p craft-file-formats -p craft-image-codecs --all-features --locked` runs the case that was failing and passes. The same test passes with `-p craft-file-formats --all-features` and with `--no-default-features`. clippy with `--all-targets --all-features -D warnings` is clean. `cargo fmt --check` is clean. Making `capabilities()` ignore the codec's read flag fails the test. That is what the comparison is for. The HEIF and deep-EXR failures in that package need the pinned corpus. My checkout has not fetched it.
2026-11-19 00:43:07 -05:00
William Dunn 4141fe7a9f craft-gpu: provider-neutral GPU job traits and the wgpu backend (#663)
* craft-gpu: add the GPU job traits and the shared providers.

This carries over crates/gpu, crates/gpu-wgpu, crates/gpu-null, and crates/gpu-providers from the cut-down #160 branch, with minimal workspace wiring.

None of these crates names a vendor or any app. craft-gpu defines GpuJob and ProviderRegistry. craft-gpu-null is an in-memory context for tests. craft-gpu-providers holds the shared craft.* WGSL providers. craft-gpu-wgpu is the wgpu backend, native and WebGPU.

* craft-gpu: real device wiring, device loss and async readback (RFC-0022)

Addresses skylartaylor's review gate on #663 at 138f7b2. RFC-0022 has merged
since that review. This follows its acceptance requirements.

WgpuContext now requests a real device. DeviceCaps comes from that device,
reflecting the limits and features actually enabled on it. Buffers are real
wgpu::Buffer values when a device exists. The no-adapter case still degrades
to the same staging behavior as craft-gpu-null. The RFC defines that case
explicitly as the no-adapter path. Device loss is registered via
set_device_lost_callback. It surfaces as GpuFault::DeviceLost. It never
surfaces as a panic. The recovery is stated on GpuContext's trait docs.

GpuContext::read_buffer is no longer a required method. The primitives are
request_read and poll_reads. That mirrors craft-worker-host's own
HostMessage::GpuJobs to WorkerMessage::GpuBatchDone split one level down.
read_buffer stays as a default blocking convenience. It resolves immediately
on the null and staging paths. Native wgpu blocks on
Device::poll(wait_indefinitely). On wasm32 it returns GpuFault::Operation,
since a blocking wait there would freeze the one thread map_async's own
callback needs to run on.

crates/gpu-wgpu/src/tests.rs adds a real-backend suite, gated on
adapter-probe plus non-wasm32. It runs upload, readback and device-loss
tests against a real WgpuContext. It also runs three craft-gpu-providers
CPU-stand-in providers against that same real WgpuContext. It skips with a clear message when no adapter is present.
Verified against lavapipe with mesa-vulkan-drivers, using
--features adapter-probe,native-vulkan: every test passes. That run first
caught a real wgpu panic on buffer lengths that are not a multiple of 4,
COPY_BUFFER_ALIGNMENT. The fix pads real buffers transparently. Every caller
still sees exact, unpadded bytes.

docs/gpu-backends.md and docs/gpu-providers.md are updated to match,
including named consumers (the runtime slice first, then EffectCraft and
FilmCraft) and a device-ownership note for when egui's wgpu renderer is also
running.

* craft-gpu: buffer-size guards, empty-buffer parity, read_buffer keeps other completions

Answers the six findings in CodeRabbit review 5852678306 on PR #663.

upload_buffer on the device path refuses a padded size past the device's
max_buffer_size with GpuFault::InvalidJob before creating the buffer.
request_read guards its staging copy the same way. An oversized request
used to reach wgpu as a validation error on the device's error scope.

Empty buffers are accepted everywhere, matching craft-gpu-null and the
documented staging parity. The device path resolves an empty readback
immediately (wgpu refuses an empty map range). The blanket InvalidJob on
empty upload bytes is gone.

read_buffer no longer eats completions that belong to another
outstanding request. The wgpu override re-queues them for the next
poll_reads. The null context gains an override that takes only its own
completion. The trait's default-body contract is documented: with the
default body, do not interleave read_buffer with an outstanding
request_read.

ReadbackProvider validates the storage-binding cap directly. The old
chunk_buffer call allocated a Vec of slices only to drop it.

parse_u32 and params_contain refuse an empty prefix or needle.
windows(0) panics and the crate's rule is never to crash.

The manifest guard test now also rejects *-engine dependency lines, per
docs/gpu-providers.md.

* craft-gpu: per-job batch results, wasm staging reads resolve

Two findings CodeRabbit raised against the carried copy on PR 662, fixed here where the crates live. dispatch_batch now answers per job in input order. The old first-failure abort discarded outcomes earlier providers had already produced, leaving the caller nothing to reply with and no way to name the jobs worth retrying. A job fed by a failed predecessor fails honestly on its own bad handles. On wasm32 read_buffer now serves the staging backing, whose reads resolve synchronously. The backing on that target is always staging today. The refusal remains for a read that did not resolve synchronously, guarding the future wasm device backing where blocking would hang the tab.

* Add free_buffer and device_status to GpuContext.

Two CodeRabbit findings against crates/gpu-wgpu, both answered at the
trait level since craft-gpu-null has the exact same gap.

free_buffer (lib.rs:313). Every upload_buffer call added an entry to a
backend's buffer table. So did every output buffer a provider's job
created. Nothing ever removed one. Repeated jobs retained memory for
the whole lifetime of a context. The new required method releases a
buffer's resources. A freed handle behaves as invalid afterward, the
same fault an unknown handle already produces.

device_status (lib.rs:401). poll_reads can only attach a device-lost
fault to a read it has something to attach it to. A caller whose event
loop only polls, with nothing pending when loss happens, could never
observe it. The new method, default Ok(()), covers that gap directly;
a backend with no concept of device loss needs no override.

MemContext in this crate's own tests gets the same free_buffer shape as
craft-gpu-null, to keep it compiling under the new required method.

* Implement free_buffer for NullContext.

buffers moves from Vec<Vec<u8>> to Vec<Option<Vec<u8>>>. A handle is a
stable index. Freeing a slot replaces it with None. Removing it
instead would shift every later handle's index out from under its
caller. buffer_len and request_read now reject a freed index the same
way they already reject one that never existed.

Two new tests. One frees a handle and checks another's index and bytes
stay untouched. One frees a handle twice, and a handle that never
existed, and confirms both are a harmless no-op.

* Fix the no-device caps fallback, capture allocation failures, free buffers.

Four CodeRabbit findings against this crate.

The no-device fallback in WgpuContext::new called probe_caps() again
on request_device failure (lib.rs:228). A second, successful adapter
query would then report the adapter's advertised limits as if they
came from a granted device, for a context that holds none. It now
falls back to the plain, fixed caps probe_caps's own doc comment
already promises for that case.

Allocation failures during buffer creation used to reach wgpu's
default uncaptured-error handler (lib.rs:299). That handler panics.
The size check already in place only catches a request past the
device's advertised maximum. It says nothing about whether the device
can actually allocate that many bytes right now. An error scope around
both the output-buffer and the read-staging-buffer creation converts a
failure into a GpuFault instead.

free_buffer for WgpuContext (lib.rs:313) matches the Option-wrapped
shape just added to craft-gpu-null. Both backings, staging and real
device, release a buffer's resources and make the handle behave as
invalid afterward, without shifting any other handle's index.

device_status for WgpuContext (lib.rs:401) reports device loss through
the trait method just added to GpuContext. A caller that only polls
can now observe loss even with nothing pending.

New tests cover the fixed fallback value and a regression check that
the new allocation error scope does not misfire on an ordinary
allocation. They also cover free_buffer on both the staging and the
real-device path. One more covers device_status observing a destroyed
device with nothing outstanding. A genuine out-of-memory condition is not reliably
reproducible in CI; the allocation-failure test is the honest half of
that fix this can run.

* Fix the error-scope API call and run cargo fmt.

wgpu 30.0.1's Device has no pop_error_scope method. push_error_scope
returns an ErrorScopeGuard. pop() lives on that guard. Keep the guard
from push_error_scope and call pop() on it.

Also drops an unneeded mut on a test binding that never mutates its
context. Also runs cargo fmt on the lines the Option-wrapped buffer
changes touched.

* Drop a needless return clippy flagged in the adapter-probe lane.

The fallback branch in WgpuContext::new is the function's own tail
expression once the real-device branch above it has already returned
early. The explicit return on it was redundant.

* Run cargo fmt on the no-device fallback branch.

* Pop the OOM scope before the call that would misuse a failed buffer.

upload_buffer popped its scope only after write_buffer. request_read
popped its scope only after the copy and its submission. A buffer that
failed to create is invalid. Using an invalid buffer raises a VALIDATION
error that an OutOfMemory-only scope never catches. The default
uncaptured-error handler still panicked on a failed create even with the
scope in place. Pop right after create_buffer in both paths and return
before the buffer is used again, with a separate scope around the later
write or copy.

write_buffer only queues its copy into wgpu's PendingWrites. An upload
with no following submission kept the destination and staging buffers
alive inside wgpu-core until some other submit happened. upload_buffer now
flushes with an empty queue.submit right after its own write_buffer call.
A free_buffer right after an upload can now actually release the
allocation.

* Run cargo fmt on the new ordering test.

* craft-gpu-wgpu: correct the crate docs on wasm32 read_buffer

The staging backing serves wasm32 reads synchronously since the staging-reads fix. Only a read that did not complete synchronously faults. The crate-level summary still described the old unconditional fault.

* craft-gpu: sync the docs with the implemented readback behavior

Review asked for three corrections. The backends doc, the providers doc and the trait docs now state that both bundled backends override read_buffer's default body and that wasm32 serves the staging read, with a fault only for a read that did not resolve synchronously. The runtime follow-up paragraph now records that #662 consumed it. The software Vulkan container run is described as local testing. Hosted CI coverage and the pilot consumers' browser and hardware validation remain their own requirements. Em dashes swept from both docs per the house writing rules.

* has_device: say the answer once, in this file's own shape

Clippy 1.100.0 refuses the old body under `needless_bool`. The `if` returned a
bool literal with a bare `false` after it. The cfg attribute sat on the `if`
itself. The whole statement therefore vanished without the adapter-probe
feature.

Two cfg blocks replace it, one per configuration. `probe_caps` in the same
file already has that shape. `Backing::Device` exists only under that feature.
The clippy suggestion on its own would not compile.

The plain clippy leg never saw this. The line compiles only with adapter-probe
on. The all-features leg catches it, as does any workspace build that unifies
the feature in.
2026-11-18 19:05:00 -06:00
William Dunn ec65838487 craft-suite-account: provider-neutral suite account list and keychain token store (#665)
* craft-suite-account: the suite account list and keychain token store

Carries crates/suite-account over from the cut-down craft-libs#160 branch. This follows RFC-0025 (storytold/craft-contrib#35).

service.rs is removed. It was the CollabCraft device-flow client. Its Service, Flow, Identity, Polled and SignedOut types went with it. Store::sign_out is also gone. The provider adapter now owns ending a session at the deployment. Store::discard and Store::forget cover the local half that stays here.

Every remaining CollabCraft-specific word is reworded to a provider-neutral description. The one serde alias and the one test fixture name that spelled the old provider out are gone too.

Adds a generation field to Account, per RFC-0025's cross-app lifecycle guarantees. A sign-in bumps it. Store::update_token refuses a write made against a stale generation. A fuller tombstone for the removal case is left as a TODO referencing the RFC, documented on Accounts::remove.

Also drops one unused restrict() function found while verifying clippy -D warnings on Linux. It was pre-existing dead code. The unix write path already sets the file mode at creation.

* craft-suite-account: lock list mutations, make generations monotonic across removal

Fixes the three review gates on PR #665 (rev 2e9c84f).

Every mutation of accounts.json now goes through an OS-level file lock. The
lock is a sibling .lock file taken with std::fs::File::try_lock and a
bounded retry, matching the mechanism craft-ai-integrations' store already
uses for the same problem. Two processes each completing 100 sign-ins into
one folder used to leave 101 rows on file. Both the real two-process and
two-thread conformance tests now land all 200 rows.

A removed account now leaves a tombstone holding its last generation. A
re-add continues past that tombstone. It never restarts at 0.

update_token checks the generation twice. The first check runs before the
keychain is touched at all. An already-stale caller never overwrites a
newer token. The second check runs under the lock, after the keychain
write. It catches a removal that landed in the window that write opened. A
tombstoned account answers StaleGeneration. It never answers Unknown. The
second check also removes the token it just wrote, under the same lock,
when the account turns out to be gone. A refresh racing a discard can then
resurrect neither the row nor the keychain entry. discard itself now
removes the keychain entry inside the same lock hold as the list write.

The module docs now name the chosen keychain-versus-list write order for
each operation. They also name the state a crash in that window leaves
behind for the next reader to repair, per RFC-0025 guarantee 1. A new test
simulates the window update_token opens between its keychain write and its
generation commit.

The conformance tests are adapted from the maintainer's review-reproduction
gist for this crate. Forget racing a refresh is the one gist case left out.
forget is deliberately generation-agnostic and local, per RFC-0025
guarantee 4. That fix would be a separate, broader change than these three
gates.

* craft-suite-account: close the review gaps CodeRabbit found in the rebase

Six fixes. Generation bumps in sign_in, update_token and remove_with_tombstone
now use checked_add. A bump at the maximum refuses with GenerationExhausted.
It never wraps back to a small number a stale caller could pass again.
accounts::write now refuses a list that would serialize
past MAX_BYTES before touching disk. An oversized display name can then
never brick the list for every later reader. NewAccount.linked now persists
onto Account. It used to be silently dropped at sign_in. update_token's
stale-write cleanup now only removes a keychain token that still matches the
token it wrote itself. A concurrent sign-in's token for the same handle
survives that cleanup now. Store::forget and Store::has_token now return
Error::Isolated before touching the keychain, matching every other mutator.
migrate::adopt re-reads the legacy file right before deleting it and skips
the delete when something rewrote it since. The read buffers are wrapped in
Zeroizing too. A parsed-but-unused token copy no longer outlives the one
Secret already covers.

Three findings were not valid against this code and are not changed. The
torn-state window CodeRabbit flagged in update_token's generation commit is
the same crash recovery the module docs already describe. The existing
torn-state test already exercises it. Forcing the keychain write under the
same lock as two concurrent sign-ins for one handle would reintroduce the
cross-process deadlock the lock module exists to avoid. A failed discard
already reports its own error. A refresh that re-establishes a full session
afterward is recovery. It is never a silent mismatch.

* craft-suite-account: apply cargo fmt to the review-gap fixes

cargo fmt wraps the long struct literals and assert calls the previous
commit added. The content is unchanged.

* craft-suite-account: factor the race test's join-handle type out

clippy::type_complexity flagged the four-deep generic on handle_slot in the
stale-refresh-vs-re-sign-in test. A type alias clears it without changing
the test.

* craft-suite-account: flush before the rename, re-check the token under the lock

Two review findings. The temporary file is now flushed with sync_all before the rename, keeping the crash story the doc tells. A discard racing a sign-in could delete the token the sign-in had just written and the sign-in still reported Ok. The lock closure re-checks the keychain right before committing the row and writes the token again when something else changed it.

* craft-suite-account: sync the parent directory after the rename

The temp-file flush persists the bytes. The rename changes a directory entry with its own durability on Linux. Power loss after write returned could otherwise resurrect the older list and lose a tombstone a discard already reported written. A sync failure now reports an error, never success. Unix only, since directories do not open for sync elsewhere.

* craft-suite-account: keep activation out of refresh, require an explicit format marker, stop logging paths

Three fixes. update_token no longer calls Accounts::put for its row commit.
That call always makes the written row active. Refreshing an account in
the background used to silently steal the selection from whatever account
the person had actually picked. A new Accounts::refresh_in_place replaces
the row without touching active. put stays exactly as it was for sign_in
and set_active, the two calls meant to change it.

Accounts::format no longer carries #[serde(default)]. Every other field
still does. A missing format key used to default through Accounts's own
Default impl. That impl answers FORMAT. A file that never declared a
format therefore read as exactly the one format this build understands.
read now also rejects any parsed format that is not exactly FORMAT. The
old check only rejected a newer one; format 0 passed it the same way a
missing key did.

accounts::read's error messages now name only the file, never the full
path. Store::shared logs a read failure at warn. The path sits under the
user's profile folder.

restrict on Windows stays a no-op. Its comment now states the guarantee's
real scope. The default per-user config folder gives it. A portable
install or an ARTCRAFT_SUITE_DIR override does not. A real fix needs the
Win32 authorization API. Every binding for it is an unsafe fn. This
workspace forbids unsafe_code outright. That part of the finding is
refused in part. Closing it for real needs a maintainer-approved exception
for this one call site, or a vetted dependency wrapping that API safely.
Either is a decision for its own PR.

* craft-suite-account: move update_token's keychain write inside the lock

skylartaylor's finding. update_token used to write the keychain, then take
the list lock. A newer sign-in, or a discard followed by a re-add, could
land for the same handle in between. The second check under the lock
already answered StaleGeneration in that case, but the earlier write had
already landed over the newer session's token. shared() then served the
new session's row with the stale refresh's bytes. Deleting the stale token
on its own was never going to fix this; that still loses the newer
session, it only changes which bytes go missing.

The keychain write now happens only inside the lock, in the second
generation check's own success arm, immediately before the row commits.
The first, unlocked check still exists, purely to reject an already-stale
caller before it ever takes the lock; it writes nothing. Every losing
path, a newer sign-in, a discard, a discard followed by a re-add, now
answers with an error having never touched the keychain at all. There is
nothing stale left in it to clean up or weigh against a winner's own
token. Store::remove_token_if_still is gone. Its two call sites in the
losing branches never write a token to begin with now. Nothing is left
for it to conditionally remove.

This keeps the lock discipline the module docs describe: the write is
conditional on the row commit going ahead, the same shape as discard's own
keychain call inside its lock hold and sign_in's existing re-check, never
an unconditional call made regardless.

Two deterministic tests reproduce both orderings skylartaylor named, each
proving the fix against the pre-fix code before passing against the fix:
a_refresh_racing_a_newer_sign_in_for_the_same_handle_never_overwrites_its_token
and a_refresh_racing_a_discard_and_re_add_for_the_same_handle_never_overwrites_its_token.
Both hold the real accounts lock on a background thread standing in for
the winning operation. They release it only after the refresh's own
unlocked first check has had the chance to read the pre-race state. Both
then assert shared() serves the winning session's own token afterward.

The crate's own pre-existing hook-based race tests could no longer reach
the window they were built for, since that window no longer has a
keychain call in it to hook. tests/review_repro.rs's two Hooked-based
tests are rewritten onto real threads racing on a Barrier instead, the
same device the file's own two-thread sign-in test already uses. The lock
makes their outcomes hold for either ordering now. A hook could only ever
force one. The now-unused Hooked harness is removed along with them.
src/tests.rs's own matching hook-based test is replaced outright by the
two new ones above. That covers its ground and the newly found gap
together.

* craft-suite-account: pin the race tests' second-check window

skylartaylor's review note on PR 665: the two update_token race tests in
src/tests.rs send their release signal and then immediately call
update_token, so the competing sign-in or discard-and-re-add can finish
before the refresh's first, unlocked check ever runs. A pre-fix build
could then pass the same assertions by rejecting early at that first
check, never reaching the second, locked one the tests are named for.

Adds race_hook, a test-only pause point inside update_token between its
two checks. A test arms it, starts the refresh, waits for the refresh to
signal that its first check has read the pre-race generation, runs the
competing operation to completion, then releases the refresh into its
second check. Both race tests are rewritten onto this instead of holding
the real accounts lock on a background thread, which left the same gap
skylartaylor found: the lock never blocked the refresh's unlocked first
read, only its second, locked one.

* craft-suite-account: make the race test hook per store instead of process wide

CI runs this crate's suite with the default, parallel test runner. The
hook update_token pauses on between its two generation checks lived
behind one process wide slot, so when the Workspace gate's parallel run
landed both race tests at the same time, one test's release on that
slot answered the other test's pause: the pinned ordering collapsed,
the refresh ran ahead of the competing write, its second check legitimately
matched, and update_token returned Ok where the test expected
StaleGeneration. Reproduced on the lab build host with the crate's
default threaded test run; failed on the first attempt, matching the
CI failure exactly.

The hook now lives on the Store instance, one per store, armed only on
the exact store a given test built. A concurrent test's own store keeps
its own hook, so there is nothing left for two tests to cross no matter
how the runner schedules them. Checked the rest of the suite for the
same kind of shared state: every other test builds its own tempdir and
its own in-memory keychain, and the two-process test spawns its own
child with --test-threads=1 for that child's own run, so none of them
depend on the parent suite running single threaded.
2026-11-17 21:56:16 -06:00
William Dunn bfe246b5b4 craft-ui: leave the menu module ungated, as main has it
This branch gated `pub mod menu;` behind the esign feature, which was right when main had no menu module of its own. #160 landed one, and its cloud pages use it (crates/ui/src/cloud/pages.rs, cloud/title.rs). The gate therefore broke every build with cloud on and esign off, which is what the workspace clippy leg does. The gate was the whole remaining content of the commit that carried the helper across.
2026-11-17 21:04:35 -05:00
William Dunn 22978401ce Cargo.toml: drop the craft-cloud workspace entry that #160 landed
This branch added craft-cloud to [workspace.dependencies] for the e-sign dialog's vocabulary. #160 added the same entry beside craft-cloud-local while this branch waited, in a different place in the list, so the rebase kept both and cargo refused the manifest. Main's entry stays. Cargo.lock is regenerated on the new base.
2026-11-17 21:04:35 -05:00
William Dunn a64ad59593 craft-esign make the outstanding-send regression test actually outstanding
The send helper submitted the create immediately, consuming the captured context before the status request ran. The test now queues and takes document A's send without submitting it, leaving the context pending. That pending context is the scenario the guard exists for.
2026-11-17 21:03:40 -05:00
William Dunn 52d874ae96 craft-esign keep the send context off status requests
submit_request consumed the captured send context for every request kind. A status refresh for the current document submitted while another document's send was still outstanding then carried the old context. pump dropped its reply as stale. The context now goes only to the create submission that answers the taken send request. Every other request uses the current context.
2026-11-17 21:03:40 -05:00
William Dunn df8f35d297 craft-esign apply rustfmt to the refresh caption test
Wraps a line fmt would otherwise reject on the next check.
2026-11-17 21:03:40 -05:00
William Dunn 9e70a85182 craft-esign fix status routing, relink, role reuse, close and i18n gaps
A public submit_request call carrying Request::Status never registered
status_seq. Its own reply then failed the supersession guard. The dialog
kept showing an envelope's old state. submit_request now records
status_seq for a Status submission the same way status_panel's own button
already does.

Once available() turns true it never asks again. A backend whose linked
value changes after an out-of-band sign-in stayed stuck showing the
sign-in message. A new reset_capabilities method reprobes the current
backend. It reuses the same reset set_backend already performs.

Recipient roles were derived from the current recipient count. Add two
recipients, remove the first, then add a third: the third gets the
second's exact role. A placement keyed to a removed recipient's role
could then bind to whichever recipient later receives that reused label.
Roles now come from a counter that only climbs. A recipient removal also
drops any placement keyed to a role no recipient holds anymore.

Both Close buttons set self.open to false inside the window's content
closure. show() then overwrote it with the window's own unchanged open
binding, undoing the click. show() now requires both to agree the dialog
stays open.

The manual status refresh button showed the English "Refresh status"
caption regardless of the labels a host supplied. EsignLabels gained a
refresh field for it.

Each fix adds a test that fails without it.
2026-11-17 21:03:40 -05:00
William Dunn 4e007a5fb0 craft-esign add the missing regression test for the capabilities race
The is_caps_reply guard from the earlier commit had no test of its own. A
reply from a replaced backend now provably cannot overwrite the new
backend's capabilities, responsible party or linked state.
2026-11-17 21:03:40 -05:00
William Dunn 5c44349a89 craft-esign apply rustfmt to the new tests
Wraps a few lines fmt would otherwise reject on the next check.
2026-11-17 21:03:40 -05:00
William Dunn 820aa7b32c craft-esign clear the texture delta the sign-in message test's frame leaves
run_ui's FullOutput carries textures_delta. egui panics on drop when a test
never applies or clears it.
2026-11-17 21:03:40 -05:00
William Dunn b0b5c2bf17 craft-esign close context, idempotency and busy-ownership gaps in the dialog
A reply from a replaced backend could overwrite capabilities for the new
one. A reply for an older document revision could install under a reopened
dialog. A send request taken before a reopen could tag its reply with the
wrong context. A duplicate answer from a backend holding a second Replier
could reinstall state the dialog had already moved past. A superseded
status refresh could overwrite a newer one. A failed lookup could clear
busy for a create that was still running.

Placements and the draft idempotency key could also survive a document
change or a field edit that should have invalidated them. A contact with no
email address could become a recipient using its share id as the address.
Two dialog instances could mint the same idempotency key for the same
document. An unlinked account showed a disabled Send button with no
explanation.

The context model now carries the document revision and an opening counter
alongside the document id and account. Pending-send context is captured at
queue time and consumed by the eventual submit or result call. A late reply
or result keeps the context it was built under. Each fix adds a test that
fails without it.
2026-11-17 21:03:40 -05:00
William Dunn 98bfed94c2 craft-esign: carry the menu helper behind the esign feature on the new egui
Main's craft-ui no longer has a standalone menu module. The esign dialog is the only consumer of the split-button helper this slice carries. The module is therefore feature-gated so the default craft-ui build matches main exactly. The three widget_info calls move from the deprecated egui::WidgetType alias to egui::Role. The current pin denies that deprecation as a warning.
2026-11-17 21:03:40 -05:00
William Dunn 81bdd0dbe8 craft-esign: context-keyed replies, context-based staleness, two completion digests
Fixes three gate items skylartaylor raised on PR #661. He reproduced them
against 0a937ef in
https://gist.github.com/skylartaylor/c1108ecf20d63c5e3183947408ddab7a.

The request-signatures dialog now tags every in-flight create, status,
completed, void and remind request with the context that issued it. That
context is the document identity plus the account identity. A reply
installs only when that context still matches the dialog's current
context. This replaces the old staleness rule. That rule keyed off a global
sequence counter that typing in the signer search also bumped. It dropped a
late create reply and left the dialog on Sending forever.

CompletedDocument now carries original_content_sha256 and
signed_content_sha256 as distinct fields, per RFC-0021's evidence guarantee
in storytold/craft-contrib#37. The crate's in-process test double computes
both from the bytes it actually holds. It applies a fake seal that changes
the signed bytes first. The two digests are never conflated.

Regression tests, all in crates/ui/src/esign/review_repro.rs unless noted:

1. review_h5_reply_for_previous_document_is_installed_after_reopen
2. review_h5_reply_for_previous_account_is_installed_after_account_switch
3. review_n1_create_reply_dropped_after_a_lookup_leaves_dialog_busy
4. completed_document_keeps_original_and_signed_digests_distinct, in crates/esign/src/lib.rs
2026-11-17 21:03:40 -05:00
William Dunn be5c6accc1 craft-esign: add the e-sign contract and craft-ui's esign feature
This carries over crates/esign and craft-ui's esign dialog from the cut-down #160 branch, with minimal workspace wiring. The esign dialog speaks only craft_cloud::Contact and craft_esign types. This also brings crates/cloud along as a dependency until PR #160 lands on main.
2026-11-17 21:03:40 -05:00
William Dunn aa4647a777 craft-cloud-local: confine every path through a Dir capability, not a path string
benandez's re-review reproduced three escapes the first confinement fix still
left open. A dangling symlink: canonicalize reported it as missing, so the
old confine_to_root walked up to root and accepted it, and write created the
symlink's target for real, outside root. A check-then-use race: confine_to_root
checked one path string and a later fs::read or fs::write resolved that same
string again, a second lookup a concurrently swapped link could land in
between. A hard link: write truncated the shared inode in place, with nothing
in a canonicalized path to show that another name pointed at the same file
outside root.

list, read, write and create now resolve every already segment-checked
relative path through a cap_std::fs::Dir capability opened on root, instead
of joining an absolute OS path and handing it to plain std::fs. cap_std
resolves one path component at a time against real, already-open directory
handles, so a symlink or a Windows junction cannot walk resolution above
root, dangling or not, and there is no separate check with a window for the
directory tree to change underneath it: the one resolution is the open. This
is the same family of guarantee craft-font-store already depends on through
cap-primitives, which cap_std is built on.

write no longer truncates its target in place either way: it writes a new
sibling file and renames it over the target, so a hard link's directory
entry is replaced rather than its shared content being overwritten.

Per that review's non-blocking notes: a name that already exists on disk
with an ordinary ':' or '\' byte (macOS stores a typed '/' as ':') stays
reachable by list and read, since neither character is a path separator on
any platform's filesystem; the stricter refusal now applies only to a name
being chosen by Create. Create also goes back to bringing a fresh root into
existence, matching its behaviour before the first confinement fix. A
Windows reserved device name (CON, COM1, CONIN$, with or without an
extension) is refused in a chosen name on every platform.

Regression tests reproduce all three escapes (dangling symlink, swapped-link
race, hard link), plus the previously missing coverage: a link in the folder
a Create targets, and a write test that actually reaches disk instead of
being refused for an unrelated reason before confinement ever ran. Verified
by hand that each of the three new write-path tests fails against the
pre-fix pattern (an absolute OS path joined by string concatenation) before
trusting them.
2026-11-17 00:51:58 -05:00
William Dunn e5e9433413 craft-cloud-local: confine list, read, write and create to the configured root
FredApps' re-review found that resolve only split on slash and rejected a
segment equal to parent-dir, with no constraint on a Windows backslash, a
drive letter or UNC prefix, or a filesystem link, and that create joined
the Job::Create name onto the resolved folder with no validation of the
name at all.

Every path segment, and a Create name on its own, now goes through one
shared confine_segment check: accepted only when it parses as exactly one
Component::Normal equal to the original text, with a backslash or colon
refused outright first so a Windows-shaped escape cannot slip past a
Linux build's narrower native parser. A second shared check, confine_to_root,
canonicalises the nearest existing ancestor of a resolved path and
confirms it still sits under the canonicalised root, refusing a symlink or
a Windows junction that would otherwise redirect outside it. List, read,
write and create all run both checks before touching disk.

Regression tests cover the review's own examples (a parent segment, an
absolute path, the three Windows-shaped forms) for Create, the same
Windows-shaped escape for a List folder path, and a symlink (Unix) or
junction (Windows) placed inside the root for list, read and write, each
against a sibling sentinel file and directory that must stay untouched.
2026-11-16 23:48:02 -05:00
William Dunn 658cc01501 craft-ui cloud: stop using unreachable in the conflict modal tests
clippy::unreachable is denied at the crate root with no in-tests
carve-out, unlike unwrap, expect and panic. The three let-else
fallbacks in conflict_tests.rs now panic with a message instead,
matching the pattern used everywhere else in this crate's tests.
2026-11-16 23:48:02 -05:00
William Dunn c5e9e87309 craft-cloud-local: fix stale etag and racing create
Read now stats the file it just read. The returned entry reflects
that read. It no longer echoes the etag of the entry passed in. A
reload after a conflict used to carry the version that was just
refused into the next save, conflicting it again.

Create opens the file with exclusive creation. An exists check no
longer precedes a separate write. Two creates of the same name can no
longer both observe an empty slot and both report success. Regression
tests drive both fixes through craft_ui::cloud's public functions
against a real folder on disk.
2026-11-16 23:48:02 -05:00
William Dunn b49ac50ed5 craft-ui cloud: fix conflict modal and session identity bugs
Reload from the conflict modal now acts on the conflicted document's
uid. Save as a copy acts on that same uid too. Neither acts on the
active tab anymore. A window with more than one document open keeps
them separate.

Sign-out bumps an account generation. Sign-in bumps it too. Each
clears busy. A job's reply carries the generation it was issued
under. A reply from an older generation gets dropped. A stale session
cannot restore its account or its files over a newer one. A job that
never answers cannot refuse every save afterward. Regression tests
for both pairs of findings run through a held backend that answers
jobs on the test's own schedule.
2026-11-16 23:48:01 -05:00
William Dunn a170341225 craft-cloud-local test: name the opened-documents type
The current clippy warns on the inline Arc Mutex tuple type in the test harness. A named OpenedDocs alias carries the same meaning.
2026-11-16 23:48:00 -05:00
William Dunn 07d2747efc craft-cloud-local: collapse the etag conflict check into one let chain
The current clippy denies collapsible_if here. Behaviour is unchanged. A missing file still has nothing to conflict with.
2026-11-16 23:48:00 -05:00
William Dunn b1fce2be74 craft-ui cloud pages: move off deprecated egui aliases
The current egui pin denies the deprecated egui::WidgetType alias and egui::Id::new. The slice's pages (account, cloud, share, presence, the menu helper) move to egui::Role::Button and egui::Id::unique, the same spellings main's craft-ui already uses.
2026-11-16 23:47:59 -05:00
William Dunn 8334fd3c83 craft-cloud: cut-down contract plus ui pages 2026-11-16 23:47:58 -05:00