Craft Anything: understand how any software works, and craft your own.
Rust
Preserve empty query pairs in older stand-in recordings (#673)
Afloat5ac0e2b68db4
diff --git a/crates/analysis/src/standin.rs b/crates/analysis/src/standin.rsindex 697c5f1d..40356bcb 100644--- a/crates/analysis/src/standin.rs+++ b/crates/analysis/src/standin.rs@@ -501,12 +501,13 @@ impl Scrub {(names, kept.join("&"))}- /// Apply the current query rules to incoming requests and older saved samples alike.- fn query_text(&mut self, query: &str) -> String {+ /// Apply current rules to a request or a saved query. Raw requests ignore empty segments,+ /// but canonical saved queries use empty slots for explicit empty key/value pairs (`=`).+ fn query_text(&mut self, query: &str, preserve_empty_pairs: bool) -> String {let pairs: Vec<(String, String)> = query.split('&')+ .filter(|p| preserve_empty_pairs || !p.is_empty()).take(200)- .filter(|p| !p.is_empty()).map(|p| p.split_once('=').map_or((p.to_string(), String::new()), |(k, v)| (k.to_string(), v.to_string()))).collect();self.query(&pairs, false).1@@ -1126,7 +1127,7 @@ pub fn answer(standin: &StandIn, turns: &mut Turns, method: &str, path: &str, qu// A request is brought to the same form as the recording, so a dropped value still compares equal.let mut scrub = Scrub::new(&[]);let clean_path = scrub.path(path.split(['?', '#']).next().unwrap_or_default(), false);- let clean_query = scrub.query_text(query);+ let clean_query = scrub.query_text(query, false);let key = request_key(body);let key = key.as_deref();@@ -1150,7 +1151,7 @@ pub fn answer(standin: &StandIn, turns: &mut Turns, method: &str, path: &str, qu.samples.iter().enumerate()- .filter(|(_, s)| s.path == clean_path && (s.query == clean_query || scrub.query_text(&s.query) == clean_query))+ .filter(|(_, s)| s.path == clean_path && (s.query == clean_query || scrub.query_text(&s.query, true) == clean_query)).map(|(i, _)| i).collect();if let Some(fit) = consider(route, exact) {diff --git a/crates/analysis/tests/regression_standin_legacy_queries.rs b/crates/analysis/tests/regression_standin_legacy_queries.rsindex edb318e9..a08f57bb 100644--- a/crates/analysis/tests/regression_standin_legacy_queries.rs+++ b/crates/analysis/tests/regression_standin_legacy_queries.rs@@ -23,6 +23,21 @@ fn expect_answer(saved: &StandIn, query: &str, expected: &[u8], how: MatchKind)assert_eq!(found.how, how, "{query}");}+fn recorded_v1(first: &str, second: &str) -> StandIn {+ let entries: Vec<_> = [(first, "first-page"), (second, "second-page")]+ .into_iter()+ .map(|(query, text)| {+ json!({+ "request": {"method": "GET", "url": format!("https://example.test/feed?{query}")},+ "response": {"status": 200, "content": {"mimeType": "application/json", "text": text}}+ })+ })+ .collect();+ let har = serde_json::to_vec(&json!({"log": {"version": "1.2", "entries": entries}})).unwrap();+ let recording = standin::build_from_bytes(&har, &standin::BuildOptions::default()).unwrap();+ serde_json::from_slice(&serde_json::to_vec(&recording).unwrap()).unwrap()+}+#[test]fn legacy_v1_encoded_credential_queries_select_the_matching_variant() {for name in ["%74oken", "a%70i_key", "ACCESS%5fTOKEN"] {@@ -48,3 +63,47 @@ fn an_unrecorded_query_keeps_the_existing_path_fallback() {let saved = saved_v1("%74oken=recorded-fake&page=1", "%74oken=recorded-fake&page=2");expect_answer(&saved, "page=3&%74oken=replacement-fake", b"first-page", MatchKind::Path);}++#[test]+fn legacy_v1_empty_query_pairs_survive_current_credential_scrubbing() {+ for count in [1, 2] {+ // An explicit '=' was saved as an empty slot before encoded credentials were scrubbed.+ let saved_prefix = "&".repeat(count);+ let request_prefix = "=&".repeat(count);+ let saved = saved_v1(&format!("{saved_prefix}%74oken=recorded-fake&page=1"), &format!("{saved_prefix}%74oken=recorded-fake&page=2"));+ expect_answer(&saved, &format!("{request_prefix}%74oken=replacement-fake&page=2"), b"second-page", MatchKind::PathAndQuery);+ expect_answer(&saved, &format!("{request_prefix}%74oken=replacement-fake&page=1"), b"first-page", MatchKind::PathAndQuery);+ }+}++#[test]+fn raw_empty_query_segments_are_not_recorded_as_pairs() {+ let saved = recorded_v1("&&a&&b&&page=1&&", "&&a&&b&&page=2&&");+ for query in ["a&b&page=2", "&&a&&b&&page=2&&"] {+ expect_answer(&saved, query, b"second-page", MatchKind::PathAndQuery);+ }+}++#[test]+fn explicit_empty_query_pairs_still_round_trip_in_new_recordings() {+ for count in [1, 2] {+ let prefix = "=&".repeat(count);+ let saved = recorded_v1(&format!("{prefix}%74oken=recorded-fake&page=1"), &format!("{prefix}%74oken=recorded-fake&page=2"));+ assert_eq!(saved.routes[0].samples[1].query, format!("{}%74oken=[dropped]&page=2", "&".repeat(count)));+ expect_answer(&saved, &format!("{prefix}%74oken=replacement-fake&page=2"), b"second-page", MatchKind::PathAndQuery);+ }+}++#[test]+fn ignored_query_separators_do_not_consume_the_pair_limit() {+ let prefix = "&".repeat(201);+ let saved = recorded_v1(&format!("{prefix}%74oken=recorded-fake&page=1"), &format!("{prefix}%74oken=recorded-fake&page=2"));+ expect_answer(&saved, &format!("{prefix}%74oken=replacement-fake&page=2"), b"second-page", MatchKind::PathAndQuery);+}++#[test]+fn replay_keeps_the_recorders_two_hundred_pair_limit() {+ let prefix = (0..199).map(|i| format!("field{i}=public&")).collect::<String>();+ let saved = recorded_v1(&format!("{prefix}page=1&ignored=first"), &format!("{prefix}page=2&ignored=second"));+ expect_answer(&saved, &format!("{prefix}page=2&ignored=replacement"), b"second-page", MatchKind::PathAndQuery);+}diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 49c1c37c..a28fa379 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -636,6 +636,8 @@ Owner: open · Status: in progressbackend matches older recordings the same way), redact declared secrets in every kept field(names, methods, hosts, versions, timings), count body bytes before text conversion, andtemplate only real calendar dates in API paths (#602–#605, by Afloat16)+- [x] Preserve empty query pairs when matching older stand-in recordings, without treating raw+ query separators as pairs — claimed: Afloat16, branch `bugfix/r3.13-preserve-empty-query-pairs-20261103`---diff --git a/docs/STATUS.md b/docs/STATUS.mdindex 08dc7470..5c955ca7 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -23,7 +23,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi| esbuild module dependencies | Recognised CommonJS and ESM wrappers keep their dependency edges after identifier minification; semantic bindings distinguish shadowed and reused names, and repeated calls produce one edge. Ordinary calls do not consume the 4096-wrapper dependency budget, including when the wrapper is declared later | 50 JS tests pass. Synthetic regressions cover short names, forward declarations, both wrapper kinds and function/arrow bodies, shadowed parameters, reused names, unrelated calls and duplicates. Public analysis fixtures include 4096 distinct ordinary calls before a wrapper dependency and 4097 real wrapper dependencies to check the cap and first-seen order. No real minified application was run for this correction; sources above the existing semantic-analysis size limit retain name-based resolution || Program facts across builds | `native_library_calls_list` (delay-load too), `native_offered_symbols_list`, `native_publisher_show` (checks the file hash and the signature, not Windows trust), `app_builds_line_up` pairs functions across two builds and says how, `native_source_folder_write` writes pseudo-C to a folder and picks up where it stopped, `android_components_list` | Unit tests. Real PE, ELF and Mach-O files; two builds of a 276 MB program; a signed Microsoft DLL; Android components from one real APK, spot-checked || ARM32 value flow | A32 and Thumb calls define ARM scratch registers, and word results flow through `r0` into returns in `native_value_flow_show`. Conditional A32 calls retain the earlier value when skipped and a possible returned result; calls to known non-returning targets keep only the skipped path | Synthetic instruction fixtures for leaf results and indirect calls in both modes, with AArch64 and x86-64 controls; direct and indirect A32 conditional calls within and across basic blocks, including a named `abort` target and unconditional controls. This correction was not checked on real ARM binaries or devices |-| Stand-in backends | `web_standin_build` turns a HAR into `standin.json` (secrets dropped, varying path parts templated); `web_standin_start` answers from it on loopback; `web_standin_show` lists what it had no answer for. A 304 without a usable cached body is counted at build time and skipped during replay; if its matching group has no usable answer, requests get a 404 with `cached_body_unavailable`, also shown in the request log. Writes replay what was recorded and don't change later reads. App maps list GraphQL and tRPC operations; `web_walkthrough_check` checks a scripted session without a browser | Unit tests, real loopback requests, and a run with curl on a hand-written HAR. The 304 correction passes 99 analysis tests and a real-loopback regression, covering mixed samples, omitted bodies, matching boundaries and existing v1 files. [Hosted CI for #543](https://github.com/storytold/craft-anything/actions/runs/41585168291) also passed the full engine tests and workspace gates. No browser-made recording or real front end yet |+| Stand-in backends | `web_standin_build` turns a HAR into `standin.json` (secrets dropped, varying path parts templated); `web_standin_start` answers from it on loopback; `web_standin_show` lists what it had no answer for. A 304 without a usable cached body is counted at build time and skipped during replay; if its matching group has no usable answer, requests get a 404 with `cached_body_unavailable`, also shown in the request log. Writes replay what was recorded and don't change later reads. Older saved query variants keep explicit empty pairs when credential rules are reapplied; raw separators remain ignored and the 200-pair limit matches capture. App maps list GraphQL and tRPC operations; `web_walkthrough_check` checks a scripted session without a browser | Unit tests, real loopback requests, and a run with curl on a hand-written HAR. The 304 correction passes 99 analysis tests and a real-loopback regression, covering mixed samples, omitted bodies, matching boundaries and existing v1 files. [Hosted CI for #543](https://github.com/storytold/craft-anything/actions/runs/41585168291) also passed the full engine tests and workspace gates. Public capture/replay regressions cover legacy empty pairs, raw separators and the query-pair limit. No browser-made recording or real front end yet || Websites as targets | `web_site_open` keeps a private browser for the session and every browser tool inspects that page; `web_site_capture` records screenshots at each width (desktop, tablet and phone), rendered HTML, design tokens (colours in hex, spacing, content widths), the CSS breakpoints, the layout at each width (page width, heading sizes, each section's padding, gap, content column and items per row), page health (script and console errors, failed requests) and an accessibility outline, layout outline, assets with font files and requests, links and form outlines. In Clean room the capture keeps only what a visitor sees (no HTML, CSS rules, scripts, requests or errors), and opening a site reports no load errors | Live run on example.com; unit tests || Electron window comparisons | `app_graphs_compare` retains every unassigned window and every construction with a reused local binding. Windows are paired by module, binding and occurrence, so inserting comments does not hide preference changes. Colliding display labels receive a separate `#N` suffix without changing literal binding names or occurrence indices | Synthetic applications parsed through the ordinary analyzer exercise anonymous and reused bindings, shifted source lines, unequal counts, literal names resembling occurrence or collision suffixes, and stable labels when only one window changes. Pairing remains positional within each binding group; reordered constructions and real application releases were not checked for this correction || Rebuild workflow (Study → Build → Check → Refine) | `crates/ai/src/rebuild/` (kinds, checks and stacks are pluggable: docs/extending.md). Three kinds: website, app, game (a project whose stack is a game engine is always a game). The request decides how to build: a language, framework, engine or platform it names wins over the kind's default stack (Rust + egui for apps, Unity for games, the original's for websites), and the build check, the recorded stack and Play follow what was built (an Electron app opens in its own Electron; a plain static site has nothing to build and passes the build check as it is). Websites: Study also captures up to 4 other pages of the site; menus are opened on a computer and on a phone; the check serves the build on loopback and compares every page at 1440, 768 and 390 px (likeness = mean of layout and perceptual detail, SSIM, averaged over pages, leaving out the parts of the original that change by themselves, found by photographing it three times; the note adds text, page structure, the colours, font, text sizes and spacing the build misses, and per width a page that scrolls sideways, heading sizes and sections whose padding, items per row or content column differ, the errors, failed requests and accessibility gaps the build adds, and the opened menus and pop-ups). A stack or library named in the request (Next.js, shadcn/ui, Tailwind CSS…, `stacks.toml`) is what the builder uses; with none named, a website's stack is the builder's choice (told to match what the original is built with) and the stack it used is recorded from app/package.json. The builder leads: it studies, asks the tools follow-up questions, records what it can't find out as unknowns (`core_unknown_add`; the run reports the open ones), and tests its own build mid-turn with `rebuild_check` (the same checks, for every kind); a check with anything it couldn't compare, or any claim that fails (a website page that scrolls sideways, logs new errors, fails to load a file, lacks a landmark, or a menu that doesn't open; for games each self-test step, for Deep-mode sheets each original number in the code, for console apps the same exit and output as the original's runs), isn't good enough; apps and games by whether they build. Up to 6 refinement rounds, or until a website reaches 90% likeness. A turn cut off by a time limit, crash or dropped connection resumes (up to 3 times); builder turns may run 24 h. A project copied from another computer (or moved to another folder) keeps building with Claude Code: the project keeps a copy of the builder's session (`agent-session.jsonl`) after every turn and puts it back where Claude Code finds it on a computer without it, so the same conversation carries on (#451); when the session still isn't there, a new one starts from the brief, what's in app/ and the kept requests and replies (or the last summary), and questions about the build put the kept session back too, else are answered from the files and forget the missing session (#452). Live runs with Claude Code 2.1.316 on one Mac (2026-11-02), a second computer stood in for by a separate signed-in `CLAUDE_CONFIG_DIR`: a copied project's session was put back and resumed (the builder recalled its first reply from memory); a kept copy of another session was refused and the new session used the handoff; a real project synced from Windows whose session was missing started afresh and reached Ready. Not yet run between two real computers | Unit tests for prompts, stack choice, site detection, feed folding; live runs reached Build and decompiling (below) |