refactor(claw): the watch table is the one truth — the config stops carrying watches

The YAML `watches:` seed was the last piece of forge state the config
file carried. Everything else about watches already lived in the
extension: the table (SQLite, runtime-managed), the HTTP routes
(`GET/POST/DELETE /v1/watches`), the chat tools, the poller that reads
the table fresh every pass. A static seed list on top meant two homes
for one fact — and the seed's own semantics (import-once, ignored
once the table has rows) had to be explained to every reader.

Now the config carries none of it:

- `ClawConfig.watches` is gone, with the `Watch` seed type and the
  boot-time validation loop that guarded it. A config still carrying
  `watches:` is refused at parse time — `deny_unknown_fields` turns
  the retirement into a loud migration, not a silent no-op.
- `Watch` moved to `watch_store` (re-exported from the crate root),
  where the row's vocabulary belongs; `validate_watch` keeps guarding
  the one door every writer shares — the routes and the tools both
  call it, so the moved validation tests test it there.
- `seed_from_config` and the daemon's seeding are gone; the operator
  seeds once over HTTP or `watches add`, and the table stays true.

The one guarantee the seed carried that nothing else did — boot
refuses a tokenless watch — goes with it, deliberately: a tokenless
watch now fails at its first poll, loudly, like any other watch the
agent adds at runtime. Boot-time certainty was paying for config
state the daemon no longer owns.
This commit is contained in:
vhaudiquet committed 2026-10-24 01:35:35 +02:00
1 parent f96f8c4c1d
commit c6a3ed8c97
9 files changed
+120 -373

No files matched your search

+14 -9
View File
@@ -5,7 +5,7 @@
use std::sync::Arc;
use rhema_claw::{ClawConfig, ForgeKind, Watch, run_once};
use rhema_claw::{ClawConfig, run_once};
use rhema_core::{Message, MockProvider, ModelOutput, Role, StopReason, Usage};
use rhema_rsd::{
Dispatcher, DispatcherConfig, KeyState, Outcome, ResourceKey, SqliteStore, SystemClock,
@@ -43,7 +43,7 @@ fn reply(text: &str) -> ModelOutput {
/// The test's claw config: everything under one tempdir, the watch aimed
/// at the mock server. The provider never resolves through it — the
/// daemon library takes the built provider, and the test builds a mock.
fn config(server: &MockServer, dir: &tempfile::TempDir) -> ClawConfig {
fn config(dir: &tempfile::TempDir) -> ClawConfig {
ClawConfig {
db: Some(dir.path().join("dispatch.db")),
workspace_root: Some(dir.path().join("workspaces")),
@@ -59,16 +59,20 @@ fn config(server: &MockServer, dir: &tempfile::TempDir) -> ClawConfig {
tools_bin: None,
transcript: None,
ingest_token: None,
watches: vec![Watch {
forge: ForgeKind::GitHub,
repo: "acme/widgets".to_owned(),
host: Some(server.uri()),
token: Some("tok".to_owned()),
}],
calendars: Vec::new(),
}
}
/// Seeds the watch row straight into the table — the config stopped
/// carrying watches, and the test speaks to the daemon the way an
/// integration would: through the store the routes share.
fn seed_watch(dir: &tempfile::TempDir, host: &str) {
rhema_claw::ClawStore::open(dir.path().join("dispatch.db"))
.expect("the watch table opens")
.add("github", "acme/widgets", Some(host), "tok")
.expect("the seed row lands");
}
#[tokio::test]
async fn one_pass_polls_reasons_and_posts() {
let server = MockServer::start().await;
@@ -103,7 +107,8 @@ async fn one_pass_polls_reasons_and_posts() {
.await;
let dir = tempfile::tempdir().expect("tempdir");
let config = config(&server, &dir);
let config = config(&dir);
seed_watch(&dir, &server.uri());
let provider = Arc::new(MockProvider::new([reply("on it")]));
let report = run_once(&config, mock_registry(provider))
.await