Skip to content

Commit 8e63a44

Browse files
test: share the retired-with-resources fixture
PR #439 added `retired_catalog_with_resources` to tests/doctor.rs — a 20-line copy of `retired_catalog` differing only in the retirement clause and two `resource` lines — and duplicated the same two-`resource` KDL literal inline in tests/agent_desired_state.rs. Hoist the literal to `support::RETIRED_RESOURCES`, parameterize `retired_catalog(root, retirement, extra)`, and delete the clone. Net -4 lines with the 20-line clone gone; the fixture literal now exists once. agent-identity: dev3.direct.omp.v6c4mkm2 agent-persona: generalist agent-supervisor: unavailable agent-tool: OMP agent-tool-version: 18.1.2 agent-runtime: OMP 18.1.2 tooling-profile: dotfiles@7534055
1 parent 4b06068 commit 8e63a44

3 files changed

Lines changed: 28 additions & 32 deletions

File tree

tests/agent_desired_state.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use std::fs;
22
use std::path::Path;
33
use std::process::{Command, Output};
44

5+
mod support;
6+
7+
use support::RETIRED_RESOURCES;
8+
59
fn write(root: &Path, relative: &str, contents: &str) {
610
let path = root.join(relative);
711
fs::create_dir_all(path.parent().unwrap()).unwrap();
@@ -250,12 +254,8 @@ fn cli_applies_the_existing_self_or_descendant_authority_guardrail() {
250254
fn legacy_retirement_reads_and_authoring_preserves_resources() {
251255
let temporary = tempfile::tempdir().unwrap();
252256
let root = temporary.path();
253-
let resources = concat!(
254-
" resource \"work\" uri=\"work://h/current-task\" reason=\"Current implementation task.\"\n",
255-
" resource \"issue\" uri=\"github-issue://example/project/41\" reason=\"Tracking issue.\"\n",
256-
);
257257
let legacy = format!(
258-
"agent \"worker\" {{\n host \"h\"\n retired #true\n{resources} command \"true\"\n}}\n"
258+
"agent \"worker\" {{\n host \"h\"\n retired #true\n{RETIRED_RESOURCES} command \"true\"\n}}\n"
259259
);
260260
write(root, "h/worker/agent.kdl", &legacy);
261261

tests/doctor.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,21 @@ use std::time::{Duration, Instant};
88

99
use sha2::{Digest as _, Sha256};
1010

11+
mod support;
12+
13+
use support::RETIRED_RESOURCES;
14+
1115
fn executable(path: &Path, body: &str) {
1216
fs::write(path, body).unwrap();
1317
fs::set_permissions(path, fs::Permissions::from_mode(0o755)).unwrap();
1418
}
1519

16-
fn retired_catalog(root: &Path) -> Child {
17-
let declaration = root.join("agents/h/gone/agent.kdl");
18-
fs::create_dir_all(declaration.parent().unwrap()).unwrap();
19-
fs::write(
20-
declaration,
21-
"agent \"gone\" { host \"h\"; retired #true; command \"true\" }\n",
22-
)
23-
.unwrap();
24-
let owner = Command::new("sleep").arg("30").spawn().unwrap();
25-
fs::write(root.join(".st2.h.lock"), format!("{}\n", owner.id())).unwrap();
26-
owner
27-
}
28-
29-
fn retired_catalog_with_resources(root: &Path) -> Child {
20+
fn retired_catalog(root: &Path, retirement: &str, extra: &str) -> Child {
3021
let declaration = root.join("agents/h/gone/agent.kdl");
3122
fs::create_dir_all(declaration.parent().unwrap()).unwrap();
3223
fs::write(
3324
declaration,
34-
concat!(
35-
"agent \"gone\" {\n",
36-
" host \"h\"\n",
37-
" desired-state \"retired\" reason=\"Mission complete\"\n",
38-
" resource \"work\" uri=\"work://h/current-task\" reason=\"Current implementation task.\"\n",
39-
" resource \"issue\" uri=\"github-issue://example/project/41\" reason=\"Tracking issue.\"\n",
40-
" command \"true\"\n",
41-
"}\n",
42-
),
25+
format!("agent \"gone\" {{\n host \"h\"\n {retirement}\n{extra} command \"true\"\n}}\n"),
4326
)
4427
.unwrap();
4528
let owner = Command::new("sleep").arg("30").spawn().unwrap();
@@ -323,7 +306,7 @@ fn retired_declaration_is_healthy_when_tasks_and_presence_are_absent() {
323306
&bin.join("pty"),
324307
"#!/bin/sh\nif [ \"$1\" = list ]; then printf '[]\\n'; fi\n",
325308
);
326-
let mut owner = retired_catalog(&catalog);
309+
let mut owner = retired_catalog(&catalog, "retired #true", "");
327310

328311
let output = doctor(&catalog, &bin, &tmp.path().join("state"));
329312
let _ = owner.kill();
@@ -359,7 +342,11 @@ fn retired_declaration_with_resources_is_healthy_when_tasks_are_absent() {
359342
"#!/bin/sh\nif [ \"$1\" = list ]; then printf '[]\\n'; fi\n",
360343
);
361344
let declaration = catalog.join("agents/h/gone/agent.kdl");
362-
let mut owner = retired_catalog_with_resources(&catalog);
345+
let mut owner = retired_catalog(
346+
&catalog,
347+
"desired-state \"retired\" reason=\"Mission complete\"",
348+
RETIRED_RESOURCES,
349+
);
363350
let before = fs::read(&declaration).unwrap();
364351

365352
let output = doctor(&catalog, &bin, &tmp.path().join("state"));
@@ -395,7 +382,7 @@ fn retired_declaration_is_unhealthy_while_a_declared_task_is_alive() {
395382
&bin.join("pty"),
396383
"#!/bin/sh\nif [ \"$1\" = list ]; then printf '[{\"name\":\"h.gone\",\"status\":\"running\"}]\\n'; fi\n",
397384
);
398-
let mut owner = retired_catalog(&catalog);
385+
let mut owner = retired_catalog(&catalog, "retired #true", "");
399386

400387
let output = doctor(&catalog, &bin, &tmp.path().join("state"));
401388
let _ = owner.kill();
@@ -433,7 +420,7 @@ fn retired_declaration_is_unhealthy_while_a_dead_task_record_remains() {
433420
&bin.join("pty"),
434421
"#!/bin/sh\nif [ \"$1\" = list ]; then printf '[{\"name\":\"h.gone\",\"status\":\"exited\"}]\\n'; fi\n",
435422
);
436-
let mut owner = retired_catalog(&catalog);
423+
let mut owner = retired_catalog(&catalog, "retired #true", "");
437424

438425
let output = doctor(&catalog, &bin, &tmp.path().join("state"));
439426
let _ = owner.kill();

tests/support/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Shared by several test binaries; each one uses only the parts it needs.
2+
#![allow(dead_code)]
3+
14
use std::io;
25
use std::ops::{Deref, DerefMut};
36
use std::os::fd::{AsRawFd as _, OwnedFd};
@@ -10,6 +13,12 @@ use std::time::{Duration, Instant};
1013

1114
const CLEANUP_DEADLINE: Duration = Duration::from_secs(2);
1215

16+
/// A retired agent's declared `resource` bindings, shared by the desired-state and doctor fixtures.
17+
pub const RETIRED_RESOURCES: &str = concat!(
18+
" resource \"work\" uri=\"work://h/current-task\" reason=\"Current implementation task.\"\n",
19+
" resource \"issue\" uri=\"github-issue://example/project/41\" reason=\"Tracking issue.\"\n",
20+
);
21+
1322
/// A subprocess group whose lifetime is bounded by the test process that spawned it.
1423
///
1524
/// A watchdog pins the process-group identity and observes a close-on-exec socket owned only by the

0 commit comments

Comments
 (0)