Skip to content

Commit 2b520f1

Browse files
davafonsclaude
andcommitted
up: report only a ready run as already running
A crashed run goes on to the start path again, which replaces it. The live suites now expect a second up to report the running environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3da64c1 commit 2b520f1

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

‎scripts/live/core.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def run(caddy, compose, **_):
101101
first = live.json(compose_path, 'up', '--detach', '--process-compose', compose)
102102
assert first['detached'] and first['live']['state'] == 'ready'
103103
assert first['workspace']['generation'] == first['session']['generation']
104-
assert cli(compose_path, 'up', '--detach', '--process-compose', compose, check=False).returncode != 0
104+
again = live.json(compose_path, 'up', '--detach', '--process-compose', compose)
105+
assert again['already_running'] and again['session']['token'] == first['session']['token']
105106
second = live.json(compose_path, 'restart', '--detach', '--process-compose', compose)
106107
assert second['session']['generation'] > first['session']['generation']
107108
assert second['session']['token'] != first['session']['token']

‎scripts/live/recovery.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,12 @@ def up_recovers_surviving_graph(f):
311311
assert status['state'] == 'ready' and [process['name'] for process in status['processes']] == ['web'], status
312312
assert status['processes'][0]['state'] == 'running' and status['processes'][0]['pid'], status
313313
duplicate = f.cli(app['path'], 'up', '--detach', '--process-compose', f.compose, '--backend-port', str(app['port']))
314-
assert duplicate.returncode != 0 and json.loads(f.probe(app)[1])['pid'] == service['pid'], 'a live owner is never replaced'
314+
assert duplicate.returncode == 0 and json.loads(duplicate.stdout)['already_running'], duplicate.stderr
315+
assert f.session(app)['token'] == before['token'] and json.loads(f.probe(app)[1])['pid'] == service['pid'], 'a live owner is never replaced'
315316
down = f.cli(app['path'], 'down')
316317
assert down.returncode == 0 and json.loads(down.stdout)['state'] == 'stopped', down.stderr
317318
assert not listening(app['port'])
318-
return {'up_detach_recovered': True, 'service_pid_preserved': True, 'generation_preserved': True, 'duplicate_up_refused': True}
319+
return {'up_detach_recovered': True, 'service_pid_preserved': True, 'generation_preserved': True, 'duplicate_up_reported': True}
319320

320321
def up_foreground_recovers_surviving_graph(f):
321322
app = f.app('upforeground')

‎src/cli/commands.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{
33
output::{Output, status_diagnostics},
44
render,
55
};
6-
use anyhow::{Context, Result, bail, ensure};
6+
use anyhow::{Context, Result, ensure};
77
use parcela::{
88
config::{Manifest, locate},
99
context::ResolvedContext,
@@ -565,7 +565,7 @@ fn start(state: &Path, path: &Path, start: Start, out: Output) -> Result<i32> {
565565
}
566566

567567
/// `up` on a ready environment reports it like a fresh start, as `docker compose up -d` does.
568-
/// Any other live state, or a ready run without the sharing asked for, is refused.
568+
/// A ready run without the sharing asked for is refused.
569569
fn already_running(
570570
registry: &Registry,
571571
workspace: &Workspace,
@@ -579,14 +579,10 @@ fn already_running(
579579
}
580580
let status = lifecycle::status(registry, workspace)?;
581581
let name = render::name(&serde_json::to_value(workspace)?);
582+
// Anything but ready goes on to the start path, which takes back or replaces a crashed run.
582583
let state = status["state"].as_str().unwrap_or("unknown");
583-
match state {
584-
"ready" => {}
585-
"unknown" => bail!(
586-
"{name} has a run Parcela cannot reach ({}); see `parcela status`",
587-
status["diagnostic"].as_str().unwrap_or("no owner")
588-
),
589-
_ => bail!("{name} is {state}; see `parcela status`, or run `parcela restart`"),
584+
if state != "ready" {
585+
return Ok(None);
590586
}
591587
let shared: Vec<&str> = status["live"]["endpoints"]
592588
.as_object()

0 commit comments

Comments
 (0)