Skip to content

test(conformance): fix the bytes of a UUID in the scalar profile - #2021

Open
coderdan wants to merge 4 commits into
nextfrom
test/uuid-conformance
Open

coderdan wants to merge 4 commits into
nextfrom
test/uuid-conformance

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Summary

The engine's value model takes a UUID, but no conformance case held one. So nothing checked that Rust, Go, and TypeScript write the same UUID frame and derive the same equality term. This pull request adds UUID cases to the scalar profile, record-scalars-v1.

The Rust engine froze the frame, the equality term, and a ciphertext of each case. Native Rust and Go run every case. The TypeScript value bridge checks the frames. The TypeScript runner of the whole profile is pending, because the addon cannot store a UUID until #1996 merges.

This is step 3 of #1821. Step 4 is still open, so this pull request does not close the issue. Step 4 adds a UUID to the Go generated code and the TypeScript addon.

Changes

  • conformance/stack-encrypt/v1/record-scalars-v1.cases.json: three accepted cases and five refused ones.
    • uuid (123e4567-e89b-12d3-a456-426614174000), uuid-nil (all zeros), and uuid-max (all ones).
    • uuid and uuid-max list the same UUID in uppercase, and uuid also in mixed case, under a new spellings key.
    • query-text-for-uuid, query-bytes-for-uuid, query-uuid-for-bytes, and query-uuid-for-string are refused as field_type. query-uuid-null is refused as null_query. So the engine converts nothing to or from a UUID.
  • record-scalars-v1.expected.rust-native.json: the frame, equality term, and ciphertext of each new case, written by the Rust runner with STACK_CONFORMANCE_UPDATE=1. Each normal run compares the engine's output with these values, so they cannot drift.
  • packages/stack-encrypt/tests/conformance.rs: the runner seals and opens a value::Uuid, and checks each spelling. An update now keeps the frozen ciphertext of a case whose frame and equality term have not changed. So adding these cases added three entries and left the other ciphertexts as they were.
  • packages/stack-encrypt/tests/common/conformance.rs: the uuid input type. The code is the same as in feat(stack-encrypt)!: encrypt and decrypt one value known only at run time, and bound the typed decrypt to a scalar #2011, so the two pull requests should merge without a conflict there.
  • languages/golang/encrypt/conformance_test.go: the Go runner builds a vcvalue.UUID, and checks each spelling with vcvalue.ParseUUID.
  • languages/typescript/packages/recipher-js/value-napi/tests/frames.cjs and its two fixture files: six VcUuid values, from every case and spelling, compared with the frozen frames. The fixtures were regenerated with RECIPHER_UPDATE_FIXTURES=1.
  • conformance/stack-encrypt/README.md and coverage.md: the new input type, the spellings key, the cases, and which runners run them.

No changeset: the pull request changes tests, test data, and conformance documents only. No published package changes.

Verification

Run in a worktree on this branch:

  • cargo test -p stack-encrypt --all-features --test conformance: passes, with and without STACK_CONFORMANCE_UPDATE=1. --test value_conformance and --test runtime_conformance also pass, because they share the changed helper.
  • Go to Rust: Go's fresh artifacts, exported with STACK_CONFORMANCE_OUTPUT, open in Rust with STACK_CONFORMANCE_INPUT.
  • go vet ./encrypt and gofmt -l: clean. The Go selection that test:conformance runs passes, against both guests built from this branch.
  • cargo test -p recipher-value-napi --test node: passes in check mode after the fixtures were regenerated.
  • cargo fmt --check and cargo clippy -p stack-encrypt --all-features --all-targets -D warnings: clean.
  • pnpm run test:scripts: 99 files pass, including the conformance-suite checks and the TypeScript frame parity test.
  • Biome 2.6.4 check on the changed JSON and JavaScript: clean.

Not run: mise run test:conformance as one task (mise is not trusted in the worktree), so I ran its steps by hand as listed above. I did not build the EQL guest, so I did not run the whole Go ./encrypt package. This pull request does not touch the tests that need it.

Related

Refs #1821 (step 3).

Review notes

The value model takes a UUID, but no conformance case held one. So
nothing checked that Rust, Go, and TypeScript write the same UUID frame
and derive the same equality term.

record-scalars-v1 now has three UUID cases: an ordinary UUID, the nil
UUID, and the max UUID. The Rust engine froze the frame, equality term,
and ciphertext of each. Two cases list the same UUID in other letter
cases.

Five new refusals show that the engine converts nothing to or from
a UUID. A UUID field refuses a string, bytes, or a null. A bytes field
and a string field each refuse a UUID.

Native Rust and Go run every case. The TypeScript value bridge checks the
frames, from each spelling. The TypeScript runner of the whole profile
waits on the addon storing a UUID (#1996).

An update of the frozen file now keeps the ciphertext of a case whose
frame and equality term have not changed. So adding a case adds one
entry.

Refs #1821
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a52667d3-c88e-4672-beca-fbafae1dec68

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@changeset-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d6dd343

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth, stack-encrypt, stack-encrypt-jsonpath, vitaminc-aead, recipher-frame, vitaminc-aead-derive)

No mutants were generated for the changed lines.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of this pull request: five findings. One is important: the update mode can no longer refresh a frozen ciphertext.

case.id
);
}
let kept = previous

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important. STACK_CONFORMANCE_UPDATE=1 can no longer refresh a frozen ciphertext. When a case's frame and equality term are unchanged, the update opens the old ciphertext with .unwrap() and writes it back (line 381). If the old ciphertext no longer opens, the update panics instead of writing a new one. Line 236 also panics through serde_json::from_slice(..).unwrap() when the old file no longer parses under deny_unknown_fields. So after a deliberate change to the ciphertext header, the only way to regenerate is to delete the expected file by hand.

Fix: fall back to the fresh artifact when the kept ciphertext fails to open, treat an unreadable previous file as missing, or add a full-regenerate option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d3d3c6.

  • STACK_CONFORMANCE_UPDATE=1 now opens a kept ciphertext first, through the scalar API and the record path, with no unwrap. If it does not open to the input, the update writes the fresh ciphertext and logs the case.
  • A previous expected file that does not parse is treated as missing. The update logs it and writes every artifact fresh.
  • STACK_CONFORMANCE_UPDATE=all writes every artifact fresh. Any other value fails the test. The README describes both values.

How I tested the fallback, on the expected file in the worktree, restoring it with git checkout after each step:

  1. I changed one hex digit of the uuid ciphertext, then ran with STACK_CONFORMANCE_UPDATE=1. The log said uuid: the frozen ciphertext no longer opens (Aead); writing a fresh one. Only uuid changed, and a check run then passed.
  2. I replaced the file with {"not": "artifacts"} and ran with =1. The log said the file does not parse, all 11 ciphertexts were written fresh, and a check run passed.
  3. With =all, all 11 ciphertexts changed, and a check run passed.
  4. With =1 on the unchanged file, there was no diff.

case.id
);
output.cases.insert(case.id.clone(), artifact);
let written = if update { reference.clone() } else { artifact };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. In update mode, STACK_CONFORMANCE_OUTPUT now writes the kept old ciphertexts, while the producer field names the current crate version. A consumer that wants ciphertexts this build made, as the exchange profile does, gets old ones. Fix: write the fresh artifact to the output path, and use the kept one only for the expected file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d3d3c6. The runner keeps two maps now. STACK_CONFORMANCE_OUTPUT gets the artifacts this run made. Only the expected file gets the kept ciphertexts.

I ran STACK_CONFORMANCE_UPDATE=1 with an output path: all 11 ciphertexts in the output differ from the kept ones in the expected file. The README says that the output never contains a kept ciphertext.

use serde_json::json;
use stack_encrypt::dynamic::{self, frame::OwnedFrame, record, Fidelity, NoTargets, Op, Operand};
use stack_encrypt::target::IndexSpec;
use stack_encrypt::value::Uuid;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. The test now imports stack_encrypt::value::Uuid, which exists only with the uuid feature, but the file is gated only on feature = "dynamic". cargo test -p stack-encrypt --no-default-features --features dynamic fails with E0432. tests/value_bytes.rs gates on both features for this reason. Fix: gate on both, or gate only the UUID arms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d3d3c6. Only the UUID parts are gated now: the value::Uuid import, parse_uuid, the uuid arms of the seal and open matches, and the spelling check. A build without uuid has no typed UUID. So it skips the three accepted UUID cases with a log line, and runs every other case, the five UUID refusals included. An update without the feature fails, because it would drop those entries.

cargo test -p stack-encrypt --no-default-features --features dynamic --test conformance builds and passes. Clippy with -D warnings is clean with that feature set and with --all-features --all-targets.

'record-scalars-v1/uuid',
],
[
'VcUuid uppercase',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. The TypeScript check hard-codes the UUID spellings instead of reading each case's spellings from the corpus, while the README (lines 62 and 288) says it writes every spelling. A spelling added to the corpus is checked by Rust and Go but not by the TypeScript bridge, and nothing notices. Fix: read spellings from the corpus, or have the parity test check that every corpus spelling has a matching input.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d3d3c6. frames.cjs no longer names any UUID. On a regenerate it reads the text and spellings of each accepted UUID case from record-scalars-v1.cases.json. It stores them under uuids in corpus-frames.json, so a check run still reads nothing outside the package.

It writes a VcUuid frame from each text and each spelling. I regenerated both fixtures.

The parity test has two new checks:

  • The uuids copy must equal the UUID cases in the corpus.
  • js-frames.json must pin a frame for every text and spelling, with the right case and same_as_corpus: true.

To check them, I added a spelling to uuid-max in the corpus without regenerating. Both checks failed. Then I restored the file.

Comment thread conformance/stack-encrypt/README.md Outdated
The engine converts nothing to or from a UUID.

Boolean equality is not admitted by the current engine. Boolean scalar
encryption, nullable records, other numeric kinds, bytes, JSON, EQL targets,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. The profile text still lists "bytes" among the kinds that need later profiles, but this pull request adds query-uuid-for-bytes, a case whose field is bytes. Fix: say that bytes positives and bytes equality need later cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1d3d3c6. The paragraph now says that bytes need accepted cases and frozen equality terms. It also says that the one bytes field in the profile only refuses a UUID. I split the list there into shorter sentences.

These changes address the review of the UUID cases.

The scalar runner's update kept a frozen ciphertext and then failed when
that ciphertext no longer opened. Now the update first checks that the
kept ciphertext opens. If it does not, the update writes a fresh one. A
previous file that does not parse keeps nothing.

STACK_CONFORMANCE_UPDATE=all writes every artifact fresh.
STACK_CONFORMANCE_OUTPUT always gets the artifacts this run made.

The runner now builds without the uuid feature. Only the UUID arms need
it, and a build without the feature skips the accepted UUID cases.

The TypeScript frame suite reads each UUID case's text and spellings from
the corpus, through its copy. The parity test fails when the copy differs
from the corpus, or when a spelling has no pinned frame.

The README says which bytes cases are still to come.

Refs #1821
@coderdan
coderdan marked this pull request as ready for review November 29, 2026 02:57
@coderdan
coderdan requested a review from a team as a code owner November 29, 2026 02:57

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed 1d3d3c6 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review standards and spec agents · claude-opus-5-5; review-cross-check verifiers · claude-opus-5-5
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check, company-skills:review-post

Findings (6): 6 minor — 6 inline.

rust-security found nothing to report: the Rust changes are test-only and use deterministic test keys. Earlier findings already raised in this PR's threads were not repeated. Findings left out because they turn on a design choice, or did not hold up at head, are not posted here.


Generated by Claude Code

Comment on lines +272 to +284
assert!(
case.spellings.is_empty() || case.input.kind == "uuid",
"{}: only a UUID input has other spellings",
case.id
);
for spelling in &case.spellings {
assert!(
spelling != &case.input.text && spelling.eq_ignore_ascii_case(&case.input.text),
"{}: {spelling} is not the input's text in another letter case",
case.id
);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor A case with expected_error may list spellings, and no runner ever reads them: Rust continues at the expected_error branch before the spelling loop, Go returns before its loop (conformance_test.go:257), and both corpusUuids() copies drop error cases. Adding a spelling to query-uuid-for-bytes passes every runner unread. Also require case.expected_error.is_none() when spellings is non-empty here, in Go at conformance_test.go:215, and in the parity test.

Source: code-review (medium); verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. A refused case with spellings now fails in three places:

  • the Rust runner's corpus check
  • the Go runner's corpus check (conformance_test.go)
  • a new parity test, finds spellings only on accepted UUID cases

To check this, I added a spelling to query-uuid-for-bytes. All three failed. The two runners said "only an accepted case with a UUID input has other spellings". Then I restored the file. The README says the same.

Comment on lines +372 to +375
if cfg!(not(feature = "uuid")) && case.input.kind == "uuid" {
eprintln!("conformance: {}: skipped, needs the uuid feature", case.id);
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor (nit) Without the uuid feature this skips the whole accepted UUID case, including record::encrypt, query_term and record::decrypt, which need no feature (common::conformance::value builds the UUID frame ungated). So --no-default-features --features dynamic passes without checking the dynamic UUID path, and the only signal is an eprintln that nextest hides. Skip only scalar()/open_scalar and the spellings, taking the artifact ciphertext from the record's c leaf.

Source: code-review (medium) + spec agent; verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. Without the uuid feature, an accepted UUID case now runs record::encrypt, record::decrypt, query_term, and both record cross-opens. It also compares the frame and the equality term with the frozen ones. The case skips only the owned scalar seal and open, and the spellings. Its fresh ciphertext is the record's c leaf.

cargo test -p stack-encrypt --no-default-features --features dynamic --test conformance passes, and logs "checking the record path" for the three UUID cases. Clippy with -D warnings is clean for that feature set. An update without the feature still fails, because the owned scalar API made the ciphertexts in the expected file.

Comment on lines +99 to +107
fn try_unhex(text: &str) -> Result<Vec<u8>, String> {
if !text.is_ascii() || !text.len().is_multiple_of(2) {
return Err("not hex".into());
}
(0..text.len())
.step_by(2)
.map(|i| u8::from_str_radix(&text[i..i + 2], 16).map_err(|e| e.to_string()))
.collect()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor try_unhex repeats common::unhex (tests/common/mod.rs:378) apart from returning Err. Move it into common and have unhex call try_unhex(text).expect("hex").

Source: mattpocock-skills:code-review standards agent; verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. try_unhex is now in tests/common/mod.rs, and unhex calls try_unhex(text).expect("hex"). The runner imports it from there.

Comment on lines +113 to +116
fn parse_uuid(text: &str) -> uuid::Uuid {
uuid::Uuid::try_parse(text).expect("a hyphenated UUID")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor This lenient parse_uuid (any case, braced, simple, urn) shares its name with the strict canonical parse_uuid in tests/common/conformance.rs:209. Rename this one, for example read_spelling; the expect("a hyphenated UUID") message also overstates what try_parse requires.

Source: mattpocock-skills:code-review standards agent; verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. The runner's lenient reader is now read_uuid_text, and its doc comment says which texts reach it. Its message is now "a UUID". The strict corpus reader in tests/common/conformance.rs keeps the name parse_uuid.

Comment on lines +223 to +231
async fn reopens(
keyset: &KeysetCipher<'_, common::DeterministicSource>,
corpus: &Corpus,
case: &Case,
plan: &record::Plan,
candidate: &Artifact,
(input, row): (&OwnedFrame, &OwnedFrame),
context: &Label,
) -> Result<(), String> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor reopens takes seven parameters, one an ad-hoc (input, row) tuple that keeps it under clippy's too_many_arguments; corpus is used only for corpus.field and case only for case.kind. Pass field: &str and kind: &str, or a small struct for the expected input and row.

Source: mattpocock-skills:code-review standards agent; verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. reopens is now Opening::check(&self, candidate). The Opening struct has the keyset, the plan, the context, the field name, and the kind. It also has the expected input and row, and whether the owned scalar API is available. try_stored and stored now take the field name instead of the corpus.

Comment on lines +430 to +433
let unchanged = previous
.as_ref()
.and_then(|p| p.cases.get(&case.id))
.filter(|old| old.frame == artifact.frame && old.equality == artifact.equality);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor unchanged is an Option<&Artifact> holding the previous artifact but reads as a boolean; frozen holds fresh artifacts under all or after a fallback. Rename, for example previous_match and written.

Source: mattpocock-skills:code-review standards agent; verified by review-cross-check · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87b03c3. unchanged is now previous_match, with a comment saying it is the previous artifact whose frame and equality term match. frozen is now written, the map an update writes to the expected file.

These changes address the second review of the UUID cases.

The Rust and Go runners, and the frame parity test, now refuse
`spellings` on a refused case. No runner read them there.

A Rust build without the uuid feature now runs the record path and the
equality term of each UUID case. It skips only the owned scalar API and
the spellings, and takes its fresh ciphertext from the record's leaf.

The hex reader that can fail moves into the shared test helpers, and
`unhex` calls it. The runner's UUID reader is renamed, so that it no
longer shares a name with the strict corpus reader. One struct now holds
what a ciphertext must open to. Two variables have clearer names.

Refs #1821
Brings in #2011 and its single-value profile.

- coverage.md: both sides changed one row of the table. This branch
  changed the row about scalar widths, and next changed the row about
  owned ciphertexts. The merge keeps both rows as they were changed.
- Both sides added the same `uuid` input type to the shared conformance
  helper, tests/common/conformance.rs. Git merged the two copies into
  one.
- The single-value contract defines the `uuid` input text as this
  branch's README does: lowercase hex in groups of 8, 4, 4, 4, and 12
  digits.

This branch has not been deployed

No deployments
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