Files
bsodfather 54ce770682
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.

Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
  Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
  3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
  revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
  version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
  dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
  resources/list admission fix for bound template publications.

Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
  `just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
  a real MCP Inspector 2.12.0 client smoke.

Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
  runs only on main), story events run the changed packages, the full workspace suite
  stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
  release entry of the tag instead of dying with the runner workspace.

Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.

Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
2026-10-25 09:08:22 +00:00

758 lines
28 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! ATDD (RED) Story 3.7 — AC04 и stale-Agent часть AC06: exact Resource binding.
//!
//! Источники: live Gitea #14 (`STORY37-SOURCE.md`, AC04/AC06), canonical `tickets.toml`
//! entry 7 (lines 174–232), `docs/acceptance-test-plan.md` AT-3.7-04/06,
//! `_bmad-output/test-artifacts/test-design-epic-3.md` rows 3.7-INT-A/B (risk E3-R3) и
//! TL interface decisions (`.tmp/t_8c38b75f/STORY37-NEXT.md`, пункты 1–4).
//!
//! Контракт реализован в Story 3.7 build: `resource_bindings` в Config-форме
//! `POST .../agents/{agent_id}/bindings`, отдельный `resource_bindings` в ответе
//! `AgentVersionRecord`, typed binding table `agent_resource_bindings` (V18) и
//! атомарный `catalog_revision`. Эти тесты остаются behavioural ATDD: они
//! проверяют реальный HTTP-ответ и PostgreSQL-инварианты, а не строки исходников.
//! Позитивный контроль `story37_at04_...` держит уже принятое поведение публикации
//! Resource (`story37_at03_*`) и публикации Agent.
//!
//! Фильтр запуска:
//! `cargo test -p admin-api --test integration --locked story37_at04_ -- --test-threads=1`
//! (stale-Agent тесты: `story37_at06_`).
use reqwest::StatusCode;
use serde_json::json;
use serial_test::serial;
use super::common::*;
mod fixtures;
use fixtures::*;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_resource_binding_pins_exact_published_version() {
let (_registry, server, client) = spawn_workspace("story37_at04_pin").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/pin",
"pin_doc",
b"v1\n",
)
.await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_pin_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at04-pin-agent").await;
// Config-форма: существующие Operation bindings + additive exact Resource binding.
let saved = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_pin_tool")]),
json!([resource_binding(&resource_id, 1)]),
),
"AC04 exact binding v1",
)
.await;
assert_eq!(
saved["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"save response must expose the exact typed Resource binding next to Operation bindings: \
{saved}"
);
assert_eq!(
saved["bindings"].as_array().map(|items| items.len()),
Some(1),
"existing Operation bindings must keep their meaning in Config form: {saved}"
);
let draft = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
draft["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"GET versions/1 must return the same exact typed Resource binding: {draft}"
);
let before_publish = get_agent(&client, &server_url, &agent_id).await;
let catalog_before = before_publish["catalog_revision"]
.as_i64()
.unwrap_or_else(|| panic!("agent summary must expose catalog_revision: {before_publish}"));
publish_agent_expect_success(&client, &server_url, &agent_id, 1, "AC04 publication").await;
let after_publish = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after_publish["catalog_revision"].as_i64(),
Some(catalog_before + 1),
"Agent publication must raise catalog_revision by exactly one: {before_publish} -> {after_publish}"
);
let published = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
published["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the published immutable Agent snapshot must carry the exact Resource Version: {published}"
);
// Resource v2 не меняет уже зафиксированный v1 snapshot и catalog_revision.
edit_and_publish_second_version(&client, &server_url, &resource_id, b"v2\n", "resource v2")
.await;
let still_pinned = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
still_pinned["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"a newer Published Resource Version must not replace the pinned v1 in the Agent snapshot: \
{still_pinned}"
);
let after_resource_v2 = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after_resource_v2["catalog_revision"].as_i64(),
Some(catalog_before + 1),
"a Resource publication must not bump the Agent catalog_revision: {after_resource_v2}"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_republish_agent_changes_resource_snapshot_only_explicitly() {
let (_registry, server, client) = spawn_workspace("story37_at04_republish").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/republish",
"republish_doc",
b"pinned v1\n",
)
.await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_republish_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at04-republish-agent").await;
save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_republish_tool")]),
json!([resource_binding(&resource_id, 1)]),
),
"republish: initial v1 binding",
)
.await;
publish_agent_expect_success(&client, &server_url, &agent_id, 1, "republish: publish v1").await;
let published_v1 = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
published_v1["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"published v1 snapshot must carry Resource v1: {published_v1}"
);
edit_and_publish_second_version(&client, &server_url, &resource_id, b"pinned v2\n", "v2").await;
// Явное изменение binding на v2 форкает новый Draft и только он несёт v2.
let draft_v2 = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_republish_tool")]),
json!([resource_binding(&resource_id, 2)]),
),
"republish: explicit v2 binding",
)
.await;
assert_eq!(
draft_v2["version"],
json!(2),
"editing a published Agent must fork exactly one new Draft version: {draft_v2}"
);
assert_eq!(
draft_v2["resource_bindings"],
expected_resource_bindings(&resource_id, 2),
"the new Draft must carry the explicitly requested v2: {draft_v2}"
);
// Старый published snapshot остаётся exact v1.
let published_v1_after = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
published_v1_after["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the earlier published snapshot must not change when the Draft pins v2: {published_v1_after}"
);
let before_republish = get_agent(&client, &server_url, &agent_id).await;
let catalog_before = before_republish["catalog_revision"].as_i64().unwrap();
publish_agent_expect_success(&client, &server_url, &agent_id, 2, "republish: publish v2").await;
let published_v2 = get_agent_version(&client, &server_url, &agent_id, 2).await;
assert_eq!(
published_v2["resource_bindings"],
expected_resource_bindings(&resource_id, 2),
"the explicitly republished snapshot must carry v2: {published_v2}"
);
let after_republish = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after_republish["catalog_revision"].as_i64(),
Some(catalog_before + 1),
"the second Agent publication must raise catalog_revision by exactly one: {after_republish}"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_foreign_and_unpublished_versions_are_sanitized_404() {
let (registry, server, client) = spawn_workspace("story37_at04_scope").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
// Draft, который никогда не публиковался: точная версия недоступна для binding.
let unpublished_metadata = draft_metadata(
"crank://story37/unpublished",
"unpublished_doc",
"text",
"text/plain",
"internal",
);
let (unpublished_id, _) = create_draft(
&client,
&server_url,
&unpublished_metadata,
b"never published\n",
"story37-unpublished.txt",
"text/plain",
)
.await;
// Чужой опубликованный Resource Version в WorkspaceB.
let foreign_workspace =
create_owned_workspace(&registry, "ws_story37_at04_foreign", "story37-at04-foreign").await;
let foreign_url = workspace_url(&server, foreign_workspace.as_str());
let foreign_client = authorized_client(&foreign_url).await;
let (foreign_id, _) = create_published_resource(
&foreign_client,
&foreign_url,
"crank://story37/foreign",
"foreign_doc",
b"foreign v1\n",
)
.await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_scope_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at04-scope-agent").await;
save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_scope_tool")]),
json!([]),
),
"scope: base Agent config",
)
.await;
let before = get_agent(&client, &server_url, &agent_id).await;
let before_version = get_agent_version(&client, &server_url, &agent_id, 1).await;
let before_catalog = before["catalog_revision"].as_i64().unwrap();
let before_versions = agent_version_count(&registry, &agent_id).await;
let etag = agent_etag(&client, &server_url, &agent_id).await;
let (foreign_status, foreign_text, foreign_body) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_scope_tool")]),
json!([resource_binding(&foreign_id, 1)]),
),
)
.await;
assert_eq!(
foreign_status,
StatusCode::NOT_FOUND,
"a foreign workspace Resource Version must be refused as sanitized 404; \
observed {foreign_status} body={foreign_text}"
);
assert!(
foreign_body["error"]["code"].is_string(),
"refusal must keep the sanitized error envelope: {foreign_text}"
);
let etag = agent_etag(&client, &server_url, &agent_id).await;
let (unpublished_status, unpublished_text, unpublished_body) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_scope_tool")]),
json!([resource_binding(&unpublished_id, 1)]),
),
)
.await;
assert_eq!(
unpublished_status,
StatusCode::NOT_FOUND,
"an unpublished Resource Version must be refused as sanitized 404; \
observed {unpublished_status} body={unpublished_text}"
);
assert_eq!(
unpublished_body["error"]["code"], foreign_body["error"]["code"],
"foreign and unpublished/missing versions must be indistinguishable: \
foreign={foreign_text} unpublished={unpublished_text}"
);
// Несуществующая Resource Version даёт тот же sanitized 404 (нет утечки существования).
let etag = agent_etag(&client, &server_url, &agent_id).await;
let (missing_status, missing_text, missing_body) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_scope_tool")]),
json!([resource_binding("res_story37_missing", 1)]),
),
)
.await;
assert_eq!(
missing_status,
StatusCode::NOT_FOUND,
"a missing Resource Version must be refused as sanitized 404; \
observed {missing_status} body={missing_text}"
);
assert_eq!(
missing_body["error"]["code"], foreign_body["error"]["code"],
"missing, foreign and unpublished versions must share one taxonomy: \
foreign={foreign_text} missing={missing_text}"
);
// Отказ не меняет Draft/snapshot/catalog_revision и не пишет новую версию.
assert_eq!(
get_agent_version(&client, &server_url, &agent_id, 1).await,
before_version,
"a refused Resource binding must not mutate the Agent version"
);
let after = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after["catalog_revision"].as_i64(),
Some(before_catalog),
"a refused Resource binding must not change catalog_revision: {after}"
);
assert_eq!(
after["current_draft_version"], before["current_draft_version"],
"a refused Resource binding must not fork a Draft version: {after}"
);
assert_eq!(
agent_version_count(&registry, &agent_id).await,
before_versions,
"a refused Resource binding must not write an Agent version row"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_duplicate_and_invalid_resource_bindings_refused_without_writes() {
let (registry, server, client) = spawn_workspace("story37_at04_invalid").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/invalid",
"invalid_doc",
b"valid v1\n",
)
.await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_invalid_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at04-invalid-agent").await;
let saved = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_invalid_tool")]),
json!([resource_binding(&resource_id, 1)]),
),
"invalid: base config",
)
.await;
assert_eq!(
saved["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"base config must be saved before the refusal checks: {saved}"
);
let before = get_agent(&client, &server_url, &agent_id).await;
let before_version = get_agent_version(&client, &server_url, &agent_id, 1).await;
let before_catalog = before["catalog_revision"].as_i64().unwrap();
let before_versions = agent_version_count(&registry, &agent_id).await;
// Повтор пары в одном запросе — validation refusal без partial writes.
let duplicate = json!([
resource_binding(&resource_id, 1),
resource_binding(&resource_id, 1)
]);
let etag = agent_etag(&client, &server_url, &agent_id).await;
let (status, text, body) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_invalid_tool")]),
duplicate,
),
)
.await;
assert_eq!(
status,
StatusCode::BAD_REQUEST,
"a duplicated (resource_id, resource_version) pair must be a validation refusal; \
observed {status} body={text}"
);
assert!(
body["error"]["code"].is_string(),
"validation refusal must keep the sanitized error envelope: {text}"
);
// Невалидный exact version (не positive integer) также отклоняется до записи.
let etag = agent_etag(&client, &server_url, &agent_id).await;
let (status, text, _) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_invalid_tool")]),
json!([resource_binding(&resource_id, 0)]),
),
)
.await;
assert_eq!(
status,
StatusCode::BAD_REQUEST,
"resource_version must be a positive exact integer; observed {status} body={text}"
);
assert_eq!(
get_agent_version(&client, &server_url, &agent_id, 1).await,
before_version,
"invalid Resource bindings must not mutate the Agent version"
);
let after = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after["catalog_revision"].as_i64(),
Some(before_catalog),
"invalid Resource bindings must not change catalog_revision: {after}"
);
assert_eq!(
after["current_draft_version"], before["current_draft_version"],
"invalid Resource bindings must not fork a Draft version: {after}"
);
assert_eq!(
agent_version_count(&registry, &agent_id).await,
before_versions,
"invalid Resource bindings must not write an Agent version row"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_resource_only_agent_publishes_exact_snapshot() {
let (_registry, server, client) = spawn_workspace("story37_at04_resource_only").await;
let server_url = server.as_ref().to_owned();
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/resource-only",
"resource_only_doc",
b"resource only\n",
)
.await;
let agent_id = create_agent(&client, &server_url, "story37-at04-resource-only").await;
let saved = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(json!([]), json!([resource_binding(&resource_id, 1)])),
"resource-only Agent: save",
)
.await;
assert_eq!(
saved["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"a Resource-only Agent must still expose its exact typed binding: {saved}"
);
assert_eq!(
saved["bindings"].as_array().map(|items| items.len()),
Some(0),
"empty Operation bindings must stay valid: {saved}"
);
let before = get_agent(&client, &server_url, &agent_id).await;
let catalog_before = before["catalog_revision"].as_i64().unwrap();
publish_agent_expect_success(
&client,
&server_url,
&agent_id,
1,
"resource-only Agent publication",
)
.await;
let published = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
published["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the published snapshot must atomically include the Resource: {published}"
);
let after = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after["catalog_revision"].as_i64(),
Some(catalog_before + 1),
"resource-only publication must raise catalog_revision by exactly one: {after}"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at04_absent_or_legacy_config_preserves_and_explicit_empty_clears() {
let (_registry, server, client) = spawn_workspace("story37_at04_tristate").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/tristate",
"tristate_doc",
b"tristate v1\n",
)
.await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_tristate_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at04-tristate-agent").await;
let saved = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_tristate_tool")]),
json!([resource_binding(&resource_id, 1)]),
),
"tristate: base v1 binding",
)
.await;
assert_eq!(
saved["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the base config must pin v1: {saved}"
);
// Config без поля `resource_bindings` сохраняет прежние Resource bindings.
let preserved = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&json!({
"bindings": [operation_binding(&operation_id, "story37_tristate_tool")],
"tool_selection_policy": {},
}),
"tristate: absent field preserves",
)
.await;
assert_eq!(
preserved["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"an absent additive field must preserve the exact binding: {preserved}"
);
// Legacy array-форма тоже сохраняет прежние Resource bindings.
let legacy = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&json!([operation_binding(&operation_id, "story37_tristate_tool")]),
"tristate: legacy array preserves",
)
.await;
assert_eq!(
legacy["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the legacy Operation-bindings array must keep Resource bindings: {legacy}"
);
// Явный `[]` очищает Resource bindings в Draft.
let cleared = save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_tristate_tool")]),
json!([]),
),
"tristate: explicit empty clears",
)
.await;
assert_eq!(
cleared["resource_bindings"],
json!([]),
"an explicit empty list must clear Resource bindings: {cleared}"
);
let reread = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
reread["resource_bindings"],
json!([]),
"the cleared state must be durable on version 1: {reread}"
);
}
// ---------------------------------------------------------------------------
// AC06: stale Agent revision (Resource binding часть)
// ---------------------------------------------------------------------------
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial]
async fn story37_at06_stale_agent_save_and_publish_leave_resource_bindings_untouched() {
let (registry, server, client) = spawn_workspace("story37_at06_stale").await;
let server_url = server.as_ref().to_owned();
let upstream = spawn_upstream_server().await;
let (resource_id, _) = create_published_resource(
&client,
&server_url,
"crank://story37/stale",
"stale_doc",
b"stale v1\n",
)
.await;
edit_and_publish_second_version(&client, &server_url, &resource_id, b"stale v2\n", "v2").await;
let operation_id =
create_published_operation(&client, &server_url, &upstream, "story37_stale_tool").await;
let agent_id = create_agent(&client, &server_url, "story37-at06-stale-agent").await;
save_bindings_expect_success(
&client,
&server_url,
&agent_id,
&catalog_config(
json!([operation_binding(&operation_id, "story37_stale_tool")]),
json!([resource_binding(&resource_id, 1)]),
),
"stale: base v1 binding",
)
.await;
// Устаревший If-Match: параллельная правка summary тем же клиентом.
let stale_etag = agent_etag(&client, &server_url, &agent_id).await;
let summary_update = read_response(
client
.patch(format!("{server_url}/agents/{agent_id}"))
.header(reqwest::header::IF_MATCH, stale_etag.clone())
.json(&json!({
"slug": "story37-at06-stale-agent",
"display_name": "Story 3.7 stale agent (renamed)",
"description": "concurrent summary edit makes the prior ETag stale"
}))
.send()
.await
.expect("summary update must complete"),
)
.await;
assert_eq!(
summary_update.0,
StatusCode::OK,
"positive control: the summary edit must be accepted first; observed {} body={}",
summary_update.0,
summary_update.1
);
let before = get_agent(&client, &server_url, &agent_id).await;
let before_version = get_agent_version(&client, &server_url, &agent_id, 1).await;
assert_eq!(
before_version["resource_bindings"],
expected_resource_bindings(&resource_id, 1),
"the draft must keep Resource v1 before the stale attempts: {before_version}"
);
let catalog_before = before["catalog_revision"].as_i64().unwrap();
let versions_before = agent_version_count(&registry, &agent_id).await;
// Stale save с явно запрошенным v2 не должен ничего записать.
let (status, text, body) = save_bindings_raw(
&client,
&server_url,
&agent_id,
&stale_etag,
&catalog_config(
json!([operation_binding(&operation_id, "story37_stale_tool")]),
json!([resource_binding(&resource_id, 2)]),
),
)
.await;
assert_eq!(
status,
StatusCode::CONFLICT,
"a stale save must be refused with 409; observed {status} body={text}"
);
assert_eq!(
body["error"]["code"],
json!("agent_stale_revision"),
"stale save must keep the Agent taxonomy error code: {text}"
);
assert_eq!(
body["error"]["context"]["recovery"],
json!("reload"),
"stale save must keep recovery=reload: {text}"
);
// Stale publish не должен ни публиковать, ни повышать catalog_revision.
let (status, text, body) =
publish_agent_raw(&client, &server_url, &agent_id, &stale_etag, 1).await;
assert_eq!(
status,
StatusCode::CONFLICT,
"a stale publish must be refused with 409; observed {status} body={text}"
);
assert_eq!(
body["error"]["code"],
json!("agent_stale_revision"),
"stale publish must keep the Agent taxonomy error code: {text}"
);
assert_eq!(
body["error"]["context"]["recovery"],
json!("reload"),
"stale publish must keep recovery=reload: {text}"
);
assert_eq!(
get_agent_version(&client, &server_url, &agent_id, 1).await,
before_version,
"stale save/publish must not mutate the exact Resource binding snapshot"
);
let after = get_agent(&client, &server_url, &agent_id).await;
assert_eq!(
after["catalog_revision"].as_i64(),
Some(catalog_before),
"stale save/publish must not bump catalog_revision: {after}"
);
assert_eq!(
agent_version_count(&registry, &agent_id).await,
versions_before,
"stale save/publish must not write an Agent version row"
);
}