fix: preserve documents on repeat create

This commit is contained in:
Eric Wendland 2026-07-05 22:43:02 +02:00
commit 6fc1410e65
3 changed files with 25 additions and 4 deletions

View file

@ -7754,6 +7754,11 @@ pub fn handle_request(
ControlRequest::DocumentCreate { name } => { ControlRequest::DocumentCreate { name } => {
geth_document::validate_document_name(&name) geth_document::validate_document_name(&name)
.map_err(|_| NodeError::InvalidDocumentName(name.clone()))?; .map_err(|_| NodeError::InvalidDocumentName(name.clone()))?;
if let Some(existing) = store.get_document_resource_by_name(&name)? {
return Ok(ControlResponse::DocumentCreated {
document: document_resource_from_stored(&existing),
});
}
let resource_id = format!("resource:document:{name}"); let resource_id = format!("resource:document:{name}");
let document_id = format!("document:{name}"); let document_id = format!("document:{name}");
let resource = StoredResource { let resource = StoredResource {

View file

@ -3617,6 +3617,14 @@ fn kv_create_set_get_use_local_store() {
other => panic!("unexpected response: {other:?}"), other => panic!("unexpected response: {other:?}"),
} }
geth_node::handle_request(
&node,
geth_control::ControlRequest::KvCreate {
name: "prefs".to_owned(),
},
)
.expect("repeat kv create");
let response = geth_node::handle_request( let response = geth_node::handle_request(
&node, &node,
geth_control::ControlRequest::KvGet { geth_control::ControlRequest::KvGet {
@ -3772,6 +3780,14 @@ fn document_create_and_status_use_local_store() {
other => panic!("unexpected response: {other:?}"), other => panic!("unexpected response: {other:?}"),
} }
geth_node::handle_request(
&node,
geth_control::ControlRequest::DocumentCreate {
name: "notes".to_owned(),
},
)
.expect("repeat document create");
let reopened = geth_node::open_node(&paths).expect("reopen node"); let reopened = geth_node::open_node(&paths).expect("reopen node");
let response = geth_node::handle_request( let response = geth_node::handle_request(
&reopened, &reopened,

View file

@ -252,11 +252,11 @@ Goal: make `geth` ergonomic and stable as a base layer for custom automation.
or stale. or stale.
- `[x]` Wait commands support JSON output and timeout flags. - `[x]` Wait commands support JSON output and timeout flags.
- `[ ]` Make common commands idempotent. - `[x]` Make common commands idempotent.
Acceptance criteria: Acceptance criteria:
- `[ ]` Resource creation commands can be safely repeated where practical. - `[x]` Resource creation commands can be safely repeated where practical.
- `[ ]` Grant creation supports deterministic caller-provided IDs. - `[x]` Grant creation supports deterministic caller-provided IDs.
- `[ ]` Repeated sync and import commands report no-op state clearly. - `[x]` Repeated sync and import commands report no-op state clearly.
- `[x]` Publish automation examples. - `[x]` Publish automation examples.
Acceptance criteria: Acceptance criteria: