I rebuilt a question found in actual production source as independent synthetic code. The complete implementation, examples and tests are shared without connecting the original business program or material.
Keep three distinct values
Current input, supplied saved input and example origin remain separate. Opening an example preserves the draft; saved input becomes current only through an explicit load. The model develops the source screen’s example-first and draft-offer structure into an inspectable origin contract.
It does not read localStorage or control tabs. Functions copy supplied values and return new state, with no actual deletion or cross-device synchronization. An interface message and durable server persistence are therefore different promises.
Check the local revision before replacement
Loading, preset application and current reset check an expected revision. An action created before an edit fails. Clearing a stored value and resetting the current one also have distinct consequences. This policy was added independently, not installed in the original business application.
The revision describes ordering inside one document. It provides no authentication, server locking or cross-user concurrency solution. Those remain separate integration responsibilities; a small draft-preservation function should not imply them.
An envelope is not a valid measurement
Storage accepts version one and bounded distance and liters text. The query accepts one known preset, rejecting duplicates and unknown keys. A valid draft string is not necessarily a valid measurement; units and numeric bounds require separate calculation validation.
The complete code follows. Non-mutating functions make before-and-after state inspectable. Extending fields requires reviewing personal-data exposure and old-version handling; increasing a version number alone is not a compatibility policy.
Explore the implementation
Complete independent synthetic implementation
"""Synthetic draft-origin state only. No browser storage, server or URL navigation."""
from copy import deepcopy
from urllib.parse import parse_qsl
PRESETS={'example-v1':{'distance':'100','liters':'20'}}
def fields(value):
if not isinstance(value,dict) or set(value)!={'distance','liters'}:raise ValueError('known draft fields')
if any(not isinstance(v,str) or len(v)>40 for v in value.values()):raise ValueError('bounded draft text')
return dict(value)
def import_stored(value):
if value is None:return None
if not isinstance(value,dict) or set(value)!={'version','inputs'} or type(value['version']) is not int or value['version']!=1:raise ValueError('storage version')
return {'version':1,'inputs':fields(value['inputs'])}
def query_preset(query):
if not isinstance(query,str) or len(query)>200:raise ValueError('bounded query')
values=parse_qsl(query.lstrip('?'),keep_blank_values=True,strict_parsing=True)
if len(values)>1 or any(k!='preset' for k,v in values):raise ValueError('known query only')
if not values:return None
name=values[0][1]
if name not in PRESETS:raise ValueError('unknown preset')
return name
def open_state(preset=None,stored=None):
stored=import_stored(stored)
if preset is not None and preset not in PRESETS:raise ValueError('unknown preset')
return {'revision':0,'current':deepcopy(PRESETS[preset]) if preset else {'distance':'','liters':''},'origin':'example' if preset else 'blank','stored':deepcopy(stored)}
def require_revision(state,expected):
if type(expected) is not int or expected!=state['revision']:raise ValueError('input changed')
def edit(state,field,text):
if field not in ('distance','liters') or not isinstance(text,str) or len(text)>40:raise ValueError('edit')
out=deepcopy(state);out['current'][field]=text;out['revision']+=1;out['origin']='edited';return out
def save_draft(state):
out=deepcopy(state);out['stored']={'version':1,'inputs':fields(state['current'])};return out
def load_saved(state,expected):
require_revision(state,expected)
if state['stored'] is None:raise ValueError('no saved draft')
out=deepcopy(state);out['current']=fields(import_stored(state['stored'])['inputs']);out['revision']+=1;out['origin']='saved';return out
def clear_saved(state):
out=deepcopy(state);out['stored']=None;return out
def reset_current(state,expected):
require_revision(state,expected);out=deepcopy(state);out.update(current={'distance':'','liters':''},origin='blank',revision=state['revision']+1);return out
def apply_preset(state,preset,expected):
require_revision(state,expected)
if preset not in PRESETS:raise ValueError('unknown preset')
out=deepcopy(state);out.update(current=deepcopy(PRESETS[preset]),origin='example',revision=state['revision']+1);return outCheck two different reset outcomes
With example A current and draft B stored, clearing saved data preserves A. Starting from the same state, resetting current input preserves B. Recording both outcomes makes action labels meaningful and explains why current and stored values must not share one variable.
The counterexample is inspectable through tests and saved execution records. Adoption requires checking input meaning and failure policy before changing labels. A small independent function does not replace an operational application.
Published code and ZIP use the same reviewed files. The central decision can be inspected without importing company records or running another system. Any added integration needs separate observed results; the existing package does not pre-certify its behavior.
Actual execution evidence and its boundary
The source folder and a fresh ZIP extraction each passed 14 tests. Actual example results are saved in records.json, and the published core can be compared with the download. Historical project completion messages and test totals were not reused as evidence of this execution.
The selector reads results saved by actual local runs; it does not execute Python or a server in the browser. These checks do not establish rendered-browser or physical-device behavior. An integrated service needs its own observed verification rather than inheriting a broader claim from these small tests.
Before adapting the download
The ZIP contains core implementation, tests, runner, saved results and guidance; live examples also include bilingual HTML. This is new synthetic code with permission to modify and reuse, without original customer images, operational records or credentials. It contains no instruction to execute the source business program or transmit its material.
Begin adoption by defining units, input provenance and failure messages for the actual workflow. Passing tests cannot certify all supplied facts or grant operational authority. Authentication, persistence, transmission and rendered-interface review remain outside the small contract. I share both a reusable implementation and the decisions an adopter still needs to make.