capture.offer applies capture.enabled/excludedHosts/monitoredExtensions/
monitoredMimeTypes/minSizeBytes from settings, then the rules table (new
store::Rules + CORE's vdm::rules::match_rules/glob_match — DAEMON only converts its
own stored proto::Rule JSON into CORE's plain vocabulary, per that header's own
layering note), resolves the category folder (a rule's explicit categoryId/saveDir,
else store::Categories::guess_by_extension — the same extension guess
download.probe's suggestedCategoryId already used, now shared instead of
duplicated), dedupes against active (non-terminal) tasks by exact URL, and on `take`
calls add_one() — the same path download.add itself uses, so a captured download is
a real, admitted, persisted task, not a special case.
The 750ms deadline (CLAUDE.md §4 / AGENT-DAEMON.md build step 6) is checked
cooperatively between every step via a new rpc::CaptureDataSource seam: the real
implementation wraps store::Settings/Categories/Rules/Tasks; a test fake can jump its
own injected clock forward to simulate "the store was slow just now" with zero real
sleep. This catches the realistic failure mode (several slow steps adding up) though
it cannot preempt a single pathologically stuck call mid-flight — a true preemptive
guarantee would need the same async/background-thread treatment as download.probe,
which isn't safe to do against the same sqlite3 connection (opened SQLITE_OPEN_NOMUTEX,
explicitly not for concurrent use) without a second connection; left as a known,
documented limit of this pass rather than adding that plumbing speculatively.
capture.getRules returns the same settings-backed fields capture.offer itself reads,
so the two can never drift. rulesVersion is a placeholder constant (1) — no persisted
revision counter exists yet, and the extension already re-fetches on
event.settings.changed regardless.
New store/rules.{hpp,cpp}: rules table CRUD (list, and an atomic upsert+remove for
rules.upsert later). store::Categories::guess_by_extension replaces a duplicate copy
that used to live in sched/scheduler.cpp. store::Tasks::has_active_duplicate for the
dedupe check.
Verified against real veloxd + tools/testserver: a monitored-type offer answers in
~5ms and actually creates + downloads the task, correctly categorized; an
unmonitored type, an excluded host, a rule-vetoed host, and a second offer for a
still-active URL all answer ignore with the right reason; a bad category save dir
surfaces its real -32011. New capture_offer_test covers all of the above plus the
deadline itself (two cases, one per "slow" checkpoint), asserting real wall-clock
time barely moves even though the fake clock jumped 2 simulated seconds. Full ctest:
54/54 (excluding the pre-existing, unrelated conformance failure noted in the
previous commit).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GRDjHGgpYmMoPE2UFbe7pP
38 lines
1.4 KiB
C++
38 lines
1.4 KiB
C++
#pragma once
|
|
|
|
// Read/write access to the `rules` table (rules.list / rules.upsert / capture.offer's own
|
|
// read path). match/action are stored as their generated-JSON text (velox::proto::RuleMatch
|
|
// / RuleAction), so no bespoke schema lives here beyond the table's own columns.
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "store/sqlite.hpp"
|
|
#include "velox_proto.hpp"
|
|
|
|
namespace velox::daemon::store {
|
|
|
|
class Rules {
|
|
public:
|
|
explicit Rules(Db& db) : db_(db) {}
|
|
|
|
// Enabled and disabled rules alike, in priority order (ties broken by rule_id) —
|
|
// rules.list's own contract ("the rules engine's table, in priority order"); capture
|
|
// offer's own caller filters to enabled ones itself, same as vdm::rules::match_rules
|
|
// already does internally.
|
|
DbResult<std::vector<velox::proto::Rule>> list();
|
|
|
|
// rules.upsert: "upsert carries the rules to store and remove the ruleIds to drop;
|
|
// applying both at once means a reprioritisation never leaves the table in a
|
|
// half-valid state" (the schema's own words) — one transaction. An empty ruleId in
|
|
// `upsert` generates one (create); a non-empty one replaces. Returns the full table
|
|
// after the write, in priority order.
|
|
DbResult<std::vector<velox::proto::Rule>> apply(std::vector<velox::proto::Rule> upsert,
|
|
const std::vector<std::string>& remove);
|
|
|
|
private:
|
|
Db& db_;
|
|
};
|
|
|
|
} // namespace velox::daemon::store
|